Game Development Reference
In-Depth Information
suspendEditing()
undo off
(
numVertex = polyOp.getNumVerts outTriMesh
for j = 1 to numVertex do
(
--for every face sharing the vertex
faces = polyop.getFacesUsingVert outTriMesh j
polyVertices = #() --vertices of the new face
indexFace = #() --the face, contains vertices index...all the v[]
for i = 1 to faces.count do
(
if faces[i] == true then
(
--get the face
curF = polyOp.getFaceVerts outTriMesh i
--find the center of the face and add to the polygon list
x1 = (polyOp.getVert outTriMesh curF[1]).x
x2 = (polyOp.getVert outTriMesh curF[2]).x
x3 = (polyOp.getVert outTriMesh curF[3]).x
y1 = (polyOp.getVert outTriMesh curF[1]).y
y2 = (polyOp.getVert outTriMesh curF[2]).y
y3 = (polyOp.getVert outTriMesh curF[3]).y
D = 2*( x1*(y2 - y3) + x2*(y3 - y1) + x3*(y1 - y2))
A = ( ((y1*y1 + x1*x1)*(y2 - y3)) + ((y2*y2 + x2*x2)*(y3 - y1)) + ((y3*y3 + x3*x3)*(y1 - y2)) )
A = A / float(D)
B = ( ((y1*y1 + x1*x1)*(x3 - x2)) + ((y2*y2 + x2*x2)*(x1 - x3)) + ((y3*y3 + x3*x3)*(x2 - x1)) )
B = B / float(D)
--check for the center, if it's inside the plane or inside the passed mesh it's ok
if(baseMesh != "undefined") then
(
--check if the center is inside the triangles of the mesh using the barycentric coords
properties
customShapeMesh = snapshotAsMesh baseMesh
numFaces = meshop.getNumFaces customShapeMesh
numVertices = meshop.getNumVerts customShapeMesh
--for every triangle:
for i=1 to numFaces do
(
--get the three vertices
triVertices = meshop.getVertsUsingFace customShapeMesh i
Search WWH ::




Custom Search