From b7993a80ba544a4bb142cb2f62f938bb7e6dfd0d Mon Sep 17 00:00:00 2001 From: "bre..ns" Date: Sat, 3 Sep 2011 01:20:28 +0000 Subject: [PATCH] lights now have in-scene marker icons in SceneComposer git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8151 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../SceneComposerToolController.java | 164 ++++++++++++++++++ .../SceneComposerTopComponent.java | 4 + .../scenecomposer/SceneEditorController.java | 12 ++ .../jme3/gde/scenecomposer/lightbulb32.png | Bin 0 -> 1496 bytes .../gde/terraineditor/AddTerrainAction.java | 2 +- 5 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/lightbulb32.png diff --git a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerToolController.java b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerToolController.java index 88af21492..f64d9d667 100644 --- a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerToolController.java +++ b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerToolController.java @@ -5,15 +5,35 @@ package com.jme3.gde.scenecomposer; 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.controller.SceneToolController; 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.Vector3f; import com.jme3.renderer.Camera; import com.jme3.renderer.RenderManager; 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.SceneGraphVisitor; 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; /** @@ -28,10 +48,14 @@ public class SceneComposerToolController extends SceneToolController { private ComposerCameraController cameraController; private ViewPort overlayView; private Node onTopToolsNode; + private Node lightMarkersNode; + private Material lightMarkerMaterial; public SceneComposerToolController(Node toolsNode, AssetManager manager, JmeNode rootNode) { super(toolsNode, manager); this.rootNode = rootNode; + lightMarkersNode = new Node("lightMarkersNode"); + toolsNode.attachChild(lightMarkersNode); } public SceneComposerToolController(AssetManager manager) { @@ -179,4 +203,144 @@ public class SceneComposerToolController extends SceneToolController { 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; + } + + } } diff --git a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerTopComponent.java b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerTopComponent.java index a80a7ba6b..cd7107170 100644 --- a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerTopComponent.java +++ b/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(); toolController.showEditTool(tool); toolController.setShowSelection(true); + + editorController.setToolController(toolController); + toolController.refreshNonSpatialMarkers(); }/* else { SceneApplication.getApplication().removeSceneListener(this); currentRequest = null; @@ -923,4 +926,5 @@ private void scaleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F public void previewRequested(PreviewRequest request) { } + } diff --git a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneEditorController.java b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneEditorController.java index e77d973be..54a3c09b2 100644 --- a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneEditorController.java +++ b/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.SpatialAssetDataObject; 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.JmeSpatial; import com.jme3.gde.core.undoredo.AbstractUndoableSceneEdit; @@ -72,12 +73,17 @@ public class SceneEditorController implements PropertyChangeListener, NodeListen private JmeSpatial selectedSpat; private DataObject currentFileObject; // private boolean needSave = false; + private SceneComposerToolController toolController; public SceneEditorController(JmeSpatial jmeRootNode, DataObject currentFileObject) { this.jmeRootNode = jmeRootNode; this.currentFileObject = currentFileObject; } + public void setToolController(SceneComposerToolController toolController) { + this.toolController = toolController; + } + public JmeSpatial getJmeRootNode() { return jmeRootNode; } @@ -148,12 +154,14 @@ public class SceneEditorController implements PropertyChangeListener, NodeListen public void sceneUndo() throws CannotUndoException { //undo stuff here undoParent.removeLight(undoLight); + toolController.removeLightMarker(undoLight); } @Override public void sceneRedo() throws CannotRedoException { //redo stuff here undoParent.addLight(undoLight); + toolController.addLightMarker(undoLight); } @Override @@ -705,18 +713,22 @@ public class SceneEditorController implements PropertyChangeListener, NodeListen public void childrenAdded(NodeMemberEvent ev) { // setNeedsSave(true); + toolController.refreshNonSpatialMarkers(); } public void childrenRemoved(NodeMemberEvent ev) { // setNeedsSave(true); + toolController.refreshNonSpatialMarkers(); } public void childrenReordered(NodeReorderEvent ev) { // setNeedsSave(true); + toolController.refreshNonSpatialMarkers(); } public void nodeDestroyed(NodeEvent ev) { // setNeedsSave(true); + toolController.refreshNonSpatialMarkers(); } public void saveScene() { diff --git a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/lightbulb32.png b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/lightbulb32.png new file mode 100644 index 0000000000000000000000000000000000000000..17181a9b97241d120176f63a9468340dece8be43 GIT binary patch literal 1496 zcmV;}1t?gFiw?W^Y5;PtNLC@jnBfQh+$+V1xT_& zCSwN7!8W8qf8xxk5Q1Z=)sMg4zGp&kDql_%9&do}%6 z5DNn4v}Dx8znIse0R4lziBmz8oX&wL;9MN~bVaMLrV15a4^Vjz`PG2&5ReW7ndr5| zYs9l;NS1Y2mu(dCQz!#2zgJm1(_clYa}rUSGi2PzUSC_2(?EP%mULLxKN4O`jLk%e zk^#sen`RzgJeP5!Md^-sAF5@0B}l@34;t7^hJ6UrW&AJ zN>?&4QB+q?j6}|##1{C^rMVZ~8YsoIBCceR2JzzYdY%1ZsViR;ou5`7_T2%5$Np z7LR3Ec2~#Qb*#%a%B=w&eB+G1w4u9g&oAc*L_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