View Full Version : Center of EditableMesh face/polygon
07-20-2011, 05:21 PM
Because the editable mesh is a triangulated mesh the results are not what I was expecting.
If you run this code you'll see.
It's creating twice as many spheres as it needs and they are not at the center of the entire polygon. Should I loop through and for every two spheres create a sphere at the middle distance of the 2 spheres created to get the proper sphere placement at the center of the actual polygon?
--Editable Mesh Face
numFaces = $.numfaces
for f = 1 to numFaces do
newPos = meshop.getFaceCenter $ f -- EditableMesh
sphere radius:1 pos:NewPos
07-20-2011, 06:22 PM
Little bit of user error there. getFaceCenter returns the triangle face, not the poly face. The code below converts the selected object to mesh and faces to poly to properly do what you need.
objMesh = snapshot $ --Snap to get obj as mesh so code will run on any object type
facesArr = for val = 1 to objMesh.numfaces collect val -- get faces as array
while facesArr.count != 0 do -- since we will be adjusting array inside the test no need to loop, test auto shrinks and will stop when there are no more faces
faceArr = #(facesArr) -- get the first array item as array
polyBit = meshop.getPolysUsingFace objMesh faceArr -- Poly using Face
vertBit = meshop.getVertsUsingFace objMesh polyBit -- Verts used by the Poly
setVertSelection objMesh vertBit -- Set vert selection
selCenter = averageSelVertCenter objMesh -- Get vert selection center
newpos = selCenter*$.objectTransform -- set newPos
setVertSelection objMesh #() -- Clear vert selection
sphere radius:1 pos:NewPos -- create sphere at poly center
facesArr = ((facesArr as bitarray)-polyBit) as array --reduce the facesArr by the faces in the poly and convert back to array
delete objMesh -- delete the snapshot-Eric
EDIT: There appears to be issues with Pole triangle faces with this approach. Not sure the cause, but don't have time to track down now.
07-21-2011, 02:22 PM
Thanks Pixel Monkey for the response. I think what you have here will help for sure.
I'll see where I can get with it.
07-21-2011, 02:22 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2015, Jelsoft Enterprises Ltd.