Removed depricated material example in hellomaterial, refactored some object names
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10724 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
6baff6f8d9
commit
2224767cbe
@ -46,8 +46,7 @@ import com.jme3.texture.Texture;
|
||||
import com.jme3.util.TangentBinormalGenerator;
|
||||
|
||||
/** Sample 6 - how to give an object's surface a material and texture.
|
||||
* How to make objects transparent, or let colors "leak" through partially
|
||||
* transparent textures. How to make bumpy and shiny surfaces. */
|
||||
* How to make objects transparent. How to make bumpy and shiny surfaces. */
|
||||
public class HelloMaterial extends SimpleApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
@ -59,59 +58,47 @@ public class HelloMaterial extends SimpleApplication {
|
||||
public void simpleInitApp() {
|
||||
|
||||
/** A simple textured cube -- in good MIP map quality. */
|
||||
Box boxshape1 = new Box( 1f,1f,1f);
|
||||
Geometry cube = new Geometry("My Textured Box", boxshape1);
|
||||
cube.setLocalTranslation(new Vector3f(-3f,1.1f,0f));
|
||||
Material mat_stl = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
Texture tex_ml = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
|
||||
mat_stl.setTexture("ColorMap", tex_ml);
|
||||
cube.setMaterial(mat_stl);
|
||||
rootNode.attachChild(cube);
|
||||
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");
|
||||
cube1Mat.setTexture("ColorMap", cube1Tex);
|
||||
cube1Geo.setMaterial(cube1Mat);
|
||||
rootNode.attachChild(cube1Geo);
|
||||
|
||||
/** A translucent/transparent texture, similar to a window frame. */
|
||||
Box boxshape3 = new Box( 1f,1f,0.01f);
|
||||
Geometry window_frame = new Geometry("window frame", boxshape3);
|
||||
Material mat_tt = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
mat_tt.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
|
||||
mat_tt.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); // activate transparency
|
||||
window_frame.setQueueBucket(Bucket.Transparent);
|
||||
window_frame.setMaterial(mat_tt);
|
||||
rootNode.attachChild(window_frame);
|
||||
|
||||
|
||||
/** A cube with its base color "leaking" through a partially transparent texture */
|
||||
Box boxshape4 = new Box(1f,1f,1f);
|
||||
Geometry cube_leak = new Geometry("Leak-through color cube", boxshape4);
|
||||
cube_leak.setLocalTranslation(new Vector3f(3f,-1f,0f));
|
||||
Material mat_tl = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
mat_tl.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
|
||||
mat_tl.setColor("Color", new ColorRGBA(1f,0f,1f, 1f)); // purple
|
||||
cube_leak.setMaterial(mat_tl);
|
||||
rootNode.attachChild(cube_leak);
|
||||
// cube_leak.setMaterial((Material) assetManager.loadAsset( "Materials/LeakThrough.j3m"));
|
||||
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); // activate transparency
|
||||
cube2Geo.setQueueBucket(Bucket.Transparent);
|
||||
cube2Geo.setMaterial(cube2Mat);
|
||||
rootNode.attachChild(cube2Geo);
|
||||
|
||||
/** 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 shinyRockGeo = new Geometry("Shiny rock", sphereMesh);
|
||||
Geometry sphereGeo = new Geometry("Shiny rock", sphereMesh);
|
||||
sphereMesh.setTextureMode(Sphere.TextureMode.Projected); // better quality on spheres
|
||||
TangentBinormalGenerator.generate(sphereMesh); // for lighting effect
|
||||
Material litMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
|
||||
litMat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg"));
|
||||
litMat.setTexture("NormalMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond_normal.png"));
|
||||
litMat.setBoolean("UseMaterialColors",true);
|
||||
litMat.setColor("Specular",ColorRGBA.White);
|
||||
litMat.setColor("Diffuse",ColorRGBA.White);
|
||||
litMat.setFloat("Shininess", 64f); // [0,128]
|
||||
shinyRockGeo.setMaterial(litMat);
|
||||
shinyRockGeo.setLocalTranslation(0,2,-2); // Move it a bit
|
||||
shinyRockGeo.rotate(1.6f, 0, 0); // Rotate it a bit
|
||||
rootNode.attachChild(shinyRockGeo);
|
||||
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);
|
||||
|
||||
/** Must add a light to make the lit object visible! */
|
||||
DirectionalLight sun = new DirectionalLight();
|
||||
sun.setDirection(new Vector3f(1,0,-2).normalizeLocal());
|
||||
sun.setColor(ColorRGBA.White);
|
||||
rootNode.addLight(sun);
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user