Freezing transforms doesn't freeze pivot?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 03 March 2013   #1
Freezing transforms doesn't freeze pivot?

So basically I created a script that moves the pivot to various parts of the object. Everything works fine until I freeze the transforms of the object. Here is what I have:


////////////////////
 //		 +Y	 //
 ////////////////////
 global proc MaxY()
 {
 	//Get the selected object(s)
 	string $Selection[] = `ls -sl`;
 	
 
 
 	//Loop through the objects
 	for($x = 0; $x < size($Selection); $x++)
 	{
 		
 		//Get the current pivot point location
 		float $pivot[] = `xform -q -t ($Selection[$x] + ".scalePivot")`;
 		
 		//Get the bounding box for Y
 		float $MinY = `getAttr ($Selection[$x] + ".boundingBoxMinY")`;
 		float $MaxY = `getAttr ($Selection[$x] + ".boundingBoxMaxY")`;
 		
 		//Calculate the new pivot point
 		float $PivotY = ($MaxY - $MinY) / 2;
 		
 		//Center the pivot
 		xform -cp $Selection[$x];
 		
 		move -r $pivot[0] $PivotY $pivot[2] ($Selection[$x] + ".scalePivot") ($Selection[$x] + ".rotatePivot");
 	}
 }
 ////////////////////
 //	 End +Y	 //
 ////////////////////


I'm still a beginner with MEL, any ideas why freezing the transforms messes up the code?
 
Old 03 March 2013   #2
Can you explain what you mean with "messing up the code" and "doesnt freeze pivot"?
 
Old 03 March 2013   #3
It doesn't really mess up the code, it just acts differently when the transforms of the object are frozen. If I run that bit of code with a newly created object it will put the pivot point at the top (Y) most point of that object. If I then freeze the transforms of that object and run the code again, it will put the pivot point for that object no where near the object in XY or Z.

So I'm guessing when click free transforms something is changing with the pivot location or the pivot location isn't "freezing".
 
Old 03 March 2013   #4
As long as you do not freeze objects their bounding box matches the objects local transformation. Freezing then resets the transformation relative to the parents space, so a new, axis aligned bounding box will be the result, all former object transformations go into the vertices/control points. Just put your viewport shading into bounding box mode, create a poly box, rotate it and group it, then rotate the group. Now freeze the cube and after that freeze the group and look what happens. Your script just behaves as it is supposed to be.
 
Old 03 March 2013   #5
why not just query worldspace bounding box coordinates with "xform -q -boundingBox -worldSpace", calculate object "top" from that bounding box (no center pivot shenanigans) and set pivot position with "xform -rotatePivot"? Not at maya right now so can't give exact code for that, but should be pretty straightforward.
__________________
Victor
ngskintools.com - skinning plugin for Autodesk Maya
 
Old 03 March 2013   #6
Ok I did what you suggested and everything is working. I have another procedure within the script that I can't figure out when the transforms are frozen. I am trying to center only X and Z, what I have now is:

////////////////////
 //	Center XZ   //
 ////////////////////
 global proc CenterXZ()
 {
 	//Get the selected object(s)
 	string $Selection[] = `ls -sl`;
 
 	//Loop through the objects
 	for($x = 0; $x < size($Selection); $x++)
 	{
 		//Get the current pivot point location
 		float $pivot[] = `xform -q -bb -ws ($Selection[$x] + ".scalePivot")`;
 		
 		//Center the pivot
 		xform -cp $Selection[$x];
 		
 		move -r 0 $pivot[1] 0 ($Selection[$x] + ".scalePivot") ($Selection[$x] + ".rotatePivot");
 	}
 }
 ////////////////////
 //  End Center XZ //
 ////////////////////


Which it does center X and Z, but Y keeps moving and I understand why. I have tried to calculate the center of X and Z and leave Y at 0 when moving the pivot but that didn't work. What I did was:

////////////////////
 //	Center XZ   //
 ////////////////////
 global proc CenterXZ()
 {
 	//Get the selected object(s)
 	string $Selection[] = `ls -sl`;
 
 	//Loop through the objects
 	for($x = 0; $x < size($Selection); $x++)
 	{
 		//Get the current pivot point location
 		float $pivot[] = `xform -q -bb -ws ($Selection[$x] + ".scalePivot")`;
 		
 		float $MinX = `getAttr ($Selection[$x] + ".boundingBoxMinX")`;
 		float $MaxX = `getAttr ($Selection[$x] + ".boundingBoxMaxX")`;
 		float $MinZ = `getAttr ($Selection[$x] + ".boundingBoxMinZ")`;
 		float $MaxZ = `getAttr ($Selection[$x] + ".boundingBoxMaxZ")`;
 		
 		float $PivotX = (($MaxX - $MinX) / 2) - $pivot[0];
 		float $PivotZ = (($MaxZ - $MinZ) / 2) - $pivot[2];
 		
 		move -r $PivotX 0 $PivotZ ($Selection[$x] + ".scalePivot") ($Selection[$x] + ".rotatePivot");
 	}
 }
 ////////////////////
 //  End Center XZ //
 ////////////////////


What would be the best way of centering just X and Z after the transforms are frozen?
 
Old 03 March 2013   #7
If you really only want to center XY in your new bounding box the math you use is wrong. The center is (bbMin + bbMax) * .5 . Also the positioning of the pivot you do is just adding the new values relative on top of your current position. Try this


 		 float $PivotX = ($MaxX + $MinX) / 2;
 		 float $PivotZ = ($MaxZ + $MinZ) / 2;
 		 
 
 		xform -ws -piv $PivotX $pivot[1] $PivotZ $Selection[$x];
 
 
Old 03 March 2013   #8
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 08:35 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.