4646import com .jme3 .math .Quaternion ;
4747import com .jme3 .math .Vector3f ;
4848import com .jme3 .renderer .RenderManager ;
49+ import com .jme3 .renderer .ViewPort ;
4950import com .jme3 .renderer .queue .RenderQueue ;
5051import com .jme3 .scene .Geometry ;
5152import com .jme3 .scene .Node ;
@@ -80,6 +81,7 @@ public class LightsDebugState extends BaseAppState {
8081
8182 // The scene whose lights will be debugged
8283 private Spatial scene ;
84+ private ViewPort viewPort ;
8385 private Node debugNode ;
8486 private final Map <Light , Spatial > lightGizmoMap = new WeakHashMap <>();
8587 private final ArrayDeque <Light > lightDeque = new ArrayDeque <>();
@@ -88,17 +90,18 @@ public class LightsDebugState extends BaseAppState {
8890 private Material debugMaterial ;
8991
9092 private float lightProbeScale = 1.0f ;
93+ private final ColorRGBA debugColor = ColorRGBA .DarkGray ;
9194 private final Quaternion tempRotation = new Quaternion ();
92- private final ColorRGBA GIZMO_COLOR = ColorRGBA .DarkGray ;
9395
9496 @ Override
9597 protected void initialize (Application app ) {
9698
9799 this .assetManager = app .getAssetManager ();
100+ viewPort = app .getRenderManager ().createMainView ("EnvDebugView" , app .getCamera ());
98101 debugNode = new Node ("LightsDebugNode" );
99102
100103 debugMaterial = new Material (assetManager , "Common/MatDefs/Misc/Unshaded.j3md" );
101- debugMaterial .setColor ("Color" , GIZMO_COLOR );
104+ debugMaterial .setColor ("Color" , debugColor );
102105 debugMaterial .getAdditionalRenderState ().setWireframe (true );
103106
104107 if (scene == null ) {
@@ -128,7 +131,7 @@ private Spatial createBulb() {
128131 private Geometry createRadiusShape (String name , float dashSize ) {
129132 Geometry radius = Circle .createShape (assetManager , name );
130133 Material mat = radius .getMaterial ();
131- mat .setColor ("Color" , GIZMO_COLOR );
134+ mat .setColor ("Color" , debugColor );
132135 mat .setFloat ("DashSize" , dashSize );
133136 return radius ;
134137 }
@@ -213,7 +216,7 @@ public void update(float tpf) {
213216 @ Override
214217 public void render (RenderManager rm ) {
215218 debugNode .updateGeometricState ();
216- rm .renderScene (debugNode , getApplication (). getViewPort () );
219+ rm .renderScene (debugNode , viewPort );
217220 }
218221
219222 /**
@@ -224,7 +227,7 @@ public void render(RenderManager rm) {
224227 */
225228 private void updateLightGizmos (Spatial spatial ) {
226229 // Add or update gizmos for lights attached to the current spatial
227- for (Light light : spatial .getWorldLightList ()) {
230+ for (Light light : spatial .getLocalLightList ()) {
228231 lightDeque .add (light );
229232 Spatial gizmo = lightGizmoMap .get (light );
230233
@@ -401,14 +404,17 @@ protected void cleanup(Application app) {
401404 lightGizmoMap .clear ();
402405 lightDeque .clear ();
403406 debugMaterial = null ;
407+ app .getRenderManager ().removeMainView (viewPort );
404408 }
405409
406410 @ Override
407411 protected void onEnable () {
412+ viewPort .attachScene (debugNode );
408413 }
409414
410415 @ Override
411416 protected void onDisable () {
417+ viewPort .detachScene (debugNode );
412418 }
413419
414420}
0 commit comments