MeshBlob
- Namespace: Turian.Engine.Core
- Source File: MeshBlob.cs
Reads the .ammesh binary mesh container: a 12-byte header followed by a binary manifest chunk and a payload chunk holding the vertex streams and the index buffer. Attribute semantics and component types are glTF 2.0's.
Fields
FileExtension (string) = ".ammesh": File extension of the container.
Magic (uint) = 0x48534D41: Header magic, the ASCII bytes AMSH.
Version (uint) = 1: Container version this reader accepts.
ManifestChunkType (uint) = 0x494E414D: Chunk type of the binary manifest, the ASCII bytes MANI.
PayloadChunkType (uint) = 0x004E4942: Chunk type of the payload, the ASCII bytes BIN\0.
ComponentTypeFloat (uint) = 5126: glTF 2.0 component type for 32-bit floats.
ComponentTypeUnsignedInt (uint) = 5125: glTF 2.0 component type for 32-bit unsigned integers.
Properties
VertexStreamAttributes
(IReadOnlyList[ new(MeshAttributeSemantic.Position, ComponentTypeFloat, 3, (uint)Marshal.OffsetOf<Vertex>(nameof(Vertex.Position))), new(MeshAttributeSemantic.Color0, ComponentTypeFloat, 3, (uint)Marshal.OffsetOf<Vertex>(nameof(Vertex.Color))), new(MeshAttributeSemantic.Normal, ComponentTypeFloat, 3, (uint)Marshal.OffsetOf<Vertex>(nameof(Vertex.Normal))), new(MeshAttributeSemantic.TexCoord0, ComponentTypeFloat, 2, (uint)Marshal.OffsetOf<Vertex>(nameof(Vertex.Uv))), new(MeshAttributeSemantic.Tangent, ComponentTypeFloat, 4, (uint)Marshal.OffsetOf<Vertex>(nameof(Vertex.Tangent))), ]: Layout of the interleaved Vertex stream, which is always stream 0.
TexCoord1StreamAttributes
(IReadOnlyList[ new(MeshAttributeSemantic.TexCoord1, ComponentTypeFloat, 2, 0), ]: Layout of the optional secondary UV stream, which is always stream 1 when present.
Streams
(IReadOnlyList[]: The stream descriptors as they were written.
Vertices
(Vertex[]) = []: The interleaved vertices decoded from stream 0.
TexCoord1
(Vector2[]) = []: The secondary UV set decoded from stream 1, empty when the file has none.
Indices
(uint[]) = []: The shared index buffer every submesh addresses.
SubMeshes
(IReadOnlyList[]: The submesh table.
Meshes
(IReadOnlyList[]: The mesh table; one entry per MeshAsset the file produces.
Bounds
(Bounds) : Axis-aligned bounds covering every mesh in the file.
Public Methods
Load
public static MeshBlob Load(string path)
Reads a mesh blob from a file.
Parameters:
path(string): Absolute path of the.ammeshfile.
Returns: MeshBlob
Read
public static MeshBlob Read(Stream stream)
Reads a mesh blob from a stream, consuming it to the end.
Parameters:
stream(Stream): The stream positioned at the container header.
Returns: MeshBlob
Read
public static MeshBlob Read(ReadOnlySpan<byte> data)
Reads a mesh blob from an in-memory container.
Parameters:
data(ReadOnlySpan): The complete container bytes.
Returns: MeshBlob
ToModelBuilder
public ModelBuilder ToModelBuilder()
Projects the blob onto a ModelBuilder so it can be uploaded as a single Model sharing one vertex buffer and one index buffer.
Returns: ModelBuilder
Padding
public static int Padding(int length)
Returns the number of bytes needed after length to reach a 4-byte boundary.
Parameters:
length(int): Length of the preceding run of bytes.
Returns: int