TriMesh class

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.

Inheritance: TriMeshEntitySceneObjectA3DObject

The TriMesh type exposes the following members:

Constructors

ConstructorDescription
__init__(self, name, declaration)Initialize an instance of TriMesh

Properties

PropertyDescription
nameGets or sets the name.
propertiesGets the collection of all properties.
sceneGets the scene that this object belongs to
parent_nodesGets all parent nodes, an entity can be attached to multiple parent nodes for geometry instancing
excludedGets or sets whether to exclude this entity during exporting.
parent_nodeGets or sets the first parent node, if set the first parent node, this entity will be detached from other parent nodes.
vertex_declarationThe vertex layout of the TriMesh.
vertices_countThe count of vertices in this TriMesh
indices_countThe count of indices in this TriMesh
unmerged_vertices_countThe count of unmerged vertices that passed in by TriMesh.begin_vertex and TriMesh.end_vertex.
capacityThe capacity of pre-allocated vertices.
vertices_size_in_bytesThe total size of all vertices in bytes

Methods

MethodDescription
remove_property(self, property)Removes a dynamic property.
remove_property(self, property)Remove the specified property identified by name
from_mesh(, declaration, mesh)Create a TriMesh from given mesh object with given vertex layout.
from_mesh(, mesh, use_float)Create a TriMesh from given mesh object, the vertex declaration are based on the input mesh’s structure.
indices_to_array(self, result)
indices_to_array(self, result)
get_property(self, property)Get the value of specified property
set_property(self, property, value)Sets the value of specified property
find_property(self, property_name)Finds the property.
It can be a dynamic property (Created by CreateDynamicProperty/SetProperty)
or native property(Identified by its name)
get_bounding_box(self)Gets the bounding box of current entity in its object space coordinate system.
get_entity_renderer_key(self)Gets the key of the entity renderer registered in the renderer
copy_from(, input, vd)Copy the TriMesh from input with new vertex layout
begin_vertex(self)Begin adding vertex
end_vertex(self)End adding vertex
write_vertices_to(self, stream)Write vertices data to the specified stream
write_16b_indices_to(self, stream)Write the indices data as 16bit integer to the stream
write_32b_indices_to(self, stream)Write the indices data as 32bit integer to the stream
vertices_to_array(self)Convert the vertices data to byte array
from_raw_data(, vd, vertices, indices, generate_vertex_mapping)Create TriMesh from raw data
load_vertices_from_bytes(self, vertices_in_bytes)Load vertices from bytes, the length of bytes must be an integer multiple of vertex size.
add_triangle(self, a, b, c)Add a new triangle
read_vector4(self, idx, field)Read the vector4 field
read_f_vector4(self, idx, field)Read the vector4 field
read_vector3(self, idx, field)Read the vector3 field
read_f_vector3(self, idx, field)Read the vector3 field
read_vector2(self, idx, field)Read the vector2 field
read_f_vector2(self, idx, field)Read the vector2 field
read_double(self, idx, field)Read the double field
read_float(self, idx, field)Read the float field

Example

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

from aspose.threed.entities import Sphere, TriMesh
from aspose.threed.utilities import VertexDeclaration, VertexFieldDataType, VertexFieldSemantic

# Define a vertex declaration as {FVector3 Position; FVector3 Normal; FVector2 UV}
vd = VertexDeclaration()
vd.add_field(VertexFieldDataType.F_VECTOR3, VertexFieldSemantic.POSITION)
vd.add_field(VertexFieldDataType.F_VECTOR3, VertexFieldSemantic.NORMAL)
vd.add_field(VertexFieldDataType.F_VECTOR2, VertexFieldSemantic.UV)
# convert a mesh to tri-mesh using specified memory layout
mesh = Sphere().to_mesh()
triMesh = TriMesh.from_mesh(vd, mesh)
# save it to a stream, 115 vertices * 32bytes per vertex
with open("output.bin", "wb") as stream:
    triMesh.write_vertices_to(stream)
    # save indices as ushort to stream, 504 indices * 2 bytes per index
    triMesh.write_16b_indices_to(stream)

See Also