Help~I embed model and animation in swf, but when play the animation. The model looks like be distorted.

Software: Away3D 4.x

liuyi, Member
Posted: 20 October 2011 11:23 AM   Total Posts: 65

I embed model and animation in swf, but when play the animation.
The model looks like be distorted.


embed:

[Embed(source '../embeds/hellknight/hellknight.md5mesh'mimeType 'application/octet-stream')]
  
private var monsterModel:Class
  
[Embed(source '../embeds/hellknight/idle2.md5anim'mimeType 'application/octet-stream')]
  
private var monsterIdleAnim:Class
  
[Embed(source='../embeds/hellknight/walk7.md5anim'mimeType='application/octet-stream')]
  
private var monsterWalkAnim:Class 


parse data:

AssetLibrary.loadData(monsterModelnull"monsterModel", new MD5MeshParser());
   
   
AssetLibrary.loadData(idleAnimnull"idle", new MD5AnimParser());
   
AssetLibrary.loadData(walkAnimnull"walk", new MD5AnimParser());
    
   
AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETEonAnimationComplete


play: I added the monster’s mesh into a objectContainer3D object.

var monster:Human = new Human();
   
monster.model _modelManager.getModel("monster").clone() as ObjectContainer3D;
   
monster.model.position = new Vector3D(01500);
   
   
monster.animationControler = new SmoothSkeletonAnimator(SkeletonAnimationState((monster.model.getChildAt(0) as Mesh).animationState));
   
monster.animationControler.updateRootPosition false;
   
monster.animationControler.addSequence(_modelManager.getAnimation("monsterIdle") as SkeletonAnimationSequence);
   
monster.animationControler.addSequence(_modelManager.getAnimation("monsterWalk") as SkeletonAnimationSequence);
   
monster.animationControler.play("monsterWalk");
   
_view.scene.addChild(monster.model); 


It worked very well in example, but not in my project.
Thanks!

 

   

Avatar
80prozent, Sr. Member
Posted: 20 October 2011 12:15 PM   Total Posts: 430   [ # 1 ]

hi

i am not shure, but maybe its because you loading mesh and animation data at the same time. in the examples, first the mesh data gets loadet and build, then (using asset.Complete listener) the animation data gets loadet and parsed.

 Signature 

sorry…i hope my actionscript is better than my english…

   

liuyi, Member
Posted: 20 October 2011 12:28 PM   Total Posts: 65   [ # 2 ]

Thanks 80prozent,

but i am sure it isn’t this reason,
because I do this after loaded lots of models and textures , and applied textures to these models.

Now I found that when load a md5mesh, there will be a skeleton file,
so I added this skeleton to my assets list.

I don’t know how to get assets from AssetLib classes, so I wrote a classes to load models and set name and so on.

Like this:

_modelManager.addFile(monsterModel'monster',new MD5MeshParser());
 
_modelManager.addFile(monsterIdleAnim'monsterIdle', new MD5AnimParser());
 
_modelManager.addFile(monsterWalkAnim'monsterWalk' ,new MD5AnimParser());

_modelManager.start(); 

after loaded then,

apply animation and skeleton to this model:

//add monster
   
var monster:Human = new Human();
   
monster.model _modelManager.getModel("monster").clone() as ObjectContainer3D;
   
monster.model.position = new Vector3D(01500);
   
  
   var 
skeleton:Skeleton _modelManager.getSkeleton("monster");
     var 
skeletonAnimation:SkeletonAnimation = new SkeletonAnimation(_modelManager.getSkeleton("monster"));
   
monster.animationControler = new SmoothSkeletonAnimator(new SkeletonAnimationState(skeletonAnimation));
   
monster.animationControler.updateRootPosition false;
   
   var 
idle:SkeletonAnimationSequence _modelManager.getAnimation("monsterIdle") as SkeletonAnimationSequence;
   
idle.looping true;
   
monster.animationControler.addSequence(idle);
   
monster.animationControler.addSequence(_modelManager.getAnimation("monsterWalk") as SkeletonAnimationSequence);
   
monster.animationControler.play("monsterIdle");
   
_view.scene.addChild(monster.model);
   
   
_camera.lookAt(monster.model.position); 


NOW THE MODEL CAN NOT PLAY ANIMATION…

 

 

   

liuyi, Member
Posted: 20 October 2011 12:51 PM   Total Posts: 65   [ # 3 ]
//add monster
   
var monster:Human = new Human();
   
monster.model _modelManager.getModel("monster").clone() as ObjectContainer3D;
   
monster.model.position = new Vector3D(01500);
   
  
   var 
skeleton:Skeleton _modelManager.getSkeleton("monster");//origin
    
var skeletonAnimation:SkeletonAnimation = new SkeletonAnimation(_modelManager.getSkeleton("monster"));
   var 
state:SkeletonAnimationState=new SkeletonAnimationState(skeletonAnimation)
   
monster.animationControler = new SmoothSkeletonAnimator(state);
   
monster.animationControler.updateRootPosition false;
   var 
monsterMesh:Mesh monster.model.getChildAt(0) as Mesh;
   
monsterMesh.geometry.animation skeletonAnimation;
   
monsterMesh.animationState state;
   
   
   var 
idle:SkeletonAnimationSequence _modelManager.getAnimation("monsterIdle") as SkeletonAnimationSequence;
   
idle.looping true;
   
monster.animationControler.addSequence(idle);
   
monster.animationControler.addSequence(_modelManager.getAnimation("monsterWalk") as SkeletonAnimationSequence);

   
_view.scene.addChild(monster.model);
   
monster.animationControler.play("monsterIdle");
   
_camera.lookAt(monster.model.position); 


I wrote my code like his code,
http://away3d.com/forum/viewthread/439/

when render ,errors came
RangeError: Error #2006:  index is out of range
at flash.display3D::Context3D/setProgramConstantsFromVector()

   

liuyi, Member
Posted: 20 October 2011 01:07 PM   Total Posts: 65   [ # 4 ]

I trace the skeleton’s infomation:
monster null 110 110 monster //trace

is the same as the md5mesh file.

copy from md5mesh file:
numJoints 110
numMeshes 4

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X