|
| 1 | +package jme3test.light; |
| 2 | + |
| 3 | +import com.jme3.app.SimpleApplication; |
| 4 | +import com.jme3.asset.AssetManager; |
| 5 | +import com.jme3.light.AmbientLight; |
| 6 | +import com.jme3.light.PointLight; |
| 7 | +import com.jme3.material.Material; |
| 8 | +import com.jme3.math.ColorRGBA; |
| 9 | +import com.jme3.math.Vector3f; |
| 10 | +import com.jme3.scene.Geometry; |
| 11 | +import com.jme3.scene.Node; |
| 12 | +import com.jme3.scene.shape.Box; |
| 13 | + |
| 14 | +public class TestGlobalLight extends SimpleApplication { |
| 15 | + public static void main(String[] args) { |
| 16 | + TestGlobalLight test = new TestGlobalLight(); |
| 17 | + test.start(); |
| 18 | + } |
| 19 | + |
| 20 | + private static Geometry createLitWhiteCube(AssetManager assetManager, String name) { |
| 21 | + Box box = new Box(1, 1, 1); |
| 22 | + Geometry cube = new Geometry(name, box); |
| 23 | + Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); |
| 24 | + mat.setColor("Diffuse", ColorRGBA.White); |
| 25 | + mat.setColor("Ambient", ColorRGBA.White); |
| 26 | + mat.setBoolean("UseMaterialColors", true); |
| 27 | + cube.setMaterial(mat); |
| 28 | + return cube; |
| 29 | + } |
| 30 | + |
| 31 | + @Override |
| 32 | + public void simpleInitApp() { |
| 33 | + flyCam.setEnabled(false); |
| 34 | + final PointLight globalPointLight = new PointLight(true); |
| 35 | + final Node lightsAttachedNode = new Node("lightsAttachedNode"); |
| 36 | + Vector3f testOffset = new Vector3f(0, 0, 0); |
| 37 | + |
| 38 | + lightsAttachedNode.setLocalTranslation(testOffset); |
| 39 | + |
| 40 | + Node lightsNotAttachedNode = new Node("lightsNotAttachedNode"); |
| 41 | + lightsNotAttachedNode.setLocalTranslation(testOffset); |
| 42 | + |
| 43 | + Geometry litByAll = createLitWhiteCube(getAssetManager(), "litByAll"); |
| 44 | + litByAll.setLocalTranslation(2, 0, -1); |
| 45 | + lightsAttachedNode.attachChild(litByAll); |
| 46 | + |
| 47 | + Geometry litOnlyByGlobal = createLitWhiteCube(getAssetManager(), "litOnlyByGlobal"); |
| 48 | + litOnlyByGlobal.setLocalTranslation(-2, 0, -1); |
| 49 | + lightsNotAttachedNode.attachChild(litOnlyByGlobal); |
| 50 | + |
| 51 | + PointLight localPointLight = new PointLight(); |
| 52 | + localPointLight.setColor(ColorRGBA.Red); |
| 53 | + |
| 54 | + globalPointLight.setColor(ColorRGBA.Green); |
| 55 | + |
| 56 | + getCamera().setLocation(testOffset.add(new Vector3f(0, 0, 10))); |
| 57 | + getCamera().lookAt(testOffset, Vector3f.UNIT_Y); |
| 58 | + |
| 59 | + Node rootNode = new Node(); |
| 60 | + rootNode.attachChild(lightsAttachedNode); |
| 61 | + rootNode.attachChild(lightsNotAttachedNode); |
| 62 | + |
| 63 | + Node rootRootNode = new Node(); |
| 64 | + getRootNode().attachChild(rootRootNode); |
| 65 | + |
| 66 | + lightsAttachedNode.addLight(localPointLight); |
| 67 | + lightsAttachedNode.addLight(globalPointLight); |
| 68 | + |
| 69 | + rootRootNode.attachChild(rootNode); |
| 70 | + |
| 71 | + getRootNode().addLight(new AmbientLight(new ColorRGBA(0.01f, 0.01f, 0.01f, 1))); |
| 72 | + } |
| 73 | +} |
0 commit comments