ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

get 3D position info in outer comp for 2d object in nested comp

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Steve Bentley
get 3D position info in outer comp for 2d object in nested comp
on Mar 23, 2018 at 2:11:24 pm

Example file attached in link: Ignore the text readouts they are just for me checking values. I've done it in CS6 so it's more compatible for everyone who hasn't upgraded yet. But I will be doing this in 2018 so if there is a newer library that will allow other methods, I'm game. - magicallyGetPosition()?

I have a child 2D object (object1) moving around in a preComp. (you can slide the time marker to see this happen)
preComp is a 3D layer in the outer Comp called "SimpleToOuterWorld". The preComp is a smaller comp than the outer comp.
I want to get the 3D position of object1 in the outerComp when the preComp layer is moved and scaled.
I can get this far, no issues. (although there must be a better way)

The problems start when I move the preComp layer and push it back into z depth.
A layer called tracker receives the position data and follows the nested object1 just fine as long as there is no z translation.
I thought once I got tracker able to work with position and scale, I could project that point to the outer comp's 2D space (or even world space) and then just replace the z position with the z position from the preComp layer. I wasn't sure how the position data would be presented to the camera once preComp had started into the distance.
I also tried calcing a vector from the 2D position to the virtual 3D position but no luck (and isn't that what all these world space transforms are doing anyway?)

The other comp is just another version of the outer comp called "finalPostitionAndScale" and it shows where preComp needs to move to (position,scale and position in z) and how the tracker and a 3D version of that tracker does not stick to the position of Object1.

I've had to use some cheats to get to this point - Tracker is parented to the preComp layer. I'd rather it not be because I'm going to use the final position data for a Particular system (2D layer, but 3D emitter position) - so the Particular layer can't scale and move with the moving preComp layer. And once the tracker is following the object1 around while preComp is at its z depth I wasn't sure if I could then do a spacetransform and tease its world position out. (relative to the outer comp)

Is there a solution to this? Is there a more elegant solution to get to the point I already have?


Return to posts index

Dan Ebberts
Re: get 3D position info in outer comp for 2d object in nested comp
on Mar 23, 2018 at 4:26:14 pm

I'm not exactly sure what you're trying to do, but this should give you the position of your Object1 layer within your finalPositionAndScale comp:

preComp = comp("preComp");
object = preComp.layer("Object1");
p1 = object.toComp(object.anchorPoint);
L = thisComp.layer("preComp");


Return to posts index

Steve Bentley
Re: get 3D position info in outer comp for 2d object in nested comp
on Mar 23, 2018 at 5:30:04 pm

Thanks Dan,
That did the trick. I guess I was overthinking it - assuming I would have to reintroduce the inner object to the new "world" of the outer differently sized comp, or, compToSurface the point on the layer that was in 3d and scaling and moving in depth. I'll post the fix so others can benefit. I actually thought I had tried this first but my layer getting the position info may have been parented or not in 3D at the time I tried it.

As always, you've made my day brighter.

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved