Przeglądaj źródła

Updated GizmoUpdate Classes:
- Added Copyright
- They now really invoke the getPosition/getDirection each frame instead of only holding a reference to the Method.
- Improved Javadoc

MeFisto94 7 lat temu
rodzic
commit
78534509d8

+ 46 - 11
jme3-scenecomposer/src/com/jme3/gde/scenecomposer/gizmo/light/LightColorUpdate.java

@@ -1,7 +1,33 @@
 /*
- * 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.
+ *  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;
 
@@ -13,23 +39,32 @@ import com.jme3.renderer.ViewPort;
 import com.jme3.scene.control.AbstractControl;
 
 /**
- *
+ * A utility control to update the color of a material as the color of
+ * a tracked light changes. This is used to re-colorize gizmos as the
+ * user is changing the light color using the Properties Editor.
+ * 
  * @author dokthar
  */
 public class LightColorUpdate extends AbstractControl {
 
-    private Light light;
+    private final Light light;
     private final ColorRGBA lastCol = new ColorRGBA();
-    private ColorRGBA lightCol;
-    private Material mat;
-    private String name;
+    private final ColorRGBA lightCol;
+    private final Material mat;
+    private final String name;
 
-    public LightColorUpdate(Light l, Material mat, String name) {
+    /**
+     * 
+     * @param l The Light to track
+     * @param mat The Material to edit
+     * @param parameterName The Name of the Parameter (DiffuseMap, Color, ...)
+     */
+    public LightColorUpdate(Light l, Material mat, String parameterName) {
         light = l;
         lightCol = light.getColor();
         this.mat = mat;
-        this.name = name;
-        mat.setColor(name, lightCol);
+        this.name = parameterName;
+        mat.setColor(parameterName, lightCol);
     }
 
     @Override

+ 41 - 6
jme3-scenecomposer/src/com/jme3/gde/scenecomposer/gizmo/light/LightConeRadiusUpdate.java

@@ -1,7 +1,33 @@
 /*
- * 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.
+ *  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;
 
@@ -13,17 +39,26 @@ import com.jme3.scene.Geometry;
 import com.jme3.scene.control.AbstractControl;
 
 /**
- *
+ * A utility control to update the radius of the lightcone gizmo as the radius
+ * of a tracked cone radius changes. This is used to adjust gizmos as the
+ * user is changing the light parameters using the Properties Editor.
+ * 
  * @author dokthar
  */
 public class LightConeRadiusUpdate extends AbstractControl {
 
-    private SpotLight light;
+    private final SpotLight light;
     private float lastInnerAngle = -1;
     private float lastOuterAngle = -1;
     private float lastRange = -1;
-    private Geometry inner, outer;
+    private final Geometry inner, outer;
 
+    /**
+     * 
+     * @param l The Spotlight to track
+     * @param inner The Geometry representing the inner angle
+     * @param outer The Geometry representing the outer angle
+     */
     public LightConeRadiusUpdate(SpotLight l, Geometry inner, Geometry outer) {
         this.light = l;
         this.inner = inner;

+ 59 - 24
jme3-scenecomposer/src/com/jme3/gde/scenecomposer/gizmo/light/LightDirectionUpdate.java

@@ -1,10 +1,37 @@
 /*
- * 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.
+ *  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.gde.core.errorreport.ExceptionUtils;
 import com.jme3.gde.scenecomposer.gizmo.NodeCallback;
 import com.jme3.light.Light;
 import com.jme3.math.Quaternion;
@@ -12,44 +39,51 @@ import com.jme3.math.Vector3f;
 import com.jme3.renderer.RenderManager;
 import com.jme3.renderer.ViewPort;
 import com.jme3.scene.control.AbstractControl;
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import org.openide.util.Exceptions;
 
 /**
- *
+ * A utility control to update the direction of an arrow as the direction of
+ * a tracked light changes. This is used to adjust gizmos as the
+ * user is changing the light direction using the Properties Editor.
+ * 
  * @author dokthar
  */
 public class LightDirectionUpdate extends AbstractControl {
 
-    private Light light;
-    private NodeCallback gizmo;
+    private final Light light;
+    private final NodeCallback gizmo;
+    private Method getDirection = null;
 
     private final Vector3f lastDir = new Vector3f();
     private Vector3f lightDir;
 
-    public LightDirectionUpdate(Light l, NodeCallback g) {
-        gizmo = g;
-        light = l;
-
+    public LightDirectionUpdate(Light light, NodeCallback gizmo) {
+        this.gizmo = gizmo;
+        this.light = light;
+        
         try {
-            Method getDirection = light.getClass().getMethod("getDirection");
-            lightDir = (Vector3f) getDirection.invoke(light);
+            getDirection = light.getClass().getMethod("getDirection");
         } catch (NoSuchMethodException ex) {
-            //light type doesn't have a get position method, silancing the exception
-        } catch (SecurityException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (IllegalAccessException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (IllegalArgumentException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (InvocationTargetException ex) {
-            Exceptions.printStackTrace(ex);
+            ExceptionUtils.caughtException(ex, "The LightDirectionUpdate "
+                + "Control has been added for a light which doesn't even "
+                + "have a direction. This means someone has seriously "
+                + "fucked up. I just hope it's not me ;)");
+        }
+    }
+    
+    protected void refreshLightDirection() {
+        try {
+            if (getDirection != null) {
+                lightDir = (Vector3f) getDirection.invoke(light);
+            }
+        } catch (Exception ex) {
+            ExceptionUtils.caughtException(ex);
         }
     }
 
     @Override
     protected void controlUpdate(float f) {
+        refreshLightDirection();
         if (!lightDir.equals(lastDir)) {
             lastDir.set(lightDir);
 
@@ -57,7 +91,8 @@ public class LightDirectionUpdate extends AbstractControl {
             float angle = Vector3f.UNIT_Y.angleBetween(lastDir);
             //Quaternion rotation = gizmo.getWorldRotation().inverse().mult(new Quaternion().fromAngleAxis(angle, axis));
             Quaternion rotation = new Quaternion().fromAngleAxis(angle, axis);
-            gizmo.silentLocalRotation(rotation);
+            gizmo.silentLocalRotation(rotation); /* silent, because otherwise
+            the gizmo would call light.setDirection() and update the property */
         }
     }
 

+ 57 - 26
jme3-scenecomposer/src/com/jme3/gde/scenecomposer/gizmo/light/LightGizmoControl.java

@@ -1,57 +1,88 @@
 /*
- * 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.
+ *  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.gde.core.errorreport.ExceptionUtils;
+import com.jme3.gde.scenecomposer.gizmo.NodeCallback;
 import com.jme3.light.Light;
 import com.jme3.math.Vector3f;
 import com.jme3.scene.control.BillboardControl;
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import org.openide.util.Exceptions;
 
 /**
  * Updates the marker's position whenever the light has moved. It is also a
- * BillboardControl, so this marker always faces the camera
+ * BillboardControl, so this marker always faces the camera.
+ * 
+ * Basically this is the combination of {@link LightPositionUpdate} and {@link 
+ * BillboardControl}, but without u
  */
 public class LightGizmoControl extends BillboardControl {
 
     private final Vector3f lastPos = new Vector3f();
     private Vector3f lightPos;
+    private Method getPosition = null;
+    private Light light;
 
     LightGizmoControl(Light light) {
         super();
-
+        this.light = light;
+        
         try {
-            Method getPosition = light.getClass().getMethod("getPosition");
-            lightPos = (Vector3f) getPosition.invoke(light);
+            getPosition = light.getClass().getMethod("getPosition");
         } catch (NoSuchMethodException ex) {
-            //light type doesn't have a get position method, silancing the exception
-        } catch (SecurityException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (IllegalAccessException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (IllegalArgumentException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (InvocationTargetException ex) {
-            Exceptions.printStackTrace(ex);
+            ExceptionUtils.caughtException(ex, "The LightPositionUpdate "
+                + "Control has been added for a light which doesn't even "
+                + "have a position. This means someone has seriously "
+                + "fucked up. I just hope it's not me ;)");
+        }
+    }
+    
+    protected void updateLightPosition() {
+        try {
+            lightPos = (Vector3f) getPosition.invoke(light);
+        } catch (Exception ex) {
+            ExceptionUtils.caughtException(ex);
         }
-
     }
 
     @Override
     protected void controlUpdate(float f) {
         super.controlUpdate(f);
-
+        updateLightPosition();
+        
         if (!lightPos.equals(lastPos)) {
-            if (getSpatial() != null) {
-                lastPos.set(lightPos);
-                getSpatial().setLocalTranslation(lastPos);
-            }
+            lastPos.set(lightPos);
+            getSpatial().getParent().worldToLocal(lastPos, lastPos);
+            ((NodeCallback)getSpatial()).silentLocalTranslation(lastPos);
         }
-
     }
-
 }

+ 51 - 18
jme3-scenecomposer/src/com/jme3/gde/scenecomposer/gizmo/light/LightPositionUpdate.java

@@ -1,29 +1,57 @@
 /*
- * 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.
+ *  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.gde.core.errorreport.ExceptionUtils;
 import com.jme3.gde.scenecomposer.gizmo.NodeCallback;
 import com.jme3.light.Light;
 import com.jme3.math.Vector3f;
 import com.jme3.renderer.RenderManager;
 import com.jme3.renderer.ViewPort;
 import com.jme3.scene.control.AbstractControl;
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import org.openide.util.Exceptions;
 
 /**
- *
+ * A utility control to update the position of a gizmo as the position of
+ * a tracked light changes. This is used to adjust gizmos as the
+ * user is changing the light position using the Properties Editor.
+ * 
  * @author dokthar
  */
 public class LightPositionUpdate extends AbstractControl {
 
     private Light light;
     private NodeCallback gizmo;
-    
+    private Method getPosition = null;
     private final Vector3f lastPos = new Vector3f();
     private Vector3f lightPos;
 
@@ -32,23 +60,28 @@ public class LightPositionUpdate extends AbstractControl {
         light = l;
 
         try {
-            Method getPosition = light.getClass().getMethod("getPosition");
-            lightPos = (Vector3f) getPosition.invoke(light);
+            getPosition = light.getClass().getMethod("getPosition");
+            
         } catch (NoSuchMethodException ex) {
-            //light type doesn't have a get position method, silancing the exception
-        } catch (SecurityException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (IllegalAccessException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (IllegalArgumentException ex) {
-            Exceptions.printStackTrace(ex);
-        } catch (InvocationTargetException ex) {
-            Exceptions.printStackTrace(ex);
+            ExceptionUtils.caughtException(ex, "The LightPositionUpdate "
+                + "Control has been added for a light which doesn't even "
+                + "have a position. This means someone has seriously "
+                + "fucked up. I just hope it's not me ;)");
+        }
+    }
+    
+    protected void updateLightPosition() {
+        try {
+            lightPos = (Vector3f) getPosition.invoke(light);
+        } catch (Exception ex) {
+            ExceptionUtils.caughtException(ex);
         }
     }
 
     @Override
     protected void controlUpdate(float f) {
+        updateLightPosition();
+        
         if (!lightPos.equals(lastPos)) {
             lastPos.set(lightPos);
             gizmo.getParent().worldToLocal(lastPos, lastPos);