Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (604)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (654)
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 4432 times)
0 Members and 1 Guest are viewing this topic.
Offline ww

Senior Newbie

« Posted 2007-02-11 07: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();
        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:

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

Offline ww

Senior Newbie

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

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

Is this accurate?

Offline ww

Senior Newbie

« Reply #2 - Posted 2007-02-11 08: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:

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):

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

Junior Devvie

There is nothing common about common sense

« Reply #3 - Posted 2007-02-12 13: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:

Have you tried something like that?

Offline ww

Senior Newbie

« Reply #4 - Posted 2007-02-12 15: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 Devvie

There is nothing common about common sense

« Reply #5 - Posted 2007-02-12 20: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?

Offline ww

Senior Newbie

« Reply #6 - Posted 2007-02-13 06: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 Devvie

There is nothing common about common sense

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

Anyway you can convert to another file format?

Offline ww

Senior Newbie

« Reply #8 - Posted 2007-02-20 05: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 06: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 08: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.

bilznatch (27 views)
2015-08-04 11:03:17

SHC (44 views)
2015-08-01 03:58:20

Jesse (25 views)
2015-07-29 04:35:27

Riven (48 views)
2015-07-27 16:38:00

Riven (26 views)
2015-07-27 15:35:20

Riven (28 views)
2015-07-27 12:26:13

Riven (19 views)
2015-07-27 12:23:39

BurntPizza (42 views)
2015-07-25 00:14:37

BurntPizza (56 views)
2015-07-24 22:06:39

BurntPizza (35 views)
2015-07-24 06:06:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 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‑
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!