Author Topic: Model is not rendered correctly in Android using jpct-ae  (Read 538 times)

Offline jaychang0917

  • int
  • **
  • Posts: 50
    • View Profile
Model is not rendered correctly in Android using jpct-ae
« 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)
Code: [Select]
frameBuffer = new FrameBuffer(width, height);

For desktop (jpct)
Code: [Select]
frameBuffer = new FrameBuffer(width, height, FrameBuffer.SAMPLINGMODE_NORMAL);

The following code is used to render model in Android
Code: [Select]
    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);
   }
}

Code: [Select]
@Override
  public void draw() {
    super.draw();
    frameBuffer.clear();
    world.renderScene(frameBuffer);
    world.draw(frameBuffer);
    frameBuffer.display();
  }


I have no idea why this happens. Thanks!
« Last Edit: April 13, 2017, 06:29:08 am by jaychang0917 »

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Model is not rendered correctly in Android using jpct-ae
« Reply #1 on: April 11, 2017, 08:18:36 pm »
Have you tried it on another device? It might be a driver issue, because the model seems pretty high poly...

Offline AeroShark333

  • long
  • ***
  • Posts: 149
    • View Profile
Re: Model is not rendered correctly in Android using jpct-ae
« Reply #2 on: April 11, 2017, 08:50:24 pm »
Maybe you could try to increase the amount of maximum polygons visible...

Change this:

Code: [Select]
if (frameBuffer != null) {
      frameBuffer.dispose();
}

into:

Code: [Select]
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..)
« Last Edit: April 11, 2017, 08:52:26 pm by AeroShark333 »

Offline jaychang0917

  • int
  • **
  • Posts: 50
    • View Profile
Re: Model is not rendered correctly in Android using jpct-ae
« Reply #3 on: April 12, 2017, 04:13:05 am »
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?
« Last Edit: April 12, 2017, 06:12:03 am by jaychang0917 »

Offline jaychang0917

  • int
  • **
  • Posts: 50
    • View Profile
Re: Model is not rendered correctly in Android using jpct-ae
« Reply #4 on: April 12, 2017, 04:27:42 am »
Maybe you could try to increase the amount of maximum polygons visible...

Change this:

Code: [Select]
if (frameBuffer != null) {
      frameBuffer.dispose();
}

into:

Code: [Select]
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
Code: [Select]
Config.maxPolysVisible = 10*Config.maxPolysVisible;


Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Model is not rendered correctly in Android using jpct-ae
« Reply #5 on: April 12, 2017, 07:37:59 am »
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.

Offline jaychang0917

  • int
  • **
  • Posts: 50
    • View Profile
Re: Model is not rendered correctly in Android using jpct-ae
« Reply #6 on: April 12, 2017, 08:29:17 am »
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.

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Model is not rendered correctly in Android using jpct-ae
« Reply #7 on: April 12, 2017, 12:40:09 pm »
Can you provide me with the model?

Offline jaychang0917

  • int
  • **
  • Posts: 50
    • View Profile
Re: Model is not rendered correctly in Android using jpct-ae
« Reply #8 on: April 12, 2017, 12:58:46 pm »
Can you provide me with the model?

I sent you the model via pm.

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Model is not rendered correctly in Android using jpct-ae
« Reply #9 on: April 12, 2017, 01:08:25 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.

Offline jaychang0917

  • int
  • **
  • Posts: 50
    • View Profile
Re: Model is not rendered correctly in Android using jpct-ae
« Reply #10 on: April 13, 2017, 04:52:09 am »
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!
« Last Edit: April 13, 2017, 09:31:36 am by jaychang0917 »