AssimpLoader.js 51 KB

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