webgl_loader_fbx_nurbs.html 2.4 KB

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