webgl_loader_assimp.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. let container, stats;
  23. let camera, scene, renderer;
  24. let 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. const ambient = new THREE.HemisphereLight( 0x8888fff, 0xff8888, 0.5 );
  34. ambient.position.set( 0, 1, 0 );
  35. scene.add( ambient );
  36. const 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. const controls = new OrbitControls( camera, renderer.domElement );
  44. controls.minDistance = 750;
  45. controls.maxDistance = 2500;
  46. stats = new Stats();
  47. container.appendChild( stats.dom );
  48. const loader = new AssimpLoader();
  49. loader.load( './models/assimp/octaminator/Octaminator.assimp', function ( result ) {
  50. const object = result.object;
  51. object.position.y = - 100;
  52. object.rotation.x = Math.PI / 2;
  53. scene.add( object );
  54. animation = result.animation;
  55. } );
  56. window.addEventListener( 'resize', onWindowResize );
  57. animate();
  58. }
  59. function onWindowResize() {
  60. camera.aspect = window.innerWidth / window.innerHeight;
  61. camera.updateProjectionMatrix();
  62. renderer.setSize( window.innerWidth, window.innerHeight );
  63. }
  64. function animate() {
  65. requestAnimationFrame( animate, renderer.domElement );
  66. renderer.render( scene, camera );
  67. if ( animation ) animation.setTime( performance.now() / 1000 );
  68. stats.update();
  69. }
  70. </script>
  71. </body>
  72. </html>