webgl_loader_fbx_nurbs.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - FBX loader - Nurbs</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. </head>
  9. <body>
  10. <div id="info">
  11. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - FBXLoader - Nurbs
  12. </div>
  13. <!-- Import maps polyfill -->
  14. <!-- Remove this when import maps will be widely supported -->
  15. <script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
  16. <script type="importmap">
  17. {
  18. "imports": {
  19. "three": "../build/three.module.js",
  20. "three/addons/": "./jsm/"
  21. }
  22. }
  23. </script>
  24. <script type="module">
  25. import * as THREE from 'three';
  26. import Stats from 'three/addons/libs/stats.module.js';
  27. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  28. import { FBXLoader } from 'three/addons/loaders/FBXLoader.js';
  29. let camera, scene, renderer, stats;
  30. init();
  31. animate();
  32. function init() {
  33. const container = document.createElement( 'div' );
  34. document.body.appendChild( container );
  35. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
  36. camera.position.set( 2, 18, 28 );
  37. scene = new THREE.Scene();
  38. const hemiLight = new THREE.HemisphereLight( 0xffffff, 0x444444 );
  39. hemiLight.position.set( 0, 1, 0 );
  40. scene.add( hemiLight );
  41. const dirLight = new THREE.DirectionalLight( 0xffffff );
  42. dirLight.position.set( 0, 1, 0 );
  43. scene.add( dirLight );
  44. // grid
  45. const gridHelper = new THREE.GridHelper( 28, 28, 0x303030, 0x303030 );
  46. scene.add( gridHelper );
  47. // stats
  48. stats = new Stats();
  49. container.appendChild( stats.dom );
  50. // model
  51. const loader = new FBXLoader();
  52. loader.load( 'models/fbx/nurbs.fbx', function ( object ) {
  53. scene.add( object );
  54. } );
  55. renderer = new THREE.WebGLRenderer();
  56. renderer.setPixelRatio( window.devicePixelRatio );
  57. renderer.setSize( window.innerWidth, window.innerHeight );
  58. container.appendChild( renderer.domElement );
  59. const controls = new OrbitControls( camera, renderer.domElement );
  60. controls.target.set( 0, 12, 0 );
  61. controls.update();
  62. window.addEventListener( 'resize', onWindowResize );
  63. }
  64. function onWindowResize() {
  65. camera.aspect = window.innerWidth / window.innerHeight;
  66. camera.updateProjectionMatrix();
  67. renderer.setSize( window.innerWidth, window.innerHeight );
  68. }
  69. //
  70. function animate() {
  71. requestAnimationFrame( animate );
  72. renderer.render( scene, camera );
  73. stats.update();
  74. }
  75. </script>
  76. </body>
  77. </html>