XLoader.js 40 KB

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