XLoader.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758
  1. import {
  2. AnimationClip,
  3. AnimationMixer,
  4. Bone,
  5. BufferGeometry,
  6. FileLoader,
  7. Float32BufferAttribute,
  8. FrontSide,
  9. Loader,
  10. LoaderUtils,
  11. Matrix4,
  12. Mesh,
  13. MeshPhongMaterial,
  14. Quaternion,
  15. Skeleton,
  16. SkinnedMesh,
  17. TextureLoader,
  18. Uint16BufferAttribute,
  19. Vector2,
  20. Vector3
  21. } from "../../../build/three.module.js";
  22. var XLoader = ( function () {
  23. var classCallCheck = function ( instance, Constructor ) {
  24. if ( ! ( instance instanceof Constructor ) ) {
  25. throw new TypeError( "Cannot call a class as a function" );
  26. }
  27. };
  28. var createClass = function () {
  29. function defineProperties( target, props ) {
  30. for ( var i = 0; i < props.length; i ++ ) {
  31. var descriptor = props[ i ];
  32. descriptor.enumerable = descriptor.enumerable || false;
  33. descriptor.configurable = true;
  34. if ( "value" in descriptor ) descriptor.writable = true;
  35. Object.defineProperty( target, descriptor.key, descriptor );
  36. }
  37. }
  38. return function ( Constructor, protoProps, staticProps ) {
  39. if ( protoProps ) defineProperties( Constructor.prototype, protoProps );
  40. if ( staticProps ) defineProperties( Constructor, staticProps );
  41. return Constructor;
  42. };
  43. }();
  44. var XboneInf = function XboneInf() {
  45. classCallCheck( this, XboneInf );
  46. this.boneName = "";
  47. this.BoneIndex = 0;
  48. this.Indeces = [];
  49. this.Weights = [];
  50. this.initMatrix = null;
  51. this.OffsetMatrix = null;
  52. };
  53. var XAnimationInfo = function XAnimationInfo() {
  54. classCallCheck( this, XAnimationInfo );
  55. this.animeName = "";
  56. this.boneName = "";
  57. this.targetBone = null;
  58. this.keyType = 4;
  59. this.frameStartLv = 0;
  60. this.keyFrames = [];
  61. this.InverseMx = null;
  62. };
  63. var XAnimationObj = function () {
  64. function XAnimationObj( _flags ) {
  65. classCallCheck( this, XAnimationObj );
  66. this.fps = 30;
  67. this.name = 'xanimation';
  68. this.length = 0;
  69. this.hierarchy = [];
  70. this.putFlags = _flags;
  71. if ( this.putFlags.putPos === undefined ) {
  72. this.putFlags.putPos = true;
  73. }
  74. if ( this.putFlags.putRot === undefined ) {
  75. this.putFlags.putRot = true;
  76. }
  77. if ( this.putFlags.putScl === undefined ) {
  78. this.putFlags.putScl = true;
  79. }
  80. }
  81. createClass( XAnimationObj, [ {
  82. key: "make",
  83. value: function make( XAnimationInfoArray ) {
  84. for ( var i = 0; i < XAnimationInfoArray.length; i ++ ) {
  85. this.hierarchy.push( this.makeBonekeys( XAnimationInfoArray[ i ] ) );
  86. }
  87. this.length = this.hierarchy[ 0 ].keys[ this.hierarchy[ 0 ].keys.length - 1 ].time;
  88. }
  89. }, {
  90. key: "clone",
  91. value: function clone() {
  92. return Object.assign( {}, this );
  93. }
  94. }, {
  95. key: "makeBonekeys",
  96. value: function makeBonekeys( XAnimationInfo ) {
  97. var refObj = {};
  98. refObj.name = XAnimationInfo.boneName;
  99. refObj.parent = "";
  100. refObj.keys = this.keyFrameRefactor( XAnimationInfo );
  101. refObj.copy = function () {
  102. return Object.assign( {}, this );
  103. };
  104. return refObj;
  105. }
  106. }, {
  107. key: "keyFrameRefactor",
  108. value: function keyFrameRefactor( XAnimationInfo ) {
  109. var keys = [];
  110. for ( var i = 0; i < XAnimationInfo.keyFrames.length; i ++ ) {
  111. var keyframe = {};
  112. keyframe.time = XAnimationInfo.keyFrames[ i ].time * this.fps;
  113. if ( XAnimationInfo.keyFrames[ i ].pos && this.putFlags.putPos ) {
  114. keyframe.pos = XAnimationInfo.keyFrames[ i ].pos;
  115. }
  116. if ( XAnimationInfo.keyFrames[ i ].rot && this.putFlags.putRot ) {
  117. keyframe.rot = XAnimationInfo.keyFrames[ i ].rot;
  118. }
  119. if ( XAnimationInfo.keyFrames[ i ].scl && this.putFlags.putScl ) {
  120. keyframe.scl = XAnimationInfo.keyFrames[ i ].scl;
  121. }
  122. if ( XAnimationInfo.keyFrames[ i ].matrix ) {
  123. keyframe.matrix = XAnimationInfo.keyFrames[ i ].matrix;
  124. if ( this.putFlags.putPos ) {
  125. keyframe.pos = new Vector3().setFromMatrixPosition( keyframe.matrix );
  126. }
  127. if ( this.putFlags.putRot ) {
  128. keyframe.rot = new Quaternion().setFromRotationMatrix( keyframe.matrix );
  129. }
  130. if ( this.putFlags.putScl ) {
  131. keyframe.scl = new Vector3().setFromMatrixScale( keyframe.matrix );
  132. }
  133. }
  134. keys.push( keyframe );
  135. }
  136. return keys;
  137. }
  138. } ] );
  139. return XAnimationObj;
  140. }();
  141. var XKeyFrameInfo = function XKeyFrameInfo() {
  142. classCallCheck( this, XKeyFrameInfo );
  143. this.index = 0;
  144. this.Frame = 0;
  145. this.time = 0.0;
  146. this.matrix = null;
  147. };
  148. var XLoader = function () {
  149. function XLoader( manager ) {
  150. Loader.call( this, manager );
  151. classCallCheck( this, XLoader );
  152. this.debug = false;
  153. this.texloader = new TextureLoader( this.manager );
  154. this.url = "";
  155. this._putMatLength = 0;
  156. this._nowMat = null;
  157. this._nowFrameName = "";
  158. this.frameHierarchie = [];
  159. this.Hierarchies = {};
  160. this.HieStack = [];
  161. this._currentObject = {};
  162. this._currentFrame = {};
  163. this._data = null;
  164. this.onLoad = null;
  165. this.IsUvYReverse = true;
  166. this.Meshes = [];
  167. this.animations = [];
  168. this.animTicksPerSecond = 30;
  169. this._currentGeo = null;
  170. this._currentAnime = null;
  171. this._currentAnimeFrames = null;
  172. }
  173. createClass( XLoader, [ {
  174. key: '_setArgOption',
  175. value: function _setArgOption( _arg ) {
  176. var _start = arguments.length > 1 && arguments[ 1 ] !== undefined ? arguments[ 1 ] : 0;
  177. if ( ! _arg ) {
  178. return;
  179. }
  180. for ( var i = _start; i < _arg.length; i ++ ) {
  181. switch ( i ) {
  182. case 0:
  183. this.url = _arg[ i ];
  184. break;
  185. case 1:
  186. this.options = _arg[ i ];
  187. break;
  188. }
  189. }
  190. if ( this.options === undefined ) {
  191. this.options = {};
  192. }
  193. }
  194. }, {
  195. key: 'load',
  196. value: function load( _arg, onLoad, onProgress, onError ) {
  197. var _this = this;
  198. this._setArgOption( _arg );
  199. var loader = new FileLoader( this.manager );
  200. loader.setPath( this.path );
  201. loader.setResponseType( 'arraybuffer' );
  202. loader.setRequestHeader( this.requestHeader );
  203. loader.load( this.url, function ( response ) {
  204. try {
  205. _this.parse( response, onLoad );
  206. } catch ( e ) {
  207. if ( onError ) {
  208. onError( e );
  209. } else {
  210. console.error( e );
  211. }
  212. _this.manager.itemError( _this.url );
  213. }
  214. }, onProgress, onError );
  215. }
  216. }, {
  217. key: '_readLine',
  218. value: function _readLine( line ) {
  219. var readed = 0;
  220. while ( true ) {
  221. var find = - 1;
  222. find = line.indexOf( '//', readed );
  223. if ( find === - 1 ) {
  224. find = line.indexOf( '#', readed );
  225. }
  226. if ( find > - 1 && find < 2 ) {
  227. var foundNewLine = - 1;
  228. foundNewLine = line.indexOf( "\r\n", readed );
  229. if ( foundNewLine > 0 ) {
  230. readed = foundNewLine + 2;
  231. } else {
  232. foundNewLine = line.indexOf( "\r", readed );
  233. if ( foundNewLine > 0 ) {
  234. readed = foundNewLine + 1;
  235. } else {
  236. readed = line.indexOf( "\n", readed ) + 1;
  237. }
  238. }
  239. } else {
  240. break;
  241. }
  242. }
  243. return line.substr( readed );
  244. }
  245. }, {
  246. key: '_readLine',
  247. value: function _readLine( line ) {
  248. var readed = 0;
  249. while ( true ) {
  250. var find = - 1;
  251. find = line.indexOf( '//', readed );
  252. if ( find === - 1 ) {
  253. find = line.indexOf( '#', readed );
  254. }
  255. if ( find > - 1 && find < 2 ) {
  256. var foundNewLine = - 1;
  257. foundNewLine = line.indexOf( "\r\n", readed );
  258. if ( foundNewLine > 0 ) {
  259. readed = foundNewLine + 2;
  260. } else {
  261. foundNewLine = line.indexOf( "\r", readed );
  262. if ( foundNewLine > 0 ) {
  263. readed = foundNewLine + 1;
  264. } else {
  265. readed = line.indexOf( "\n", readed ) + 1;
  266. }
  267. }
  268. } else {
  269. break;
  270. }
  271. }
  272. return line.substr( readed );
  273. }
  274. }, {
  275. key: '_isBinary',
  276. value: function _isBinary( binData ) {
  277. var reader = new DataView( binData );
  278. var face_size = 32 / 8 * 3 + 32 / 8 * 3 * 3 + 16 / 8;
  279. var n_faces = reader.getUint32( 80, true );
  280. var expect = 80 + 32 / 8 + n_faces * face_size;
  281. if ( expect === reader.byteLength ) {
  282. return true;
  283. }
  284. var fileLength = reader.byteLength;
  285. for ( var index = 0; index < fileLength; index ++ ) {
  286. if ( reader.getUint8( index, false ) > 127 ) {
  287. return true;
  288. }
  289. }
  290. return false;
  291. }
  292. }, {
  293. key: '_ensureBinary',
  294. value: function _ensureBinary( buf ) {
  295. if ( typeof buf === "string" ) {
  296. var array_buffer = new Uint8Array( buf.length );
  297. for ( var i = 0; i < buf.length; i ++ ) {
  298. array_buffer[ i ] = buf.charCodeAt( i ) & 0xff;
  299. }
  300. return array_buffer.buffer || array_buffer;
  301. } else {
  302. return buf;
  303. }
  304. }
  305. }, {
  306. key: '_ensureString',
  307. value: function _ensureString( buf ) {
  308. if ( typeof buf !== "string" ) {
  309. return LoaderUtils.decodeText( new Uint8Array( buf ) );
  310. } else {
  311. return buf;
  312. }
  313. }
  314. }, {
  315. key: 'parse',
  316. value: function _parse( data, onLoad ) {
  317. var binData = this._ensureBinary( data );
  318. this._data = this._ensureString( data );
  319. this.onLoad = onLoad;
  320. return this._isBinary( binData ) ? this._parseBinary( binData ) : this._parseASCII();
  321. }
  322. }, {
  323. key: '_parseBinary',
  324. value: function _parseBinary( data ) {
  325. return this._parseASCII( LoaderUtils.decodeText( new Uint8Array( data ) ) );
  326. }
  327. }, {
  328. key: '_parseASCII',
  329. value: function _parseASCII() {
  330. var path;
  331. if ( this.resourcePath !== '' ) {
  332. path = this.resourcePath;
  333. } else if ( this.path !== '' ) {
  334. path = this.path;
  335. } else {
  336. path = LoaderUtils.extractUrlBase( this.url );
  337. }
  338. this.texloader.setPath( path ).setCrossOrigin( this.crossOrigin );
  339. var endRead = 16;
  340. this.Hierarchies.children = [];
  341. this._hierarchieParse( this.Hierarchies, endRead );
  342. this._changeRoot();
  343. this._currentObject = this.Hierarchies.children.shift();
  344. this._mainloop();
  345. }
  346. }, {
  347. key: '_hierarchieParse',
  348. value: function _hierarchieParse( _parent, _end ) {
  349. var endRead = _end;
  350. while ( true ) {
  351. var find1 = this._data.indexOf( '{', endRead ) + 1;
  352. var findEnd = this._data.indexOf( '}', endRead );
  353. var findNext = this._data.indexOf( '{', find1 ) + 1;
  354. if ( find1 > 0 && findEnd > find1 ) {
  355. var _currentObject = {};
  356. _currentObject.children = [];
  357. var nameData = this._readLine( this._data.substr( endRead, find1 - endRead - 1 ) ).trim();
  358. var word = nameData.split( / /g );
  359. if ( word.length > 0 ) {
  360. _currentObject.type = word[ 0 ];
  361. if ( word.length >= 2 ) {
  362. _currentObject.name = word[ 1 ];
  363. } else {
  364. _currentObject.name = word[ 0 ] + this.Hierarchies.children.length;
  365. }
  366. } else {
  367. _currentObject.name = nameData;
  368. _currentObject.type = "";
  369. }
  370. if ( _currentObject.type === "Animation" ) {
  371. _currentObject.data = this._data.substr( findNext, findEnd - findNext ).trim();
  372. var refs = this._hierarchieParse( _currentObject, findEnd + 1 );
  373. endRead = refs.end;
  374. _currentObject.children = refs.parent.children;
  375. } else {
  376. var DataEnder = this._data.lastIndexOf( ';', findNext > 0 ? Math.min( findNext, findEnd ) : findEnd );
  377. _currentObject.data = this._data.substr( find1, DataEnder - find1 ).trim();
  378. if ( findNext <= 0 || findEnd < findNext ) {
  379. endRead = findEnd + 1;
  380. } else {
  381. var nextStart = Math.max( DataEnder + 1, find1 );
  382. var _refs = this._hierarchieParse( _currentObject, nextStart );
  383. endRead = _refs.end;
  384. _currentObject.children = _refs.parent.children;
  385. }
  386. }
  387. _currentObject.parent = _parent;
  388. if ( _currentObject.type != "template" ) {
  389. _parent.children.push( _currentObject );
  390. }
  391. } else {
  392. endRead = find1 === - 1 ? this._data.length : findEnd + 1;
  393. break;
  394. }
  395. }
  396. return {
  397. parent: _parent,
  398. end: endRead
  399. };
  400. }
  401. }, {
  402. key: '_mainloop',
  403. value: function _mainloop() {
  404. var _this2 = this;
  405. this._mainProc();
  406. if ( this._currentObject.parent || this._currentObject.children.length > 0 || ! this._currentObject.worked ) {
  407. setTimeout( function () {
  408. _this2._mainloop();
  409. }, 1 );
  410. } else {
  411. setTimeout( function () {
  412. _this2.onLoad( {
  413. models: _this2.Meshes,
  414. animations: _this2.animations
  415. } );
  416. }, 1 );
  417. }
  418. }
  419. }, {
  420. key: '_mainProc',
  421. value: function _mainProc() {
  422. var breakFlag = false;
  423. while ( true ) {
  424. if ( ! this._currentObject.worked ) {
  425. switch ( this._currentObject.type ) {
  426. case "template":
  427. break;
  428. case "AnimTicksPerSecond":
  429. this.animTicksPerSecond = parseInt( this._currentObject.data );
  430. break;
  431. case "Frame":
  432. this._setFrame();
  433. break;
  434. case "FrameTransformMatrix":
  435. this._setFrameTransformMatrix();
  436. break;
  437. case "Mesh":
  438. this._changeRoot();
  439. this._currentGeo = {};
  440. this._currentGeo.name = this._currentObject.name.trim();
  441. this._currentGeo.parentName = this._getParentName( this._currentObject ).trim();
  442. this._currentGeo.VertexSetedBoneCount = [];
  443. this._currentGeo.GeometryData = {
  444. vertices: [],
  445. normals: [],
  446. uvs: [],
  447. skinIndices: [],
  448. skinWeights: [],
  449. indices: [],
  450. materialIndices: []
  451. };
  452. this._currentGeo.Materials = [];
  453. this._currentGeo.normalVectors = [];
  454. this._currentGeo.BoneInfs = [];
  455. this._currentGeo.baseFrame = this._currentFrame;
  456. this._makeBoneFrom_CurrentFrame();
  457. this._readVertexDatas();
  458. breakFlag = true;
  459. break;
  460. case "MeshNormals":
  461. this._readVertexDatas();
  462. break;
  463. case "MeshTextureCoords":
  464. this._setMeshTextureCoords();
  465. break;
  466. case "VertexDuplicationIndices":
  467. break;
  468. case "MeshMaterialList":
  469. this._setMeshMaterialList();
  470. break;
  471. case "Material":
  472. this._setMaterial();
  473. break;
  474. case "SkinWeights":
  475. this._setSkinWeights();
  476. break;
  477. case "AnimationSet":
  478. this._changeRoot();
  479. this._currentAnime = {};
  480. this._currentAnime.name = this._currentObject.name.trim();
  481. this._currentAnime.AnimeFrames = [];
  482. break;
  483. case "Animation":
  484. if ( this._currentAnimeFrames ) {
  485. this._currentAnime.AnimeFrames.push( this._currentAnimeFrames );
  486. }
  487. this._currentAnimeFrames = new XAnimationInfo();
  488. this._currentAnimeFrames.boneName = this._currentObject.data.trim();
  489. break;
  490. case "AnimationKey":
  491. this._readAnimationKey();
  492. breakFlag = true;
  493. break;
  494. }
  495. this._currentObject.worked = true;
  496. }
  497. if ( this._currentObject.children.length > 0 ) {
  498. this._currentObject = this._currentObject.children.shift();
  499. if ( this.debug ) {
  500. console.log( 'processing ' + this._currentObject.name );
  501. }
  502. if ( breakFlag ) break;
  503. } else {
  504. if ( this._currentObject.worked ) {
  505. if ( this._currentObject.parent && ! this._currentObject.parent.parent ) {
  506. this._changeRoot();
  507. }
  508. }
  509. if ( this._currentObject.parent ) {
  510. this._currentObject = this._currentObject.parent;
  511. } else {
  512. breakFlag = true;
  513. }
  514. if ( breakFlag ) break;
  515. }
  516. }
  517. return;
  518. }
  519. }, {
  520. key: '_changeRoot',
  521. value: function _changeRoot() {
  522. if ( this._currentGeo != null && this._currentGeo.name ) {
  523. this._makeOutputGeometry();
  524. }
  525. this._currentGeo = {};
  526. if ( this._currentAnime != null && this._currentAnime.name ) {
  527. if ( this._currentAnimeFrames ) {
  528. this._currentAnime.AnimeFrames.push( this._currentAnimeFrames );
  529. this._currentAnimeFrames = null;
  530. }
  531. this._makeOutputAnimation();
  532. }
  533. this._currentAnime = {};
  534. }
  535. }, {
  536. key: '_getParentName',
  537. value: function _getParentName( _obj ) {
  538. if ( _obj.parent ) {
  539. if ( _obj.parent.name ) {
  540. return _obj.parent.name;
  541. } else {
  542. return this._getParentName( _obj.parent );
  543. }
  544. } else {
  545. return "";
  546. }
  547. }
  548. }, {
  549. key: '_setFrame',
  550. value: function _setFrame() {
  551. this._nowFrameName = this._currentObject.name.trim();
  552. this._currentFrame = {};
  553. this._currentFrame.name = this._nowFrameName;
  554. this._currentFrame.children = [];
  555. if ( this._currentObject.parent && this._currentObject.parent.name ) {
  556. this._currentFrame.parentName = this._currentObject.parent.name;
  557. }
  558. this.frameHierarchie.push( this._nowFrameName );
  559. this.HieStack[ this._nowFrameName ] = this._currentFrame;
  560. }
  561. }, {
  562. key: '_setFrameTransformMatrix',
  563. value: function _setFrameTransformMatrix() {
  564. this._currentFrame.FrameTransformMatrix = new Matrix4();
  565. var data = this._currentObject.data.split( "," );
  566. this._ParseMatrixData( this._currentFrame.FrameTransformMatrix, data );
  567. this._makeBoneFrom_CurrentFrame();
  568. }
  569. }, {
  570. key: '_makeBoneFrom_CurrentFrame',
  571. value: function _makeBoneFrom_CurrentFrame() {
  572. if ( ! this._currentFrame.FrameTransformMatrix ) {
  573. return;
  574. }
  575. var b = new Bone();
  576. b.name = this._currentFrame.name;
  577. b.applyMatrix4( this._currentFrame.FrameTransformMatrix );
  578. b.matrixWorld = b.matrix;
  579. b.FrameTransformMatrix = this._currentFrame.FrameTransformMatrix;
  580. this._currentFrame.putBone = b;
  581. if ( this._currentFrame.parentName ) {
  582. for ( var frame in this.HieStack ) {
  583. if ( this.HieStack[ frame ].name === this._currentFrame.parentName ) {
  584. this.HieStack[ frame ].putBone.add( this._currentFrame.putBone );
  585. }
  586. }
  587. }
  588. }
  589. }, {
  590. key: '_readVertexDatas',
  591. value: function _readVertexDatas() {
  592. var endRead = 0;
  593. var mode = 0;
  594. var mode_local = 0;
  595. var maxLength = 0;
  596. while ( true ) {
  597. var changeMode = false;
  598. if ( mode_local === 0 ) {
  599. var refO = this._readInt1( endRead );
  600. endRead = refO.endRead;
  601. mode_local = 1;
  602. maxLength = this._currentObject.data.indexOf( ';;', endRead ) + 1;
  603. if ( maxLength <= 0 ) {
  604. maxLength = this._currentObject.data.length;
  605. }
  606. } else {
  607. var find = 0;
  608. switch ( mode ) {
  609. case 0:
  610. find = this._currentObject.data.indexOf( ',', endRead ) + 1;
  611. break;
  612. case 1:
  613. find = this._currentObject.data.indexOf( ';,', endRead ) + 1;
  614. break;
  615. }
  616. if ( find === 0 || find > maxLength ) {
  617. find = maxLength;
  618. mode_local = 0;
  619. changeMode = true;
  620. }
  621. switch ( this._currentObject.type ) {
  622. case "Mesh":
  623. switch ( mode ) {
  624. case 0:
  625. this._readVertex1( this._currentObject.data.substr( endRead, find - endRead ) );
  626. break;
  627. case 1:
  628. this._readFace1( this._currentObject.data.substr( endRead, find - endRead ) );
  629. break;
  630. }
  631. break;
  632. case "MeshNormals":
  633. switch ( mode ) {
  634. case 0:
  635. this._readNormalVector1( this._currentObject.data.substr( endRead, find - endRead ) );
  636. break;
  637. }
  638. break;
  639. }
  640. endRead = find + 1;
  641. if ( changeMode ) {
  642. mode ++;
  643. }
  644. }
  645. if ( endRead >= this._currentObject.data.length ) {
  646. break;
  647. }
  648. }
  649. }
  650. }, {
  651. key: '_readInt1',
  652. value: function _readInt1( start ) {
  653. var find = this._currentObject.data.indexOf( ';', start );
  654. return {
  655. refI: parseInt( this._currentObject.data.substr( start, find - start ) ),
  656. endRead: find + 1
  657. };
  658. }
  659. }, {
  660. key: '_readVertex1',
  661. value: function _readVertex1( line ) {
  662. var data = this._readLine( line.trim() ).substr( 0, line.length - 2 ).split( ";" );
  663. this._currentGeo.GeometryData.vertices.push( parseFloat( data[ 0 ] ), parseFloat( data[ 1 ] ), parseFloat( data[ 2 ] ) );
  664. this._currentGeo.GeometryData.skinIndices.push( 0, 0, 0, 0 );
  665. this._currentGeo.GeometryData.skinWeights.push( 1, 0, 0, 0 );
  666. this._currentGeo.VertexSetedBoneCount.push( 0 );
  667. }
  668. }, {
  669. key: '_readFace1',
  670. value: function _readFace1( line ) {
  671. var data = this._readLine( line.trim() ).substr( 2, line.length - 4 ).split( "," );
  672. this._currentGeo.GeometryData.indices.push( parseInt( data[ 0 ], 10 ), parseInt( data[ 1 ], 10 ), parseInt( data[ 2 ], 10 ) );
  673. }
  674. }, {
  675. key: '_readNormalVector1',
  676. value: function _readNormalVector1( line ) {
  677. var data = this._readLine( line.trim() ).substr( 0, line.length - 2 ).split( ";" );
  678. this._currentGeo.GeometryData.normals.push( parseFloat( data[ 0 ] ), parseFloat( data[ 1 ] ), parseFloat( data[ 2 ] ) );
  679. }
  680. }, {
  681. key: '_buildGeometry',
  682. value: function _buildGeometry() {
  683. var bufferGeometry = new BufferGeometry();
  684. var position = [];
  685. var normals = [];
  686. var uvs = [];
  687. var skinIndices = [];
  688. var skinWeights = [];
  689. //
  690. var data = this._currentGeo.GeometryData;
  691. for ( var i = 0, l = data.indices.length; i < l; i ++ ) {
  692. var stride2 = data.indices[ i ] * 2;
  693. var stride3 = data.indices[ i ] * 3;
  694. var stride4 = data.indices[ i ] * 4;
  695. position.push( data.vertices[ stride3 ], data.vertices[ stride3 + 1 ], data.vertices[ stride3 + 2 ] );
  696. normals.push( data.normals[ stride3 ], data.normals[ stride3 + 1 ], data.normals[ stride3 + 2 ] );
  697. skinIndices.push( data.skinIndices[ stride4 ], data.skinIndices[ stride4 + 1 ], data.skinIndices[ stride4 + 2 ], data.skinIndices[ stride4 + 3 ] );
  698. skinWeights.push( data.skinWeights[ stride4 ], data.skinWeights[ stride4 + 1 ], data.skinWeights[ stride4 + 2 ], data.skinWeights[ stride4 + 3 ] );
  699. uvs.push( data.uvs[ stride2 ], data.uvs[ stride2 + 1 ] );
  700. }
  701. //
  702. bufferGeometry.setAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  703. bufferGeometry.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  704. bufferGeometry.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  705. bufferGeometry.setAttribute( 'skinIndex', new Uint16BufferAttribute( skinIndices, 4 ) );
  706. bufferGeometry.setAttribute( 'skinWeight', new Float32BufferAttribute( skinWeights, 4 ) );
  707. this._computeGroups( bufferGeometry, data.materialIndices );
  708. return bufferGeometry;
  709. }
  710. }, {
  711. key: '_computeGroups',
  712. value: function _computeGroups( bufferGeometry, materialIndices ) {
  713. var group;
  714. var groups = [];
  715. var materialIndex = undefined;
  716. for ( var i = 0; i < materialIndices.length; i ++ ) {
  717. var currentMaterialIndex = materialIndices[ i ];
  718. if ( currentMaterialIndex !== materialIndex ) {
  719. materialIndex = currentMaterialIndex;
  720. if ( group !== undefined ) {
  721. group.count = ( i * 3 ) - group.start;
  722. groups.push( group );
  723. }
  724. group = {
  725. start: i * 3,
  726. materialIndex: materialIndex
  727. };
  728. }
  729. }
  730. if ( group !== undefined ) {
  731. group.count = ( i * 3 ) - group.start;
  732. groups.push( group );
  733. }
  734. bufferGeometry.groups = groups;
  735. }
  736. }, {
  737. key: '_setMeshTextureCoords',
  738. value: function _setMeshTextureCoords() {
  739. var endRead = 0;
  740. var mode = 0;
  741. var mode_local = 0;
  742. while ( true ) {
  743. switch ( mode ) {
  744. case 0:
  745. if ( mode_local === 0 ) {
  746. var refO = this._readInt1( 0 );
  747. endRead = refO.endRead;
  748. mode_local = 1;
  749. } else {
  750. var find = this._currentObject.data.indexOf( ',', endRead ) + 1;
  751. if ( find === 0 ) {
  752. find = this._currentObject.data.length;
  753. mode = 2;
  754. mode_local = 0;
  755. }
  756. var line = this._currentObject.data.substr( endRead, find - endRead );
  757. var data = this._readLine( line.trim() ).split( ";" );
  758. if ( this.IsUvYReverse ) {
  759. this._currentGeo.GeometryData.uvs.push( parseFloat( data[ 0 ] ), 1 - parseFloat( data[ 1 ] ) );
  760. } else {
  761. this._currentGeo.GeometryData.uvs.push( parseFloat( data[ 0 ] ), parseFloat( data[ 1 ] ) );
  762. }
  763. endRead = find + 1;
  764. }
  765. break;
  766. }
  767. if ( endRead >= this._currentObject.data.length ) {
  768. break;
  769. }
  770. }
  771. }
  772. }, {
  773. key: '_setMeshMaterialList',
  774. value: function _setMeshMaterialList() {
  775. var endRead = 0;
  776. var mode = 0;
  777. var mode_local = 0;
  778. while ( true ) {
  779. if ( mode_local < 2 ) {
  780. var refO = this._readInt1( endRead );
  781. endRead = refO.endRead;
  782. mode_local ++;
  783. } else {
  784. var find = this._currentObject.data.indexOf( ';', endRead );
  785. if ( find === - 1 ) {
  786. find = this._currentObject.data.length;
  787. mode = 3;
  788. mode_local = 0;
  789. }
  790. var line = this._currentObject.data.substr( endRead, find - endRead );
  791. var data = this._readLine( line.trim() ).split( "," );
  792. for ( var i = 0; i < data.length; i ++ ) {
  793. this._currentGeo.GeometryData.materialIndices[ i ] = parseInt( data[ i ] );
  794. }
  795. endRead = this._currentObject.data.length;
  796. }
  797. if ( endRead >= this._currentObject.data.length || mode >= 3 ) {
  798. break;
  799. }
  800. }
  801. }
  802. }, {
  803. key: '_setMaterial',
  804. value: function _setMaterial() {
  805. var _nowMat = new MeshPhongMaterial( {
  806. color: Math.random() * 0xffffff
  807. } );
  808. _nowMat.side = FrontSide;
  809. _nowMat.name = this._currentObject.name;
  810. var endRead = 0;
  811. var find = this._currentObject.data.indexOf( ';;', endRead );
  812. var line = this._currentObject.data.substr( endRead, find - endRead );
  813. var data = this._readLine( line.trim() ).split( ";" );
  814. _nowMat.color.r = parseFloat( data[ 0 ] );
  815. _nowMat.color.g = parseFloat( data[ 1 ] );
  816. _nowMat.color.b = parseFloat( data[ 2 ] );
  817. endRead = find + 2;
  818. find = this._currentObject.data.indexOf( ';', endRead );
  819. line = this._currentObject.data.substr( endRead, find - endRead );
  820. _nowMat.shininess = parseFloat( this._readLine( line ) );
  821. endRead = find + 1;
  822. find = this._currentObject.data.indexOf( ';;', endRead );
  823. line = this._currentObject.data.substr( endRead, find - endRead );
  824. var data2 = this._readLine( line.trim() ).split( ";" );
  825. _nowMat.specular.r = parseFloat( data2[ 0 ] );
  826. _nowMat.specular.g = parseFloat( data2[ 1 ] );
  827. _nowMat.specular.b = parseFloat( data2[ 2 ] );
  828. endRead = find + 2;
  829. find = this._currentObject.data.indexOf( ';;', endRead );
  830. if ( find === - 1 ) {
  831. find = this._currentObject.data.length;
  832. }
  833. line = this._currentObject.data.substr( endRead, find - endRead );
  834. var data3 = this._readLine( line.trim() ).split( ";" );
  835. _nowMat.emissive.r = parseFloat( data3[ 0 ] );
  836. _nowMat.emissive.g = parseFloat( data3[ 1 ] );
  837. _nowMat.emissive.b = parseFloat( data3[ 2 ] );
  838. var localObject = null;
  839. while ( true ) {
  840. if ( this._currentObject.children.length > 0 ) {
  841. localObject = this._currentObject.children.shift();
  842. if ( this.debug ) {
  843. console.log( 'processing ' + localObject.name );
  844. }
  845. var fileName = localObject.data.substr( 1, localObject.data.length - 2 );
  846. switch ( localObject.type ) {
  847. case "TextureFilename":
  848. _nowMat.map = this.texloader.load( fileName );
  849. break;
  850. case "BumpMapFilename":
  851. _nowMat.bumpMap = this.texloader.load( fileName );
  852. _nowMat.bumpScale = 0.05;
  853. break;
  854. case "NormalMapFilename":
  855. _nowMat.normalMap = this.texloader.load( fileName );
  856. _nowMat.normalScale = new Vector2( 2, 2 );
  857. break;
  858. case "EmissiveMapFilename":
  859. _nowMat.emissiveMap = this.texloader.load( fileName );
  860. break;
  861. case "LightMapFilename":
  862. _nowMat.lightMap = this.texloader.load( fileName );
  863. break;
  864. }
  865. } else {
  866. break;
  867. }
  868. }
  869. this._currentGeo.Materials.push( _nowMat );
  870. }
  871. }, {
  872. key: '_setSkinWeights',
  873. value: function _setSkinWeights() {
  874. var boneInf = new XboneInf();
  875. var endRead = 0;
  876. var find = this._currentObject.data.indexOf( ';', endRead );
  877. var line = this._currentObject.data.substr( endRead, find - endRead );
  878. endRead = find + 1;
  879. boneInf.boneName = line.substr( 1, line.length - 2 );
  880. boneInf.BoneIndex = this._currentGeo.BoneInfs.length;
  881. find = this._currentObject.data.indexOf( ';', endRead );
  882. endRead = find + 1;
  883. find = this._currentObject.data.indexOf( ';', endRead );
  884. line = this._currentObject.data.substr( endRead, find - endRead );
  885. var data = this._readLine( line.trim() ).split( "," );
  886. for ( var i = 0; i < data.length; i ++ ) {
  887. boneInf.Indeces.push( parseInt( data[ i ] ) );
  888. }
  889. endRead = find + 1;
  890. find = this._currentObject.data.indexOf( ';', endRead );
  891. line = this._currentObject.data.substr( endRead, find - endRead );
  892. var data2 = this._readLine( line.trim() ).split( "," );
  893. for ( var _i = 0; _i < data2.length; _i ++ ) {
  894. boneInf.Weights.push( parseFloat( data2[ _i ] ) );
  895. }
  896. endRead = find + 1;
  897. find = this._currentObject.data.indexOf( ';', endRead );
  898. if ( find <= 0 ) {
  899. find = this._currentObject.data.length;
  900. }
  901. line = this._currentObject.data.substr( endRead, find - endRead );
  902. var data3 = this._readLine( line.trim() ).split( "," );
  903. boneInf.OffsetMatrix = new Matrix4();
  904. this._ParseMatrixData( boneInf.OffsetMatrix, data3 );
  905. this._currentGeo.BoneInfs.push( boneInf );
  906. }
  907. }, {
  908. key: '_makePutBoneList',
  909. value: function _makePutBoneList( _RootName, _bones ) {
  910. var putting = false;
  911. for ( var frame in this.HieStack ) {
  912. if ( this.HieStack[ frame ].name === _RootName || putting ) {
  913. putting = true;
  914. var b = new Bone();
  915. b.name = this.HieStack[ frame ].name;
  916. b.applyMatrix4( this.HieStack[ frame ].FrameTransformMatrix );
  917. b.matrixWorld = b.matrix;
  918. b.FrameTransformMatrix = this.HieStack[ frame ].FrameTransformMatrix;
  919. b.pos = new Vector3().setFromMatrixPosition( b.FrameTransformMatrix ).toArray();
  920. b.rotq = new Quaternion().setFromRotationMatrix( b.FrameTransformMatrix ).toArray();
  921. b.scl = new Vector3().setFromMatrixScale( b.FrameTransformMatrix ).toArray();
  922. if ( this.HieStack[ frame ].parentName && this.HieStack[ frame ].parentName.length > 0 ) {
  923. for ( var i = 0; i < _bones.length; i ++ ) {
  924. if ( this.HieStack[ frame ].parentName === _bones[ i ].name ) {
  925. _bones[ i ].add( b );
  926. b.parent = i;
  927. break;
  928. }
  929. }
  930. }
  931. _bones.push( b );
  932. }
  933. }
  934. }
  935. }, {
  936. key: '_makeOutputGeometry',
  937. value: function _makeOutputGeometry() {
  938. var mesh = null;
  939. if ( this._currentGeo.BoneInfs.length > 0 ) {
  940. var putBones = [];
  941. this._makePutBoneList( this._currentGeo.baseFrame.parentName, putBones );
  942. for ( var bi = 0; bi < this._currentGeo.BoneInfs.length; bi ++ ) {
  943. var boneIndex = 0;
  944. for ( var bb = 0; bb < putBones.length; bb ++ ) {
  945. if ( putBones[ bb ].name === this._currentGeo.BoneInfs[ bi ].boneName ) {
  946. boneIndex = bb;
  947. putBones[ bb ].OffsetMatrix = new Matrix4();
  948. putBones[ bb ].OffsetMatrix.copy( this._currentGeo.BoneInfs[ bi ].OffsetMatrix );
  949. break;
  950. }
  951. }
  952. for ( var vi = 0; vi < this._currentGeo.BoneInfs[ bi ].Indeces.length; vi ++ ) {
  953. var nowVertexID = this._currentGeo.BoneInfs[ bi ].Indeces[ vi ];
  954. var nowVal = this._currentGeo.BoneInfs[ bi ].Weights[ vi ];
  955. var stride = nowVertexID * 4;
  956. switch ( this._currentGeo.VertexSetedBoneCount[ nowVertexID ] ) {
  957. case 0:
  958. this._currentGeo.GeometryData.skinIndices[ stride ] = boneIndex;
  959. this._currentGeo.GeometryData.skinWeights[ stride ] = nowVal;
  960. break;
  961. case 1:
  962. this._currentGeo.GeometryData.skinIndices[ stride + 1 ] = boneIndex;
  963. this._currentGeo.GeometryData.skinWeights[ stride + 1 ] = nowVal;
  964. break;
  965. case 2:
  966. this._currentGeo.GeometryData.skinIndices[ stride + 2 ] = boneIndex;
  967. this._currentGeo.GeometryData.skinWeights[ stride + 2 ] = nowVal;
  968. break;
  969. case 3:
  970. this._currentGeo.GeometryData.skinIndices[ stride + 3 ] = boneIndex;
  971. this._currentGeo.GeometryData.skinWeights[ stride + 3 ] = nowVal;
  972. break;
  973. }
  974. this._currentGeo.VertexSetedBoneCount[ nowVertexID ] ++;
  975. if ( this._currentGeo.VertexSetedBoneCount[ nowVertexID ] > 4 ) {
  976. console.log( 'warn! over 4 bone weight! :' + nowVertexID );
  977. }
  978. }
  979. }
  980. for ( var sk = 0; sk < this._currentGeo.Materials.length; sk ++ ) {
  981. this._currentGeo.Materials[ sk ].skinning = true;
  982. }
  983. var offsetList = [];
  984. for ( var _bi = 0; _bi < putBones.length; _bi ++ ) {
  985. if ( putBones[ _bi ].OffsetMatrix ) {
  986. offsetList.push( putBones[ _bi ].OffsetMatrix );
  987. } else {
  988. offsetList.push( new Matrix4() );
  989. }
  990. }
  991. var bufferGeometry = this._buildGeometry();
  992. mesh = new SkinnedMesh( bufferGeometry, this._currentGeo.Materials.length === 1 ? this._currentGeo.Materials[ 0 ] : this._currentGeo.Materials );
  993. this._initSkeleton( mesh, putBones, offsetList );
  994. } else {
  995. var _bufferGeometry = this._buildGeometry();
  996. mesh = new Mesh( _bufferGeometry, this._currentGeo.Materials.length === 1 ? this._currentGeo.Materials[ 0 ] : this._currentGeo.Materials );
  997. }
  998. mesh.name = this._currentGeo.name;
  999. var worldBaseMx = new Matrix4();
  1000. var currentMxFrame = this._currentGeo.baseFrame.putBone;
  1001. if ( currentMxFrame && currentMxFrame.parent ) {
  1002. while ( true ) {
  1003. currentMxFrame = currentMxFrame.parent;
  1004. if ( currentMxFrame ) {
  1005. worldBaseMx.multiply( currentMxFrame.FrameTransformMatrix );
  1006. } else {
  1007. break;
  1008. }
  1009. }
  1010. mesh.applyMatrix4( worldBaseMx );
  1011. }
  1012. this.Meshes.push( mesh );
  1013. }
  1014. }, {
  1015. key: '_initSkeleton',
  1016. value: function _initSkeleton( mesh, boneList, boneInverses ) {
  1017. var bones = [], bone, gbone;
  1018. var i, il;
  1019. for ( i = 0, il = boneList.length; i < il; i ++ ) {
  1020. gbone = boneList[ i ];
  1021. bone = new Bone();
  1022. bones.push( bone );
  1023. bone.name = gbone.name;
  1024. bone.position.fromArray( gbone.pos );
  1025. bone.quaternion.fromArray( gbone.rotq );
  1026. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  1027. }
  1028. for ( i = 0, il = boneList.length; i < il; i ++ ) {
  1029. gbone = boneList[ i ];
  1030. if ( ( gbone.parent !== - 1 ) && ( gbone.parent !== null ) && ( bones[ gbone.parent ] !== undefined ) ) {
  1031. bones[ gbone.parent ].add( bones[ i ] );
  1032. } else {
  1033. mesh.add( bones[ i ] );
  1034. }
  1035. }
  1036. mesh.updateMatrixWorld( true );
  1037. var skeleton = new Skeleton( bones, boneInverses );
  1038. mesh.bind( skeleton, mesh.matrixWorld );
  1039. }
  1040. }, {
  1041. key: '_readAnimationKey',
  1042. value: function _readAnimationKey() {
  1043. var endRead = 0;
  1044. var find = this._currentObject.data.indexOf( ';', endRead );
  1045. var line = this._currentObject.data.substr( endRead, find - endRead );
  1046. endRead = find + 1;
  1047. var nowKeyType = parseInt( this._readLine( line ) );
  1048. find = this._currentObject.data.indexOf( ';', endRead );
  1049. endRead = find + 1;
  1050. line = this._currentObject.data.substr( endRead );
  1051. var data = this._readLine( line.trim() ).split( ";;," );
  1052. for ( var i = 0; i < data.length; i ++ ) {
  1053. var data2 = data[ i ].split( ";" );
  1054. var keyInfo = new XKeyFrameInfo();
  1055. keyInfo.type = nowKeyType;
  1056. keyInfo.Frame = parseInt( data2[ 0 ] );
  1057. keyInfo.index = this._currentAnimeFrames.keyFrames.length;
  1058. keyInfo.time = keyInfo.Frame;
  1059. if ( nowKeyType != 4 ) {
  1060. var frameFound = false;
  1061. for ( var mm = 0; mm < this._currentAnimeFrames.keyFrames.length; mm ++ ) {
  1062. if ( this._currentAnimeFrames.keyFrames[ mm ].Frame === keyInfo.Frame ) {
  1063. keyInfo = this._currentAnimeFrames.keyFrames[ mm ];
  1064. frameFound = true;
  1065. break;
  1066. }
  1067. }
  1068. var frameValue = data2[ 2 ].split( "," );
  1069. switch ( nowKeyType ) {
  1070. case 0:
  1071. keyInfo.rot = new Quaternion( parseFloat( frameValue[ 1 ] ), parseFloat( frameValue[ 2 ] ), parseFloat( frameValue[ 3 ] ), parseFloat( frameValue[ 0 ] ) * - 1 );
  1072. break;
  1073. case 1:
  1074. keyInfo.scl = new Vector3( parseFloat( frameValue[ 0 ] ), parseFloat( frameValue[ 1 ] ), parseFloat( frameValue[ 2 ] ) );
  1075. break;
  1076. case 2:
  1077. keyInfo.pos = new Vector3( parseFloat( frameValue[ 0 ] ), parseFloat( frameValue[ 1 ] ), parseFloat( frameValue[ 2 ] ) );
  1078. break;
  1079. }
  1080. if ( ! frameFound ) {
  1081. this._currentAnimeFrames.keyFrames.push( keyInfo );
  1082. }
  1083. } else {
  1084. keyInfo.matrix = new Matrix4();
  1085. this._ParseMatrixData( keyInfo.matrix, data2[ 2 ].split( "," ) );
  1086. this._currentAnimeFrames.keyFrames.push( keyInfo );
  1087. }
  1088. }
  1089. }
  1090. }, {
  1091. key: '_makeOutputAnimation',
  1092. value: function _makeOutputAnimation() {
  1093. var animationObj = new XAnimationObj( this.options );
  1094. animationObj.fps = this.animTicksPerSecond;
  1095. animationObj.name = this._currentAnime.name;
  1096. animationObj.make( this._currentAnime.AnimeFrames );
  1097. this.animations.push( animationObj );
  1098. }
  1099. }, {
  1100. key: 'assignAnimation',
  1101. value: function assignAnimation( _model, _animation ) {
  1102. var model = _model;
  1103. var animation = _animation;
  1104. if ( ! model ) {
  1105. model = this.Meshes[ 0 ];
  1106. }
  1107. if ( ! animation ) {
  1108. animation = this.animations[ 0 ];
  1109. }
  1110. if ( ! model || ! animation ) {
  1111. return null;
  1112. }
  1113. var put = {};
  1114. put.fps = animation.fps;
  1115. put.name = animation.name;
  1116. put.length = animation.length;
  1117. put.hierarchy = [];
  1118. for ( var b = 0; b < model.skeleton.bones.length; b ++ ) {
  1119. var findAnimation = false;
  1120. for ( var i = 0; i < animation.hierarchy.length; i ++ ) {
  1121. if ( model.skeleton.bones[ b ].name === animation.hierarchy[ i ].name ) {
  1122. findAnimation = true;
  1123. var c_key = animation.hierarchy[ i ].copy();
  1124. c_key.parent = - 1;
  1125. if ( model.skeleton.bones[ b ].parent && model.skeleton.bones[ b ].parent.type === "Bone" ) {
  1126. for ( var bb = 0; bb < put.hierarchy.length; bb ++ ) {
  1127. if ( put.hierarchy[ bb ].name === model.skeleton.bones[ b ].parent.name ) {
  1128. c_key.parent = bb;
  1129. c_key.parentName = model.skeleton.bones[ b ].parent.name;
  1130. }
  1131. }
  1132. }
  1133. put.hierarchy.push( c_key );
  1134. break;
  1135. }
  1136. }
  1137. if ( ! findAnimation ) {
  1138. var _c_key = animation.hierarchy[ 0 ].copy();
  1139. _c_key.name = model.skeleton.bones[ b ].name;
  1140. _c_key.parent = - 1;
  1141. for ( var k = 0; k < _c_key.keys.length; k ++ ) {
  1142. if ( _c_key.keys[ k ].pos ) {
  1143. _c_key.keys[ k ].pos.set( 0, 0, 0 );
  1144. }
  1145. if ( _c_key.keys[ k ].scl ) {
  1146. _c_key.keys[ k ].scl.set( 1, 1, 1 );
  1147. }
  1148. if ( _c_key.keys[ k ].rot ) {
  1149. _c_key.keys[ k ].rot.set( 0, 0, 0, 1 );
  1150. }
  1151. }
  1152. put.hierarchy.push( _c_key );
  1153. }
  1154. }
  1155. if ( ! model.geometry.animations ) {
  1156. model.geometry.animations = [];
  1157. }
  1158. model.geometry.animations.push( AnimationClip.parseAnimation( put, model.skeleton.bones ) );
  1159. if ( ! model.animationMixer ) {
  1160. model.animationMixer = new AnimationMixer( model );
  1161. }
  1162. return put;
  1163. }
  1164. }, {
  1165. key: '_ParseMatrixData',
  1166. value: function _ParseMatrixData( targetMatrix, data ) {
  1167. targetMatrix.set( parseFloat( data[ 0 ] ), parseFloat( data[ 4 ] ), parseFloat( data[ 8 ] ), parseFloat( data[ 12 ] ), parseFloat( data[ 1 ] ), parseFloat( data[ 5 ] ), parseFloat( data[ 9 ] ), parseFloat( data[ 13 ] ), parseFloat( data[ 2 ] ), parseFloat( data[ 6 ] ), parseFloat( data[ 10 ] ), parseFloat( data[ 14 ] ), parseFloat( data[ 3 ] ), parseFloat( data[ 7 ] ), parseFloat( data[ 11 ] ), parseFloat( data[ 15 ] ) );
  1168. }
  1169. } ] );
  1170. return XLoader;
  1171. }();
  1172. return XLoader;
  1173. } )();
  1174. export { XLoader };