Im not sure if im just doing something wrong, but i have been messing around with loading 3d models for a while now but i have hit a snag… When i load a .obj everything is fine, my code is…
URL model = MainGameState.class.getClassLoader().getResource("org/src/level.obj");
FormatConverter converter = new ObjToJme();
ByteArrayOutputStream BO = new ByteArrayOutputStream();
BinaryImporter jbr = new BinaryImporter();
TriMesh level = null;
ts1 = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
ts1.setEnabled(true);
ts1.setTexture(TextureManager.loadTexture(MainGameState.class.getClassLoader() .getResource("org/src/stone.jpg")));
for(int x=0;x<1;x++ ) {
try { converter.convert(model.openStream(), BO);
level = (TriMesh) jbr.load(new ByteArrayInputStream(BO.toByteArray()));
}
catch (IOException e) { e.printStackTrace(); System.exit(0); } level.setLocalScale(.1f); level.setRenderState(ts1);
level.setLocalTranslation(new Vector3f(0,-100,0));
level.setModelBound(new BoundingBox());
level.updateModelBound();
}
and this works great, i add it to a physicsNode and all is well. however when i try and load a .3DS file i have some trouble. I cant seem to find a way to load such a file type into a YriMesh format. Every way i can find loads it into a Node. When i try and attach this to a physicsNode it yells at me saying there is no TriMesh to be used. is there anyway to load a 3ds in a way that would work with Jbullet, or in the end get me int he right format? just for reference this is some of the code i was trying to use to load the 3ds.
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()));
return model;
} catch(IOException e) {
e.printStackTrace();
}
}
// no cached model found -> convert the 3ds file and cache it
try {
ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE,
new SimpleResourceLocator(file.getParentFile().toURI()));
converter.convert(new FileInputStream(file), bo);
model = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(bo.toByteArray()));
bo.writeTo(new FileOutputStream("cache/"+file.getName()+".jme"));
ResourceLocatorTool.removeResourceLocator(ResourceLocatorTool.TYPE_TEXTURE,
new SimpleResourceLocator(file.getParentFile().toURI()));
} catch(IOException e) {
e.printStackTrace();
}
return model;
}
i tried a few other ways, but in the end they all do the same thing.. any help would be great.