virtualreality.adoc 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. = Virtual Reality
  2. :author:
  3. :revnumber:
  4. :revdate: 2016/10/23 11:22
  5. :relfileprefix: ../
  6. :imagesdir: ..
  7. ifdef::env-github,env-browser[:outfilesuffix: .adoc]
  8. Please see this link:https://hub.jmonkeyengine.org/t/official-vr-module/37830/67[forum post] for additional information on JME Official VR module.
  9. jMonkeyEngine 3 has a wide range of support for Virtual Reality (VR). The known supported systems are:
  10. HTC Vive and systems supporting SteamVR/OpenVR
  11. Native Oculus Rift support (and through SteamVR)
  12. Razer HDK and systems supporting OSVR
  13. Google Cardboard / GoogleVR
  14. Two implementations exist for OpenVR. A community maintained JNA based binding and LWJGL's JNI based.
  15. To use the JNA based bindings, put:
  16. settings.put(VRConstants.SETTING_VRAPI, VRConstants.SETTING_VRAPI_OPENVR_VALUE);
  17. in your settings. To use LWJGL, instead put:
  18. settings.put(VRConstants.SETTING_VRAPI, VRConstants.SETTING_VRAPI_OPENVR_LWJGL_VALUE);
  19. Note that the LWJGL bindings require LWJGL3 (jme3-lwjgl3) to be used.
  20. == Sample Application
  21. [source,java]
  22. ----
  23. public class Main extends SimpleApplication {
  24. public static void main(String[] args) {
  25. AppSettings settings = new AppSettings(true);
  26. settings.put(VRConstants.SETTING_VRAPI, VRConstants.SETTING_VRAPI_OPENVR_LWJGL_VALUE);
  27. settings.put(VRConstants.SETTING_ENABLE_MIRROR_WINDOW, true);
  28. VREnvironment env = new VREnvironment(settings);
  29. env.initialize();
  30. // Checking if the VR environment is well initialized
  31. // (access to the underlying VR system is effective, VR devices are detected).
  32. if (env.isInitialized()){
  33. VRAppState vrAppState = new VRAppState(settings, env);
  34. vrAppState.setMirrorWindowSize(1024, 800);
  35. Main app = new Main(vrAppState);
  36. app.setLostFocusBehavior(LostFocusBehavior.Disabled);
  37. app.setSettings(settings);
  38. app.setShowSettings(false);
  39. app.start();
  40. }
  41. }
  42. public Main(AppState... appStates) {
  43. super(appStates);
  44. }
  45. @Override
  46. public void simpleInitApp() {
  47. Box b = new Box(1, 1, 1);
  48. Geometry geom = new Geometry("Box", b);
  49. Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  50. mat.setColor("Color", ColorRGBA.Blue);
  51. geom.setMaterial(mat);
  52. rootNode.attachChild(geom);
  53. }
  54. @Override
  55. public void simpleUpdate(float tpf) {
  56. //TODO: add update code
  57. }
  58. @Override
  59. public void simpleRender(RenderManager rm) {
  60. //TODO: add render code
  61. }
  62. }
  63. ----
  64. Project source: https://github.com/neph1/VRSampleApplication
  65. == Google Cardboard VR SDK 1.0 integration
  66. gvr-android-jme (https://github.com/nordfalk/gvr-android-jme)
  67. == Legacy
  68. The following projects are not up to date, but may provide functionality not found in the other packages.
  69. Google Cardboard up to version 0.6: https://github.com/neph1/jme-cardboard