Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Opacity based on distance from Camera: multiple nested compositions

  • Opacity based on distance from Camera: multiple nested compositions

    Posted by Edan Dover on May 17, 2011 at 2:25 pm

    I have three comps, each nested in the previous:

    MASTER > Scene1 > SongsRow1

    Inside SongsRow1, there is a layer called “test” that I’d like to fade out as it pulls a certain distance away from the camera.

    I am having trouble using “toWorld” to navigate all these nested comps… I’m still not 100% clear on how “toWorld” works. This is what I have (in the opacity field of layer “test”):


    startFade = thisComp.layer("controls").effect("startfade")("Slider");
    endFade = thisComp.layer("controls").effect("endfade")("Slider");
    C = comp("MASTER").activeCamera.toWorld([0,0,0]);
    P = comp("MASTER").layer("Scene1").toWorld(comp("Scene1").layer("SongsRow1").toWorld(thisComp.layer("test").anchorPoint)); // This is where the problem is, I think
    d = length(C,P);
    linear(d,startFade,endFade,100,0)

    Thanks!

    Dan Ebberts replied 15 years, 3 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    May 17, 2011 at 3:15 pm

    I think it’s easier to do each transform as a separate step. I haven’t tested this, but I’d try it this way:

    startFade = thisComp.layer(“controls”).effect(“startfade”)(“Slider”);
    endFade = thisComp.layer(“controls”).effect(“endfade”)(“Slider”);
    C = comp(“MASTER”).activeCamera.toWorld([0,0,0]);
    P1 = toWorld(anchorPoint); // convert test postion to SongsRow1 world space
    L2 = comp(“Scene1”).layer(“SongsRow1”);
    P2 = L2.toWorld(P1); // convert P1 to Scene1 world space
    L3 = comp(“MASTER”).layer(“Scene1”);
    P3 = L3.toWorld(P2); // convert P2 to MASTER world space
    d = length(C,P3);
    linear(d,startFade,endFade,100,0)

    Dan

  • Edan Dover

    May 17, 2011 at 4:13 pm

    Hey Dan, first, thanks for your help!

    Does your code account for if one of the parent compositions are moving? I tried it and I’m getting a result, but “d” only wiggles between 520 and 560 (due to a wiggle in the camera position), where in actuality that value should move from 0 to 10,000, because “SongsRow1” is moving further and further away from the camera..

  • Dan Ebberts

    May 17, 2011 at 4:33 pm

    It should. Are all of your “Collapse Transformation” switches turned on?

    Dan

  • Edan Dover

    May 17, 2011 at 6:37 pm

    yes they are…

  • Dan Ebberts

    May 17, 2011 at 8:44 pm

    OK – I just set up the three nested comps and it seems to work fine for me. I can go into any of the comps and move the nested, collapsed 3D layer around and the text fades in and out. I really don’t know why it doesn’t work for you.

    Dan

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