I’m using the jMonkey Platform. When I assign materials like in this tutorial, I get runtime errors. For example, the following code compiles:
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.texture.Texture;
public class Main extends SimpleApplication {
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
/** A simple textured cube -- in good MIP map quality. */
Box boxshape1 = new Box(new Vector3f(-3f,1.1f,0f), 1f,1f,1f);
Geometry cube = new Geometry("My Textured Box", boxshape1);
Material mat_stl = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
Texture tex_ml = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
mat_stl.setTexture("m_ColorMap", tex_ml);
cube.setMaterial(mat_stl);
rootNode.attachChild(cube);
}
}
However, the program crashes with this in the log:
java.lang.NullPointerException
at com.jme3.material.Material.setTexture(Material.java:240)
at mygame.Main.simpleInitApp(Main.java:25)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:141)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:102)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:147)
at java.lang.Thread.run(Thread.java:619)
But, the method of assigning materials from this tutorial works fine, creating a plain blue cube:
/** A blue cube **/
Box boxshape1 = new Box(new Vector3f(-3f,1.1f,0f), 1f,1f,1f);
Geometry cube = new Geometry("My Textured Box", boxshape1);
Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
mat1.setColor("m_Color", ColorRGBA.Blue);
cube.setMaterial(mat1);
rootNode.attachChild(cube);
I have a poor understanding of the assetManager and material classes, which I think is responsible for the above code working fine even in the example packages. Any help would be appreciated!