Convert 3d Rotation to Orientation

What type of scripts do you need?

Moderator: byronnash

Post Reply
floating.point
Posts: 7
Joined: May 12th, 2009, 5:15 pm

May 25th, 2009, 2:47 am

Okay I think this should (?) be an easy one

(but I am not at all savvy with scripting so perhaps someone else can whip something up?)

Basically I have a bunch of layers which were automatically distributed and aligned using Red Giant's Planespace.

Unfortunately this aligned the layers using orientation rather than rotation. I need these layers to be aligned using rotation rather than orientation...

So a script that could convert each layers orientation to rotation , or even swap between the 2, would be so incredibly beneficial and appreciated! :wink:


Ps. I know I could do this by hand, but I have A LOT of layers!!
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

May 25th, 2009, 7:12 am

This script will convert orientation values to rotation values for all 3D layers in the selected comp. I've assumed the layers don't have keyframed rotation/orientation values. If they do, the script will fail.

Code: Select all

{	
	var theComp = app.project.activeItem;
	
	if (theComp != null && theComp instanceof CompItem) {
		app.beginUndoGroup("Convert Orient To Rot");
		
		for (x = 1; x <= theComp.layers.length; x++) {
			
			if (theComp.layer(x) instanceof AVLayer && theComp.layer(x).threeDLayer == true) {
					theComp.layer(x).rotationX.setValue(theComp.layer(x).orientation.value[0]);
					theComp.layer(x).rotationY.setValue(theComp.layer(x).orientation.value[1]);
					theComp.layer(x).rotationZ.setValue(theComp.layer(x).orientation.value[2]);
					theComp.layer(x).orientation.setValue([0,0,0]);
			}
		}
		app.endUndoGroup();
	} else {
		alert("You need to select a composition first");
	}
}
floating.point
Posts: 7
Joined: May 12th, 2009, 5:15 pm

May 25th, 2009, 9:26 am

Thankyou Paul

What a great community the AE one is!!

Many Thanks,

Nathan.
floating.point
Posts: 7
Joined: May 12th, 2009, 5:15 pm

May 26th, 2009, 11:07 pm

Okay so what if the layer has rotation and orientation values set, and i need to convert it to just rotation values...

Need a script that looks at a 3d layers rotation and orientation values and bakes them into rotation values only.

Also, rather than applying it to the entire comp, applying it to selected layers would be fantastic!

Perhaps to make it usefull to a broader range of applications there could be a choice between baking to Rotation or baking to Orientation.

Anybodies help with this would be spectacular!
Yenaphe
Posts: 84
Joined: February 3rd, 2009, 6:30 pm
Location: Paris - France
Contact:

May 27th, 2009, 1:16 am

what do you mean by "baking" the orientation & rotation: adding the values, substracting the value, multiplying the values...

So much stuff can be done to "bake" them, i guess you'll have to be more specific :)
bartpop
Posts: 2
Joined: March 6th, 2010, 11:01 pm

October 16th, 2010, 12:37 am

This script will convert orientation values to rotation values for all 3D layers in the selected comp. I've assumed the layers don't have keyframed rotation/orientation values. If they do, the script will fail.
Hi Paul,

I'm looking for a script that will convert orientation keyframes to rotation keyframes. I've got a comp with 3000 orientation keyframes and need to figure out how to move them all to rotational values.

Cheers,
Bart
bartpop
Posts: 2
Joined: March 6th, 2010, 11:01 pm

October 18th, 2010, 10:34 am

I figured out a way to accomplish what I needed, though I'd love to know how to write this in script form.

I added an expression to each of my Rotation parameters, to set the values based on to the appropriate Orientation value:

transform.orientation[0]

for the X Rotation for example. I did this for each X,Y,Z Rotation value. I then applied the Animation > Keyframe Assistant > Convert expression to Keyframes command to apply the values to keyframes across the entire timeline. I then went to the first frame of the comp, deleted all of the Orientation keyframes and set the Orientation to 0,0,0.

This effectively converted all of my Orientation Keyframes to Rotation Keyframes. Not quite as elegant as a scripted version, perhaps someone can help me through the code to script this procedure? I compulsively like to know how things work.

Thanks,
Bart
davidjbourke
Posts: 1
Joined: October 30th, 2010, 10:58 pm

October 30th, 2010, 11:11 pm

Hi Paul,
I've been using your AE to C4D script recently in conjunction with The Foundry's AE tracker and its awesome. Great job.

I've just got an issue where some of my camera's have orientation on them instead of rotation, which doesn't export through your C4D script.

Is it possible for you to modify the above script to change the orientation of a camera to rotation, so that I can export it to C4D? The current script seems to ignore cameras.

Thanks for this, I'm new to all of this stuff but learning fast I promise. If I'm approaching this backwards let me know!

cheers,
Dave.
sshahriyari
Posts: 11
Joined: January 16th, 2017, 11:59 pm
Contact:

January 23rd, 2017, 10:55 am

Paul Tuersley wrote:This script will convert orientation values to rotation values for all 3D layers in the selected comp. I've assumed the layers don't have keyframed rotation/orientation values. If they do, the script will fail.

Code: Select all

{ 
 var theComp = app.project.activeItem;
 
 if (theComp != null && theComp instanceof CompItem) {
 app.beginUndoGroup("Convert Orient To Rot");
 
 for (x = 1; x <= theComp.layers.length; x++) {
 
 if (theComp.layer(x) instanceof AVLayer && theComp.layer(x).threeDLayer == true) {
 theComp.layer(x).rotationX.setValue(theComp.layer(x).orientation.value[0]);
 theComp.layer(x).rotationY.setValue(theComp.layer(x).orientation.value[1]);
 theComp.layer(x).rotationZ.setValue(theComp.layer(x).orientation.value[2]);
 theComp.layer(x).orientation.setValue([0,0,0]);
 }
 }
 app.endUndoGroup();
 } else {
 alert("You need to select a composition first");
 }
}
Hi,
I have a same question but...
how can convert all keyframe in layer?
runegan
Posts: 22
Joined: November 4th, 2016, 3:18 pm
Contact:

January 24th, 2017, 6:08 am

Hey, this is a rewrite of that script which will convert orientation values to rotation values for keyframes on all orientation properties in the active comp. It does not take the original values of the rotation properties into account, so any values or keyframes on those properties may be overwritten. It also ignores any easing on the keyframes, so that will be lost

Code: Select all

function orientationToRotation() {

// Get the active comp
var comp = app.project.activeItem

// Alert and stop script if active item is not a comp
if ( !comp || !( comp instanceof CompItem ) ) {
	alert( 'You need to select a composition first' )
	return
}

// Create undo group so any changes can be undone
app.beginUndoGroup( 'Convert Orient To Rot' )

// Loop through every layer in the comp
for ( var i = 1, il = comp.numLayers; i <= il; i++ ) {
	var layer = comp.layers[ i ]

	// Check if layer is 3D and AVlayer
	if ( layer.threeDLayer && layer instanceof AVLayer ) {
		convertOrientation( layer )
	}
}

app.endUndoGroup()

function convertOrientation( layer ) {

	// Check if there are keyframes on orientation property and call the appropiate function
	if ( layer.orientation.numKeys !== 0 ) {
		convertOrientationWithKeys( layer )
	} else {
		convertOrientationNoKeys( layer )
	}
}

function convertOrientationWithKeys( layer ) {
	var orientation = layer.orientation
	var rotX = layer.rotationX
	var rotY = layer.rotationY
	var rotZ = layer.rotationZ

	// Loop through all keyframes on orientation property
	// It loops backwards so keyframes can be removed as it loops
	for ( var i = orientation.numKeys; i > 0; i-- ) {
		var keyValue = orientation.keyValue( i )
		var keyTime = orientation.keyTime( i )

		// Set values on rotation properties at the current key time
		rotX.setValueAtTime( keyTime, keyValue[ 0 ] )
		rotY.setValueAtTime( keyTime, keyValue[ 1 ] )
		rotZ.setValueAtTime( keyTime, keyValue[ 2 ] )

		orientation.removeKey( i )
	}

	orientation.setValue( [ 0, 0, 0 ] )
}

function convertOrientationNoKeys( layer ) {
	var value = layer.orientation.value

	// Set values on rotation properties
	layer.rotationX.setValue( value[ 0 ] )
	layer.rotationY.setValue( value[ 1 ] )
	layer.rotationZ.setValue( value[ 2 ] )

	// Set orientation value back to default
	layer.orientation.setValue( [ 0, 0, 0 ] )
}

}
orientationToRotation()
sshahriyari
Posts: 11
Joined: January 16th, 2017, 11:59 pm
Contact:

April 30th, 2017, 2:04 am

use this script :
viewtopic.php?f=3&t=3087
Post Reply