how-to-create-vr-content.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <!DOCTYPE html><html lang="en"><head>
  2. <meta charset="utf-8">
  3. <title>How to create VR content</title>
  4. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  5. <meta name="twitter:card" content="summary_large_image">
  6. <meta name="twitter:site" content="@threejs">
  7. <meta name="twitter:title" content="Three.js – How to create VR content">
  8. <meta property="og:image" content="https://threejs.org/files/share.png">
  9. <link rel="shortcut icon" href="../../files/favicon_white.ico" media="(prefers-color-scheme: dark)">
  10. <link rel="shortcut icon" href="../../files/favicon.ico" media="(prefers-color-scheme: light)">
  11. <link rel="stylesheet" href="../resources/lesson.css">
  12. <link rel="stylesheet" href="../resources/lang.css">
  13. <script type="importmap">
  14. {
  15. "imports": {
  16. "three": "../../build/three.module.js"
  17. }
  18. }
  19. </script>
  20. </head>
  21. <body>
  22. <div class="container">
  23. <div class="lesson-title">
  24. <h1>How to create VR content</h1>
  25. </div>
  26. <div class="lesson">
  27. <div class="lesson-main">
  28. <p>
  29. This guide provides a brief overview of the basic components of a web-based VR application
  30. made with three.js.
  31. </p>
  32. <h2>Workflow</h2>
  33. <p>
  34. First, you have to include [link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/webxr/VRButton.js VRButton.js]
  35. into your project.
  36. </p>
  37. <pre class="prettyprint notranslate lang-js" translate="no">
  38. import { VRButton } from 'three/addons/webxr/VRButton.js';
  39. </pre>
  40. <p>
  41. *VRButton.createButton()* does two important things: It creates a button which indicates
  42. VR compatibility. Besides, it initiates a VR session if the user activates the button. The only thing you have
  43. to do is to add the following line of code to your app.
  44. </p>
  45. <pre class="prettyprint notranslate lang-js" translate="no">
  46. document.body.appendChild( VRButton.createButton( renderer ) );
  47. </pre>
  48. <p>
  49. Next, you have to tell your instance of `WebGLRenderer` to enable XR rendering.
  50. </p>
  51. <pre class="prettyprint notranslate lang-js" translate="no">
  52. renderer.xr.enabled = true;
  53. </pre>
  54. <p>
  55. Finally, you have to adjust your animation loop since we can't use our well known
  56. *window.requestAnimationFrame()* function. For VR projects we use `renderer.setAnimationLoop()`.
  57. The minimal code looks like this:
  58. </p>
  59. <pre class="prettyprint notranslate lang-js" translate="no">
  60. renderer.setAnimationLoop( function () {
  61. renderer.render( scene, camera );
  62. } );
  63. </pre>
  64. <h2>Next Steps</h2>
  65. <p>
  66. Have a look at one of the official WebVR examples to see this workflow in action.<br /><br />
  67. [example:webxr_xr_ballshooter WebXR / XR / ballshooter]<br />
  68. [example:webxr_xr_cubes WebXR / XR / cubes]<br />
  69. [example:webxr_xr_dragging WebXR / XR / dragging]<br />
  70. [example:webxr_xr_paint WebXR / XR / paint]<br />
  71. [example:webxr_xr_sculpt WebXR / XR / sculpt]<br />
  72. [example:webxr_vr_panorama_depth WebXR / VR / panorama_depth]<br />
  73. [example:webxr_vr_panorama WebXR / VR / panorama]<br />
  74. [example:webxr_vr_rollercoaster WebXR / VR / rollercoaster]<br />
  75. [example:webxr_vr_sandbox WebXR / VR / sandbox]<br />
  76. [example:webxr_vr_video WebXR / VR / video]
  77. </p>
  78. </div>
  79. </div>
  80. </div>
  81. <script src="../resources/prettify.js"></script>
  82. <script src="../resources/lesson.js"></script>
  83. </body></html>
粤ICP备19079148号