virtualreality.adoc 2.9 KB

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