|
@@ -47,10 +47,8 @@ public class HelloMaterial extends SimpleApplication {
|
|
|
Box cube1Mesh = new Box( 1f,1f,1f);
|
|
|
Geometry cube1Geo = new Geometry("My Textured Box", cube1Mesh);
|
|
|
cube1Geo.setLocalTranslation(new Vector3f(-3f,1.1f,0f));
|
|
|
- Material cube1Mat = new Material(assetManager,
|
|
|
- "Common/MatDefs/Misc/Unshaded.j3md");
|
|
|
- Texture cube1Tex = assetManager.loadTexture(
|
|
|
- "Interface/Logo/Monkey.jpg");
|
|
|
+ Material cube1Mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
|
|
+ Texture cube1Tex = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
|
|
|
cube1Mat.setTexture("ColorMap", cube1Tex);
|
|
|
cube1Geo.setMaterial(cube1Mat);
|
|
|
rootNode.attachChild(cube1Geo);
|
|
@@ -58,31 +56,27 @@ public class HelloMaterial extends SimpleApplication {
|
|
|
/** A translucent/transparent texture, similar to a window frame. */
|
|
|
Box cube2Mesh = new Box( 1f,1f,0.01f);
|
|
|
Geometry cube2Geo = new Geometry("window frame", cube2Mesh);
|
|
|
- Material cube2Mat = new Material(assetManager,
|
|
|
- "Common/MatDefs/Misc/Unshaded.j3md");
|
|
|
- cube2Mat.setTexture("ColorMap",
|
|
|
- assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
|
|
|
- cube2Mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
|
|
|
+ Material cube2Mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
|
|
+ cube2Mat.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
|
|
|
+ cube2Mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); // activate transparency
|
|
|
cube2Geo.setQueueBucket(Bucket.Transparent);
|
|
|
cube2Geo.setMaterial(cube2Mat);
|
|
|
rootNode.attachChild(cube2Geo);
|
|
|
|
|
|
- /** A bumpy rock with a shiny light effect.*/
|
|
|
+ /* A bumpy rock with a shiny light effect. To make bumpy objects you must create a NormalMap. */
|
|
|
Sphere sphereMesh = new Sphere(32,32, 2f);
|
|
|
Geometry sphereGeo = new Geometry("Shiny rock", sphereMesh);
|
|
|
sphereMesh.setTextureMode(Sphere.TextureMode.Projected); // better quality on spheres
|
|
|
TangentBinormalGenerator.generate(sphereMesh); // for lighting effect
|
|
|
- Material sphereMat = new Material(assetManager,
|
|
|
- "Common/MatDefs/Light/Lighting.j3md");
|
|
|
- sphereMat.setTexture("DiffuseMap",
|
|
|
- assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg"));
|
|
|
- sphereMat.setTexture("NormalMap",
|
|
|
- assetManager.loadTexture("Textures/Terrain/Pond/Pond_normal.png"));
|
|
|
+ Material sphereMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
|
|
|
+ sphereMat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg"));
|
|
|
+ sphereMat.setTexture("NormalMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond_normal.png"));
|
|
|
sphereMat.setBoolean("UseMaterialColors",true);
|
|
|
sphereMat.setColor("Diffuse",ColorRGBA.White);
|
|
|
sphereMat.setColor("Specular",ColorRGBA.White);
|
|
|
sphereMat.setFloat("Shininess", 64f); // [0,128]
|
|
|
sphereGeo.setMaterial(sphereMat);
|
|
|
+ //sphereGeo.setMaterial((Material) assetManager.loadMaterial("Materials/MyCustomMaterial.j3m"));
|
|
|
sphereGeo.setLocalTranslation(0,2,-2); // Move it a bit
|
|
|
sphereGeo.rotate(1.6f, 0, 0); // Rotate it a bit
|
|
|
rootNode.attachChild(sphereGeo);
|
|
@@ -117,10 +111,8 @@ Typically you want to give objects in your scene textures: It can be rock, grass
|
|
|
Box cube1Mesh = new Box( 1f,1f,1f);
|
|
|
Geometry cube1Geo = new Geometry("My Textured Box", cube1Mesh);
|
|
|
cube1Geo.setLocalTranslation(new Vector3f(-3f,1.1f,0f));
|
|
|
- Material cube1Mat = new Material(assetManager,
|
|
|
- "Common/MatDefs/Misc/Unshaded.j3md");
|
|
|
- Texture cube1Tex = assetManager.loadTexture(
|
|
|
- "Interface/Logo/Monkey.jpg");
|
|
|
+ Material cube1Mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
|
|
+ Texture cube1Tex = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
|
|
|
cube1Mat.setTexture("ColorMap", cube1Tex);
|
|
|
cube1Geo.setMaterial(cube1Mat);
|
|
|
rootNode.attachChild(cube1Geo);
|
|
@@ -153,12 +145,10 @@ This bucket ensures that the transparent object is drawn on top of objects behin
|
|
|
/** A translucent/transparent texture, similar to a window frame. */
|
|
|
Box cube2Mesh = new Box( 1f,1f,0.01f);
|
|
|
Geometry cube2Geo = new Geometry("window frame", cube2Mesh);
|
|
|
- Material cube2Mat = new Material(assetManager,
|
|
|
- "Common/MatDefs/Misc/Unshaded.j3md");
|
|
|
- cube2Mat.setTexture("ColorMap",
|
|
|
- assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
|
|
|
- cube2Mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); // !
|
|
|
- cube2Geo.setQueueBucket(Bucket.Transparent); // !
|
|
|
+ Material cube2Mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
|
|
+ cube2Mat.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
|
|
|
+ cube2Mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); // activate transparency
|
|
|
+ cube2Geo.setQueueBucket(Bucket.Transparent);
|
|
|
cube2Geo.setMaterial(cube2Mat);
|
|
|
rootNode.attachChild(cube2Geo);
|
|
|
|
|
@@ -223,9 +213,7 @@ Let's have a look at the part of the code example where you create the shiny bum
|
|
|
+
|
|
|
[source,java]
|
|
|
----
|
|
|
-
|
|
|
- Material sphereMat = new Material(assetManager,
|
|
|
- "Common/MatDefs/Light/Lighting.j3md");
|
|
|
+ Material sphereMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
|
|
|
----
|
|
|
|
|
|
.. Set a standard rocky texture in the `DiffuseMap` layer.
|
|
@@ -234,10 +222,7 @@ image::https://github.com/jMonkeyEngine/jmonkeyengine/raw/445f7ed010199d30c484fe
|
|
|
+
|
|
|
[source,java]
|
|
|
----
|
|
|
-
|
|
|
- sphereMat.setTexture("DiffuseMap",
|
|
|
- assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg"));
|
|
|
-
|
|
|
+ sphereMat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg"));
|
|
|
----
|
|
|
|
|
|
.. Set the `NormalMap` layer that contains the bumpiness. The NormalMap was generated for this particular DiffuseMap with a special tool (e.g. Blender).
|
|
@@ -246,9 +231,7 @@ image::https://github.com/jMonkeyEngine/jmonkeyengine/raw/445f7ed010199d30c484fe
|
|
|
+
|
|
|
[source,java]
|
|
|
----
|
|
|
-
|
|
|
- sphereMat.setTexture("NormalMap",
|
|
|
- assetManager.loadTexture("Textures/Terrain/Pond/Pond_normal.png"));
|
|
|
+ sphereMat.setTexture("NormalMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond_normal.png"));
|
|
|
----
|
|
|
|
|
|
.. Set the Material's Shininess to a value between 1 and 128. For a rock, a low fuzzy shininess is appropriate. Use material colors to define the shiny Specular color.
|
|
@@ -363,9 +346,7 @@ Material My shiny custom material : Common/MatDefs/Light/Lighting.j3md {
|
|
|
+
|
|
|
[source,java]
|
|
|
----
|
|
|
-sphereGeo.setMaterial((Material) assetManager.loadMaterial(
|
|
|
- "Materials/MyCustomMaterial.j3m"));
|
|
|
-
|
|
|
+ sphereGeo.setMaterial((Material) assetManager.loadMaterial("Materials/MyCustomMaterial.j3m"));
|
|
|
----
|
|
|
|
|
|
. Run the app. The result is the same.
|