webgl_loader_fbx_nurbs.html 2.4 KB

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