Browse Source

Fixes #153 - LightProbes get moved correctly now and their radius is also updated and updateable using Scene Composer Scale Tools

MeFisto94 8 years ago
parent
commit
0c346bdded

+ 23 - 5
jme3-scenecomposer/src/com/jme3/gde/scenecomposer/gizmo/light/LightGizmoFactory.java

@@ -10,6 +10,7 @@ import com.jme3.environment.util.BoundingSphereDebug;
 import com.jme3.gde.scenecomposer.gizmo.light.shape.ProbeRadiusShape;
 import com.jme3.gde.scenecomposer.gizmo.light.shape.ProbeRadiusShape;
 import com.jme3.gde.core.sceneexplorer.nodes.JmeDirectionalLight;
 import com.jme3.gde.core.sceneexplorer.nodes.JmeDirectionalLight;
 import com.jme3.gde.core.sceneexplorer.nodes.JmeLight;
 import com.jme3.gde.core.sceneexplorer.nodes.JmeLight;
+import com.jme3.gde.core.sceneexplorer.nodes.JmeLightProbe;
 import com.jme3.gde.core.sceneexplorer.nodes.JmePointLight;
 import com.jme3.gde.core.sceneexplorer.nodes.JmePointLight;
 import com.jme3.gde.core.sceneexplorer.nodes.JmeSpotLight;
 import com.jme3.gde.core.sceneexplorer.nodes.JmeSpotLight;
 import com.jme3.gde.scenecomposer.gizmo.shape.RadiusShape;
 import com.jme3.gde.scenecomposer.gizmo.shape.RadiusShape;
@@ -56,7 +57,7 @@ public class LightGizmoFactory {
                 return createDirectionalGizmo(assetManager, (JmeDirectionalLight) lightNode, light);
                 return createDirectionalGizmo(assetManager, (JmeDirectionalLight) lightNode, light);
                 
                 
             case Probe:
             case Probe:
-                return createLightProbeGizmo(assetManager, light);
+                return createLightProbeGizmo(assetManager, (JmeLightProbe)lightNode);
 
 
             //  default:
             //  default:
             //      return createDefaultGizmo(assetManager, lightNode);
             //      return createDefaultGizmo(assetManager, lightNode);
@@ -71,7 +72,7 @@ public class LightGizmoFactory {
         Node billboardNode = new Node("billboard lightGizmo");
         Node billboardNode = new Node("billboard lightGizmo");
         billboardNode.addControl(new BillboardControl());
         billboardNode.addControl(new BillboardControl());
         gizmo.attachChild(billboardNode);
         gizmo.attachChild(billboardNode);
-        billboardNode.attachChild(createLightBulbe(assetManager));
+        billboardNode.attachChild(createLightBulb(assetManager));
         
         
         Geometry radius = RadiusShape.createShape(assetManager, "radius shape");
         Geometry radius = RadiusShape.createShape(assetManager, "radius shape");
         radius.addControl(new LightRadiusUpdate((PointLight) light));
         radius.addControl(new LightRadiusUpdate((PointLight) light));
@@ -88,7 +89,7 @@ public class LightGizmoFactory {
         Node billboardNode = new Node("billboard lightGizmo");
         Node billboardNode = new Node("billboard lightGizmo");
         billboardNode.addControl(new BillboardControl());
         billboardNode.addControl(new BillboardControl());
         gizmo.attachChild(billboardNode);
         gizmo.attachChild(billboardNode);
-        billboardNode.attachChild(createLightBulbe(assetManager));
+        billboardNode.attachChild(createLightBulb(assetManager));
         
         
         Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
         Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
         mat.setColor("Color", ColorRGBA.White);
         mat.setColor("Color", ColorRGBA.White);
@@ -112,7 +113,7 @@ public class LightGizmoFactory {
         Node billboardNode = new Node("billboard lightGizmo");
         Node billboardNode = new Node("billboard lightGizmo");
         gizmo.attachChild(billboardNode);
         gizmo.attachChild(billboardNode);
         billboardNode.addControl(new BillboardControl());
         billboardNode.addControl(new BillboardControl());
-        billboardNode.attachChild(createLightBulbe(assetManager));
+        billboardNode.attachChild(createLightBulb(assetManager));
         
         
         Node radiusNode = new Node("radius Node");
         Node radiusNode = new Node("radius Node");
         gizmo.attachChild(radiusNode);
         gizmo.attachChild(radiusNode);
@@ -152,7 +153,24 @@ public class LightGizmoFactory {
         return gizmo;
         return gizmo;
     }
     }
     
     
-    protected static Geometry createLightBulbe(AssetManager assetManager) {
+    private static Spatial createLightProbeGizmo(AssetManager assetManager, JmeLightProbe probe){
+        LightProbeGizmo gizmo = new LightProbeGizmo(probe);//new Node("Environment debug Node");
+        gizmo.addControl(new LightPositionUpdate(probe.getLightProbe(), gizmo));
+        gizmo.addControl(new LightProbeUpdate(probe));
+        
+        Sphere s = new Sphere(16, 16, 0.5f);
+        Geometry debugGeom = new Geometry(probe.getLightProbe().getName(), s);
+        Material debugMaterial = new Material(assetManager, "Common/MatDefs/Misc/reflect.j3md");
+        debugGeom.setMaterial(debugMaterial);
+        Spatial debugBounds = ProbeRadiusShape.createShape(assetManager);
+        
+        gizmo.attachChild(debugGeom);
+        gizmo.attachChild(debugBounds);
+        
+        return gizmo;        
+    }
+    
+    protected static Geometry createLightBulb(AssetManager assetManager) {
         Quad q = new Quad(0.5f, 0.5f);
         Quad q = new Quad(0.5f, 0.5f);
         Geometry lightBulb = new Geometry("light bulb", q);
         Geometry lightBulb = new Geometry("light bulb", q);
         lightBulb.move(-q.getHeight() / 2f, -q.getWidth() / 2f, 0);
         lightBulb.move(-q.getHeight() / 2f, -q.getWidth() / 2f, 0);

+ 131 - 0
jme3-scenecomposer/src/com/jme3/gde/scenecomposer/gizmo/light/LightProbeGizmo.java

@@ -0,0 +1,131 @@
+/*
+ *  Copyright (c) 2009-2018 jMonkeyEngine
+ *  All rights reserved.
+ * 
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ * 
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ *  * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.gde.scenecomposer.gizmo.light;
+
+import com.jme3.bounding.BoundingSphere;
+import com.jme3.bounding.BoundingVolume;
+import com.jme3.gde.core.sceneexplorer.nodes.JmeLightProbe;
+import com.jme3.gde.scenecomposer.gizmo.NodeCallback;
+import com.jme3.light.LightProbe;
+import com.jme3.math.Quaternion;
+import com.jme3.math.Vector3f;
+
+/**
+ * Updates the marker's position whenever the light probe has moved. 
+ * Also update the gizmo radius according to the probe radius.
+ * Each Gizmo extends NodeCallback, so it is notified, when it's moved
+ * by the Scene Composer Tools.
+ */
+public class LightProbeGizmo extends NodeCallback {
+
+    private final Vector3f lastPos = new Vector3f();
+    private final LightProbe lightProbe;
+    private final JmeLightProbe jmeProbe;    
+
+    LightProbeGizmo(JmeLightProbe jmeProbe) {
+        super("point light callback", true, false, false);
+        this.jmeProbe = jmeProbe;
+        lightProbe = jmeProbe.getLightProbe();
+    }
+    
+    protected float getRadius() {
+        if (lightProbe.isReady()) {
+            return ((BoundingSphere)lightProbe.getBounds()).getRadius();
+        } else {
+            return 0f;
+        }
+    }
+
+    /**
+     * Handles the SceneComposers Translation "Requests".
+     * Essentially this is called when setLocalTranslation is invoked on the Gizmo.
+     * We then need to ensure that the Properties update and that the light
+     * itself updates (since the SceneComposer actually works with our Gizmos).
+     * 
+     * @param oldTranslation The Translation as it was before
+     * @param newTranslation The Translation as it is now
+     */
+    @Override
+    public void onTranslation(Vector3f oldTranslation, Vector3f newTranslation) {
+        // For lights, we're always interested in the WorldTranslation
+        lightProbe.setPosition(getWorldTranslation());
+        jmeProbe.setValue("position", lightProbe.getPosition());
+    }
+
+    /**
+     * Handles the SceneComposers Scale "Requests".
+     * Essentially this is called when setLocalScale is invoked on the Gizmo.
+     * We then need to ensure that the Propertries update and that the light
+     * itself updates (since the SceneComposer actually works with our Gizmos).
+     * 
+     * @param oldScale The Scale as it was before
+     * @param newScale The Scale as it is now
+     */
+    @Override
+    public void onResize(Vector3f oldScale, Vector3f newScale) {
+        ((BoundingSphere)jmeProbe.getLightProbe().getBounds()).setRadius(LightGizmoFactory.scaleToRadius(newScale));
+    }
+
+    /**
+     * Handles the SceneComposers Rotate "Requests".
+     * Essentially this is called when setLocalRotation is invoked on the Gizmo.
+     * We then need to ensure that the Propertries update and that the light
+     * itself updates (since the SceneComposer actually works with our Gizmos).
+     * 
+     * @param oldRotation The Rotation as it was before
+     * @param newRotation The Rotation as it is now
+     */
+    @Override
+    public void onRotation(Quaternion oldRotation, Quaternion newRotation) {
+        // Does not make sense.
+    }
+    
+    
+    // Convert Radius to a fake "scale"
+    @Override
+    public Vector3f getLocalScale() {
+        float r = getRadius();
+        return new Vector3f(r, r, r);
+    }
+
+    @Override
+    public Vector3f getWorldScale() {
+        float r = getRadius();
+        return new Vector3f(r, r, r);
+    }
+
+    @Override
+    public BoundingVolume getWorldBound() {
+        return new BoundingSphere(getRadius(), lightProbe.getPosition());
+    }
+
+}

+ 0 - 59
jme3-scenecomposer/src/com/jme3/gde/scenecomposer/gizmo/light/LightProbeGizmoControl.java

@@ -1,59 +0,0 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package com.jme3.gde.scenecomposer.gizmo.light;
-
-import com.jme3.bounding.BoundingSphere;
-import com.jme3.environment.util.LightsDebugState;
-import com.jme3.light.LightProbe;
-import com.jme3.material.Material;
-import com.jme3.math.Vector3f;
-import com.jme3.renderer.RenderManager;
-import com.jme3.renderer.ViewPort;
-import com.jme3.scene.Geometry;
-import com.jme3.scene.Node;
-import com.jme3.scene.control.AbstractControl;
-
-/**
- * Updates the marker's position whenever the light probe has moved. 
- * Also update the gizmo radius according to the probe radius.
- */
-public class LightProbeGizmoControl extends AbstractControl{
-
-    private final Vector3f lastPos = new Vector3f();
-    private final LightProbe lightProbe;
-
-    LightProbeGizmoControl(LightProbe light) {
-        lightProbe = light;
-
-    }
-
-    @Override
-    protected void controlUpdate(float f) {       
-
-        if (!lightProbe.getPosition().equals(lastPos)) {
-            if (getSpatial() != null) {
-                lastPos.set(lightProbe.getPosition());
-                getSpatial().setLocalTranslation(lastPos);
-            }
-        }
-          
-        Geometry probeGeom = (Geometry) ((Node) getSpatial()).getChild(0);
-        Material m = probeGeom.getMaterial();        
-        if (lightProbe.isReady()) {            
-            m.setTexture("CubeMap", lightProbe.getPrefilteredEnvMap());            
-        } 
-        Geometry probeRadius = (Geometry) ((Node) getSpatial()).getChild(1);
-        probeRadius.setLocalScale(((BoundingSphere) lightProbe.getBounds()).getRadius());
-        
-
-    }
-
-    @Override
-    protected void controlRender(RenderManager rm, ViewPort vp) {
-        
-    }
-
-}

+ 72 - 0
jme3-scenecomposer/src/com/jme3/gde/scenecomposer/gizmo/light/LightProbeUpdate.java

@@ -0,0 +1,72 @@
+/*
+ *  Copyright (c) 2009-2018 jMonkeyEngine
+ *  All rights reserved.
+ * 
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ * 
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ *  * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.gde.scenecomposer.gizmo.light;
+
+import com.jme3.bounding.BoundingSphere;
+import com.jme3.gde.core.sceneexplorer.nodes.JmeLightProbe;
+import com.jme3.material.Material;
+import com.jme3.renderer.RenderManager;
+import com.jme3.renderer.ViewPort;
+import com.jme3.scene.Geometry;
+import com.jme3.scene.Node;
+import com.jme3.scene.control.AbstractControl;
+
+/**
+ * Updates the Gizmo's Texture to display the EnvMap when ready.
+ * It also applies changes to the Probe's Radius to the Gizmo.
+ * 
+ * @author MeFisto94
+ */
+public class LightProbeUpdate extends AbstractControl {
+    JmeLightProbe jmeProbe;
+
+    public LightProbeUpdate(JmeLightProbe jmeProbe) {
+        this.jmeProbe = jmeProbe;
+    }
+
+    @Override
+    protected void controlUpdate(float f) {
+        Geometry probeGeom = (Geometry) ((Node) getSpatial()).getChild(0);
+        Material m = probeGeom.getMaterial();
+        
+        if (jmeProbe.getLightProbe().isReady()) {            
+            m.setTexture("CubeMap", jmeProbe.getLightProbe().getPrefilteredEnvMap());            
+        }
+        
+        Geometry probeRadius = (Geometry) ((Node) getSpatial()).getChild(1);
+        probeRadius.setLocalScale(((BoundingSphere) jmeProbe.getLightProbe().getBounds()).getRadius());
+    }
+
+    @Override
+    protected void controlRender(RenderManager rm, ViewPort vp) {
+    }
+}