Page 1 of 1

Place and orient layer on a plane formed by three points

Posted: October 11th, 2004, 5:22 pm
by Donat
Hi,

When I import data from a 3D soft or from a 3D tracker into AE, I need to place and orient a layer to some nulls coming from the 3D data. Instead of adjusting this manually you can use the following expression. Remember that this expression uses three nulls/lights/layers that should be placed on top of the layer to be placed.

Position expression:

Code: Select all

a = thisComp.layer(thisLayer, -1).position;
b = thisComp.layer(thisLayer, -2).position;
c = thisComp.layer(thisLayer, -3).position;

(a+b+c)/3
[/color]

This places the layer in the middle of the three points.

You then have to add an expression for the orientation :

Code: Select all

a = thisComp.layer(thisLayer, -1).position;
b = thisComp.layer(thisLayer, -2).position;
c = thisComp.layer(thisLayer, -3).position;

n = cross ((a-b),(a-c));
orientation+lookAt(a, n)
[/color]

This will orient the layer to be parallel with the plane formed by the three points. You'll need to manually adjust the Z orientation though.

Any feedback or suggestions to make it better are really apreciated.

Donat

If only I'd looked at this a couple of weeks ago

Posted: December 21st, 2005, 6:05 pm
by glennser
I wish I had looked at this a couple of weeks ago as we were doing a lot of camera tracking and had to do exactly what this script is designed for, eyeing it in manually is no fun at all!!
As soon as I get a chance I'll try it out and let you know how it goes.
Glenn Stewart
1k Studios

Re: Place and orient layer on a plane formed by three points

Posted: April 29th, 2009, 3:53 pm
by dkvfx
Hi Donat

I've been trying to use this expression. It seems straight forward.
But when I apply it to a layer with 3 null points in space, the plane does not intersect the 3 null points.
Furthermore, if I change the order of the nulls the Normal changes. I don't get this... the normal would be the same whatever the order, at worst it would reverse direction, but not the orientation.
I cant figure out where its going wrong. The Maths are sound, so why doesn't this work for me. Grrrr!
I could have really used this today.
Any chance of a teeny weeny project example to put my hurting brain at its ease.

Re: Place and orient layer on a plane formed by three points

Posted: May 7th, 2009, 8:14 am
by kobyg
dkvfx,

I've check this expression and it worked for me !
I've used the same scenario you've described: 3 Null layers in 3D space in order to position and orient a solid according to them, and it worked great.

Note however for a few things:
1. You have to put the 3D layer JUST below the 3 Nulls.
2. Perhaps your layer is too small and that is why it doesn't intersect the 3 Null points ?
3. Try using square pixels.

Koby.