How to clear out (set to 0) the rotation of a joint in Maya
Reset the "rotate" attribute of a Maya joint without changing its "Joint Orient" attribute or its world position - 04/2023 - #Jumble
You have two options to set the rotation x,y and z of a joint to zero (without affecting the world position of the rest of the joint hierarchy):
- - Freeze the joint (Menu:
Modify
->Freeze Transformation
), but this will bake in / set the "Joint Orientation" values. - - Unparent its direct child (select child Shift + P) set the rotation values to zero and re-parent it (select child then parent while pressing Shift then press P), this will change the translation values of the child but
Joint Orientation
will stay untouched
Here is a script to automatically reset the rotation of every joints inside a skeleton hierarchy without affecting the Joint Orient
attributes (this will modify translation values but joint position will stay the same relative to the world)
/* - Select root joint and call: source "clear_rotations.mel"; ROD_clear_rotation(); This will clear joint rotations. (joint orient stay the same though) */ global proc ROD_clear_rotation() { string $selected_joints[] = get_selected_joints(); if( size($selected_joints) != 1){ print("Selected the root joint"); return; } string $root_joint = get_root_of_type($selected_joints[0], "joint"); string $all_joints[] = `listRelatives -allDescendents -type "joint" $root_joint`; string $list_parents[] = {}; for($joint in $all_joints){ push_s($list_parents, get_parent($joint)); } int $acc = 0; for($joint in $all_joints){ if($list_parents[$acc] != "") parent -world $joint; $acc += 1; } $acc = 0; for($joint in $all_joints){ if($list_parents[$acc] != "") xform -absolute -rotation 0 0 0 $joint; $acc += 1; } $acc = 0; for($joint in $all_joints){ if($list_parents[$acc] != "") parent $joint $list_parents[$acc]; $acc += 1; } }
global proc string get_shape( string $xform ) { string $shape; if ( "transform" == `nodeType $xform` ) { string $parents[] = `listRelatives -fullPath -shapes $xform`; if( size($parents) > 0) { $shape = $parents[0]; } } else { // Assume it's already a shape; $shape = $xform; } return $shape; } // ----------------------------------------------------------------------------- global proc string[] get_shapes( string $xform[] ) { string $shapes[]; for ($node in $xform) { $shapes[size($shapes)] = get_shape($node); } return $shapes; } // ----------------------------------------------------------------------------- proc string[] filter_by_type( string $type, string $objects[] ) { string $new_list[]; for ($node in $objects) { if( $node != ""){ if( nodeType( $node ) == $type ){ $new_list[size($new_list)] = $node; } } } return $new_list; } // ----------------------------------------------------------------------------- /// @return highest dag node above '$node' and of type '$type' proc string get_root_of_type(string $node, string $type) { string $longname[] = ls("-l", $node); string $tokens[]; tokenize($longname[0], "|", $tokens); string $list[] = filter_by_type($type, $tokens); if( size($list) > 0 ) return $list[0]; else return ""; } // ----------------------------------------------------------------------------- proc string get_parent( string $node) { string $parent[] = `listRelatives -parent $node`; if( size($parent) ) { return $parent[0]; } else { return ""; } } // ----------------------------------------------------------------------------- proc push_s(string $array[], string $elt){ $array[ size($array) ] = $elt; } /// Add '$elt' only if it doesn't exist in '$array' global proc push_unique_s(string $array[], string $elt){ if( !exists_s( $array, $elt ) ){ push_s($array, $elt); } } /// @true if '$elt' is present in '$array' global proc int exists_s(string $array[], string $elt) { return stringArrayContains($elt, $array); } // ----------------------------------------------------------------------------- proc string[] get_selected_joints() { string $sel[] = `ls -selection -objectsOnly -long`; $sel = get_shapes($sel); string $list[]; for( $i = 0; $i < size($sel); $i++ ){ // Notice we reverse the order to garantee the active selection // comes first in the list push_unique_s($list, $sel[size($sel)-1-$i]); } return filter_by_type("joint", $list); }
No comments