XLoader.js 39 KB

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