mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
Start of new materials, disable async asset loading
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
namespace GlitchyEditor.Assets;
|
namespace GlitchyEditor.Assets;
|
||||||
|
|
||||||
|
[Obsolete]
|
||||||
abstract class AssetPropertiesEditor
|
abstract class AssetPropertiesEditor
|
||||||
{
|
{
|
||||||
private AssetFile _asset;
|
private AssetFile _asset;
|
||||||
|
|||||||
@@ -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> Effect;
|
||||||
|
|
||||||
|
public Dictionary<String, AssetHandle<Texture>> Textures = new .() ~ DeleteDictionaryAndKeys!(_);
|
||||||
|
public Dictionary<String, MaterialVariableValue> 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<Self>();
|
||||||
|
|
||||||
|
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<void> VariableValueDeserialize(BonReader reader, ValueView val, BonEnvironment env)
|
||||||
|
{
|
||||||
|
return .Ok;
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class MaterialImporter: IAssetImporter
|
||||||
|
{
|
||||||
|
private static readonly List<StringView> _fileExtensions = new .(){".mat"} ~ delete _;
|
||||||
|
|
||||||
|
public static List<StringView> FileExtensions => _fileExtensions;
|
||||||
|
|
||||||
|
public static Type ProcessedAssetType => typeof(NewMaterialFile);
|
||||||
|
|
||||||
|
public AssetImporterConfig CreateDefaultConfig()
|
||||||
|
{
|
||||||
|
return new AssetImporterConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result<ImportedResource> 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<NewMaterialFile>(ref material, fullText));
|
||||||
|
|
||||||
|
return material;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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<String, uint8[]> _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<void> Process(ImportedResource importedResource, AssetConfig config, List<ProcessedResource> 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<Effect>(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -362,13 +362,13 @@ class EditorContentManager : IContentManager
|
|||||||
return _identiferToHandle.ContainsKey(identifier);
|
return _identiferToHandle.ContainsKey(identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Asset GetAsset(Type assetType, AssetHandle handle)
|
public Asset GetAsset(Type assetType, AssetHandle handle, bool blocking = false)
|
||||||
{
|
{
|
||||||
Asset asset = null;
|
Asset asset = null;
|
||||||
|
|
||||||
if (!_handleToAsset.TryGetValue(handle, out asset))
|
if (!_handleToAsset.TryGetValue(handle, out asset))
|
||||||
{
|
{
|
||||||
LoadAsset(handle);
|
LoadAsset(handle, blocking);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (var placeholder = asset as PlaceholderAsset)
|
if (var placeholder = asset as PlaceholderAsset)
|
||||||
|
|||||||
@@ -5,5 +5,6 @@ enum AssetType : uint16
|
|||||||
Unknown,
|
Unknown,
|
||||||
Texture,
|
Texture,
|
||||||
Sprite,
|
Sprite,
|
||||||
Shader
|
Shader,
|
||||||
|
Material
|
||||||
}
|
}
|
||||||
@@ -94,27 +94,27 @@ namespace GlitchyEngine.Content
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 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 T GetAsset<T>(AssetHandle handle, IContentManager contentManager = null) where T : Asset
|
public static T GetAsset<T>(AssetHandle handle, IContentManager contentManager = null, bool blocking = false) where T : Asset
|
||||||
{
|
{
|
||||||
var contentManager;
|
var contentManager;
|
||||||
|
|
||||||
if (contentManager == null)
|
if (contentManager == null)
|
||||||
contentManager = Application.Get().ContentManager;
|
contentManager = Application.Get().ContentManager;
|
||||||
|
|
||||||
Asset asset = contentManager.GetAsset(typeof(T), handle);
|
Asset asset = contentManager.GetAsset(typeof(T), handle, blocking);
|
||||||
|
|
||||||
return (T)asset;
|
return (T)asset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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 Asset GetAsset(AssetHandle handle, IContentManager contentManager = null)
|
public static Asset GetAsset(AssetHandle handle, IContentManager contentManager = null, bool blocking = false)
|
||||||
{
|
{
|
||||||
var contentManager;
|
var contentManager;
|
||||||
|
|
||||||
if (contentManager == null)
|
if (contentManager == null)
|
||||||
contentManager = Application.Instance.ContentManager;
|
contentManager = Application.Instance.ContentManager;
|
||||||
|
|
||||||
Asset asset = contentManager.GetAsset(null, handle);
|
Asset asset = contentManager.GetAsset(null, handle, blocking);
|
||||||
|
|
||||||
return asset;
|
return asset;
|
||||||
}
|
}
|
||||||
@@ -142,20 +142,25 @@ namespace GlitchyEngine.Content
|
|||||||
|
|
||||||
interface IContentManager
|
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);
|
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.
|
/// 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);
|
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, 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.
|
/// 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)
|
/// The content manager will manage the asset (e.g. provide it when LoadAsset is called with the assets identifier)
|
||||||
AssetHandle ManageAsset(Asset asset);
|
AssetHandle ManageAsset(Asset asset);
|
||||||
|
|||||||
Reference in New Issue
Block a user