diff --git a/GlitchyEditor/src/Assets/AssetPropertiesEditor.bf b/GlitchyEditor/src/Assets/AssetPropertiesEditor.bf index 96e6535..794f4d8 100644 --- a/GlitchyEditor/src/Assets/AssetPropertiesEditor.bf +++ b/GlitchyEditor/src/Assets/AssetPropertiesEditor.bf @@ -1,5 +1,8 @@ +using System; + namespace GlitchyEditor.Assets; +[Obsolete] abstract class AssetPropertiesEditor { private AssetFile _asset; diff --git a/GlitchyEditor/src/Assets/Importers/MaterialImporter.bf b/GlitchyEditor/src/Assets/Importers/MaterialImporter.bf new file mode 100644 index 0000000..0429f9c --- /dev/null +++ b/GlitchyEditor/src/Assets/Importers/MaterialImporter.bf @@ -0,0 +1,115 @@ +using System; +using System.Collections; +using GlitchyEngine.Content; +using GlitchyEngine.Renderer; +using Bon; +using GlitchyEngine.Math; +using System.IO; + +namespace GlitchyEditor.Assets.Importers; + +[BonTarget] +class NewMaterialFile : ImportedResource +{ + public AssetHandle Effect; + + public Dictionary> Textures = new .() ~ DeleteDictionaryAndKeys!(_); + public Dictionary Constants = new .() ~ DeleteDictionaryAndKeys!(_); + + public this(AssetIdentifier ownAssetIdentifier) : base(ownAssetIdentifier) + { + + } +} + + +[BonTarget] +public enum MaterialVariableValue +{ + case bool(bool Value); + case bool2(bool2 Value); + case bool3(bool3 Value); + case bool4(bool4 Value); + case int(int Value); + case int2(int2 Value); + case int3(int3 Value); + case int4(int4 Value); + case uint(uint Value); + case uint2(uint2 Value); + case uint3(uint3 Value); + case uint4(uint4 Value); + case Float(float Value); + case Float2(float2 Value); + case Float3(float3 Value); + case Float4(float4 Value); + case Half(half Value); + case Half2(half2 Value); + case Half3(half3 Value); + case Half4(half4 Value); + case ColorRGB(ColorRGB Value); + case ColorRGBA(ColorRGBA Value); + case None; + + /*static this() + { + gBonEnv.typeHandlers.Add(typeof(Self), + ((.)new => VariableValueSerialize, (.)new => VariableValueDeserialize)); + } + + static void VariableValueSerialize(BonWriter writer, ValueView value, BonEnvironment env) + { + Log.EngineLogger.Assert(value.type == typeof(Self)); + + let variableValue = value.Get(); + + writer.Type(variableValue) + using (writer.ObjectBlock()) + { + Serialize.Value(writer, nameof(MaterialFile.Effect), materialFile.Effect, env); + Serialize.Value(writer, nameof(MaterialFile.Textures), materialFile.Textures, env); + + + } + } + + static Result VariableValueDeserialize(BonReader reader, ValueView val, BonEnvironment env) + { + return .Ok; + }*/ +} + + +class MaterialImporter: IAssetImporter +{ + private static readonly List _fileExtensions = new .(){".mat"} ~ delete _; + + public static List FileExtensions => _fileExtensions; + + public static Type ProcessedAssetType => typeof(NewMaterialFile); + + public AssetImporterConfig CreateDefaultConfig() + { + return new AssetImporterConfig(); + } + + public Result Import(StringView fullFileName, AssetIdentifier assetIdentifier, AssetConfig config) + { + NewMaterialFile material = new .(new AssetIdentifier(assetIdentifier.FullIdentifier)); + + defer + { + if (@return case .Err) + { + delete material; + } + } + + String fullText = scope .(); + Try!(File.ReadAllText(fullFileName, fullText, true)); + + Try!(Bon.Deserialize(ref material, fullText)); + + return material; + } + +} \ No newline at end of file diff --git a/GlitchyEditor/src/Assets/Processors/MaterialProcessor.bf b/GlitchyEditor/src/Assets/Processors/MaterialProcessor.bf new file mode 100644 index 0000000..d908a5a --- /dev/null +++ b/GlitchyEditor/src/Assets/Processors/MaterialProcessor.bf @@ -0,0 +1,68 @@ +using System; +using System.Collections; +using GlitchyEditor.Assets.Importers; +using GlitchyEngine.Renderer; +using GlitchyEngine; +using GlitchyEngine.Content; + +namespace GlitchyEditor.Assets.Processors; + +class ProcessedMaterial : ProcessedResource +{ + private Dictionary _bufferData = new .() ~ DeleteDictionaryAndKeysAndValues!(_); + + public override AssetType AssetType => .Material; + + public this(AssetIdentifier ownAssetIdentifier, AssetHandle assetHandle) : base(ownAssetIdentifier, assetHandle) + { + + } + + public uint8[] CloneBuffer(ConstantBuffer cBuffer) + { + String name = new String(cBuffer.Name); + //uint8[] data = cBuffer. + + return null; + } +} + +class MaterialProcessor : IAssetProcessor +{ + public AssetProcessorConfig CreateDefaultConfig() + { + return new AssetProcessorConfig(); + } + + public static Type ProcessedAssetType => typeof(NewMaterialFile) + + public Result Process(ImportedResource importedResource, AssetConfig config, List outProcessedResources) + { + NewMaterialFile importedMaterial = importedResource as NewMaterialFile; + if (importedMaterial == null) + { + Log.EngineLogger.Error($"Expected type {nameof(NewMaterialFile)} but received {importedResource.GetType()} instead."); + return .Err; + } + + Effect effect = Content.GetAsset(importedMaterial.Effect, blocking: true); + + ProcessedMaterial processedMaterial = new .(new AssetIdentifier(importedMaterial.AssetIdentifier), config.AssetHandle); + + for (let buffer in effect.Buffers) + { + ConstantBuffer cBuffer = buffer.Buffer as ConstantBuffer; + + if (cBuffer == null) + { + + } + + processedMaterial.CloneBuffer(cBuffer); + } + + // Create buffers + + return default; + } +} \ No newline at end of file diff --git a/GlitchyEditor/src/EditorContentManager.bf b/GlitchyEditor/src/EditorContentManager.bf index 89356b6..5479a50 100644 --- a/GlitchyEditor/src/EditorContentManager.bf +++ b/GlitchyEditor/src/EditorContentManager.bf @@ -362,13 +362,13 @@ class EditorContentManager : IContentManager return _identiferToHandle.ContainsKey(identifier); } - public Asset GetAsset(Type assetType, AssetHandle handle) + public Asset GetAsset(Type assetType, AssetHandle handle, bool blocking = false) { Asset asset = null; if (!_handleToAsset.TryGetValue(handle, out asset)) { - LoadAsset(handle); + LoadAsset(handle, blocking); } if (var placeholder = asset as PlaceholderAsset) diff --git a/GlitchyEngine/src/Content/AssetType.bf b/GlitchyEngine/src/Content/AssetType.bf index 465c9ec..5f0da3c 100644 --- a/GlitchyEngine/src/Content/AssetType.bf +++ b/GlitchyEngine/src/Content/AssetType.bf @@ -5,5 +5,6 @@ enum AssetType : uint16 Unknown, Texture, Sprite, - Shader + Shader, + Material } \ No newline at end of file diff --git a/GlitchyEngine/src/Content/ContentManager.bf b/GlitchyEngine/src/Content/ContentManager.bf index 5906740..361b131 100644 --- a/GlitchyEngine/src/Content/ContentManager.bf +++ b/GlitchyEngine/src/Content/ContentManager.bf @@ -94,27 +94,27 @@ namespace GlitchyEngine.Content } /// Loads the specified asset with the given contentManager or the current applications content manager. - public static T GetAsset(AssetHandle handle, IContentManager contentManager = null) where T : Asset + public static T GetAsset(AssetHandle handle, IContentManager contentManager = null, bool blocking = false) where T : Asset { var contentManager; if (contentManager == null) contentManager = Application.Get().ContentManager; - Asset asset = contentManager.GetAsset(typeof(T), handle); + Asset asset = contentManager.GetAsset(typeof(T), handle, blocking); return (T)asset; } /// Loads the specified asset with the given contentManager or the current applications content manager. - public static Asset GetAsset(AssetHandle handle, IContentManager contentManager = null) + public static Asset GetAsset(AssetHandle handle, IContentManager contentManager = null, bool blocking = false) { var contentManager; if (contentManager == null) contentManager = Application.Instance.ContentManager; - Asset asset = contentManager.GetAsset(null, handle); + Asset asset = contentManager.GetAsset(null, handle, blocking); return asset; } @@ -142,20 +142,25 @@ namespace GlitchyEngine.Content interface IContentManager { - /// Loads the Asset with the given handle and returns the handle. + /// Loads the Asset with the given identifier and returns the handle. + /// @param assetIdentifier The identifier of the asset to load. + /// @param blocking If false, the AssetHandle might represent a placeholder until the asset is finished loading. + /// If true, LoadAsset will wait until the Asset is loaded and the handle represents the actual asset. + /// @return An AssetHandle representing the Asset identifierd by the specified assetIdentifier or a placeholder. + /// If the asset doesn't exist or loading failed, the Handle will represent an error-placeholder. 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) + Asset GetAsset(AssetHandle handle, bool blocking = false) { - return GetAsset(null, handle); + return GetAsset(null, handle, blocking); } /// Returns the asset for the given handle or the default asset of the given type. - Asset GetAsset(Type assetType, AssetHandle handle); + Asset GetAsset(Type assetType, AssetHandle handle, bool blocking = false); /// The content manager will manage the asset (e.g. provide it when LoadAsset is called with the assets identifier) AssetHandle ManageAsset(Asset asset);