AssimpLoader.js 51 KB

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