Page 1 of 1

script to align layers between two points in 3d space

Posted: June 23rd, 2009, 9:40 am
by cardeiro
I just wrote a script trajectory. It creates two 3d nulls at the bottom of the composition. It will then take every layer in the composition, make them 3d and put a position expression that will distribute all the layers on a line between the two points. Once finished you can move the nulls and the layers will stay distributed between the points.

you can get the script at http://michaelcardeiro.com/aeScripts/ it is right below the spellcheck script

The only flaky part about it is that the z positions of the nulls need to be different otherwise the script tries to do a division by zero and throws an error. I really don't understand the math (sure wish I'd paid more attention in school instead of thinking I would never need this math) and because of that it took quite a while to come up with an algorithmm that worked...but I don't understand it enough to modify it to work when both z values are the same.

Re: script to align layers between two points in 3d space

Posted: June 23rd, 2009, 10:22 am
by Dan Ebberts
You could use this expression and eliminate the divide by zero issue:

n = thisComp.numLayers;
v1 = thisComp.layer(n-1).position;
v2 = thisComp.layer(n).position;
v1 + (v2 - v1)*(index/(n-1))


Dan

Re: script to align layers between two points in 3d space

Posted: June 24th, 2009, 6:10 am
by cardeiro
Dan Ebberts wrote:You could use this expression and eliminate the divide by zero issue:

n = thisComp.numLayers;
v1 = thisComp.layer(n-1).position;
v2 = thisComp.layer(n).position;
v1 + (v2 - v1)*(index/(n-1))
Wow, so much cleaner than my expression...the only problem with it is I always want the first layer to have the position of null1 and the last layer to have position of null2 and everything in between to be evenly dispersed along the line. So if there were three layers in the comp(not counting nulls) layer one would be where null1 is, layer 3 is where null 2 is and layer 2 is halfway between them; which works with my expression but chokes if the z position of both nulls are ever equal.

Mike Cardeiro

Re: script to align layers between two points in 3d space

Posted: June 24th, 2009, 6:27 am
by Dan Ebberts
Ah, OK. This would be better then:

Code: Select all

n = thisComp.numLayers;
v1 = thisComp.layer(n-1).position;
v2 = thisComp.layer(n).position;
if (index == 1){
  v1
}else if (index == n-2){
  v2
}else{
  v1 + (v2 - v1)*((index-1)/(n-3))
}
Dan

Re: script to align layers between two points in 3d space

Posted: June 24th, 2009, 7:54 am
by cardeiro
Perfect! Thanks Dan