Hello,
i have a problem using UVW and 3ds.
The Method load3ds provided on this website should load the model with its texture.
The texture doesnt appear, the model stays gray but shades strange by rotating the object.
[ftp=ftp://home.arcor.de/michailo/uvw.rar]home.arcor.de/michailo/uvw.rar[/ftp]
UVW.rar contains the .3ds, .jpg, and the .uvw
public static Spatial load3ds(String modelPath, String textureDir) {
Spatial output = null; // the geometry will go here.
final ByteArrayOutputStream outStream =
new ByteArrayOutputStream(); // byte array streams don't have to be closed
try {
final File textures;
if(textureDir != null) { // set textureDir location
textures = new File( textureDir );
} else {// try to infer textureDir from modelPath.
textures = new File(
modelPath.substring(0, modelPath.lastIndexOf('/')) );
} // Add texture URL to auto-locator
final SimpleResourceLocator location =
new SimpleResourceLocator(textures.toURI().toURL());
ResourceLocatorTool.addResourceLocator(
ResourceLocatorTool.TYPE_TEXTURE, location );
// read .3ds file into memory & convert it to a jME usable format.
final FileInputStream rawIn = new FileInputStream(modelPath);
CONVERTER_3DS.convert(rawIn, outStream);
rawIn.close(); // FileInputStream s must be explicitly closed.
// prepare outStream for loading.
final ByteArrayInputStream convertedIn =
new ByteArrayInputStream(outStream.toByteArray());
// import the converted stream to jME as a Spatial
output = (Spatial) BinaryImporter.getInstance().load(convertedIn);
} catch (FileNotFoundException e) {
e.printStackTrace();
System.err.println("File not found at: " + modelPath);
} catch (IOException e) {
e.printStackTrace();
System.err.println("Unable read model at: " + modelPath);
} catch (URISyntaxException e) {
e.printStackTrace();
System.err.println("Invalid texture location at:" + textureDir);
} /*
* The bounding box is an important optimization.
* There is no point in rendering geometry outside of the camera's
* field of view. However, testing whether each individual triangle
* is visible is nearly as expensive as actually rendering it. So you
* don't test every triangle. Instead, you just test the bounding box.
* If the box isn't in view, don't bother looking for triangles inside.
*/
output.setModelBound(new BoundingBox());
output.updateModelBound();
return output;
}
The only thing I do is:
rootNode.attachChild(load3ds("res/uvw.3DS", "res/uvw.jpg");
What is wrong?