Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - jaynemesisz

Pages: [1]
1
Support / Animated 3ds model does not move [Solved]
« on: September 07, 2011, 02:53:16 pm »
Hi all,

I am trying to animate a 3ds model in an Android application, but it just doesn't move. I have been following the wiki's implementation closely. Hence I don't understand what could go wrong.

Will be really grateful to anyone who can help to pick out the problem. I've been staring at the code for the longest time and trying all sorts of solutions posted in the forums here, but none has worked for me. My codes are attached below.

If this is any help at all, I am running the app on Android 2.1, HTC flyer.

Code: [Select]
private void createWorld() {
if (world != null) {
return;
}
world = new World();

TextureManager tm = TextureManager.getInstance();
tm.flush();
Texture eyetex = new Texture(res.openRawResource(R.raw.eyesmall));
tm.addTexture("EYE.TIF", eyetex);

bear = loadModel(res.openRawResource(R.raw.bearb), 1f);

Animation anim = new Animation(4);
                anim.createSubSequence("walk");
                anim.addKeyFrame(loadModel(res.openRawResource(R.raw.bear_walk1b), 1).getMesh());
                anim.addKeyFrame(loadModel(res.openRawResource(R.raw.bear_walk2b), 1).getMesh());
                anim.addKeyFrame(loadModel(res.openRawResource(R.raw.bear_walk3b), 1).getMesh());
                anim.addKeyFrame(loadModel(res.openRawResource(R.raw.bear_walk4b), 1).getMesh());
                bear.setAnimationSequence(anim);

                world.addObject(bear);

world.setAmbientLight(127, 127, 127);
//world.buildAllObjects();

// Set lighting
float[] bb = bear.getMesh().getBoundingBox();
float height = (bb[3] - bb[2]);
new Light(world).setPosition(new SimpleVector(0, -height/2, height));

// Set camera
cameraController = new GLCameraOrbitController(world.getCamera());
cameraController.cameraAngle = 0;
}

private Object3D loadModel(InputStream filename, float scale) {
                Loader.setVertexOptimization(false);
               
                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)( -.5*Math.PI));
                    temp.rotateY((float)(-Math.PI));
                    temp.rotateMesh();
                    temp.setRotationMatrix(new Matrix());
                    o3d = Object3D.mergeObjects(o3d, temp);
           
                }
                o3d.build();
                return o3d;
        }

private float _anim3DS = 0.0f;

private void doAnimate() {

try{
if(_anim3DS > 1.0f)
_anim3DS = 0.0f;
else
_anim3DS += 0.1f;

bear.animate(_anim3DS, bear.getAnimationSequence().getSequence("walk"));

} catch(Exception e){
System.err.println("MoveTest::checkAnimate3DS() " + e.getMessage());
e.printStackTrace();
}
       
}

/****************************************************************
* GLSurfaceView.Renderer methods
*/
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
Logger.log("onSurfaceCreated");
}

@Override
public void onSurfaceChanged(GL10 gl, int w, int h) {
Logger.log("onSurfaceChanged");

if (frameBuffer != null) {
frameBuffer.dispose();
}
frameBuffer = new FrameBuffer(gl, w, h);

createWorld();

autoAdjustCamera(bear);
}

@Override
public void onDrawFrame(GL10 gl) {

if (frameBuffer == null) {
return;
}

doAnimate();

cameraController.placeCamera();

frameBuffer.clear();
world.renderScene(frameBuffer);
world.draw(frameBuffer);

frameBuffer.display();
}


Pages: [1]