XLoader.js 41 KB

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