XLoader.js 40 KB

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