script to align layers between two points in 3d space

All things .jsx

Moderator: Paul Tuersley

Post Reply
cardeiro
Posts: 31
Joined: March 27th, 2006, 2:03 pm
Location: philadelphia, PA
Contact:

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.
Mike Cardeiro
------------------------------
Animator - Designer
D4 Creative Group
Philadelphia, PA
------------------------------
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

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
cardeiro
Posts: 31
Joined: March 27th, 2006, 2:03 pm
Location: philadelphia, PA
Contact:

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
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

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
cardeiro
Posts: 31
Joined: March 27th, 2006, 2:03 pm
Location: philadelphia, PA
Contact:

Perfect! Thanks Dan
Mike Cardeiro
------------------------------
Animator - Designer
D4 Creative Group
Philadelphia, PA
------------------------------
Post Reply