Skip to content

Commit c739b66

Browse files
When in VR attach the debug scene to the two eye's scenes. Fix#1795 (#1888)
* #1795 When in VR attach the debug scene to the two eye's scenes This ensures they show up correctly * #1795 Whitespace corrections * #1795 Further whitespace corrections * #1795 Yet more whitespace corrections * #1795 Add explanatory comment as to why VR and non-VR have totally different approaches
1 parent 4e80c9b commit c739b66

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

jme3-jbullet/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dependencies {
1818
api 'javax.vecmath:vecmath:1.5.2'
1919
api project(':jme3-core')
2020
api project(':jme3-terrain')
21+
compileOnly project(':jme3-vr') //is selectively used if on classpath
2122
testRuntimeOnly project(':jme3-desktop')
2223
testRuntimeOnly project(':jme3-testdata')
2324
}

jme3-jbullet/src/main/java/com/jme3/bullet/debug/BulletDebugAppState.java

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
package com.jme3.bullet.debug;
3333

3434
import com.jme3.app.Application;
35+
import com.jme3.app.VRAppState;
3536
import com.jme3.app.state.AbstractAppState;
3637
import com.jme3.app.state.AppStateManager;
3738
import com.jme3.asset.AssetManager;
@@ -67,6 +68,12 @@ public class BulletDebugAppState extends AbstractAppState {
6768
* message logger for this class
6869
*/
6970
protected static final Logger logger = Logger.getLogger(BulletDebugAppState.class.getName());
71+
72+
/**
73+
* caches the virtual reality state (null means not yet determined)
74+
*/
75+
private Boolean isVr = null;
76+
7077
/**
7178
* limit which objects are visualized, or null to visualize all objects
7279
*/
@@ -165,9 +172,18 @@ public void initialize(AppStateManager stateManager, Application app) {
165172
this.assetManager = app.getAssetManager();
166173
setupMaterials(app);
167174
physicsDebugRootNode.setCullHint(Spatial.CullHint.Never);
168-
viewPort = rm.createMainView("Physics Debug Overlay", app.getCamera());
169-
viewPort.setClearFlags(false, true, false);
170-
viewPort.attachScene(physicsDebugRootNode);
175+
176+
if (isVr()) {
177+
/* This is a less good solution than the non-vr version (as the debug shapes can be obscured by the regular
178+
* geometry), however it is the best possible as VR does not currently support multiple viewports per eye */
179+
VRAppState vrAppState = stateManager.getState(VRAppState.ID, VRAppState.class);
180+
vrAppState.getLeftViewPort().attachScene(physicsDebugRootNode);
181+
vrAppState.getRightViewPort().attachScene(physicsDebugRootNode);
182+
} else {
183+
viewPort = rm.createMainView("Physics Debug Overlay", app.getCamera());
184+
viewPort.setClearFlags(false, true, false);
185+
viewPort.attachScene(physicsDebugRootNode);
186+
}
171187
}
172188

173189
/**
@@ -178,7 +194,14 @@ public void initialize(AppStateManager stateManager, Application app) {
178194
*/
179195
@Override
180196
public void cleanup() {
181-
rm.removeMainView(viewPort);
197+
if (isVr()) {
198+
VRAppState vrAppState = app.getStateManager().getState(VRAppState.ID, VRAppState.class);
199+
vrAppState.getLeftViewPort().detachScene(physicsDebugRootNode);
200+
vrAppState.getRightViewPort().detachScene(physicsDebugRootNode);
201+
} else {
202+
rm.removeMainView(viewPort);
203+
}
204+
182205
super.cleanup();
183206
}
184207

@@ -413,4 +436,17 @@ public static interface DebugAppStateFilter {
413436
*/
414437
public boolean displayObject(Object obj);
415438
}
416-
}
439+
440+
private boolean isVr() {
441+
if (isVr == null) {
442+
try {
443+
VRAppState vrAppState = app.getStateManager().getState(VRAppState.ID, VRAppState.class);
444+
isVr = vrAppState != null && !vrAppState.DISABLE_VR;
445+
} catch (NoClassDefFoundError e) {
446+
//Vr isn't even on the classpath
447+
isVr = false;
448+
}
449+
}
450+
return isVr;
451+
}
452+
}

jme3-vr/src/main/java/com/jme3/app/VRAppState.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
* @author Julien Seinturier - COMEX SA - <a href="http://www.seinturier.fr">http://www.seinturier.fr</a>
7575
*/
7676
public class VRAppState extends AbstractAppState {
77+
public static final String ID = "VRAppState";
7778
private static final Logger logger = Logger.getLogger(VRAppState.class.getName());
7879

7980
/**
@@ -105,7 +106,7 @@ public class VRAppState extends AbstractAppState {
105106
* @param environment the {@link VREnvironment VR environment} that this app state is using.
106107
*/
107108
public VRAppState(VREnvironment environment) {
108-
super();
109+
super(ID);
109110

110111
this.environment = environment;
111112

0 commit comments

Comments
 (0)