XLoader.js 39 KB

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