webgl_loader_assimp.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. <style>
  8. body {
  9. color: #000;
  10. font-family: Monospace;
  11. font-size: 13px;
  12. text-align: center;
  13. background-color: #000;
  14. margin: 0px;
  15. overflow: hidden;
  16. }
  17. #info {
  18. color: #fff;
  19. position: absolute;
  20. top: 10px;
  21. width: 100%;
  22. text-align: center;
  23. z-index: 100;
  24. display:block;
  25. }
  26. a { color: skyblue }
  27. .button { background:#999; color:#eee; padding:0.2em 0.5em; cursor:pointer }
  28. .highlight { background:orange; color:#fff; }
  29. span {
  30. display: inline-block;
  31. width: 60px;
  32. text-align: center;
  33. }
  34. </style>
  35. </head>
  36. <body>
  37. <div id="container"></div>
  38. <div id="info">
  39. <a href="http://threejs.org" target="_blank" rel="noopener">three.js</a>
  40. <a href="https://github.com/Virtulous" target="_blank" rel="noopener">Assimp File format</a>
  41. <div>Assimp loader by <a href="https://virtulo.us" target="_blank" rel="noopener">Virtulous</a></div>
  42. <div>Octaminator model from <a href="http://opengameart.org/content/octaminator-engine-ready" target="_blank" rel="noopener">Teh_Bucket and raymoohawk</a></div>
  43. </div>
  44. <script src="../build/three.js"></script>
  45. <script src="js/loaders/AssimpLoader.js"></script>
  46. <script src="js/WebGL.js"></script>
  47. <script src="js/libs/stats.min.js"></script>
  48. <script src="js/controls/OrbitControls.js"></script>
  49. <script>
  50. if ( WEBGL.isWebGLAvailable() === false ) {
  51. document.body.appendChild( WEBGL.getWebGLErrorMessage() );
  52. }
  53. var container, stats;
  54. var camera, scene, renderer;
  55. var animation;
  56. init();
  57. function init() {
  58. container = document.getElementById( 'container' );
  59. camera = new THREE.PerspectiveCamera( 25, window.innerWidth / window.innerHeight, 1, 10000 );
  60. camera.position.set( 600, 1150, 5 );
  61. camera.up.set( 0, 0, 1 );
  62. camera.lookAt( - 100, 0, 0 );
  63. scene = new THREE.Scene();
  64. var ambient = new THREE.HemisphereLight( 0x8888fff, 0xff8888, 0.5 );
  65. ambient.position.set( 0, 1, 0 );
  66. scene.add( ambient );
  67. var light = new THREE.DirectionalLight( 0xffffff, 1 );
  68. light.position.set( 0, 4, 4 ).normalize();
  69. scene.add( light );
  70. renderer = new THREE.WebGLRenderer( { antialias: true } );
  71. renderer.setPixelRatio( window.devicePixelRatio );
  72. renderer.setSize( window.innerWidth, window.innerHeight );
  73. container.appendChild( renderer.domElement );
  74. var controls = new THREE.OrbitControls( camera, renderer.domElement );
  75. stats = new Stats();
  76. container.appendChild( stats.dom );
  77. var loader = new THREE.AssimpLoader();
  78. loader.load( './models/assimp/octaminator/Octaminator.assimp', function ( result ) {
  79. var object = result.object;
  80. object.position.y = - 100;
  81. object.rotation.x = Math.PI / 2;
  82. scene.add( object );
  83. animation = result.animation;
  84. } );
  85. window.addEventListener( 'resize', onWindowResize, false );
  86. animate();
  87. }
  88. function onWindowResize() {
  89. camera.aspect = window.innerWidth / window.innerHeight;
  90. camera.updateProjectionMatrix();
  91. renderer.setSize( window.innerWidth, window.innerHeight );
  92. }
  93. function animate() {
  94. requestAnimationFrame( animate, renderer.domElement );
  95. renderer.render( scene, camera );
  96. if ( animation ) animation.setTime( performance.now() / 1000 );
  97. stats.update();
  98. }
  99. </script>
  100. </body>
  101. </html>