PDA

View Full Version : how to find out an object's "true" transformation?


nessus
04-27-2006, 02:58 AM
I am trying to match transformation(trans, rot, scale) of one object to another. eg. if obj A is located at (12, 6, 5), i want to match obj B to that location as well. same idea goes for rotation and scale.

the problem right now is that if obj A is freezed, all its transformation info goes to zero. so at this stage if i want to match again, obj B would be transformed to the origin of the world which is not what i want.

logically i think maya has to store each object's "absolute" transform info somewhere (perhaps in a node) so that when two objects, for example at (1, 1, 1) and (5, 5, 5) are freezed, their values go back to 0 (1 for scale), but still maintain in their position and scale. The transform node in maya help looks like the node i am looking for, but after reading through the doc, i still dont find anything related to what i mentioned above.

perhaps someone with better knowledge of this node can give me some answers? thx!

john_homer
04-27-2006, 04:17 AM
check out the xform command.

you may need to use -piv
xform -ws -q -piv locator1;

read the docs on it..


.j

nessus
04-27-2006, 06:50 AM
thx alot john_homer,

I dont know too much about the mel commands and nodes, and your post certainly helps alot. As i was looking through the transform node of the object in attribute editor, i noticed under Pivots there are local/world space options which is exactly the same as what you have quoted in your post.

the good thing is: maya does keep "absolute" values of object's pivot points, so i can use them to match other object using these values.
the bad thing is: what if the user changes the piovt away from the object's center? then everything becomes all "relative" again.

i still dont get the part how and where maya stores an object's absolute transformation values? or its actually in the transform or xform node, i just dont see it?

Goon
04-27-2006, 07:31 AM
while we're talking about xform, I've got an issue where i grab world position
float $pos[3] = `xform -q -ws -a -rp $object`; and apply that position xform -ws -a -t $pos[0] $pos[1] $pos[2] $object2; So, simple stuff. Done it many times before. But no matter what, the second object will not go to the proper position. Are there any known, predictable causes for xform to fail at appying values?

john_homer
04-27-2006, 07:36 AM
Are there any known, predictable causes for xform to fail at appying values?

I would suspect...

frozen transforms.
parents with transforms.
parents with frozen transforms.

but I dont have time to ests 'em all.. ;^)

.j

nessus
04-27-2006, 08:29 AM
I would suspect...

frozen transforms.
parents with transforms.
parents with frozen transforms.

but I dont have time to ests 'em all.. ;^)

.j

so bassically if its frozen you cannot no longer determine its true transformation in terms of world space?

tciny
04-27-2006, 08:33 AM
no, because the transform has been applied to the vertices and is no longer present in the transform node

nessus
04-27-2006, 09:13 AM
this is more complicated than i initially thought of. so for what i am trying to do, it would make more sense to match translate of an object to a single vertex? what about rotation and scale?

the reason i want to implement something like this is because i have switched from XSI to maya, and match tranformation is a very common tool in XSI. so i would do something similar in maya as well.

john_homer
04-27-2006, 12:08 PM
inno, because the transform has been applied to the vertices and is no longer present in the transform node

interesting...

what about a locator?
or null?

.j

Robert Bateman
04-27-2006, 01:26 PM
a locator has a point (single vertex), however afaik, freeze transforms only affects those nodes that represent geometry (lattices, nurbs, polys, subdivs).

anyhow, given 3 points on similar meshes, the transform can always be deduced, however i've not got time at the moment to go through it.

LennO
04-27-2006, 01:48 PM
Why would you want a match transform using vertices? XSI doesn't do this as well. Transformations can always be matched, as long as you strictly work with world-space coordinates. Also, instead of dealing with complex hierarchies you should just unparent the specific object temporarily to circumvent any frozen-transform problems the parent might introduce. The world space coordinate of any object is it's rotate pivot position (which is the local axis in XSI and the thing that match transform operations in all applications match, and can be queried as john already pointed out). Frozen transforms are great when you're sure your objects position (controllers etc) are finalized but in most other situations, especially during modelling they are a bitch to work with…which is why i wrote a lil "center pivot" script that does NOT freeze transforms, as mayas default center pivot command does. Your case is similar. Matching rotation and scale will again pose some problems due to the way maya stores transforms. Froozen rotation and scale can't be so-to-say reverse engineered as you won't be able to derivate any kind of scale or orientation from the vertex data, unless you know that some edge should pe parallel to a given axis or your meshes are identical as Robert pointed out. In short, don't try match transforms on frozen objects for anything else then translation.

Cheers, Lennart

Stucky
04-27-2006, 04:26 PM
nessus I made a script to snap objects. You can download it here (http://www.highend3d.com/maya/downloads/mel_scripts/utility_external/misc/3731.html)

Take a look at it.

Cheers


-S

nessus
04-27-2006, 06:02 PM
Stucky, I have downloaded your mel script. Its the same case as i mentioned above. it works after freeze as long as the pivot is still in the center of the object. but if the user changes it, say the object is at (5, 5, 5), but he/she moves the pivot of rot and scale back to (0, 0, 0), the script will match the new object to (0, 0, 0) which is not the result i want.

LennO
Froozen rotation and scale can't be so-to-say reverse engineered as you won't be able to derivate any kind of scale or orientation from the vertex data...

now i think i understand the problem. same idea as "tciny" mentioned as well i think. actually this makes more sense to me now.

my thinking is: objects have volume in 3D space, its logically not acurate to say its position in 3D space anways, more precisely a coordinate system can only repersent one vertex a time. and an object is made of vertices(in polygon case), so even its frozen its values of vertices still preserved anyhow, and thats how maya keeps track of an object's position in 3D space.

learn something new everyday! thank you guys!!

LennO
04-27-2006, 06:28 PM
Stucky, I have downloaded your mel script. Its the same case as i mentioned above. it works after freeze as long as the pivot is still in the center of the object. but if the user changes it, say the object is at (5, 5, 5), but he/she moves the pivot of rot and scale back to (0, 0, 0), the script will match the new object to (0, 0, 0) which is not the result i want.

But that's what matching transforms does. As in XSI, the transformation values _are_ the pivot point location and orientation. When you match two objects transform you want pivot of object B to lineup with pivot of object A. As a result they have matching transformation values: their world matrix is identical. If you want two identical or almost identical objects to line up, regardless of their pivot point location, you'd approach it differently. What you'd want to do is to get the bounding box center of object A (which is a an attrib on any transform node.) Then you'd center the pivot of the object you want to move (Object B). Then do a move in worldspace coords to 0 0 0. Freeze Transforms again and then move it to the previously stored bounding box center values of object A. This works with frozen objects. However, you _cannot_ regain rotational information if an object rotation has been frozen, unless you do the following (which i believe is related to the last part of your message, which I honestly, didn't understand):

If you know that one edge of an object would be parallel to say, the global x axis, and another edge parallel to global z (if the object was at 0 0 0 rotation) you can create two vectors (x and z) for your new transform matrix by substracting vertex coordinates. The third axis (y) would be computed as x cross z. This will involve a lot of calculation and requires the user to select the specific edges/vertices, if they do exist at all. In the end though, this has not much to do with matching transforms. Matching transforms is just that: Transforms, not objects.

nessus
04-27-2006, 07:45 PM
Thank you LennO, sorry i understood how XSI does match transformation in a very wrong way.

By the way, "you _cannot_ regain rotational information if an object rotation has been frozen...". did u actually mean move the pivots away from the center of its object(which is the default position for all the pivots)? cuz i dont know how u can freeze a pivot in maya?

LennO
04-27-2006, 07:56 PM
Did u actually mean move the pivots away from the center of its object(which is the default position for all the pivots)? cuz i dont know how u can freeze a pivot in maya?

I believe you do, since you stated that very thing in your first post. Freezing a transform is when you, well, press exactly that menu-entry, which means that all transformation info (or only translation rotation or scale) are reset to 0 or 1 respectively. Rotation information gets lost and the rotation pivot will be aligned with the the global coordinate sys (hence rotation of 0 0 0.) Actually when you move a pivot away from an objects center (or the origin, where pivots of nulls/new objects default to)the translation info (.tx, .ty, .tz) is wrong, as the values will be kept. Hence the "true" position of any object where the pivot has been modified (or transform frozen) is the world rotate pivot position.

nessus
04-27-2006, 08:15 PM
OK, now i understand thats what u mean by freeze pivot.

for you 2nd last post, i believe find the bounding box of obj A and move obj B to the "center mass" of obj A is the way to approach my way of "match translate", at least thats how i thought about match translate an object to another.

since "xform -q -bb objA;" can return xmin ymin zmin xmax ymax zmax, it would be possible to calculate the "center mass" of this box and use it as the pivot to translate obj B to obj A.

sorry if i am still being picky about this, however this is how my colleagues ask about for this feature. at least thats what they want to have when they do "match translation".

LennO
04-27-2006, 08:40 PM
Well…just in case your colleagues were refering to XSI's match transforms: Tell them if they expect the same behaviour i XSI, they are required not to do anything else then they'd do in XSI. As long as you never move the pivot away from an objects center, no problem whatsoever. If you do that in XSI, you won't get the "object A on object B" as well, like you'd want it.

For a simple solution:

float $pos[3]=`xform -q -rp -ws objA`;
move -a -ws -rpr $pos[0] $pos[1] $pos[2] objB;

works when the pivot is at the center. Tell your colleagues to do a center pivot beforehand.

If not, query the boundingBoxCenter as in:

string $sel[]=`ls-sl`;
float $posX=getAttr($sel[0]+".boundingBoxCenterX");

and use those values.

goin
05-01-2006, 11:18 AM
see if this attached script works for you nessus. I had the problem myself when I first started to work with maya, so I wrote it. I use the pivot information stored in the transform node and put it back where it belongs ;-) So far it worked fine with the stuff I do. You might wanna give it a try....

cheers, Ingo

nessus
05-01-2006, 06:44 PM
see if this attached script works for you nessus. I had the problem myself when I first started to work with maya, so I wrote it. I use the pivot information stored in the transform node and put it back where it belongs ;-) So far it worked fine with the stuff I do. You might wanna give it a try....

cheers, Ingo

Thank you, Ingo. I wrote one myself too

Stucky
05-01-2006, 07:48 PM
have you solved the problem nessus? Did you try getting the bounding box center value as LennO said?


-S

nessus
05-02-2006, 04:38 PM
have you solved the problem nessus? Did you try getting the bounding box center value as LennO said?
Yes, i did that as well. big thx go to him! or her...

CGTalk Moderation
05-02-2006, 04:38 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.