[SOLVED] Issue with setColor Material

I use the following code:

package de.visiongamestudios.client;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.debug.Arrow;

public class test extends SimpleApplication {

	@Override
	public void simpleInitApp() {
		Arrow rawSpatial = new Arrow(new Vector3f(10, 0, 0));

		Geometry geom = new Geometry("dummy", rawSpatial);

		Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
		mat.setColor("Color ", ColorRGBA.White);
		mat.getAdditionalRenderState().setLineWidth(1);
		geom.setMaterial(mat);
	}

	public static void main(String[] args) {
		new test().start();;
	}
}

This crashes with:
java.lang.IllegalArgumentException: Material parameter is not defined: Color
at com.jme3.material.Material.checkSetParam(Material.java:460)
at com.jme3.material.Material.setParam(Material.java:476)
at com.jme3.material.Material.setColor(Material.java:660)
at de.visiongamestudios.client.test.simpleInitApp(test.java:19)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:220)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:211)
at java.lang.Thread.run(Thread.java:748)

Debugging into Material

private void checkSetParam(VarType type, String name) {
    MatParam paramDef = def.getMaterialParam(name);
    if (paramDef == null) {
        throw new IllegalArgumentException("Material parameter is not defined: " + name);
    }
    if (type != null && paramDef.getVarType() != type) {
        logger.log(Level.WARNING, "Material parameter being set: {0} with "
                + "type {1} doesn''t match definition types {2}", new Object[]{name, type.name(), paramDef.getVarType()});
    }
}

I see that paramDef is null, and thus the code is aborting.
However
def.matParams HashMap<K,V> (id=72) contains this entry:
[18] HashMap$Node<K,V> (id=129) → Color=Vector4 Color

Can anyone explain, why this is not found, as it should have the key Color in it?

Your problem is just because a typo: You hit one more space

  • “Color” √
  • "Color " ×

By the way, I think it’s good to understand how Materials are work. You can learn more about it with follow article:

https://jmonkeyengine.github.io/wiki/jme3/intermediate/how_to_use_materials.html

The parameters of Material are defined in material definition file (.j3md).

jMonkeyEngine use shaders to renderer 3d scene. Shaders are running in GPU.
Shader can define its own parameters, when using shader in OpenGL/Direct3D we have to send parameters to Shader.

Material is something to descripe how the geometries are renderered. Material descripe that with shader. You can think that Material is a bridge between Java and Shader. The parameters a Material need is what the shader need infact, that’s why you can’t find the reall problem in Material class.

The Common/MatDefs/Misc/Unshaded.j3mdyou used to instance a Material object, defined what parameter the shader need.

1 Like

:chimpanzee_eek: … Did I really spend like 3 hours debugging this because of a type …damn. Good find tho :+1:

2 Likes