webgl_loader_fbx_nurbs.html 2.4 KB

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