XLoader.js 39 KB

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