DATAKIT API  V2025.1
How to use Dtk_mesh Class

Overview

A Dtk_mesh class allows storing a mesh.

Figure 1

A Dtk_mesh is composed of multiple sub-meshes, called mesh_faces. All mesh_faces refer to the Dtk_mesh_vertex array. See Figure 2 for a definition of Dtk_mesh_vertex and Figure 3 for the definition of Dtk_mesh_face.



Vertices

Figure 2

A vertex can be derived into several forms. It depends on how much information you need. You can have :

  • Dtk_mesh_vertex : this form contains only x,y,z coordinates of the vertex. It can be used for a compact mesh.
  • Dtk_mesh_vertex_norm : also stores the normal for each vertex. Can be used to have a smooth render.
  • Dtk_mesh_vertex_norm_color : also stores a color for each vertex. Can be used for color gradient. (Note that we can give color on a whole mesh without enabling this option)
  • Dtk_mesh_vertex_norm_color_uv : also stores u,v coordinates for the vertex. May be used for using textures.

You can choose the vertex format you want with a parameter given to the Dtk_mesh constructor.



Mesh_faces

This is the definition of a sub mesh.

Figure 3

A Dtk_mesh_face is a container that can hold different forms of a mesh. Each element of the Dtk_mesh_face (see Figure 3) is an array of indexes referring to the Dtk_mesh_vertex array (see Figure 1). \nThe different types of arrays stored in a Dtk_mesh_face are :

Array of triangles

It is a simple array of vertices defining triangles. Each element is the index of a vertex and triangles are defined by three successive vertices (which means that the array size is three times the number of triangles). See the following example :

Figure 3.1

There are 4 triangles. They are oriented so the definition of their indexes must be in the trigonometric sense. The array may be : 1, 3, 2, 1, 4, 3, 3, 4, 5, 3, 5, 0.
Of course, it will refer to vertices from 0 et 5 (inclusive) inside Dtk_mesh_vertex array (see Figure 1).

Array of triangle-strip

In Figure 3.1, we can consider the triangles A, B and C shaping a triangle-strip (series of connected triangles, each of them sharing an edge with his neighbourhood(s)). Instead of storing them individually in an array of triangles, we rather can use an array of triangle-strip. This type of array is composed of the indexes of the vertices defining the triangle-strip. In our example, this array may be 2, 1, 3, 4, 5.
Since a mesh_face can store multiple triangle-strips, the array of triangle-strip is a 2-dimensional array of indexes.

Array of triangle-fan

Still in Figure 3.1, we can also consider the triangles A, B, C, D shaping a triangle-fan (series of connected triangles, all of them sharing a central vertex). It is defined with the same logic than the one explained for an array of triangle-strip. In our example, this array may be 3, 2, 1, 4, 5, 0.
Since a mesh_face can store multiple triangle-fans, the array of triangle-fans is a 2-dimensional array of indexes.

Array of polygons

Figure 3.4

A polygon is another array of indexes referring to vertices. In the example of Figure 3.4, the array of this polygon may be 0, 1, 2, 3, 4, 5, 6, 7.
Since a mesh_face can store multiple polygons, the array of polygons is a 2-dimensional array of indexes.

Array of mockups

Figure 3.5

A mockup is a polygon with polygonal holes inside. It is composed of multiple polylines (array of vertices). The first array is the outer trim and there is only one outer trim possible. The others arrays are inner trims.
We usually write the outer trim in the trigonometrical sense, and inner trims in clockwise sense.
Note that a mockup with only one array of indexes, so with only the outer trim, is a polygon.

Seeing Figure 3.5. we have a mockup with 3 arrays (1 outer, 2 inners)

These arrays are :
a0, a1, a2, a3, a4, a5, a6
c7, c6, c5, c4, c3, c2, c1, c0
b5, b4, b3, b2, b1, b0

Since a mesh_face can store multiple mockups, the array of mockups is a 3-dimensional array of indexes.

Array of line-strip

This array allows storing line-strips (polylines) for wireframe elements.

Figure 3.6

The array of this line strip may be 0, 1, 2, 3. Since a mesh_face can store multiple line strips, the array of line strips is a 2-dimensional array of indexes.

Array of points

For wireframe, this type of array simply isolates points that can be kept inside this 1-dimensional array of indexes.