From 60725c3588dddad78200971fb40fd77e2d1c7a41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Tue, 1 Aug 2023 21:38:54 +0200 Subject: [PATCH] Universal AssetHandles. Serialize AssetHandle instead of AssetIdentifier A bit unstable --- .../Assets/Models/plane.glb.ass | 3 +- .../Assets/Models/sphere.glb.ass | 3 +- .../Assets/Scenes/New Scene.scene | 119 ++++++++++++++++ .../Assets/Textures/DefaultNormal.png.ass | 7 +- .../Assets/Textures/New Material.mat | 39 +++++ .../Assets/Textures/New Material.mat.ass | 5 + .../Assets/Textures/RocketMaterial.mat.ass | 3 +- .../Assets/Textures/TestMat/nrm.png.ass | 7 +- .../TestMat/rustediron2_albedo.png.ass | 25 ++-- .../TestMat/rustediron2_metallic.png.ass | 17 +-- .../TestMat/rustediron2_normal.png.ass | 15 +- .../TestMat/rustediron2_roughness.png.ass | 11 +- .../Assets/Textures/TestMaterial.mat.ass | 3 +- .../Assets/Textures/White.png.ass | 7 +- .../Assets/Textures/rocket.dds.ass | 4 +- .../Assets/Textures/rocket.png.ass | 10 +- .../Assets/Textures/test_skybox.dds.ass | 8 +- GlitchyEditor/resources/Shaders/ACES.hlsl.ass | 3 +- .../resources/Shaders/ClearUInt.hlsl.ass | 3 +- .../resources/Shaders/GammaCorrect.hlsl.ass | 3 +- .../resources/Shaders/GlitchyEngine.hlsl.ass | 3 +- .../Shaders/LightingFunctions.hlsl.ass | 3 +- GlitchyEditor/resources/Shaders/PBR.hlsl.ass | 3 +- .../Shaders/RenderTargetGroupViewer.hlsl.ass | 3 +- .../resources/Shaders/ShaderHelpers.hlsl.ass | 3 +- .../Shaders/SimpleTonemapping.hlsl.ass | 3 +- .../resources/Shaders/circlebatch.hlsl.ass | 3 +- .../resources/Shaders/lineShader.hlsl.ass | 3 +- .../resources/Shaders/linebatch.hlsl.ass | 3 +- .../resources/Shaders/msdfShader.hlsl.ass | 3 +- .../resources/Shaders/myEffect.hlsl.ass | 3 +- .../resources/Shaders/simpleLight.hlsl.ass | 3 +- .../resources/Shaders/spritebatch.hlsl.ass | 3 +- .../Shaders/textureViewerShader.hlsl.ass | 3 +- .../resources/Textures/EditorIcons.dds.ass | 3 +- GlitchyEditor/src/AssetFile.bf | 12 ++ GlitchyEditor/src/Assets/AssetHierarchy.bf | 25 +++- .../src/Assets/MaterialAssetLoader.bf | 19 +-- .../src/EditWindows/ComponentEditWindow.bf | 2 +- .../src/EditWindows/EditorViewportWindow.bf | 14 +- GlitchyEditor/src/EditorContentManager.bf | 134 +++++++++++++++++- GlitchyEditor/src/EditorLayer.bf | 7 +- GlitchyEngine/src/Content/Asset.bf | 42 +++++- GlitchyEngine/src/Content/AssetHandle.bf | 36 +++-- GlitchyEngine/src/Content/ContentManager.bf | 16 +++ 45 files changed, 520 insertions(+), 127 deletions(-) create mode 100644 GlitchyEditor/SandboxProject/Assets/Scenes/New Scene.scene create mode 100644 GlitchyEditor/SandboxProject/Assets/Textures/New Material.mat create mode 100644 GlitchyEditor/SandboxProject/Assets/Textures/New Material.mat.ass diff --git a/GlitchyEditor/SandboxProject/Assets/Models/plane.glb.ass b/GlitchyEditor/SandboxProject/Assets/Models/plane.glb.ass index d5fb47f..3c9c5d5 100644 --- a/GlitchyEditor/SandboxProject/Assets/Models/plane.glb.ass +++ b/GlitchyEditor/SandboxProject/Assets/Models/plane.glb.ass @@ -1,4 +1,5 @@ { AssetLoader = "ModelAssetLoader", - Config = (GlitchyEditor.Assets.ModelAssetLoaderConfig){} + Config = (GlitchyEditor.Assets.ModelAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.ModelAssetLoaderConfig. Add [BonTarget] or force it */, + AssetHandle = 141014598923215615 } \ No newline at end of file diff --git a/GlitchyEditor/SandboxProject/Assets/Models/sphere.glb.ass b/GlitchyEditor/SandboxProject/Assets/Models/sphere.glb.ass index d5fb47f..4c2777c 100644 --- a/GlitchyEditor/SandboxProject/Assets/Models/sphere.glb.ass +++ b/GlitchyEditor/SandboxProject/Assets/Models/sphere.glb.ass @@ -1,4 +1,5 @@ { AssetLoader = "ModelAssetLoader", - Config = (GlitchyEditor.Assets.ModelAssetLoaderConfig){} + Config = (GlitchyEditor.Assets.ModelAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.ModelAssetLoaderConfig. Add [BonTarget] or force it */, + AssetHandle = 11221639476224465119 } \ No newline at end of file diff --git a/GlitchyEditor/SandboxProject/Assets/Scenes/New Scene.scene b/GlitchyEditor/SandboxProject/Assets/Scenes/New Scene.scene new file mode 100644 index 0000000..39500b0 --- /dev/null +++ b/GlitchyEditor/SandboxProject/Assets/Scenes/New Scene.scene @@ -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 + } + } + ] +} \ No newline at end of file diff --git a/GlitchyEditor/SandboxProject/Assets/Textures/DefaultNormal.png.ass b/GlitchyEditor/SandboxProject/Assets/Textures/DefaultNormal.png.ass index 1f70168..da1689f 100644 --- a/GlitchyEditor/SandboxProject/Assets/Textures/DefaultNormal.png.ass +++ b/GlitchyEditor/SandboxProject/Assets/Textures/DefaultNormal.png.ass @@ -9,8 +9,8 @@ AddressModeU = .Clamp, AddressModeV = .Clamp, AddressModeW = .Clamp, - MipMinLOD = -340282346638528859811704183484516925440, - MipMaxLOD = 340282346638528859811704183484516925440, + MipMinLOD = -3.40282347e+38, + MipMaxLOD = 3.40282347e+38, MaxAnisotropy = 1, BorderColor = { R = 1, @@ -19,5 +19,6 @@ A = 1 } } - } + }, + AssetHandle = 13149961070100324290 } \ No newline at end of file diff --git a/GlitchyEditor/SandboxProject/Assets/Textures/New Material.mat b/GlitchyEditor/SandboxProject/Assets/Textures/New Material.mat new file mode 100644 index 0000000..6c8d76d --- /dev/null +++ b/GlitchyEditor/SandboxProject/Assets/Textures/New Material.mat @@ -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 + } + } + ] +} \ No newline at end of file diff --git a/GlitchyEditor/SandboxProject/Assets/Textures/New Material.mat.ass b/GlitchyEditor/SandboxProject/Assets/Textures/New Material.mat.ass new file mode 100644 index 0000000..c11f03b --- /dev/null +++ b/GlitchyEditor/SandboxProject/Assets/Textures/New Material.mat.ass @@ -0,0 +1,5 @@ +{ + AssetLoader = "MaterialAssetLoader", + Config = (GlitchyEditor.Assets.ModelAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.ModelAssetLoaderConfig. Add [BonTarget] or force it */, + AssetHandle = 15093501654975430075 +} \ No newline at end of file diff --git a/GlitchyEditor/SandboxProject/Assets/Textures/RocketMaterial.mat.ass b/GlitchyEditor/SandboxProject/Assets/Textures/RocketMaterial.mat.ass index 4eb3f21..3af7309 100644 --- a/GlitchyEditor/SandboxProject/Assets/Textures/RocketMaterial.mat.ass +++ b/GlitchyEditor/SandboxProject/Assets/Textures/RocketMaterial.mat.ass @@ -1,4 +1,5 @@ { 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 } \ No newline at end of file diff --git a/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/nrm.png.ass b/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/nrm.png.ass index 1f70168..08a28ac 100644 --- a/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/nrm.png.ass +++ b/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/nrm.png.ass @@ -9,8 +9,8 @@ AddressModeU = .Clamp, AddressModeV = .Clamp, AddressModeW = .Clamp, - MipMinLOD = -340282346638528859811704183484516925440, - MipMaxLOD = 340282346638528859811704183484516925440, + MipMinLOD = -3.40282347e+38, + MipMaxLOD = 3.40282347e+38, MaxAnisotropy = 1, BorderColor = { R = 1, @@ -19,5 +19,6 @@ A = 1 } } - } + }, + AssetHandle = 5558090951492679375 } \ No newline at end of file diff --git a/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_albedo.png.ass b/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_albedo.png.ass index f0b6937..1799f14 100644 --- a/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_albedo.png.ass +++ b/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_albedo.png.ass @@ -1,21 +1,17 @@ { AssetLoader = "EditorTextureAssetLoader", Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){ - _generateMipMaps = true, - _isSrgb = true, _samplerStateDescription = { - MinFilter = .Anisotropic, - MagFilter = .Anisotropic, - MipFilter = .Anisotropic, - FilterMode = .Default, + MinFilter = .Linear, + MagFilter = .Linear, + MipFilter = .Linear, ComparisonFunction = .Never, - AddressModeU = .Wrap, - AddressModeV = .Wrap, - AddressModeW = .Wrap, - MipLODBias = 0, - MipMinLOD = 0, - MipMaxLOD = 3, - MaxAnisotropy = 16, + AddressModeU = .Clamp, + AddressModeV = .Clamp, + AddressModeW = .Clamp, + MipMinLOD = -3.40282347e+38, + MipMaxLOD = 3.40282347e+38, + MaxAnisotropy = 1, BorderColor = { R = 1, G = 1, @@ -23,5 +19,6 @@ A = 1 } } - } + }, + AssetHandle = 8153940681327484189 } \ No newline at end of file diff --git a/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_metallic.png.ass b/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_metallic.png.ass index b40adb4..ed84f80 100644 --- a/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_metallic.png.ass +++ b/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_metallic.png.ass @@ -2,15 +2,15 @@ AssetLoader = "EditorTextureAssetLoader", Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){ _samplerStateDescription = { - MinFilter = .Anisotropic, - MagFilter = .Anisotropic, - MipFilter = .Anisotropic, + MinFilter = .Linear, + MagFilter = .Linear, + MipFilter = .Linear, ComparisonFunction = .Never, - AddressModeU = .Wrap, - AddressModeV = .Wrap, + AddressModeU = .Clamp, + AddressModeV = .Clamp, AddressModeW = .Clamp, - MipMinLOD = -Infinity, - MipMaxLOD = Infinity, + MipMinLOD = -3.40282347e+38, + MipMaxLOD = 3.40282347e+38, MaxAnisotropy = 1, BorderColor = { R = 1, @@ -19,5 +19,6 @@ A = 1 } } - } + }, + AssetHandle = 13527693616095745667 } \ No newline at end of file diff --git a/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_normal.png.ass b/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_normal.png.ass index d366f65..389bd1e 100644 --- a/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_normal.png.ass +++ b/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_normal.png.ass @@ -1,20 +1,16 @@ { AssetLoader = "EditorTextureAssetLoader", Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){ - _generateMipMaps = false, - _isSrgb = false, _samplerStateDescription = { MinFilter = .Linear, MagFilter = .Linear, MipFilter = .Linear, - FilterMode = .Default, ComparisonFunction = .Never, - AddressModeU = .Wrap, - AddressModeV = .Wrap, + AddressModeU = .Clamp, + AddressModeV = .Clamp, AddressModeW = .Clamp, - MipLODBias = 2.5999999, - MipMinLOD = -Infinity, - MipMaxLOD = Infinity, + MipMinLOD = -3.40282347e+38, + MipMaxLOD = 3.40282347e+38, MaxAnisotropy = 1, BorderColor = { R = 1, @@ -23,5 +19,6 @@ A = 1 } } - } + }, + AssetHandle = 15822842502398518390 } \ No newline at end of file diff --git a/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_roughness.png.ass b/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_roughness.png.ass index dd43ef6..58f6fba 100644 --- a/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_roughness.png.ass +++ b/GlitchyEditor/SandboxProject/Assets/Textures/TestMat/rustediron2_roughness.png.ass @@ -1,18 +1,14 @@ { AssetLoader = "EditorTextureAssetLoader", Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){ - _generateMipMaps = false, - _isSrgb = true, _samplerStateDescription = { MinFilter = .Linear, MagFilter = .Linear, MipFilter = .Linear, - FilterMode = .Default, ComparisonFunction = .Never, - AddressModeU = .Wrap, - AddressModeV = .Wrap, + AddressModeU = .Clamp, + AddressModeV = .Clamp, AddressModeW = .Clamp, - MipLODBias = 0, MipMinLOD = -3.40282347e+38, MipMaxLOD = 3.40282347e+38, MaxAnisotropy = 1, @@ -23,5 +19,6 @@ A = 1 } } - } + }, + AssetHandle = 4141437666158293647 } \ No newline at end of file diff --git a/GlitchyEditor/SandboxProject/Assets/Textures/TestMaterial.mat.ass b/GlitchyEditor/SandboxProject/Assets/Textures/TestMaterial.mat.ass index 105823c..396ea54 100644 --- a/GlitchyEditor/SandboxProject/Assets/Textures/TestMaterial.mat.ass +++ b/GlitchyEditor/SandboxProject/Assets/Textures/TestMaterial.mat.ass @@ -1,4 +1,5 @@ { AssetLoader = "MaterialAssetLoader", - Config = (GlitchyEditor.Assets.ModelAssetLoaderConfig){} + Config = (GlitchyEditor.Assets.ModelAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.ModelAssetLoaderConfig. Add [BonTarget] or force it */, + AssetHandle = 9886473966965265328 } \ No newline at end of file diff --git a/GlitchyEditor/SandboxProject/Assets/Textures/White.png.ass b/GlitchyEditor/SandboxProject/Assets/Textures/White.png.ass index 1f70168..b917b5e 100644 --- a/GlitchyEditor/SandboxProject/Assets/Textures/White.png.ass +++ b/GlitchyEditor/SandboxProject/Assets/Textures/White.png.ass @@ -9,8 +9,8 @@ AddressModeU = .Clamp, AddressModeV = .Clamp, AddressModeW = .Clamp, - MipMinLOD = -340282346638528859811704183484516925440, - MipMaxLOD = 340282346638528859811704183484516925440, + MipMinLOD = -3.40282347e+38, + MipMaxLOD = 3.40282347e+38, MaxAnisotropy = 1, BorderColor = { R = 1, @@ -19,5 +19,6 @@ A = 1 } } - } + }, + AssetHandle = 14357509390762845070 } \ No newline at end of file diff --git a/GlitchyEditor/SandboxProject/Assets/Textures/rocket.dds.ass b/GlitchyEditor/SandboxProject/Assets/Textures/rocket.dds.ass index c350a18..a452178 100644 --- a/GlitchyEditor/SandboxProject/Assets/Textures/rocket.dds.ass +++ b/GlitchyEditor/SandboxProject/Assets/Textures/rocket.dds.ass @@ -1,7 +1,6 @@ { AssetLoader = "EditorTextureAssetLoader", Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){ - _isSrgb = true, _samplerStateDescription = { MinFilter = .Linear, MagFilter = .Linear, @@ -20,5 +19,6 @@ A = 1 } } - } + }, + AssetHandle = 5635535744559587375 } \ No newline at end of file diff --git a/GlitchyEditor/SandboxProject/Assets/Textures/rocket.png.ass b/GlitchyEditor/SandboxProject/Assets/Textures/rocket.png.ass index ffe1195..c410c33 100644 --- a/GlitchyEditor/SandboxProject/Assets/Textures/rocket.png.ass +++ b/GlitchyEditor/SandboxProject/Assets/Textures/rocket.png.ass @@ -1,15 +1,16 @@ { AssetLoader = "EditorTextureAssetLoader", Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){ - _isSrgb = true, _samplerStateDescription = { MinFilter = .Linear, + MagFilter = .Linear, + MipFilter = .Linear, ComparisonFunction = .Never, AddressModeU = .Clamp, AddressModeV = .Clamp, AddressModeW = .Clamp, - MipMinLOD = -340282346638528859811704183484516925440, - MipMaxLOD = 340282346638528859811704183484516925440, + MipMinLOD = -3.40282347e+38, + MipMaxLOD = 3.40282347e+38, MaxAnisotropy = 1, BorderColor = { R = 1, @@ -18,5 +19,6 @@ A = 1 } } - } + }, + AssetHandle = 10807131213209469263 } \ No newline at end of file diff --git a/GlitchyEditor/SandboxProject/Assets/Textures/test_skybox.dds.ass b/GlitchyEditor/SandboxProject/Assets/Textures/test_skybox.dds.ass index 2f2df14..7af563b 100644 --- a/GlitchyEditor/SandboxProject/Assets/Textures/test_skybox.dds.ass +++ b/GlitchyEditor/SandboxProject/Assets/Textures/test_skybox.dds.ass @@ -1,7 +1,6 @@ { AssetLoader = "EditorTextureAssetLoader", Config = (GlitchyEditor.Assets.EditorTextureAssetLoaderConfig){ - _isSrgb = true, _samplerStateDescription = { MinFilter = .Linear, MagFilter = .Linear, @@ -10,8 +9,8 @@ AddressModeU = .Clamp, AddressModeV = .Clamp, AddressModeW = .Clamp, - MipMinLOD = -Infinity, - MipMaxLOD = Infinity, + MipMinLOD = -3.40282347e+38, + MipMaxLOD = 3.40282347e+38, MaxAnisotropy = 1, BorderColor = { R = 1, @@ -20,5 +19,6 @@ A = 1 } } - } + }, + AssetHandle = 5889819840498959425 } \ No newline at end of file diff --git a/GlitchyEditor/resources/Shaders/ACES.hlsl.ass b/GlitchyEditor/resources/Shaders/ACES.hlsl.ass index 0dc97c1..be09759 100644 --- a/GlitchyEditor/resources/Shaders/ACES.hlsl.ass +++ b/GlitchyEditor/resources/Shaders/ACES.hlsl.ass @@ -1,4 +1,5 @@ { AssetLoader = "EffectAssetLoader", - Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} + Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */, + AssetHandle = 5360037389314667000 } \ No newline at end of file diff --git a/GlitchyEditor/resources/Shaders/ClearUInt.hlsl.ass b/GlitchyEditor/resources/Shaders/ClearUInt.hlsl.ass index 0dc97c1..903995b 100644 --- a/GlitchyEditor/resources/Shaders/ClearUInt.hlsl.ass +++ b/GlitchyEditor/resources/Shaders/ClearUInt.hlsl.ass @@ -1,4 +1,5 @@ { AssetLoader = "EffectAssetLoader", - Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} + Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */, + AssetHandle = 15597986932192091061 } \ No newline at end of file diff --git a/GlitchyEditor/resources/Shaders/GammaCorrect.hlsl.ass b/GlitchyEditor/resources/Shaders/GammaCorrect.hlsl.ass index 0dc97c1..9c9d439 100644 --- a/GlitchyEditor/resources/Shaders/GammaCorrect.hlsl.ass +++ b/GlitchyEditor/resources/Shaders/GammaCorrect.hlsl.ass @@ -1,4 +1,5 @@ { AssetLoader = "EffectAssetLoader", - Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} + Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */, + AssetHandle = 7082287996527160060 } \ No newline at end of file diff --git a/GlitchyEditor/resources/Shaders/GlitchyEngine.hlsl.ass b/GlitchyEditor/resources/Shaders/GlitchyEngine.hlsl.ass index ccd76fa..5933f91 100644 --- a/GlitchyEditor/resources/Shaders/GlitchyEngine.hlsl.ass +++ b/GlitchyEditor/resources/Shaders/GlitchyEngine.hlsl.ass @@ -1,4 +1,5 @@ { 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 } \ No newline at end of file diff --git a/GlitchyEditor/resources/Shaders/LightingFunctions.hlsl.ass b/GlitchyEditor/resources/Shaders/LightingFunctions.hlsl.ass index 0dc97c1..8d10f78 100644 --- a/GlitchyEditor/resources/Shaders/LightingFunctions.hlsl.ass +++ b/GlitchyEditor/resources/Shaders/LightingFunctions.hlsl.ass @@ -1,4 +1,5 @@ { AssetLoader = "EffectAssetLoader", - Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} + Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */, + AssetHandle = 17917061300990589192 } \ No newline at end of file diff --git a/GlitchyEditor/resources/Shaders/PBR.hlsl.ass b/GlitchyEditor/resources/Shaders/PBR.hlsl.ass index 0dc97c1..24f70b3 100644 --- a/GlitchyEditor/resources/Shaders/PBR.hlsl.ass +++ b/GlitchyEditor/resources/Shaders/PBR.hlsl.ass @@ -1,4 +1,5 @@ { AssetLoader = "EffectAssetLoader", - Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} + Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */, + AssetHandle = 8336560834161185660 } \ No newline at end of file diff --git a/GlitchyEditor/resources/Shaders/RenderTargetGroupViewer.hlsl.ass b/GlitchyEditor/resources/Shaders/RenderTargetGroupViewer.hlsl.ass index ccd76fa..8fe571b 100644 --- a/GlitchyEditor/resources/Shaders/RenderTargetGroupViewer.hlsl.ass +++ b/GlitchyEditor/resources/Shaders/RenderTargetGroupViewer.hlsl.ass @@ -1,4 +1,5 @@ { 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 } \ No newline at end of file diff --git a/GlitchyEditor/resources/Shaders/ShaderHelpers.hlsl.ass b/GlitchyEditor/resources/Shaders/ShaderHelpers.hlsl.ass index 0dc97c1..77baf62 100644 --- a/GlitchyEditor/resources/Shaders/ShaderHelpers.hlsl.ass +++ b/GlitchyEditor/resources/Shaders/ShaderHelpers.hlsl.ass @@ -1,4 +1,5 @@ { AssetLoader = "EffectAssetLoader", - Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} + Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */, + AssetHandle = 13663488523997149295 } \ No newline at end of file diff --git a/GlitchyEditor/resources/Shaders/SimpleTonemapping.hlsl.ass b/GlitchyEditor/resources/Shaders/SimpleTonemapping.hlsl.ass index 0dc97c1..9c1997c 100644 --- a/GlitchyEditor/resources/Shaders/SimpleTonemapping.hlsl.ass +++ b/GlitchyEditor/resources/Shaders/SimpleTonemapping.hlsl.ass @@ -1,4 +1,5 @@ { AssetLoader = "EffectAssetLoader", - Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} + Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */, + AssetHandle = 9450907808112906391 } \ No newline at end of file diff --git a/GlitchyEditor/resources/Shaders/circlebatch.hlsl.ass b/GlitchyEditor/resources/Shaders/circlebatch.hlsl.ass index 0dc97c1..509a3d2 100644 --- a/GlitchyEditor/resources/Shaders/circlebatch.hlsl.ass +++ b/GlitchyEditor/resources/Shaders/circlebatch.hlsl.ass @@ -1,4 +1,5 @@ { AssetLoader = "EffectAssetLoader", - Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} + Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */, + AssetHandle = 4086392147967882920 } \ No newline at end of file diff --git a/GlitchyEditor/resources/Shaders/lineShader.hlsl.ass b/GlitchyEditor/resources/Shaders/lineShader.hlsl.ass index 0dc97c1..4bdf7d8 100644 --- a/GlitchyEditor/resources/Shaders/lineShader.hlsl.ass +++ b/GlitchyEditor/resources/Shaders/lineShader.hlsl.ass @@ -1,4 +1,5 @@ { AssetLoader = "EffectAssetLoader", - Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} + Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */, + AssetHandle = 3929078354809894230 } \ No newline at end of file diff --git a/GlitchyEditor/resources/Shaders/linebatch.hlsl.ass b/GlitchyEditor/resources/Shaders/linebatch.hlsl.ass index ccd76fa..95fd11e 100644 --- a/GlitchyEditor/resources/Shaders/linebatch.hlsl.ass +++ b/GlitchyEditor/resources/Shaders/linebatch.hlsl.ass @@ -1,4 +1,5 @@ { 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 } \ No newline at end of file diff --git a/GlitchyEditor/resources/Shaders/msdfShader.hlsl.ass b/GlitchyEditor/resources/Shaders/msdfShader.hlsl.ass index 0dc97c1..44a0563 100644 --- a/GlitchyEditor/resources/Shaders/msdfShader.hlsl.ass +++ b/GlitchyEditor/resources/Shaders/msdfShader.hlsl.ass @@ -1,4 +1,5 @@ { AssetLoader = "EffectAssetLoader", - Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} + Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */, + AssetHandle = 17001330646928133106 } \ No newline at end of file diff --git a/GlitchyEditor/resources/Shaders/myEffect.hlsl.ass b/GlitchyEditor/resources/Shaders/myEffect.hlsl.ass index 0dc97c1..2b6f675 100644 --- a/GlitchyEditor/resources/Shaders/myEffect.hlsl.ass +++ b/GlitchyEditor/resources/Shaders/myEffect.hlsl.ass @@ -1,4 +1,5 @@ { AssetLoader = "EffectAssetLoader", - Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} + Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */, + AssetHandle = 2913314865396454015 } \ No newline at end of file diff --git a/GlitchyEditor/resources/Shaders/simpleLight.hlsl.ass b/GlitchyEditor/resources/Shaders/simpleLight.hlsl.ass index 0dc97c1..2451690 100644 --- a/GlitchyEditor/resources/Shaders/simpleLight.hlsl.ass +++ b/GlitchyEditor/resources/Shaders/simpleLight.hlsl.ass @@ -1,4 +1,5 @@ { AssetLoader = "EffectAssetLoader", - Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} + Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */, + AssetHandle = 9047671870217222298 } \ No newline at end of file diff --git a/GlitchyEditor/resources/Shaders/spritebatch.hlsl.ass b/GlitchyEditor/resources/Shaders/spritebatch.hlsl.ass index 0dc97c1..5657c97 100644 --- a/GlitchyEditor/resources/Shaders/spritebatch.hlsl.ass +++ b/GlitchyEditor/resources/Shaders/spritebatch.hlsl.ass @@ -1,4 +1,5 @@ { AssetLoader = "EffectAssetLoader", - Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} + Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */, + AssetHandle = 14473519405124742382 } \ No newline at end of file diff --git a/GlitchyEditor/resources/Shaders/textureViewerShader.hlsl.ass b/GlitchyEditor/resources/Shaders/textureViewerShader.hlsl.ass index 0dc97c1..f704c28 100644 --- a/GlitchyEditor/resources/Shaders/textureViewerShader.hlsl.ass +++ b/GlitchyEditor/resources/Shaders/textureViewerShader.hlsl.ass @@ -1,4 +1,5 @@ { AssetLoader = "EffectAssetLoader", - Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){} + Config = (GlitchyEditor.Assets.EffectAssetLoaderConfig){}/* No reflection data for GlitchyEditor.Assets.EffectAssetLoaderConfig. Add [BonTarget] or force it */, + AssetHandle = 10276018270467402814 } \ No newline at end of file diff --git a/GlitchyEditor/resources/Textures/EditorIcons.dds.ass b/GlitchyEditor/resources/Textures/EditorIcons.dds.ass index 94df200..0a04a8a 100644 --- a/GlitchyEditor/resources/Textures/EditorIcons.dds.ass +++ b/GlitchyEditor/resources/Textures/EditorIcons.dds.ass @@ -19,5 +19,6 @@ A = 1 } } - } + }, + AssetHandle = 16828117378770367285 } \ No newline at end of file diff --git a/GlitchyEditor/src/AssetFile.bf b/GlitchyEditor/src/AssetFile.bf index 75c814e..b9834df 100644 --- a/GlitchyEditor/src/AssetFile.bf +++ b/GlitchyEditor/src/AssetFile.bf @@ -17,6 +17,9 @@ class AssetConfig [BonInclude] public AssetLoaderConfig Config ~ delete _; + + [BonInclude] + public AssetHandle AssetHandle = .Invalid; } class AssetFile @@ -79,11 +82,19 @@ class AssetFile } } + private void GenerateAssetHandle() + { + _assetConfig.AssetHandle = .(); + } + private void CreateDefaultAssetLoader() { String fileExtension = Path.GetExtension(_path, .. scope .()); _assetConfig = new AssetConfig(); + + GenerateAssetHandle(); + var assetLoader = _contentManager.GetDefaultAssetLoader(fileExtension); // We don't have a loader -> we don't need a config @@ -96,6 +107,7 @@ class AssetFile _assetConfig.Config = assetLoader?.GetDefaultConfig(); _assetConfig.Config?.[Friend]_changed = true; + SaveAssetConfig(); } diff --git a/GlitchyEditor/src/Assets/AssetHierarchy.bf b/GlitchyEditor/src/Assets/AssetHierarchy.bf index 6d1faff..aaf3952 100644 --- a/GlitchyEditor/src/Assets/AssetHierarchy.bf +++ b/GlitchyEditor/src/Assets/AssetHierarchy.bf @@ -5,6 +5,7 @@ using System; using System.Collections; using System.IO; using System.Linq; +using GlitchyEngine.Content; namespace GlitchyEditor.Assets; @@ -96,6 +97,7 @@ class AssetHierarchy internal TreeNode _assetsDirectoryNode = null; private append Dictionary> _pathToAssetNode = .(); private append Dictionary> _identifierToAssetNode = .(); + private append Dictionary> _handleToAssetNode = .(); private append String _resourcesDirectory = .(); 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) { ResourcesDirectory = fileName; @@ -206,6 +209,7 @@ class AssetHierarchy Update(); } + /// Sets path to the directory that contains the game assets. public void SetAssetsDirectory(StringView fileName) { AssetsDirectory = fileName; @@ -225,7 +229,6 @@ class AssetHierarchy return; } - AssetNode assetNode = new AssetNode(); assetNode.Path = new String(AssetsDirectory); assetNode.Name = new String(); @@ -239,7 +242,6 @@ class AssetHierarchy Log.EngineLogger.Trace($"Created directory node for: \"{AssetsDirectory}\""); - _fileSystemDirty = true; SetupFileSystemWatcher(); @@ -297,7 +299,7 @@ class AssetHierarchy 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. /// @remarks Do not hold a reference to the TreeNode because it can become invalid when the file hierarchy changes. public Result> GetNodeFromIdentifier(StringView identifier) @@ -310,6 +312,19 @@ class AssetHierarchy 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> GetNodeFromAssetHandle(AssetHandle assetHandle) + { + if (_handleToAssetNode.TryGetValue(assetHandle, let treeNode)) + { + return treeNode; + } + + return .Err; + } + public bool FileExists(StringView filePath) { return _pathToAssetNode.ContainsKey(filePath); @@ -399,6 +414,8 @@ class AssetHierarchy //GrabSubAssets(node); HandleFile(treeNode.Value); + _handleToAssetNode.Add(assetNode.AssetFile.AssetConfig.AssetHandle, treeNode); + Log.EngineLogger.Trace($"Created file node for: \"{assetNode.Path}\""); } } diff --git a/GlitchyEditor/src/Assets/MaterialAssetLoader.bf b/GlitchyEditor/src/Assets/MaterialAssetLoader.bf index b64c1f3..afec1cb 100644 --- a/GlitchyEditor/src/Assets/MaterialAssetLoader.bf +++ b/GlitchyEditor/src/Assets/MaterialAssetLoader.bf @@ -103,7 +103,10 @@ class MaterialAssetPropertiesEditor : AssetPropertiesEditor { for (let texture in effect.Textures) { - ImGui.Button(texture.key); + ImGui.TextUnformatted(texture.key); + ImGui.SameLine(); + + ImGui.Button("Texture"); if (ImGui.BeginDragDropTarget()) { @@ -315,7 +318,8 @@ class MaterialFile { public String Effect ~ delete _; - public Dictionary Textures ~ DeleteDictionaryAndKeysAndValues!(_); + //public Dictionary Textures ~ DeleteDictionaryAndKeysAndValues!(_); + public Dictionary> Textures ~ DeleteDictionaryAndKeys!(_); public Dictionary Variables ~ { if (_ != null) @@ -417,14 +421,13 @@ class MaterialAssetLoader : IAssetLoader, IAssetSaver //, IReloadingAssetLoader Material material = new Material(fx); - for (let (slotName, textureIdentifier) in materialFile.Textures) + for (let (slotName, textureHandle) in materialFile.Textures) { - - AssetHandle texture = contentManager.LoadAsset(textureIdentifier); + AssetHandle texture = contentManager.LoadAsset(textureHandle); if (texture.IsInvalid) { - Log.EngineLogger.Error($"Failed to load texture \"{textureIdentifier}\"."); + Log.EngineLogger.Error($"Failed to load texture \"{textureHandle}\"."); } material.SetTexture(slotName, texture); @@ -475,9 +478,7 @@ class MaterialAssetLoader : IAssetLoader, IAssetSaver //, IReloadingAssetLoader for (let (slotName, texture) in material.[Friend]_textures) { - Texture textureAsset = texture.Handle.Get(); - - materialFile.Textures.Add(new String(slotName), new String(textureAsset?.Identifier ?? "")); + materialFile.Textures.Add(new String(slotName), texture.Handle); } Effect effect = material.Effect; diff --git a/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf b/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf index aaa269b..d61e959 100644 --- a/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf +++ b/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf @@ -1064,7 +1064,7 @@ namespace GlitchyEditor.EditWindows GeometryBinding mesh = meshComponent.Mesh; - StringView identifier = mesh?.Identifier ?? "None"; + StringView identifier = mesh?.Identifier ?? (meshComponent.Mesh.IsValid ? "" : "None"); ImGui.Button(identifier.ToScopeCStr!()); if (ImGui.BeginDragDropTarget()) diff --git a/GlitchyEditor/src/EditWindows/EditorViewportWindow.bf b/GlitchyEditor/src/EditWindows/EditorViewportWindow.bf index f1abfde..9ec068f 100644 --- a/GlitchyEditor/src/EditWindows/EditorViewportWindow.bf +++ b/GlitchyEditor/src/EditWindows/EditorViewportWindow.bf @@ -141,8 +141,18 @@ namespace GlitchyEditor.EditWindows if (payload != null) { - StringView path = .((char8*)payload.Data, (int)payload.DataSize); - _editor.RequestOpenScene(this, path); + StringView assetIdentifier = .((char8*)payload.Data, (int)payload.DataSize); + + 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(); diff --git a/GlitchyEditor/src/EditorContentManager.bf b/GlitchyEditor/src/EditorContentManager.bf index e5a9ce4..c6c1d2d 100644 --- a/GlitchyEditor/src/EditorContentManager.bf +++ b/GlitchyEditor/src/EditorContentManager.bf @@ -221,7 +221,10 @@ class EditorContentManager : IContentManager { Asset asset = null; - _handleToAsset.TryGetValue(handle, out asset); + if (!_handleToAsset.TryGetValue(handle, out asset)) + { + LoadAsset(handle); + } if (var placeholder = asset as PlaceholderAsset) { @@ -339,7 +342,92 @@ class EditorContentManager : IContentManager private append List<(PlaceholderAsset placeholder, Asset newAsset)> _finishedEntries = .(); 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> 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) { Debug.Profiler.ProfileResourceFunction!(); @@ -347,10 +435,31 @@ class EditorContentManager : IContentManager // It's valid to request no entity, but no entity is obviously invalid. if (identifier.IsWhiteSpace) return .Invalid; - + + // We allow backslashes as well as forward slashes. Some Path stuff like /./ is also allowed. String fixedIdentifier = scope String(identifier); 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> resultNode = AssetHierarchy.GetNodeFromIdentifier(fixedIdentifier); + + //resultNode. + + /* if (_identiferToHandle.TryGetValue(fixedIdentifier, let asset)) return asset; @@ -411,7 +520,24 @@ class EditorContentManager : IContentManager } 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. loadedAsset.ReleaseRef(); @@ -420,7 +546,7 @@ class EditorContentManager : IContentManager file.[Friend]_loadedAsset = loadedAsset; - return handle; + return handle;*/ } private void AsyncLoadAsset(PlaceholderAsset placeholder, String filePath, IAssetLoader assetLoader, AssetFile file, String resourceName, String subassetName) diff --git a/GlitchyEditor/src/EditorLayer.bf b/GlitchyEditor/src/EditorLayer.bf index d2cb491..ee99c85 100644 --- a/GlitchyEditor/src/EditorLayer.bf +++ b/GlitchyEditor/src/EditorLayer.bf @@ -235,10 +235,7 @@ namespace GlitchyEditor _editor.EditorSceneRenderer = _editorSceneRenderer; _editor.RequestOpenScene.Add(new (s, fileName) => { - String fullName = scope .(); - Path.Combine(fullName, _currentProject.AssetsFolder, fileName); - - LoadSceneFile(fullName); + LoadSceneFile(fileName); }); } @@ -1105,7 +1102,7 @@ namespace GlitchyEditor private void ShowOpenRecentSceneMenu() { - if (_currentProject == null) + if (_currentProject == null || _currentProject.UserSettings.RecentScenes == null) return; int i = 0; diff --git a/GlitchyEngine/src/Content/Asset.bf b/GlitchyEngine/src/Content/Asset.bf index 067d6b0..d7b7bd4 100644 --- a/GlitchyEngine/src/Content/Asset.bf +++ b/GlitchyEngine/src/Content/Asset.bf @@ -50,16 +50,50 @@ abstract class Asset : RefCounter static void AssetSerialize(BonWriter writer, ValueView value, BonEnvironment environment, SerializeValueState state) { Log.EngineLogger.Assert(value.type == typeof(Asset)); + + var handle = value.Get()._handle; + Serialize.Value(writer, handle, environment); - let identifier = value.Get().Identifier; - writer.String(identifier); + + //AssetHandle.[Friend]AssetSerialize(writer, ValueView(typeof(AssetHandle), &handle), environment, state); + + //writer.String(identifier); } static Result AssetDeserialize(BonReader reader, ValueView value, BonEnvironment environment, DeserializeValueState state) { Log.EngineLogger.Assert(value.type == typeof(Asset)); - String identifier = scope .(); + Try!(Deserialize.Value(reader, let handle, environment)); + + //String identifier = scope .(); + + //Deserialize.String!(reader, ref identifier, environment); + + AssetHandle loadedHandle = Content.LoadAsset(handle); + + if (loadedHandle == .Invalid) + { + value.Assign(null); + return .Ok; + } + + Asset asset = Content.GetAsset(handle); + + if (asset != null) + { + Asset oldAsset = value.Get(); + 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); @@ -84,7 +118,7 @@ abstract class Asset : RefCounter else { Deserialize.Error!("Invalid resource path", reader, value.type); - } + }*/ } //gBonEnv.typeHandlers.Add(typeof(Resource<>), diff --git a/GlitchyEngine/src/Content/AssetHandle.bf b/GlitchyEngine/src/Content/AssetHandle.bf index 55a6d0f..e96a66d 100644 --- a/GlitchyEngine/src/Content/AssetHandle.bf +++ b/GlitchyEngine/src/Content/AssetHandle.bf @@ -50,6 +50,11 @@ struct AssetHandle : IHashable { Log.EngineLogger.Assert(value.type == typeof(AssetHandle)); + var uuid = value.Get()._uuid; + Serialize.Value(writer, uuid, environment); + + /*Log.EngineLogger.Assert(value.type == typeof(AssetHandle)); + AssetHandle handle = value.Get(); if (handle.IsInvalid) @@ -58,20 +63,24 @@ struct AssetHandle : IHashable { let identifier = handle.Get().Identifier; writer.String(identifier); - } + }*/ } static Result AssetDeserialize(BonReader reader, ValueView value, BonEnvironment environment, DeserializeValueState state) { Log.EngineLogger.Assert(value.type == typeof(AssetHandle)); - String identifier = scope .(); + Try!(Deserialize.Value(reader, let uuid, environment)); + + value.Assign(AssetHandle(uuid)); + + /*String identifier = scope .(); Deserialize.String!(reader, ref identifier, environment); AssetHandle handle = Content.LoadAsset(identifier); - value.Assign(handle); + value.Assign(handle);*/ return .Ok; } @@ -314,29 +323,18 @@ struct AssetHandle where T : Asset static void AssetSerialize(BonWriter writer, ValueView value, BonEnvironment environment, SerializeValueState state) { Log.EngineLogger.Assert(value.type == typeof(AssetHandle)); - + AssetHandle handle = value.Get>(); - - if (handle.IsInvalid) - writer.String(""); - else - { - let identifier = handle.Get().Identifier; - writer.String(identifier); - } + Serialize.Value(writer, handle, environment); } static Result AssetDeserialize(BonReader reader, ValueView value, BonEnvironment environment, DeserializeValueState state) { Log.EngineLogger.Assert(value.type == typeof(AssetHandle)); - - String identifier = scope .(); - - Deserialize.String!(reader, ref identifier, environment); - - AssetHandle handle = Content.LoadAsset(identifier); - value.Assign>(handle); + Try!(Deserialize.Value(reader, let handle, environment)); + + value.Assign(AssetHandle(handle)); return .Ok; } diff --git a/GlitchyEngine/src/Content/ContentManager.bf b/GlitchyEngine/src/Content/ContentManager.bf index 0a83026..c813f82 100644 --- a/GlitchyEngine/src/Content/ContentManager.bf +++ b/GlitchyEngine/src/Content/ContentManager.bf @@ -67,6 +67,19 @@ namespace GlitchyEngine.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. 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. 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. Asset GetAsset(AssetHandle handle) {