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

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