XLoader.js 39 KB

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