|
Visual Computing Library
devel
|
We can first declare a new Triangle Mesh and load a ply file:
Or:
The TriMesh data structure has containers of Vertices and Faces, plus some other info like Bounding Box, Transform Matrix, ...
You can find more info about the TriMesh class and other built-in classes in the Built-in Meshes page and the list of them in the Meshes group.
We can, for example, print some statistics and update the bounding box component of the mesh after that it has been loaded:
We can access to the elements (Vertices, Faces, ...) of the mesh by index:
We can also iterate over Vertices and over Faces of the mesh:
Note that iterating over the vertices of the faces of the Mesh returns the vertices/faces/elements objects by reference, while iterating over the vertices of the face (or, in general, adjacencies of a specific element) returns the pointer to an element that is stored inside the same Mesh. Note also that this pointer may be nullptr: in this small example we assume that the mesh is consistent meaning that this cannot happen.
We can create from scratch a mesh:
Each data that is stored in a mesh or in a element is called "component". For example, the position of a vertex is a component, the normal of a face is a component, the color of a vertex is a component, and so on.
Depending on how the Element is defined, the components can be stored in different ways, and they can be optional: that means that a component can be enabled or disabled at runtime, using the required memory only when it is needed.
For example, in the TriMesh class, the Vertex and Face elements have their Color component optional, and disabled by default. We can enable them by calling:
Accessing to disabled components is not allowed, and will cause undefined behavior.