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

Linking a 2D layer to a 3D layer

Apr 26, 2009 Apr 26, 2009

Copy link to clipboard

Copied

Ok, i've come to my limitation of expression skills.

I've setuped a 3D composition, with various elements at various depths. One of this element is a Sun. I setuped a camera to do a pan inside my 3D world.

So far, so good. None of my elements are animated.

Now i'd like to link a lens flare on my sun, which is a 2D layer. I've tried with the "toWorld" and "toComp" expression, but i don't get any results as my 3D layer "Sun" is not moving. Only my camera (and for some reasons i mustn't turn my Lense flare into a 3D layer).

But i can't figure out how to calculate the position of my "Sun" layer inside my comp with an offset from the camera position.

I'm sure it's possible, but i'm so bad when it comes to heavy math.

TOPICS
Expressions

Views

7.9K

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

correct answers 1 Correct answer

Community Expert , Apr 26, 2009 Apr 26, 2009

Try adding the expression to the Lens Flair Center and not to the solid position. If you also want to animate the lens flair a bit change the expression to this:

L = thisComp.layer("sun");

value + L.toComp(L.anchorPoint)

Works for me (project file)

Votes

Translate

Translate
Community Expert ,
Apr 26, 2009 Apr 26, 2009

Copy link to clipboard

Copied

Did you try it this way?

L = thisComp.layer("sun");
L.toComp(L.anchorPoint)

Dan

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
Apr 26, 2009 Apr 26, 2009

Copy link to clipboard

Copied

Yup Dan, that's the first thing i tried.

Either with toComp and toWorld, my layer reposition itself correctly on the first frame, but during the camera panning, it's position value stays the same whereas it should move, because the sun is "moving" because of the camera movement, and the 2D layer is not affected by my camera.

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
Community Expert ,
Apr 26, 2009 Apr 26, 2009

Copy link to clipboard

Copied

Try adding the expression to the Lens Flair Center and not to the solid position. If you also want to animate the lens flair a bit change the expression to this:

L = thisComp.layer("sun");

value + L.toComp(L.anchorPoint)

Works for me (project file)

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
Apr 26, 2009 Apr 26, 2009

Copy link to clipboard

Copied

Well i've just figured out what my problem is.

The "sun" i have to track is burried into 2 nested comps. The sun is in 2D space inside it's comp, it's comp is inside a 3D world, with 3D switch activated and rasterize switch on, and this comp is inside my main comp, also with 3D switch and rasterize on.

That's why it doesn't follow properly the sun layer. And the lens flare i have to add is not the built in lens flare, it's just a 2D layer with the "flare" designed on it.

So it looks like something like that:

MAIN COMP > BG COMP> SUN COMP > Sun Layer

My Lensflare is in Main comp, and so is my camera.

The expression right now looks like that (on the position of the lensflare):

c = comp("BG COMP").layer("SUN COMP");
p = c.toComp(c.anchor_point);

Is there a way to do something like:

c = comp("BG COMP").layer("SUN COMP").layer("Sun Layer");

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
Community Expert ,
Apr 26, 2009 Apr 26, 2009

Copy link to clipboard

Copied

The toComp only works within a comp but there's nothing that says you couldn't add a null to your main comp and link the null to the sun pre-comp position then point toComp to the null.

Something like this:

Null position expression :

comp("BG Comp").layer("Sun Comp").position

Flair layer Flare Center Expression:

L = thisComp.layer("Null 1");

L.toComp(L.anchorPoint)

That should work just fine.

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
Apr 26, 2009 Apr 26, 2009

Copy link to clipboard

Copied

Yeah, that's almost it !

Now i can track nearly properly the object. The only thing that makes it not following exactly is that my sun is inside a precomp with rasterize on and 3d switch on (to pass the 3D inside my comp), and this precomp is also moved in 3D space.

My sun, in it's comp, is 4000px in Z space, and it's comp is 300 in z space in my main comp (x,y axis are changed too). How do i calculate the acurate position on my null object. I've tried various things, but it gives me strange results.

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
Apr 26, 2009 Apr 26, 2009

Copy link to clipboard

Copied

My bad, it's totally working Rick. I just forgot to unparent my layer to a temporary null object.

Thank you !

[EDIT] Sorry i can't flag this answer as the correct answer as i already flagged it as a helpfull answer. I'll flag your first one instead.

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
Community Expert ,
Apr 26, 2009 Apr 26, 2009

Copy link to clipboard

Copied

Just for fun, here's how you can do it without the null:

L = comp("SUN COMP").layer("Sun Layer");
p1 = L.toWorld(L.anchorPoint);
p2 = comp("BG COMP").layer("SUN COMP").toWorld(p1);
thisComp.layer("BG COMP").toComp(p2)

Dan

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
Apr 26, 2009 Apr 26, 2009

Copy link to clipboard

Copied

Thanks Dan !

The lesser layer, the better !

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
Community Expert ,
Apr 27, 2009 Apr 27, 2009

Copy link to clipboard

Copied

LATEST

That's brilliant Dan. I never would have thought of using the toWorld function as a variable.

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