webgl_loader_assimp2json.html 3.5 KB

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