webgl_loader_fbx_nurbs.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. }
  21. }
  22. </script>
  23. <script type="module">
  24. import * as THREE from 'three';
  25. import Stats from './jsm/libs/stats.module.js';
  26. import { OrbitControls } from './jsm/controls/OrbitControls.js';
  27. import { FBXLoader } from './jsm/loaders/FBXLoader.js';
  28. let camera, scene, renderer, stats;
  29. init();
  30. animate();
  31. function init() {
  32. const container = document.createElement( 'div' );
  33. document.body.appendChild( container );
  34. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
  35. camera.position.set( 2, 18, 28 );
  36. scene = new THREE.Scene();
  37. const hemiLight = new THREE.HemisphereLight( 0xffffff, 0x444444 );
  38. hemiLight.position.set( 0, 1, 0 );
  39. scene.add( hemiLight );
  40. const dirLight = new THREE.DirectionalLight( 0xffffff );
  41. dirLight.position.set( 0, 1, 0 );
  42. scene.add( dirLight );
  43. // grid
  44. const gridHelper = new THREE.GridHelper( 28, 28, 0x303030, 0x303030 );
  45. scene.add( gridHelper );
  46. // stats
  47. stats = new Stats();
  48. container.appendChild( stats.dom );
  49. // model
  50. const loader = new FBXLoader();
  51. loader.load( 'models/fbx/nurbs.fbx', function ( object ) {
  52. scene.add( object );
  53. } );
  54. renderer = new THREE.WebGLRenderer();
  55. renderer.setPixelRatio( window.devicePixelRatio );
  56. renderer.setSize( window.innerWidth, window.innerHeight );
  57. container.appendChild( renderer.domElement );
  58. const controls = new OrbitControls( camera, renderer.domElement );
  59. controls.target.set( 0, 12, 0 );
  60. controls.update();
  61. window.addEventListener( 'resize', onWindowResize );
  62. }
  63. function onWindowResize() {
  64. camera.aspect = window.innerWidth / window.innerHeight;
  65. camera.updateProjectionMatrix();
  66. renderer.setSize( window.innerWidth, window.innerHeight );
  67. }
  68. //
  69. function animate() {
  70. requestAnimationFrame( animate );
  71. renderer.render( scene, camera );
  72. stats.update();
  73. }
  74. </script>
  75. </body>
  76. </html>