I tried to use code provided here https://wiki.jmonkeyengine.org/legacy/doku.php/starter:hello_modelloading?s[]=mtl to load .obj and the .mtl file. But all I can see is white object without any texture.
I am trying to load a model of a car and I am loading the model inside buildPlayer() function.
[java]private void buildPlayer() {
Spatial mesh=null;
FormatConverter converter = new ObjToJme();
URL model = RoadRunnerSimulation.class.getClassLoader().getResource(“jmetest/data/model/rapide/rapide.obj”);
URL mtl = RoadRunnerSimulation.class.getClassLoader().getResource(“jmetest/data/model/rapide/rapide.mtl”);
// Point the converter to where it will find the .mtl file from
converter.setProperty(“mtllib”,mtl);
ByteArrayOutputStream BO = new ByteArrayOutputStream();
try {
// Use the format converter to convert .obj to .jme
converter.convert(model.openStream(), BO);
mesh = (Node) BinaryImporter.getInstance().load(
new ByteArrayInputStream(BO.toByteArray()));
mesh.setLocalScale(10f);
mesh.setModelBound(new BoundingBox());
mesh.updateModelBound();
mesh.updateRenderState();
} catch (IOException e) { // Just in case anything happens
}
//set the vehicles attributes (these numbers can be thought
//of as Unit/Second).
player = new MyCar(“Player Node”, mesh);
player.setAcceleration(15);
player.setBraking(15);
player.setTurnSpeed(2.5f);
player.setWeight(25);
player.setMaxSpeed(25);
player.setMinSpeed(15);
player.setLocalTranslation(new Vector3f(100, 0, 100));
scene.attachChild(player);
scene.updateGeometricState(0, true);
agl = ((BoundingBox) model.getWorldBound()).yExtent;
player.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
}[/java]
I tried parsing URL model instead of URL mtl but nothing changed. When I gave the directory that contain mtl file car didn’t appear at all.
Any help is greatly appreciated
Create a resource locator:
[snippet id=“11”]
Or use jme3 which has a proper asset manager
1 Like