Author Topic: 3ds model texture behavior  (Read 2269 times)

Offline Nick

  • byte
  • *
  • Posts: 8
    • View Profile
3ds model texture behavior
« on: December 15, 2010, 11:05:22 pm »
Hello,

I'm having difficulties with displaying and texturing some 3ds models, made in sketchup. When displaying and rotating  the camera, at different angles some models are seen through other models. Turning the camera stops it at some angles. I've added some screenshots for better explanation.

The "wrong" angle: http://img810.imageshack.us/i/wrongb.png/

The "good" angle: http://img217.imageshack.us/i/gooddv.png/

This is the code which I use to import 3ds files and edit them a bit.
Code: [Select]
private Object3D getBuilding(String link, float x, float y, float z, float rotate, String texture) {

Object3D obj = null;
Object3D[] imports = Loader.load3DS(link, 1f);
if (imports.length > 0) {
obj = imports[0];
}
obj.rotateX((float) -Math.PI / 2f);
obj.rotateY((float) ((rotate / 180) * Math.PI));
obj.translateMesh();
obj.rotateMesh();
obj.setTranslationMatrix(new Matrix());
obj.setRotationMatrix(new Matrix());
obj.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
obj.setEnvmapped(Object3D.ENVMAP_ENABLED);
obj.setTexture(texture);
obj.translate(x, y, z);
obj.build();

return obj;
}

Does somebody know why this behavior is taking place?

Greetings,

Nick

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: 3ds model texture behavior
« Reply #1 on: December 16, 2010, 12:34:46 am »
From the picture, it seems like there are parallel faces that are too close to each other (the floor vs. the ground), and that is causing some interference over which ones are closer to the camera and should be drawn.  Try raising the house up from the ground a bit to see if that helps.

--EDIT-- if that brown texture is part of the house model, you might have to edit the model a bit to increase the distance between those polys and the wall's polys.
« Last Edit: December 16, 2010, 12:36:20 am by paulscode »

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
Re: 3ds model texture behavior
« Reply #2 on: December 16, 2010, 03:35:21 pm »
Another thing you might want to do is mess around with the scale a bit.  Generally a larger scale will have less problems with separations like that.  I did it in the game I'm currently working on because at a lower scale, the objects couldn't be as close together, relatively speaking.
click here->Fireside 7 Games<-

Offline Nick

  • byte
  • *
  • Posts: 8
    • View Profile
Re: 3ds model texture behavior
« Reply #3 on: December 16, 2010, 06:44:31 pm »
@paulscode
I'm using different objects, so the dark gray/brown color is another model, behind the light gray model. But i'm also finding troubles when looking to just one object, then I'll see through it and can see the other side (Just at some angles, also like above screenshots)

@fireside
I've been messing around with the scaling, but it doesn't seem to help. Also when having objects farther from each other I can look through them.

Also tried to turn off fogging, but didn't help.

Also very funny when compiling the objects, it's even getting worse! Look at the screenshot:

http://img46.imageshack.us/i/compiledp.png/

Does anybody have some tips or have (had) the same problems?

Greetings,

Nick

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
Re: 3ds model texture behavior
« Reply #4 on: December 16, 2010, 08:17:11 pm »
Have you checked to see all your normals are going in the right direction?
click here->Fireside 7 Games<-

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: 3ds model texture behavior
« Reply #5 on: December 16, 2010, 08:50:47 pm »
The best way to determine exactly what is causing your problem, is to to have just the one object in the scene (with a black, empty background), and then look at it from the inside at various angles.  If you can still see through it at certain angles, then it is probably a problem with the normals.  If you are instead seeing odd triangles showing up that are not black, then it is probably due to some stray polygons in your model that shouldn't be there, which are protruding through the model, and only visible from certain angles.  If everything looks fine from whatever angle, then it is probably a problem with parallel faces being too close to each other.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: 3ds model texture behavior
« Reply #6 on: December 16, 2010, 09:05:03 pm »
Any transparency used on these objects?

Offline Nick

  • byte
  • *
  • Posts: 8
    • View Profile
Re: 3ds model texture behavior
« Reply #7 on: December 17, 2010, 01:11:29 pm »
@EgonOlsen
I'm not using transparency on one of the objects.

@fireside and pauslcode
I've made a new scene with only one object in it, and it still happens, like above screenshot in my last post. You both say it then must be a problem with my normals. What do you actually mean with that? I know normals are vectors that are perpendicular to a surface, but I can't connect that with my problem.

Thanks for your time,

Nick

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: 3ds model texture behavior
« Reply #8 on: December 17, 2010, 01:19:24 pm »
The usual problem with normals is reversed normals, which results in the backface culling taking out polys that you expect to be visible.  The easiest way to check for this is to call setCulling(false) on your object and see if the behavior is still there.

Offline Nick

  • byte
  • *
  • Posts: 8
    • View Profile
Re: 3ds model texture behavior
« Reply #9 on: December 17, 2010, 01:55:37 pm »
Hmm, tried the setCulling to false, but nothing helped. I'm now trying to edit an object to make smaller triangles, maybe that helps. I could just give it a try though...

EDIT: Coming back on what paulscode said before: faces which are almost parallel to each other are probably the problem. I was working with generated triangles, but the triangles where not that logical placed. Made one object already with my own triangles, and it's not flickering anymore. And another difference is the size of the 3ds file, it's increased by 20%. I will edit this post if I done with the tests.
« Last Edit: December 17, 2010, 02:13:48 pm by Nick »