webgl_loader_usdz.html 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - loaders - USDZLoader</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <link type="text/css" rel="stylesheet" href="main.css">
  8. <style>
  9. body {
  10. background-color: #eee;
  11. color: #444;
  12. }
  13. a {
  14. color: #08f;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <div id="info">
  20. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - USDZLoader
  21. </div>
  22. <script type="importmap">
  23. {
  24. "imports": {
  25. "three": "../build/three.module.js",
  26. "three/addons/": "./jsm/"
  27. }
  28. }
  29. </script>
  30. <script type="module">
  31. import * as THREE from 'three';
  32. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  33. import { USDZLoader } from 'three/addons/loaders/USDZLoader.js';
  34. let camera, scene, renderer;
  35. init();
  36. animate();
  37. function init() {
  38. camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 100 );
  39. camera.position.set( 0, 0.75, - 1 );
  40. scene = new THREE.Scene();
  41. scene.background = new THREE.Color( 0xeeeeee );
  42. scene.add( new THREE.GridHelper( 2, 4, 0xc1c1c1, 0x8d8d8d ) );
  43. const light = new THREE.DirectionalLight( 0xffffff, 3 );
  44. light.position.set( 1, 1, 1 );
  45. scene.add( light );
  46. const light2 = new THREE.HemisphereLight( 0xffffff, 0xc1c1c1, 3 );
  47. scene.add( light2 );
  48. // renderer
  49. renderer = new THREE.WebGLRenderer( { antialias: true } );
  50. renderer.setPixelRatio( window.devicePixelRatio );
  51. renderer.setSize( window.innerWidth, window.innerHeight );
  52. document.body.appendChild( renderer.domElement );
  53. const controls = new OrbitControls( camera, renderer.domElement );
  54. controls.minDistance = 1;
  55. controls.maxDistance = 8;
  56. const loader = new USDZLoader();
  57. loader.load( 'models/usdz/saeukkang.usdz', function ( usd ) {
  58. scene.add( usd );
  59. } );
  60. window.addEventListener( 'resize', onWindowResize );
  61. }
  62. function onWindowResize() {
  63. camera.aspect = window.innerWidth / window.innerHeight;
  64. camera.updateProjectionMatrix();
  65. renderer.setSize( window.innerWidth, window.innerHeight );
  66. }
  67. function animate() {
  68. requestAnimationFrame( animate );
  69. renderer.render( scene, camera );
  70. }
  71. </script>
  72. </body>
  73. </html>