Changing materials (3ds imported models)

Hi people,



i'v been trying to change the materials of the models that i have imported from 3dsmax (using 3ds).

The model looks okey but is to shiny, has some transparacy in it, etc.



i'v been trying to change the materials when i load them in and have tried to locate a node and then change it materials. both not working…



So heres my code:



part of "loadModel function" fond on the great forum :slight_smile: :



try {
            formatConverter.convert(modelURL.openStream(), BO);
            loadedModel = (Node) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
            
            if (modelFormat.equals("3ds")) {
               //3ds from max gets exporter in wrong direction
               Quaternion rotate = new Quaternion();
               rotate.fromAngleAxis(FastMath.PI / 2, new Vector3f(-1, 0, 0));
               loadedModel.setLocalRotation(rotate);
               //set material stuff // testing....
               MaterialState ms = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
                 ms.setEnabled(true);
               ms.setShininess(0);
               ms.setDiffuse(ColorRGBA.red);
               ms.setAmbient(new ColorRGBA(0,0,0,0));
               ms.setSpecular(new ColorRGBA(0,0,0,0));
               ms.setEmissive(new ColorRGBA(0,0,0,0));
               loadedModel.setRenderState(ms);
               loadedModel.updateRenderState();
               
               
               
            }



and a other function "setWater" (when finished this function set a water material.. i  hope):


private void setWater() {
      System.out.println("Try to locate a water object and change its material... pfieuwww");

      Spatial wNode = rootNode.getChild("Plane01");
      
      
      MaterialState ms = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
      ms.setDiffuse(new ColorRGBA(1,0,0,1));
      ms.setEnabled(true);
      ms.setColorMaterial(ColorMaterial.Diffuse);
      wNode.setRenderState(ms);
      wNode.updateRenderState();
      //System.out.println(wNode.getName());
      
   }



both of them seem to have no effect, so i'm guessing i'm doing something wrong.
But i have yet not found an working method on this forum/wiki/javadocs

Perhaps you can show me how to do this. but als important how to find the information that i need to solve this problem. for example the javadocs have a list of sorta functions but i kinda lacks on usefull examples or howto use... perhaps this is something to work on.. ?

Best regards!

Try using Scene Monitor to play with your material settings. This will show you exactly in the scene hierarchy where your material states are and also demonstrate the different settings and their effects. Once you get that far, you should be better poised to make those changes in your code.

wow thats some handy thing! thx for the pointer!



But i have a question tho.



in my function load model i set a materialstate and assing it to "loadedModel"

in the code i posted you can see i set some stuff to colorRGBA (0,0,0,1)



But if i look in the scenemonitor they all have different values.

thus this is not applied… any idea why ?




pixelstudio said:

in my function load model i set a materialstate and assing it to "loadedModel"
in the code i posted you can see i set some stuff to colorRGBA (0,0,0,1)

But if i look in the scenemonitor they all have different values.
thus this is not applied..... any idea why ?

Does the loaded model already have a materials state? I don't have jME in front of me but I would guess that setting a renderstate would overwrite any existing one, but maybe thats not the case. If loadedmodel already has a material state, then try either removing that one, or using it instead of a new one.

hmm still no luck here, trying several things but no sollution yet.



however i see in the scenegraph



plane01>

    Material State

    Plane01##0

              Material Sate

              Render State





So i looks like it hase two material states and the last one is gettings applied.

So thats not good.

perhaps any1 can show me how to set the material state on the correct child…cause i have no clue how to set it on the "child" cuase model.getChild does not work…



thx again

The material state of Plane01##0 will override the settings of the material state of plane01. It works just like inheritance, all renderstates are applied down the tree, adding a renderstate to a child will override the renderstate settings of a parent.

So if we wanted to remove the material state from Plane01##0 we would do this…


 

Spatial plane01__0 = loadedModel.getChild("Plane01##0");

if(plane01__0 != null) {
    plane01__0.clearRenderState(MaterialState.getType());
    plane01__0.updateRenderState();
}


Seem pretty logical.



However i have not found a way to clear the material state of the Plane01##0 object.

Or found a way to replace the materialstate under Plane01##0 with a new one…



i dont seem to find a child of plane01…



how do you do this… ?