aligns obj to a face normal using api

49 views
Skip to first unread message

Fleming Lin

unread,
Nov 6, 2018, 10:18:10 PM11/6/18
to Python Programming for Autodesk Maya
hi guys...I have done many research online and still can't figure out where I did wrong....all I want...is just create one angry puffer fish( or "sphere")...please help...

...so my first idea was to collect all the facial normal using MItMeshPolygon.getPolygonNormal(( faceIter.index(), om.MSpace.kWorld)) and then set both the position and rotation base on the normal I got...but here is what I get....(see code and result attach below). And I noticed that after I moved the sphere, the "thorns" would remained at the origin instead of translated with the sphere..... So I then use the om.MItMeshPolygon.center(om.MSpace.kWorld) to get the center position of the face for the translation and normal for the rotation...  Now I get the position right..but still the wrong rotation....what should I do now? : <

Screen Shot 2018-11-06 at 9.57.11 PM.png


Screen Shot 2018-11-06 at 9.58.57 PM.png

Screen Shot 2018-11-06 at 9.59.14 PM.png


changed I made

Screen Shot 2018-11-06 at 10.15.52 PM.png

Screen Shot 2018-11-06 at 10.14.59 PM.png





any help would be ultra appreciated!!! 

Neil Roche

unread,
Nov 7, 2018, 9:08:56 AM11/7/18
to Python Programming for Autodesk Maya
Hi,

The method getPolygonNormal will return a vector not a rotation, so you will need to either do some vector math to get the euler rotation from the vector using the position at the centre of the face and the normal vector to start with or maybe use an aimConstraint to align your cone along the vector.

This should help:

Reply all
Reply to author
Forward
0 new messages