View Single Post
# 24 29-05-2012 , 10:20 AM
ctbram's Avatar
Moderator
Join Date: Jan 2004
Location: Michigan, USA
Posts: 2,998
I have a question for ND. Do we really want to maintain the global world space pivot or would it not be more appropriate to maintain the relative object space pivot?

I would just add a line to save the object space pivot -

float $osPivot[] = `xform -q -os -rp $obj';

and replace the line that restores the world space pivot with -

xform -os -rp $osPivot[0] $osPivot[1] $osPivot[2] $obj;

With this version the objects pivot maintains its relative position to the object when it is moved. Wouldn't this be better?

Here is a modified version of the code to maintain the relative pivot of each object as it is moved...

Code:
// procedure rmToFloor()
// Move the lowest point of all objects in the selection so they sit exactly on the 
// top of the grid (global Y=0).
// 
// usage: rmToFloor();
// Copy this script to your maya scripts folder and source it and then make a selection of all
// the objects you want to move so they are sitting on the grid and enter the command
// rmToFloor;. 
//
// notes: 
//(1) This procedure depends on the mel command "exactWorldBoundingBox $obj" which 
// returns a float[] xmin ymin zmin xmax ymax zmax.  I use ymin to temporarily set
// the Y position of $obj's pivot so I can move it along Y such that it sits on the grid. 
// Moving each object to the grid has a constant complexity O(1).  This procedure has a 
// complexity of O(n), where n is the number of objects in the selection.
//
// [strike](2) this procedure moves the object but leaves the objects pivot in the same worldspace
// location.  I am not sure of the value of doing this and may want to either keep the
// local (relative) pivot location or just center the pivot.
//
// (3) changed the script to maintain the relative pivot when the object is moved.
// 
// author: ctbram with valuable input from nextdesign
// date: 05292012
//
// change log:
// 05292012 - changed the program so the relative pivot of the object is maintained rather
// then the world pivot
//
global proc rmToFloor()
{
    string $sel[] = `ls -sl`;
    string $obj;
    
    for($obj in $sel)
    {
         float $osPivot[] = `xform -q -os -rp $obj`;                // save the object space (relative) pivot
         
	 // move the object using world space coordinates...
	 float $wsPivot[] = `xform -q -ws -rp $obj`;                // save world space $obj pivot
         float $bbox[] = `exactWorldBoundingBox $obj`;              // get bounding box world space coords
         float $lowest = $bbox[1];                                  // get lowest vert (ymin)
         xform -ws -rp $wsPivot[0] $lowest $wsPivot[2] $obj;        // reset the pivot to the lowest point in world space
         move -rpr $wsPivot[0] 0 $wsPivot[2] $obj;                  // move the object to the grid
         
         xform -os -rp $osPivot[0] $osPivot[1] $osPivot[2] $obj;    // restore the object space (relative) pivot
    }
}


"If I have seen further it is by standing on the shoulders of giants." Sir Isaac Newton, 1675

Last edited by ctbram; 29-05-2012 at 10:37 AM.