Java examples for Game:JME3
Light in jme3
package material; import com.jme3.app.SimpleApplication; import com.jme3.asset.TextureKey; import com.jme3.light.AmbientLight; import com.jme3.light.DirectionalLight; import com.jme3.light.PointLight; import com.jme3.light.SpotLight; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.FastMath; import com.jme3.math.Vector2f; import com.jme3.math.Vector3f; import com.jme3.post.FilterPostProcessor; import com.jme3.post.filters.BloomFilter; import com.jme3.renderer.RenderManager; import com.jme3.scene.Geometry; import com.jme3.scene.Node; import com.jme3.scene.shape.Box; import com.jme3.texture.Texture.WrapMode; import com.jme3.util.TangentBinormalGenerator; /**//from w w w. j a va 2 s.c om * test * * @author normenhansen */ public class HoverTank extends SimpleApplication { public static void main(String[] args) { HoverTank app = new HoverTank(); app.start(); } // SpotLight spot; @Override public void simpleInitApp() { flyCam.setMoveSpeed(30); AmbientLight ambient = new AmbientLight(); ambient.setColor(ColorRGBA.White.mult(0.4f)); rootNode.addLight(ambient); PointLight lamp = new PointLight(); lamp.setPosition(new Vector3f(0, 1, 0)); lamp.setColor(ColorRGBA.Yellow); System.out.println(lamp.getRadius()); rootNode.addLight(lamp); DirectionalLight sun = new DirectionalLight(); sun.setDirection(new Vector3f(1, 0.0f, -2)); sun.setColor(ColorRGBA.White); rootNode.addLight(sun); // spot = new SpotLight(); // spot.setSpotRange(100); // spot.setSpotOuterAngle(20 * FastMath.DEG_TO_RAD); // spot.setSpotInnerAngle(15 * FastMath.DEG_TO_RAD); // rootNode.addLight(spot); Node tank = (Node) assetManager .loadModel("Models/HoverTank/Tank2.mesh.xml"); // Material mat = new Material( // assetManager, "Common/MatDefs/Light/Lighting.j3md"); // TextureKey tankDiffuse = new TextureKey( // "Models/HoverTank/tank_diffuse.jpg", false); // mat.setTexture("DiffuseMap", // assetManager.loadTexture(tankDiffuse)); // // TangentBinormalGenerator.generate(tank); // // TextureKey tankNormal = new TextureKey( // "Models/HoverTank/tank_normals.png", false); // mat.setTexture("NormalMap", // assetManager.loadTexture(tankNormal)); // // TextureKey tankSpecular = new TextureKey( // "Models/HoverTank/tank_specular.jpg", false); // mat.setTexture("SpecularMap", // assetManager.loadTexture(tankSpecular)); // mat.setBoolean("UseMaterialColors", true); // mat.setColor("Ambient", ColorRGBA.Gray); // mat.setColor("Diffuse", ColorRGBA.White); // mat.setColor("Specular", ColorRGBA.White); // mat.setFloat("Shininess", 100f); // // FilterPostProcessor fpp = new FilterPostProcessor(assetManager); // viewPort.addProcessor(fpp); // BloomFilter bloom = // new BloomFilter(BloomFilter.GlowMode.SceneAndObjects); // fpp.addFilter(bloom); // TextureKey tankGlow = new TextureKey( // "Models/HoverTank/tank_glow_map.jpg", false); // mat.setTexture("GlowMap", // assetManager.loadTexture(tankGlow)); // mat.setColor("GlowColor", ColorRGBA.White); // tank.setMaterial(mat); Material mat = assetManager.loadMaterial("Materials/tank.j3m"); tank.setMaterial(mat); Box floorMesh = new Box(new Vector3f(-20, -2, -20), new Vector3f( 20, -3, 20)); floorMesh.scaleTextureCoordinates(new Vector2f(16, 16)); Geometry floorGeo = new Geometry("floor", floorMesh); Material floorMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); floorMat.setTexture("DiffuseMap", assetManager .loadTexture("Textures/BrickWall/BrickWall_diffuse.jpg")); floorMat.setTexture("NormalMap", assetManager .loadTexture("Textures/BrickWall/BrickWall_normal.jpg")); floorMat.getTextureParam("NormalMap").getTextureValue() .setWrap(WrapMode.Repeat); floorMat.getTextureParam("DiffuseMap").getTextureValue() .setWrap(WrapMode.Repeat); floorGeo.setMaterial(floorMat); rootNode.attachChild(floorGeo); rootNode.attachChild(tank); } @Override public void simpleUpdate(float tpf) { //TODO: add update code // spot.setDirection(cam.getDirection()); // spot.setPosition(cam.getLocation()); } @Override public void simpleRender(RenderManager rm) { //TODO: add render code } }