Hello everyone! I just don't get my textures loaded with the model.
I wrote the following method to load the model:
public Node getModel3ds(File file) {
FormatConverter converter = new MaxToJme();
Node model;
ByteArrayOutputStream bo = new ByteArrayOutputStream();
File input = new File("cache/"+file.getName() + ".jme");
// check if a converted version of the model already exists
if(input.isFile()) {
converter.setProperty("texurl", file.getParentFile().toURL());
converter.convert(new FileInputStream(file), bo);
model = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(bo.toByteArray()));
// save model to jme format
bo.writeTo(new FileOutputStream("cache/"+file.getName()+".jme"));
} catch(IOException e) {
e.printStackTrace();
model = new Node();
}
return model;
}
The textures are in the same directory as the 3ds file, but they aren't loaded.
I've been searching the forum for at least an hour but could not find a (working) solution.
As you can see i try to set the path with converter.setProperty, but it has no effect, as it seems.
Also i read about using TextureKey.setOverrideLocation, but this method does not exist any more
in my jME version. So I'm pretty much stumped.
For other beginners i'll post the code of my 3ds model loading method, maybe it's useful for someone.
This method tries to load a model specified by "file". If it could be loaded the file will be saved in jme format
into the directory "cache" (relative to the project directory). Next time the method is called a saved model
will be loaded from that "cache" right away for speeding things up.
public Node getModel3ds(File file) {
FormatConverter converter = new MaxToJme();
Node model = null;
ByteArrayOutputStream bo = new ByteArrayOutputStream();
File input = new File("cache/"+file.getName() + ".jme");
// check if there is a cached jme format model for the requested file
if(input.isFile()) {
try {
ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE,
new SimpleResourceLocator(file.getParentFile().toURI()));
model = (Node)BinaryImporter.getInstance().load(input);
ResourceLocatorTool.removeResourceLocator(ResourceLocatorTool.TYPE_TEXTURE,
new SimpleResourceLocator(file.getParentFile().toURI()));
Wow, I can't believe it took so long for me to find your post. I've been searching all over the place to try and figure out why my textures weren't showing up. Thanks for sharing that simple code, it is exactly what I needed (though I doubt you're still watching this post after a year).