webgl_loader_assimp.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - Assimp</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="container"></div>
  11. <div id="info">
  12. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a>
  13. <a href="https://github.com/Virtulous" target="_blank" rel="noopener">Assimp File format</a>
  14. <div>Assimp loader by <a href="https://virtulo.us" target="_blank" rel="noopener">Virtulous</a></div>
  15. <div>Octaminator model from <a href="http://opengameart.org/content/octaminator-engine-ready" target="_blank" rel="noopener">Teh_Bucket and raymoohawk</a></div>
  16. </div>
  17. <script type="module">
  18. import * as THREE from '../build/three.module.js';
  19. import Stats from './jsm/libs/stats.module.js';
  20. import { OrbitControls } from './jsm/controls/OrbitControls.js';
  21. import { AssimpLoader } from './jsm/loaders/AssimpLoader.js';
  22. var container, stats;
  23. var camera, scene, renderer;
  24. var animation;
  25. init();
  26. function init() {
  27. container = document.getElementById( 'container' );
  28. camera = new THREE.PerspectiveCamera( 25, window.innerWidth / window.innerHeight, 1, 10000 );
  29. camera.position.set( 600, 1150, 5 );
  30. camera.up.set( 0, 0, 1 );
  31. camera.lookAt( - 100, 0, 0 );
  32. scene = new THREE.Scene();
  33. var ambient = new THREE.HemisphereLight( 0x8888fff, 0xff8888, 0.5 );
  34. ambient.position.set( 0, 1, 0 );
  35. scene.add( ambient );
  36. var light = new THREE.DirectionalLight( 0xffffff, 1 );
  37. light.position.set( 0, 4, 4 ).normalize();
  38. scene.add( light );
  39. renderer = new THREE.WebGLRenderer( { antialias: true } );
  40. renderer.setPixelRatio( window.devicePixelRatio );
  41. renderer.setSize( window.innerWidth, window.innerHeight );
  42. container.appendChild( renderer.domElement );
  43. var controls = new OrbitControls( camera, renderer.domElement );
  44. stats = new Stats();
  45. container.appendChild( stats.dom );
  46. var loader = new AssimpLoader();
  47. loader.load( './models/assimp/octaminator/Octaminator.assimp', function ( result ) {
  48. var object = result.object;
  49. object.position.y = - 100;
  50. object.rotation.x = Math.PI / 2;
  51. scene.add( object );
  52. animation = result.animation;
  53. } );
  54. window.addEventListener( 'resize', onWindowResize, false );
  55. animate();
  56. }
  57. function onWindowResize() {
  58. camera.aspect = window.innerWidth / window.innerHeight;
  59. camera.updateProjectionMatrix();
  60. renderer.setSize( window.innerWidth, window.innerHeight );
  61. }
  62. function animate() {
  63. requestAnimationFrame( animate, renderer.domElement );
  64. renderer.render( scene, camera );
  65. if ( animation ) animation.setTime( performance.now() / 1000 );
  66. stats.update();
  67. }
  68. </script>
  69. </body>
  70. </html>