浏览代码

Feat: Add light filter to customize debug light display

Wyatt Gillette 3 月之前
父节点
当前提交
c90dcd8184
共有 1 个文件被更改,包括 16 次插入0 次删除
  1. 16 0
      jme3-core/src/main/java/com/jme3/environment/util/LightsDebugState.java

+ 16 - 0
jme3-core/src/main/java/com/jme3/environment/util/LightsDebugState.java

@@ -61,6 +61,7 @@ import java.util.ArrayDeque;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.WeakHashMap;
+import java.util.function.Predicate;
 
 /**
  * A debug state that visualizes different types of lights in the scene with gizmos.
@@ -85,6 +86,7 @@ public class LightsDebugState extends BaseAppState {
     private Node debugNode;
     private final Map<Light, Spatial> lightGizmoMap = new WeakHashMap<>();
     private final ArrayDeque<Light> lightDeque = new ArrayDeque<>();
+    private Predicate<Light> lightFilter = x -> true; // Identity Function
 
     private AssetManager assetManager;
     private Material debugMaterial;
@@ -228,6 +230,10 @@ public class LightsDebugState extends BaseAppState {
     private void updateLightGizmos(Spatial spatial) {
         // Add or update gizmos for lights attached to the current spatial
         for (Light light : spatial.getLocalLightList()) {
+            if (!lightFilter.test(light)) {
+                continue;
+            }
+
             lightDeque.add(light);
             Spatial gizmo = lightGizmoMap.get(light);
 
@@ -392,6 +398,16 @@ public class LightsDebugState extends BaseAppState {
         this.lightProbeScale = scale;
     }
 
+    /**
+     * Sets a filter to control which lights are displayed by the debug state.
+     * By default, no filter is applied, meaning all lights are displayed.
+     *
+     * @param lightFilter A {@link Predicate} that tests a {@link Light} object.
+     */
+    public void setLightFilter(Predicate<Light> lightFilter) {
+        this.lightFilter = lightFilter;
+    }
+
     /**
      * Cleans up resources when the app state is detached.
      *