Universal AssetHandles. Serialize AssetHandle instead of AssetIdentifier

A bit unstable
This commit is contained in:
Simon Lübeß
2023-08-01 21:38:54 +02:00
parent 6d7f26b1f4
commit 60725c3588
45 changed files with 520 additions and 127 deletions
@@ -1,4 +1,5 @@
{ {
AssetLoader = "ModelAssetLoader", AssetLoader = "ModelAssetLoader",
Config = (GlitchyEditor.Assets.ModelAssetLoaderConfig){} Config = (GlitchyEditor.Assets.ModelAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.ModelAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 141014598923215615
} }
@@ -1,4 +1,5 @@
{ {
AssetLoader = "ModelAssetLoader", AssetLoader = "ModelAssetLoader",
Config = (GlitchyEditor.Assets.ModelAssetLoaderConfig){} Config = (GlitchyEditor.Assets.ModelAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.ModelAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 11221639476224465119
} }
@@ -0,0 +1,119 @@
{
Name = "Scene name here pls!!!",
Entities = [
{
Id = 8726995825602656358,
NameComponent = {
Name = "Camera"
},
TransformComponent = {
Position = {
X = 0,
Y = 2,
Z = -5
},
Rotation = {
X = 0,
Y = 0.21643962,
Z = 0,
W = 0.976296008
},
Scale = {
X = 1,
Y = 1,
Z = 1
},
EditorEulerRotation = {
X = 0,
Y = 0.436332315,
Z = 0
}
},
CameraComponent = {
Primary = true,
ProjectionType = .InfinitePerspective,
PerspectiveFovY = 1.30899692,
PerspectiveNearPlane = 0.100000001,
PerspectiveFarPlane = 10000,
OrthographicHeight = 10,
OrthographicNearPlane = 0,
OrthographicFarPlane = 10,
AspectRatio = 1.83772814,
FixedAspectRatio = false
}
},
{
Id = 5254899955475338567,
NameComponent = {
Name = "Light"
},
TransformComponent = {
Position = {
X = -3,
Y = 4,
Z = -1.5
},
Rotation = {
X = 0.239775807,
Y = 0.61432755,
Z = 0.0315670744,
W = 0.751074195
},
Scale = {
X = 1,
Y = 1,
Z = 1
},
EditorEulerRotation = {
X = 0.3490659,
Y = 1.3089968,
Z = 0.34906587
}
},
LightComponent = {
LightType = .Directional,
Illuminance = 10,
Color = {
R = 1,
G = 0.949999988,
B = 0.800000012
}
}
},
{
Id = 10018854473822844403,
NameComponent = {
Name = "Entity"
},
TransformComponent = {
Position = {
X = 0,
Y = 0,
Z = 0
},
Rotation = {
X = 0,
Y = 0,
Z = 0,
W = 1
},
Scale = {
X = 1,
Y = 1,
Z = 1
},
EditorEulerRotation = {
X = 0,
Y = 0,
Z = 0
}
},
MeshComponent = {
Mesh = 141014598923215615
},
MeshRendererComponent = {
Material = 15093501654975430075
}
}
]
}
@@ -9,8 +9,8 @@
AddressModeU = .Clamp, AddressModeU = .Clamp,
AddressModeV = .Clamp, AddressModeV = .Clamp,
AddressModeW = .Clamp, AddressModeW = .Clamp,
MipMinLOD = -340282346638528859811704183484516925440, MipMinLOD = -3.40282347e+38,
MipMaxLOD = 340282346638528859811704183484516925440, MipMaxLOD = 3.40282347e+38,
MaxAnisotropy = 1, MaxAnisotropy = 1,
BorderColor = { BorderColor = {
R = 1, R = 1,
@@ -19,5 +19,6 @@
A = 1 A = 1
} }
} }
} },
AssetHandle = 13149961070100324290
} }
@@ -0,0 +1,39 @@
{
Effect = "Resources/Shaders/myEffect.hlsl",
Textures = [
"AlbedoTexture": 8153940681327484189,
"NormalTexture": 15822842502398518390,
"MetallicTexture": 13527693616095745667,
"RoughnessTexture": 4141437666158293647,
"EmissiveTexture": 0
],
Variables = [
"AlbedoColor": .ColorRGBA{
Value = {
R = 1,
G = 1,
B = 1,
A = 1
}
},
"NormalScaling": .Float2{
Value = {
X = 1,
Y = 1
}
},
"MetallicFactor": .Float{
Value = 1
},
"RoughnessFactor": .Float{
Value = 0
},
"EmissiveColor": .Float3{
Value = {
X = 0,
Y = 0,
Z = 0
}
}
]
}
@@ -0,0 +1,5 @@
{
AssetLoader = "MaterialAssetLoader",
Config = (GlitchyEditor.Assets.ModelAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.ModelAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 15093501654975430075
}
@@ -1,4 +1,5 @@
{ {
AssetLoader = "MaterialAssetLoader", AssetLoader = "MaterialAssetLoader",
Config = (GlitchyEditor.Assets.ModelAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.ModelAssetLoaderConfig. Add [BonTarget] or force it */ Config = (GlitchyEditor.Assets.ModelAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.ModelAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 8829406607210635133
} }
@@ -9,8 +9,8 @@
AddressModeU = .Clamp, AddressModeU = .Clamp,
AddressModeV = .Clamp, AddressModeV = .Clamp,
AddressModeW = .Clamp, AddressModeW = .Clamp,
MipMinLOD = -340282346638528859811704183484516925440, MipMinLOD = -3.40282347e+38,
MipMaxLOD = 340282346638528859811704183484516925440, MipMaxLOD = 3.40282347e+38,
MaxAnisotropy = 1, MaxAnisotropy = 1,
BorderColor = { BorderColor = {
R = 1, R = 1,
@@ -19,5 +19,6 @@
A = 1 A = 1
} }
} }
} },
AssetHandle = 5558090951492679375
} }
@@ -1,21 +1,17 @@
{ {
AssetLoader = "EditorTextureAssetLoader", AssetLoader = "EditorTextureAssetLoader",
Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){ Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){
_generateMipMaps = true,
_isSrgb = true,
_samplerStateDescription = { _samplerStateDescription = {
MinFilter = .Anisotropic, MinFilter = .Linear,
MagFilter = .Anisotropic, MagFilter = .Linear,
MipFilter = .Anisotropic, MipFilter = .Linear,
FilterMode = .Default,
ComparisonFunction = .Never, ComparisonFunction = .Never,
AddressModeU = .Wrap, AddressModeU = .Clamp,
AddressModeV = .Wrap, AddressModeV = .Clamp,
AddressModeW = .Wrap, AddressModeW = .Clamp,
MipLODBias = 0, MipMinLOD = -3.40282347e+38,
MipMinLOD = 0, MipMaxLOD = 3.40282347e+38,
MipMaxLOD = 3, MaxAnisotropy = 1,
MaxAnisotropy = 16,
BorderColor = { BorderColor = {
R = 1, R = 1,
G = 1, G = 1,
@@ -23,5 +19,6 @@
A = 1 A = 1
} }
} }
} },
AssetHandle = 8153940681327484189
} }
@@ -2,15 +2,15 @@
AssetLoader = "EditorTextureAssetLoader", AssetLoader = "EditorTextureAssetLoader",
Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){ Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){
_samplerStateDescription = { _samplerStateDescription = {
MinFilter = .Anisotropic, MinFilter = .Linear,
MagFilter = .Anisotropic, MagFilter = .Linear,
MipFilter = .Anisotropic, MipFilter = .Linear,
ComparisonFunction = .Never, ComparisonFunction = .Never,
AddressModeU = .Wrap, AddressModeU = .Clamp,
AddressModeV = .Wrap, AddressModeV = .Clamp,
AddressModeW = .Clamp, AddressModeW = .Clamp,
MipMinLOD = -Infinity, MipMinLOD = -3.40282347e+38,
MipMaxLOD = Infinity, MipMaxLOD = 3.40282347e+38,
MaxAnisotropy = 1, MaxAnisotropy = 1,
BorderColor = { BorderColor = {
R = 1, R = 1,
@@ -19,5 +19,6 @@
A = 1 A = 1
} }
} }
} },
AssetHandle = 13527693616095745667
} }
@@ -1,20 +1,16 @@
{ {
AssetLoader = "EditorTextureAssetLoader", AssetLoader = "EditorTextureAssetLoader",
Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){ Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){
_generateMipMaps = false,
_isSrgb = false,
_samplerStateDescription = { _samplerStateDescription = {
MinFilter = .Linear, MinFilter = .Linear,
MagFilter = .Linear, MagFilter = .Linear,
MipFilter = .Linear, MipFilter = .Linear,
FilterMode = .Default,
ComparisonFunction = .Never, ComparisonFunction = .Never,
AddressModeU = .Wrap, AddressModeU = .Clamp,
AddressModeV = .Wrap, AddressModeV = .Clamp,
AddressModeW = .Clamp, AddressModeW = .Clamp,
MipLODBias = 2.5999999, MipMinLOD = -3.40282347e+38,
MipMinLOD = -Infinity, MipMaxLOD = 3.40282347e+38,
MipMaxLOD = Infinity,
MaxAnisotropy = 1, MaxAnisotropy = 1,
BorderColor = { BorderColor = {
R = 1, R = 1,
@@ -23,5 +19,6 @@
A = 1 A = 1
} }
} }
} },
AssetHandle = 15822842502398518390
} }
@@ -1,18 +1,14 @@
{ {
AssetLoader = "EditorTextureAssetLoader", AssetLoader = "EditorTextureAssetLoader",
Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){ Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){
_generateMipMaps = false,
_isSrgb = true,
_samplerStateDescription = { _samplerStateDescription = {
MinFilter = .Linear, MinFilter = .Linear,
MagFilter = .Linear, MagFilter = .Linear,
MipFilter = .Linear, MipFilter = .Linear,
FilterMode = .Default,
ComparisonFunction = .Never, ComparisonFunction = .Never,
AddressModeU = .Wrap, AddressModeU = .Clamp,
AddressModeV = .Wrap, AddressModeV = .Clamp,
AddressModeW = .Clamp, AddressModeW = .Clamp,
MipLODBias = 0,
MipMinLOD = -3.40282347e+38, MipMinLOD = -3.40282347e+38,
MipMaxLOD = 3.40282347e+38, MipMaxLOD = 3.40282347e+38,
MaxAnisotropy = 1, MaxAnisotropy = 1,
@@ -23,5 +19,6 @@
A = 1 A = 1
} }
} }
} },
AssetHandle = 4141437666158293647
} }
@@ -1,4 +1,5 @@
{ {
AssetLoader = "MaterialAssetLoader", AssetLoader = "MaterialAssetLoader",
Config = (GlitchyEditor.Assets.ModelAssetLoaderConfig){} Config = (GlitchyEditor.Assets.ModelAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.ModelAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 9886473966965265328
} }
@@ -9,8 +9,8 @@
AddressModeU = .Clamp, AddressModeU = .Clamp,
AddressModeV = .Clamp, AddressModeV = .Clamp,
AddressModeW = .Clamp, AddressModeW = .Clamp,
MipMinLOD = -340282346638528859811704183484516925440, MipMinLOD = -3.40282347e+38,
MipMaxLOD = 340282346638528859811704183484516925440, MipMaxLOD = 3.40282347e+38,
MaxAnisotropy = 1, MaxAnisotropy = 1,
BorderColor = { BorderColor = {
R = 1, R = 1,
@@ -19,5 +19,6 @@
A = 1 A = 1
} }
} }
} },
AssetHandle = 14357509390762845070
} }
@@ -1,7 +1,6 @@
{ {
AssetLoader = "EditorTextureAssetLoader", AssetLoader = "EditorTextureAssetLoader",
Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){ Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){
_isSrgb = true,
_samplerStateDescription = { _samplerStateDescription = {
MinFilter = .Linear, MinFilter = .Linear,
MagFilter = .Linear, MagFilter = .Linear,
@@ -20,5 +19,6 @@
A = 1 A = 1
} }
} }
} },
AssetHandle = 5635535744559587375
} }
@@ -1,15 +1,16 @@
{ {
AssetLoader = "EditorTextureAssetLoader", AssetLoader = "EditorTextureAssetLoader",
Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){ Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){
_isSrgb = true,
_samplerStateDescription = { _samplerStateDescription = {
MinFilter = .Linear, MinFilter = .Linear,
MagFilter = .Linear,
MipFilter = .Linear,
ComparisonFunction = .Never, ComparisonFunction = .Never,
AddressModeU = .Clamp, AddressModeU = .Clamp,
AddressModeV = .Clamp, AddressModeV = .Clamp,
AddressModeW = .Clamp, AddressModeW = .Clamp,
MipMinLOD = -340282346638528859811704183484516925440, MipMinLOD = -3.40282347e+38,
MipMaxLOD = 340282346638528859811704183484516925440, MipMaxLOD = 3.40282347e+38,
MaxAnisotropy = 1, MaxAnisotropy = 1,
BorderColor = { BorderColor = {
R = 1, R = 1,
@@ -18,5 +19,6 @@
A = 1 A = 1
} }
} }
} },
AssetHandle = 10807131213209469263
} }
@@ -1,7 +1,6 @@
{ {
AssetLoader = "EditorTextureAssetLoader", AssetLoader = "EditorTextureAssetLoader",
Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){ Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){
_isSrgb = true,
_samplerStateDescription = { _samplerStateDescription = {
MinFilter = .Linear, MinFilter = .Linear,
MagFilter = .Linear, MagFilter = .Linear,
@@ -10,8 +9,8 @@
AddressModeU = .Clamp, AddressModeU = .Clamp,
AddressModeV = .Clamp, AddressModeV = .Clamp,
AddressModeW = .Clamp, AddressModeW = .Clamp,
MipMinLOD = -Infinity, MipMinLOD = -3.40282347e+38,
MipMaxLOD = Infinity, MipMaxLOD = 3.40282347e+38,
MaxAnisotropy = 1, MaxAnisotropy = 1,
BorderColor = { BorderColor = {
R = 1, R = 1,
@@ -20,5 +19,6 @@
A = 1 A = 1
} }
} }
} },
AssetHandle = 5889819840498959425
} }
@@ -1,4 +1,5 @@
{ {
AssetLoader = "EffectAssetLoader", AssetLoader = "EffectAssetLoader",
Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 5360037389314667000
} }
@@ -1,4 +1,5 @@
{ {
AssetLoader = "EffectAssetLoader", AssetLoader = "EffectAssetLoader",
Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 15597986932192091061
} }
@@ -1,4 +1,5 @@
{ {
AssetLoader = "EffectAssetLoader", AssetLoader = "EffectAssetLoader",
Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 7082287996527160060
} }
@@ -1,4 +1,5 @@
{ {
AssetLoader = "EffectAssetLoader", AssetLoader = "EffectAssetLoader",
Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */ Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 17297254839128368932
} }
@@ -1,4 +1,5 @@
{ {
AssetLoader = "EffectAssetLoader", AssetLoader = "EffectAssetLoader",
Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 17917061300990589192
} }
+2 -1
View File
@@ -1,4 +1,5 @@
{ {
AssetLoader = "EffectAssetLoader", AssetLoader = "EffectAssetLoader",
Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 8336560834161185660
} }
@@ -1,4 +1,5 @@
{ {
AssetLoader = "EffectAssetLoader", AssetLoader = "EffectAssetLoader",
Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */ Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 1518912886664733757
} }
@@ -1,4 +1,5 @@
{ {
AssetLoader = "EffectAssetLoader", AssetLoader = "EffectAssetLoader",
Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 13663488523997149295
} }
@@ -1,4 +1,5 @@
{ {
AssetLoader = "EffectAssetLoader", AssetLoader = "EffectAssetLoader",
Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 9450907808112906391
} }
@@ -1,4 +1,5 @@
{ {
AssetLoader = "EffectAssetLoader", AssetLoader = "EffectAssetLoader",
Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 4086392147967882920
} }
@@ -1,4 +1,5 @@
{ {
AssetLoader = "EffectAssetLoader", AssetLoader = "EffectAssetLoader",
Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 3929078354809894230
} }
@@ -1,4 +1,5 @@
{ {
AssetLoader = "EffectAssetLoader", AssetLoader = "EffectAssetLoader",
Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */ Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 5414648614681927202
} }
@@ -1,4 +1,5 @@
{ {
AssetLoader = "EffectAssetLoader", AssetLoader = "EffectAssetLoader",
Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 17001330646928133106
} }
@@ -1,4 +1,5 @@
{ {
AssetLoader = "EffectAssetLoader", AssetLoader = "EffectAssetLoader",
Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 2913314865396454015
} }
@@ -1,4 +1,5 @@
{ {
AssetLoader = "EffectAssetLoader", AssetLoader = "EffectAssetLoader",
Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 9047671870217222298
} }
@@ -1,4 +1,5 @@
{ {
AssetLoader = "EffectAssetLoader", AssetLoader = "EffectAssetLoader",
Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 14473519405124742382
} }
@@ -1,4 +1,5 @@
{ {
AssetLoader = "EffectAssetLoader", AssetLoader = "EffectAssetLoader",
Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */,
AssetHandle = 10276018270467402814
} }
@@ -19,5 +19,6 @@
A = 1 A = 1
} }
} }
} },
AssetHandle = 16828117378770367285
} }
+12
View File
@@ -17,6 +17,9 @@ class AssetConfig
[BonInclude] [BonInclude]
public AssetLoaderConfig Config ~ delete _; public AssetLoaderConfig Config ~ delete _;
[BonInclude]
public AssetHandle AssetHandle = .Invalid;
} }
class AssetFile class AssetFile
@@ -79,11 +82,19 @@ class AssetFile
} }
} }
private void GenerateAssetHandle()
{
_assetConfig.AssetHandle = .();
}
private void CreateDefaultAssetLoader() private void CreateDefaultAssetLoader()
{ {
String fileExtension = Path.GetExtension(_path, .. scope .()); String fileExtension = Path.GetExtension(_path, .. scope .());
_assetConfig = new AssetConfig(); _assetConfig = new AssetConfig();
GenerateAssetHandle();
var assetLoader = _contentManager.GetDefaultAssetLoader(fileExtension); var assetLoader = _contentManager.GetDefaultAssetLoader(fileExtension);
// We don't have a loader -> we don't need a config // We don't have a loader -> we don't need a config
@@ -96,6 +107,7 @@ class AssetFile
_assetConfig.Config = assetLoader?.GetDefaultConfig(); _assetConfig.Config = assetLoader?.GetDefaultConfig();
_assetConfig.Config?.[Friend]_changed = true; _assetConfig.Config?.[Friend]_changed = true;
SaveAssetConfig(); SaveAssetConfig();
} }
+21 -4
View File
@@ -5,6 +5,7 @@ using System;
using System.Collections; using System.Collections;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using GlitchyEngine.Content;
namespace GlitchyEditor.Assets; namespace GlitchyEditor.Assets;
@@ -96,6 +97,7 @@ class AssetHierarchy
internal TreeNode<AssetNode> _assetsDirectoryNode = null; internal TreeNode<AssetNode> _assetsDirectoryNode = null;
private append Dictionary<StringView, TreeNode<AssetNode>> _pathToAssetNode = .(); private append Dictionary<StringView, TreeNode<AssetNode>> _pathToAssetNode = .();
private append Dictionary<StringView, TreeNode<AssetNode>> _identifierToAssetNode = .(); private append Dictionary<StringView, TreeNode<AssetNode>> _identifierToAssetNode = .();
private append Dictionary<AssetHandle, TreeNode<AssetNode>> _handleToAssetNode = .();
private append String _resourcesDirectory = .(); private append String _resourcesDirectory = .();
private append String _assetsDirectory = .(); private append String _assetsDirectory = .();
@@ -166,7 +168,8 @@ class AssetHierarchy
} }
} }
} }
/// Sets path to the directory that contains the engine assets.
public void SetResourcesDirectory(StringView fileName) public void SetResourcesDirectory(StringView fileName)
{ {
ResourcesDirectory = fileName; ResourcesDirectory = fileName;
@@ -206,6 +209,7 @@ class AssetHierarchy
Update(); Update();
} }
/// Sets path to the directory that contains the game assets.
public void SetAssetsDirectory(StringView fileName) public void SetAssetsDirectory(StringView fileName)
{ {
AssetsDirectory = fileName; AssetsDirectory = fileName;
@@ -225,7 +229,6 @@ class AssetHierarchy
return; return;
} }
AssetNode assetNode = new AssetNode(); AssetNode assetNode = new AssetNode();
assetNode.Path = new String(AssetsDirectory); assetNode.Path = new String(AssetsDirectory);
assetNode.Name = new String(); assetNode.Name = new String();
@@ -239,7 +242,6 @@ class AssetHierarchy
Log.EngineLogger.Trace($"Created directory node for: \"{AssetsDirectory}\""); Log.EngineLogger.Trace($"Created directory node for: \"{AssetsDirectory}\"");
_fileSystemDirty = true; _fileSystemDirty = true;
SetupFileSystemWatcher(); SetupFileSystemWatcher();
@@ -297,7 +299,7 @@ class AssetHierarchy
return .Err; return .Err;
} }
/// Gets the tree node for the given filePath or .Err, if the file/directory doesn't exist. /// Gets the tree node for the given asset identifier or .Err, if the file/directory doesn't exist.
/// @param filePath the path for which to return the tree node. /// @param filePath the path for which to return the tree node.
/// @remarks Do not hold a reference to the TreeNode because it can become invalid when the file hierarchy changes. /// @remarks Do not hold a reference to the TreeNode because it can become invalid when the file hierarchy changes.
public Result<TreeNode<AssetNode>> GetNodeFromIdentifier(StringView identifier) public Result<TreeNode<AssetNode>> GetNodeFromIdentifier(StringView identifier)
@@ -310,6 +312,19 @@ class AssetHierarchy
return .Err; return .Err;
} }
/// Gets the tree node for the given asset handle; or .Err, if no file exists with the given handle.
/// @param filePath the path for which to return the tree node.
/// @remarks Do not hold a reference to the TreeNode because it can become invalid when the file hierarchy changes.
public Result<TreeNode<AssetNode>> GetNodeFromAssetHandle(AssetHandle assetHandle)
{
if (_handleToAssetNode.TryGetValue(assetHandle, let treeNode))
{
return treeNode;
}
return .Err;
}
public bool FileExists(StringView filePath) public bool FileExists(StringView filePath)
{ {
return _pathToAssetNode.ContainsKey(filePath); return _pathToAssetNode.ContainsKey(filePath);
@@ -399,6 +414,8 @@ class AssetHierarchy
//GrabSubAssets(node); //GrabSubAssets(node);
HandleFile(treeNode.Value); HandleFile(treeNode.Value);
_handleToAssetNode.Add(assetNode.AssetFile.AssetConfig.AssetHandle, treeNode);
Log.EngineLogger.Trace($"Created file node for: \"{assetNode.Path}\""); Log.EngineLogger.Trace($"Created file node for: \"{assetNode.Path}\"");
} }
} }
@@ -103,7 +103,10 @@ class MaterialAssetPropertiesEditor : AssetPropertiesEditor
{ {
for (let texture in effect.Textures) for (let texture in effect.Textures)
{ {
ImGui.Button(texture.key); ImGui.TextUnformatted(texture.key);
ImGui.SameLine();
ImGui.Button("Texture");
if (ImGui.BeginDragDropTarget()) if (ImGui.BeginDragDropTarget())
{ {
@@ -315,7 +318,8 @@ class MaterialFile
{ {
public String Effect ~ delete _; public String Effect ~ delete _;
public Dictionary<String, String> Textures ~ DeleteDictionaryAndKeysAndValues!(_); //public Dictionary<String, String> Textures ~ DeleteDictionaryAndKeysAndValues!(_);
public Dictionary<String, AssetHandle<Texture>> Textures ~ DeleteDictionaryAndKeys!(_);
public Dictionary<String, VariableValue> Variables ~ public Dictionary<String, VariableValue> Variables ~
{ {
if (_ != null) if (_ != null)
@@ -417,14 +421,13 @@ class MaterialAssetLoader : IAssetLoader, IAssetSaver //, IReloadingAssetLoader
Material material = new Material(fx); Material material = new Material(fx);
for (let (slotName, textureIdentifier) in materialFile.Textures) for (let (slotName, textureHandle) in materialFile.Textures)
{ {
AssetHandle<Texture> texture = contentManager.LoadAsset(textureHandle);
AssetHandle<Texture> texture = contentManager.LoadAsset(textureIdentifier);
if (texture.IsInvalid) if (texture.IsInvalid)
{ {
Log.EngineLogger.Error($"Failed to load texture \"{textureIdentifier}\"."); Log.EngineLogger.Error($"Failed to load texture \"{textureHandle}\".");
} }
material.SetTexture(slotName, texture); material.SetTexture(slotName, texture);
@@ -475,9 +478,7 @@ class MaterialAssetLoader : IAssetLoader, IAssetSaver //, IReloadingAssetLoader
for (let (slotName, texture) in material.[Friend]_textures) for (let (slotName, texture) in material.[Friend]_textures)
{ {
Texture textureAsset = texture.Handle.Get(); materialFile.Textures.Add(new String(slotName), texture.Handle);
materialFile.Textures.Add(new String(slotName), new String(textureAsset?.Identifier ?? ""));
} }
Effect effect = material.Effect; Effect effect = material.Effect;
@@ -1064,7 +1064,7 @@ namespace GlitchyEditor.EditWindows
GeometryBinding mesh = meshComponent.Mesh; GeometryBinding mesh = meshComponent.Mesh;
StringView identifier = mesh?.Identifier ?? "None"; StringView identifier = mesh?.Identifier ?? (meshComponent.Mesh.IsValid ? "<Missing Asset>" : "None");
ImGui.Button(identifier.ToScopeCStr!()); ImGui.Button(identifier.ToScopeCStr!());
if (ImGui.BeginDragDropTarget()) if (ImGui.BeginDragDropTarget())
@@ -141,8 +141,18 @@ namespace GlitchyEditor.EditWindows
if (payload != null) if (payload != null)
{ {
StringView path = .((char8*)payload.Data, (int)payload.DataSize); StringView assetIdentifier = .((char8*)payload.Data, (int)payload.DataSize);
_editor.RequestOpenScene(this, path);
let treeNode = _editor.ContentManager.AssetHierarchy.GetNodeFromIdentifier(assetIdentifier);
if (treeNode case .Err)
{
Log.EngineLogger.Error($"Dragged Asset doesn't exist. {assetIdentifier}");
return;
}
_editor.RequestOpenScene(this, treeNode->Value.Path);
} }
ImGui.EndDragDropTarget(); ImGui.EndDragDropTarget();
+130 -4
View File
@@ -221,7 +221,10 @@ class EditorContentManager : IContentManager
{ {
Asset asset = null; Asset asset = null;
_handleToAsset.TryGetValue(handle, out asset); if (!_handleToAsset.TryGetValue(handle, out asset))
{
LoadAsset(handle);
}
if (var placeholder = asset as PlaceholderAsset) if (var placeholder = asset as PlaceholderAsset)
{ {
@@ -339,7 +342,92 @@ class EditorContentManager : IContentManager
private append List<(PlaceholderAsset placeholder, Asset newAsset)> _finishedEntries = .(); private append List<(PlaceholderAsset placeholder, Asset newAsset)> _finishedEntries = .();
private class MissingAsset : Asset {} private class MissingAsset : Asset {}
/// Loads the Asset that is represented by the given AssetHandle.
/// @returns The AssetHandle of the loaded asset or .Invalid if no asset exists with the given handle.
public AssetHandle LoadAsset(AssetHandle handle, bool blocking = false)
{
Debug.Profiler.ProfileResourceFunction!();
if (handle.IsInvalid)
return .Invalid;
// If _handleToAsset contains handle, we for sure have an asset for it.
if (_handleToAsset.ContainsKey(handle))
return handle;
Result<TreeNode<AssetNode>> resultNode = AssetHierarchy.GetNodeFromAssetHandle(handle);
if (resultNode case .Err)
{
Log.EngineLogger.Error($"Could not find asset with handle {handle}.");
return .Invalid;
}
String filePath = scope String(resultNode->Value.Path);
AssetFile file = resultNode->Value.AssetFile;
GetResourceAndSubassetName(file.Identifier, let resourceName, let subassetName);
IAssetLoader assetLoader = GetAssetLoader(file);
// TODO: what are we supposed to do if we don't find a loader? Surely not crash...
//Log.EngineLogger.AssertDebug(assetLoader != null);
if (assetLoader == null)
{
Log.EngineLogger.Error($"No asset loader registered for asset \"{resultNode->Value.Identifier}\" ({handle}).");
return .Invalid;
}
Asset loadedAsset;
// TODO: Support lazy loading for all asset types
if (!(assetLoader is EditorTextureAssetLoader) || blocking)
{
Stream stream = OpenStream(filePath, true);
loadedAsset = assetLoader.LoadAsset(stream, file.AssetConfig.Config, resourceName, subassetName, this);
delete stream;
if (loadedAsset == null)
return .Invalid;
}
else
{
PlaceholderAsset placeholder = new PlaceholderAsset(file, assetLoader, .Loading);
String filePath2 = new String(filePath);
String newResourceName = new String(resourceName);
String newSesourceName = subassetName == null ? null : new String(subassetName.Value);
placeholder.LoadingTask = new Task(new () => {
AsyncLoadAsset(placeholder, filePath2, assetLoader, file,
newResourceName, newSesourceName);
});
ThreadPool.QueueUserWorkItem(placeholder.LoadingTask);
loadedAsset = placeholder;
}
loadedAsset.Identifier = file.Identifier;
_handleToAsset.Add(handle, loadedAsset);
loadedAsset.[Friend]_contentManager = this;
loadedAsset.[Friend]_handle = handle;
// Add to Identifier -> Handle map
_identiferToHandle.Add(loadedAsset.Identifier, handle);
file.[Friend]_loadedAsset = loadedAsset;
return handle;
}
/// Loads the Asset with the given asset identifier
public AssetHandle LoadAsset(StringView identifier, bool blocking = false) public AssetHandle LoadAsset(StringView identifier, bool blocking = false)
{ {
Debug.Profiler.ProfileResourceFunction!(); Debug.Profiler.ProfileResourceFunction!();
@@ -347,10 +435,31 @@ class EditorContentManager : IContentManager
// It's valid to request no entity, but no entity is obviously invalid. // It's valid to request no entity, but no entity is obviously invalid.
if (identifier.IsWhiteSpace) if (identifier.IsWhiteSpace)
return .Invalid; return .Invalid;
// We allow backslashes as well as forward slashes. Some Path stuff like /./ is also allowed.
String fixedIdentifier = scope String(identifier); String fixedIdentifier = scope String(identifier);
AssetIdentifier.Fixup(fixedIdentifier); AssetIdentifier.Fixup(fixedIdentifier);
// If we have an identifier -> handle mapping, we for sure have the asset and are done.
if (_identiferToHandle.TryGetValue(fixedIdentifier, let asset))
return asset;
if (AssetHierarchy.GetNodeFromIdentifier(fixedIdentifier) case .Ok(let assetNode))
{
return LoadAsset(assetNode->AssetFile.AssetConfig.AssetHandle, blocking);
}
else
{
Log.EngineLogger.Error($"Could not get asset node for asset {fixedIdentifier}");
return .Invalid;
}
//Result<TreeNode<AssetNode>> resultNode = AssetHierarchy.GetNodeFromIdentifier(fixedIdentifier);
//resultNode.
/*
if (_identiferToHandle.TryGetValue(fixedIdentifier, let asset)) if (_identiferToHandle.TryGetValue(fixedIdentifier, let asset))
return asset; return asset;
@@ -411,7 +520,24 @@ class EditorContentManager : IContentManager
} }
loadedAsset.Identifier = fixedIdentifier; loadedAsset.Identifier = fixedIdentifier;
AssetHandle handle = ManageAsset(loadedAsset);
AssetHandle handle = .Invalid;
if (file.AssetConfig.AssetHandle == .Invalid)
{
handle = ManageAsset(loadedAsset);
// TODO: Does this ever happen?
file.AssetConfig.AssetHandle = handle;
}
else
{
handle = file.AssetConfig.AssetHandle;
_handleToAsset.Add(handle, loadedAsset);
loadedAsset.[Friend]_contentManager = this;
loadedAsset.[Friend]_handle = handle;
}
// ManageAsset increases RefCount, but this scope also holds a reference. // ManageAsset increases RefCount, but this scope also holds a reference.
loadedAsset.ReleaseRef(); loadedAsset.ReleaseRef();
@@ -420,7 +546,7 @@ class EditorContentManager : IContentManager
file.[Friend]_loadedAsset = loadedAsset; file.[Friend]_loadedAsset = loadedAsset;
return handle; return handle;*/
} }
private void AsyncLoadAsset(PlaceholderAsset placeholder, String filePath, IAssetLoader assetLoader, AssetFile file, String resourceName, String subassetName) private void AsyncLoadAsset(PlaceholderAsset placeholder, String filePath, IAssetLoader assetLoader, AssetFile file, String resourceName, String subassetName)
+2 -5
View File
@@ -235,10 +235,7 @@ namespace GlitchyEditor
_editor.EditorSceneRenderer = _editorSceneRenderer; _editor.EditorSceneRenderer = _editorSceneRenderer;
_editor.RequestOpenScene.Add(new (s, fileName) => { _editor.RequestOpenScene.Add(new (s, fileName) => {
String fullName = scope .(); LoadSceneFile(fileName);
Path.Combine(fullName, _currentProject.AssetsFolder, fileName);
LoadSceneFile(fullName);
}); });
} }
@@ -1105,7 +1102,7 @@ namespace GlitchyEditor
private void ShowOpenRecentSceneMenu() private void ShowOpenRecentSceneMenu()
{ {
if (_currentProject == null) if (_currentProject == null || _currentProject.UserSettings.RecentScenes == null)
return; return;
int i = 0; int i = 0;
+38 -4
View File
@@ -50,16 +50,50 @@ abstract class Asset : RefCounter
static void AssetSerialize(BonWriter writer, ValueView value, BonEnvironment environment, SerializeValueState state) static void AssetSerialize(BonWriter writer, ValueView value, BonEnvironment environment, SerializeValueState state)
{ {
Log.EngineLogger.Assert(value.type == typeof(Asset)); Log.EngineLogger.Assert(value.type == typeof(Asset));
var handle = value.Get<Asset>()._handle;
Serialize.Value(writer, handle, environment);
let identifier = value.Get<Asset>().Identifier;
writer.String(identifier); //AssetHandle.[Friend]AssetSerialize(writer, ValueView(typeof(AssetHandle), &handle), environment, state);
//writer.String(identifier);
} }
static Result<void> AssetDeserialize(BonReader reader, ValueView value, BonEnvironment environment, DeserializeValueState state) static Result<void> AssetDeserialize(BonReader reader, ValueView value, BonEnvironment environment, DeserializeValueState state)
{ {
Log.EngineLogger.Assert(value.type == typeof(Asset)); Log.EngineLogger.Assert(value.type == typeof(Asset));
String identifier = scope .(); Try!(Deserialize.Value<AssetHandle>(reader, let handle, environment));
//String identifier = scope .();
//Deserialize.String!(reader, ref identifier, environment);
AssetHandle loadedHandle = Content.LoadAsset(handle);
if (loadedHandle == .Invalid)
{
value.Assign<Asset>(null);
return .Ok;
}
Asset asset = Content.GetAsset<Asset>(handle);
if (asset != null)
{
Asset oldAsset = value.Get<Asset>();
oldAsset.ReleaseRef();
value.Assign(asset);
return .Ok;
}
else
{
Deserialize.Error!("Invalid resource path", reader, value.type);
}
/*String identifier = scope .();
Deserialize.String!(reader, ref identifier, environment); Deserialize.String!(reader, ref identifier, environment);
@@ -84,7 +118,7 @@ abstract class Asset : RefCounter
else else
{ {
Deserialize.Error!("Invalid resource path", reader, value.type); Deserialize.Error!("Invalid resource path", reader, value.type);
} }*/
} }
//gBonEnv.typeHandlers.Add(typeof(Resource<>), //gBonEnv.typeHandlers.Add(typeof(Resource<>),
+17 -19
View File
@@ -50,6 +50,11 @@ struct AssetHandle : IHashable
{ {
Log.EngineLogger.Assert(value.type == typeof(AssetHandle)); Log.EngineLogger.Assert(value.type == typeof(AssetHandle));
var uuid = value.Get<AssetHandle>()._uuid;
Serialize.Value(writer, uuid, environment);
/*Log.EngineLogger.Assert(value.type == typeof(AssetHandle));
AssetHandle handle = value.Get<AssetHandle>(); AssetHandle handle = value.Get<AssetHandle>();
if (handle.IsInvalid) if (handle.IsInvalid)
@@ -58,20 +63,24 @@ struct AssetHandle : IHashable
{ {
let identifier = handle.Get<Asset>().Identifier; let identifier = handle.Get<Asset>().Identifier;
writer.String(identifier); writer.String(identifier);
} }*/
} }
static Result<void> AssetDeserialize(BonReader reader, ValueView value, BonEnvironment environment, DeserializeValueState state) static Result<void> AssetDeserialize(BonReader reader, ValueView value, BonEnvironment environment, DeserializeValueState state)
{ {
Log.EngineLogger.Assert(value.type == typeof(AssetHandle)); Log.EngineLogger.Assert(value.type == typeof(AssetHandle));
String identifier = scope .(); Try!(Deserialize.Value<UUID>(reader, let uuid, environment));
value.Assign(AssetHandle(uuid));
/*String identifier = scope .();
Deserialize.String!(reader, ref identifier, environment); Deserialize.String!(reader, ref identifier, environment);
AssetHandle handle = Content.LoadAsset(identifier); AssetHandle handle = Content.LoadAsset(identifier);
value.Assign<AssetHandle>(handle); value.Assign<AssetHandle>(handle);*/
return .Ok; return .Ok;
} }
@@ -314,29 +323,18 @@ struct AssetHandle<T> where T : Asset
static void AssetSerialize(BonWriter writer, ValueView value, BonEnvironment environment, SerializeValueState state) static void AssetSerialize(BonWriter writer, ValueView value, BonEnvironment environment, SerializeValueState state)
{ {
Log.EngineLogger.Assert(value.type == typeof(AssetHandle<T>)); Log.EngineLogger.Assert(value.type == typeof(AssetHandle<T>));
AssetHandle handle = value.Get<AssetHandle<T>>(); AssetHandle handle = value.Get<AssetHandle<T>>();
Serialize.Value(writer, handle, environment);
if (handle.IsInvalid)
writer.String("");
else
{
let identifier = handle.Get<Asset>().Identifier;
writer.String(identifier);
}
} }
static Result<void> AssetDeserialize(BonReader reader, ValueView value, BonEnvironment environment, DeserializeValueState state) static Result<void> AssetDeserialize(BonReader reader, ValueView value, BonEnvironment environment, DeserializeValueState state)
{ {
Log.EngineLogger.Assert(value.type == typeof(AssetHandle<T>)); Log.EngineLogger.Assert(value.type == typeof(AssetHandle<T>));
String identifier = scope .();
Deserialize.String!(reader, ref identifier, environment);
AssetHandle<T> handle = Content.LoadAsset(identifier);
value.Assign<AssetHandle<T>>(handle); Try!(Deserialize.Value<AssetHandle>(reader, let handle, environment));
value.Assign(AssetHandle<T>(handle));
return .Ok; return .Ok;
} }
@@ -67,6 +67,19 @@ namespace GlitchyEngine.Content
static class Content static class Content
{ {
/// Loads the specified asset with the given contentManager or the current applications content manager.
public static AssetHandle LoadAsset(AssetHandle assetHandle, IContentManager contentManager = null, bool blocking = false)
{
var contentManager;
if (contentManager == null)
contentManager = Application.Get().ContentManager;
AssetHandle handle = contentManager.LoadAsset(assetHandle, blocking);
return handle;
}
/// Loads the specified asset with the given contentManager or the current applications content manager. /// Loads the specified asset with the given contentManager or the current applications content manager.
public static AssetHandle LoadAsset(StringView assetIdentifier, IContentManager contentManager = null, bool blocking = false) public static AssetHandle LoadAsset(StringView assetIdentifier, IContentManager contentManager = null, bool blocking = false)
{ {
@@ -119,6 +132,9 @@ namespace GlitchyEngine.Content
/// Loads the Asset with the given handle and returns the handle. /// Loads the Asset with the given handle and returns the handle.
AssetHandle LoadAsset(StringView assetIdentifier, bool blocking = false); AssetHandle LoadAsset(StringView assetIdentifier, bool blocking = false);
/// Loads the Asset with the given handle and returns the handle. Returns .Invalid, if the asset handle doesn't exist.
AssetHandle LoadAsset(AssetHandle handle, bool blocking = false);
/// Returns the asset for the given handle or null, if it isn't loaded. /// Returns the asset for the given handle or null, if it isn't loaded.
Asset GetAsset(AssetHandle handle) Asset GetAsset(AssetHandle handle)
{ {