diff --git a/Source/Engine/Data/IQM.cs b/Source/Engine/Data/IQM.cs index 2d396a4..f697aeb 100644 --- a/Source/Engine/Data/IQM.cs +++ b/Source/Engine/Data/IQM.cs @@ -39,19 +39,11 @@ public enum IQMAnimFlags : uint Loop = 1<<0 } -public class IQMModelResource : IResource +public class IQMModelResource : ModelResource, IResource { public const string Magic = "INTERQUAKEMODEL"; public const int Version = 2; - public struct MeshPrimitive - { - public string Name; - public MeshHandle Handle; - public MaterialResource Material; - public ResourceSet ShaderResSet; - } - char[] m_FullText; public IReadOnlyList Vertices => m_Vertices; @@ -59,9 +51,6 @@ public struct MeshPrimitive List m_Vertices = new List(); List m_Indices = new List(); - public IReadOnlyList Primitives => m_Primitives; - List m_Primitives = new List(); - #region IQM Data public IQMHeader Header; diff --git a/Source/Engine/Data/ModelResource.cs b/Source/Engine/Data/ModelResource.cs index bb153b3..7607957 100644 --- a/Source/Engine/Data/ModelResource.cs +++ b/Source/Engine/Data/ModelResource.cs @@ -12,20 +12,24 @@ namespace WinterEngine.Data; -public class GLBModelResource : IResource +public abstract class ModelResource { public struct MeshPrimitive { + public string Name; public MeshHandle Handle; public MaterialResource Material; // used by the render system to hold the shader parameter resources public ResourceSet ShaderResSet; } - ModelRoot m_ModelRoot; - public IReadOnlyList Primitives => m_Primitives; - List m_Primitives = new List(); + protected List m_Primitives = new List(); +} + +public class GLBModelResource : ModelResource, IResource +{ + ModelRoot m_ModelRoot; public void LoadData(Stream stream) { @@ -74,6 +78,7 @@ public void LoadData(Stream stream) Indices.Add((ushort)index); meshPrimitive.Handle = new MeshHandle(Vertices.ToArray(), Indices.ToArray()); + m_Primitives.Add(meshPrimitive); } } diff --git a/Source/Game/testgame/Entities/EntStrawberryTest.cs b/Source/Game/testgame/Entities/EntStrawberryTest.cs index d6d8fe3..9883cde 100644 --- a/Source/Game/testgame/Entities/EntStrawberryTest.cs +++ b/Source/Game/testgame/Entities/EntStrawberryTest.cs @@ -12,13 +12,13 @@ internal class EntStrawberryTest : Entity, IRenderable { struct MeshRenderData { - public IQMModelResource.MeshPrimitive Mesh; + public ModelResource.MeshPrimitive Mesh; public Pipeline Pipeline; public ResourceSet ShaderResources; } #pragma warning disable CS8618 - private IQMModelResource m_Model; + private ModelResource m_Model; private List m_RenderData = new List(); private DeviceBuffer m_LocalWorldBuffer; @@ -30,7 +30,14 @@ struct MeshRenderData public override void Spawn() { - m_Model = ResourceManager.Load("models/gort.iqm"); + try + { + m_Model = ResourceManager.Load("models/gort.iqm"); + } + catch + { + m_Model = ResourceManager.Load("models/engine/error.glb"); + } CreateDeviceResources(); }