XREstimatedLight.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <!DOCTYPE html>
  2. <html lang="en">
  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. [page:Group] &rarr;
  11. <h1>[name]</h1>
  12. <p class="desc">
  13. XREstimatedLight uses WebXR's light estimation to create
  14. a light probe, a directional light, and (optionally) an environment map
  15. that model the user's real-world environment and lighting.<br>
  16. As WebXR updates the light and environment estimation, XREstimatedLight
  17. automatically updates the light probe, directional light, and environment map.<br><br>
  18. It's important to specify `light-estimation` as an optional or required
  19. feature when creating the WebXR session, otherwise the light estimation
  20. can't work.<br><br>
  21. See <a href="https://developer.mozilla.org/en-US/docs/Web/API/XRLightProbe#browser_compatibility">here</a>
  22. for browser compatibility information, as this is still an experimental feature in WebXR.<br><br>
  23. To use this, as with all files in the /examples directory, you will have to
  24. include the file separately in your HTML.
  25. </p>
  26. <h2>Import</h2>
  27. <p>
  28. [name] is an add-on, and must be imported explicitly.
  29. See [link:#manual/introduction/Installation Installation / Addons].
  30. </p>
  31. <code>
  32. import { XREstimatedLight } from 'three/addons/webxr/XREstimatedLight.js';
  33. </code>
  34. <h2>Code Example</h2>
  35. <code>
  36. renderer.xr.enabled = true;
  37. // Don't add the XREstimatedLight to the scene initially.
  38. // It doesn't have any estimated lighting values until an AR session starts.
  39. const xrLight = new XREstimatedLight( renderer );
  40. xrLight.addEventListener( 'estimationstart' , () => {
  41. scene.add( xrLight );
  42. if ( xrLight.environment ) {
  43. scene.environment = xrLight.environment;
  44. }
  45. } );
  46. xrLight.addEventListener( 'estimationend', () => {
  47. scene.remove( xrLight );
  48. scene.environment = null;
  49. } );
  50. // In order for lighting estimation to work, 'light-estimation' must be included as either
  51. // an optional or required feature.
  52. document.body.appendChild( XRButton.createButton( renderer, {
  53. optionalFeatures: [ 'light-estimation' ]
  54. } ) );
  55. </code>
  56. <h2>Examples</h2>
  57. <p>[example:webxr_ar_lighting webxr / light estimation]</p>
  58. <h2>Constructor</h2>
  59. <h3>[name]( [param:WebGLRenderer renderer], [param:Boolean environmentEstimation] )</h3>
  60. <p>
  61. [page:WebGLRenderer renderer]: (required) The renderer used to render the Scene. Mainly used to interact with WebXRManager.<br><br>
  62. environmentEstimation: If `true`, use WebXR to estimate an environment map.
  63. </p>
  64. <h2>Events</h2>
  65. <h3>estimationstart</h3>
  66. <p>
  67. Fires when the estimated lighting values start being updated.
  68. </p>
  69. <h3>estimationend</h3>
  70. <p>
  71. Fires when the estimated lighting values stop being updated.
  72. </p>
  73. <h2>Properties</h2>
  74. <h3>[property:Texture environment]</h3>
  75. <p>
  76. The environment map estimated by WebXR. This is only available if environmentEstimation is `true`.<br><br>
  77. It can be used as the [page:Scene.environment], for
  78. [page:MeshStandardMaterial.envMap], or
  79. as the [page:Scene.background].
  80. </p>
  81. <h2>Source</h2>
  82. <p>
  83. [link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/webxr/XREstimatedLight.js examples/jsm/webxr/XREstimatedLight.js]
  84. </p>
  85. </body>
  86. </html>