XRManager.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>XRManager - Three.js Docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <script src="../scripts/highlight.min.js"></script>
  8. <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
  9. <link type="text/css" rel="stylesheet" href="../styles/page.css">
  10. </head>
  11. <body>
  12. <p class="inheritance" translate="no"><a href="EventDispatcher.html">EventDispatcher</a> → </p>
  13. <h1 translate="no">XRManager</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>The XR manager is built on top of the WebXR Device API to
  17. manage XR sessions with <code>WebGPURenderer</code>.</p>
  18. <p>XR is currently only supported with a WebGL 2 backend.</p></div>
  19. </header>
  20. <article>
  21. <div class="container-overview">
  22. <h2>Constructor</h2>
  23. <h3 class="name name-method" id="XRManager" translate="no">new <a href="#XRManager">XRManager</a><span class="signature">( renderer : <span class="param-type">Renderer</span>, multiview : <span class="param-type">boolean</span> )</span> </h3>
  24. <div class="method">
  25. <div class="description">
  26. <p>Constructs a new XR manager.</p>
  27. </div>
  28. <table class="params">
  29. <tbody>
  30. <tr>
  31. <td class="name"><code>renderer</code></td>
  32. <td class="description last"><p>The renderer.</p></td>
  33. </tr>
  34. <tr>
  35. <td class="name"><code>multiview</code></td>
  36. <td class="description last"><p>Enables multiview if the device supports it.<br/>Default is <code>false</code>.</p></td>
  37. </tr>
  38. </tbody>
  39. </table>
  40. </div>
  41. </div>
  42. <h2 class="subsection-title">Properties</h2>
  43. <div class="member">
  44. <h3 class="name" id="_sessionUsesLayers" translate="no">.<a href="#_sessionUsesLayers">_sessionUsesLayers</a><span class="type-signature"> : boolean</span> </h3>
  45. <div class="description">
  46. <p>Whether the XR session uses layers.<br/>Default is <code>false</code>.</p>
  47. </div>
  48. </div>
  49. <div class="member">
  50. <h3 class="name" id="cameraAutoUpdate" translate="no">.<a href="#cameraAutoUpdate">cameraAutoUpdate</a><span class="type-signature"> : boolean</span> </h3>
  51. <div class="description">
  52. <p>Whether the XR camera should automatically be updated or not.<br/>Default is <code>true</code>.</p>
  53. </div>
  54. </div>
  55. <div class="member">
  56. <h3 class="name" id="enabled" translate="no">.<a href="#enabled">enabled</a><span class="type-signature"> : boolean</span> </h3>
  57. <div class="description">
  58. <p>This flag globally enables XR rendering.<br/>Default is <code>false</code>.</p>
  59. </div>
  60. </div>
  61. <div class="member">
  62. <h3 class="name" id="isPresenting" translate="no">.<a href="#isPresenting">isPresenting</a><span class="type-signature"> : boolean</span> <span class="type-signature">(readonly) </span></h3>
  63. <div class="description">
  64. <p>Whether the XR device is currently presenting or not.<br/>Default is <code>false</code>.</p>
  65. </div>
  66. </div>
  67. <h2 class="subsection-title">Methods</h2>
  68. <h3 class="name name-method" id="createCylinderLayer" translate="no">.<a href="#createCylinderLayer">createCylinderLayer</a><span class="signature">( radius : <span class="param-type">number</span>, centralAngle : <span class="param-type">number</span>, aspectratio : <span class="param-type">number</span>, translation : <span class="param-type">Vector3</span>, quaternion : <span class="param-type">Quaternion</span>, pixelwidth : <span class="param-type">number</span>, pixelheight : <span class="param-type">number</span>, rendercall : <span class="param-type">function</span>, attributes : <span class="param-type">Object</span> )</span><span class="type-signature"> : <a href="Mesh.html">Mesh</a></span> </h3>
  69. <div class="method">
  70. <div class="description">
  71. <p>This method can be used in XR applications to create a cylindrical layer that presents a separate
  72. rendered scene.</p>
  73. </div>
  74. <table class="params">
  75. <tbody>
  76. <tr>
  77. <td class="name"><code>radius</code></td>
  78. <td class="description last"><p>The radius of the cylinder in world units.</p></td>
  79. </tr>
  80. <tr>
  81. <td class="name"><code>centralAngle</code></td>
  82. <td class="description last"><p>The central angle of the cylinder in radians.</p></td>
  83. </tr>
  84. <tr>
  85. <td class="name"><code>aspectratio</code></td>
  86. <td class="description last"><p>The aspect ratio.</p></td>
  87. </tr>
  88. <tr>
  89. <td class="name"><code>translation</code></td>
  90. <td class="description last"><p>The position/translation of the layer plane in world units.</p></td>
  91. </tr>
  92. <tr>
  93. <td class="name"><code>quaternion</code></td>
  94. <td class="description last"><p>The orientation of the layer plane expressed as a quaternion.</p></td>
  95. </tr>
  96. <tr>
  97. <td class="name"><code>pixelwidth</code></td>
  98. <td class="description last"><p>The width of the layer's render target in pixels.</p></td>
  99. </tr>
  100. <tr>
  101. <td class="name"><code>pixelheight</code></td>
  102. <td class="description last"><p>The height of the layer's render target in pixels.</p></td>
  103. </tr>
  104. <tr>
  105. <td class="name"><code>rendercall</code></td>
  106. <td class="description last"><p>A callback function that renders the layer. Similar to code in
  107. the default animation loop, this method can be used to update/transform 3D object in the layer's scene.</p></td>
  108. </tr>
  109. <tr>
  110. <td class="name"><code>attributes</code></td>
  111. <td class="description last"><p>Allows to configure the layer's render target.<br/>Default is <code>{}</code>.</p></td>
  112. </tr>
  113. </tbody>
  114. </table>
  115. <dl class="details">
  116. <dt class="tag-returns"><strong>Returns:</strong> A mesh representing the cylindrical XR layer. This mesh should be added to the XR scene.</dt>
  117. </dl>
  118. </div>
  119. <h3 class="name name-method" id="createQuadLayer" translate="no">.<a href="#createQuadLayer">createQuadLayer</a><span class="signature">( width : <span class="param-type">number</span>, height : <span class="param-type">number</span>, translation : <span class="param-type">Vector3</span>, quaternion : <span class="param-type">Quaternion</span>, pixelwidth : <span class="param-type">number</span>, pixelheight : <span class="param-type">number</span>, rendercall : <span class="param-type">function</span>, attributes : <span class="param-type">Object</span> )</span><span class="type-signature"> : <a href="Mesh.html">Mesh</a></span> </h3>
  120. <div class="method">
  121. <div class="description">
  122. <p>This method can be used in XR applications to create a quadratic layer that presents a separate
  123. rendered scene.</p>
  124. </div>
  125. <table class="params">
  126. <tbody>
  127. <tr>
  128. <td class="name"><code>width</code></td>
  129. <td class="description last"><p>The width of the layer plane in world units.</p></td>
  130. </tr>
  131. <tr>
  132. <td class="name"><code>height</code></td>
  133. <td class="description last"><p>The height of the layer plane in world units.</p></td>
  134. </tr>
  135. <tr>
  136. <td class="name"><code>translation</code></td>
  137. <td class="description last"><p>The position/translation of the layer plane in world units.</p></td>
  138. </tr>
  139. <tr>
  140. <td class="name"><code>quaternion</code></td>
  141. <td class="description last"><p>The orientation of the layer plane expressed as a quaternion.</p></td>
  142. </tr>
  143. <tr>
  144. <td class="name"><code>pixelwidth</code></td>
  145. <td class="description last"><p>The width of the layer's render target in pixels.</p></td>
  146. </tr>
  147. <tr>
  148. <td class="name"><code>pixelheight</code></td>
  149. <td class="description last"><p>The height of the layer's render target in pixels.</p></td>
  150. </tr>
  151. <tr>
  152. <td class="name"><code>rendercall</code></td>
  153. <td class="description last"><p>A callback function that renders the layer. Similar to code in
  154. the default animation loop, this method can be used to update/transform 3D object in the layer's scene.</p></td>
  155. </tr>
  156. <tr>
  157. <td class="name"><code>attributes</code></td>
  158. <td class="description last"><p>Allows to configure the layer's render target.<br/>Default is <code>{}</code>.</p></td>
  159. </tr>
  160. </tbody>
  161. </table>
  162. <dl class="details">
  163. <dt class="tag-returns"><strong>Returns:</strong> A mesh representing the quadratic XR layer. This mesh should be added to the XR scene.</dt>
  164. </dl>
  165. </div>
  166. <h3 class="name name-method" id="getBinding" translate="no">.<a href="#getBinding">getBinding</a><span class="signature">()</span><span class="type-signature"> : XRWebGLBinding</span> </h3>
  167. <div class="method">
  168. <div class="description">
  169. <p>Returns the current XR binding.</p>
  170. <p>Creates a new binding if needed and the browser is
  171. capable of doing so.</p>
  172. </div>
  173. <dl class="details">
  174. <dt class="tag-returns"><strong>Returns:</strong> The XR binding. Returns <code>null</code> if one cannot be created.</dt>
  175. </dl>
  176. </div>
  177. <h3 class="name name-method" id="getCamera" translate="no">.<a href="#getCamera">getCamera</a><span class="signature">()</span><span class="type-signature"> : <a href="ArrayCamera.html">ArrayCamera</a></span> </h3>
  178. <div class="method">
  179. <div class="description">
  180. <p>Returns the XR camera.</p>
  181. </div>
  182. <dl class="details">
  183. <dt class="tag-returns"><strong>Returns:</strong> The XR camera.</dt>
  184. </dl>
  185. </div>
  186. <h3 class="name name-method" id="getController" translate="no">.<a href="#getController">getController</a><span class="signature">( index : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Group.html">Group</a></span> </h3>
  187. <div class="method">
  188. <div class="description">
  189. <p>Returns an instance of <code>THREE.Group</code> that represents the transformation
  190. of a XR controller in target ray space. The requested controller is defined
  191. by the given index.</p>
  192. </div>
  193. <table class="params">
  194. <tbody>
  195. <tr>
  196. <td class="name"><code>index</code></td>
  197. <td class="description last"><p>The index of the XR controller.</p></td>
  198. </tr>
  199. </tbody>
  200. </table>
  201. <dl class="details">
  202. <dt class="tag-returns"><strong>Returns:</strong> A group that represents the controller's transformation.</dt>
  203. </dl>
  204. </div>
  205. <h3 class="name name-method" id="getControllerGrip" translate="no">.<a href="#getControllerGrip">getControllerGrip</a><span class="signature">( index : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Group.html">Group</a></span> </h3>
  206. <div class="method">
  207. <div class="description">
  208. <p>Returns an instance of <code>THREE.Group</code> that represents the transformation
  209. of a XR controller in grip space. The requested controller is defined
  210. by the given index.</p>
  211. </div>
  212. <table class="params">
  213. <tbody>
  214. <tr>
  215. <td class="name"><code>index</code></td>
  216. <td class="description last"><p>The index of the XR controller.</p></td>
  217. </tr>
  218. </tbody>
  219. </table>
  220. <dl class="details">
  221. <dt class="tag-returns"><strong>Returns:</strong> A group that represents the controller's transformation.</dt>
  222. </dl>
  223. </div>
  224. <h3 class="name name-method" id="getEnvironmentBlendMode" translate="no">.<a href="#getEnvironmentBlendMode">getEnvironmentBlendMode</a><span class="signature">()</span><span class="type-signature"> : 'opaque' | 'additive' | 'alpha-blend' | undefined</span> </h3>
  225. <div class="method">
  226. <div class="description">
  227. <p>Returns the environment blend mode from the current XR session.</p>
  228. </div>
  229. <dl class="details">
  230. <dt class="tag-returns"><strong>Returns:</strong> The environment blend mode. Returns <code>undefined</code> when used outside of a XR session.</dt>
  231. </dl>
  232. </div>
  233. <h3 class="name name-method" id="getFoveation" translate="no">.<a href="#getFoveation">getFoveation</a><span class="signature">()</span><span class="type-signature"> : number | undefined</span> </h3>
  234. <div class="method">
  235. <div class="description">
  236. <p>Returns the foveation value.</p>
  237. </div>
  238. <dl class="details">
  239. <dt class="tag-returns"><strong>Returns:</strong> The foveation value. Returns <code>undefined</code> if no base or projection layer is defined.</dt>
  240. </dl>
  241. </div>
  242. <h3 class="name name-method" id="getFrame" translate="no">.<a href="#getFrame">getFrame</a><span class="signature">()</span><span class="type-signature"> : XRFrame</span> </h3>
  243. <div class="method">
  244. <div class="description">
  245. <p>Returns the current XR frame.</p>
  246. </div>
  247. <dl class="details">
  248. <dt class="tag-returns"><strong>Returns:</strong> The XR frame. Returns <code>null</code> when used outside a XR session.</dt>
  249. </dl>
  250. </div>
  251. <h3 class="name name-method" id="getFramebufferScaleFactor" translate="no">.<a href="#getFramebufferScaleFactor">getFramebufferScaleFactor</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  252. <div class="method">
  253. <div class="description">
  254. <p>Returns the framebuffer scale factor.</p>
  255. </div>
  256. <dl class="details">
  257. <dt class="tag-returns"><strong>Returns:</strong> The framebuffer scale factor.</dt>
  258. </dl>
  259. </div>
  260. <h3 class="name name-method" id="getHand" translate="no">.<a href="#getHand">getHand</a><span class="signature">( index : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Group.html">Group</a></span> </h3>
  261. <div class="method">
  262. <div class="description">
  263. <p>Returns an instance of <code>THREE.Group</code> that represents the transformation
  264. of a XR controller in hand space. The requested controller is defined
  265. by the given index.</p>
  266. </div>
  267. <table class="params">
  268. <tbody>
  269. <tr>
  270. <td class="name"><code>index</code></td>
  271. <td class="description last"><p>The index of the XR controller.</p></td>
  272. </tr>
  273. </tbody>
  274. </table>
  275. <dl class="details">
  276. <dt class="tag-returns"><strong>Returns:</strong> A group that represents the controller's transformation.</dt>
  277. </dl>
  278. </div>
  279. <h3 class="name name-method" id="getReferenceSpace" translate="no">.<a href="#getReferenceSpace">getReferenceSpace</a><span class="signature">()</span><span class="type-signature"> : XRReferenceSpace</span> </h3>
  280. <div class="method">
  281. <div class="description">
  282. <p>Returns the XR reference space.</p>
  283. </div>
  284. <dl class="details">
  285. <dt class="tag-returns"><strong>Returns:</strong> The XR reference space.</dt>
  286. </dl>
  287. </div>
  288. <h3 class="name name-method" id="getReferenceSpaceType" translate="no">.<a href="#getReferenceSpaceType">getReferenceSpaceType</a><span class="signature">()</span><span class="type-signature"> : XRReferenceSpaceType</span> </h3>
  289. <div class="method">
  290. <div class="description">
  291. <p>Returns the reference space type.</p>
  292. </div>
  293. <dl class="details">
  294. <dt class="tag-returns"><strong>Returns:</strong> The reference space type.</dt>
  295. </dl>
  296. </div>
  297. <h3 class="name name-method" id="getSession" translate="no">.<a href="#getSession">getSession</a><span class="signature">()</span><span class="type-signature"> : XRSession</span> </h3>
  298. <div class="method">
  299. <div class="description">
  300. <p>Returns the current XR session.</p>
  301. </div>
  302. <dl class="details">
  303. <dt class="tag-returns"><strong>Returns:</strong> The XR session. Returns <code>null</code> when used outside a XR session.</dt>
  304. </dl>
  305. </div>
  306. <h3 class="name name-method" id="renderLayers" translate="no">.<a href="#renderLayers">renderLayers</a><span class="signature">()</span> </h3>
  307. <div class="method">
  308. <div class="description">
  309. <p>Renders the XR layers that have been previously added to the scene.</p>
  310. <p>This method is usually called in your animation loop before rendering
  311. the actual scene via <code>renderer.render( scene, camera );</code>.</p>
  312. </div>
  313. </div>
  314. <h3 class="name name-method" id="setFoveation" translate="no">.<a href="#setFoveation">setFoveation</a><span class="signature">( foveation : <span class="param-type">number</span> )</span> </h3>
  315. <div class="method">
  316. <div class="description">
  317. <p>Sets the foveation value.</p>
  318. </div>
  319. <table class="params">
  320. <tbody>
  321. <tr>
  322. <td class="name"><code>foveation</code></td>
  323. <td class="description last"><p>A number in the range <code>[0,1]</code> where <code>0</code> means no foveation (full resolution)
  324. and <code>1</code> means maximum foveation (the edges render at lower resolution).</p></td>
  325. </tr>
  326. </tbody>
  327. </table>
  328. </div>
  329. <h3 class="name name-method" id="setFramebufferScaleFactor" translate="no">.<a href="#setFramebufferScaleFactor">setFramebufferScaleFactor</a><span class="signature">( factor : <span class="param-type">number</span> )</span> </h3>
  330. <div class="method">
  331. <div class="description">
  332. <p>Sets the framebuffer scale factor.</p>
  333. <p>This method can not be used during a XR session.</p>
  334. </div>
  335. <table class="params">
  336. <tbody>
  337. <tr>
  338. <td class="name"><code>factor</code></td>
  339. <td class="description last"><p>The framebuffer scale factor.</p></td>
  340. </tr>
  341. </tbody>
  342. </table>
  343. </div>
  344. <h3 class="name name-method" id="setReferenceSpace" translate="no">.<a href="#setReferenceSpace">setReferenceSpace</a><span class="signature">( space : <span class="param-type">XRReferenceSpace</span> )</span> </h3>
  345. <div class="method">
  346. <div class="description">
  347. <p>Sets a custom XR reference space.</p>
  348. </div>
  349. <table class="params">
  350. <tbody>
  351. <tr>
  352. <td class="name"><code>space</code></td>
  353. <td class="description last"><p>The XR reference space.</p></td>
  354. </tr>
  355. </tbody>
  356. </table>
  357. </div>
  358. <h3 class="name name-method" id="setReferenceSpaceType" translate="no">.<a href="#setReferenceSpaceType">setReferenceSpaceType</a><span class="signature">( type : <span class="param-type">XRReferenceSpaceType</span> )</span> </h3>
  359. <div class="method">
  360. <div class="description">
  361. <p>Sets the reference space type.</p>
  362. <p>This method can not be used during a XR session.</p>
  363. </div>
  364. <table class="params">
  365. <tbody>
  366. <tr>
  367. <td class="name"><code>type</code></td>
  368. <td class="description last"><p>The reference space type.</p></td>
  369. </tr>
  370. </tbody>
  371. </table>
  372. </div>
  373. <h3 class="name name-method" id="setSession" translate="no">.<a href="#setSession">setSession</a><span class="signature">( session : <span class="param-type">XRSession</span> )</span><span class="type-signature"> : Promise</span> <span class="type-signature">(async) </span></h3>
  374. <div class="method">
  375. <div class="description">
  376. <p>After a XR session has been requested usually with one of the <code>*Button</code> modules, it
  377. is injected into the renderer with this method. This method triggers the start of
  378. the actual XR rendering.</p>
  379. </div>
  380. <table class="params">
  381. <tbody>
  382. <tr>
  383. <td class="name"><code>session</code></td>
  384. <td class="description last"><p>The XR session to set.</p></td>
  385. </tr>
  386. </tbody>
  387. </table>
  388. <dl class="details">
  389. <dt class="tag-returns"><strong>Returns:</strong> A Promise that resolves when the session has been set.</dt>
  390. </dl>
  391. </div>
  392. <h3 class="name name-method" id="updateCamera" translate="no">.<a href="#updateCamera">updateCamera</a><span class="signature">( camera : <span class="param-type">PerspectiveCamera</span> )</span> </h3>
  393. <div class="method">
  394. <div class="description">
  395. <p>This method is called by the renderer per frame and updates the XR camera
  396. and it sub cameras based on the given camera. The given camera is the &quot;user&quot;
  397. camera created on application level and used for non-XR rendering.</p>
  398. </div>
  399. <table class="params">
  400. <tbody>
  401. <tr>
  402. <td class="name"><code>camera</code></td>
  403. <td class="description last"><p>The camera.</p></td>
  404. </tr>
  405. </tbody>
  406. </table>
  407. </div>
  408. <h3 class="name name-method" id="useMultiview" translate="no">.<a href="#useMultiview">useMultiview</a><span class="signature">()</span><span class="type-signature"> : boolean</span> </h3>
  409. <div class="method">
  410. <div class="description">
  411. <p>Returns <code>true</code> if the engine renders to a multiview target.</p>
  412. </div>
  413. <dl class="details">
  414. <dt class="tag-returns"><strong>Returns:</strong> Whether the engine renders to a multiview render target or not.</dt>
  415. </dl>
  416. </div>
  417. <h2 class="subsection-title">Source</h2>
  418. <p>
  419. <a href="https://github.com/mrdoob/three.js/blob/master/src/renderers/common/XRManager.js" target="_blank" rel="noopener" translate="no">src/renderers/common/XRManager.js</a>
  420. </p>
  421. </article>
  422. </section>
  423. <script src="../scripts/linenumber.js"></script>
  424. <script src="../scripts/page.js"></script>
  425. </body>
  426. </html>
粤ICP备19079148号