2
0

webgl_loader_assimp2json.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. <style>
  8. body {
  9. font-family: Monospace;
  10. background-color: #000000;
  11. margin: 0px;
  12. overflow: hidden;
  13. }
  14. #info {
  15. color: #fff;
  16. position: absolute;
  17. top: 10px;
  18. width: 100%;
  19. text-align: center;
  20. z-index: 100;
  21. display:block;
  22. }
  23. a { color: red }
  24. #stats { position: absolute; top:0; left: 0 }
  25. #stats #fps { background: transparent !important }
  26. #stats #fps #fpsText { color: #aaa !important }
  27. #stats #fps #fpsGraph { display: none }
  28. </style>
  29. </head>
  30. <body>
  31. <div id="info">
  32. <a href="http://threejs.org" target="_blank">three.js</a> -
  33. Jeep by Psionic, interior from
  34. <a href="http://assimp.sf.net" target="_blank">Assimp</a>
  35. </div>
  36. <script src="../build/three.min.js"></script>
  37. <script src="js/loaders/AssimpJSONLoader.js"></script>
  38. <script src="js/Detector.js"></script>
  39. <script src="js/libs/stats.min.js"></script>
  40. <script>
  41. if ( ! Detector.webgl ) {
  42. Detector.addGetWebGLMessage();
  43. }
  44. /*
  45. Simple demo for loading json files generated by assimp2json
  46. https://github.com/acgessler/assimp2json
  47. assimp2json uses assimp (http://assimp.sf.net) to import 40+ 3D file
  48. formats, including 3ds, obj, dae, blend, fbx, x, ms3d, lwo (and many
  49. more).
  50. TODOs:
  51. - assimp supports skeletal animations and assimp2son exports
  52. them. This demo currently doesn't read them.
  53. - not all material properties supported by assimp are currently
  54. mapped to THREE.js
  55. The sample files for this demo originate in assimp's repository,
  56. and were converted using assimp2json 2.0. The interior file was
  57. slightly edited to adjust for lower-case texture names.
  58. */
  59. var container, stats;
  60. var camera, scene, renderer, objects;
  61. var clock = new THREE.Clock();
  62. // init scene
  63. init();
  64. var onProgress = function ( xhr ) {
  65. if ( xhr.lengthComputable ) {
  66. var percentComplete = xhr.loaded / xhr.total * 100;
  67. console.log( Math.round(percentComplete, 2) + '% downloaded' );
  68. }
  69. };
  70. var onError = function ( xhr ) {
  71. };
  72. // Load jeep model using the AssimpJSONLoader
  73. var loader1 = new THREE.AssimpJSONLoader();
  74. loader1.load( 'models/assimp/jeep/jeep.assimp.json', function ( assimpjson ) {
  75. assimpjson.scale.x = assimpjson.scale.y = assimpjson.scale.z = 0.2;
  76. assimpjson.updateMatrix();
  77. scene.add(assimpjson);
  78. }, onProgress, onError );
  79. // load interior model
  80. var loader2 = new THREE.AssimpJSONLoader();
  81. loader2.load( 'models/assimp/interior/interior.assimp.json', function ( assimpjson ) {
  82. assimpjson.scale.x = assimpjson.scale.y = assimpjson.scale.z = 1;
  83. assimpjson.updateMatrix();
  84. scene.add( assimpjson );
  85. }, onProgress, onError );
  86. animate();
  87. //
  88. function init() {
  89. container = document.createElement( 'div' );
  90. document.body.appendChild( container );
  91. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 2000 );
  92. camera.position.set( 2, 4, 5 );
  93. scene = new THREE.Scene();
  94. scene.fog = new THREE.FogExp2( 0x000000, 0.035 );
  95. // Lights
  96. scene.add( new THREE.AmbientLight( 0xcccccc ) );
  97. var directionalLight = new THREE.DirectionalLight(/*Math.random() * 0xffffff*/0xeeeeee );
  98. directionalLight.position.x = Math.random() - 0.5;
  99. directionalLight.position.y = Math.random() - 0.5;
  100. directionalLight.position.z = Math.random() - 0.5;
  101. directionalLight.position.normalize();
  102. scene.add( directionalLight );
  103. // Renderer
  104. renderer = new THREE.WebGLRenderer();
  105. renderer.setSize( window.innerWidth, window.innerHeight );
  106. container.appendChild( renderer.domElement );
  107. // Stats
  108. stats = new Stats();
  109. container.appendChild( stats.domElement );
  110. // Events
  111. window.addEventListener( 'resize', onWindowResize, false );
  112. }
  113. //
  114. function onWindowResize( event ) {
  115. renderer.setSize( window.innerWidth, window.innerHeight );
  116. camera.aspect = window.innerWidth / window.innerHeight;
  117. camera.updateProjectionMatrix();
  118. }
  119. //
  120. var t = 0;
  121. function animate() {
  122. requestAnimationFrame( animate );
  123. render();
  124. stats.update();
  125. }
  126. //
  127. function render() {
  128. var timer = Date.now() * 0.0005;
  129. camera.position.x = Math.cos( timer ) * 10;
  130. camera.position.y = 4;
  131. camera.position.z = Math.sin( timer ) * 10;
  132. camera.lookAt( scene.position );
  133. renderer.render( scene, camera );
  134. }
  135. </script>
  136. </body>
  137. </html>