Browse Source

lights now have in-scene marker icons in SceneComposer

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8151 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
bre..ns 14 years ago
parent
commit
b7993a80ba

+ 164 - 0
sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerToolController.java

@@ -5,15 +5,35 @@
 package com.jme3.gde.scenecomposer;
 package com.jme3.gde.scenecomposer;
 
 
 import com.jme3.asset.AssetManager;
 import com.jme3.asset.AssetManager;
+import com.jme3.bounding.BoundingVolume;
+import com.jme3.collision.Collidable;
+import com.jme3.collision.CollisionResults;
+import com.jme3.collision.UnsupportedCollisionException;
 import com.jme3.gde.core.scene.SceneApplication;
 import com.jme3.gde.core.scene.SceneApplication;
 import com.jme3.gde.core.scene.controller.SceneToolController;
 import com.jme3.gde.core.scene.controller.SceneToolController;
 import com.jme3.gde.core.sceneexplorer.nodes.JmeNode;
 import com.jme3.gde.core.sceneexplorer.nodes.JmeNode;
+import com.jme3.light.Light;
+import com.jme3.light.LightList;
+import com.jme3.light.PointLight;
+import com.jme3.light.SpotLight;
+import com.jme3.material.Material;
+import com.jme3.material.RenderState.BlendMode;
 import com.jme3.math.Vector2f;
 import com.jme3.math.Vector2f;
+import com.jme3.math.Vector3f;
 import com.jme3.renderer.Camera;
 import com.jme3.renderer.Camera;
 import com.jme3.renderer.RenderManager;
 import com.jme3.renderer.RenderManager;
 import com.jme3.renderer.ViewPort;
 import com.jme3.renderer.ViewPort;
+import com.jme3.renderer.queue.RenderQueue.Bucket;
+import com.jme3.scene.Geometry;
 import com.jme3.scene.Node;
 import com.jme3.scene.Node;
+import com.jme3.scene.SceneGraphVisitor;
 import com.jme3.scene.Spatial;
 import com.jme3.scene.Spatial;
+import com.jme3.scene.control.AbstractControl;
+import com.jme3.scene.control.BillboardControl;
+import com.jme3.scene.control.Control;
+import com.jme3.scene.shape.Quad;
+import com.jme3.texture.Texture;
+import java.util.Queue;
 import java.util.concurrent.Callable;
 import java.util.concurrent.Callable;
 
 
 /**
 /**
@@ -28,10 +48,14 @@ public class SceneComposerToolController extends SceneToolController {
     private ComposerCameraController cameraController;
     private ComposerCameraController cameraController;
     private ViewPort overlayView;
     private ViewPort overlayView;
     private Node onTopToolsNode;
     private Node onTopToolsNode;
+    private Node lightMarkersNode;
+    private Material lightMarkerMaterial;
 
 
     public SceneComposerToolController(Node toolsNode, AssetManager manager, JmeNode rootNode) {
     public SceneComposerToolController(Node toolsNode, AssetManager manager, JmeNode rootNode) {
         super(toolsNode, manager);
         super(toolsNode, manager);
         this.rootNode = rootNode;
         this.rootNode = rootNode;
+        lightMarkersNode = new Node("lightMarkersNode");
+        toolsNode.attachChild(lightMarkersNode);
     }
     }
 
 
     public SceneComposerToolController(AssetManager manager) {
     public SceneComposerToolController(AssetManager manager) {
@@ -179,4 +203,144 @@ public class SceneComposerToolController extends SceneToolController {
             editTool.draggedSecondary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject());
             editTool.draggedSecondary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject());
         }
         }
     }
     }
+
+    public Node getLightMarkersNode() {
+        return lightMarkersNode;
+    }
+    
+    /**
+     * Adds a marker for the light to the scene if it does not exist yet
+     */
+    public void addLightMarker(Light light) {
+        if (!(light instanceof PointLight) && !(light instanceof SpotLight))
+            return; // only handle point and spot lights
+        
+        Spatial s = lightMarkersNode.getChild(light.getName());
+        if (s != null) {
+            // update location maybe? Remove old and replace with new?
+            return;
+        }
+        
+        LightMarker lm = new LightMarker(light);
+        lightMarkersNode.attachChild(lm);
+    }
+    
+    /**
+     * Removes a light marker from the scene's tool node
+     */
+    public void removeLightMarker(Light light) {
+        Spatial s = lightMarkersNode.getChild(light.getName());
+        s.removeFromParent();
+    }
+    
+    private Material getLightMarkerMaterial() {
+        if (lightMarkerMaterial == null) {
+            Material mat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
+            Texture tex = manager.loadTexture("com/jme3/gde/scenecomposer/lightbulb32.png");
+            mat.setTexture("ColorMap", tex);
+            mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
+            lightMarkerMaterial = mat;
+        }
+        return lightMarkerMaterial;
+    }
+
+    protected void refreshNonSpatialMarkers() {
+        lightMarkersNode.detachAllChildren();
+        addMarkers(rootNode.getLookup().lookup(Node.class));
+    }
+    
+    private void addMarkers(Node parent) {
+        
+        for (Light light : parent.getLocalLightList())
+            addLightMarker(light);
+        
+        for (Spatial s : parent.getChildren()) {
+            if (s instanceof Node)
+                addMarkers((Node)s);
+            else {
+                //TODO later if we include other types of non-spatial markers
+            }
+        }
+    }
+    
+    /**
+     * A marker on the screen that shows where a point light or
+     * a spot light is. This marker is not part of the scene,
+     * but is part of the tools node.
+     */
+    protected class LightMarker extends Geometry {
+        private Light light;
+        
+        protected LightMarker() {}
+    
+        protected LightMarker(Light light) {
+            this.light = light;
+            Quad q = new Quad(0.5f, 0.5f);
+            this.setMesh(q);
+            this.setMaterial(getLightMarkerMaterial());
+            this.addControl(new LightMarkerControl());
+            this.setQueueBucket(Bucket.Transparent);
+        }
+        
+        protected Light getLight() {
+            return light;
+        }
+        
+        @Override
+        public void setLocalTranslation(Vector3f location) {
+            super.setLocalTranslation(location);
+            if (light instanceof PointLight)
+                ((PointLight)light).setPosition(location);
+            else if (light instanceof SpotLight)
+                ((SpotLight)light).setPosition(location);
+        }
+        
+        @Override
+        public void setLocalTranslation(float x, float y, float z) {
+            super.setLocalTranslation(x, y, z);
+            if (light instanceof PointLight)
+                ((PointLight)light).setPosition(new Vector3f(x,y,z));
+            else if (light instanceof SpotLight)
+                ((SpotLight)light).setPosition(new Vector3f(x,y,z));
+        }
+    }
+    
+    /**
+     * Updates the marker's position whenever the light has moved.
+     * It is also a BillboardControl, so this marker always faces
+     * the camera
+     */
+    protected class LightMarkerControl extends BillboardControl {
+
+        LightMarkerControl(){
+            super();
+        }
+        
+        @Override
+        protected void controlUpdate(float f) {
+            super.controlUpdate(f);
+            LightMarker marker = (LightMarker) getSpatial();
+            if (marker != null) {
+                if (marker.getLight() instanceof PointLight) {
+                    marker.setLocalTranslation(((PointLight)marker.getLight()).getPosition());
+                } else if (marker.getLight() instanceof SpotLight) {
+                    marker.setLocalTranslation(((SpotLight)marker.getLight()).getPosition());
+                }
+            }
+        }
+
+        @Override
+        protected void controlRender(RenderManager rm, ViewPort vp) {
+            super.controlRender(rm, vp);
+        }
+
+        @Override
+        public Control cloneForSpatial(Spatial sptl) {
+            LightMarkerControl c = new LightMarkerControl();
+            c.setSpatial(sptl);
+            //TODO this isn't correct, none of BillboardControl is copied over
+            return c;
+        }
+        
+    }
 }
 }

+ 4 - 0
sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerTopComponent.java

@@ -894,6 +894,9 @@ private void scaleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F
             SelectTool tool = new SelectTool();
             SelectTool tool = new SelectTool();
             toolController.showEditTool(tool);
             toolController.showEditTool(tool);
             toolController.setShowSelection(true);
             toolController.setShowSelection(true);
+            
+            editorController.setToolController(toolController);
+            toolController.refreshNonSpatialMarkers();
         }/* else {
         }/* else {
          SceneApplication.getApplication().removeSceneListener(this);
          SceneApplication.getApplication().removeSceneListener(this);
          currentRequest = null;
          currentRequest = null;
@@ -923,4 +926,5 @@ private void scaleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F
 
 
     public void previewRequested(PreviewRequest request) {
     public void previewRequested(PreviewRequest request) {
     }
     }
+    
 }
 }

+ 12 - 0
sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneEditorController.java

@@ -17,6 +17,7 @@ import com.jme3.effect.ParticleMesh;
 import com.jme3.gde.core.assets.ProjectAssetManager;
 import com.jme3.gde.core.assets.ProjectAssetManager;
 import com.jme3.gde.core.assets.SpatialAssetDataObject;
 import com.jme3.gde.core.assets.SpatialAssetDataObject;
 import com.jme3.gde.core.scene.SceneApplication;
 import com.jme3.gde.core.scene.SceneApplication;
+import com.jme3.gde.core.scene.controller.SceneToolController;
 import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode;
 import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode;
 import com.jme3.gde.core.sceneexplorer.nodes.JmeSpatial;
 import com.jme3.gde.core.sceneexplorer.nodes.JmeSpatial;
 import com.jme3.gde.core.undoredo.AbstractUndoableSceneEdit;
 import com.jme3.gde.core.undoredo.AbstractUndoableSceneEdit;
@@ -72,12 +73,17 @@ public class SceneEditorController implements PropertyChangeListener, NodeListen
     private JmeSpatial selectedSpat;
     private JmeSpatial selectedSpat;
     private DataObject currentFileObject;
     private DataObject currentFileObject;
 //    private boolean needSave = false;
 //    private boolean needSave = false;
+    private SceneComposerToolController toolController;
 
 
     public SceneEditorController(JmeSpatial jmeRootNode, DataObject currentFileObject) {
     public SceneEditorController(JmeSpatial jmeRootNode, DataObject currentFileObject) {
         this.jmeRootNode = jmeRootNode;
         this.jmeRootNode = jmeRootNode;
         this.currentFileObject = currentFileObject;
         this.currentFileObject = currentFileObject;
     }
     }
 
 
+    public void setToolController(SceneComposerToolController toolController) {
+        this.toolController = toolController;
+    }
+
     public JmeSpatial getJmeRootNode() {
     public JmeSpatial getJmeRootNode() {
         return jmeRootNode;
         return jmeRootNode;
     }
     }
@@ -148,12 +154,14 @@ public class SceneEditorController implements PropertyChangeListener, NodeListen
                 public void sceneUndo() throws CannotUndoException {
                 public void sceneUndo() throws CannotUndoException {
                     //undo stuff here
                     //undo stuff here
                     undoParent.removeLight(undoLight);
                     undoParent.removeLight(undoLight);
+                    toolController.removeLightMarker(undoLight);
                 }
                 }
 
 
                 @Override
                 @Override
                 public void sceneRedo() throws CannotRedoException {
                 public void sceneRedo() throws CannotRedoException {
                     //redo stuff here
                     //redo stuff here
                     undoParent.addLight(undoLight);
                     undoParent.addLight(undoLight);
+                    toolController.addLightMarker(undoLight);
                 }
                 }
 
 
                 @Override
                 @Override
@@ -705,18 +713,22 @@ public class SceneEditorController implements PropertyChangeListener, NodeListen
 
 
     public void childrenAdded(NodeMemberEvent ev) {
     public void childrenAdded(NodeMemberEvent ev) {
 //        setNeedsSave(true);
 //        setNeedsSave(true);
+        toolController.refreshNonSpatialMarkers();
     }
     }
 
 
     public void childrenRemoved(NodeMemberEvent ev) {
     public void childrenRemoved(NodeMemberEvent ev) {
 //        setNeedsSave(true);
 //        setNeedsSave(true);
+        toolController.refreshNonSpatialMarkers();
     }
     }
 
 
     public void childrenReordered(NodeReorderEvent ev) {
     public void childrenReordered(NodeReorderEvent ev) {
 //        setNeedsSave(true);
 //        setNeedsSave(true);
+        toolController.refreshNonSpatialMarkers();
     }
     }
 
 
     public void nodeDestroyed(NodeEvent ev) {
     public void nodeDestroyed(NodeEvent ev) {
 //        setNeedsSave(true);
 //        setNeedsSave(true);
+        toolController.refreshNonSpatialMarkers();
     }
     }
 
 
     public void saveScene() {
     public void saveScene() {

BIN
sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/lightbulb32.png


+ 1 - 1
sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/AddTerrainAction.java

@@ -159,7 +159,7 @@ public class AddTerrainAction extends AbstractNewSpatialWizardAction {
         ((Node)terrain).setModelBound(new BoundingBox());
         ((Node)terrain).setModelBound(new BoundingBox());
         ((Node)terrain).updateModelBound();
         ((Node)terrain).updateModelBound();
         ((Node)terrain).setLocalTranslation(0, 0, 0);
         ((Node)terrain).setLocalTranslation(0, 0, 0);
-        ((Node)terrain).setLocalScale(4f, 1f, 4f);
+        ((Node)terrain).setLocalScale(1f, 1f, 1f);
 
 
         // add the lod control
         // add the lod control
         TerrainLodControl control = new TerrainLodControl(terrain, SceneApplication.getApplication().getCamera());
         TerrainLodControl control = new TerrainLodControl(terrain, SceneApplication.getApplication().getCamera());