XLoader.js 39 KB

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