Pratical challange of coloring

Hi,

I tried mmmh… many things to paint my object blue, but it maintains either white or black. I require that lightning keeps on.

I would like to give you my object and you could try to render it blue in a SimpleGame or whatever you like.

package mce.test;

import java.io.IOException;

import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.scene.Spatial;
import com.jme.util.export.binary.BinaryImporter;

public class TestColoring extends SimpleGame
{
public static void main(String[] args)
{
TestColoring t = new TestColoring();
t.start();
}

@Override
protected void simpleInitGame()
{
//Load the gate object.
Spatial s=null;
try
{
s=(Spatial) BinaryImporter.getInstance().load(getClass().getClassLoader().getResource(“mce/game/data/models/gate_checkpoint.jme”));
s.setModelBound(new BoundingBox());
s.updateModelBound();
}
catch (IOException e)
{
e.printStackTrace();
}

  //Here you can try to render the gate blue
  
  rootNode.attachChild(s);

}

}

s.getDefaultColor().r=0;

s.getDefaultColor().g=0;

s.getDefaultColor().b=1;

s.getDefaultColor().a=0;



or

s.setDefaultColor(new ColorRGBA(0,0,1,0));



You might have to declare it as Geometry (or better yet Node) instead of Spatial (i don't think spatial has default colors)

If you want to use lighting, you'll want to create a MaterialState and set the diffuse to blue.

Scene Monitor is a invaluable tool.



your .jme scene has already a MaterialState set.

You need to either retrieve this MaterialState and modify its values or save the scene without the Materialstate, if you want to color it later.

Better yet, set the correct MaterialState and then save the scene :slight_smile:



Thank you!



SceneMonitor is a great tool, it is amazing helpful.



The properties sidebar can figure out the material state of the spatial. So if the tool can do this, a programmer should be able to do that as well.



How can I retrieve the materialState out of the spatial as the tool is able to do? I don't know how to save the spatial with the new properties other than using the BinaryExporter which would save the spatial.

something like:



if you have more then one child you can get the correct child also by its name.


       Node tdsScene  = (Node)rootNode.getChild(0);
      Node castle = (Node)tdsScene.getChild(0);
      Spatial spatial = castle.getChild(0);
      MaterialState ms = (MaterialState)spatial.getRenderState(RenderState.RS_MATERIAL);
      ms.setDiffuse(ColorRGBA.blue);
      ms.setAmbient(ColorRGBA.blue);

renanse said:

If you want to use lighting, you'll want to create a MaterialState and set the diffuse to blue.


I want to set the color of my objects manually so I don't need lighting.  How would you do this for a Node object?  Here's the maggie code which I've got.

            Node maggie=(Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
            maggie.setLocalScale(10.f);
            maggie.setModelBound(new BoundingSphere());
            maggie.updateModelBound();
            rootNode.attachChild(maggie);

harsha said:

I want to set the color of my objects manually so I don't need lighting.  How would you do this for a Node object?  Here's the maggie code which I've got.

            Node maggie=(Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
            maggie.setLocalScale(10.f);
            maggie.setModelBound(new BoundingSphere());
            maggie.updateModelBound();
            rootNode.attachChild(maggie);




try maggie.setDefaultColor(new ColorRGBA(0,0,1,0));

Node doesn't have that method, Geometry does. 



Answer)I found some code in Arrow which finds the geometry child.

           for (int x = 0; x < maggie.getQuantity(); x++) {

               if (maggie.getChild(x) instanceof Geometry)

                   ((Geometry)maggie.getChild(x)).setDefaultColor(ColorRGBA.red);

           }







Question) When I import an obj file and display it to the screen, it displays the colors that I initialised from Blender.  That's great the material importing works there.  My question is where does that information exist?  If I extract out the geometry and call getColorBuffer() it returns null.  But when I display the object, the colors are there.