XLoader.js 39 KB

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