TriMesh.FromMesh

FromMesh(VertexDeclaration, Mesh)

Create a TriMesh from given mesh object with given vertex layout.

public static TriMesh FromMesh(VertexDeclaration declaration, Mesh mesh)
ParameterTypeDescription
declarationVertexDeclarationVertex’s type definition, or memory layout
meshMeshSource mesh

Return Value

Instance of TriMesh converted from input mesh with specified vertex’s memory layout

Examples

The following code shows how to create a TriMesh with custom memory layout, and export it to file.

//Define a vertex declaration as {FVector3 Position; FVector3 Normal; FVector2 UV}
VertexDeclaration vd = new VertexDeclaration();
vd.AddField(VertexFieldDataType.FVector3, VertexFieldSemantic.Position);
vd.AddField(VertexFieldDataType.FVector3, VertexFieldSemantic.Normal);
vd.AddField(VertexFieldDataType.FVector2, VertexFieldSemantic.UV);
//convert a mesh to tri-mesh using specified memory layout  
var mesh = (new Sphere()).ToMesh();
var triMesh = TriMesh.FromMesh(vd, mesh);
//save it to a stream, 115 vertices * 32bytes per vertex
using (var stream = new FileStream("output.bin", FileMode.Create))
{
    triMesh.WriteVerticesTo(stream);
    //save indices as ushort to stream, 504 indices * 2 bytes per index
    triMesh.Write16bIndicesTo(stream);
}

See Also


FromMesh(Mesh, bool)

Create a TriMesh from given mesh object, the vertex declaration are based on the input mesh’s structure.

public static TriMesh FromMesh(Mesh mesh, bool useFloat = true)
ParameterTypeDescription
meshMesh
useFloatBooleanUse float type instead of double type for each vertex element component.

Return Value

The TriMesh generated from given Mesh

Examples

The following code shows how to create a TriMesh with custom memory layout, and export it to file.

//Define a vertex declaration as {FVector3 Position; FVector3 Normal; FVector2 UV}
VertexDeclaration vd = new VertexDeclaration();
vd.AddField(VertexFieldDataType.FVector3, VertexFieldSemantic.Position);
vd.AddField(VertexFieldDataType.FVector3, VertexFieldSemantic.Normal);
vd.AddField(VertexFieldDataType.FVector2, VertexFieldSemantic.UV);
//convert a mesh to tri-mesh using specified memory layout  
var mesh = (new Sphere()).ToMesh();
var triMesh = TriMesh.FromMesh(vd, mesh);
//save it to a stream, 115 vertices * 32bytes per vertex
using (var stream = new FileStream("output.bin", FileMode.Create))
{
    triMesh.WriteVerticesTo(stream);
    //save indices as ushort to stream, 504 indices * 2 bytes per index
    triMesh.Write16bIndicesTo(stream);
}

See Also