XLoader.js 39 KB

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