Skip to content

Game.Prefabs.MeshVertex

Assembly: Assembly-CSharp (typical Unity game assembly; may vary)
Namespace: Game.Prefabs

Type: struct

Base: IBufferElementData

Summary:
Represents a single mesh vertex stored as a float3 and intended for use as an ECS dynamic buffer element (DynamicBuffer). Provides helper methods to unpack raw vertex data (from asset/mesh vertex attribute bytes) into either a DynamicBuffer or a NativeArray. Supports 32-bit float vertex attribute data (3 components) and 16-bit float (half) data via a native conversion helper. Unsafe pointer operations are used for the half->float path, and an exception is thrown for unsupported formats/dimensions.


Fields

  • public float3 m_Vertex
    Holds the vertex position as a float3 (x, y, z). This is the data stored per buffer element.

Properties

  • None.
    This type exposes no properties; it only contains the public field m_Vertex and static helper methods.

Constructors

  • public MeshVertex(float3 vertex)
    Initializes a MeshVertex instance by setting m_Vertex to the provided float3.

Methods

  • public static void Unpack(NativeSlice<byte> src, DynamicBuffer<MeshVertex> dst, int count, VertexAttributeFormat format, int dimension)
    Resizes the destination DynamicBuffer to count elements and delegates to the NativeArray overload. Use this when you want to write directly into an entity's DynamicBuffer.

Behavior: - Calls dst.ResizeUninitialized(count). - Calls the unsafe NativeArray overload with dst.AsNativeArray().

  • public unsafe static void Unpack(NativeSlice<byte> src, NativeArray<MeshVertex> dst, int count, VertexAttributeFormat format, int dimension)
    Converts raw vertex attribute bytes in src into count MeshVertex entries in dst.

Behavior and supported formats: - If format == VertexAttributeFormat.Float32 and dimension == 3: - Interprets the bytes directly as MeshVertex entries and performs a zero-copy style conversion via src.SliceConvert().CopyTo(dst). - If format == VertexAttributeFormat.Float16: - Calls Colossal.AssetPipeline.Native.NativeMath.ArrayHalfToFloat with unsafe pointers to convert half-precision floats to 32-bit floats. The conversion writes into the dst buffer, producing 3 floats per vertex (float3). - Otherwise: - Throws an Exception: "Unsupported source position format/dimension in Unpack {format} {dimension}"

Notes: - The half->float conversion uses unsafe pointer operations; the method is marked unsafe. - The method expects vertex positions to be 3-component vectors in supported formats; other dimensions are not handled. - Requires Unity.Collections.LowLevel.Unsafe and Colossal.AssetPipeline.Native.NativeMath to be available at runtime.

Usage Example

// Unpack into an entity DynamicBuffer<MeshVertex>
NativeSlice<byte> vertexAttributeBytes = /* obtained from asset/mesh */;
int vertexCount = /* number of vertices */;
VertexAttributeFormat format = /* VertexAttributeFormat.Float32 or Float16 */;
int dimension = /* typically 3 for positions */;

DynamicBuffer<MeshVertex> buffer = entityManager.GetBuffer<MeshVertex>(entity);
MeshVertex.Unpack(vertexAttributeBytes, buffer, vertexCount, format, dimension);

// Or unpack into a temporary NativeArray
var vertices = new NativeArray<MeshVertex>(vertexCount, Allocator.Temp);
try
{
    MeshVertex.Unpack(vertexAttributeBytes, vertices, vertexCount, format, dimension);
    // use vertices...
}
finally
{
    vertices.Dispose();
}

Additional details and suggestions: - The struct is annotated with [InternalBufferCapacity(0)], so DynamicBuffer starts with zero internal capacity — it will reallocate when resized. - Ensure the format and dimension parameters match the source vertex attribute layout (this helper only supports float32 with dimension==3 or float16). - The float16 path delegates to a native conversion function (NativeMath.ArrayHalfToFloat); ensure that function and the associated native interop are available in your mod/runtime environment.