I found a weird issue that the model (.bones) is not rendered correctly in Android using jpct-ae, but it is rendered correctly in desktop using jpct. The code are almost identical except the FrameBuffer object creation.
For android (jpct-ae)
frameBuffer = new FrameBuffer(width, height);
For desktop (jpct)
frameBuffer = new FrameBuffer(width, height, FrameBuffer.SAMPLINGMODE_NORMAL);
The following code is used to render model in Android
if (frameBuffer != null) {
frameBuffer.dispose();
}
frameBuffer = new FrameBuffer(width, height);
if (world == null) {
world = new World();
// load model
// mode.bones, which is exported using bones script (dae -> bones)
InputStream stream = context.getResources().openRawResource(R.raw.model);
try {
animatedModel = BonesIO.loadGroup(stream);
model = animatedModel.getRoot();
Texture blueHead = new Texture((BitmapHelper.convert(context.getResources().getDrawable(R.drawable.blue_head))));
Texture blue = new Texture((BitmapHelper.convert(context.getResources().getDrawable(R.drawable.blue))));
Texture eye = new Texture((BitmapHelper.convert(context.getResources().getDrawable(R.drawable.eye))));
Texture face = new Texture((BitmapHelper.convert(context.getResources().getDrawable(R.drawable.face))));
Texture headTop = new Texture((BitmapHelper.convert(context.getResources().getDrawable(R.drawable.head_top))));
Texture side = new Texture((BitmapHelper.convert(context.getResources().getDrawable(R.drawable.side))));
Texture metalLightGrey = new Texture(8, 8, new RGBColor(61, 61, 61));
Texture metalDark = new Texture(8, 8, new RGBColor(16, 16, 16));
Texture metalGrey = new Texture(8, 8, new RGBColor(41, 41, 41));
Texture metalBlue = new Texture(8, 8, new RGBColor(0, 52, 112));
Texture metal = new Texture(8, 8, new RGBColor(102, 102, 102));
Texture black = new Texture(8, 8, new RGBColor(0, 0, 0));
// image
TextureManager.getInstance().addTexture("blueHead", blueHead);
TextureManager.getInstance().addTexture("blue", blue);
TextureManager.getInstance().addTexture("eye", eye);
TextureManager.getInstance().addTexture("face", face);
TextureManager.getInstance().addTexture("headTop", headTop);
TextureManager.getInstance().addTexture("side", side);
// color
TextureManager.getInstance().addTexture("metalLightGrey", metalLightGrey);
TextureManager.getInstance().addTexture("metalDark", metalDark);
TextureManager.getInstance().addTexture("metalGrey", metalGrey);
TextureManager.getInstance().addTexture("metalBlue", metalBlue);
TextureManager.getInstance().addTexture("metal", metal);
TextureManager.getInstance().addTexture("black", black);
for (Animated3D o : animatedModel) {
o.build();
o.discardMeshData();
}
// set texture
animatedModel.get(0).setTexture("blueHead");
animatedModel.get(1).setTexture("headTop");
animatedModel.get(2).setTexture("metalLightGrey");
animatedModel.get(3).setTexture("metalDark");
animatedModel.get(4).setTexture("eye");
animatedModel.get(5).setTexture("face");
....
animatedModel.addToWorld(world);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
// camera
com.threed.jpct.Camera cam = world.getCamera();
cam.moveCamera(com.threed.jpct.Camera.CAMERA_MOVEOUT, 80);
cam.lookAt(model.getTransformedCenter());
// light
world.setAmbientLight(20, 20, 20);
sun = new Light(world);
sun.setIntensity(250, 250, 250);
SimpleVector sv = new SimpleVector();
sv.set(model.getTransformedCenter());
sv.y -= 100;
sv.z -= 100;
sun.setPosition(sv);
}
}
@Override
public void draw() {
super.draw();
frameBuffer.clear();
world.renderScene(frameBuffer);
world.draw(frameBuffer);
frameBuffer.display();
}
I have no idea why this happens. Thanks!