Expressions/Scripts/Presets

Moderators: Disciple, zlovatt

 
Berserker
Topic Author
Posts: 3
Joined: Thu Nov 22, 2007 2:17 am

Using mask boundry box as a reference

Thu Nov 22, 2007 3:34 am

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,
 
Dan Ebberts
Posts: 318
Joined: Sat Jun 26, 2004 10:01 am
Location: Folsom, CA
Contact:

Thu Nov 22, 2007 1:40 pm

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.

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
 
Dan Ebberts
Posts: 318
Joined: Sat Jun 26, 2004 10:01 am
Location: Folsom, CA
Contact:

Thu Nov 22, 2007 2:23 pm

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.

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
 
Dan Ebberts
Posts: 318
Joined: Sat Jun 26, 2004 10:01 am
Location: Folsom, CA
Contact:

Thu Nov 22, 2007 2:38 pm

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
 
Berserker
Topic Author
Posts: 3
Joined: Thu Nov 22, 2007 2:17 am

Sun Nov 25, 2007 3:44 pm

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..
 
Berserker
Topic Author
Posts: 3
Joined: Thu Nov 22, 2007 2:17 am

Tue Nov 27, 2007 1:55 am

It actually works! Alltough only in CS3, but it works! This is really great! Thanks!

Who is online

Users browsing this forum: No registered users and 2 guests