Download movies or not download movies?.
Away3D.com
   
 
Quality dvd movies, buy movies online and download movies!!!
rulururu

post Tutorial: How to use the Animator class

June 3rd, 2008

Filed under: AWAY3D — Fabrice Closier @ 6:12 pm

butterflies

This tutorial shows you how to use the Animator class using the Away3D 1.9.4 library or higher.

The Animator class allows you to generate one or more series of animation sequences and add them to the internal animation system. It could be described as a runtime md2 generator – a vertex animation format.

The vertex animations are updated at a given fps (a user defined framerate per second). The object can have one or more logical sequences, and each sequence is defined by a prefix string. Keyframes (the vertex geometry for a single frame of a sequence) in a sequence are identified by the same prefix string and a number; for instance a walk sequence would be defined as prefix: “walk”, each keyframe would then use the naming convention prefix+increment to give ‘walk0′, ‘walk1′, ‘walk2′ etc…

Once defined you are then able to change the sequences at runtime like you would do for a movieclip. (movieclip.play(”timeline anchor”);) The engine will play the frames within this sequence “timeline” until it reaches the last frame. In our walk sequence it would stop at frame walk2. the sequence can be looped by setting the loop property to true, and the animations can be smoothed (tweened) by setting the smooth property to true, otherwise the sequence plays as individual frames.

To make your Animator object you need at least two parameters: the base object (used as the starting mesh to be used for all subsequent vertex movements), and the vertices positions for each keyframe. For this reason it is important to pass the same amount of vertex positions for each keyframe. The order of vertex positions must remain coherent throughout each sequence. How to model in a 3D application is beyond the scope of the tutorial. It is possible to tween any two shapes as long as they both have the same amount of vertices.

How to implement
You only need to import 1 class using the 1.9.4 library from the animation package and for version 2.1 and higher you’ll also need the AnimationSequence class.

import away3d.animations.Animator;
//using 2.0 and higher
import away3d.core.base.AnimationSequence;

This example shows 2 meshes exported as still .as files (AS3 export is native in Away3D)
Both butterflies shapes were modeled in a third party editor.

butterfly1
As you can see, each keyframe shows a different state.
butterfly2

private function generateButterfly():void
{
 // the material
 var mat:IMaterial = new BitmapMaterial(new butterfly_texture(), {smooth:false}); 

//instance of the first as3 file (you could create the same using a loader)
 var but1:Butterfly1 = new Butterfly1({scaling:0.6});

//instance of the second as3 file
 var but2:Butterfly2 = new Butterfly2({scaling:0.6});

// instance Animator
 // first parameter, we set the object reference
 // second parameter, a series of objects where we pass the geometry
 // third parameter, the init object
 // fourth parameter, if we want to loop.
 butterfly = new Animator(but1,
                             [{vertices:but1.vertices, prefix:"fly1"},
                              {vertices:but2.vertices, prefix:"fly2"}],
                             {material:mat, y:0, x:0,z:0,bothsides:true},
                             true);

//using 1.9.4
 //_butterfly.play({prefix:"fly", smooth:true, loop:true, fps:8});

//using 2.0 and higher
 butterfly.play(new AnimationSequence("fly", true, true, 8));

//add object to the scene
 scene.addChild(butterfly);
}

In order to update the animation on screen, place the following code in your onEnterFrame listener:

private function refreshScreen(event:Event):void
{
 //move the position of the butterfly as it animates if needed
 butterfly.rotationY = -10+Math.random()*20;
 butterfly.moveForward(5);

// update the internal animation
 scene.updateTime();

// showtime
 view.render();
}

It is also possible to use the Animator class with any primitive. Here an example using the Cube primitive.
animation

var mat:IMaterial = new BitmapMaterial(myBitmadata, {});
var cube = new Cube({width:350, height:350, depth:350});
var cube2 = new Cube({width:500, height:50, depth:250});
var cube3 = new Cube({width:150, height:450, depth:50});
var cube4 = new Cube({width:650, height:250, depth:550}); 

_anim = new Animator(cube,
                     [{vertices:cube2.vertices, prefix:"cube01"},
                      {vertices:cube3.vertices, prefix:"cube02"},
                      {vertices:cube4.vertices, prefix:"cube03"},
                      {vertices:cube2.vertices, prefix:"cube04"}] ,
                     {material:mat, y:0, x:0, z:0, bothsides:false});
scene.addChild(_anim);

//using 1.9.4
//_anim.play({prefix:"cube", smooth:true, loop:true, fps:.5});

//using 2.0 and higher
_anim.play({new AnimationSequence("cube", true, true, .5));

Adding more sequences
You can add other sequences using the following source+increment syntax – shown here for “run”, “jump” and “land” sequences:

_anim = new Animator(but1,
                     [{vertices:source1.vertices, prefix:"run0"},
                      {vertices:source2.vertices, prefix:"run1"},
                      {vertices:source3.vertices, prefix:"run2"},
                      {vertices:source4.vertices, prefix:"jump0"},
                      {vertices:source5.vertices, prefix:"jump1"},
                      {vertices:source6.vertices, prefix:"land0"},
                      {vertices:source7.vertices, prefix:"land1"}],
                     {material:mat, y:0, x:0, z:0, bothsides:false},
                     true);

You are now able to toggle the animations at runtime using the following:

_anim.play({new AnimationSequence("run", true, true, .5));
_anim.play({new AnimationSequence("jump", true, true, .5));
_anim.play({new AnimationSequence("land" true, true, .5));

More
The examples shown above are using simple geometry. You can of course do exactly the same with much more complex models.
Like the md2 format and as3 animated format, you can also access many handlers like play, gotoAndPlay, stop etc., but you can also check which prefix is playing, the actual frame number, add listeners onCycle and onSequence – events fired by the animation engine to ease the programming as the motion complexity increases…

Another tutorial will cover these events in depth. More information can be found in the BaseMesh class documentation.

Popularity: 5% [?]

14 Comments »

  1. hi!

    humm… I still have doubs about as3 and loading animations into away3d… the sample isnt clear in that aspect.. just tells “This example shows 2 meshes exported as still .as files”

    I am a 3d modeler and I don know the what is that “export as still .as”

    Comment by Flamander MEXICO — March 2, 2009 @ 7:31 pm

  2. Away has in 2.3, 3 ways to export own or loaded content to AS3 classes.

    In this case, the example loads the meshes exported from a third party app, then after they are loaded in Away at dev time, they are exported from Away to AS3 classes using the AS3Exporter. These classes are then compiled with the project, as a result you get very small file size and no loading blues.

    You can do exact same thing loading external files without exporting them to AS3. If you make a game for instance, you will not be able to upload your game somewhere if you have external files, since it requires one single file in most cases. In a game or any other project, you avoid this way to have a loading management code and your whole project becomes smaller…

    Comment by Fabrice Closier NETHERLANDS — March 4, 2009 @ 3:24 pm

  3. I have a .3ds file, when I import to 3d max 8 it contains animation (the cube is rotation animated)

    when loading the file in away 3d (flash cs3) using:

    loader = Max3DS.load(”assets/f360.3ds”, {material:carMaterial, ownCanvas:true, centerMeshes:true, pushfront:true});

    I tried to find it on the animationData trought a loader or ObjectContainer3D but nothing…

    the Max3DS loader/parser class can “read” the animation info of a 3ds?

    Comment by Flamander MEXICO — March 4, 2009 @ 7:25 pm

  4. No, 3Ds animation is not supported yet

    Comment by Fabrice Closier NETHERLANDS — March 5, 2009 @ 3:35 am

  5. ok thanks for your attention. you’re really nice person. see ya!

    Comment by Flamander MEXICO — March 5, 2009 @ 11:11 am

  6. is it possible to load the verticies from some external file such as XML, rather then doing each frame with a A3 class? if so where would i find information on the format of such a file?

    are there source files for this example?

    Comment by chris UNITED STATES — April 27, 2009 @ 1:35 pm

  7. Hey Chris, the code displayed above is pretty much the source… Yes you can load your geometry from external files, the only thing required is to write your own mesh generator. Look at As3Exporter to see how it’s done.

    Comment by Fabrice Closier NETHERLANDS — April 28, 2009 @ 8:51 am

  8. Here is my problem. I have a model that i am loading into away3D via COLLADA. i need to apply transformations per vertex to the model (without using bones). I would like to use animator for this but i can’t create a AS3 class for each of the frames.

    Esentially what i am doing is I have a piece of video and am tracking/match moving it to a model. This produces per vertex transformation data, i need to be able to load that data externally via XML or some other format and apply it to the verticies of the COLLADA model, again without any bones. Animator seems to be able to do this, but I don’t know how to format the data since the only i have seen are using this as3 export idea.

    Comment by chris UNITED STATES — April 29, 2009 @ 5:16 pm

  9. Hey chris, why don’t you register to our dev group? This is not the right place for technical help…

    Comment by Fabrice Closier NETHERLANDS — April 29, 2009 @ 5:45 pm

  10. k i will post it to the dev group again.

    Comment by chris UNITED STATES — April 29, 2009 @ 6:07 pm

  11. Hi, chris, for “butterfly.play(new AnimationSequence(”fly”, true, true, 8));”, how can I get the prefix “fly”?

    I am using 3dmax and used the md2 exporter, created a md2 file (cannot see the code in txt format), but when I use AnimationSequence, it needs me provide the prefix, please kindly help to tell how can I get this?

    or any method I need to do?

    Comment by golden20hk HONG KONG — June 8, 2009 @ 12:26 am

  12. Hi, Fabrice Closier, for “butterfly.play(new AnimationSequence(”fly”, true, true, 8));”, how can I get the prefix “fly”?

    I am using 3dmax and used the md2 exporter, created a md2 file (cannot see the code in txt format), but when I use AnimationSequence, it needs me provide the prefix, please kindly help to tell how can I get this?

    or any method I need to do?

    Comment by golden20hk HONG KONG — June 8, 2009 @ 12:28 am

  13. You mix up two different things.
    “AnimationSequence” is the animation player, whereas “Animator” is (at least supposed to) creating the animation, “tweening” between two different geometries.

    Note that you cannot expect to “spare” any motion capture phases with it, unless the motion is simply “vibrational”.

    That is, this is only a “tweener”, or, in human speech, morpher – deriving LINEAR steps between two given states.

    Comment by crusher HUNGARY — November 25, 2009 @ 11:14 am

  14. @golden, please register to our google group for technical questions.

    Comment by Fabrice Closier NETHERLANDS — November 27, 2009 @ 7:41 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment

ruldrurd
   
 
Hair drug test and herbal detox products. Visit drug detox website for more details on cannabis and marijuana drug detox.
FireStats iconPowered by FireStats
Powered by WordPress, Web Design by Laurentiu Piron
Entries (RSS) and Comments (RSS)




rmvb player and mkv codec