2
0

XLoader.js 39 KB

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