Skip to content

Commit

Permalink
When in VR attach the debug scene to the two eye's scenes. Fix#1795 (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
richardTingle authored Jan 11, 2023
1 parent 4e80c9b commit c739b66
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
1 change: 1 addition & 0 deletions jme3-jbullet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies {
api 'javax.vecmath:vecmath:1.5.2'
api project(':jme3-core')
api project(':jme3-terrain')
compileOnly project(':jme3-vr') //is selectively used if on classpath
testRuntimeOnly project(':jme3-desktop')
testRuntimeOnly project(':jme3-testdata')
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
package com.jme3.bullet.debug;

import com.jme3.app.Application;
import com.jme3.app.VRAppState;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.asset.AssetManager;
Expand Down Expand Up @@ -67,6 +68,12 @@ public class BulletDebugAppState extends AbstractAppState {
* message logger for this class
*/
protected static final Logger logger = Logger.getLogger(BulletDebugAppState.class.getName());

/**
* caches the virtual reality state (null means not yet determined)
*/
private Boolean isVr = null;

/**
* limit which objects are visualized, or null to visualize all objects
*/
Expand Down Expand Up @@ -165,9 +172,18 @@ public void initialize(AppStateManager stateManager, Application app) {
this.assetManager = app.getAssetManager();
setupMaterials(app);
physicsDebugRootNode.setCullHint(Spatial.CullHint.Never);
viewPort = rm.createMainView("Physics Debug Overlay", app.getCamera());
viewPort.setClearFlags(false, true, false);
viewPort.attachScene(physicsDebugRootNode);

if (isVr()) {
/* This is a less good solution than the non-vr version (as the debug shapes can be obscured by the regular
* geometry), however it is the best possible as VR does not currently support multiple viewports per eye */
VRAppState vrAppState = stateManager.getState(VRAppState.ID, VRAppState.class);
vrAppState.getLeftViewPort().attachScene(physicsDebugRootNode);
vrAppState.getRightViewPort().attachScene(physicsDebugRootNode);
} else {
viewPort = rm.createMainView("Physics Debug Overlay", app.getCamera());
viewPort.setClearFlags(false, true, false);
viewPort.attachScene(physicsDebugRootNode);
}
}

/**
Expand All @@ -178,7 +194,14 @@ public void initialize(AppStateManager stateManager, Application app) {
*/
@Override
public void cleanup() {
rm.removeMainView(viewPort);
if (isVr()) {
VRAppState vrAppState = app.getStateManager().getState(VRAppState.ID, VRAppState.class);
vrAppState.getLeftViewPort().detachScene(physicsDebugRootNode);
vrAppState.getRightViewPort().detachScene(physicsDebugRootNode);
} else {
rm.removeMainView(viewPort);
}

super.cleanup();
}

Expand Down Expand Up @@ -413,4 +436,17 @@ public static interface DebugAppStateFilter {
*/
public boolean displayObject(Object obj);
}
}

private boolean isVr() {
if (isVr == null) {
try {
VRAppState vrAppState = app.getStateManager().getState(VRAppState.ID, VRAppState.class);
isVr = vrAppState != null && !vrAppState.DISABLE_VR;
} catch (NoClassDefFoundError e) {
//Vr isn't even on the classpath
isVr = false;
}
}
return isVr;
}
}
3 changes: 2 additions & 1 deletion jme3-vr/src/main/java/com/jme3/app/VRAppState.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
* @author Julien Seinturier - COMEX SA - <a href="http://www.seinturier.fr">http://www.seinturier.fr</a>
*/
public class VRAppState extends AbstractAppState {
public static final String ID = "VRAppState";
private static final Logger logger = Logger.getLogger(VRAppState.class.getName());

/**
Expand Down Expand Up @@ -105,7 +106,7 @@ public class VRAppState extends AbstractAppState {
* @param environment the {@link VREnvironment VR environment} that this app state is using.
*/
public VRAppState(VREnvironment environment) {
super();
super(ID);

this.environment = environment;

Expand Down

0 comments on commit c739b66

Please sign in to comment.