Error When Applying Lighting

Hello,
I was recently trying to add lighting to my mesh and when I did the program crashed and the message “Material parameter is not defined: VertexColor” is displayed… I am not sure how to fix this… Here is the code that corresponds with this section. All help is appreciated, thanks!
[java]
mesh.setBuffer(Type.Position,3,BufferUtils.createFloatBuffer(vertices));
mesh.setBuffer(Type.Index,3,BufferUtils.createIntBuffer(IndexArr));
mesh.setBuffer(Type.Color,4,(colorArr));
mesh.updateBound();
DirectionalLight light = new DirectionalLight();
light.setColor(ColorRGBA.White);
light.setDirection(new Vector3f(1f,1f,1f).normalizeLocal());
rootNode.addLight(light);
Geometry geo = new Geometry(“PlanetMesh”,mesh);
TangentBinormalGenerator.generate(geo);
Material mat = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);
mat.setBoolean(“VertexColor”, true);
mat.setColor(“Ambient”, ColorRGBA.White);
mat.setColor(“Diffuse”, ColorRGBA.White);
mat.setColor(“Specular”, ColorRGBA.Yellow);
mat.setBoolean(“UseMaterialColors”, true);
mat.getAdditionalRenderState().setWireframe(false);
mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
geo.setMaterial(mat);
rootNode.attachChild(geo);
[/java]

Lighting.j3md doesn’t have a parameter called VertexColor… so I think the error is pretty accurate.

So you cannot have a lit material without textures?

How to use Materials: Colored or Textured

[java]
mat.setBoolean(“UseMaterialColors”,true); // with Lighting.j3md
[/java]

Right…but when I do that the per-vertex colors are not applied…the mesh is just set the color of the diffuse light…
[java]mesh.setBuffer(Type.Color,4,(colorArr));[/java] < those colors are the ones that are not being set

As nice as the docs are, they are not always correct and sometimes it pays to take 30 seconds and find the file in question:
http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core-data/Common/MatDefs/Light/Lighting.j3md

From that, try “UseVertexColor” instead of just “VertexColor”.

1 Like