PDA

View Full Version : Querying the Center of an Object


McCartneyChris
02-24-2009, 12:58 AM
Hi there im currently doing an assignment where i need to find out the center of an object , anybody know the mel command to do this ?

claydough
02-24-2009, 03:14 AM
.
Depends...
on the shape of the object.


The bounding box area of an object does not always produce a center.
( which I believe is how Maya xform -cp works )
The center of a pentagon fer instance will be wrong if you xform -q -ws -rp
Even after "centering pivot".

As far as I know there isnt a mel command that will "truley" get center for every case.





( for the pentagon tho.. I believe u can git radius from any two "base's mid points" connected to their opposite "corner points" the intersection of jes two such division's would be a true pentagon center )

like:
http://farm4.static.flickr.com/3300/3305749060_8837c9ddc4_o.jpg

The Manipulators represent false bounding approximation.




if u continue around the shape till finished then delete the base mid points' connecting edges
leaving center to corner points' edges:

http://farm4.static.flickr.com/3311/3304941559_cd499fd0e4_o.jpg

we can now clearly see by the equidistant tris, the error of the manipulator position
( making a cylinder with 5 sides will produce caps with the same result... truely centered intersection of tri tips )

Not sure if this is what yer assignment requires, but I would recommend custom logic for finding center in real world scenarios ( i.e., yer glorious maya coding future )

Dontnoun
02-24-2009, 08:18 AM
//select -r [yourmesh]
CenterPivot;
vector $obj_c = `getAttr .c`;
print $obj_c

McCartneyChris
02-26-2009, 12:21 AM
Hey guys thanks for the replies =D it all helps hey im totally new to the whole MEL scene so gettin my head around it slowly ;P , busy writing a basic lighting script so reason for asking was to find out the center of an object so i can snap the say " Spotlights " center of interest to the exact center of an object so they would be aimed at whatever object upon creation

But yeah ill keep grinding it :P

WANGSHAOWEN
03-03-2009, 02:37 PM
//select -r [yourmesh]
CenterPivot;
vector $obj_c = `getAttr .c`;
print $obj_c

`getAttr .c` what's c is stand for? who can tell me?

Dontnoun
03-03-2009, 04:13 PM
getAttr .c 是 getAttr .center的缩写

CGTalk Moderation
03-03-2009, 04:13 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.