Przeglądaj źródła

Extracted scaleToRadius method of Pointlight because it's also of use for LightProbes etc.

MeFisto94 7 lat temu
rodzic
commit
21088435f4

+ 43 - 13
jme3-scenecomposer/src/com/jme3/gde/scenecomposer/gizmo/light/LightGizmoFactory.java

@@ -167,18 +167,48 @@ public class LightGizmoFactory {
         return lightBulb;
     }
     
-    private static Spatial createLightProbeGizmo(AssetManager assetManager, Light light){
-        Node debugNode = new Node("Environment debug Node");
-        Sphere s = new Sphere(16, 16, 0.5f);
-        Geometry debugGeom = new Geometry(light.getName(), s);
-        Material debugMaterial = new Material(assetManager, "Common/MatDefs/Misc/reflect.j3md");
-        debugGeom.setMaterial(debugMaterial);
-        Spatial debugBounds = ProbeRadiusShape.createShape(assetManager);
-        
-        debugNode.attachChild(debugGeom);
-        debugNode.attachChild(debugBounds);
-        debugNode.addControl(new LightProbeGizmoControl((LightProbe)light));
-        
-        return debugNode;        
+    /**
+     * Helper Method to convert a Vector3f Scale into a radius. This is required,
+     * because the Gizmos are scaled like regular jME Nodes.
+     *
+     * Note: In case of non-uniform scaling, the code picks the minimum or maximum
+     * of all three components.
+     * 
+     * @param scale The Scale to convert
+     * @return The Radius
+     */
+    protected static float scaleToRadius(Vector3f scale) {
+        final float eps = 0.0000125f;        
+        float m;
+
+        float x = FastMath.abs(scale.x);
+        float y = FastMath.abs(scale.y);
+        float z = FastMath.abs(scale.z);
+        float max = Math.max(Math.max(x, y), z);
+        float min = Math.min(Math.min(x, y), z);
+
+        if (max - min <= eps) {
+            // x == y == z
+            m = x;
+        } else {
+            int nbMax = 0;
+            if (max - x <= eps) {
+                nbMax++;
+            }
+            if (max - y <= eps) {
+                nbMax++;
+            }
+            if (max - z <= eps) {
+                nbMax++;
+            }
+            if (nbMax >= 2) {
+                m = min;
+            } else {
+                m = max;
+            }
+        }
+        
+        return m;
     }
+    
 }

+ 1 - 33
jme3-scenecomposer/src/com/jme3/gde/scenecomposer/gizmo/light/PointLightGizmo.java

@@ -28,7 +28,6 @@ public class PointLightGizmo extends NodeCallback {
         super("point light callback", true, false, false);
         jmeLight = jmelight;
         light = jmeLight.getLookup().lookup(PointLight.class);
-
     }
 
     @Override
@@ -37,40 +36,9 @@ public class PointLightGizmo extends NodeCallback {
         jmeLight.setValue("position", light.getPosition());
     }
 
-    private final float eps = 0.0000125f;
-
     @Override
     public void onResize(Vector3f oldScale, Vector3f newScale) {
-        float m;
-
-        float x = FastMath.abs(newScale.x);
-        float y = FastMath.abs(newScale.y);
-        float z = FastMath.abs(newScale.z);
-        float max = Math.max(Math.max(x, y), z);
-        float min = Math.min(Math.min(x, y), z);
-
-        if (max - min <= eps) {
-            // x == y == z
-            m = x;
-        } else {
-            int nbMax = 0;
-            if (max - x <= eps) {
-                nbMax++;
-            }
-            if (max - y <= eps) {
-                nbMax++;
-            }
-            if (max - z <= eps) {
-                nbMax++;
-            }
-            if (nbMax >= 2) {
-                m = min;
-            } else {
-                m = max;
-            }
-        }
-
-        light.setRadius(m);
+        light.setRadius(LightGizmoFactory.scaleToRadius(newScale));
         jmeLight.setValue("radius", light.getRadius());
     }