webgl_loader_fbx_nurbs.html 2.8 KB

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