XLoader.js 39 KB

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