Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (578)
games submitted by our members
Games in WIP (499)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Problem loading Wavefront textures in Java3D  (Read 3614 times)
0 Members and 1 Guest are viewing this topic.
Offline ww

Senior Newbie





« Posted 2007-02-11 08:38:47 »

Hi all,

I am using the Wavefront loader that comes with Java3D to load an .obj model. The model has a reference to a .mtl file that in turn has multiple references to a single .jpg texture file.

When I load the .obj file using PoseRay, both the geometry and the texture load just fine. However, when I load the .obj using ObjectFile in Java3D, only the geometry loads--no textures.

I went into the .obj and .mtl files to tweak the references and see whether they have the expected effect on the model when loading it into PoseRay. The tweaks have exactly the expected effect. For example, if inside the .mtl file I break a reference to the .jpg file, then the corresponding texture disappears from the loaded model in PoseRay. So I am comfortable that the .obj and .mtl files are at least what PoseRay expects.

Note that the .obj and .mtl files were originally generated by PoseRay from a .3ds file. I used PoseRay to load a .3ds model and export as .obj. When PoseRay exports to .obj it uses absolute file paths for the .jpg references. I changed those to relative file paths and then loaded them back into PoseRay just to make sure that PoseRay would still be able to find the .jpg.  It was able to.

Also, I tried leaving in the absolute file paths and putting the .jpg file at the required location, and then loading using Java3D. No luck either with absolute or relative paths to the .jpg. I'm assuming that if I have the .obj, .mtl, and .jpg in the same directory, then I can reference the .mtl from .obj using the filename alone, and that I can reference the .jpg file from the .mtl file using the filename alone.

So: Does the ObjectLoader support loading the referenced textures?   Grin

Here is the Java code I am using:

        ObjectFile objFile = new ObjectFile();
        InputStream is = ClassLoader.getSystemResourceAsStream("path/to/model.obj"); // This works; I see the geom
        Scene scene = objFile.load(new InputStreamReader(is));
        Map<String, Shape3D> map = scene.getNamedObjects();
        BranchGroup root = scene.getSceneGroup();
        root.removeAllChildren();
        Shape3D shape = map.get("medievalHouse");

Also, I saw this thread, which appears to describe a problem similar to the one I'm having, but it doesn't seem that I should have to use LWJGL to solve the problem:

http://www.java-gaming.org/forums/index.php?topic=13753.0

Thanks for any help that people may be able to offer.

Willie
Offline ww

Senior Newbie





« Reply #1 - Posted 2007-02-11 08:55:56 »

I just saw this post, which claims that Wavefront models loaded by ObjectFile are untextured:

http://www.java-gaming.org/forums/index.php?topic=15114.0

Is this accurate?

Thanks,
Willie
Offline ww

Senior Newbie





« Reply #2 - Posted 2007-02-11 09:21:09 »

I'm going through the forums and looking for more related posts, partly to try to solve my problem and partly to consolidate information for the benefit of others who may in the future have the same issue.  Here is a post from a long time ago:

http://www.java-gaming.org/forums/index.php?topic=123.0

The thing on the minimart is that the texture files are type .int, .inta, and some others.  No .jpg.  Yet according to the following page, .jpg is a supported texture file format (see the bottom):

http://java3d.j3d.org/utilities/loaders/obj/sun.html

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #3 - Posted 2007-02-12 14:31:16 »

So I use the VRML97 Loader for my projects.  I have noticed that relative paths don't work.  Meaning, if my texture file is called texture.jpg then inside my VRML file, I have to remove the path to this file (which is automatically set by my 3D Modeler program).  I then have to copy the texture file to the same directory as the .wrl file.

So the director would look like this:
data/object.wrl
data/texture.jpg

Have you tried something like that?

Ubuntu
Offline ww

Senior Newbie





« Reply #4 - Posted 2007-02-12 16:16:29 »

Thanks Conzar for the reply. Yup, that is exactly the approach that I have been trying to make work.  Smiley  (But with .obj files rather than .wrl files.)  The modeler tool outputs the materials and texture files to the same directory as the model file (good), but uses absolute file paths in the model file (bad). So I go in and replace the absolute file paths with relative file paths. The modeler tool still finds the materials and textures.  But Java3D--specifically, ObjectFile it would seem--doesn't find them, or doesn't care about them, or something.  And Java3D doesn't find them with the absolute paths either.
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #5 - Posted 2007-02-12 21:57:21 »

Hey.  Try to not use paths at all.

Meaning, put your textures in the same directory as what they are applied to.

Inside the model file, point the texture path just to the file name itself

Did you try that?

Ubuntu
Offline ww

Senior Newbie





« Reply #6 - Posted 2007-02-13 07:24:56 »

Yeah, that's the approach I've been taking all along. I just put the three files in the same directory and just used filenames for references. PoseRay was able to resolve the refs just fine but no such luck with Java3D. I suspect that ObjectFile doesn't know how to handle the materials reference.  Cry
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #7 - Posted 2007-02-16 19:15:08 »

Anyway you can convert to another file format?

Ubuntu
Offline ww

Senior Newbie





« Reply #8 - Posted 2007-02-20 06:07:45 »

That's a good idea.  I guess I'll try that then.  Either that or maybe look for a better OBJ loader...
Offline ww

Senior Newbie





« Reply #9 - Posted 2007-02-20 07:01:45 »

Well, somehow the Java3D OBJ loader *can* load textures.  :-)  I just tried using the demo ObjLoad demo program, which uses the ObjectFile Wavefront loader, and it correctly loaded both the geometry and the textures.  So I just haven't figured it out yet.  I'll crack open the source code and when I figure out what I've been doing incorrectly I'll post it.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ww

Senior Newbie





« Reply #10 - Posted 2007-02-21 09:18:44 »

Hooray, I figured out what was wrong, and now the model has textures:



The problem was related to my having tried to use an InputStream and InputStreamReader to load the model instead of using a URL.  With the InputStream, apparently ObjectFile did not know the base directory for resolving the reference to the materials file.  Once I switched over to using a URL, ObjectFile was able to figure it out...

Thanks Conzar for your help.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (28 views)
2014-04-15 18:08:23

BurntPizza (25 views)
2014-04-15 03:46:01

UprightPath (40 views)
2014-04-14 17:39:50

UprightPath (22 views)
2014-04-14 17:35:47

Porlus (38 views)
2014-04-14 15:48:38

tom_mai78101 (62 views)
2014-04-10 04:04:31

BurntPizza (121 views)
2014-04-08 23:06:04

tom_mai78101 (221 views)
2014-04-05 13:34:39

trollwarrior1 (188 views)
2014-04-04 12:06:45

CJLetsGame (195 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!