Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3509 Members - Latest Member: lioneltenel

27. May 2012, 12:40:25 am
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)Appearance problem while using OBJ loader
Pages: [1] 2
Print
Author Topic: Appearance problem while using OBJ loader  (Read 3184 times)
Ludovic Marcé
Enjoying the stay
*
Offline Offline

Posts: 60


ludo123456@jabber.fr
View Profile
« on: 07. September 2007, 03:57:46 pm »

Hi again,

I've a problem loading OBJ objects with Xith in my application.
Better than an inexact explication, i show you my problem in attached image.
I think this is a problem about normals, but i don't know how to resolve it.

Do you know what happened and how to resolve this appearance problem ?
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #1 on: 07. September 2007, 04:02:37 pm »

Well, what did you expect the model to look like? I guess, you used a 3d modeler (blender?) to create the model. So you could attach a screenshot of blender showing the model.

Marvin
Logged
Ludovic Marcé
Enjoying the stay
*
Offline Offline

Posts: 60


ludo123456@jabber.fr
View Profile
« Reply #2 on: 07. September 2007, 04:35:01 pm »

The attached file show what i can see when loading and rendering it with Blender.
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #3 on: 07. September 2007, 04:36:51 pm »

Hmm... This looks indeed strange.

Could you maybe attach the .blend file and the .obj file?

Marvin
Logged
Ludovic Marcé
Enjoying the stay
*
Offline Offline

Posts: 60


ludo123456@jabber.fr
View Profile
« Reply #4 on: 07. September 2007, 04:39:27 pm »

Sure.
Logged
Ludovic Marcé
Enjoying the stay
*
Offline Offline

Posts: 60


ludo123456@jabber.fr
View Profile
« Reply #5 on: 10. September 2007, 03:48:18 pm »

Up !

Any idea ?
Logged
Mathias 'cylab' Henze
Fierce Warrior
****
Offline Offline

Posts: 540

1064620
View Profile WWW
« Reply #6 on: 10. September 2007, 03:56:04 pm »

I would say either the .obj does not specify the all triangles in the same order (clockwise/anticlockwise) or the importer does not correctly set up the triangles regarding this aspect from that file. And since your .obj file seems to not contain normals your get the wrong autogenerated ones. Try to add normals to your .obj export and see, if it makes any difference.
Logged

Ludovic Marcé
Enjoying the stay
*
Offline Offline

Posts: 60


ludo123456@jabber.fr
View Profile
« Reply #7 on: 10. September 2007, 06:26:31 pm »

Thanks for your answer. So, i suppose my OBJs aren't correct.
In fact, i create this OBJ file from a list of points on the fly.
See here why : http://xith.org/forum/index.php/topic,530.msg4566.html#msg4566

I think i should add normals (how?) when creating the OBJ file, or calculate them after loading the OBJ file.
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #8 on: 10. September 2007, 07:28:04 pm »

You could use calculateFaceNormals() to get some good normals.

Marvin
Logged
Ludovic Marcé
Enjoying the stay
*
Offline Offline

Posts: 60


ludo123456@jabber.fr
View Profile
« Reply #9 on: 10. September 2007, 08:13:34 pm »

Something like that?
Code:
            OBJModel model = new OBJLoader().loadModel( fileName );
            for (Shape3D shape : model.getShapeNodes())
            {
            ((TriangleArray)shape.getGeometry()).calculateFaceNormals();           
            System.out.println("getTriangleCount(): " + ((TriangleArray)shape.getGeometry()).getTriangleCount());
            }

But i know what is my problem now, the obj file i create is not good. Some faces are duplicated...  Sad
Is there any way to detect and remove duplicated triangles ?
Or you suggest me to create correct OBJ files instead ?
Logged
'n ddrylliog
Guru
*****
Offline Offline

Posts: 1188



View Profile WWW Email
« Reply #10 on: 10. September 2007, 08:15:34 pm »

I'd use something like epsilonEquals() from Point3f to test all the triangles' points.
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #11 on: 10. September 2007, 08:28:10 pm »

I guess, the simplest and most high performance way would be to search blender for a function like that.

Marvin
Logged
Ludovic Marcé
Enjoying the stay
*
Offline Offline

Posts: 60


ludo123456@jabber.fr
View Profile
« Reply #12 on: 10. September 2007, 09:19:17 pm »

I'd use something like epsilonEquals() from Point3f to test all the triangles' points.
I know this very useful fonction but i don't know exactly how to use it in this case. Huh

I guess, the simplest and most high performance way would be to search blender for a function like that.

Marvin
The problem is that i don't create these OBJ files from blender, but in the code when i want to convert on the fly the format used at my work.

So the best solution probably is to fix my converter. Smiley
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #13 on: 10. September 2007, 09:36:45 pm »

I know this very useful fonction but i don't know exactly how to use it in this case. Huh

Just loop over all triangles ( @see: getTriangle() ) in your model's shapes and compare each with each {O(n²)} using the Point3f.epsilonEquals() method.

Marvin
Logged
Ludovic Marcé
Enjoying the stay
*
Offline Offline

Posts: 60


ludo123456@jabber.fr
View Profile
« Reply #14 on: 10. September 2007, 10:34:24 pm »

In fact, i don't think this is a problem with duplicated faces.
I've tested with a small OBJ file with only 2 triangles, and i've the same problem as you can see.
The first screenshot shows the "front" side of my shape and the second shows the back side.
I also include the OBJ file.

Should i triangulate the shapes to avoid this phenomenon? If yes, how to do that?
Logged
Pages: [1] 2
Print
Jump to:  

Theme orange-lt created by panic