XRManager.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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"><a href="Renderer.html">Renderer</a></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">
  32. <strong>renderer</strong>
  33. </td>
  34. <td class="description last">
  35. <p>The renderer.</p>
  36. </td>
  37. </tr>
  38. <tr>
  39. <td class="name">
  40. <strong>multiview</strong>
  41. </td>
  42. <td class="description last">
  43. <p>Enables multiview if the device supports it.</p>
  44. <p>Default is <code>false</code>.</p>
  45. </td>
  46. </tr>
  47. </tbody>
  48. </table>
  49. </div>
  50. </div>
  51. <h2 class="subsection-title">Properties</h2>
  52. <div class="member">
  53. <h3 class="name" id="cameraAutoUpdate" translate="no">.<a href="#cameraAutoUpdate">cameraAutoUpdate</a><span class="type-signature"> : boolean</span> </h3>
  54. <div class="description">
  55. <p>Whether the XR camera should automatically be updated or not.</p>
  56. <p>Default is <code>true</code>.</p>
  57. </div>
  58. </div>
  59. <div class="member">
  60. <h3 class="name" id="enabled" translate="no">.<a href="#enabled">enabled</a><span class="type-signature"> : boolean</span> </h3>
  61. <div class="description">
  62. <p>This flag globally enables XR rendering.</p>
  63. <p>Default is <code>false</code>.</p>
  64. </div>
  65. </div>
  66. <div class="member">
  67. <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>
  68. <div class="description">
  69. <p>Whether the XR device is currently presenting or not.</p>
  70. <p>Default is <code>false</code>.</p>
  71. </div>
  72. </div>
  73. <h2 class="subsection-title">Methods</h2>
  74. <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"><a href="Vector3.html">Vector3</a></span>, quaternion : <span class="param-type"><a href="Quaternion.html">Quaternion</a></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>
  75. <div class="method">
  76. <div class="description">
  77. <p>This method can be used in XR applications to create a cylindrical layer that presents a separate
  78. rendered scene.</p>
  79. </div>
  80. <table class="params">
  81. <tbody>
  82. <tr>
  83. <td class="name">
  84. <strong>radius</strong>
  85. </td>
  86. <td class="description last">
  87. <p>The radius of the cylinder in world units.</p>
  88. </td>
  89. </tr>
  90. <tr>
  91. <td class="name">
  92. <strong>centralAngle</strong>
  93. </td>
  94. <td class="description last">
  95. <p>The central angle of the cylinder in radians.</p>
  96. </td>
  97. </tr>
  98. <tr>
  99. <td class="name">
  100. <strong>aspectratio</strong>
  101. </td>
  102. <td class="description last">
  103. <p>The aspect ratio.</p>
  104. </td>
  105. </tr>
  106. <tr>
  107. <td class="name">
  108. <strong>translation</strong>
  109. </td>
  110. <td class="description last">
  111. <p>The position/translation of the layer plane in world units.</p>
  112. </td>
  113. </tr>
  114. <tr>
  115. <td class="name">
  116. <strong>quaternion</strong>
  117. </td>
  118. <td class="description last">
  119. <p>The orientation of the layer plane expressed as a quaternion.</p>
  120. </td>
  121. </tr>
  122. <tr>
  123. <td class="name">
  124. <strong>pixelwidth</strong>
  125. </td>
  126. <td class="description last">
  127. <p>The width of the layer's render target in pixels.</p>
  128. </td>
  129. </tr>
  130. <tr>
  131. <td class="name">
  132. <strong>pixelheight</strong>
  133. </td>
  134. <td class="description last">
  135. <p>The height of the layer's render target in pixels.</p>
  136. </td>
  137. </tr>
  138. <tr>
  139. <td class="name">
  140. <strong>rendercall</strong>
  141. </td>
  142. <td class="description last">
  143. <p>A callback function that renders the layer. Similar to code in
  144. the default animation loop, this method can be used to update/transform 3D object in the layer's scene.</p>
  145. </td>
  146. </tr>
  147. <tr>
  148. <td class="name">
  149. <strong>attributes</strong>
  150. </td>
  151. <td class="description last">
  152. <p>Allows to configure the layer's render target.</p>
  153. <p>Default is <code>{}</code>.</p>
  154. </td>
  155. </tr>
  156. </tbody>
  157. </table>
  158. <dl class="details">
  159. <dt class="tag-returns"><strong>Returns:</strong> A mesh representing the cylindrical XR layer. This mesh should be added to the XR scene.</dt>
  160. </dl>
  161. </div>
  162. <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"><a href="Vector3.html">Vector3</a></span>, quaternion : <span class="param-type"><a href="Quaternion.html">Quaternion</a></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>
  163. <div class="method">
  164. <div class="description">
  165. <p>This method can be used in XR applications to create a quadratic layer that presents a separate
  166. rendered scene.</p>
  167. </div>
  168. <table class="params">
  169. <tbody>
  170. <tr>
  171. <td class="name">
  172. <strong>width</strong>
  173. </td>
  174. <td class="description last">
  175. <p>The width of the layer plane in world units.</p>
  176. </td>
  177. </tr>
  178. <tr>
  179. <td class="name">
  180. <strong>height</strong>
  181. </td>
  182. <td class="description last">
  183. <p>The height of the layer plane in world units.</p>
  184. </td>
  185. </tr>
  186. <tr>
  187. <td class="name">
  188. <strong>translation</strong>
  189. </td>
  190. <td class="description last">
  191. <p>The position/translation of the layer plane in world units.</p>
  192. </td>
  193. </tr>
  194. <tr>
  195. <td class="name">
  196. <strong>quaternion</strong>
  197. </td>
  198. <td class="description last">
  199. <p>The orientation of the layer plane expressed as a quaternion.</p>
  200. </td>
  201. </tr>
  202. <tr>
  203. <td class="name">
  204. <strong>pixelwidth</strong>
  205. </td>
  206. <td class="description last">
  207. <p>The width of the layer's render target in pixels.</p>
  208. </td>
  209. </tr>
  210. <tr>
  211. <td class="name">
  212. <strong>pixelheight</strong>
  213. </td>
  214. <td class="description last">
  215. <p>The height of the layer's render target in pixels.</p>
  216. </td>
  217. </tr>
  218. <tr>
  219. <td class="name">
  220. <strong>rendercall</strong>
  221. </td>
  222. <td class="description last">
  223. <p>A callback function that renders the layer. Similar to code in
  224. the default animation loop, this method can be used to update/transform 3D object in the layer's scene.</p>
  225. </td>
  226. </tr>
  227. <tr>
  228. <td class="name">
  229. <strong>attributes</strong>
  230. </td>
  231. <td class="description last">
  232. <p>Allows to configure the layer's render target.</p>
  233. <p>Default is <code>{}</code>.</p>
  234. </td>
  235. </tr>
  236. </tbody>
  237. </table>
  238. <dl class="details">
  239. <dt class="tag-returns"><strong>Returns:</strong> A mesh representing the quadratic XR layer. This mesh should be added to the XR scene.</dt>
  240. </dl>
  241. </div>
  242. <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>
  243. <div class="method">
  244. <div class="description">
  245. <p>Returns the current XR binding.</p>
  246. <p>Creates a new binding if needed and the browser is
  247. capable of doing so.</p>
  248. </div>
  249. <dl class="details">
  250. <dt class="tag-returns"><strong>Returns:</strong> The XR binding. Returns <code>null</code> if one cannot be created.</dt>
  251. </dl>
  252. </div>
  253. <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>
  254. <div class="method">
  255. <div class="description">
  256. <p>Returns the XR camera.</p>
  257. </div>
  258. <dl class="details">
  259. <dt class="tag-returns"><strong>Returns:</strong> The XR camera.</dt>
  260. </dl>
  261. </div>
  262. <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>
  263. <div class="method">
  264. <div class="description">
  265. <p>Returns an instance of <code>THREE.Group</code> that represents the transformation
  266. of a XR controller in target ray space. The requested controller is defined
  267. by the given index.</p>
  268. </div>
  269. <table class="params">
  270. <tbody>
  271. <tr>
  272. <td class="name">
  273. <strong>index</strong>
  274. </td>
  275. <td class="description last">
  276. <p>The index of the XR controller.</p>
  277. </td>
  278. </tr>
  279. </tbody>
  280. </table>
  281. <dl class="details">
  282. <dt class="tag-returns"><strong>Returns:</strong> A group that represents the controller's transformation.</dt>
  283. </dl>
  284. </div>
  285. <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>
  286. <div class="method">
  287. <div class="description">
  288. <p>Returns an instance of <code>THREE.Group</code> that represents the transformation
  289. of a XR controller in grip space. The requested controller is defined
  290. by the given index.</p>
  291. </div>
  292. <table class="params">
  293. <tbody>
  294. <tr>
  295. <td class="name">
  296. <strong>index</strong>
  297. </td>
  298. <td class="description last">
  299. <p>The index of the XR controller.</p>
  300. </td>
  301. </tr>
  302. </tbody>
  303. </table>
  304. <dl class="details">
  305. <dt class="tag-returns"><strong>Returns:</strong> A group that represents the controller's transformation.</dt>
  306. </dl>
  307. </div>
  308. <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>
  309. <div class="method">
  310. <div class="description">
  311. <p>Returns the environment blend mode from the current XR session.</p>
  312. </div>
  313. <dl class="details">
  314. <dt class="tag-returns"><strong>Returns:</strong> The environment blend mode. Returns <code>undefined</code> when used outside of a XR session.</dt>
  315. </dl>
  316. </div>
  317. <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>
  318. <div class="method">
  319. <div class="description">
  320. <p>Returns the foveation value.</p>
  321. </div>
  322. <dl class="details">
  323. <dt class="tag-returns"><strong>Returns:</strong> The foveation value. Returns <code>undefined</code> if no base or projection layer is defined.</dt>
  324. </dl>
  325. </div>
  326. <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>
  327. <div class="method">
  328. <div class="description">
  329. <p>Returns the current XR frame.</p>
  330. </div>
  331. <dl class="details">
  332. <dt class="tag-returns"><strong>Returns:</strong> The XR frame. Returns <code>null</code> when used outside a XR session.</dt>
  333. </dl>
  334. </div>
  335. <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>
  336. <div class="method">
  337. <div class="description">
  338. <p>Returns the framebuffer scale factor.</p>
  339. </div>
  340. <dl class="details">
  341. <dt class="tag-returns"><strong>Returns:</strong> The framebuffer scale factor.</dt>
  342. </dl>
  343. </div>
  344. <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>
  345. <div class="method">
  346. <div class="description">
  347. <p>Returns an instance of <code>THREE.Group</code> that represents the transformation
  348. of a XR controller in hand space. The requested controller is defined
  349. by the given index.</p>
  350. </div>
  351. <table class="params">
  352. <tbody>
  353. <tr>
  354. <td class="name">
  355. <strong>index</strong>
  356. </td>
  357. <td class="description last">
  358. <p>The index of the XR controller.</p>
  359. </td>
  360. </tr>
  361. </tbody>
  362. </table>
  363. <dl class="details">
  364. <dt class="tag-returns"><strong>Returns:</strong> A group that represents the controller's transformation.</dt>
  365. </dl>
  366. </div>
  367. <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>
  368. <div class="method">
  369. <div class="description">
  370. <p>Returns the XR reference space.</p>
  371. </div>
  372. <dl class="details">
  373. <dt class="tag-returns"><strong>Returns:</strong> The XR reference space.</dt>
  374. </dl>
  375. </div>
  376. <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>
  377. <div class="method">
  378. <div class="description">
  379. <p>Returns the reference space type.</p>
  380. </div>
  381. <dl class="details">
  382. <dt class="tag-returns"><strong>Returns:</strong> The reference space type.</dt>
  383. </dl>
  384. </div>
  385. <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>
  386. <div class="method">
  387. <div class="description">
  388. <p>Returns the current XR session.</p>
  389. </div>
  390. <dl class="details">
  391. <dt class="tag-returns"><strong>Returns:</strong> The XR session. Returns <code>null</code> when used outside a XR session.</dt>
  392. </dl>
  393. </div>
  394. <h3 class="name name-method" id="renderLayers" translate="no">.<a href="#renderLayers">renderLayers</a><span class="signature">()</span> </h3>
  395. <div class="method">
  396. <div class="description">
  397. <p>Renders the XR layers that have been previously added to the scene.</p>
  398. <p>This method is usually called in your animation loop before rendering
  399. the actual scene via <code>renderer.render( scene, camera );</code>.</p>
  400. </div>
  401. </div>
  402. <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>
  403. <div class="method">
  404. <div class="description">
  405. <p>Sets the foveation value.</p>
  406. </div>
  407. <table class="params">
  408. <tbody>
  409. <tr>
  410. <td class="name">
  411. <strong>foveation</strong>
  412. </td>
  413. <td class="description last">
  414. <p>A number in the range <code>[0,1]</code> where <code>0</code> means no foveation (full resolution)
  415. and <code>1</code> means maximum foveation (the edges render at lower resolution).</p>
  416. </td>
  417. </tr>
  418. </tbody>
  419. </table>
  420. </div>
  421. <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>
  422. <div class="method">
  423. <div class="description">
  424. <p>Sets the framebuffer scale factor.</p>
  425. <p>This method can not be used during a XR session.</p>
  426. </div>
  427. <table class="params">
  428. <tbody>
  429. <tr>
  430. <td class="name">
  431. <strong>factor</strong>
  432. </td>
  433. <td class="description last">
  434. <p>The framebuffer scale factor.</p>
  435. </td>
  436. </tr>
  437. </tbody>
  438. </table>
  439. </div>
  440. <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>
  441. <div class="method">
  442. <div class="description">
  443. <p>Sets a custom XR reference space.</p>
  444. </div>
  445. <table class="params">
  446. <tbody>
  447. <tr>
  448. <td class="name">
  449. <strong>space</strong>
  450. </td>
  451. <td class="description last">
  452. <p>The XR reference space.</p>
  453. </td>
  454. </tr>
  455. </tbody>
  456. </table>
  457. </div>
  458. <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>
  459. <div class="method">
  460. <div class="description">
  461. <p>Sets the reference space type.</p>
  462. <p>This method can not be used during a XR session.</p>
  463. </div>
  464. <table class="params">
  465. <tbody>
  466. <tr>
  467. <td class="name">
  468. <strong>type</strong>
  469. </td>
  470. <td class="description last">
  471. <p>The reference space type.</p>
  472. </td>
  473. </tr>
  474. </tbody>
  475. </table>
  476. </div>
  477. <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>
  478. <div class="method">
  479. <div class="description">
  480. <p>After a XR session has been requested usually with one of the <code>*Button</code> modules, it
  481. is injected into the renderer with this method. This method triggers the start of
  482. the actual XR rendering.</p>
  483. </div>
  484. <table class="params">
  485. <tbody>
  486. <tr>
  487. <td class="name">
  488. <strong>session</strong>
  489. </td>
  490. <td class="description last">
  491. <p>The XR session to set.</p>
  492. </td>
  493. </tr>
  494. </tbody>
  495. </table>
  496. <dl class="details">
  497. <dt class="tag-returns"><strong>Returns:</strong> A Promise that resolves when the session has been set.</dt>
  498. </dl>
  499. </div>
  500. <h3 class="name name-method" id="updateCamera" translate="no">.<a href="#updateCamera">updateCamera</a><span class="signature">( camera : <span class="param-type"><a href="PerspectiveCamera.html">PerspectiveCamera</a></span> )</span> </h3>
  501. <div class="method">
  502. <div class="description">
  503. <p>This method is called by the renderer per frame and updates the XR camera
  504. and it sub cameras based on the given camera. The given camera is the &quot;user&quot;
  505. camera created on application level and used for non-XR rendering.</p>
  506. </div>
  507. <table class="params">
  508. <tbody>
  509. <tr>
  510. <td class="name">
  511. <strong>camera</strong>
  512. </td>
  513. <td class="description last">
  514. <p>The camera.</p>
  515. </td>
  516. </tr>
  517. </tbody>
  518. </table>
  519. </div>
  520. <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>
  521. <div class="method">
  522. <div class="description">
  523. <p>Returns <code>true</code> if the engine renders to a multiview target.</p>
  524. </div>
  525. <dl class="details">
  526. <dt class="tag-returns"><strong>Returns:</strong> Whether the engine renders to a multiview render target or not.</dt>
  527. </dl>
  528. </div>
  529. <h2 class="subsection-title">Source</h2>
  530. <p>
  531. <a href="https://github.com/mrdoob/three.js/blob/master/src/renderers/common/XRManager.js" translate="no" target="_blank" rel="noopener">src/renderers/common/XRManager.js</a>
  532. </p>
  533. </article>
  534. </section>
  535. <script src="../scripts/linenumber.js"></script>
  536. <script src="../scripts/page.js"></script>
  537. </body>
  538. </html>
粤ICP备19079148号