![]() |
Public API Reference |
#include <tesselat.h>
To use, simply fill a grid cell struct with the required corner positions and values. Allocate at least 15 vertices in the vertices buffer and hand it to tesselate. It will return the filled buffer and the number of vertices it contains. The buffer will contain up to 15 vertices in multiples of three, each representing a triangle. The normals point inward, so to obtain a concave hull from the list, assign the vertices in order to a triangle. To obtain a convex hull, swap two of the vertices (1 and 3 does nicely). The algorithm is just about bullet proof, however there are a few simple rules to using the algorithm:
p[0]: (0,1,1) p[1]: (1,1,1) p[2]: (1,1,0) p[3]: (0,1,0) p[4]: (0,0,1) p[5]: (1,0,1) p[6]: (1,0,0) p[7]: (0,0,0)
The edge table represents a vertex outcome based on the the corner map it was supplied. It is a twelve bit mapping respresenting each edge of the cube. The order is specifc, and these are the edge vertices. (This table is based on the one earlier on.)
bit 0: p[0] - p[1] bit 1: p[1] - p[2] bit 2: p[2] - p[3] bit 3: p[3] - p[0] bit 4: p[4] - p[5] bit 5: p[5] - p[6] bit 6: p[6] - p[7] bit 7: p[7] - p[4] bit 8: p[0] - p[4] bit 9: p[1] - p[5] bit 10: p[2] - p[6] bit 11: p[3] - p[7] *
For each state where one vertex is greater than zero and its nieghbour is is less than zero, a corresopnding flag is set by the edge table. After all edges that incur an intersection are set, the next step is interpolating the intersection vertices. The interpolation algorithm uses the values of each corner (GridCell.val[]) to produce a linear estimate of where the intersection with the edge occurs. This is not 100% accurate, but does provide a nice approximation.
The triangle table is a scripted set of triangle maps based on the cube index. It contains 256 mappings with up to five triangles. The sixteenth element of every mapping is -1, to terminate the mapping. In many cases, the map table is filled with terminations after two or three triangles. Now although there are only twelve resultant vertices from the interpolation unit, in some cases, a given edge vertex may be used up to four times in a given mapping, resulting in a maximum of fifteen vertices in the output.
Examples of fast methods to fill the grid cell can be found in the MetaBall mesh plugin and the metagen
mesh plugin (CS/plugins/mesh/metaball/object/process.cpp
and CS/plugins/mesh/metagen/object/mgproc.cpp
, respectively).
Definition at line 114 of file tesselat.h.