Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////////////////////////////////////////////////////////////
- //
- //
- // Reset rotation of objects using 3 vertices
- //
- // Features:
- // # restores rotation of objects
- // # resets world space transforms
- //
- // Usage:
- // # select 3 vertices in a 90 degree optimal angle
- // point - center of orientation
- // y - orientation of where Y-axis should point
- // z - orientation of where Z-axis should point
- // # hit run
- //
- // Criteria to work:
- // # if many objects are selected, they need to have identical vertex IDs on respective vertex
- //
- //
- //
- // Ludvig Lindqvist 1/7-2010
- //
- //////////////////////////////////////////////////////////////////////////////////////////
- // create window with 5 buttons
- global proc ludo_resetRotation()
- {
- if (`window -exists VFXresetRotationWin`) deleteUI -window VFXresetRotationWin;
- string $window = `window -title "reset rotation" -widthHeight 160 155 -s 0 VFXresetRotationWin`;
- columnLayout -adjustableColumn true;
- rowColumnLayout -nc 2 -cw 1 50 -cw 2 100;
- text -l "Origin" -al "center";
- $t = `button -label "vertex" -bgc 0.7 0.7 0.7 -c "getVert(1)" ludoVert1`;
- text -l "localY" -al "center";
- $t = `button -label "vertex" -bgc 0.7 0.7 0.7 -c "getVert(2)" -en 0 ludoVert2`;
- text -l "localZ" -al "center";
- $t = `button -label "vertex" -bgc 0.7 0.7 0.7 -c "getVert(3)" -en 0 ludoVert3`;
- text -l " " -al "center";
- string $clearButton = `button -label "clear" -bgc 0.8 0.8 0.8`;
- button -e -c "ludo_resetRotation()" $clearButton;
- setParent ..;
- separator;
- $t = `button -label "run on selected objects" -bgc 0.8 0.8 0.8 -c "createVertArray()" -en 0 ludoRunIt`;
- text -l "select 3 vertices" -en 0 -al "center";
- showWindow $window;
- }
- global proc getVert(int $id)
- {
- string $sel[] = `ls -sl -fl`;
- $sel = `filterExpand -sm 31`; // just verts please
- if (size($sel) == 1 ) {
- string $component = `match "\\..*" $sel[0]`;
- switch ($id) {
- case 1:
- $t = `button -e -label $component ludoVert1`;
- $t = `button -e -en 1 ludoVert2`;
- break;
- case 2:
- $t = `button -e -label $component ludoVert2`;
- $t = `button -e -en 1 ludoVert3`;
- break;
- case 3:
- $t = `button -e -label $component ludoVert3`;
- $t = `button -e -en 1 ludoRunIt`;
- break;
- }
- }
- }
- //////////////////////////////////////////////////////////////////////////////////////////
- // get all button labels with stores vertex data
- // check if all buttons are set
- global proc createVertArray(){
- string $selVert[];
- int $fail = 0;
- $selVert[0] = `button -q -label ludoVert1`;
- $selVert[1] = `button -q -label ludoVert2`;
- $selVert[2] = `button -q -label ludoVert3`;
- if($selVert[0] == "vertex") {
- $fail = 1;
- error("load vertex to all buttons");
- }
- if($selVert[1] == "vertex") {
- $fail = 1;
- error("load vertex to all buttons");
- }
- if($selVert[2] == "vertex") {
- $fail = 1;
- error("load vertex to all buttons");
- }
- if($fail == 0) getObjNames($selVert);
- }
- //////////////////////////////////////////////////////////////////////////////////////////
- // loop objects in this procedure
- // rebuilds the button string with previously stripped components eg. object.vtx[n], was previously .vtx[n]
- // runs through rest of linked procedures within the loop for each object
- // applies world coordinates for every object
- global proc getObjNames(string $selVert[]){
- string $objSel[] = `ls -sl -fl`;
- if(size($objSel)!=0){
- int $i;
- string $nVert[];
- $nVert[0] = $selVert[0];
- $nVert[1] = $selVert[1];
- $nVert[2] = $selVert[2];
- for($i = 0 ; $i<size($objSel) ; $i++){
- select $objSel[$i];
- FreezeTransformations;
- $selVert[0] = $objSel[$i] + $nVert[0];
- $selVert[1] = $objSel[$i] + $nVert[1];
- $selVert[2] = $objSel[$i] + $nVert[2];
- createEmitter($selVert, $objSel[$i]);
- }
- worldPos($objSel);
- }
- else error("select items to reset");
- }
- //////////////////////////////////////////////////////////////////////////////////////////
- // create emitters at specified vertices
- // call camera procedure for emitters
- global proc createEmitter(string $verts[], string $obj){
- string $emitterCollection[];
- string $tmp[];
- string $eName = $obj + "_emitter";
- int $i;
- for($i = 0 ; $i < 3 ; $i++){
- select $verts[$i];
- $tmp = `emitter -n $eName`;
- $emitterCollection[$i] = $tmp[1];
- }
- createCamera($emitterCollection, $obj);
- }
- //////////////////////////////////////////////////////////////////////////////////////////
- // create a "Camera Aim and Up"
- // move camera to the emitters tied to vertices
- // move Aim and Up to emitters
- // delete emitters
- global proc createCamera(string $emitterCollection[], string $obj){
- string $tmpCam[] = `camera`;
- cameraMakeNode 3 "";
- string $cam = $tmpCam[0];
- string $tmpStr;
- string $tmpCamera;
- float $vPos[];
- $tmpStr = $emitterCollection[2] + ".translate";
- $vPos = `getAttr $tmpStr`;
- $tmpCamera = $cam + ".translate";
- setAttr $tmpCamera -type "double3" $vPos[0] $vPos[1] $vPos[2];
- $tmpStr = $emitterCollection[0] + ".translate";
- $vPos = `getAttr $tmpStr`;
- $tmpCamera = $cam + "_aim.translate";
- setAttr $tmpCamera -type "double3" $vPos[0] $vPos[1] $vPos[2];
- $tmpStr = $emitterCollection[1] + ".translate";
- $vPos = `getAttr $tmpStr`;
- $tmpCamera = $cam + "_up.translate";
- setAttr $tmpCamera -type "double3" $vPos[0] $vPos[1] $vPos[2];
- for($i = 0 ; $i < 3 ; $i++){ select $emitterCollection[$i]; delete; }
- sunParentWhatever($cam, $obj);
- }
- //////////////////////////////////////////////////////////////////////////////////////////
- // parent object to camera then freeze object
- // unparent object to get relative rotations correct
- // delete camera
- global proc sunParentWhatever(string $cam, string $obj){
- parent $obj $cam;
- select $obj;
- FreezeTransformations;
- parent -w $obj;
- delete `listRelatives -p $cam`;
- }
- //////////////////////////////////////////////////////////////////////////////////////////
- // apply world coordinates
- global proc worldPos(string $sel[]){
- float $worldPos[];
- for ($obj in $sel){
- select $obj;
- $worldPos = `xform -q -ws -piv`;
- makeIdentity -apply true -t 1 -r 0 -s 1 -n 0 $obj;
- move -r -wd ($worldPos[0]*-1) ($worldPos[1]*-1) ($worldPos[2]*-1);
- makeIdentity -apply true -t 1 -r 0 -s 1 -n 0 $obj;
- move -r -wd $worldPos[0] $worldPos[1] $worldPos[2];
- }
- select $sel;
- }
- //////////////////////////////////////////////////////////////////////////////////////////
- ludo_resetRotation();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement