Hi,
I have a OBJ (with respective material files, MTL, etc.) model that I created myself and that I can load into Blender just fine.
I am now trying to load that model into jME3 and am having difficulty getting it to display correctly.
My full source code can be found here, and if you’re interested in reproducing what I’m seeing you just need to clone it and run gradlew run
(or ./gradlew run
on Mac) from a terminal. But the long-story short is that this code:
public class SampleApp extends SimpleApplication {
public static void main(String[] args) {
new SampleApp().start();
}
@Override
public void simpleInitApp() {
Spatial spatial = assetManager.loadModel("house-ext-front/house-ext-front.obj");
rootNode.attachChild(spatial);
/*
// Attempt to zoom the camera closer to the model...
float aspect = (float) settings.getWidth() / settings.getHeight();
float invZoom = 20f;
float product = aspect * invZoom;
cam.setParallelProjection( true );
cam.setFrustum( 0f, 150f, -product, product, -invZoom, invZoom );
cam.update();
*/
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
rootNode.addLight(sun);
}
}
…produces this scene graph/display.
Squinting at the model, it seems I have several issues:
- The model is not rotated/oriented as I had expected; and
- The model is fairly far away from the camera; and
- It almost looks like the OBJ file isn’t being read correctly, and/or the full mesh and textures aren’t being read correctly. But it’s hard to tell because the spatial is so far away from the camera.
For the rotation/orientation issue, I have tried adding and tweaking the arguments of this setter, but to no avail:
spatial.setLocalTranslation(0.0f, -5.0f, -2.0f) // I've played with many different arg values
For the issue regarding the model being far away from the camera, the following code (which is also in the snippet above) is what I tried to “zoom” the camera in, but that doesn’t help either:
/*
// Attempt to zoom the camera closer to the model...
float aspect = (float) settings.getWidth() / settings.getHeight();
float invZoom = 20f;
float product = aspect * invZoom;
cam.setParallelProjection( true );
cam.setFrustum( 0f, 150f, -product, product, -invZoom, invZoom );
cam.update();
*/
As for the model or its textures not being loaded correctly, I simply have no idea where that might be going wrong. It will be easier to tell once I have the first two issue solved. However, perhaps there is bad dat in the model/texture files that Blender simply ignores (or auto-corrects) that jME3 does not.
Can anybody steer me in the right direction here?