Game Development Reference
In-Depth Information
The fn_delaunayTriangulation function takes two arguments. vNumber contains the number of new vertices
that will be created inside each triangle of your existing geometry; baseMesh is the existing geometry. Please note that
using a high value in vNumber could slow down the MAXScript computation time.
The barycentric coordinates are used to add vertices in triangles defined by the passed mesh: a point inside a
triangle can be expressed in terms of triangle's vertices coordinates, using the following notation:
newVertex = a * tP1 + b * tP2 + c * tP3
a + b + c = 1.0
c = 1.0 - a - b
The sum of a, b, and c must be equal to 1, so generating a and b randomly (checking their sum, too), the c value
will equal 1.0 minus a minus b.
At last, the vertices of the passed mesh will be added to your set, as in Listing 4-2.
Listing 4-2. The Vertices of the Passed Mesh Are Added to the Set.
-------------------
-- continue above
-------------------
--sort the vertex array over the x axis
qsort vertices ut_compareVx
--find the point plane bounds --> min MAX
xmin = vertices[1].x
ymin = vertices[1].y
xmax = xmin
ymax = ymin
for p in vertices do
(
if(p.x < xmin) then xmin = p.x
if(p.x > xmax) then xmax = p.x
if(p.y < ymin) then ymin = p.y
if(p.y > ymax) then ymax = p.y
)
dx = xmax - xmin
dy = ymax - ymin
if(dx > dy) then dmax = dx
else dmax=dy
xmid = (xmax + xmin) / 2.0
ymid = (ymax + ymin) / 2.0
--create the super triangle containing all the vertices in the array
superTriangle = triangle [(xmid - 2*dmax), (ymid - dmax), 0.0] [xmid, (ymid + 2*dmax), 0.0]
[(xmid + 2*dmax), (ymid - dmax), 0.0]
append delunayTriangles superTriangle
Search WWH ::




Custom Search