Load an object exported by using ogre xml

Hello, i created a simple cube colored with red, i exported and i tried to load it into jme, but the color is not shown, instead of a red cube, it appears a white cube, it does not show the real color, despite i used material state.

   
public static Node load(String mesh,String mat)
   {
        OgreLoader loader = new OgreLoader();
        MaterialLoader matLoader = new MaterialLoader();
       
        try {
            URL matURL = Model.class.getClassLoader().getResource(mat);
            URL meshURL = Model.class.getClassLoader().getResource(mesh);
            if (matURL != null){
                matLoader.load(matURL.openStream());
                if (matLoader.getMaterials().size() > 0)
                    loader.setMaterials(matLoader.getMaterials());
            }
            Node model = (Node) loader.loadModel(meshURL);
            return model;
        }
        catch (Exception e)
        {
           e.printStackTrace();
           return null;
        }
   }




compasBox = Model.load("res/Cube.mesh.xml", "res/Scene.material");
MaterialState ms = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
      ms.setDiffuse(ColorRGBA.red);
      ms.setAmbient(ColorRGBA.white);
      ms.setEnabled(true);
      compasBox.setRenderState(ms);



What can i be doing wrong?


      ms.setAmbient(ColorRGBA.white);



Everything is added to ambient color, if ambient is ALREADY white everything will be whiter than white, which is still white.

EDIT: that would depend on the light configuration though. try around with the colors

I changed the ambient to red, but nothing happened. The cube is still white. I also have a pointlight and if i change the ambient of this, the object is colored with that colour. What can be wrong?

It would be best if you could paste the whole loading and light generation code, but do you call this:



compasBox.updateRenderState();



after attaching the Material? If that doesn't solve it paste your code.

Here the code:


compasBox = Model.load("res/ogre/Cajon.001.mesh.xml", "res/ogre/Scene.material");
MaterialState ms = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
      ms.setDiffuse(ColorRGBA.gray);
      ms.setAmbient(ColorRGBA.gray);
      ms.setEnabled(true);
      compasBox.setRenderState(ms);

      rootNode.attachChild(compasBox);
      
      PointLight l=new PointLight();
      l.setEnabled(true);
      l.setLocation(new Vector3f(0, 10, -10));
      l.setDiffuse(ColorRGBA.white);
      l.setAmbient(ColorRGBA.lightGray);
      LightState ls=DisplaySystem.getDisplaySystem().getRenderer().createLightState();
      ls.attach(l);
      ls.setEnabled(true);
      
      rootNode.setRenderState(ls);
      rootNode.updateRenderState();

what's the content of the Scene.material file?

Maybe the problem occur during export from blender and not when importing to JME

You cannot really see anything conclusive because its all a grey soup.



try it with that configuration and repost a screenshot:



compasBox = Model.load("res/ogre/Cajon.001.mesh.xml", "res/ogre/Scene.material");
MaterialState ms = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
      ms.setDiffuse(ColorRGBA.blue.clone());
      ms.setAmbient(ColorRGBA.red.clone());
      ms.setEnabled(true);
      compasBox.setRenderState(ms);

      rootNode.attachChild(compasBox);
      
      PointLight l=new PointLight();
      l.setEnabled(true);
      l.setLocation(new Vector3f(0, 10, -10));
      l.setDiffuse(ColorRGBA.white.clone());
      l.setAmbient(ColorRGBA.white.clone());
                l.setSpecular(ColorRGBA.black.clone());
      LightState ls=DisplaySystem.getDisplaySystem().getRenderer().createLightState();
      ls.attach(l);
      ls.setEnabled(true);
      
      rootNode.setRenderState(ls);
      rootNode.updateRenderState();

Hi antu,

If you don't get any Diffuse or Specular light on your surface it might as well be because your surface normals point in the wrong direction. I guess you are rendering a closed shape.



Easiest way to check if this is the problem is to attach a CullState with "setCullFace(Face.Back)" to your object.

Should look like this:



CullState cs = display.getRenderer().createCullState();
cs.setEnabled(true);
cs.setCullFace(Face.Back);
compasBox.setRenderState(cs);



Regards, Myke.

Maybe blender is the problem:

This is the object renderer with blender.





Uploaded with ImageShack.us



But when i export using ogre xml the file generated is this:

material BaseWhite

{

technique

{

pass

{

}

}

}

And i get this error:

Error: Face(s) without material assignment in obj “Cajon”, mesh “Cajon”



But i do not know what face could be.

And this is the object in blender:



Ok,

the scene.material is empty,this mean something is not set correctly in blender



My guess is that there are no UV coordinate for your model.

Ogre only export UVs and materials associated with them.



You should check this way

What are uv coordinates? Sorry but i am a little noob with blender.

It seems it does not export materials, because if i export to .obj format the .mtl file is also empty.

Any help: http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro/UV_Map_Basics ?