Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11992 Posts in 1588 Topics- by 3508 Members - Latest Member: PienueDut

26. May 2012, 11:17:07 am
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)problems with obj loader
Pages: [1]
Print
Author Topic: problems with obj loader  (Read 4503 times)
hawkwind
Getting respectable
***
Offline Offline

Posts: 363



View Profile Email
« on: 07. December 2006, 01:57:07 am »

All

  One aspect of the OBJ missing textures is below in FaceList.  The loop using the array data does not return a valid Appearance for all Face's.  It is getting null at some point and that isa what is set for the Shape3d.  In my hack below I test for null Appearance and preserve the last good one.  Using the Archer.obj instead of the Galleon.obj model in the OBJLoaderTest I see a yellow Archer not a white-no-appearance archer.  Don't know what this means...but it is not right.  The code makes little sense to me though why iterate and find multiple Appearances if only a single one is used for the shape.

 
Code:
        Appearance app = null;
       
        for (int i=0;i<data.size();i++) {
            Face face = (Face) data.get(i);
            if(face.getAppearance()!= null)  //hawkwind hack
            {
            app = face.getAppearance();
            }
           
            //face.configure(array,currentVert);
            face.configure(dataPoints, dataCoords, dataNormals, currentVert);
            currentVert += face.getCount();
        }
       
        array.setCoordinates(0,dataPoints);
        if (texturesUsed) {
        if(dataCoords != null) {
        array.setTextureCoordinates(0, 0, dataCoords);
        }
        }
        array.setNormals(0,dataNormals);
       
        Shape3D shape = factory.createShape3D(array, app);
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #1 on: 07. December 2006, 04:10:16 am »

I had a further look at the ObjLoader. And the problem in my test is, that in FaceList the variable "texturesUsed" stays false. But this seems to be right, since Blender didn't export the texture-coordinates correctly.

@hawkwind: Why can't you simply send me a previously working obj+mtl+texture Huh Then I can effectively debug the loader. If you have license problems with your models, then please simply export something from AOI (you said it was easy). But please send me something. I am willing to fix the loader, but I can't do it without a model.

Marvin
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #2 on: 07. December 2006, 10:07:50 pm »

I still couldn't find any model with a working mtllib. But I found a model with correct texture coordinates, loaded it (as is) and applied the textures afterwards manually:

Code:
for (Shape3D shape: model.getShapeNodes())
{
    shape.getAppearance().setTexture( manuallyLoadedTexture );
}

And everything was fine. I really think, the problem is in the model. Please check, if the texture coordinates are correctly exported and the mtllib correctly linked. Then everything should be fine.

BTW: What format do your textures have? The ones I downloaded were in jpg format.

Marvin
Logged
hawkwind
Getting respectable
***
Offline Offline

Posts: 363



View Profile Email
« Reply #3 on: 08. December 2006, 12:22:18 am »

try the following...sorry it took so long, life has been perplexing recently.
this zip contain an square obj, a mtl file and a white and black grid texture.



http://home.mindspring.com/~hawkwind/xith-tree.zip

I use png/gif/jpg

I am convinced my models are correct as they worked up until my latst SVN pull.
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #4 on: 09. December 2006, 01:17:52 am »

try the following...sorry it took so long, life has been perplexing recently.
this zip contain an square obj, a mtl file and a white and black grid texture.

http://home.mindspring.com/~hawkwind/xith-tree.zip

Huh No it doesn't. It containse the sgtree info items (java files). Please resend the model.
Logged
hawkwind
Getting respectable
***
Offline Offline

Posts: 363



View Profile Email
« Reply #5 on: 09. December 2006, 01:43:02 pm »

i am an idiot...


 http://home.mindspring.com/~hawkwind/xith-obj.zip


Crap!!!  This loads ok for me.   

i wonder if I am getting hosed by the Texture loading stuff.  I have placed my models in demo\rooms\room1\ and am using a modified Xith3DDemoFolder.  if the obj's and PNG textures are in the same dir.  What path do i need to add to the TextureLoader.getInstance().addTextureStreamLocator to find the textures in a manner appropriate for the OBJ loader??
« Last Edit: 09. December 2006, 02:08:59 pm by hawkwind » Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #6 on: 09. December 2006, 03:18:06 pm »

i am an idiot...


 http://home.mindspring.com/~hawkwind/xith-obj.zip


Crap!!!  This loads ok for me.   

Yeah. The load definitely is ok. It is loaded with texture without problems and without modifications. Please doublecheck your model. It works perfectly for me. See the screenshot.

@Amos: Could you maybe send me the mirage.obj file, that you used for the XIN example?

i wonder if I am getting hosed by the Texture loading stuff.  I have placed my models in demo\rooms\room1\ and am using a modified Xith3DDemoFolder.  if the obj's and PNG textures are in the same dir.  What path do i need to add to the TextureLoader.getInstance().addTextureStreamLocator to find the textures in a manner appropriate for the OBJ loader??

Try this:
Code:
TextureLoader.getInstance().addTextureStreamLocator( new TextureStreamLocatorFile( "demo\rooms\room1\" ) );

Or, if your resources are in the classpath you can try:
Code:
TextureLoader.getInstance().addTextureStreamLocator( new TextureStreamLocatorURL( this.getClass().getClassLoader().getResource( "demo/rooms/room1/" ) );

The second way could also work, if loaded from file.

You should anyways use slashes in favor of backslashes (but never mix), since the File class also takes slashes on Windows (if not mixed), and it will work everywhere (not only on windows). And it just looks better Grin.

Marvin
Logged
hawkwind
Getting respectable
***
Offline Offline

Posts: 363



View Profile Email
« Reply #7 on: 09. December 2006, 04:08:50 pm »

Got part of it...

In the method of OBJLoader
Code:
private void load(BufferedReader bufferedReader, NodeFactory factory,
Vector3f vec, LoadedGraph<SceneGraphObject> graph)
throws IOException {

In this line, around 145 of  the OBJLoader class, currentApp was always null. 


Code:
else if (line.startsWith("usemtl")) {
String name = line.substring(line.indexOf(" ") + 1);
currentApp = matMap.get(name);
}

 I think it is because my *mtl file contains more than one entry.  The prblem is the line below return a single Appearance no matter how many are defined in the file, in my case many.

Code:
Appearance app = matLoader.parse(name);



My hack fix is o add a static public HashMap to MaterialLibLoader which hold all of the Appearance defined, indexed by Appearance name.  i then hacked the line as follows to extract the current Appearance from my HashMap.  This is an almost complete fix for me.


 
Code:
else if (line.startsWith("usemtl")) {
String name = line.substring(line.indexOf(" ") + 1);
System.out.println("usemtl:name "+name);
currentApp =(Appearance) MaterialLibLoader.allApps.get(name);
// currentApp = matMap.get(name);
}


I do need to point out in previous version this was not a problem.

My mtl file looks like this, note more than one "newmtl" entry

===================================================

#Produced by Art of Illusion 2.3.1, Sat Dec 09 09:36:11 EST 2006
 
newmtl rain_1
Kd 1 1 1
map_Kd Untitled131.png
Ks 1 1 1
map_Ks Untitled132.png
Ka 0 0 0
illum 2
Ns 129
newmtl note
Kd 1 1 1
map_Kd Untitled49.png
Ks 0 0 0
Ka 0.8 0.3 0
illum 1
newmtl hide_1
Kd 1 1 1
map_Kd Untitled107.png
Ks 0.3 0.3 0.12
Ka 0 0 0
illum 2
Ns 103
newmtl silver_4
Kd 1 1 1
map_Kd Untitled29.png
Ks 0.3 0.3 0.3
Ka 0 0 0
illum 2
Ns 103
Logged
hawkwind
Getting respectable
***
Offline Offline

Posts: 363



View Profile Email
« Reply #8 on: 09. December 2006, 04:23:46 pm »

multi appearance example, square (black/white) shpere (red/green), cylinder (wood pattern)

   

http://home.mindspring.com/~hawkwind/xith-obj-2.zip
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #9 on: 09. December 2006, 07:12:20 pm »

Thanks for the new example file. I will have a look at it this night.

Note, that there already is a HashMap holding all the read appearances. But maybe I messed something up with it. Your new example file will hopefully show it to me.

Marvin
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #10 on: 10. December 2006, 03:26:11 am »

The Loader is fixed now. See the SVN diffs for the specific lines I changed. Was my fault. Sorry for that.

Be aware, that the Untitled1.png in your archive is a strange one (not the black-and-white texture as before and as expected).

Marvin
Logged
hawkwind
Getting respectable
***
Offline Offline

Posts: 363



View Profile Email
« Reply #11 on: 10. December 2006, 04:27:21 am »

Coolllll Grin

Quote
Was my fault. Sorry for that.
Huh  None of that crap, no apologies expected or required.  You are making massive improvements (my game runs 200% faster and your render loop stuff exposed a nasty threading problem I had)  Keep up the good work...thanx for the help.

Most likely a good post for javagaming.org also.
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #12 on: 10. December 2006, 02:25:33 pm »

Coolllll Grin

Quote
Was my fault. Sorry for that.
Huh  None of that crap, no apologies expected or required.  You are making massive improvements (my game runs 200% faster and your render loop stuff exposed a nasty threading problem I had)  Keep up the good work...thanx for the help.

Oil on my soul. Thanks a lot for the compliments. And you're welcome.

Most likely a good post for javagaming.org also.

Agreed.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic