All Geometries need a Materual. Every Material is based on a Material Definition. The most common Material Definitions are included in the engine, advanced users can create custom ones.
Spatial myGeometry = assetManager.loadModel("Models/Teapot/Teapot.j3o"); Material mat = new Material(assetManager, // Create new material and... "Common/MatDefs/Misc/Unshaded.j3md"); // ... specify a Material Definition file, here "Unshaded.j3md"! mat.setColor("Color", ColorRGBA.Blue); // Set one or more material parameters. myGeometry.setMaterial(mat); // Use material on this Geometry.
In the Materials Overview list,
Unshaded.j3md.In your Java code,
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Yellow ); // and more
myGeometry.setMaterial(mat);
geometry.scaleTextureCoordinates(new Vector2f(1f, .5f));
For details see also: How to Use Materials
Here are examples of the methods that set the different data types:
mat.setColor( "Color", ColorRGBA.White ); mat.setTexture( "ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.png" ));mat.setFloat( "Shininess", 5f);mat.setBoolean( "SphereMap", true);mat.setVector3( "NormalScale", new Vector3f(1f,1f,1f));A simpled textured material.
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setTexture("ColorMap", assetManager.loadTexture( "Interface/Logo/Monkey.jpg"));
A textured material with a color bleeding through transparent areas.
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setTexture("ColorMap", assetManager.loadTexture( "Textures/ColoredTex/Monkey.png")); mat.setColor("Color", ColorRGBA.Blue);
You can test these examples within the following code snippet. It creates a box and applies the material:
Box b = new Box(Vector3f.ZERO, 1, 1, 1); Geometry geom = new Geometry("Box", b); // ... insert Material definition... geom.setMaterial(mat); rootNode.attachChild(geom);
Check out the engine source code and have a look at how Material Definitions are implemented. You can create your own Material Definitions and place them in your projects MatDefs directory.
engine/src/core-data/Common/MatDefs/.