571
Support / Re: animation
« on: February 22, 2008, 08:08:47 pm »
Well, I just went through this in blender. You make your animation. Then you save key frames of the animation. Like, legs apart, lifting left leg, lifting right leg, other legs apart. You save them as 3ds. I have a character that is a mouse. So this is the code I did for the animation. First you need code that loads the model and turns it the right way and builds it:
Then I use this code to load the animation:
Then you animate as was explained earlier in this thread. The index starts with one so, in this case, walk is 1, stand is 2, jump is 3.
Code: [Select]
private Object3D loadModel(String filename, float scale)
{
Object3D[] model = Loader.load3DS(filename, scale);
Object3D o3d = new Object3D(0);
Object3D temp = null;
for (int i=0; i<model.length; i++)
{
temp=model[i];
temp.setCenter(SimpleVector.ORIGIN);
temp.rotateX((float)-Math.PI);
temp.rotateMesh();
temp.setRotationMatrix(new Matrix());
o3d=Object3D.mergeObjects(o3d, temp);
o3d.build();
}
return o3d;
}
I have to build the model in the y up positon in blender for that to work.Then I use this code to load the animation:
Code: [Select]
Mouse = loadModel("data/stand.3ds",1);
Mouse.translate(0, -5, 0);
TextureManager tm = TextureManager.getInstance();
Texture tex=new Texture("data/fur.jpg");
tm.addTexture("fur", tex);
tex = new Texture("data/red.jpg");
tm.addTexture("red", tex);
Mouse.setTexture("fur");
world.addObject(Mouse);
Animation mouse = new Animation(10);
mouse.createSubSequence("walk");
mouse.addKeyFrame(loadModel("data/walk2.3ds",1).getMesh());
mouse.addKeyFrame(loadModel("data/walk3.3ds",1).getMesh());
mouse.addKeyFrame(loadModel("data/walk4.3ds",1).getMesh());
mouse.addKeyFrame(loadModel("data/walk1.3ds",1).getMesh());
mouse.createSubSequence("stand");
mouse.addKeyFrame(loadModel("data/stand.3ds",1).getMesh());
mouse.addKeyFrame(loadModel("data/stand2.3ds",1).getMesh());
mouse.createSubSequence("jump");
mouse.addKeyFrame(loadModel("data/stand.3ds",1).getMesh());
mouse.addKeyFrame(loadModel("data/jump.3ds",1).getMesh());
mouse.addKeyFrame(loadModel("data/jump2.3ds",1).getMesh());
Mouse.setAnimationSequence(mouse);
Mouse.rotateY(3.1416f/2f);
Mouse.setCollisionMode(Object3D.COLLISION_CHECK_SELF);
Mouse.setCollisionOptimization(Object3D.COLLISION_DETECTION_OPTIMIZED);
Then you animate as was explained earlier in this thread. The index starts with one so, in this case, walk is 1, stand is 2, jump is 3.