/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ // Original file Copyright Crytek GMBH or its affiliates, used under license. proc int cryPivotTranslationLocked( string $node ) { if( `attributeExists "translate" $node` ) { if( `getAttr -lock ($node+".translateX")` || `getAttr -lock ($node+".translateY")` || `getAttr -lock ($node+".translateZ")` ) return 1; } return 0; } global proc int cryPivotRecurseMoveNode(int $centrePivots,string $node,vector $offset) { float $fpivot[]; vector $pivot; if(`attributeExists "intermediateObject" $node`) { if(`getAttr ($node+".intermediateObject")` == 1 ) return 1; // Stop processing this node but carry on with siblings. } if( `cryPivotTranslationLocked $node` ) { confirmDialog -title "Lumberyard Pivot" -message ("Failure. The node `"+$node+"` has locked transform attributes.") -button "OK" -defaultButton "OK"; return 0; // Fail. Exit all the way up the recusion. } if(`nodeType $node` == "transform") { if( $centrePivots == 1 ) { xform -centerPivots -preserve true $node; } $fpivot = `xform -q -os -rotatePivot $node`; xform -r -translation ($fpivot[0] - $offset.x) ($fpivot[1] - $offset.y) ($fpivot[2] - $offset.z) $node; xform -os -pivots (0) (0) (0) $node; $offset = <<$fpivot[0],$fpivot[1],$fpivot[2]>>; } else if(`nodeType $node` == "mesh") { int $eval[] = `polyEvaluate -v $node`; $vertCount = $eval[0]; move -r (-$offset.x) (-$offset.y) (-$offset.z) ($node+".vtx[0:"+$vertCount+"]"); } string $children[]; string $child; $children = `listRelatives -children -fullPath $node`; for ($child in $children) { if( `cryPivotRecurseMoveNode $centrePivots $child $offset` == 0 ) { return 0; // Fail. Exit all the way up the recursion } } return 1; // Success. } global proc cryPivotCloseWindow() { if(`window -ex CRYPIVOT_WINDOW`) { deleteUI -window CRYPIVOT_WINDOW; } } global proc cryPivotClickedRun() { int $centrePivots = 0; if(`window -ex CRYPIVOT_WINDOW`) { $centrePivots = `checkBox -q -v CRYPIVOT_CENTREPIVOTS`; } cryPivotRun($centrePivots); } global proc cryPivotRun(int $centrePivots) { $sellist = `ls -sl -long`; if(size($sellist) != 1) { confirmDialog -title "Lumberyard Pivot" -message "Wrong number of nodes selected, expected 1." -button "OK" -defaultButton "OK"; return; } cryPivotCloseWindow; string $node = $sellist[0]; if( `cryPivotRecurseMoveNode $centrePivots $node <<0,0,0>>` == 1 ) { confirmDialog -title "Lumberyard Pivot" -message "Origins set sucessfully." -button "OK" -defaultButton "OK"; } } proc cryPivotOptionWindow() { if(!`window -ex CRYPIVOT_WINDOW`) { if(`windowPref -exists CRYPIVOT_WINDOW`) { windowPref -wh 400 110 -tlc `windowPref -q -topEdge CRYPIVOT_WINDOW` `windowPref -q -leftEdge CRYPIVOT_WINDOW` CRYPIVOT_WINDOW; //windowPref -remove CRYPIVOT_WINDOW; } window -titleBar true -title "Fixup Node Origins" -widthHeight 400 110 -sizeable true -mnb false -mxb false CRYPIVOT_WINDOW; $layout1 = `formLayout -numberOfDivisions 100`; { columnLayout -adjustableColumn true CRYPIVOT_COL; { text -align "left" -label "This will move the origin of the selected node to it's pivot position.\nThe centre pivot option will centre the pivot point before moving the origin."; text -label ""; checkBox -label "Centre Pivots" -align "center" CRYPIVOT_CENTREPIVOTS; } setParent ..; } $runbutton = `button -label "Run" -command ("cryPivotClickedRun")`; $cancelbutton = `button -label "Cancel" -command ("cryPivotCloseWindow")`; setParent ..; formLayout -edit -attachForm CRYPIVOT_COL "top" 5 -attachForm CRYPIVOT_COL "left" 5 -attachForm CRYPIVOT_COL "right" 5 -attachControl CRYPIVOT_COL "bottom" 5 $cancelbutton -attachForm $runbutton "bottom" 5 -attachForm $runbutton "left" 5 -attachPosition $runbutton "right" 5 50 -attachNone $runbutton "top" -attachForm $cancelbutton "bottom" 5 -attachPosition $cancelbutton "left" 5 50 -attachForm $cancelbutton "right" 5 -attachNone $cancelbutton "top" $layout1; } showWindow CRYPIVOT_WINDOW; } global proc cryPivot() { cryPivotOptionWindow; }