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
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 tocount
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 insrc
intocount
MeshVertex entries indst
.
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
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