For some reason I am having a hard time figuring out how to add obj models to JME. I am new to JME and have not imported models before (other than the sample assets tutorial).
I created a basic model in Blender and exported it as an obj. I added the obj to the project/assets/models folder and the mtl to the the materials folder. Unfortunately, I am still unable to see the model when I run the program. The scene appears black. I am able to see a 1x1x1 cube created in JME.
The object is a default square with another square intersecting it. Both squares have default textures.
public class TestImport extends SimpleApplication {
public static void main(String[] args){
TestImport app = new TestImport();
app.start();
}
@Override
public void simpleInitApp(){
Spatial object = assetManager.loadModel(“Models/TestingOBJ/TestingOBJ.obj”);
rootNode.attachChild(object);
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(-2f,-2f,-2f).normalizeLocal());
rootNode.addLight(sun);
}
}
Help please!
Textures are not exported in .obj files, and therefore you are trying to view an untextured asset within JME. Try adding a Material to the object after using the asset manager to load the model.
public class TestImport extends SimpleApplication {
public static void main(String[] args){
TestImport app = new TestImport();
app.start();
}
@Override
public void simpleInitApp(){
Spatial object = assetManager.loadModel(“Models/TestingOBJ/TestingOBJ.obj”);
Material mat_default = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
object.setMaterial(mat_default);
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(-2f,-2f,-2f).normalizeLocal());
rootNode.addLight(sun);
}
}
So that JME knows where to find them, ensure that you have placed your assets in the assets/Textures/ folder.