CGTalk > Software Specific Forums > Autodesk Maya > Maya Programming
To minimize the ads you see on this page create a CGTalk account and log in HERE
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 12-16-2012, 06:12 PM   #1
cgbeige
Expert
 
cgbeige's Avatar
portfolio
Dave Girard
Opinions are mine. You can't have them.
San_Francisrococo, USA
 
Join Date: Jul 2005
Posts: 6,999
how to get local bounding box values?

I'm making a simple pivot toolbox and have it set up for world space bbox coordinates but I'm wondering how to get these values as something that can be input into the xform -piv command:



That's an arbitrarily rotated object so world space doesn't work and querying/setting object space sets the pivot in the wrong spot. I want to be able to set the pivot to any point on the local bounding box (mid, min, max). I realize Local Tools does this but I just want to know for myself
 
Old 12-16-2012, 08:26 PM   #2
zaskar
Expert
portfolio
franky****inFourFingaz
-
Dresden, Germany
 
Join Date: Dec 2010
Posts: 321
Now you have the shape node with its local bounding box information and the transformation matrix of the parent transform. With both you can calculate the world space points of the local bbox midpoints as you sketched. Either use some python api or faster, use mel:

Code:
{ string $sel[] = `ls -sl`; string $shape[] = `ls -dag -shapes $sel[0]`; string $mat = `createNode pointMatrixMult`; connectAttr ($sel[0] + ".worldMatrix") ($mat + ".inMatrix"); float $bbOSMin[] = `getAttr ($shape[0] + ".boundingBoxMin")`; float $bbOSMax[] = `getAttr ($shape[0] + ".boundingBoxMax")`; //midPoint of +z float $zPositive[] = {(($bbOSMin[0] + $bbOSMax[0]) * .5),(($bbOSMin[1] + $bbOSMax[1]) * .5),$bbOSMax[2]}; setAttr ($mat + ".inPoint") $zPositive[0] $zPositive[1] $zPositive[2]; float $result[] = `getAttr ($mat + ".output")`; print $result; delete $mat; }
 
Old 12-17-2012, 03:26 PM   #3
cgbeige
Expert
 
cgbeige's Avatar
portfolio
Dave Girard
Opinions are mine. You can't have them.
San_Francisrococo, USA
 
Join Date: Jul 2005
Posts: 6,999
thanks - it was more work than I thought it would be so this is a big help.
 
Old 12-17-2012, 05:35 PM   #4
cgbeige
Expert
 
cgbeige's Avatar
portfolio
Dave Girard
Opinions are mine. You can't have them.
San_Francisrococo, USA
 
Join Date: Jul 2005
Posts: 6,999
ok - I seem to be almost there but these min/max values aren't correct for some reason - the mid ones work fine. If you can figure out where I'm wrong, it would be great. This is the first time I'm dealing with matrixes for stuff like this.

Code:
//START LOCATION BBOX proc string $sel[] = `ls -sl`; //do the X coords switch($currentXPivotMenuSelection) { case "min": for ($n=0 ; $n<size($sel) ; $n++) { string $shape[] = `ls -dag -shapes $sel[$n]`; string $matrixZee = `createNode pointMatrixMult`; connectAttr ($sel[$n] + ".worldMatrix") ($matrixZee + ".inMatrix"); float $bbOSMin[] = `getAttr ($shape[0] + ".boundingBoxMin")`; float $bbOSMax[] = `getAttr ($shape[0] + ".boundingBoxMax")`; //minPoint of +x float $zPositive[] = {$bbOSMin[0],(($bbOSMin[1] + $bbOSMax[1]) * .5),$bbOSMin[2]}; setAttr ($matrixZee + ".inPoint") $zPositive[0] $zPositive[1] $zPositive[2]; float $resuloot[] = `getAttr ($matrixZee + ".output")`; xform -ws -piv $resuloot[0] $resuloot[1] $resuloot[2] $sel[$n]; } break; case "mid": for ($n=0 ; $n<size($sel) ; $n++) { string $shape[] = `ls -dag -shapes $sel[$n]`; string $matrixZee = `createNode pointMatrixMult`; connectAttr ($sel[$n] + ".worldMatrix") ($matrixZee + ".inMatrix"); float $bbOSMin[] = `getAttr ($shape[0] + ".boundingBoxMin")`; float $bbOSMax[] = `getAttr ($shape[0] + ".boundingBoxMax")`; //midPoint of +z float $zPositive[] = {(($bbOSMin[0] + $bbOSMax[0]) * .5),(($bbOSMin[1] + $bbOSMax[1]) * .5),(($bbOSMin[2] + $bbOSMax[2]) * .5)}; setAttr ($matrixZee + ".inPoint") $zPositive[0] $zPositive[1] $zPositive[2]; float $resuloot[] = `getAttr ($matrixZee + ".output")`; xform -ws -piv $resuloot[0] $resuloot[1] $resuloot[2] $sel[$n]; } break; case "max": for ($n=0 ; $n<size($sel) ; $n++) { string $shape[] = `ls -dag -shapes $sel[$n]`; string $matrixZee = `createNode pointMatrixMult`; connectAttr ($sel[$n] + ".worldMatrix") ($matrixZee + ".inMatrix"); float $bbOSMin[] = `getAttr ($shape[0] + ".boundingBoxMin")`; float $bbOSMax[] = `getAttr ($shape[0] + ".boundingBoxMax")`; //midPoint of +z float $zPositive[] = {$bbOSMax[0],(($bbOSMin[1] + $bbOSMax[1]) * .5),$bbOSMax[2]}; setAttr ($matrixZee + ".inPoint") $zPositive[0] $zPositive[1] $zPositive[2]; float $resuloot[] = `getAttr ($matrixZee + ".output")`; xform -ws -piv $resuloot[0] $resuloot[1] $resuloot[2] $sel[$n]; } break; default: $currentXPivotMenuSelection = "min"; } //do the Y coords switch($currentYPivotMenuSelection) { case "min": for ($n=0 ; $n<size($sel) ; $n++) { float $currentPivCoord[]=`xform -q -ws -piv $sel[$n]`; string $shape[] = `ls -dag -shapes $sel[$n]`; string $matrixZee = `createNode pointMatrixMult`; connectAttr ($sel[$n] + ".worldMatrix") ($matrixZee + ".inMatrix"); float $bbOSMin[] = `getAttr ($shape[0] + ".boundingBoxMin")`; float $bbOSMax[] = `getAttr ($shape[0] + ".boundingBoxMax")`; //minPoint of +y float $zPositive[] = {(($bbOSMin[0] + $bbOSMax[0]) * .5),($bbOSMin[1]),$bbOSMin[2]}; setAttr ($matrixZee + ".inPoint") $zPositive[0] $zPositive[1] $zPositive[2]; float $resuloot[] = `getAttr ($matrixZee + ".output")`; xform -ws -piv $currentPivCoord[0] $resuloot[1] $resuloot[2] $sel[$n]; } break; case "mid": for ($n=0 ; $n<size($sel) ; $n++) { float $currentPivCoord[]=`xform -q -ws -piv $sel[$n]`; string $shape[] = `ls -dag -shapes $sel[$n]`; string $matrixZee = `createNode pointMatrixMult`; connectAttr ($sel[$n] + ".worldMatrix") ($matrixZee + ".inMatrix"); float $bbOSMin[] = `getAttr ($shape[0] + ".boundingBoxMin")`; float $bbOSMax[] = `getAttr ($shape[0] + ".boundingBoxMax")`; //midPoint of +z float $zPositive[] = {(($bbOSMin[0] + $bbOSMax[0]) * .5),(($bbOSMin[1] + $bbOSMax[1]) * .5),(($bbOSMin[2] + $bbOSMax[2]) * .5)}; setAttr ($matrixZee + ".inPoint") $zPositive[0] $zPositive[1] $zPositive[2]; float $resuloot[] = `getAttr ($matrixZee + ".output")`; xform -ws -piv $currentPivCoord[0] $resuloot[1] $resuloot[2] $sel[$n]; } break; case "max": for ($n=0 ; $n<size($sel) ; $n++) { float $currentPivCoord[]=`xform -q -ws -piv $sel[$n]`; string $shape[] = `ls -dag -shapes $sel[$n]`; string $matrixZee = `createNode pointMatrixMult`; connectAttr ($sel[$n] + ".worldMatrix") ($matrixZee + ".inMatrix"); float $bbOSMin[] = `getAttr ($shape[0] + ".boundingBoxMin")`; float $bbOSMax[] = `getAttr ($shape[0] + ".boundingBoxMax")`; //midPoint of +z float $zPositive[] = {(($bbOSMin[0] + $bbOSMax[0]) * .5),($bbOSMax[1]),$bbOSMax[2]}; setAttr ($matrixZee + ".inPoint") $zPositive[0] $zPositive[1] $zPositive[2]; float $resuloot[] = `getAttr ($matrixZee + ".output")`; xform -ws -piv $currentPivCoord[0] $resuloot[1] $resuloot[2] $sel[$n]; } break; default: $currentYPivotMenuSelection = "min"; } //do the Z coords switch($currentZPivotMenuSelection) { case "min": for ($n=0 ; $n<size($sel) ; $n++) { float $currentPivCoord[]=`xform -q -ws -piv $sel[$n]`; string $shape[] = `ls -dag -shapes $sel[$n]`; string $matrixZee = `createNode pointMatrixMult`; connectAttr ($sel[$n] + ".worldMatrix") ($matrixZee + ".inMatrix"); float $bbOSMin[] = `getAttr ($shape[0] + ".boundingBoxMin")`; float $bbOSMax[] = `getAttr ($shape[0] + ".boundingBoxMax")`; //minPoint of +z float $zPositive[] = {(($bbOSMin[0] + $bbOSMax[0]) * .5),(($bbOSMin[1] + $bbOSMax[1]) * .5),$bbOSMin[2]}; setAttr ($matrixZee + ".inPoint") $zPositive[0] $zPositive[1] $zPositive[2]; float $resuloot[] = `getAttr ($matrixZee + ".output")`; xform -ws -piv $currentPivCoord[0] $currentPivCoord[1] $resuloot[2] $sel[$n]; } break; case "mid": for ($n=0 ; $n<size($sel) ; $n++) { float $currentPivCoord[]=`xform -q -ws -piv $sel[$n]`;//problematic string $shape[] = `ls -dag -shapes $sel[$n]`; string $matrixZee = `createNode pointMatrixMult`; connectAttr ($sel[$n] + ".worldMatrix") ($matrixZee + ".inMatrix"); float $bbOSMin[] = `getAttr ($shape[0] + ".boundingBoxMin")`; float $bbOSMax[] = `getAttr ($shape[0] + ".boundingBoxMax")`; //midPoint of +z float $zPositive[] = {(($bbOSMin[0] + $bbOSMax[0]) * .5),(($bbOSMin[1] + $bbOSMax[1]) * .5),(($bbOSMin[2] + $bbOSMax[2]) * .5)}; setAttr ($matrixZee + ".inPoint") $zPositive[0] $zPositive[1] $zPositive[2]; float $resuloot[] = `getAttr ($matrixZee + ".output")`; xform -ws -piv $currentPivCoord[0] $currentPivCoord[1] $resuloot[2] $sel[$n]; } break; case "max": for ($n=0 ; $n<size($sel) ; $n++) { float $currentPivCoord[]=`xform -q -ws -piv $sel[$n]`; string $shape[] = `ls -dag -shapes $sel[$n]`; string $matrixZee = `createNode pointMatrixMult`; connectAttr ($sel[$n] + ".worldMatrix") ($matrixZee + ".inMatrix"); float $bbOSMin[] = `getAttr ($shape[0] + ".boundingBoxMin")`; float $bbOSMax[] = `getAttr ($shape[0] + ".boundingBoxMax")`; //midPoint of +z float $zPositive[] = {(($bbOSMin[0] + $bbOSMax[0]) * .5),(($bbOSMin[1] + $bbOSMax[1]) * .5),$bbOSMax[2]}; setAttr ($matrixZee + ".inPoint") $zPositive[0] $zPositive[1] $zPositive[2]; float $resuloot[] = `getAttr ($matrixZee + ".output")`; xform -ws -piv $currentPivCoord[0] $currentPivCoord[1] $resuloot[2] $sel[$n]; } break; default: $currentZPivotMenuSelection = "min"; }
 
Old 12-17-2012, 08:38 PM   #5
zaskar
Expert
portfolio
franky****inFourFingaz
-
Dresden, Germany
 
Join Date: Dec 2010
Posts: 321
Hard to explain what the failure in your code above is, english isnt my favourite language. So here is a simplified but fully working version of your code:
Code:
string $sel[] = `ls -sl`; for ($n=0 ; $n<size($sel) ; $n++){ string $shape[] = `ls -dag -shapes $sel[$n]`; float $bbOSMin[] = `getAttr ($shape[0] + ".boundingBoxMin")`; float $bbOSMax[] = `getAttr ($shape[0] + ".boundingBoxMax")`; float $bbXValues[] = { $bbOSMin[0], (($bbOSMin[0] + $bbOSMax[0]) * .5), $bbOSMax[0]}; float $bbYValues[] = { $bbOSMin[1], (($bbOSMin[1] + $bbOSMax[1]) * .5), $bbOSMax[1]}; float $bbZValues[] = { $bbOSMin[2], (($bbOSMin[2] + $bbOSMax[2]) * .5), $bbOSMax[2]}; float $pivX, $pivY, $pivZ; switch($currentXPivotMenuSelection) { case "min": $pivX = $bbXValues[0]; break; case "mid": $pivX = $bbXValues[1]; break; case "max": $pivX = $bbXValues[2]; break; default: $pivX = $bbXValues[0]; }; switch($currentYPivotMenuSelection) { case "min": $pivY = $bbYValues[0]; break; case "mid": $pivY = $bbYValues[1]; break; case "max": $pivY = $bbYValues[2]; break; default: $pivY = $bbYValues[0]; }; switch($currentZPivotMenuSelection) { case "min": $pivZ = $bbZValues[0]; break; case "mid": $pivZ = $bbZValues[1]; break; case "max": $pivZ = $bbZValues[2]; break; default: $pivZ = $bbZValues[0]; }; string $matrixZee = `createNode pointMatrixMult`; connectAttr ($sel[$n] + ".worldMatrix") ($matrixZee + ".inMatrix"); setAttr ($matrixZee + ".inPoint") $pivX $pivY $pivZ; float $resuloot[] = `getAttr ($matrixZee + ".output")`; xform -ws -piv $resuloot[0] $resuloot[1] $resuloot[2] $sel[$n]; delete $matrixZee; }; select $sel;
 
Old 12-17-2012, 09:03 PM   #6
cgbeige
Expert
 
cgbeige's Avatar
portfolio
Dave Girard
Opinions are mine. You can't have them.
San_Francisrococo, USA
 
Join Date: Jul 2005
Posts: 6,999
awesome - thanks. This works great.
 
Old 12-17-2012, 09:03 PM   #7
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 02:33 PM.


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