AE ENHANCERS

Expressions/Scripts/Presets
It is currently Wed Nov 26, 2014 1:33 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Using mask boundry box as a reference
PostPosted: Thu Nov 22, 2007 3:34 am 
Offline

Joined: Thu Nov 22, 2007 2:17 am
Posts: 3
Hello all!
First of all, i was inspireed by this expression; hxxp://www.motionscript.com/expressions ... lines.html

Now what I am after is, to use an animated Mask instead of the layer.
I have heard it many times, this is slightly impossible to do.
But after some Trial and Error-phases i realized this;
A Mask equals a position path.
When you have a rectangle mask, make a keyframe.
Whenever you copy this keyframe into another layers position property, you will notice 5 keyframes. `The first Keyframe is the position of the UpperLeft Vertice from your mask. the 2nd is the lowerleft position, the 3rd the lowerRight, the4th the upperright. The 5th keyframe is kind of useless.. its the connection between the 4th and 1st keyframe.
Lets say, this layer (with the 5 keyframes) we will name; keyframeLayer.

anyway.. I made 4 other solids;

UpperLeft: Position should equal the 1st keyframe from keyframeLayer.
LowerLeft: ,, ,, ,, ,, 2nd keyframe from keyframeLayer
LowerRight:,, ,, ,, ,, 3rd keyframe from keyframeLayer
UpperRight:,, ,, ,, ,, 4th keyframe from keyframeLayer

Is there an expression wich copies a keyframe into another layers property?
I want the position property of keyframeLayer to copy the keyframe from the animated mask.
And the 4 other layers to copy every 5th instance after the first keyframe;
For Upperleft this will mean it should copy keyframe no#1 and then the 6th,11th, etc etc.

Is this possible?
Hope you experts can help me!

Best Regards,


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 22, 2007 1:40 pm 
Offline

Joined: Sat Jun 26, 2004 10:01 am
Posts: 309
Location: Folsom, CA
At first I thought you were nuts. :-)

But now I think you might be on to something. There's still some work to do on this, but it's fun to play around with. This is a position expression for a layer to track a mask vertex on another layer. It assumes that the layer with the mask is named "target", that the mask's keyframes have been pasted into the corner layer's position, that the mask has 4 vertices, and the keyframes are linear. It also assumes that the corner layers are the top four layers in the layer stack.

Interesting stuff.

Code:
offset = 1;
m = thisComp.layer("target").mask("Mask 1").maskPath;
n = 0;
if (m.numKeys > 0){
  n = m.nearestKey(time).index;
    if (m.key(n).time > time){
      n--;
    }
}
if (n == 0){
  value;
}else{
  t1 = m.key(n).time;
  if (m.numKeys > n){
    t2 = m.key(n+1).time;
    linear(time,t1,t2,valueAtTime(key((n-1)*5 + offset).time),valueAtTime(key(n*5 + offset).time))
  }else{
    value;
  }
}


Dan

_________________
http://www.motionscript.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 22, 2007 2:23 pm 
Offline

Joined: Sat Jun 26, 2004 10:01 am
Posts: 309
Location: Folsom, CA
This is getting better. :-)

It appears to work with bezier mask points as well. And it works with more than four. One limitation is that you have to specify in the expression how many vertices there are (can't get at that info with an expression). I also corrected the code so that the follower layers stay in position after the last mask keyframe.

Code:
numVertices = 4;
offset = index;
m = thisComp.layer("target").mask("Mask 1").maskPath;
n = 0;
k = numVertices + 1;
if (m.numKeys > 0){
  n = m.nearestKey(time).index;
    if (m.key(n).time > time){
      n--;
    }
}
if (n == 0){
  value;
}else{
  t1 = m.key(n).time;
  if (m.numKeys > n){
    t2 = m.key(n+1).time;
    linear(time,t1,t2,valueAtTime(key((n-1)*k + offset).time),valueAtTime(key(n*k + offset).time))
  }else{
    valueAtTime(key(numKeys - index +1).time);
  }
}


Dan

_________________
http://www.motionscript.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 22, 2007 2:38 pm 
Offline

Joined: Sat Jun 26, 2004 10:01 am
Posts: 309
Location: Folsom, CA
OK - one more thing. If you easy ease all the mask keyframes, all you have to do in the expression is change linear() to ease(). Try it - it's very cool. :-)

Dan

_________________
http://www.motionscript.com


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 25, 2007 3:44 pm 
Offline

Joined: Thu Nov 22, 2007 2:17 am
Posts: 3
Thanks a lot man, for taking the time to experiment with this. I am really a newbie with those expressions. And yes.. i might be a bit nut. hehe..


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 27, 2007 1:55 am 
Offline

Joined: Thu Nov 22, 2007 2:17 am
Posts: 3
It actually works! Alltough only in CS3, but it works! This is really great! Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group