View Full Version : Translating "Record Piv Rotations" to "Remove Pivot Rotations" space

09-01-2008, 10:32 PM
Hi all,

I have a need to translate bone rotations from "Recorded Pivot Rotations" space to "Remove Pivot Rotations" space.

"Record Piv Rotations" appears to store the world space HPB rotation and all following keyframed HPB values are relative to that (like defining an "identity" or initial offset rotation for each bone). One space can be converted to the other space by adding or subtracting each bone's initial offset rotation.

Translating the keyframes between RPR and non-RPR appears at first glance to be a simple translation.

I am able to translate all keyframes manually by first using "Remove Pivot Rotations" to reset the bone rotation from (0,0,0) to (h,p,b), and then shifting all keyframe values back into place by (-h,-p,-b). This would need to be done per bone, per axis and is not a workable solution.

Before I start researching scripts is anyone aware of any existing tools that could be used to apply a rotation translation HPB to each keyframe? Or even better, a way to translate the keyframed HPB values between "Recorded Pivot Rotations" and "Remove Pivot Rotations" values?

09-02-2008, 07:41 PM
OK I've had some success and thought I'd share. This script is a bit hack'n'slash and could benefit from a rewrite but it did the job and saved a week's worth of animation from being trashed.

Problem: Removing RPR (for say, use in an FBX character rig for import into a game engine like Unity) displaces keyframed bone animations.
Answer: Running this script after removing RPR will attempt to correct your keyframes using non-recorded pivot rotations.

@name "Repair Keyframe RPR"
@script generic
// Attempts to correct keyframed bone animations after an "Remove RPR" operation.
// Use this only on "inverted" bones that are approximately -180 or +180 degrees between 1st and 2nd key.
// Select one "inverted" bone and run this script once (typically there'll only be one or two bones in a rig that need this).
// Don't need to run this on every bone.
// Save this text as Repair Keyframe RPR.ls and add as plugin. It'll most likely be placed in the Utilities > Additional menu.
// This script assumes your rig is like mine, i.e. humanoid pitch aligned with frame zero T-pose

generic {
legalFirstAngle = 170; // how wide can the first frame angle be before it's considered bad (default 170)

s = Scene().firstSelect();
chan = s.firstChannel();
while(chan) {
if(chan.name == "Rotation.H" || chan.name == "Rotation.P" || chan.name == "Rotation.B" ) {
myKey = chan.keys[i]; // gets key identifier
myKeyValue = chan.getKeyValue(myKey); // gets value
if (i==1) {
// First key (T pose)? Attempt to fix problematic first key
if (myKeyValue < -legalFirstAngle && myKeyValue <0) {
// looks like first key is problematic under legal angle
chan.setKeyValue(chan.keys[i], myKeyValue + 180);
} else if (myKeyValue > legalFirstAngle && myKeyValue > 0) {
// looks like first key is problematic over legal angle
chan.setKeyValue(chan.keys[i], myKeyValue - 180);
// remember the first frame offset value
myOffset = chan.getKeyValue(myKey);
} else {
// add the first frame offset value to all other keys
chan.setKeyValue(myKey, myKeyValue+myOffset);
chan = s.nextChannel();

09-03-2008, 03:58 AM
Thanks for sharing. :thumbsup: