Copy link to clipboard
Copied
I want to import a camera created in C4D into AE and convert the imported two-node camera into a one-node camera.
(The two-node camera has keyframes for both Point of Interest and Position.)
After asking ChatGPT, I got the following result:
// Get the active composition in After Effects
var comp = app.project.activeItem;
if (comp && comp instanceof CompItem) {
// Find the 'Two-Node Camera' layer and store it in a variable
var camLayer = comp.layer("Two-Node Camera");
if (camLayer && camLayer instanceof AVLayer && camLayer.hasCamera) {
// Get the Position and Point of Interest values of the two-node camera
var position = camLayer.transform.position;
var pointOfInterest = camLayer.camera.pointOfInterest;
// Create a one-node camera (new camera layer)
var oneNodeCam = comp.layers.addCamera("One-Node Camera", position.valueAtTime(0, false));
// Set the position of the one-node camera
oneNodeCam.transform.position.setValueAtTime(0, position.valueAtTime(0, false));
// Calculate the direction vector of the two-node camera: (Point of Interest - Camera Position)
var direction = [
pointOfInterest[0] - position.value[0],
pointOfInterest[1] - position.value[1],
pointOfInterest[2] - position.value[2]
];
// Convert the direction vector to the one-node camera's rotation values
var rotation = getRotationFromDirection(direction);
// Set the rotation of the one-node camera
oneNodeCam.transform.rotation.setValueAtTime(0, rotation);
// Copy keyframes from the two-node camera to the one-node camera
for (var i = 1; i <= camLayer.transform.position.keyCount; i++) {
var time = camLayer.transform.position.key(i).time;
oneNodeCam.transform.position.setValueAtTime(time, camLayer.transform.position.valueAtTime(time, false));
}
alert("Conversion to one-node camera completed!");
} else {
alert("No camera layer exists.");
}
} else {
alert("Please select a valid composition.");
}
// Function to calculate rotation values from the direction vector
function getRotationFromDirection(direction) {
// Convert the direction vector to rotation values
var pitch = Math.atan2(direction[1], Math.sqrt(direction[0] * direction[0] + direction[2] * direction[2])) * (180 / Math.PI);
var yaw = Math.atan2(direction[0], direction[2]) * (180 / Math.PI);
var roll = 0; // Roll value is set to 0 by default
return [pitch, yaw, roll];
}
I am trying to save it as a .jsx file, but it gives an error saying that there is no camera layer.
The two-node camera definitely exists in the layer, and I changed its name to "Two-Node Camera."
What is wrong?
Additionally, if there is a way to import the camera as a one-node camera directly from C4D to AE, or if there is a script I can purchase to do this, I would appreciate it if you could let me know.
thx.
Copy link to clipboard
Copied
The only way I know of to convert a two-node camera to a one-node camera would be like this:
var myCamera = app.project.activeItem.layer("Camera 1");
if (myCamera instanceof CameraLayer && myCamera.autoOrient == AutoOrientType.CAMERA_OR_POINT_OF_INTEREST){
myCamera.autoOrient = AutoOrientType.NO_AUTO_ORIENT;
}
Also, seriously, ChatGPT just makes stuff up. Your example has at least a couple of nonsensical, non-existent commands. Don't trust it for anything important or that you're going to hand off to anyone else.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now