Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions How to make each option in a dropdown menu to executing a set of data?

  • How to make each option in a dropdown menu to executing a set of data?

    Posted by Hiro Ober on October 14, 2024 at 10:43 am

    I’m creating a 3D camera animation template with the goal of exporting it as a .mogrt for PR users. The controllable properties include animation duration, media replacement, media position adjustments, and the ability to choose from multiple pre-set camera angles. The path animation for each camera angle is pre-defined, and the user won’t have control over it. Since the duration is variable, it’s tricky to set keyframes directly, so the camera path animations are done through expressions. In short, each camera angle animation is achieved using XYZ rotation and position parameters. For example, the parameters for the first angle might be a 15° Y-axis rotation and 200 units of X-axis position movement. Ideally, I’d like these camera animations to be presented in a dropdown menu, with options like:

    1. Bottom to top
    2. Top to bottom
    3. Left to right
    4. Right to left

    I have created and linked all the properties on a null object, but how should I encapsulate a bunch of position and rotation data into different options? I mean manually writing expressions on each property is tedious and hard to tweak, right? Any better solutions?

    Yoan Boisjoli replied 1 week, 4 days ago 2 Members · 3 Replies
  • 3 Replies
  • Yoan Boisjoli

    October 14, 2024 at 7:40 pm

    Hi Hiro! Something like this might work. I’m using ease() in this case but feel free to use easeOut(), easeIn() or linear() if you prefer.

    Position:

    var sel = effect(“Camera Angle”)(“Dropdown”);

    var duration = effect(“Animation Duration”)(“Slider”); // Assuming you have a duration slider

    // Define keyframes for each option

    var positions = [

    [[0, 0, 0], [200, 0, 0]], // Bottom to top

    [[0, 0, 0], [0, -200, 0]], // Top to bottom

    [[0, 0, 0], [-200, 0, 0]], // Left to right

    [[0, 0, 0], [200, 0, 0]] // Right to left

    ];

    // Calculate progress

    var t = time – inPoint;

    var progress = clamp(t / duration, 0, 1);

    // Interpolate using ease

    ease(progress, 0, 1, positions[sel-1][0], positions[sel-1][1]);

    And for Rotation:

    var sel = effect(“Camera Angle”)(“Dropdown”);

    var duration = effect(“Animation Duration”)(“Slider”);

    var rotations = [

    [[0, 0, 0], [0, 15, 0]], // Bottom to top

    [[0, 0, 0], [0, -15, 0]], // Top to bottom

    [[0, 0, 0], [0, 0, 15]], // Left to right

    [[0, 0, 0], [0, 0, -15]] // Right to left

    ];

    var t = time – inPoint;

    var progress = clamp(t / duration, 0, 1);

    ease(progress, 0, 1, rotations[sel-1][0], rotations[sel-1][1]);

    I haven’t tested it but let me know if this is what you were looking for. 🙂

  • Hiro Ober

    October 16, 2024 at 11:51 am

    Appreciate it mate! I reckon I don’t entirely understand it yet, but I’ll def give it try!

  • Yoan Boisjoli

    October 31, 2024 at 12:12 pm

    Hey Hiro! I finaly got to test the expression and it wasn’t working so here’s a working one with the right steps:

    1. Make a null object and link you camera to it.
    2. add a dropdown menu and two sliders
    3. paste this expression in the position:

    // Retrieve the selected direction and duration

    var direction = effect("Direction")(1).value;

    var duration = effect("Duration")(1).value;

    var distance = effect("Distance")(1).value;

    // Define movement parameters

    var startPos = [0, 0]; // Starting position (relative to current position)

    var endPos;

    // Determine end position based on selected direction

    switch (direction) {

    case 1: // Bottom to Top

    endPos = [0, -distance];

    break;

    case 2: // Top to Bottom

    endPos = [0, distance];

    break;

    case 3: // Left to Right

    endPos = [distance, 0];

    break;

    case 4: // Right to Left

    endPos = [-distance, 0];

    break;

    default:

    endPos = [0, 0];

    }

    // Determine current position using linear interpolation

    if (time < duration) {

    // Moving from startPos to endPos

    ease(time, 0, duration, startPos, endPos);

    } else {

    // After duration, stay at endPos

    endPos;

    }


    Here’s a screenshot of how it looks for me.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy