Skip to main content
Inspiring
March 14, 2024
Question

There are issues encountered when baking camera animations using a script.

  • March 14, 2024
  • 1 reply
  • 238 views

I'm currently writing a script to bake camera animations. Due to the complex parent-child relationships of the camera, I've resorted to a somewhat clumsy approach: detaching the camera from its children, recording the values for that frame, reattaching its children, shifting the time indicator to the next frame...

I've implemented a for loop to record the camera position values at each frame of the time indicator. It runs successfully, but it only captures the position values of the camera for the first frame, rather than for each frame of the animation.



app.beginUndoGroup("11111");
var rawCamera = app.project.activeItem.layer(7);
var rawCameraParentIndex = rawCamera.parent.index;
var bakeCamera = app.project.activeItem.layer(8);
var timeIndicator = app.project.activeItem.time;
for (var i = 0; i <= 20; i++) {
    var timeIndicator = i / app.project.activeItem.frameRate;
    rawCamera.parent = null;
    bakeCamera.position.setValueAtTime(timeIndicator, rawCamera.position.value);
    bakeCamera.orientation.setValueAtTime(timeIndicator, rawCamera.orientation.value);
    rawCamera.parent = app.project.activeItem.layer(rawCameraParentIndex);
}
app.endUndoGroup();

 

This topic has been closed for replies.

1 reply

Mylenium
Legend
March 14, 2024

Your timeIndicator calculation probably doesn't make a lot of sense. Why don't you use internal methods like frameToTime()? Aside from that the typical way of avoiding convoluted procedures and potentialy false calculations is to apply a temporary expression, in your case one with toWorld(), presumably, then bake the keys and remove the expression again in the script.

 

Mylenium

damomoyuAuthor
Inspiring
March 20, 2024

"I'm sorry for the late reply.

.frameToTime() is an expression that converts time units to frame units, and .toWorld() is used to convert a three-dimensional coordinate to a two-dimensional one. However, these seem unrelated to my issue.

The complex camera animation I encountered looks something like this: Camera → Parent → Null A → Parent → Null B → Parent → Null C → Parent → Null D → Parent → Null E. Each null object has a different animation applied to it. To be honest, I'm not sure which expression can accurately reproduce the coordinates of my camera itself."