XLoader.js 40 KB

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