webxr_ar_plane_detection.html 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js ar - plane detection</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
  7. <meta property="og:title" content="three.js ar - plane detection">
  8. <meta property="og:type" content="website">
  9. <meta property="og:url" content="https://threejs.org/examples/webxr_ar_plane_detection.html">
  10. <meta property="og:image" content="https://threejs.org/examples/screenshots/webxr_ar_plane_detection.jpg">
  11. <link type="text/css" rel="stylesheet" href="main.css">
  12. </head>
  13. <body>
  14. <div id="info">
  15. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> ar - plane detection<br/>
  16. </div>
  17. <script type="importmap">
  18. {
  19. "imports": {
  20. "three": "../build/three.module.js",
  21. "three/addons/": "./jsm/"
  22. }
  23. }
  24. </script>
  25. <script type="module">
  26. import * as THREE from 'three';
  27. import { ARButton } from 'three/addons/webxr/ARButton.js';
  28. import { XRPlanes } from 'three/addons/webxr/XRPlanes.js';
  29. //
  30. const renderer = new THREE.WebGLRenderer( { antialias: true, alpha: true } );
  31. renderer.setPixelRatio( window.devicePixelRatio );
  32. renderer.setSize( window.innerWidth, window.innerHeight );
  33. renderer.setAnimationLoop( animate );
  34. renderer.xr.enabled = true;
  35. document.body.appendChild( renderer.domElement );
  36. document.body.appendChild( ARButton.createButton( renderer, {
  37. requiredFeatures: [ 'plane-detection' ]
  38. } ) );
  39. window.addEventListener( 'resize', onWindowResize );
  40. //
  41. const scene = new THREE.Scene();
  42. const planes = new XRPlanes( renderer );
  43. scene.add( planes );
  44. const camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 20 );
  45. const light = new THREE.HemisphereLight( 0xffffff, 0xbbbbff, 3 );
  46. light.position.set( 0.5, 1, 0.25 );
  47. scene.add( light );
  48. //
  49. function onWindowResize() {
  50. camera.aspect = window.innerWidth / window.innerHeight;
  51. camera.updateProjectionMatrix();
  52. renderer.setSize( window.innerWidth, window.innerHeight );
  53. }
  54. function animate() {
  55. renderer.render( scene, camera );
  56. }
  57. </script>
  58. </body>
  59. </html>
粤ICP备19079148号