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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="utf-8">
  5. <base href="../../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. <h1>如何创建VR内容([name])</h1>
  12. <p>
  13. 本指南简要介绍了使用three.js来制作的基于Web的VR应用程序的基本组件。
  14. </p>
  15. <h2>工作流程</h2>
  16. <p>
  17. 首先,你需要将[link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/webxr/VRButton.js VRButton.js]
  18. 包含到你的项目中。
  19. </p>
  20. <code>
  21. import { VRButton } from 'three/examples/jsm/webxr/VRButton.js';
  22. </code>
  23. <p>*VRButton.createButton()*做了两件重要的事情:首先,它创建了一个按钮,指示了VR的兼容性;
  24. 此外,若用户激活了这个按钮,则它将开启一个VR会话。
  25. 你所要做的唯一一件事情,便是把下面的这一行代码加入到你的应用程序里。
  26. </p>
  27. <code>
  28. document.body.appendChild( VRButton.createButton( renderer ) );
  29. </code>
  30. <p>
  31. 接下来,你需要告诉你的*WebGLRenderer*实例来启用XR渲染。
  32. </p>
  33. <code>
  34. renderer.xr.enabled = true;
  35. </code>
  36. <p>
  37. 最后,你需要调整你的动画循环,因为在这里我们不能使用我们所熟知的
  38. *window.requestAnimationFrame()*函数来更新场景。对于VR项目来说,我们使用的是[page:WebGLRenderer.setAnimationLoop setAnimationLoop]。
  39. 简短的示例代码如下:
  40. </p>
  41. <code>
  42. renderer.setAnimationLoop( function () {
  43. renderer.render( scene, camera );
  44. } );
  45. </code>
  46. <h2>接下来的步骤</h2>
  47. <p>
  48. 请查看官方示例中与WebVR相关的示例,了解这一工作流程的实际使用、运行情况。
  49. <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_lorenzattractor WebXR / VR / lorenzattractor]<br />
  54. [example:webxr_vr_paint WebXR / VR / paint]<br />
  55. [example:webxr_vr_panorama_depth WebXR / VR / panorama_depth]<br />
  56. [example:webxr_vr_panorama WebXR / VR / panorama]<br />
  57. [example:webxr_vr_rollercoaster WebXR / VR / rollercoaster]<br />
  58. [example:webxr_vr_sandbox WebXR / VR / sandbox]<br />
  59. [example:webxr_vr_sculpt WebXR / VR / sculpt]<br />
  60. [example:webxr_vr_video WebXR / VR / video]
  61. </p>
  62. </body>
  63. </html>