XLoader.js 39 KB

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