How-to-create-VR-content.html 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. <h1>[name]</h1>
  11. <p>
  12. This guide provides a brief overview of the basic components of a web-based VR application
  13. made with three.js.
  14. </p>
  15. <h2>Workflow</h2>
  16. <p>
  17. First, you have to include [link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/webxr/VRButton.js VRButton.js]
  18. into your project.
  19. </p>
  20. <code>
  21. import { VRButton } from 'three/addons/webxr/VRButton.js';
  22. </code>
  23. <p>
  24. *VRButton.createButton()* does two important things: It creates a button which indicates
  25. VR compatibility. Besides, it initiates a VR session if the user activates the button. The only thing you have
  26. to do is to add the following line of code to your app.
  27. </p>
  28. <code>
  29. document.body.appendChild( VRButton.createButton( renderer ) );
  30. </code>
  31. <p>
  32. Next, you have to tell your instance of `WebGLRenderer` to enable XR rendering.
  33. </p>
  34. <code>
  35. renderer.xr.enabled = true;
  36. </code>
  37. <p>
  38. Finally, you have to adjust your animation loop since we can't use our well known
  39. *window.requestAnimationFrame()* function. For VR projects we use [page:WebGLRenderer.setAnimationLoop setAnimationLoop].
  40. The minimal code looks like this:
  41. </p>
  42. <code>
  43. renderer.setAnimationLoop( function () {
  44. renderer.render( scene, camera );
  45. } );
  46. </code>
  47. <h2>Next Steps</h2>
  48. <p>
  49. Have a look at one of the official WebVR examples to see this workflow in action.<br /><br />
  50. [example:webxr_vr_ballshooter WebXR / VR / ballshooter]<br />
  51. [example:webxr_vr_cubes WebXR / VR / cubes]<br />
  52. [example:webxr_vr_dragging WebXR / VR / dragging]<br />
  53. [example:webxr_vr_paint WebXR / VR / paint]<br />
  54. [example:webxr_vr_panorama_depth WebXR / VR / panorama_depth]<br />
  55. [example:webxr_vr_panorama WebXR / VR / panorama]<br />
  56. [example:webxr_vr_rollercoaster WebXR / VR / rollercoaster]<br />
  57. [example:webxr_vr_sandbox WebXR / VR / sandbox]<br />
  58. [example:webxr_vr_sculpt WebXR / VR / sculpt]<br />
  59. [example:webxr_vr_video WebXR / VR / video]
  60. </p>
  61. </body>
  62. </html>