[SOLVED] RenderState on Loaded Models Not Working

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...

You might be missing a call to updateRenderState after loading the scene.

I tried updating the render state at the end of simpleInitGame, but it didn't change anything.

It's likely that your tank model already has a material state set further down in the scene which is overriding your green tint.

Interesting, I'll have to check to see if that is the case.  Since I didn't set one, then ObjToJme must set one if no *.mtl library is provided?



Eventually I plan on using textured models, so it isn't a huge issue.  I just want to understand what is happening in this case.  Unfortunately, I'm at work now and won't be able to look more into it until later tonight.  Thanks for all of the help thus far.

You were right.  The ObjToJme loader was adding a material to the meshes, causing it to ignore the upstream settings.



Calling mesh.clearRenderState(RenderState.RS_MATERIAL) on each mesh after it was loaded fixed the issue.



Thanks for all the help!