I created a simple model in Art of Illusion and exported it to Wavefront (*.obj). I did not export any materials, so there is no *.mtl file. It displays the model colored white. I then tried to add a material state to color it green, but it doesn't work. The model is still white.
Just to test to see if it was something specific to the loaded model, I threw a Box into the scene and it showed up with a green tint fine.
Here is the important code:
@Override
protected void simpleInitGame() {
TriMesh base = loadMesh("base");
Node turretNode = new Node("Turret Node");
turretNode.attachChild(loadMesh("turret"));
initRotationalSpatialTransformer(turretNode);
Box b = new Box("My box", new Vector3f(2, 2, 2), new Vector3f(3, 3, 3));
b.setModelBound(new BoundingBox());
b.updateModelBound();
Node tankNode = new Node("Tank Node");
tankNode.setRenderState(getGreenMaterial());
initLighting(tankNode);
// shrink this baby down some
tankNode.setLocalScale(.5f);
tankNode.attachChild(base);
tankNode.attachChild(turretNode);
tankNode.attachChild(b);
// Put her on the scene graph
rootNode.attachChild(tankNode);
}
private MaterialState getGreenMaterial() {
// Get a MaterialState
MaterialState ms = display.getRenderer().createMaterialState();
// Give the MaterialState an emissive tint
ms.setEmissive(new ColorRGBA(0f, .4f, 0f, 1));
return ms;
}
private TriMesh loadMesh(String model) {
ClassLoader loader = TankAnimation.class.getClassLoader();
// Point the converter to where it will find the .mtl file from
//converter.setProperty("mtllib",model);
URL modelURL = loader.getResource("com/polarflare/data/model/" + model + ".obj");
// This byte array will hold my .jme file
ByteArrayOutputStream output = new ByteArrayOutputStream();
// Create something to convert .obj format to .jme
FormatConverter converter = new ObjToJme();
TriMesh mesh = null;
try {
// Use the format converter to convert .obj to .jme
converter.convert(modelURL.openStream(), output);
mesh = (TriMesh) BinaryImporter.getInstance().load(new ByteArrayInputStream(output.toByteArray()));
} catch (IOException e) { // Just in case anything happens
logger.logp(Level.SEVERE, this.getClass().toString(),
"simpleInitGame()", "Exception", e);
System.exit(0);
}
mesh.setModelBound(new BoundingBox());
mesh.updateModelBound();
return mesh;
}
I'm fairly new to this, so it is probably something simple...