www.jpct.net
jPCT-AE - a 3d engine for Android => Support => Topic started by: jaychang0917 on April 11, 2017, 12:14:32 pm
-
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!
-
Have you tried it on another device? It might be a driver issue, because the model seems pretty high poly...
-
Maybe you could try to increase the amount of maximum polygons visible...
Change this:
if (frameBuffer != null) {
frameBuffer.dispose();
}
into:
if (frameBuffer != null) {
frameBuffer.dispose();
}
Config.maxPolysVisible = 2*Config.maxPolysVisible;
And maybe it has some effects :)
(in case I do correctly see that some polygons are missing..)
-
Have you tried it on another device? It might be a driver issue, because the model seems pretty high poly...
I tried on three devices, the result are same. Is the reason that jpct-ae can't handle such amount of polygons? then can I use jpct in android?
-
Maybe you could try to increase the amount of maximum polygons visible...
Change this:
if (frameBuffer != null) {
frameBuffer.dispose();
}
into:
if (frameBuffer != null) {
frameBuffer.dispose();
}
Config.maxPolysVisible = 2*Config.maxPolysVisible;
And maybe it has some effects :)
(in case I do correctly see that some polygons are missing..)
I tried, but no luck, same result. I even tried
Config.maxPolysVisible = 10*Config.maxPolysVisible;
-
jPCT-AE doesn't care about the number of polygons/vertices. Speaking of which...how many are there in this model?
It might be worth a try to call Object3D.setFixedPointMode(false); before calling build() on the model as well.
-
jPCT-AE doesn't care about the number of polygons/vertices. Speaking of which...how many are there in this model?
It might be worth a try to call Object3D.setFixedPointMode(false); before calling build() on the model as well.
The model contains around 8000 polygons. I tried Object3D.setFixedPointMode(false);, but no luck.
-
Can you provide me with the model?
-
Can you provide me with the model?
I sent you the model via pm.
-
Thank, I'll have a look later. But looking at your screen shot again...this is the model rendered on top of a camera view? If so, make sure that the gl context that you are creating actually has a depth buffer. You have to specify this somehow, or you might end up with one without. That would explain the results as well.
-
Thank, I'll have a look later. But looking at your screen shot again...this is the model rendered on top of a camera view? If so, make sure that the gl context that you are creating actually has a depth buffer. You have to specify this somehow, or you might end up with one without. That would explain the results as well.
The root cause is that the opengl depth buffer is not created, thanks EgonOlsen!