• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Issues with Multi-Axis Rotation in After Effects Script

Explorer ,
Jul 17, 2024 Jul 17, 2024

Copy link to clipboard

Copied

Hello,

I'm encountering issues with a script I've been working on for After Effects, which is designed to offset a layer's anchor point based on its rotation and position relative to a guide layer. The script works as expected when the layer has rotation only on one axis, but it fails to produce accurate results when the layer has rotations on two or three axes.

Here’s the code I'm using:

var layerPosition = layer.position.value;
var currentAnchor = layer.anchorPoint.value;
var guidePosition = guideLayer.position.value;

var guideX = guidePosition[0];
var guideY = guidePosition[1];
var guideZ = guidePosition[2];

var offsetX = guideX - layerPosition[0];
var offsetY = guideY - layerPosition[1];
var offsetZ = guideZ - layerPosition[2];

var layerOrientation = layer.orientation.value;
var layerRotationX = layerOrientation[0];
var layerRotationY = layerOrientation[1];
var layerRotationZ = layerOrientation[2];

var thetaX = layerRotationX * Math.PI / 180;
var thetaY = layerRotationY * Math.PI / 180;
var thetaZ = layerRotationZ * Math.PI / 180;

var cosThetaX = Math.cos(thetaX);
var sinThetaX = Math.sin(thetaX);
var cosThetaY = Math.cos(thetaY);
var sinThetaY = Math.sin(thetaY);
var cosThetaZ = Math.cos(thetaZ);
var sinThetaZ = Math.sin(thetaZ);

var rotatedOffsetX = offsetX * cosThetaZ + offsetY * sinThetaZ;
var rotatedOffsetY = -offsetX * sinThetaZ + offsetY * cosThetaZ;
var rotatedOffsetZ = offsetZ;

var tempX = rotatedOffsetX * cosThetaY - rotatedOffsetZ * sinThetaY;
var tempZ = rotatedOffsetX * sinThetaY + rotatedOffsetZ * cosThetaY;
rotatedOffsetX = tempX;
rotatedOffsetZ = tempZ;

var tempY = rotatedOffsetY * cosThetaX + rotatedOffsetZ * sinThetaX;
tempZ = -rotatedOffsetY * sinThetaX + rotatedOffsetZ * cosThetaX;
rotatedOffsetY = tempY;
rotatedOffsetZ = tempZ;

var newAnchorX = currentAnchor[0] + rotatedOffsetX;
var newAnchorY = currentAnchor[1] + rotatedOffsetY;
var newAnchorZ = currentAnchor[2] + rotatedOffsetZ;

 

I would appreciate it if someone could hel.

Thanks very much

 

 

TOPICS
FAQ , Scripting

Views

103

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 17, 2024 Jul 17, 2024

Copy link to clipboard

Copied

LATEST

Unless you properly convert the orientation to actual consistent angles or use matrices this of course won't work. The old Quarternions vs. Euler thing.

 

Mylenium 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines