Vertex Animation with Away3D 3.5.0

Away3D 3.5.0 has been released! Unfortunately, the animator class has gone and has been changed to newer vertex animation system. There is no available example so far, so I try to figure out by myself. Hopefully, I am doing it right 😉

For a demo, click the picture below

run abi run

On previous post, I animated the MQO models using the old animator class. The code was based on one example from Away3D blog page. Now, I am using the new VertexAnimator class which I think is much better than the old one.

Click ‘read more’ for more the code details. This time, source code is available, including the latest Metasequoia loader for Away3D 3.5.0 😉

I generated 9 MQO models which are the animation keyframes. The models are created using Metasequoia and the animations are generated using a great Metaseq plugin called Keynote.

First, load all models using my custom Metasequoia loader. All models and materials are embedded to make the loading process easier.

_models = new Vector.<ObjectContainer3D>();
_models.push(Metasequoia.parse(ModelStand01, {materials:myMaterials, pushfront:true}));
_models.push(Metasequoia.parse(ModelRun01, {materials:myMaterials, pushfront:true}));
_models.push(Metasequoia.parse(ModelRun02, {materials:myMaterials, pushfront:true}));
_models.push(Metasequoia.parse(ModelRun03, {materials:myMaterials, pushfront:true}));
_models.push(Metasequoia.parse(ModelRun04, {materials:myMaterials, pushfront:true}));
_models.push(Metasequoia.parse(ModelRun05, {materials:myMaterials, pushfront:true}));
_models.push(Metasequoia.parse(ModelRun06, {materials:myMaterials, pushfront:true}));
_models.push(Metasequoia.parse(ModelRun07, {materials:myMaterials, pushfront:true} ));
_models.push(Metasequoia.parse(ModelRun08, {materials:myMaterials, pushfront:true}));

Once loaded, get the meshes from the model’s ObjectContainer. The number of meshes inside the model (ObjectContainer) is the same as  the number of layers in the MQO files. In this example, I have merged all MQO’s layers into one so I just load the first mesh.

var meshList:Vector.<Mesh> = new Vector.<Mesh>();
var tempMesh:Mesh;
for each (var model:ObjectContainer3D in _models)
{
    // only get the first layer from the MQO file, abandoning other layers
    tempMesh = model.children[0] as Mesh;
    meshList.push(tempMesh);
}

Insert one of the models to the Away3D Scene. This model will be the base of our animation. In the example above, I just add the model from the first frame of standing animation.

_mainModel = meshList[0];
_mainModel.rotationX = -90;
_mainModel.rotationZ = 15;
_mainModel.scale(1.5);
_scene.addChild(_mainModel);
_camera.lookAt(_mainModel.position);

Init the VertexAnimators. In the example, I created 2 animations: standing and running. Assign the main model’s vertices to all animators.

_animationRunning = new VertexAnimator(_mainModel);
_animationStanding = new VertexAnimator(_mainModel);
var theVertex:Vertex;
for each (theVertex in _mainModel.vertices)
{
    // init the vertex of the main model to the animators
    _animationStanding.addVertex(theVertex);
    _animationRunning.addVertex(theVertex);
}

Create the animation frames. Each frame will contain vertices value for every animation frame. The frame vertices are corresponding with the vertices from the main model. The code below is how I initiated 8 frames for running animation.

// init running animation
var frames:Array;
var j:int;
for (j = 1; j <= 8; j++)
{
    frames = new Array();

    for each (theVertex in meshList[j].vertices)
    {
        frames.push(new Number3D(theVertex.x, theVertex.y, theVertex.z));
    }
    _animationRunning.addFrame(frames);
}

Play the animation by calling the method play.

_currentAnimation = _animationRunning;
_currentAnimation.loop = true;
_currentAnimation.interpolate = true;
_currentAnimation.fps = runSpeed.value;
_currentAnimation.play();

Click here to download the complete source code. The MQO models are included and the source code requires Flex 4 SDK and the latest Away3D to compile.

Feel free to ask me question 😉 Enjoy!

5 thoughts on “Vertex Animation with Away3D 3.5.0

  1. Pingback: Away3D: More with Metasequoia | Abiyasa Blogs

  2. thanks again for this. I have one problem though: when I try to build this in FlashBuilder I get the error:

    “Description Resource Path Location Type
    1067: Implicit coercion of a value of type Array to an unrelated type __AS3__.vec:Vector.. Main.mxml /vv/src line 192 Flex Problem

    Would you have an idea as to why this is happening?
    Anyway thanks.
    Lawrence

    • Hi lawrence. I am not so sure why it’s happening.
      Might be there is type changing (from array to Vector) on the last trunk of Away3D? Not so sure, I haven’t checked the latest update…
      Make sure that you have import the right library (Away3D for fp10) 😉

  3. Hi, I’m trying to do the same in away3d4..For example I have 2 meshes (a plane and the same plane twisted), I want to animate them, but I’m totally stuck on it. Yes, I’m a noob 🙁

    Have you made some tests? Would be cool to make some weird things in c4d (some weird transformation of a mesh) and see them moving in away3d, with lights and stuff.

    But it’s hard!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.