AssimpLoader.js 51 KB

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