10 Replies Latest reply: Jan 28, 2012 5:42 AM by Lars Renklint RSS

    Create sphere on keyframes with expression

    Lars Renklint

      Hi,

       

      I've just begun to learn after effects and could use a little help.

       

      I have a small solid wich is moving around on the comp. This is done using expressions.

       

      What I would like to do is first to replace it with a 3d sphere.

      And secondly, instead of moving it, create a new sphere on each keyframe.

       

      First I imagined using trapcode particular, setting the particles count to 1. But that is per second, not per keyframe.

       

      Any ideas are appreciated.

       

      /Lars

        • 1. Re: Create sphere on keyframes with expression
          Lars Renklint Community Member

          My understanding right now is that there probably isn't a "create" method for creating shapes or objects in expressions. Please correct me if I'm wrong.

          Instead I should create my shape and then use expressions for duplicating that layer while repositioning it. Does this sound like the correct method?

           

          It would make sense that a keyframe couldn't hold an object. On the other hand it seems you could easily end up with a trillion layers in a comp..

          • 2. Re: Create sphere on keyframes with expression
            Dan Ebberts Community Member

            An expression can't create layers. You'd need a script for that. Also, AE doesn't have spheres. I'm not sure what you mean by that.

             

            Dan

            • 3. Re: Create sphere on keyframes with expression
              Lars Renklint Community Member

              Hi Dan,

               

              afraid that only shows my unfamilarity with AE. More used to 3D than 2,5D. So now I've found out that you can use the effect CC sphere and orient it towards the camera to make it look like 3D.

               

              Let me see if I understand you correctly.

              I have hundreds of keyframes with a single value in them. Then I use them to move a circle around the screen. But what if I would like to leave a copy of that circle everyplace it has been. Are my only options to either manually create lots of layers or do that with a script. No easier way?

              • 4. Re: Create sphere on keyframes with expression
                Dan Ebberts Community Member

                Hmmm... assuming you're talking about position keyframes and you're working with layer 1, you could add this position expression:

                 

                if (numKeys >= index)

                  if (time > key(index).time)

                    key(index).value

                  else

                    value;

                else

                  value

                 

                then duplicate the layer a bunch of times (one for each keyframe) and each layer should stop at the keyframe corresponding to its own layer index.

                 

                Dan

                • 5. Re: Create sphere on keyframes with expression
                  Lars Renklint Community Member

                  Oh, thank you. The keyframes only hold a single value so I already have an expression for the position. So the keyframes are in a separate layer.

                   

                  x=time*20;

                  note=thisComp.layer("midi").effect("ch_0_pitch")("Slider"); //this is the keyframes

                  y=linear(note, 60, 74, 0, -100);

                  centre=[50, 180, 0];

                  add(centre,[x,y]);

                   

                  midi.png

                  • 6. Re: Create sphere on keyframes with expression
                    Dan Ebberts Community Member

                    I guess you'll need to combine the two expressions. I don't have time to test it, but this should be close:

                     

                    note=thisComp.layer("midi").effect("ch_0_pitch")("Slider"); //this is the keyframes

                    t = time;

                    if ((note.numKeys >= index) && (time > note.key(index).time))

                      t = note.key(index).value;

                    x=t*20;

                    y=linear(note, 60, 74, 0, -100);

                    centre=[50, 180, 0];

                    add(centre,[x,y]);

                     

                     

                    Dan

                    • 7. Re: Create sphere on keyframes with expression
                      Lars Renklint Community Member

                      Spot on. No need to change even a comma.

                       

                      This is how it looks: (click on the images to see the animation)

                      layers.pnglayers.gif

                      But I guess to make those new layers do something, stay around for a while, scale etc for longer than until the next keyframe I need to give them their own keyframes. Something like this:

                      Untitled.gif

                      But I cant do that manually, I would like to use it for visualizing a song and it would take thousands of keyframes. Maybe someday I can learn to write scripts...

                       

                      In a project trying to visualize Pachelbels Canon in D I'm also using David van Brinks midi-script and found the same need to transform expressions to keyframes.

                      Here's the beginning of the song: http://www.screencast.com/t/eAWWQtGQp

                       

                      It's very simple to make the green sphere jump, just setting the keyframes in the midi-layer to hold. And the other frames to bezier (or linear, in this case it wont make a difference). But towards the end when I want the blue sphere to start bouncing I found it needed its own keyframes. So I used "Convert expression to keyframes". The problem is that it creates keyframes on every frame and I must have keyframes only where the midi-keyframes are (which often don't even line up with the start of a frame).

                      But some day in a far distance maybe I can write a script that creates only those keyframes that I need.

                      • 8. Re: Create sphere on keyframes with expression
                        cheerbot

                        It's very simple to make the green sphere jump, just setting the keyframes in the midi-layer to hold. And the other frames to bezier (or linear, in this case it wont make a difference). But towards the end when I want the blue sphere to start bouncing I found it needed its own keyframes. So I used "Convert expression to keyframes". The problem is that it creates keyframes on every frame and I must have keyframes only where the midi-keyframes are (which often don't even line up with the start of a frame).

                        But some day in a far distance maybe I can write a script that creates only those keyframes that I need.

                         

                        If you find a way to accomplish this Lars I am also seeking such a thing. The only work around I've found is to go piece by piece through a keyframed midi reference, adding keyframes with the values specified by the expression while it's active in the layer I need the values to change in and then turning the expression off once I'm finished.

                         

                        On an off note it's nice to see more midi based animations

                        • 9. Re: Create sphere on keyframes with expression
                          Lars Renklint Community Member

                          David pointed me out where in the script I should start looking for a way to do this. I haven't done any scripting in AE before, but will give it a try.

                          • 10. Re: Create sphere on keyframes with expression
                            Lars Renklint Community Member

                            Hi Cheerbot,

                             

                            here's how far I've come.

                             

                            https://www.dropbox.com/s/8qjqft9f226uuyv/om_midi_x.jsx

                             

                            Started by making sure the script only creates a keyframe for the note-on event the way Dan suggested in this thread: http://forums.adobe.com/thread/949850?tstart=0

                             

                            Right now I don't need the duration and velocity, so I've commented them out. You'd have to delete my comments if you need them.

                             

                            This script creates an extra slider, so for channel 0 it will create ch_0_pitch and ch_0_x

                            The keyframes in the extra slider simply holds the time value at that keyframe.

                             

                            To use it you can separate the x and y dimensions in the position parameter you would like to change. Then paste the keyframes from ch_0_pitch to the Y position and the keyframes from ch_0_x to the X position.

                             

                            If you want to make modifications you should know that the first line that has been changed by me is line 1102.

                            You could for example change line 1149 to  var xVal = t*100; which gives you a x-value of 100 instead of 1 at time 1sec.

                             

                            In AE I've used this expression - linear(value, 60, 80, 700, 100) - to change the y-values. Tried that in the script, but I guess "linear" is AE lingo and not javascript, have to look that up.

                             

                            One thing I would like is to write both the x and y value to the same keyframe, instead of to two separate sliders. So if you have any suggestions please share them.