antu
August 24, 2010, 6:37pm
1
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?
dhdd
August 24, 2010, 7:33pm
2
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
antu
August 24, 2010, 8:15pm
3
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?
dhdd
August 25, 2010, 10:33am
4
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.
antu
August 25, 2010, 1:09pm
5
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();
nehon
August 25, 2010, 1:59pm
6
what's the content of the Scene.material file?
Maybe the problem occur during export from blender and not when importing to JME
dhdd
August 25, 2010, 2:15pm
7
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();
Myke
August 25, 2010, 2:49pm
8
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.
antu
August 25, 2010, 3:21pm
9
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.
antu
August 25, 2010, 3:33pm
10
And this is the object in blender:
nehon
August 25, 2010, 3:52pm
11
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
antu
August 25, 2010, 3:57pm
12
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.