XLoader.js 40 KB

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