XLoader.js 39 KB

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