XLoader.js 38 KB

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