AssimpLoader.js 51 KB

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