Class TriMesh

TriMesh class

A TriMesh contains raw data that can be used by GPU directly. This class is a utility to help to construct a mesh that only contains per-vertex data.

public class TriMesh : Entity, IEnumerable<Vertex>

Constructors

NameDescription
TriMesh(string, VertexDeclaration)Initialize an instance of TriMesh

Properties

NameDescription
Capacity { get; }The capacity of pre-allocated vertices.
Excluded { get; set; }Gets or sets whether to exclude this entity during exporting.(Inherited from Entity.)
IndicesCount { get; }The count of indices in this TriMesh
virtual Name { get; set; }Gets or sets the name.(Inherited from A3DObject.)
ParentNode { get; set; }Gets or sets the first parent node, if set the first parent node, this entity will be detached from other parent nodes.(Inherited from Entity.)
ParentNodes { get; }Gets all parent nodes, an entity can be attached to multiple parent nodes for geometry instancing(Inherited from Entity.)
Properties { get; }Gets the collection of all properties.(Inherited from A3DObject.)
Scene { get; }Gets the scene that this object belongs to(Inherited from SceneObject.)
UnmergedVerticesCount { get; }The count of unmerged vertices that passed in by BeginVertex and EndVertex.
VertexDeclaration { get; }The vertex layout of the TriMesh.
VerticesCount { get; }The count of vertices in this TriMesh
VerticesSizeInBytes { get; }The total size of all vertices in bytes

Methods

NameDescription
static CopyFrom(TriMesh, VertexDeclaration)Copy the TriMesh from input with new vertex layout
static FromMesh(Mesh, bool)Create a TriMesh from given mesh object, the vertex declaration are based on the input mesh’s structure.
static FromMesh(VertexDeclaration, Mesh)Create a TriMesh from given mesh object with given vertex layout.
static FromRawData(VertexDeclaration, byte[], int[], bool)Create TriMesh from raw data
AddTriangle(int, int, int)Add a new triangle
BeginVertex()Begin adding vertex
EndVertex()End adding vertex
FindProperty(string)Finds the property. It can be a dynamic property (Created by CreateDynamicProperty/SetProperty) or native property(Identified by its name)(Inherited from A3DObject.)
GetBoundingBox()Gets the bounding box of current entity in its object space coordinate system.(Inherited from Entity.)
virtual GetEntityRendererKey()Gets the key of the entity renderer registered in the renderer(Inherited from Entity.)
GetEnumerator()Get the enumerator to enumerate Vertex
GetProperty(string)Get the value of specified property(Inherited from A3DObject.)
IndicesToArray(out int[])
IndicesToArray(out ushort[])
LoadVerticesFromBytes(byte[])Load vertices from bytes, the length of bytes must be an integer multiple of vertex size.
ReadDouble(int, VertexField)Read the double field
ReadFloat(int, VertexField)Read the float field
ReadFVector2(int, VertexField)Read the vector2 field
ReadFVector3(int, VertexField)Read the vector3 field
ReadFVector4(int, VertexField)Read the vector4 field
ReadVector2(int, VertexField)Read the vector2 field
ReadVector3(int, VertexField)Read the vector3 field
ReadVector4(int, VertexField)Read the vector4 field
RemoveProperty(Property)Removes a dynamic property.(Inherited from A3DObject.)
RemoveProperty(string)Remove the specified property identified by name(Inherited from A3DObject.)
SetProperty(string, object)Sets the value of specified property(Inherited from A3DObject.)
override ToString()Gets the string representation of TriMesh
VerticesToArray()Convert the vertices data to byte array
Write16bIndicesTo(Stream)Write the indices data as 16bit integer to the stream
Write32bIndicesTo(Stream)Write the indices data as 32bit integer to the stream
WriteVerticesTo(Stream)Write vertices data to the specified stream

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