AssimpLoader.js 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288
  1. console.warn( "THREE.AssimpLoader: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/index.html#manual/en/introduction/Import-via-modules." );
  2. /**
  3. * @author Virtulous / https://virtulo.us/
  4. */
  5. THREE.AssimpLoader = function ( manager ) {
  6. THREE.Loader.call( this, manager );
  7. };
  8. THREE.AssimpLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype ), {
  9. constructor: THREE.AssimpLoader,
  10. load: function ( url, onLoad, onProgress, onError ) {
  11. var scope = this;
  12. var path = ( scope.path === '' ) ? THREE.LoaderUtils.extractUrlBase( url ) : scope.path;
  13. var loader = new THREE.FileLoader( this.manager );
  14. loader.setPath( scope.path );
  15. loader.setResponseType( 'arraybuffer' );
  16. loader.load( url, function ( buffer ) {
  17. try {
  18. onLoad( scope.parse( buffer, path ) );
  19. } catch ( e ) {
  20. if ( onError ) {
  21. onError( e );
  22. } else {
  23. console.error( e );
  24. }
  25. scope.manager.itemError( url );
  26. }
  27. }, onProgress, onError );
  28. },
  29. parse: function ( buffer, path ) {
  30. var textureLoader = new THREE.TextureLoader( this.manager );
  31. textureLoader.setPath( this.resourcePath || path ).setCrossOrigin( this.crossOrigin );
  32. var Virtulous = {};
  33. Virtulous.KeyFrame = function ( time, matrix ) {
  34. this.time = time;
  35. this.matrix = matrix.clone();
  36. this.position = new THREE.Vector3();
  37. this.quaternion = new THREE.Quaternion();
  38. this.scale = new THREE.Vector3( 1, 1, 1 );
  39. this.matrix.decompose( this.position, this.quaternion, this.scale );
  40. this.clone = function () {
  41. var n = new Virtulous.KeyFrame( this.time, this.matrix );
  42. return n;
  43. };
  44. this.lerp = function ( nextKey, time ) {
  45. time -= this.time;
  46. var dist = ( nextKey.time - this.time );
  47. var l = time / dist;
  48. var l2 = 1 - l;
  49. var keypos = this.position;
  50. var keyrot = this.quaternion;
  51. // var keyscl = key.parentspaceScl || key.scl;
  52. var key2pos = nextKey.position;
  53. var key2rot = nextKey.quaternion;
  54. // var key2scl = key2.parentspaceScl || key2.scl;
  55. Virtulous.KeyFrame.tempAniPos.x = keypos.x * l2 + key2pos.x * l;
  56. Virtulous.KeyFrame.tempAniPos.y = keypos.y * l2 + key2pos.y * l;
  57. Virtulous.KeyFrame.tempAniPos.z = keypos.z * l2 + key2pos.z * l;
  58. // tempAniScale.x = keyscl[0] * l2 + key2scl[0] * l;
  59. // tempAniScale.y = keyscl[1] * l2 + key2scl[1] * l;
  60. // tempAniScale.z = keyscl[2] * l2 + key2scl[2] * l;
  61. Virtulous.KeyFrame.tempAniQuat.set( keyrot.x, keyrot.y, keyrot.z, keyrot.w );
  62. Virtulous.KeyFrame.tempAniQuat.slerp( key2rot, l );
  63. return Virtulous.KeyFrame.tempAniMatrix.compose( Virtulous.KeyFrame.tempAniPos, Virtulous.KeyFrame.tempAniQuat, Virtulous.KeyFrame.tempAniScale );
  64. };
  65. };
  66. Virtulous.KeyFrame.tempAniPos = new THREE.Vector3();
  67. Virtulous.KeyFrame.tempAniQuat = new THREE.Quaternion();
  68. Virtulous.KeyFrame.tempAniScale = new THREE.Vector3( 1, 1, 1 );
  69. Virtulous.KeyFrame.tempAniMatrix = new THREE.Matrix4();
  70. Virtulous.KeyFrameTrack = function () {
  71. this.keys = [];
  72. this.target = null;
  73. this.time = 0;
  74. this.length = 0;
  75. this._accelTable = {};
  76. this.fps = 20;
  77. this.addKey = function ( key ) {
  78. this.keys.push( key );
  79. };
  80. this.init = function () {
  81. this.sortKeys();
  82. if ( this.keys.length > 0 )
  83. this.length = this.keys[ this.keys.length - 1 ].time;
  84. else
  85. this.length = 0;
  86. if ( ! this.fps ) return;
  87. for ( var j = 0; j < this.length * this.fps; j ++ ) {
  88. for ( var i = 0; i < this.keys.length; i ++ ) {
  89. if ( this.keys[ i ].time == j ) {
  90. this._accelTable[ j ] = i;
  91. break;
  92. } else if ( this.keys[ i ].time < j / this.fps && this.keys[ i + 1 ] && this.keys[ i + 1 ].time >= j / this.fps ) {
  93. this._accelTable[ j ] = i;
  94. break;
  95. }
  96. }
  97. }
  98. };
  99. this.parseFromThree = function ( data ) {
  100. var fps = data.fps;
  101. this.target = data.node;
  102. var track = data.hierarchy[ 0 ].keys;
  103. for ( var i = 0; i < track.length; i ++ ) {
  104. this.addKey( new Virtulous.KeyFrame( i / fps || track[ i ].time, track[ i ].targets[ 0 ].data ) );
  105. }
  106. this.init();
  107. };
  108. this.parseFromCollada = function ( data ) {
  109. var track = data.keys;
  110. var fps = this.fps;
  111. for ( var i = 0; i < track.length; i ++ ) {
  112. this.addKey( new Virtulous.KeyFrame( i / fps || track[ i ].time, track[ i ].matrix ) );
  113. }
  114. this.init();
  115. };
  116. this.sortKeys = function () {
  117. this.keys.sort( this.keySortFunc );
  118. };
  119. this.keySortFunc = function ( a, b ) {
  120. return a.time - b.time;
  121. };
  122. this.clone = function () {
  123. var t = new Virtulous.KeyFrameTrack();
  124. t.target = this.target;
  125. t.time = this.time;
  126. t.length = this.length;
  127. for ( var i = 0; i < this.keys.length; i ++ ) {
  128. t.addKey( this.keys[ i ].clone() );
  129. }
  130. t.init();
  131. return t;
  132. };
  133. this.reTarget = function ( root, compareitor ) {
  134. if ( ! compareitor ) compareitor = Virtulous.TrackTargetNodeNameCompare;
  135. this.target = compareitor( root, this.target );
  136. };
  137. this.keySearchAccel = function ( time ) {
  138. time *= this.fps;
  139. time = Math.floor( time );
  140. return this._accelTable[ time ] || 0;
  141. };
  142. this.setTime = function ( time ) {
  143. time = Math.abs( time );
  144. if ( this.length )
  145. time = time % this.length + .05;
  146. var key0 = null;
  147. var key1 = null;
  148. for ( var i = this.keySearchAccel( time ); i < this.keys.length; i ++ ) {
  149. if ( this.keys[ i ].time == time ) {
  150. key0 = this.keys[ i ];
  151. key1 = this.keys[ i ];
  152. break;
  153. } else if ( this.keys[ i ].time < time && this.keys[ i + 1 ] && this.keys[ i + 1 ].time > time ) {
  154. key0 = this.keys[ i ];
  155. key1 = this.keys[ i + 1 ];
  156. break;
  157. } else if ( this.keys[ i ].time < time && i == this.keys.length - 1 ) {
  158. key0 = this.keys[ i ];
  159. key1 = this.keys[ 0 ].clone();
  160. key1.time += this.length + .05;
  161. break;
  162. }
  163. }
  164. if ( key0 && key1 && key0 !== key1 ) {
  165. this.target.matrixAutoUpdate = false;
  166. this.target.matrix.copy( key0.lerp( key1, time ) );
  167. this.target.matrixWorldNeedsUpdate = true;
  168. return;
  169. }
  170. if ( key0 && key1 && key0 == key1 ) {
  171. this.target.matrixAutoUpdate = false;
  172. this.target.matrix.copy( key0.matrix );
  173. this.target.matrixWorldNeedsUpdate = true;
  174. return;
  175. }
  176. };
  177. };
  178. Virtulous.TrackTargetNodeNameCompare = function ( root, target ) {
  179. function find( node, name ) {
  180. if ( node.name == name )
  181. return node;
  182. for ( var i = 0; i < node.children.length; i ++ ) {
  183. var r = find( node.children[ i ], name );
  184. if ( r ) return r;
  185. }
  186. return null;
  187. }
  188. return find( root, target.name );
  189. };
  190. Virtulous.Animation = function () {
  191. this.tracks = [];
  192. this.length = 0;
  193. this.addTrack = function ( track ) {
  194. this.tracks.push( track );
  195. this.length = Math.max( track.length, this.length );
  196. };
  197. this.setTime = function ( time ) {
  198. this.time = time;
  199. for ( var i = 0; i < this.tracks.length; i ++ )
  200. this.tracks[ i ].setTime( time );
  201. };
  202. this.clone = function ( target, compareitor ) {
  203. if ( ! compareitor ) compareitor = Virtulous.TrackTargetNodeNameCompare;
  204. var n = new Virtulous.Animation();
  205. n.target = target;
  206. for ( var i = 0; i < this.tracks.length; i ++ ) {
  207. var track = this.tracks[ i ].clone();
  208. track.reTarget( target, compareitor );
  209. n.addTrack( track );
  210. }
  211. return n;
  212. };
  213. };
  214. var ASSBIN_CHUNK_AICAMERA = 0x1234;
  215. var ASSBIN_CHUNK_AILIGHT = 0x1235;
  216. var ASSBIN_CHUNK_AITEXTURE = 0x1236;
  217. var ASSBIN_CHUNK_AIMESH = 0x1237;
  218. var ASSBIN_CHUNK_AINODEANIM = 0x1238;
  219. var ASSBIN_CHUNK_AISCENE = 0x1239;
  220. var ASSBIN_CHUNK_AIBONE = 0x123a;
  221. var ASSBIN_CHUNK_AIANIMATION = 0x123b;
  222. var ASSBIN_CHUNK_AINODE = 0x123c;
  223. var ASSBIN_CHUNK_AIMATERIAL = 0x123d;
  224. var ASSBIN_CHUNK_AIMATERIALPROPERTY = 0x123e;
  225. var ASSBIN_MESH_HAS_POSITIONS = 0x1;
  226. var ASSBIN_MESH_HAS_NORMALS = 0x2;
  227. var ASSBIN_MESH_HAS_TANGENTS_AND_BITANGENTS = 0x4;
  228. var ASSBIN_MESH_HAS_TEXCOORD_BASE = 0x100;
  229. var ASSBIN_MESH_HAS_COLOR_BASE = 0x10000;
  230. var AI_MAX_NUMBER_OF_COLOR_SETS = 1;
  231. var AI_MAX_NUMBER_OF_TEXTURECOORDS = 4;
  232. //var aiLightSource_UNDEFINED = 0x0;
  233. //! A directional light source has a well-defined direction
  234. //! but is infinitely far away. That's quite a good
  235. //! approximation for sun light.
  236. var aiLightSource_DIRECTIONAL = 0x1;
  237. //! A point light source has a well-defined position
  238. //! in space but no direction - it emits light in all
  239. //! directions. A normal bulb is a point light.
  240. //var aiLightSource_POINT = 0x2;
  241. //! A spot light source emits light in a specific
  242. //! angle. It has a position and a direction it is pointing to.
  243. //! A good example for a spot light is a light spot in
  244. //! sport arenas.
  245. var aiLightSource_SPOT = 0x3;
  246. //! The generic light level of the world, including the bounces
  247. //! of all other lightsources.
  248. //! Typically, there's at most one ambient light in a scene.
  249. //! This light type doesn't have a valid position, direction, or
  250. //! other properties, just a color.
  251. //var aiLightSource_AMBIENT = 0x4;
  252. /** Flat shading. Shading is done on per-face base,
  253. * diffuse only. Also known as 'faceted shading'.
  254. */
  255. //var aiShadingMode_Flat = 0x1;
  256. /** Simple Gouraud shading.
  257. */
  258. //var aiShadingMode_Gouraud = 0x2;
  259. /** Phong-Shading -
  260. */
  261. //var aiShadingMode_Phong = 0x3;
  262. /** Phong-Blinn-Shading
  263. */
  264. //var aiShadingMode_Blinn = 0x4;
  265. /** Toon-Shading per pixel
  266. *
  267. * Also known as 'comic' shader.
  268. */
  269. //var aiShadingMode_Toon = 0x5;
  270. /** OrenNayar-Shading per pixel
  271. *
  272. * Extension to standard Lambertian shading, taking the
  273. * roughness of the material into account
  274. */
  275. //var aiShadingMode_OrenNayar = 0x6;
  276. /** Minnaert-Shading per pixel
  277. *
  278. * Extension to standard Lambertian shading, taking the
  279. * "darkness" of the material into account
  280. */
  281. //var aiShadingMode_Minnaert = 0x7;
  282. /** CookTorrance-Shading per pixel
  283. *
  284. * Special shader for metallic surfaces.
  285. */
  286. //var aiShadingMode_CookTorrance = 0x8;
  287. /** No shading at all. Constant light influence of 1.0.
  288. */
  289. //var aiShadingMode_NoShading = 0x9;
  290. /** Fresnel shading
  291. */
  292. //var aiShadingMode_Fresnel = 0xa;
  293. //var aiTextureType_NONE = 0x0;
  294. /** The texture is combined with the result of the diffuse
  295. * lighting equation.
  296. */
  297. var aiTextureType_DIFFUSE = 0x1;
  298. /** The texture is combined with the result of the specular
  299. * lighting equation.
  300. */
  301. //var aiTextureType_SPECULAR = 0x2;
  302. /** The texture is combined with the result of the ambient
  303. * lighting equation.
  304. */
  305. //var aiTextureType_AMBIENT = 0x3;
  306. /** The texture is added to the result of the lighting
  307. * calculation. It isn't influenced by incoming light.
  308. */
  309. //var aiTextureType_EMISSIVE = 0x4;
  310. /** The texture is a height map.
  311. *
  312. * By convention, higher gray-scale values stand for
  313. * higher elevations from the base height.
  314. */
  315. //var aiTextureType_HEIGHT = 0x5;
  316. /** The texture is a (tangent space) normal-map.
  317. *
  318. * Again, there are several conventions for tangent-space
  319. * normal maps. Assimp does (intentionally) not
  320. * distinguish here.
  321. */
  322. var aiTextureType_NORMALS = 0x6;
  323. /** The texture defines the glossiness of the material.
  324. *
  325. * The glossiness is in fact the exponent of the specular
  326. * (phong) lighting equation. Usually there is a conversion
  327. * function defined to map the linear color values in the
  328. * texture to a suitable exponent. Have fun.
  329. */
  330. //var aiTextureType_SHININESS = 0x7;
  331. /** The texture defines per-pixel opacity.
  332. *
  333. * Usually 'white' means opaque and 'black' means
  334. * 'transparency'. Or quite the opposite. Have fun.
  335. */
  336. var aiTextureType_OPACITY = 0x8;
  337. /** Displacement texture
  338. *
  339. * The exact purpose and format is application-dependent.
  340. * Higher color values stand for higher vertex displacements.
  341. */
  342. //var aiTextureType_DISPLACEMENT = 0x9;
  343. /** Lightmap texture (aka Ambient Occlusion)
  344. *
  345. * Both 'Lightmaps' and dedicated 'ambient occlusion maps' are
  346. * covered by this material property. The texture contains a
  347. * scaling value for the final color value of a pixel. Its
  348. * intensity is not affected by incoming light.
  349. */
  350. var aiTextureType_LIGHTMAP = 0xA;
  351. /** Reflection texture
  352. *
  353. * Contains the color of a perfect mirror reflection.
  354. * Rarely used, almost never for real-time applications.
  355. */
  356. //var aiTextureType_REFLECTION = 0xB;
  357. /** Unknown texture
  358. *
  359. * A texture reference that does not match any of the definitions
  360. * above is considered to be 'unknown'. It is still imported,
  361. * but is excluded from any further postprocessing.
  362. */
  363. //var aiTextureType_UNKNOWN = 0xC;
  364. var BONESPERVERT = 4;
  365. function ASSBIN_MESH_HAS_TEXCOORD( n ) {
  366. return ASSBIN_MESH_HAS_TEXCOORD_BASE << n;
  367. }
  368. function ASSBIN_MESH_HAS_COLOR( n ) {
  369. return ASSBIN_MESH_HAS_COLOR_BASE << n;
  370. }
  371. function markBones( scene ) {
  372. for ( var i in scene.mMeshes ) {
  373. var mesh = scene.mMeshes[ i ];
  374. for ( var k in mesh.mBones ) {
  375. var boneNode = scene.findNode( mesh.mBones[ k ].mName );
  376. if ( boneNode )
  377. boneNode.isBone = true;
  378. }
  379. }
  380. }
  381. function cloneTreeToBones( root, scene ) {
  382. var rootBone = new THREE.Bone();
  383. rootBone.matrix.copy( root.matrix );
  384. rootBone.matrixWorld.copy( root.matrixWorld );
  385. rootBone.position.copy( root.position );
  386. rootBone.quaternion.copy( root.quaternion );
  387. rootBone.scale.copy( root.scale );
  388. scene.nodeCount ++;
  389. rootBone.name = "bone_" + root.name + scene.nodeCount.toString();
  390. if ( ! scene.nodeToBoneMap[ root.name ] )
  391. scene.nodeToBoneMap[ root.name ] = [];
  392. scene.nodeToBoneMap[ root.name ].push( rootBone );
  393. for ( var i in root.children ) {
  394. var child = cloneTreeToBones( root.children[ i ], scene );
  395. rootBone.add( child );
  396. }
  397. return rootBone;
  398. }
  399. function sortWeights( indexes, weights ) {
  400. var pairs = [];
  401. for ( var i = 0; i < indexes.length; i ++ ) {
  402. pairs.push( {
  403. i: indexes[ i ],
  404. w: weights[ i ]
  405. } );
  406. }
  407. pairs.sort( function ( a, b ) {
  408. return b.w - a.w;
  409. } );
  410. while ( pairs.length < 4 ) {
  411. pairs.push( {
  412. i: 0,
  413. w: 0
  414. } );
  415. }
  416. if ( pairs.length > 4 )
  417. pairs.length = 4;
  418. var sum = 0;
  419. for ( var i = 0; i < 4; i ++ ) {
  420. sum += pairs[ i ].w * pairs[ i ].w;
  421. }
  422. sum = Math.sqrt( sum );
  423. for ( var i = 0; i < 4; i ++ ) {
  424. pairs[ i ].w = pairs[ i ].w / sum;
  425. indexes[ i ] = pairs[ i ].i;
  426. weights[ i ] = pairs[ i ].w;
  427. }
  428. }
  429. function findMatchingBone( root, name ) {
  430. if ( root.name.indexOf( "bone_" + name ) == 0 )
  431. return root;
  432. for ( var i in root.children ) {
  433. var ret = findMatchingBone( root.children[ i ], name );
  434. if ( ret )
  435. return ret;
  436. }
  437. return undefined;
  438. }
  439. function aiMesh() {
  440. this.mPrimitiveTypes = 0;
  441. this.mNumVertices = 0;
  442. this.mNumFaces = 0;
  443. this.mNumBones = 0;
  444. this.mMaterialIndex = 0;
  445. this.mVertices = [];
  446. this.mNormals = [];
  447. this.mTangents = [];
  448. this.mBitangents = [];
  449. this.mColors = [
  450. []
  451. ];
  452. this.mTextureCoords = [
  453. []
  454. ];
  455. this.mFaces = [];
  456. this.mBones = [];
  457. this.hookupSkeletons = function ( scene ) {
  458. if ( this.mBones.length == 0 ) return;
  459. var allBones = [];
  460. var offsetMatrix = [];
  461. var skeletonRoot = scene.findNode( this.mBones[ 0 ].mName );
  462. while ( skeletonRoot.mParent && skeletonRoot.mParent.isBone ) {
  463. skeletonRoot = skeletonRoot.mParent;
  464. }
  465. var threeSkeletonRoot = skeletonRoot.toTHREE( scene );
  466. var threeSkeletonRootBone = cloneTreeToBones( threeSkeletonRoot, scene );
  467. this.threeNode.add( threeSkeletonRootBone );
  468. for ( var i = 0; i < this.mBones.length; i ++ ) {
  469. var bone = findMatchingBone( threeSkeletonRootBone, this.mBones[ i ].mName );
  470. if ( bone ) {
  471. var tbone = bone;
  472. allBones.push( tbone );
  473. //tbone.matrixAutoUpdate = false;
  474. offsetMatrix.push( this.mBones[ i ].mOffsetMatrix.toTHREE() );
  475. } else {
  476. var skeletonRoot = scene.findNode( this.mBones[ i ].mName );
  477. if ( ! skeletonRoot ) return;
  478. var threeSkeletonRoot = skeletonRoot.toTHREE( scene );
  479. var threeSkeletonRootBone = cloneTreeToBones( threeSkeletonRoot, scene );
  480. this.threeNode.add( threeSkeletonRootBone );
  481. var bone = findMatchingBone( threeSkeletonRootBone, this.mBones[ i ].mName );
  482. var tbone = bone;
  483. allBones.push( tbone );
  484. //tbone.matrixAutoUpdate = false;
  485. offsetMatrix.push( this.mBones[ i ].mOffsetMatrix.toTHREE() );
  486. }
  487. }
  488. var skeleton = new THREE.Skeleton( allBones, offsetMatrix );
  489. this.threeNode.bind( skeleton, new THREE.Matrix4() );
  490. this.threeNode.material.skinning = true;
  491. };
  492. this.toTHREE = function ( scene ) {
  493. if ( this.threeNode ) return this.threeNode;
  494. var geometry = new THREE.BufferGeometry();
  495. var mat;
  496. if ( scene.mMaterials[ this.mMaterialIndex ] )
  497. mat = scene.mMaterials[ this.mMaterialIndex ].toTHREE( scene );
  498. else
  499. mat = new THREE.MeshLambertMaterial();
  500. geometry.setIndex( new THREE.BufferAttribute( new Uint32Array( this.mIndexArray ), 1 ) );
  501. geometry.setAttribute( 'position', new THREE.BufferAttribute( this.mVertexBuffer, 3 ) );
  502. if ( this.mNormalBuffer && this.mNormalBuffer.length > 0 )
  503. geometry.setAttribute( 'normal', new THREE.BufferAttribute( this.mNormalBuffer, 3 ) );
  504. if ( this.mColorBuffer && this.mColorBuffer.length > 0 )
  505. geometry.setAttribute( 'color', new THREE.BufferAttribute( this.mColorBuffer, 4 ) );
  506. if ( this.mTexCoordsBuffers[ 0 ] && this.mTexCoordsBuffers[ 0 ].length > 0 )
  507. geometry.setAttribute( 'uv', new THREE.BufferAttribute( new Float32Array( this.mTexCoordsBuffers[ 0 ] ), 2 ) );
  508. if ( this.mTexCoordsBuffers[ 1 ] && this.mTexCoordsBuffers[ 1 ].length > 0 )
  509. geometry.setAttribute( 'uv1', new THREE.BufferAttribute( new Float32Array( this.mTexCoordsBuffers[ 1 ] ), 2 ) );
  510. if ( this.mTangentBuffer && this.mTangentBuffer.length > 0 )
  511. geometry.setAttribute( 'tangents', new THREE.BufferAttribute( this.mTangentBuffer, 3 ) );
  512. if ( this.mBitangentBuffer && this.mBitangentBuffer.length > 0 )
  513. geometry.setAttribute( 'bitangents', new THREE.BufferAttribute( this.mBitangentBuffer, 3 ) );
  514. if ( this.mBones.length > 0 ) {
  515. var weights = [];
  516. var bones = [];
  517. for ( var i = 0; i < this.mBones.length; i ++ ) {
  518. for ( var j = 0; j < this.mBones[ i ].mWeights.length; j ++ ) {
  519. var weight = this.mBones[ i ].mWeights[ j ];
  520. if ( weight ) {
  521. if ( ! weights[ weight.mVertexId ] ) weights[ weight.mVertexId ] = [];
  522. if ( ! bones[ weight.mVertexId ] ) bones[ weight.mVertexId ] = [];
  523. weights[ weight.mVertexId ].push( weight.mWeight );
  524. bones[ weight.mVertexId ].push( parseInt( i ) );
  525. }
  526. }
  527. }
  528. for ( var i in bones ) {
  529. sortWeights( bones[ i ], weights[ i ] );
  530. }
  531. var _weights = [];
  532. var _bones = [];
  533. for ( var i = 0; i < weights.length; i ++ ) {
  534. for ( var j = 0; j < 4; j ++ ) {
  535. if ( weights[ i ] && bones[ i ] ) {
  536. _weights.push( weights[ i ][ j ] );
  537. _bones.push( bones[ i ][ j ] );
  538. } else {
  539. _weights.push( 0 );
  540. _bones.push( 0 );
  541. }
  542. }
  543. }
  544. geometry.setAttribute( 'skinWeight', new THREE.BufferAttribute( new Float32Array( _weights ), BONESPERVERT ) );
  545. geometry.setAttribute( 'skinIndex', new THREE.BufferAttribute( new Float32Array( _bones ), BONESPERVERT ) );
  546. }
  547. var mesh;
  548. if ( this.mBones.length == 0 )
  549. mesh = new THREE.Mesh( geometry, mat );
  550. if ( this.mBones.length > 0 ) {
  551. mesh = new THREE.SkinnedMesh( geometry, mat );
  552. mesh.normalizeSkinWeights();
  553. }
  554. this.threeNode = mesh;
  555. //mesh.matrixAutoUpdate = false;
  556. return mesh;
  557. };
  558. }
  559. function aiFace() {
  560. this.mNumIndices = 0;
  561. this.mIndices = [];
  562. }
  563. function aiVector3D() {
  564. this.x = 0;
  565. this.y = 0;
  566. this.z = 0;
  567. this.toTHREE = function () {
  568. return new THREE.Vector3( this.x, this.y, this.z );
  569. };
  570. }
  571. function aiColor3D() {
  572. this.r = 0;
  573. this.g = 0;
  574. this.b = 0;
  575. this.a = 0;
  576. this.toTHREE = function () {
  577. return new THREE.Color( this.r, this.g, this.b );
  578. };
  579. }
  580. function aiQuaternion() {
  581. this.x = 0;
  582. this.y = 0;
  583. this.z = 0;
  584. this.w = 0;
  585. this.toTHREE = function () {
  586. return new THREE.Quaternion( this.x, this.y, this.z, this.w );
  587. };
  588. }
  589. function aiVertexWeight() {
  590. this.mVertexId = 0;
  591. this.mWeight = 0;
  592. }
  593. function aiString() {
  594. this.data = [];
  595. this.toString = function () {
  596. var str = '';
  597. this.data.forEach( function ( i ) {
  598. str += ( String.fromCharCode( i ) );
  599. } );
  600. return str.replace( /[^\x20-\x7E]+/g, '' );
  601. };
  602. }
  603. function aiVectorKey() {
  604. this.mTime = 0;
  605. this.mValue = null;
  606. }
  607. function aiQuatKey() {
  608. this.mTime = 0;
  609. this.mValue = null;
  610. }
  611. function aiNode() {
  612. this.mName = '';
  613. this.mTransformation = [];
  614. this.mNumChildren = 0;
  615. this.mNumMeshes = 0;
  616. this.mMeshes = [];
  617. this.mChildren = [];
  618. this.toTHREE = function ( scene ) {
  619. if ( this.threeNode ) return this.threeNode;
  620. var o = new THREE.Object3D();
  621. o.name = this.mName;
  622. o.matrix = this.mTransformation.toTHREE();
  623. for ( var i = 0; i < this.mChildren.length; i ++ ) {
  624. o.add( this.mChildren[ i ].toTHREE( scene ) );
  625. }
  626. for ( var i = 0; i < this.mMeshes.length; i ++ ) {
  627. o.add( scene.mMeshes[ this.mMeshes[ i ] ].toTHREE( scene ) );
  628. }
  629. this.threeNode = o;
  630. //o.matrixAutoUpdate = false;
  631. o.matrix.decompose( o.position, o.quaternion, o.scale );
  632. return o;
  633. };
  634. }
  635. function aiBone() {
  636. this.mName = '';
  637. this.mNumWeights = 0;
  638. this.mOffsetMatrix = 0;
  639. }
  640. function aiMaterialProperty() {
  641. this.mKey = "";
  642. this.mSemantic = 0;
  643. this.mIndex = 0;
  644. this.mData = [];
  645. this.mDataLength = 0;
  646. this.mType = 0;
  647. this.dataAsColor = function () {
  648. var array = ( new Uint8Array( this.mData ) ).buffer;
  649. var reader = new DataView( array );
  650. var r = reader.getFloat32( 0, true );
  651. var g = reader.getFloat32( 4, true );
  652. var b = reader.getFloat32( 8, true );
  653. //var a = reader.getFloat32(12, true);
  654. return new THREE.Color( r, g, b );
  655. };
  656. this.dataAsFloat = function () {
  657. var array = ( new Uint8Array( this.mData ) ).buffer;
  658. var reader = new DataView( array );
  659. var r = reader.getFloat32( 0, true );
  660. return r;
  661. };
  662. this.dataAsBool = function () {
  663. var array = ( new Uint8Array( this.mData ) ).buffer;
  664. var reader = new DataView( array );
  665. var r = reader.getFloat32( 0, true );
  666. return !! r;
  667. };
  668. this.dataAsString = function () {
  669. var s = new aiString();
  670. s.data = this.mData;
  671. return s.toString();
  672. };
  673. this.dataAsMap = function () {
  674. var s = new aiString();
  675. s.data = this.mData;
  676. var path = s.toString();
  677. path = path.replace( /\\/g, '/' );
  678. if ( path.indexOf( '/' ) != - 1 ) {
  679. path = path.substr( path.lastIndexOf( '/' ) + 1 );
  680. }
  681. return textureLoader.load( path );
  682. };
  683. }
  684. var namePropMapping = {
  685. "?mat.name": "name",
  686. "$mat.shadingm": "shading",
  687. "$mat.twosided": "twoSided",
  688. "$mat.wireframe": "wireframe",
  689. "$clr.ambient": "ambient",
  690. "$clr.diffuse": "color",
  691. "$clr.specular": "specular",
  692. "$clr.emissive": "emissive",
  693. "$clr.transparent": "transparent",
  694. "$clr.reflective": "reflect",
  695. "$mat.shininess": "shininess",
  696. "$mat.reflectivity": "reflectivity",
  697. "$mat.refracti": "refraction",
  698. "$tex.file": "map"
  699. };
  700. var nameTypeMapping = {
  701. "?mat.name": "string",
  702. "$mat.shadingm": "bool",
  703. "$mat.twosided": "bool",
  704. "$mat.wireframe": "bool",
  705. "$clr.ambient": "color",
  706. "$clr.diffuse": "color",
  707. "$clr.specular": "color",
  708. "$clr.emissive": "color",
  709. "$clr.transparent": "color",
  710. "$clr.reflective": "color",
  711. "$mat.shininess": "float",
  712. "$mat.reflectivity": "float",
  713. "$mat.refracti": "float",
  714. "$tex.file": "map"
  715. };
  716. function aiMaterial() {
  717. this.mNumAllocated = 0;
  718. this.mNumProperties = 0;
  719. this.mProperties = [];
  720. this.toTHREE = function () {
  721. var mat = new THREE.MeshPhongMaterial();
  722. for ( var i = 0; i < this.mProperties.length; i ++ ) {
  723. if ( nameTypeMapping[ this.mProperties[ i ].mKey ] == 'float' )
  724. mat[ namePropMapping[ this.mProperties[ i ].mKey ] ] = this.mProperties[ i ].dataAsFloat();
  725. if ( nameTypeMapping[ this.mProperties[ i ].mKey ] == 'color' )
  726. mat[ namePropMapping[ this.mProperties[ i ].mKey ] ] = this.mProperties[ i ].dataAsColor();
  727. if ( nameTypeMapping[ this.mProperties[ i ].mKey ] == 'bool' )
  728. mat[ namePropMapping[ this.mProperties[ i ].mKey ] ] = this.mProperties[ i ].dataAsBool();
  729. if ( nameTypeMapping[ this.mProperties[ i ].mKey ] == 'string' )
  730. mat[ namePropMapping[ this.mProperties[ i ].mKey ] ] = this.mProperties[ i ].dataAsString();
  731. if ( nameTypeMapping[ this.mProperties[ i ].mKey ] == 'map' ) {
  732. var prop = this.mProperties[ i ];
  733. if ( prop.mSemantic == aiTextureType_DIFFUSE )
  734. mat.map = this.mProperties[ i ].dataAsMap();
  735. if ( prop.mSemantic == aiTextureType_NORMALS )
  736. mat.normalMap = this.mProperties[ i ].dataAsMap();
  737. if ( prop.mSemantic == aiTextureType_LIGHTMAP )
  738. mat.lightMap = this.mProperties[ i ].dataAsMap();
  739. if ( prop.mSemantic == aiTextureType_OPACITY )
  740. mat.alphaMap = this.mProperties[ i ].dataAsMap();
  741. }
  742. }
  743. mat.ambient.r = .53;
  744. mat.ambient.g = .53;
  745. mat.ambient.b = .53;
  746. mat.color.r = 1;
  747. mat.color.g = 1;
  748. mat.color.b = 1;
  749. return mat;
  750. };
  751. }
  752. function veclerp( v1, v2, l ) {
  753. var v = new THREE.Vector3();
  754. var lm1 = 1 - l;
  755. v.x = v1.x * l + v2.x * lm1;
  756. v.y = v1.y * l + v2.y * lm1;
  757. v.z = v1.z * l + v2.z * lm1;
  758. return v;
  759. }
  760. function quatlerp( q1, q2, l ) {
  761. return q1.clone().slerp( q2, 1 - l );
  762. }
  763. function sampleTrack( keys, time, lne, lerp ) {
  764. if ( keys.length == 1 ) return keys[ 0 ].mValue.toTHREE();
  765. var dist = Infinity;
  766. var key = null;
  767. var nextKey = null;
  768. for ( var i = 0; i < keys.length; i ++ ) {
  769. var timeDist = Math.abs( keys[ i ].mTime - time );
  770. if ( timeDist < dist && keys[ i ].mTime <= time ) {
  771. dist = timeDist;
  772. key = keys[ i ];
  773. nextKey = keys[ i + 1 ];
  774. }
  775. }
  776. if ( ! key ) {
  777. return null;
  778. } else if ( nextKey ) {
  779. var dT = nextKey.mTime - key.mTime;
  780. var T = key.mTime - time;
  781. var l = T / dT;
  782. return lerp( key.mValue.toTHREE(), nextKey.mValue.toTHREE(), l );
  783. } else {
  784. nextKey = keys[ 0 ].clone();
  785. nextKey.mTime += lne;
  786. var dT = nextKey.mTime - key.mTime;
  787. var T = key.mTime - time;
  788. var l = T / dT;
  789. return lerp( key.mValue.toTHREE(), nextKey.mValue.toTHREE(), l );
  790. }
  791. }
  792. function aiNodeAnim() {
  793. this.mNodeName = "";
  794. this.mNumPositionKeys = 0;
  795. this.mNumRotationKeys = 0;
  796. this.mNumScalingKeys = 0;
  797. this.mPositionKeys = [];
  798. this.mRotationKeys = [];
  799. this.mScalingKeys = [];
  800. this.mPreState = "";
  801. this.mPostState = "";
  802. this.init = function ( tps ) {
  803. if ( ! tps ) tps = 1;
  804. function t( t ) {
  805. t.mTime /= tps;
  806. }
  807. this.mPositionKeys.forEach( t );
  808. this.mRotationKeys.forEach( t );
  809. this.mScalingKeys.forEach( t );
  810. };
  811. this.sortKeys = function () {
  812. function comp( a, b ) {
  813. return a.mTime - b.mTime;
  814. }
  815. this.mPositionKeys.sort( comp );
  816. this.mRotationKeys.sort( comp );
  817. this.mScalingKeys.sort( comp );
  818. };
  819. this.getLength = function () {
  820. return Math.max(
  821. Math.max.apply( null, this.mPositionKeys.map( function ( a ) {
  822. return a.mTime;
  823. } ) ),
  824. Math.max.apply( null, this.mRotationKeys.map( function ( a ) {
  825. return a.mTime;
  826. } ) ),
  827. Math.max.apply( null, this.mScalingKeys.map( function ( a ) {
  828. return a.mTime;
  829. } ) )
  830. );
  831. };
  832. this.toTHREE = function ( o ) {
  833. this.sortKeys();
  834. var length = this.getLength();
  835. var track = new Virtulous.KeyFrameTrack();
  836. for ( var i = 0; i < length; i += .05 ) {
  837. var matrix = new THREE.Matrix4();
  838. var time = i;
  839. var pos = sampleTrack( this.mPositionKeys, time, length, veclerp );
  840. var scale = sampleTrack( this.mScalingKeys, time, length, veclerp );
  841. var rotation = sampleTrack( this.mRotationKeys, time, length, quatlerp );
  842. matrix.compose( pos, rotation, scale );
  843. var key = new Virtulous.KeyFrame( time, matrix );
  844. track.addKey( key );
  845. }
  846. track.target = o.findNode( this.mNodeName ).toTHREE();
  847. var tracks = [ track ];
  848. if ( o.nodeToBoneMap[ this.mNodeName ] ) {
  849. for ( var i = 0; i < o.nodeToBoneMap[ this.mNodeName ].length; i ++ ) {
  850. var t2 = track.clone();
  851. t2.target = o.nodeToBoneMap[ this.mNodeName ][ i ];
  852. tracks.push( t2 );
  853. }
  854. }
  855. return tracks;
  856. };
  857. }
  858. function aiAnimation() {
  859. this.mName = "";
  860. this.mDuration = 0;
  861. this.mTicksPerSecond = 0;
  862. this.mNumChannels = 0;
  863. this.mChannels = [];
  864. this.toTHREE = function ( root ) {
  865. var animationHandle = new Virtulous.Animation();
  866. for ( var i in this.mChannels ) {
  867. this.mChannels[ i ].init( this.mTicksPerSecond );
  868. var tracks = this.mChannels[ i ].toTHREE( root );
  869. for ( var j in tracks ) {
  870. tracks[ j ].init();
  871. animationHandle.addTrack( tracks[ j ] );
  872. }
  873. }
  874. animationHandle.length = Math.max.apply( null, animationHandle.tracks.map( function ( e ) {
  875. return e.length;
  876. } ) );
  877. return animationHandle;
  878. };
  879. }
  880. function aiTexture() {
  881. this.mWidth = 0;
  882. this.mHeight = 0;
  883. this.texAchFormatHint = [];
  884. this.pcData = [];
  885. }
  886. function aiLight() {
  887. this.mName = '';
  888. this.mType = 0;
  889. this.mAttenuationConstant = 0;
  890. this.mAttenuationLinear = 0;
  891. this.mAttenuationQuadratic = 0;
  892. this.mAngleInnerCone = 0;
  893. this.mAngleOuterCone = 0;
  894. this.mColorDiffuse = null;
  895. this.mColorSpecular = null;
  896. this.mColorAmbient = null;
  897. }
  898. function aiCamera() {
  899. this.mName = '';
  900. this.mPosition = null;
  901. this.mLookAt = null;
  902. this.mUp = null;
  903. this.mHorizontalFOV = 0;
  904. this.mClipPlaneNear = 0;
  905. this.mClipPlaneFar = 0;
  906. this.mAspect = 0;
  907. }
  908. function aiScene() {
  909. this.versionMajor = 0;
  910. this.versionMinor = 0;
  911. this.versionRevision = 0;
  912. this.compileFlags = 0;
  913. this.mFlags = 0;
  914. this.mNumMeshes = 0;
  915. this.mNumMaterials = 0;
  916. this.mNumAnimations = 0;
  917. this.mNumTextures = 0;
  918. this.mNumLights = 0;
  919. this.mNumCameras = 0;
  920. this.mRootNode = null;
  921. this.mMeshes = [];
  922. this.mMaterials = [];
  923. this.mAnimations = [];
  924. this.mLights = [];
  925. this.mCameras = [];
  926. this.nodeToBoneMap = {};
  927. this.findNode = function ( name, root ) {
  928. if ( ! root ) {
  929. root = this.mRootNode;
  930. }
  931. if ( root.mName == name ) {
  932. return root;
  933. }
  934. for ( var i = 0; i < root.mChildren.length; i ++ ) {
  935. var ret = this.findNode( name, root.mChildren[ i ] );
  936. if ( ret ) return ret;
  937. }
  938. return null;
  939. };
  940. this.toTHREE = function () {
  941. this.nodeCount = 0;
  942. markBones( this );
  943. var o = this.mRootNode.toTHREE( this );
  944. for ( var i in this.mMeshes )
  945. this.mMeshes[ i ].hookupSkeletons( this );
  946. if ( this.mAnimations.length > 0 ) {
  947. var a = this.mAnimations[ 0 ].toTHREE( this );
  948. }
  949. return { object: o, animation: a };
  950. };
  951. }
  952. function aiMatrix4() {
  953. this.elements = [
  954. [],
  955. [],
  956. [],
  957. []
  958. ];
  959. this.toTHREE = function () {
  960. var m = new THREE.Matrix4();
  961. for ( var i = 0; i < 4; ++ i ) {
  962. for ( var i2 = 0; i2 < 4; ++ i2 ) {
  963. m.elements[ i * 4 + i2 ] = this.elements[ i2 ][ i ];
  964. }
  965. }
  966. return m;
  967. };
  968. }
  969. var littleEndian = true;
  970. function readFloat( dataview ) {
  971. var val = dataview.getFloat32( dataview.readOffset, littleEndian );
  972. dataview.readOffset += 4;
  973. return val;
  974. }
  975. function Read_double( dataview ) {
  976. var val = dataview.getFloat64( dataview.readOffset, littleEndian );
  977. dataview.readOffset += 8;
  978. return val;
  979. }
  980. function Read_uint8_t( dataview ) {
  981. var val = dataview.getUint8( dataview.readOffset );
  982. dataview.readOffset += 1;
  983. return val;
  984. }
  985. function Read_uint16_t( dataview ) {
  986. var val = dataview.getUint16( dataview.readOffset, littleEndian );
  987. dataview.readOffset += 2;
  988. return val;
  989. }
  990. function Read_unsigned_int( dataview ) {
  991. var val = dataview.getUint32( dataview.readOffset, littleEndian );
  992. dataview.readOffset += 4;
  993. return val;
  994. }
  995. function Read_uint32_t( dataview ) {
  996. var val = dataview.getUint32( dataview.readOffset, littleEndian );
  997. dataview.readOffset += 4;
  998. return val;
  999. }
  1000. function Read_aiVector3D( stream ) {
  1001. var v = new aiVector3D();
  1002. v.x = readFloat( stream );
  1003. v.y = readFloat( stream );
  1004. v.z = readFloat( stream );
  1005. return v;
  1006. }
  1007. function Read_aiColor3D( stream ) {
  1008. var c = new aiColor3D();
  1009. c.r = readFloat( stream );
  1010. c.g = readFloat( stream );
  1011. c.b = readFloat( stream );
  1012. return c;
  1013. }
  1014. function Read_aiQuaternion( stream ) {
  1015. var v = new aiQuaternion();
  1016. v.w = readFloat( stream );
  1017. v.x = readFloat( stream );
  1018. v.y = readFloat( stream );
  1019. v.z = readFloat( stream );
  1020. return v;
  1021. }
  1022. function Read_aiString( stream ) {
  1023. var s = new aiString();
  1024. var stringlengthbytes = Read_unsigned_int( stream );
  1025. stream.ReadBytes( s.data, 1, stringlengthbytes );
  1026. return s.toString();
  1027. }
  1028. function Read_aiVertexWeight( stream ) {
  1029. var w = new aiVertexWeight();
  1030. w.mVertexId = Read_unsigned_int( stream );
  1031. w.mWeight = readFloat( stream );
  1032. return w;
  1033. }
  1034. function Read_aiMatrix4x4( stream ) {
  1035. var m = new aiMatrix4();
  1036. for ( var i = 0; i < 4; ++ i ) {
  1037. for ( var i2 = 0; i2 < 4; ++ i2 ) {
  1038. m.elements[ i ][ i2 ] = readFloat( stream );
  1039. }
  1040. }
  1041. return m;
  1042. }
  1043. function Read_aiVectorKey( stream ) {
  1044. var v = new aiVectorKey();
  1045. v.mTime = Read_double( stream );
  1046. v.mValue = Read_aiVector3D( stream );
  1047. return v;
  1048. }
  1049. function Read_aiQuatKey( stream ) {
  1050. var v = new aiQuatKey();
  1051. v.mTime = Read_double( stream );
  1052. v.mValue = Read_aiQuaternion( stream );
  1053. return v;
  1054. }
  1055. function ReadArray_aiVertexWeight( stream, data, size ) {
  1056. for ( var i = 0; i < size; i ++ ) data[ i ] = Read_aiVertexWeight( stream );
  1057. }
  1058. function ReadArray_aiVectorKey( stream, data, size ) {
  1059. for ( var i = 0; i < size; i ++ ) data[ i ] = Read_aiVectorKey( stream );
  1060. }
  1061. function ReadArray_aiQuatKey( stream, data, size ) {
  1062. for ( var i = 0; i < size; i ++ ) data[ i ] = Read_aiQuatKey( stream );
  1063. }
  1064. function ReadBounds( stream, T /*p*/, n ) {
  1065. // not sure what to do here, the data isn't really useful.
  1066. return stream.Seek( sizeof( T ) * n, aiOrigin_CUR );
  1067. }
  1068. function ai_assert( bool ) {
  1069. if ( ! bool )
  1070. throw ( "asset failed" );
  1071. }
  1072. function ReadBinaryNode( stream, parent, depth ) {
  1073. var chunkID = Read_uint32_t( stream );
  1074. ai_assert( chunkID == ASSBIN_CHUNK_AINODE );
  1075. /*uint32_t size =*/
  1076. Read_uint32_t( stream );
  1077. var node = new aiNode();
  1078. node.mParent = parent;
  1079. node.mDepth = depth;
  1080. node.mName = Read_aiString( stream );
  1081. node.mTransformation = Read_aiMatrix4x4( stream );
  1082. node.mNumChildren = Read_unsigned_int( stream );
  1083. node.mNumMeshes = Read_unsigned_int( stream );
  1084. if ( node.mNumMeshes ) {
  1085. node.mMeshes = [];
  1086. for ( var i = 0; i < node.mNumMeshes; ++ i ) {
  1087. node.mMeshes[ i ] = Read_unsigned_int( stream );
  1088. }
  1089. }
  1090. if ( node.mNumChildren ) {
  1091. node.mChildren = [];
  1092. for ( var i = 0; i < node.mNumChildren; ++ i ) {
  1093. var node2 = ReadBinaryNode( stream, node, depth ++ );
  1094. node.mChildren[ i ] = node2;
  1095. }
  1096. }
  1097. return node;
  1098. }
  1099. // -----------------------------------------------------------------------------------
  1100. function ReadBinaryBone( stream, b ) {
  1101. var chunkID = Read_uint32_t( stream );
  1102. ai_assert( chunkID == ASSBIN_CHUNK_AIBONE );
  1103. /*uint32_t size =*/
  1104. Read_uint32_t( stream );
  1105. b.mName = Read_aiString( stream );
  1106. b.mNumWeights = Read_unsigned_int( stream );
  1107. b.mOffsetMatrix = Read_aiMatrix4x4( stream );
  1108. // for the moment we write dumb min/max values for the bones, too.
  1109. // maybe I'll add a better, hash-like solution later
  1110. if ( shortened ) {
  1111. ReadBounds( stream, b.mWeights, b.mNumWeights );
  1112. } else {
  1113. // else write as usual
  1114. b.mWeights = [];
  1115. ReadArray_aiVertexWeight( stream, b.mWeights, b.mNumWeights );
  1116. }
  1117. return b;
  1118. }
  1119. function ReadBinaryMesh( stream, mesh ) {
  1120. var chunkID = Read_uint32_t( stream );
  1121. ai_assert( chunkID == ASSBIN_CHUNK_AIMESH );
  1122. /*uint32_t size =*/
  1123. Read_uint32_t( stream );
  1124. mesh.mPrimitiveTypes = Read_unsigned_int( stream );
  1125. mesh.mNumVertices = Read_unsigned_int( stream );
  1126. mesh.mNumFaces = Read_unsigned_int( stream );
  1127. mesh.mNumBones = Read_unsigned_int( stream );
  1128. mesh.mMaterialIndex = Read_unsigned_int( stream );
  1129. mesh.mNumUVComponents = [];
  1130. // first of all, write bits for all existent vertex components
  1131. var c = Read_unsigned_int( stream );
  1132. if ( c & ASSBIN_MESH_HAS_POSITIONS ) {
  1133. if ( shortened ) {
  1134. ReadBounds( stream, mesh.mVertices, mesh.mNumVertices );
  1135. } else {
  1136. // else write as usual
  1137. mesh.mVertices = [];
  1138. mesh.mVertexBuffer = stream.subArray32( stream.readOffset, stream.readOffset + mesh.mNumVertices * 3 * 4 );
  1139. stream.Seek( mesh.mNumVertices * 3 * 4, aiOrigin_CUR );
  1140. }
  1141. }
  1142. if ( c & ASSBIN_MESH_HAS_NORMALS ) {
  1143. if ( shortened ) {
  1144. ReadBounds( stream, mesh.mNormals, mesh.mNumVertices );
  1145. } else {
  1146. // else write as usual
  1147. mesh.mNormals = [];
  1148. mesh.mNormalBuffer = stream.subArray32( stream.readOffset, stream.readOffset + mesh.mNumVertices * 3 * 4 );
  1149. stream.Seek( mesh.mNumVertices * 3 * 4, aiOrigin_CUR );
  1150. }
  1151. }
  1152. if ( c & ASSBIN_MESH_HAS_TANGENTS_AND_BITANGENTS ) {
  1153. if ( shortened ) {
  1154. ReadBounds( stream, mesh.mTangents, mesh.mNumVertices );
  1155. ReadBounds( stream, mesh.mBitangents, mesh.mNumVertices );
  1156. } else {
  1157. // else write as usual
  1158. mesh.mTangents = [];
  1159. mesh.mTangentBuffer = stream.subArray32( stream.readOffset, stream.readOffset + mesh.mNumVertices * 3 * 4 );
  1160. stream.Seek( mesh.mNumVertices * 3 * 4, aiOrigin_CUR );
  1161. mesh.mBitangents = [];
  1162. mesh.mBitangentBuffer = stream.subArray32( stream.readOffset, stream.readOffset + mesh.mNumVertices * 3 * 4 );
  1163. stream.Seek( mesh.mNumVertices * 3 * 4, aiOrigin_CUR );
  1164. }
  1165. }
  1166. for ( var n = 0; n < AI_MAX_NUMBER_OF_COLOR_SETS; ++ n ) {
  1167. if ( ! ( c & ASSBIN_MESH_HAS_COLOR( n ) ) ) break;
  1168. if ( shortened ) {
  1169. ReadBounds( stream, mesh.mColors[ n ], mesh.mNumVertices );
  1170. } else {
  1171. // else write as usual
  1172. mesh.mColors[ n ] = [];
  1173. mesh.mColorBuffer = stream.subArray32( stream.readOffset, stream.readOffset + mesh.mNumVertices * 4 * 4 );
  1174. stream.Seek( mesh.mNumVertices * 4 * 4, aiOrigin_CUR );
  1175. }
  1176. }
  1177. mesh.mTexCoordsBuffers = [];
  1178. for ( var n = 0; n < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++ n ) {
  1179. if ( ! ( c & ASSBIN_MESH_HAS_TEXCOORD( n ) ) ) break;
  1180. // write number of UV components
  1181. mesh.mNumUVComponents[ n ] = Read_unsigned_int( stream );
  1182. if ( shortened ) {
  1183. ReadBounds( stream, mesh.mTextureCoords[ n ], mesh.mNumVertices );
  1184. } else {
  1185. // else write as usual
  1186. mesh.mTextureCoords[ n ] = [];
  1187. //note that assbin always writes 3d texcoords
  1188. mesh.mTexCoordsBuffers[ n ] = [];
  1189. for ( var uv = 0; uv < mesh.mNumVertices; uv ++ ) {
  1190. mesh.mTexCoordsBuffers[ n ].push( readFloat( stream ) );
  1191. mesh.mTexCoordsBuffers[ n ].push( readFloat( stream ) );
  1192. readFloat( stream );
  1193. }
  1194. }
  1195. }
  1196. // write faces. There are no floating-point calculations involved
  1197. // in these, so we can write a simple hash over the face data
  1198. // to the dump file. We generate a single 32 Bit hash for 512 faces
  1199. // using Assimp's standard hashing function.
  1200. if ( shortened ) {
  1201. Read_unsigned_int( stream );
  1202. } else {
  1203. // else write as usual
  1204. // if there are less than 2^16 vertices, we can simply use 16 bit integers ...
  1205. mesh.mFaces = [];
  1206. mesh.mIndexArray = [];
  1207. for ( var i = 0; i < mesh.mNumFaces; ++ i ) {
  1208. var f = mesh.mFaces[ i ] = new aiFace();
  1209. // BOOST_STATIC_ASSERT(AI_MAX_FACE_INDICES <= 0xffff);
  1210. f.mNumIndices = Read_uint16_t( stream );
  1211. f.mIndices = [];
  1212. for ( var a = 0; a < f.mNumIndices; ++ a ) {
  1213. if ( mesh.mNumVertices < ( 1 << 16 ) ) {
  1214. f.mIndices[ a ] = Read_uint16_t( stream );
  1215. } else {
  1216. f.mIndices[ a ] = Read_unsigned_int( stream );
  1217. }
  1218. }
  1219. if ( f.mNumIndices === 3 ) {
  1220. mesh.mIndexArray.push( f.mIndices[ 0 ] );
  1221. mesh.mIndexArray.push( f.mIndices[ 1 ] );
  1222. mesh.mIndexArray.push( f.mIndices[ 2 ] );
  1223. } else if ( f.mNumIndices === 4 ) {
  1224. mesh.mIndexArray.push( f.mIndices[ 0 ] );
  1225. mesh.mIndexArray.push( f.mIndices[ 1 ] );
  1226. mesh.mIndexArray.push( f.mIndices[ 2 ] );
  1227. mesh.mIndexArray.push( f.mIndices[ 2 ] );
  1228. mesh.mIndexArray.push( f.mIndices[ 3 ] );
  1229. mesh.mIndexArray.push( f.mIndices[ 0 ] );
  1230. } else {
  1231. throw ( new Error( "Sorry, can't currently triangulate polys. Use the triangulate preprocessor in Assimp." ) );
  1232. }
  1233. }
  1234. }
  1235. // write bones
  1236. if ( mesh.mNumBones ) {
  1237. mesh.mBones = [];
  1238. for ( var a = 0; a < mesh.mNumBones; ++ a ) {
  1239. mesh.mBones[ a ] = new aiBone();
  1240. ReadBinaryBone( stream, mesh.mBones[ a ] );
  1241. }
  1242. }
  1243. }
  1244. function ReadBinaryMaterialProperty( stream, prop ) {
  1245. var chunkID = Read_uint32_t( stream );
  1246. ai_assert( chunkID == ASSBIN_CHUNK_AIMATERIALPROPERTY );
  1247. /*uint32_t size =*/
  1248. Read_uint32_t( stream );
  1249. prop.mKey = Read_aiString( stream );
  1250. prop.mSemantic = Read_unsigned_int( stream );
  1251. prop.mIndex = Read_unsigned_int( stream );
  1252. prop.mDataLength = Read_unsigned_int( stream );
  1253. prop.mType = Read_unsigned_int( stream );
  1254. prop.mData = [];
  1255. stream.ReadBytes( prop.mData, 1, prop.mDataLength );
  1256. }
  1257. // -----------------------------------------------------------------------------------
  1258. function ReadBinaryMaterial( stream, mat ) {
  1259. var chunkID = Read_uint32_t( stream );
  1260. ai_assert( chunkID == ASSBIN_CHUNK_AIMATERIAL );
  1261. /*uint32_t size =*/
  1262. Read_uint32_t( stream );
  1263. mat.mNumAllocated = mat.mNumProperties = Read_unsigned_int( stream );
  1264. if ( mat.mNumProperties ) {
  1265. if ( mat.mProperties ) {
  1266. delete mat.mProperties;
  1267. }
  1268. mat.mProperties = [];
  1269. for ( var i = 0; i < mat.mNumProperties; ++ i ) {
  1270. mat.mProperties[ i ] = new aiMaterialProperty();
  1271. ReadBinaryMaterialProperty( stream, mat.mProperties[ i ] );
  1272. }
  1273. }
  1274. }
  1275. function ReadBinaryNodeAnim( stream, nd ) {
  1276. var chunkID = Read_uint32_t( stream );
  1277. ai_assert( chunkID == ASSBIN_CHUNK_AINODEANIM );
  1278. /*uint32_t size =*/
  1279. Read_uint32_t( stream );
  1280. nd.mNodeName = Read_aiString( stream );
  1281. nd.mNumPositionKeys = Read_unsigned_int( stream );
  1282. nd.mNumRotationKeys = Read_unsigned_int( stream );
  1283. nd.mNumScalingKeys = Read_unsigned_int( stream );
  1284. nd.mPreState = Read_unsigned_int( stream );
  1285. nd.mPostState = Read_unsigned_int( stream );
  1286. if ( nd.mNumPositionKeys ) {
  1287. if ( shortened ) {
  1288. ReadBounds( stream, nd.mPositionKeys, nd.mNumPositionKeys );
  1289. } else {
  1290. // else write as usual
  1291. nd.mPositionKeys = [];
  1292. ReadArray_aiVectorKey( stream, nd.mPositionKeys, nd.mNumPositionKeys );
  1293. }
  1294. }
  1295. if ( nd.mNumRotationKeys ) {
  1296. if ( shortened ) {
  1297. ReadBounds( stream, nd.mRotationKeys, nd.mNumRotationKeys );
  1298. } else {
  1299. // else write as usual
  1300. nd.mRotationKeys = [];
  1301. ReadArray_aiQuatKey( stream, nd.mRotationKeys, nd.mNumRotationKeys );
  1302. }
  1303. }
  1304. if ( nd.mNumScalingKeys ) {
  1305. if ( shortened ) {
  1306. ReadBounds( stream, nd.mScalingKeys, nd.mNumScalingKeys );
  1307. } else {
  1308. // else write as usual
  1309. nd.mScalingKeys = [];
  1310. ReadArray_aiVectorKey( stream, nd.mScalingKeys, nd.mNumScalingKeys );
  1311. }
  1312. }
  1313. }
  1314. function ReadBinaryAnim( stream, anim ) {
  1315. var chunkID = Read_uint32_t( stream );
  1316. ai_assert( chunkID == ASSBIN_CHUNK_AIANIMATION );
  1317. /*uint32_t size =*/
  1318. Read_uint32_t( stream );
  1319. anim.mName = Read_aiString( stream );
  1320. anim.mDuration = Read_double( stream );
  1321. anim.mTicksPerSecond = Read_double( stream );
  1322. anim.mNumChannels = Read_unsigned_int( stream );
  1323. if ( anim.mNumChannels ) {
  1324. anim.mChannels = [];
  1325. for ( var a = 0; a < anim.mNumChannels; ++ a ) {
  1326. anim.mChannels[ a ] = new aiNodeAnim();
  1327. ReadBinaryNodeAnim( stream, anim.mChannels[ a ] );
  1328. }
  1329. }
  1330. }
  1331. function ReadBinaryTexture( stream, tex ) {
  1332. var chunkID = Read_uint32_t( stream );
  1333. ai_assert( chunkID == ASSBIN_CHUNK_AITEXTURE );
  1334. /*uint32_t size =*/
  1335. Read_uint32_t( stream );
  1336. tex.mWidth = Read_unsigned_int( stream );
  1337. tex.mHeight = Read_unsigned_int( stream );
  1338. stream.ReadBytes( tex.achFormatHint, 1, 4 );
  1339. if ( ! shortened ) {
  1340. if ( ! tex.mHeight ) {
  1341. tex.pcData = [];
  1342. stream.ReadBytes( tex.pcData, 1, tex.mWidth );
  1343. } else {
  1344. tex.pcData = [];
  1345. stream.ReadBytes( tex.pcData, 1, tex.mWidth * tex.mHeight * 4 );
  1346. }
  1347. }
  1348. }
  1349. function ReadBinaryLight( stream, l ) {
  1350. var chunkID = Read_uint32_t( stream );
  1351. ai_assert( chunkID == ASSBIN_CHUNK_AILIGHT );
  1352. /*uint32_t size =*/
  1353. Read_uint32_t( stream );
  1354. l.mName = Read_aiString( stream );
  1355. l.mType = Read_unsigned_int( stream );
  1356. if ( l.mType != aiLightSource_DIRECTIONAL ) {
  1357. l.mAttenuationConstant = readFloat( stream );
  1358. l.mAttenuationLinear = readFloat( stream );
  1359. l.mAttenuationQuadratic = readFloat( stream );
  1360. }
  1361. l.mColorDiffuse = Read_aiColor3D( stream );
  1362. l.mColorSpecular = Read_aiColor3D( stream );
  1363. l.mColorAmbient = Read_aiColor3D( stream );
  1364. if ( l.mType == aiLightSource_SPOT ) {
  1365. l.mAngleInnerCone = readFloat( stream );
  1366. l.mAngleOuterCone = readFloat( stream );
  1367. }
  1368. }
  1369. function ReadBinaryCamera( stream, cam ) {
  1370. var chunkID = Read_uint32_t( stream );
  1371. ai_assert( chunkID == ASSBIN_CHUNK_AICAMERA );
  1372. /*uint32_t size =*/
  1373. Read_uint32_t( stream );
  1374. cam.mName = Read_aiString( stream );
  1375. cam.mPosition = Read_aiVector3D( stream );
  1376. cam.mLookAt = Read_aiVector3D( stream );
  1377. cam.mUp = Read_aiVector3D( stream );
  1378. cam.mHorizontalFOV = readFloat( stream );
  1379. cam.mClipPlaneNear = readFloat( stream );
  1380. cam.mClipPlaneFar = readFloat( stream );
  1381. cam.mAspect = readFloat( stream );
  1382. }
  1383. function ReadBinaryScene( stream, scene ) {
  1384. var chunkID = Read_uint32_t( stream );
  1385. ai_assert( chunkID == ASSBIN_CHUNK_AISCENE );
  1386. /*uint32_t size =*/
  1387. Read_uint32_t( stream );
  1388. scene.mFlags = Read_unsigned_int( stream );
  1389. scene.mNumMeshes = Read_unsigned_int( stream );
  1390. scene.mNumMaterials = Read_unsigned_int( stream );
  1391. scene.mNumAnimations = Read_unsigned_int( stream );
  1392. scene.mNumTextures = Read_unsigned_int( stream );
  1393. scene.mNumLights = Read_unsigned_int( stream );
  1394. scene.mNumCameras = Read_unsigned_int( stream );
  1395. // Read node graph
  1396. scene.mRootNode = new aiNode();
  1397. scene.mRootNode = ReadBinaryNode( stream, null, 0 );
  1398. // Read all meshes
  1399. if ( scene.mNumMeshes ) {
  1400. scene.mMeshes = [];
  1401. for ( var i = 0; i < scene.mNumMeshes; ++ i ) {
  1402. scene.mMeshes[ i ] = new aiMesh();
  1403. ReadBinaryMesh( stream, scene.mMeshes[ i ] );
  1404. }
  1405. }
  1406. // Read materials
  1407. if ( scene.mNumMaterials ) {
  1408. scene.mMaterials = [];
  1409. for ( var i = 0; i < scene.mNumMaterials; ++ i ) {
  1410. scene.mMaterials[ i ] = new aiMaterial();
  1411. ReadBinaryMaterial( stream, scene.mMaterials[ i ] );
  1412. }
  1413. }
  1414. // Read all animations
  1415. if ( scene.mNumAnimations ) {
  1416. scene.mAnimations = [];
  1417. for ( var i = 0; i < scene.mNumAnimations; ++ i ) {
  1418. scene.mAnimations[ i ] = new aiAnimation();
  1419. ReadBinaryAnim( stream, scene.mAnimations[ i ] );
  1420. }
  1421. }
  1422. // Read all textures
  1423. if ( scene.mNumTextures ) {
  1424. scene.mTextures = [];
  1425. for ( var i = 0; i < scene.mNumTextures; ++ i ) {
  1426. scene.mTextures[ i ] = new aiTexture();
  1427. ReadBinaryTexture( stream, scene.mTextures[ i ] );
  1428. }
  1429. }
  1430. // Read lights
  1431. if ( scene.mNumLights ) {
  1432. scene.mLights = [];
  1433. for ( var i = 0; i < scene.mNumLights; ++ i ) {
  1434. scene.mLights[ i ] = new aiLight();
  1435. ReadBinaryLight( stream, scene.mLights[ i ] );
  1436. }
  1437. }
  1438. // Read cameras
  1439. if ( scene.mNumCameras ) {
  1440. scene.mCameras = [];
  1441. for ( var i = 0; i < scene.mNumCameras; ++ i ) {
  1442. scene.mCameras[ i ] = new aiCamera();
  1443. ReadBinaryCamera( stream, scene.mCameras[ i ] );
  1444. }
  1445. }
  1446. }
  1447. var aiOrigin_CUR = 0;
  1448. var aiOrigin_BEG = 1;
  1449. function extendStream( stream ) {
  1450. stream.readOffset = 0;
  1451. stream.Seek = function ( off, ori ) {
  1452. if ( ori == aiOrigin_CUR ) {
  1453. stream.readOffset += off;
  1454. }
  1455. if ( ori == aiOrigin_BEG ) {
  1456. stream.readOffset = off;
  1457. }
  1458. };
  1459. stream.ReadBytes = function ( buff, size, n ) {
  1460. var bytes = size * n;
  1461. for ( var i = 0; i < bytes; i ++ )
  1462. buff[ i ] = Read_uint8_t( this );
  1463. };
  1464. stream.subArray32 = function ( start, end ) {
  1465. var buff = this.buffer;
  1466. var newbuff = buff.slice( start, end );
  1467. return new Float32Array( newbuff );
  1468. };
  1469. stream.subArrayUint16 = function ( start, end ) {
  1470. var buff = this.buffer;
  1471. var newbuff = buff.slice( start, end );
  1472. return new Uint16Array( newbuff );
  1473. };
  1474. stream.subArrayUint8 = function ( start, end ) {
  1475. var buff = this.buffer;
  1476. var newbuff = buff.slice( start, end );
  1477. return new Uint8Array( newbuff );
  1478. };
  1479. stream.subArrayUint32 = function ( start, end ) {
  1480. var buff = this.buffer;
  1481. var newbuff = buff.slice( start, end );
  1482. return new Uint32Array( newbuff );
  1483. };
  1484. }
  1485. var shortened, compressed;
  1486. function InternReadFile( pFiledata ) {
  1487. var pScene = new aiScene();
  1488. var stream = new DataView( pFiledata );
  1489. extendStream( stream );
  1490. stream.Seek( 44, aiOrigin_CUR ); // signature
  1491. /*unsigned int versionMajor =*/
  1492. pScene.versionMajor = Read_unsigned_int( stream );
  1493. /*unsigned int versionMinor =*/
  1494. pScene.versionMinor = Read_unsigned_int( stream );
  1495. /*unsigned int versionRevision =*/
  1496. pScene.versionRevision = Read_unsigned_int( stream );
  1497. /*unsigned int compileFlags =*/
  1498. pScene.compileFlags = Read_unsigned_int( stream );
  1499. shortened = Read_uint16_t( stream ) > 0;
  1500. compressed = Read_uint16_t( stream ) > 0;
  1501. if ( shortened )
  1502. throw "Shortened binaries are not supported!";
  1503. stream.Seek( 256, aiOrigin_CUR ); // original filename
  1504. stream.Seek( 128, aiOrigin_CUR ); // options
  1505. stream.Seek( 64, aiOrigin_CUR ); // padding
  1506. if ( compressed ) {
  1507. var uncompressedSize = Read_uint32_t( stream );
  1508. var compressedSize = stream.FileSize() - stream.Tell();
  1509. var compressedData = [];
  1510. stream.Read( compressedData, 1, compressedSize );
  1511. var uncompressedData = [];
  1512. uncompress( uncompressedData, uncompressedSize, compressedData, compressedSize );
  1513. var buff = new ArrayBuffer( uncompressedData );
  1514. ReadBinaryScene( buff, pScene );
  1515. } else {
  1516. ReadBinaryScene( stream, pScene );
  1517. }
  1518. return pScene.toTHREE();
  1519. }
  1520. return InternReadFile( buffer );
  1521. }
  1522. } );