Game Development Reference
In-Depth Information
convertTo delaunayMesh PolyMeshObject
polyop.weldVertsByThreshold delaunayMesh #{1..(delaunayMesh.GetNumVertices())}
resumeEditing()
return delaunayMesh
)
--end fn_delaunayTriangulation function
For every triangle in the Delaunay triangle array, a single mesh is created and later attached to a void mesh.
The duplicated vertices are finally welded together. Figure 4-6 shows the base mesh and the results of the
fn_delaunayTriangulation function. Notice how the triangles in the base mesh have been subdivided.
Figure 4-6. Base mesh and Delaunay mesh
The Code: the Voronoi Diagram
The Voronoi diagram procedure is pretty simple: it takes as arguments the triangulated Delaunay mesh, a numerical
value used to delete Voronoi polygons of the same side amount, and the mesh used as the base for the triangulation.
The base mesh is needed to cut out all the Voronoi polygons that lie outside it.
Every vertex in the triangulated mesh is a Voronoi cell center, and the centers of the triangles sharing the vertex
are the cell vertices. So for every vertex in the triangulated mesh, you get all the faces that are sharing it, and for every
face, you find the circumcircle center. The angle between the current vertex and the surrounding centers is calculated
and stored in an array. This array will be ordered using a utility function. Finally, the new polygon is added to the
Editable Poly object created in the first lines of the procedure (see Listing 4-4).
Listing 4-4. Creating the Voronoi Diagram
function fn_voronoiDiagram outTriMesh cutNgons baseMesh =
(
--the object for the voronoi polys
voronoiDiagram = editable_mesh()
voronoiDiagram.name = uniqueName "voronoiPoly"
convertTo voronoiDiagram PolyMeshObject
 
Search WWH ::




Custom Search