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? ;D
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