Author Topic: Can't get the shading right - 3ds / obj  (Read 1436 times)

Offline 3-S-E

  • byte
  • *
  • Posts: 6
    • View Profile
Can't get the shading right - 3ds / obj
« on: July 04, 2011, 11:38:21 am »
Hi all,

the day before I was trying to import a 3ds and an obj file into my jPCT-AE based app, but couldn't figure out why the shading of the faces went so damn wrong.

This is how it should be (flat shaded with diffuse-colors on dedicated polys):



And this is a capture from my SGS2 device how it becomes:




I've tried to export my (triangle-only - no quads, no fancy stuff) model to a 3ds-file with 3ds max 2012 and Blender 2.58 (btw.: the worst and non-intuitive modeling-tool ever! Sorry, but it irritates me every time again I'm trying to give it a chance). Then I've tried to export it to obj with 3ds max and maya 2012 - same result on import in jPCT.

I've attached both, the 3ds- and obj-files.

Please give me a hint, what I'm doing wrong?!

Cheers...

[attachment deleted by admin]
« Last Edit: July 04, 2011, 11:40:25 am by 3-S-E »

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Can't get the shading right - 3ds / obj
« Reply #1 on: July 04, 2011, 12:11:47 pm »
try this object.setShadingMode(Object3D.SHADING_FAKED_FLAT);

Offline 3-S-E

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Can't get the shading right - 3ds / obj
« Reply #2 on: July 04, 2011, 02:06:18 pm »
If I enable this flat-shading mode, I get this:



It's still the same 3ds-file as attached to my initial post.

No Diffuse-Colors either.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: Can't get the shading right - 3ds / obj
« Reply #3 on: July 04, 2011, 05:56:46 pm »
Can you please post the log output when loading the 3ds?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: Can't get the shading right - 3ds / obj
« Reply #4 on: July 05, 2011, 09:27:33 pm »
I gave these files a try. The 3ds version is one of those that stores the diffuse color in a way that i was never able to read correctly. These files store the color in some undocumented way and i couldn't make any sense of it...which is why (at least the desktop version does this, not sure about AE) a message is logged to the console. However, i've exported the file from DeepExploration and that one can be read just fine.
About the OBJ-format: You can't load diffuse colors from that one without the mtl-file, so i couldn't try that.

I'll post the code for the test case for desktop jPCT and the converted file:

Code: [Select]
import com.threed.jpct.*;

public class HelloRoom {

private World world;
private FrameBuffer buffer;
private Object3D box;

public static void main(String[] args) throws Exception {
Config.glUseVBO=true;

new HelloRoom().loop();
}

public HelloRoom() throws Exception {
world = new World();
world.setAmbientLight(155, 155, 155);

box = Object3D.mergeAll(Loader.load3DS("lab.3ds", 0.05f));
box.rotateX((float)-Math.PI/2f);
box.compile();
box.build();
world.addObject(box);

world.getCamera().setPosition(50, -50, -5);
world.getCamera().lookAt(box.getTransformedCenter());
}

private void loop() throws Exception {
buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_GL_AA_2X);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
buffer.enableRenderer(IRenderer.RENDERER_OPENGL);

while (!org.lwjgl.opengl.Display.isCloseRequested()) {
box.rotateY(0.01f);
buffer.clear(java.awt.Color.BLUE);
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.displayGLOnly();
Thread.sleep(10);
}
buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
buffer.dispose();
System.exit(0);
}
}

[attachment deleted by admin]