Still not working, I feel like I have hit a dead end, but I will keep trying.
Here is my current test code:
package io.tlf.jme.test;
import com.jme3.app.*;
import com.jme3.app.state.AppState;
import com.jme3.asset.plugins.FileLocator;
import com.jme3.input.InputManager;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.vr.openvr.OpenVR;
import com.jme3.material.Material;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.post.CartoonSSAO;
import com.jme3.post.FilterPostProcessor;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;
import com.jme3.util.SkyFactory;
import com.jme3.util.VRGUIPositioningMode;
import org.lwjgl.openvr.VRApplications;
import java.io.File;
import java.util.logging.Logger;
public class VRTest extends SimpleApplication {
private static final Logger logger = Logger.getLogger(VRTest.class.getName());
Spatial observer;
boolean moveForward, moveBackwards, rotateLeft, rotateRight;
Material mat;
Node mainScene;
VRAppState vrAppState = null;
public VRTest(AppState... initialStates) {
super(initialStates);
vrAppState = getStateManager().getState(VRAppState.class);
}
@Override
public void simpleInitApp() {
logger.info("Updating asset manager with " + System.getProperty("user.dir"));
getAssetManager().registerLocator(System.getProperty("user.dir") + File.separator + "assets", FileLocator.class);
mainScene = new Node("scene");
observer = new Node("observer");
Spatial sky = SkyFactory.createSky(getAssetManager(), "Textures/Path.hdr", SkyFactory.EnvMapType.EquirectMap);
rootNode.attachChild(sky);
// make the floor according to the size of our play area
Geometry floor = new Geometry("floor", new Box(1f, 1f, 1f));
Vector2f playArea = vrAppState.getVREnvironment().getVRBounds().getPlaySize();
if (playArea == null) {
// no play area, use default size & height
floor.setLocalScale(2f, 0.5f, 2f);
floor.move(0f, -1.5f, 0f);
} else {
// cube model is actually 2x as big, cut it down to proper playArea size with * 0.5
floor.setLocalScale(playArea.x * 0.5f, 0.5f, playArea.y * 0.5f);
floor.move(0f, -0.5f, 0f);
}
mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
floor.setMaterial(mat);
rootNode.attachChild(floor);
// test any positioning mode here (defaults to AUTO_CAM_ALL)
vrAppState.getVRGUIManager().setPositioningMode(VRGUIPositioningMode.AUTO_OBSERVER_ALL);
vrAppState.getVRGUIManager().setGuiScale(0.4f);
observer.setLocalTranslation(new Vector3f(0.0f, 0.0f, 0.0f));
vrAppState.setObserver(observer);
mainScene.attachChild(observer);
rootNode.attachChild(mainScene);
initInputs();
getInputManager().setCursorVisible(true);
}
private void initInputs() {
InputManager inputManager = getInputManager();
inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addMapping("incShift", new KeyTrigger(KeyInput.KEY_Q));
inputManager.addMapping("decShift", new KeyTrigger(KeyInput.KEY_E));
inputManager.addMapping("forward", new KeyTrigger(KeyInput.KEY_W));
inputManager.addMapping("back", new KeyTrigger(KeyInput.KEY_S));
inputManager.addMapping("left", new KeyTrigger(KeyInput.KEY_A));
inputManager.addMapping("right", new KeyTrigger(KeyInput.KEY_D));
inputManager.addMapping("filter", new KeyTrigger(KeyInput.KEY_F));
inputManager.addMapping("dumpImages", new KeyTrigger(KeyInput.KEY_I));
inputManager.addMapping("exit", new KeyTrigger(KeyInput.KEY_ESCAPE));
ActionListener acl = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals("incShift") && keyPressed) {
vrAppState.getVRGUIManager().adjustGuiDistance(-0.1f);
} else if (name.equals("decShift") && keyPressed) {
vrAppState.getVRGUIManager().adjustGuiDistance(0.1f);
} else if (name.equals("filter") && keyPressed) {
// adding filters in realtime
CartoonSSAO cartfilt = new CartoonSSAO(vrAppState.isInstanceRendering());
FilterPostProcessor fpp = new FilterPostProcessor(getAssetManager());
fpp.addFilter(cartfilt);
getViewPort().addProcessor(fpp);
// filters added to main viewport during runtime,
// move them into VR processing
// (won't do anything if not in VR mode)
vrAppState.moveScreenProcessingToVR();
}
if (name.equals("toggle")) {
vrAppState.getVRGUIManager().positionGui();
}
if (name.equals("forward")) {
if (keyPressed) {
moveForward = true;
} else {
moveForward = false;
}
} else if (name.equals("back")) {
if (keyPressed) {
moveBackwards = true;
} else {
moveBackwards = false;
}
} else if (name.equals("dumpImages")) {
((OpenVR) vrAppState.getVRHardware()).getCompositor().CompositorDumpImages.apply();
} else if (name.equals("left")) {
if (keyPressed) {
rotateLeft = true;
} else {
rotateLeft = false;
}
} else if (name.equals("right")) {
if (keyPressed) {
rotateRight = true;
} else {
rotateRight = false;
}
} else if (name.equals("exit")) {
stop(true);
System.exit(0);
}
}
};
inputManager.addListener(acl, "forward");
inputManager.addListener(acl, "back");
inputManager.addListener(acl, "left");
inputManager.addListener(acl, "right");
inputManager.addListener(acl, "toggle");
inputManager.addListener(acl, "incShift");
inputManager.addListener(acl, "decShift");
inputManager.addListener(acl, "filter");
inputManager.addListener(acl, "dumpImages");
inputManager.addListener(acl, "exit");
}
@Override
public void simpleUpdate(float tpf) {
}
private static void registerVr() {
//Register our manifest with SteamVR
File manifest = new File("C:\\Users\\Trevor\\Desktop\\jme-tests\\src\\main\\resources\\outside.vrmanifest"); //Path to manifest
if (manifest.exists()) {
String path = manifest.getAbsolutePath(); //Must be absolute path
String appKey = "io.tlf.vr.test";
int error;
//The bool is for temporary or permanent registration
//error = VRApplications.VRApplications_RemoveApplicationManifest(path);
//logger.info("Unregister VR Manifest: " + VRApplications.VRApplications_GetApplicationsErrorNameFromEnum(error));
if (!VRApplications.VRApplications_IsApplicationInstalled(appKey)) {
error = VRApplications.VRApplications_AddApplicationManifest(path, false);
logger.info("Register VR Manifest: " + VRApplications.VRApplications_GetApplicationsErrorNameFromEnum(error));
} else {
logger.info("VR App already installed");
}
long pid = ProcessHandle.current().pid();
logger.info("PID = " + pid);
error = VRApplications.VRApplications_IdentifyApplication((int) pid, appKey);
logger.info("Set VR Manifest: " + VRApplications.VRApplications_GetApplicationsErrorNameFromEnum(error));
} else {
logger.warning("No VR Manifest found, but VR enabled!");
}
//List apps
/* This throws a native error...
int count = VRApplications.VRApplications_GetApplicationCount();
logger.info("Running apps: " + count);
for (int i = 0; i < count; i++) {
ByteBuffer buffer = ByteBuffer.allocate(VR.k_unMaxActionSetNameLength);
int error = VRApplications.VRApplications_GetApplicationKeyByIndex(i, buffer);
String name = new String(buffer.array());
logger.info("Running app: " + name);
}
*/
}
/**
* Create a {@link VRAppState VR app state} and use a Simple application that use it.<br>
* The recommended procedure is:<br>
* <ul>
* <li>Create some {@link AppSettings AppSettings} with VR related parameters.
* <li>Instanciate the {@link VRAppState VRAppState} attached to the settings.
* <li>Instanciate your {@link Application Application}.
* <li>Attach the settings to the application.
* <li>Start the application.
* </ul>
*
* @param args not used
*/
public static void main(String[] args) {
// Prepare settings for VR rendering.
// It is recommended to share same settings between the VR app state and the application.
AppSettings settings = new AppSettings(true);
settings.put(VRConstants.SETTING_VRAPI, VRConstants.SETTING_VRAPI_OPENVR_LWJGL_VALUE); // The VR api to use (need to be present on the system)
settings.put(VRConstants.SETTING_DISABLE_VR, false); // Enable VR
settings.put(VRConstants.SETTING_ENABLE_MIRROR_WINDOW, true); // Enable Mirror rendering oh the screen (disable to be faster)
settings.put(VRConstants.SETTING_VR_FORCE, false); // Not forcing VR rendering if no VR system is found.
settings.put(VRConstants.SETTING_FLIP_EYES, false); // Is the HMD eyes have to be inverted.
settings.put(VRConstants.SETTING_DEFAULT_FOV, 108f); // The default field Of View (FOV)
settings.put(VRConstants.SETTING_DEFAULT_ASPECT_RATIO, 1f); // The default aspect ratio.
settings.setRenderer(AppSettings.LWJGL_OPENGL32); // Setting the renderer. OpenGL 3 is needed if you're using Instance Rendering.
// The VR Environment.
// This object is the interface between the JMonkey world (Application, AppState, ...) and the VR specific stuff.
VREnvironment environment = new VREnvironment(settings);
environment.initialize();
registerVr();
settings.put(VRConstants.SETTING_NO_GUI, false); // enable gui.
settings.put(VRConstants.SETTING_GUI_OVERDRAW, true); // show gui even if it is behind things.
settings.put(VRConstants.SETTING_GUI_CURVED_SURFACE, true); // Curve the mesh that is displaying the GUI
// Checking if the VR environment is well initialized
// (access to the underlying VR system is effective, VR devices are detected).
if (environment.isInitialized()) {
environment.setSettings(settings);
// Initialise VR AppState with the VR environment.
VRAppState vrAppState = new VRAppState(settings, environment);
// Create the sample application with the VRAppState attached.
// There is no constraint on the Application type.
SimpleApplication test = new VRTest(vrAppState);
test.setShowSettings(false);
// Sharing settings between app state and application is recommended.
test.setSettings(settings);
// Starting the application.
test.start();
} else {
logger.severe("Cannot start VR sample application as VR system is not initialized (see log for details)");
}
}
}
{
"source": "builtin",
"applications": [
{
"app_key": "io.tlf.vr.test",
"launch_type": "binary",
"binary_path_windows": "java",
"arguments": "-jar C:\\Users\\Trevor\\Desktop\\jme-tests\\build\\libs\\jme-tests-0.0.0.jar",
"image_path": "Textures/vr_banner.png",
"strings": {
"en_us": {
"name": "Trevor's VR Test",
"description": "Testing VR Systems with JME"
}
}
}
]
}
From the output, it says it registered, but then cannot find the app:
Sep 27, 2020 11:21:56 AM com.jme3.input.vr.lwjgl_openvr.LWJGLOpenVR initialize
INFO: Model Number : VIVE_Pro MV
Sep 27, 2020 11:21:56 AM com.jme3.input.vr.lwjgl_openvr.LWJGLOpenVR initialize
INFO: Serial Number: LHR-A9D4E09A
Sep 27, 2020 11:21:56 AM com.jme3.input.vr.lwjgl_openvr.LWJGLOpenVR initialize
INFO: Initializing OpenVR system [SUCCESS]
Sep 27, 2020 11:21:56 AM io.tlf.jme.test.VRTest registerVr
INFO: Register VR Manifest: VRApplicationError_None
Sep 27, 2020 11:21:56 AM io.tlf.jme.test.VRTest registerVr
INFO: PID = 26436
Sep 27, 2020 11:21:56 AM io.tlf.jme.test.VRTest registerVr
INFO: Set VR Manifest: VRApplicationError_UnknownApplication
Sep 27, 2020 11:21:56 AM com.jme3.system.JmeDesktopSystem initialize