Author Topic: Model import produces strange results  (Read 6507 times)

Offline zed

  • byte
  • *
  • Posts: 12
    • View Profile
Model import produces strange results
« on: May 08, 2008, 06:31:05 pm »
Hey there!

I'm new to jPCT and just trying to get into the basics. Therefore I just tried to adapt the Hello-World example, that comes with the API, so that it loads and shows an external model instead of the box, usually displayed. I got myself a high poly model of an elephant (which can be found here: http://graphics.im.ntu.edu.tw/~robin/courses/cg03/model/) and imported it using the following code:

Code: [Select]
char c=File.separatorChar;
Object3D [] buffer = Loader.loadOBJ("models" + c + "elepham.obj", null, 0.05f);
elephant = buffer[0];

elephant.calcNormals();
elephant.rotateX((float)Math.PI);

world.addObject(elephant);

So far, so good. Everything compiles well and I can run the example, but the output is totally weird, as you might see in the image. What's wrong here? Is it possible, that the normals get screwed up somewhere? I have to use Software-Rendering, could this be the reason? I'm really stuck here, so I appreciate every kind of advice! Thanks!

zed



Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Model import produces strange results
« Reply #1 on: May 08, 2008, 07:48:41 pm »
Maybe the model's vertices have mixed orientations (some clock wise, some counter clock wise). jPCT relies on a model using one orientation to do the culling. You may try to disable culling (http://www.jpct.net/doc/com/threed/jpct/Object3D.html#setCulling(boolean)) and see if that helps. However, even if it does, it hurts performance.
Another question is, if the model is really defined in one part, i.e. if buffer.length is really 1.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Model import produces strange results
« Reply #2 on: May 08, 2008, 10:08:47 pm »
i'm somewhat familiar with that appearance. check Config.maxPolysVisible ;)

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Model import produces strange results
« Reply #3 on: May 08, 2008, 11:52:43 pm »
I see you calculated the normals, but did you call build on the object?

Jman

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Model import produces strange results
« Reply #4 on: May 09, 2008, 01:40:30 pm »
Like raft said, this really looks like you have run out of visible polys.  Check Java output to see if it says anything about that.  See if adding the line:

Code: [Select]
Config.maxPolysVisible = 60000;   // or some large number
Before creating the world.

Offline zed

  • byte
  • *
  • Posts: 12
    • View Profile
Re: Model import produces strange results
« Reply #5 on: May 14, 2008, 10:46:57 am »
Hey guys. Sorry for not replying for a while, but I've been busy elsewhere. Thanks for your advice, it indeed was Config.maxPolysVisible that solved my problems.

@Kearnan: Are there any special reasons, why you prefer 3ds over obj? What tools do you use to convert them?

Greetz!

zed

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Model import produces strange results
« Reply #6 on: May 15, 2008, 08:56:45 am »
I'd trust JPCT knows more about 3DS than OBJ.
Yes, that's true. The 3DS-format (as far as jPCT supports it) has only one flaw with polygon colors, where the format can either be float or int and while the specs tell you how to detect that, this doesn't work for every model...which is why jPCT makes a guess at this point. Most of the time, this works fine. If it doesn't, you can disable it in Config... ;)
About OBJ: It's a strange format IMHO, because it supports object groups and such, but within a group, you can reference vertices from outside this group but only if they were defined ealier in the file. This makes parts of a group, which should be local IMHO, kind of global. I find this completely unintuitive. There are some other quirks with material definitions that belong to a group (so you expect them to be used in that group) but can be accessed from anyway later in the file. So it all comes down to one problem: A group in OBJ looks like a group but doesn't really act as one. That's what i dislike about it and what made it hard to make the loader work.

Edit: Some more references here:

http://www.jpct.net/forum2/index.php/topic,990.0.html
http://www.jpct.net/forum2/index.php/topic,923.0.html
« Last Edit: May 15, 2008, 09:03:30 am by EgonOlsen »