TriMesh.FromRawData

TriMesh.FromRawData method

Create TriMesh from raw data

public static TriMesh FromRawData(VertexDeclaration vd, byte[] vertices, int[] indices, 
    bool generateVertexMapping)
ParameterTypeDescription
vdVertexDeclarationVertex declaration, must contains at least one field.
verticesByte[]The input vertex data, the minimum length of the vertices must be greater or equal to vertex declaration’s size
indicesInt32[]The triangle indices
generateVertexMappingBooleanGenerate Vertex for each vertex, which is not necessary for just serialization/deserialization.

Return Value

The TriMesh instance that encapsulated the input byte array.

Remarks

The returned TriMesh will not copy the input byte array for performance, external changes on the array will be reflected to this instance.

Examples

The following code shows how to construct a TriMesh from raw bytes, this is useful when build your own 3D format

var indices = new int[] { 0,  1,  2 };
var vertices = new byte[]{
    0, 0, 0, 191,
    0, 0, 0, 0,
    0, 0, 0, 191,
    0, 0, 0, 191,
    0, 0, 0, 0,
    0, 0, 0, 63,
    0, 0, 0, 63,
    0, 0, 0, 0,
    0, 0, 0, 63
};
VertexDeclaration vd = new VertexDeclaration();
vd.AddField(VertexFieldDataType.FVector3, VertexFieldSemantic.Position);
var triMesh = TriMesh.FromRawData(vd, vertices, indices, true);

See Also