AssimpLoader.js 51 KB

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