webgl_loader_assimp2json.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - Open Asset Import Library (assimp) / assimp2json</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> -
  12. Jeep by Psionic, interior from
  13. <a href="http://www.assimp.org/" target="_blank" rel="noopener">Assimp</a>
  14. </div>
  15. <script type="module">
  16. import * as THREE from '../build/three.module.js';
  17. import Stats from './jsm/libs/stats.module.js';
  18. import { AssimpJSONLoader } from './jsm/loaders/AssimpJSONLoader.js';
  19. /*
  20. Simple demo for loading json files generated by assimp2json
  21. https://github.com/acgessler/assimp2json
  22. assimp2json uses assimp (http://assimp.sf.net) to import 40+ 3D file
  23. formats, including 3ds, obj, dae, blend, fbx, x, ms3d, lwo (and many
  24. more).
  25. TODOs:
  26. - assimp supports skeletal animations and assimp2son exports
  27. them. This demo currently doesn't read them.
  28. - not all material properties supported by assimp are currently
  29. mapped to THREE.js
  30. The sample files for this demo originate in assimp's repository,
  31. and were converted using assimp2json 2.0. The interior file was
  32. slightly edited to adjust for lower-case texture names.
  33. */
  34. var container, stats, clock;
  35. var camera, scene, renderer;
  36. init();
  37. animate();
  38. //
  39. function init() {
  40. container = document.createElement( 'div' );
  41. document.body.appendChild( container );
  42. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 2000 );
  43. scene = new THREE.Scene();
  44. clock = new THREE.Clock();
  45. // load jeep model
  46. var loader = new AssimpJSONLoader();
  47. loader.load( 'models/assimp/jeep/jeep.assimp.json', function ( object ) {
  48. object.scale.multiplyScalar( 0.2 );
  49. scene.add( object );
  50. } );
  51. // load interior model
  52. loader.load( 'models/assimp/interior/interior.assimp.json', function ( object ) {
  53. scene.add( object );
  54. } );
  55. //
  56. var ambientLight = new THREE.AmbientLight( 0xcccccc, 0.4 );
  57. scene.add( ambientLight );
  58. var directionalLight = new THREE.DirectionalLight( 0xeeeeee );
  59. directionalLight.position.set( 1, 1, - 1 );
  60. directionalLight.position.normalize();
  61. scene.add( directionalLight );
  62. //
  63. renderer = new THREE.WebGLRenderer();
  64. renderer.setPixelRatio( window.devicePixelRatio );
  65. renderer.setSize( window.innerWidth, window.innerHeight );
  66. container.appendChild( renderer.domElement );
  67. //
  68. stats = new Stats();
  69. container.appendChild( stats.dom );
  70. //
  71. window.addEventListener( 'resize', onWindowResize, false );
  72. }
  73. //
  74. function onWindowResize() {
  75. renderer.setSize( window.innerWidth, window.innerHeight );
  76. camera.aspect = window.innerWidth / window.innerHeight;
  77. camera.updateProjectionMatrix();
  78. }
  79. //
  80. function animate() {
  81. requestAnimationFrame( animate );
  82. render();
  83. stats.update();
  84. }
  85. //
  86. function render() {
  87. var elapsedTime = clock.getElapsedTime();
  88. camera.position.x = Math.cos( elapsedTime * 0.5 ) * 10;
  89. camera.position.y = 4;
  90. camera.position.z = Math.sin( elapsedTime * 0.5 ) * 10;
  91. camera.lookAt( scene.position );
  92. renderer.render( scene, camera );
  93. }
  94. </script>
  95. </body>
  96. </html>