Im using this code to load models:
private Node loadModel(String fileName) {
Spatial model = null;
try {
String format = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());
File binary = new File(fileName.substring(0, fileName.lastIndexOf(".") + 1) + "jme");
if (!binary.exists()) {
FormatConverter formatConverter = null;
if (format.equalsIgnoreCase("ase")) {
formatConverter = new AseToJme();
} else if (format.equalsIgnoreCase("3ds")) {
formatConverter = new MaxToJme();
} else if (format.equalsIgnoreCase("md2")) {
formatConverter = new Md2ToJme();
} else if (format.equalsIgnoreCase("md3")) {
formatConverter = new Md3ToJme();
} else if (format.equalsIgnoreCase("ms3d")) {
formatConverter = new MilkToJme();
} else if (format.equalsIgnoreCase("obj")) {
formatConverter = new ObjToJme();
} else if (format.equalsIgnoreCase("x3d")) {
formatConverter = new X3dToJme();
}
File file = new File(fileName);
formatConverter.setProperty("texurl", file.getParentFile().toURI().toURL());
formatConverter.setProperty("mtllib", file.toURI().toURL());
ByteArrayOutputStream output = new ByteArrayOutputStream();
formatConverter.convert(file.toURI().toURL().openStream(), output);
BinaryImporter importer = BinaryImporter.getInstance();
model = (Spatial) importer.load(new ByteArrayInputStream(output.toByteArray()));
// BinaryExporter.getInstance().save((Savable) model, binary);
} else {
model = (Spatial) BinaryImporter.getInstance().load(binary.toURI().toURL());
}
} catch (Exception exception) {
exception.printStackTrace();
model = new Box("box", new Vector3f(), 15, 15, 15);
}
Node node = new Node("model");
node.attachChild(model);
return node;
}
The model loads fine but with no textures (grey) and I get warning like:
WARNING: Unable to locate: char_0.png
This file is on the same folder of my model, and I thought that this line
formatConverter.setProperty("texurl", file.getParentFile().toURI().toURL());
Some one could help me?
PS: I'm loading milkshape models