Moving back and forth in a sequence

Scripting for After Effects

Moving back and forth in a sequence

Postby panzo on 11/7/2012, 8:25 am

Hi guys,

I hope I can find help here to something I'm not able to selfeducate.

There's a footage png-sequence showing a 3d-object turning 360° in 100 pics. This should move along a motionpath and rotate accordingly.

So, what I wanna do is using expressions to calculate the moving-angle and show the appropriate frame of the png-sequence. Here's a simplified flash to show what I mean: http://www.specops12.com/archiv2012/ding/ding.html

Code could look maybe like this:

Code: Select all
   var distx:Number = mowerLayer.x - oldX;
   var disty:Number = mowerLayer.y - oldY;
   oldX = mowerLayer.x;
   oldY = mowerLayer.y;

   if (! distx && ! disty)
   {
      return;
   }

   var radiant:Number = Math.atan2(distx, disty);

   var targetFrame:int = Math.ceil(radiant/Math.PI * 100);

   mowerLayer.showFrame(targetFrame);


So far the theory.
I don't know if I can control a png-sequence-layer like this. I haven't found anything useful in the expressions-documentation.
Neither I found how I can get access to what I called "oldX / oldY". It seems like AE does not remember variables from a previous code-cycle.

Is this even possible with expressions?
panzo
 
Posts: 3
Joined: 11/7/2012, 8:18 am

Re: Moving back and forth in a sequence

Postby Mylenium on 11/7/2012, 11:36 am

panzo wrote:It seems like AE does not remember variables from a previous code-cycle.


Correct.

panzo wrote:Is this even possible with expressions?


Sure. Simply put everything in a while() loop and use valueAtTime() to retrieve the previous states. And do look up the help on expressions for the correct syntax and visit Dan Ebberts' site. You don't declare data types for variables in expressions nor is it necessary to actually define variables explicitly like in other ECMA script/ JavaScript flavors. It's a simple linear parser from top to bottom and arranging the operations in the right sequence will be good enough (and avoid redundant calculation cycles).

Mylenium
[Pour Mylène, ange sur terre]
----------------------------------------
www.mylenium.de - your After Effects resource
Mylenium
 
Posts: 3187
Joined: 02/1/2009, 11:45 am
Location: Germany

Re: Moving back and forth in a sequence

Postby panzo on 11/8/2012, 1:07 am

Hi Mylenium,

thanks for the help.
The declarations are my bad, I took parts of the code I wrote in flash and forgot to remove them.

Thanks to you and Dan Ebberts I figured out everything now, only thing left is the "mowerLayer.showFrame(targetFrame);"-Part, where I wan't to show a particular timeframe of one layer. Can you help me with this one?
panzo
 
Posts: 3
Joined: 11/7/2012, 8:18 am

Re: Moving back and forth in a sequence

Postby Maxweel on 11/8/2012, 7:13 am

If he only wants to associate a frame to a direction, does he really need a loop inside his expression?
Wouldn't it be enough to look only at position- position.valueAtTime(time-thisComp.frameDuration) to get the vector between the last frame and the new one, then compute the angle?

Code: Select all
delta = position-position.valueAtTime(time-thisComp.frameDuration);
radiansToDegrees(Math.atan2(delta[1], delta[0]))
Maxweel
 
Posts: 704
Joined: 03/12/2012, 8:21 am
Location: Ipswich, UK

Re: Moving back and forth in a sequence

Postby panzo on 11/8/2012, 8:36 am

*doublepost* didn't know I had to wait for admin-approval ;)
Last edited by panzo on 11/9/2012, 6:23 am, edited 1 time in total.
panzo
 
Posts: 3
Joined: 11/7/2012, 8:18 am

Re: Moving back and forth in a sequence

Postby Mylenium on 11/8/2012, 9:03 am

Depends on how the motion is created and what the PNGs actually show. You'd have to compensate for jittering since it's quite possible that at certain angles some images are skipped and that would best be done by basing the calculations on real time rather than simple frame math, which you would have to convert anyway, since we're talkikng time-remapping here. Of course a simpler approach might also work.

Mylenium
[Pour Mylène, ange sur terre]
----------------------------------------
www.mylenium.de - your After Effects resource
Mylenium
 
Posts: 3187
Joined: 02/1/2009, 11:45 am
Location: Germany

Re: Moving back and forth in a sequence

Postby Atom on 11/13/2012, 11:31 am

If you are still looking for a solution, here is a related thread on a similar subject.
viewtopic.php?f=5&t=92543
After Effects CS3, CS5, CS6
Windows 7 x64, OSX 10.6.8
Blender 3D
Atom
 
Posts: 177
Joined: 02/3/2010, 7:24 am


Return to After Effects Expressions