Skip to content

Commit

Permalink
feat: modelresource base class
Browse files Browse the repository at this point in the history
all model resource classes use the same outward facing format for model data.
  • Loading branch information
ashifolfi committed Apr 1, 2024
1 parent 4cb66f6 commit 8a33530
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
13 changes: 1 addition & 12 deletions Source/Engine/Data/IQM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,18 @@ 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<Vertex> Vertices => m_Vertices;
public IReadOnlyList<ushort> Indices => m_Indices;
List<Vertex> m_Vertices = new List<Vertex>();
List<ushort> m_Indices = new List<ushort>();

public IReadOnlyList<MeshPrimitive> Primitives => m_Primitives;
List<MeshPrimitive> m_Primitives = new List<MeshPrimitive>();

#region IQM Data
public IQMHeader Header;

Expand Down
13 changes: 9 additions & 4 deletions Source/Engine/Data/ModelResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MeshPrimitive> Primitives => m_Primitives;
List<MeshPrimitive> m_Primitives = new List<MeshPrimitive>();
protected List<MeshPrimitive> m_Primitives = new List<MeshPrimitive>();
}

public class GLBModelResource : ModelResource, IResource
{
ModelRoot m_ModelRoot;

public void LoadData(Stream stream)
{
Expand Down Expand Up @@ -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);
}
}
Expand Down
13 changes: 10 additions & 3 deletions Source/Game/testgame/Entities/EntStrawberryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MeshRenderData> m_RenderData = new List<MeshRenderData>();
private DeviceBuffer m_LocalWorldBuffer;
Expand All @@ -30,7 +30,14 @@ struct MeshRenderData

public override void Spawn()
{
m_Model = ResourceManager.Load<IQMModelResource>("models/gort.iqm");
try
{
m_Model = ResourceManager.Load<IQMModelResource>("models/gort.iqm");
}
catch
{
m_Model = ResourceManager.Load<GLBModelResource>("models/engine/error.glb");
}
CreateDeviceResources();
}

Expand Down

0 comments on commit 8a33530

Please sign in to comment.