animate collada bones

Software: Away3D 3.x

ge5, Newbie
Posted: 20 July 2011 04:54 PM   Total Posts: 13

Hi-
I am new to Away 3d 3.6—though comfortable with PV3D. I am going through the examples in the away3d cookbook and I’m stuck on something I really need to accomplish: animating collada through code. I am able to load my model and target the “bones” through your code, but any transforms done on these sections through the “enter frame” causes huge problems with the scale of the parts—if loaded static the model is fine.
In PV3D this worked well with ‘dae.getChildByName” and targeting the “bones” i named on my Blender model(a STATIC model with an armature)(collada export). Can anyone suggest anything? I am including some very messy code below.
Thanks so much for any help!!
Geraldine
///////////////


package
{
import away3d.containers.*;
import away3d.events.*;
import away3d.loaders.*;
import away3d.core.utils.Cast;
>import away3d.materials.BitmapMaterial;
>import away3d.loaders.data.AnimationData;

import flash.events.Event;

[SWF(width=“800”, height=“600”)]

public class AnimatingColladaBones extends SampleBase
{
[Embed(source = “ch09assets/NU22.dae”,mimeType = “application/octet-stream”)]
protected var ColladaModel:Class;
[Embed(source = “ch09assets/nu2.jpg”)]
protected var ColladaMaterial:Class;

var _skeleton:ObjectContainer3D;
private var th:Bone;
private var ring:Bone;
private var sp: Number=1;


public function AnimatingColladaBones() {
super();


protected override function _createScene() : void
{
var modelMaterial:BitmapMaterial = new BitmapMaterial(Cast.bitmap(ColladaMaterial));
_skeleton = Collada.parse(Cast.bytearray(ColladaModel),
{
>materials:
{
“Material-material”: modelMaterial

},

yUp: false,
bothsides: true,
ownCanvas: true
}
);

th=_skeleton.getBoneByName(“main_thumb”);
ring=_skeleton.getBoneByName(“main_ring”);

_skeleton.addEventListener(Event.ENTER_FRAME,_onEnterFrame);
_view.scene.addChild(_skeleton);

_skeleton.scale(15);


}

protected override function _onEnterFrame(ev : Event) : void
{
th.rotationX=sp;
sp++;
if (_skeleton) {

_skeleton.rotationY= (stage.mouseY - stage.stageHeight/2) / 4;

 

}

super._onEnterFrame(ev);
}
}
}
////////////////////////////////////////////
package
{
import away3d.containers.*;
import away3d.cameras.Camera3D;
import away3d.containers.Scene3D;
import away3d.containers.View3D;
import flash.display.*;
import flash.events.*;

public class SampleBase extends Sprite
{
protected var _view : View3D;

protected var _scene:Scene3D;
protected var _camera:Camera3D;


public function SampleBase()
{
_createView();
_createScene();
}

protected function _createView() : void
{
_view = new View3D();
_camera = new Camera3D()
_scene = _view.scene;
_camera = _view.camera;
addChild(_view);
_view.x = stage.stageWidth / 2;
_view.y = stage.stageHeight / 2;


addEventListener(Event.ENTER_FRAME, _onEnterFrame);
}

protected function _createScene() : void
{
}

protected function _onEnterFrame(ev : Event) : void
{
_view.render();

}
}
}

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X