2
0

XLoader.js 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562
  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. var b = new THREE.Bone();
  504. b.name = this._currentFrame.name;
  505. b.applyMatrix( this._currentFrame.FrameTransformMatrix );
  506. b.matrixWorld = b.matrix;
  507. b.FrameTransformMatrix = this._currentFrame.FrameTransformMatrix;
  508. this._currentFrame.putBone = b;
  509. if ( this._currentFrame.parentName ) {
  510. for ( var frame in this.HieStack ) {
  511. if ( this.HieStack[ frame ].name === this._currentFrame.parentName ) {
  512. this.HieStack[ frame ].putBone.add( this._currentFrame.putBone );
  513. }
  514. }
  515. }
  516. }
  517. }, {
  518. key: '_readVertexDatas',
  519. value: function _readVertexDatas() {
  520. var endRead = 0;
  521. var mode = 0;
  522. var mode_local = 0;
  523. var maxLength = 0;
  524. var nowReadedLine = 0;
  525. while ( true ) {
  526. var changeMode = false;
  527. if ( mode_local === 0 ) {
  528. var refO = this._readInt1( endRead );
  529. endRead = refO.endRead;
  530. mode_local = 1;
  531. nowReadedLine = 0;
  532. maxLength = this._currentObject.data.indexOf( ';;', endRead ) + 1;
  533. if ( maxLength <= 0 ) {
  534. maxLength = this._currentObject.data.length;
  535. }
  536. } else {
  537. var find = 0;
  538. switch ( mode ) {
  539. case 0:
  540. find = this._currentObject.data.indexOf( ',', endRead ) + 1;
  541. break;
  542. case 1:
  543. find = this._currentObject.data.indexOf( ';,', endRead ) + 1;
  544. break;
  545. }
  546. if ( find === 0 || find > maxLength ) {
  547. find = maxLength;
  548. mode_local = 0;
  549. changeMode = true;
  550. }
  551. switch ( this._currentObject.type ) {
  552. case "Mesh":
  553. switch ( mode ) {
  554. case 0:
  555. this._readVertex1( this._currentObject.data.substr( endRead, find - endRead ) );
  556. break;
  557. case 1:
  558. this._readFace1( this._currentObject.data.substr( endRead, find - endRead ) );
  559. break;
  560. }
  561. break;
  562. case "MeshNormals":
  563. switch ( mode ) {
  564. case 0:
  565. this._readNormalVector1( this._currentObject.data.substr( endRead, find - endRead ) );
  566. break;
  567. case 1:
  568. this._readNormalFace1( this._currentObject.data.substr( endRead, find - endRead ), nowReadedLine );
  569. break;
  570. }
  571. break;
  572. }
  573. endRead = find + 1;
  574. nowReadedLine ++;
  575. if ( changeMode ) {
  576. mode ++;
  577. }
  578. }
  579. if ( endRead >= this._currentObject.data.length ) {
  580. break;
  581. }
  582. }
  583. }
  584. }, {
  585. key: '_readInt1',
  586. value: function _readInt1( start ) {
  587. var find = this._currentObject.data.indexOf( ';', start );
  588. return {
  589. refI: parseInt( this._currentObject.data.substr( start, find - start ) ),
  590. endRead: find + 1
  591. };
  592. }
  593. }, {
  594. key: '_readVertex1',
  595. value: function _readVertex1( line ) {
  596. var data = this._readLine( line.trim() ).substr( 0, line.length - 2 ).split( ";" );
  597. this._currentGeo.Geometry.vertices.push( new THREE.Vector3( parseFloat( data[ 0 ] ), parseFloat( data[ 1 ] ), parseFloat( data[ 2 ] ) ) );
  598. this._currentGeo.Geometry.skinIndices.push( new THREE.Vector4( 0, 0, 0, 0 ) );
  599. this._currentGeo.Geometry.skinWeights.push( new THREE.Vector4( 1, 0, 0, 0 ) );
  600. this._currentGeo.VertexSetedBoneCount.push( 0 );
  601. }
  602. }, {
  603. key: '_readFace1',
  604. value: function _readFace1( line ) {
  605. var data = this._readLine( line.trim() ).substr( 2, line.length - 4 ).split( "," );
  606. 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() ) );
  607. }
  608. }, {
  609. key: '_readNormalVector1',
  610. value: function _readNormalVector1( line ) {
  611. var data = this._readLine( line.trim() ).substr( 0, line.length - 2 ).split( ";" );
  612. if ( this.options.zflag ) {
  613. this._currentGeo.normalVectors.push( new THREE.Vector3( parseFloat( data[ 0 ] ) * - 1, parseFloat( data[ 1 ] ) * - 1, parseFloat( data[ 2 ] ) * - 1 ) );
  614. } else {
  615. this._currentGeo.normalVectors.push( new THREE.Vector3( parseFloat( data[ 0 ] ), parseFloat( data[ 1 ] ), parseFloat( data[ 2 ] ) ) );
  616. }
  617. }
  618. }, {
  619. key: '_readNormalFace1',
  620. value: function _readNormalFace1( line, nowReaded ) {
  621. var data = this._readLine( line.trim() ).substr( 2, line.length - 4 ).split( "," );
  622. var nowID = parseInt( data[ 0 ], 10 );
  623. var v1 = this._currentGeo.normalVectors[ nowID ];
  624. nowID = parseInt( data[ 1 ], 10 );
  625. var v2 = this._currentGeo.normalVectors[ nowID ];
  626. nowID = parseInt( data[ 2 ], 10 );
  627. var v3 = this._currentGeo.normalVectors[ nowID ];
  628. this._currentGeo.Geometry.faces[ nowReaded ].vertexNormals = [ v1, v2, v3 ];
  629. }
  630. }, {
  631. key: '_setMeshNormals',
  632. value: function _setMeshNormals() {
  633. var endRead = 0;
  634. var mode = 0;
  635. var mode_local = 0;
  636. while ( true ) {
  637. switch ( mode ) {
  638. case 0:
  639. if ( mode_local === 0 ) {
  640. var refO = this._readInt1( 0 );
  641. endRead = refO.endRead;
  642. mode_local = 1;
  643. } else {
  644. var find = this._currentObject.data.indexOf( ',', endRead ) + 1;
  645. if ( find === - 1 ) {
  646. find = this._currentObject.data.indexOf( ';;', endRead ) + 1;
  647. mode = 2;
  648. mode_local = 0;
  649. }
  650. var line = this._currentObject.data.substr( endRead, find - endRead );
  651. var data = this._readLine( line.trim() ).split( ";" );
  652. this._currentGeo.normalVectors.push( [ parseFloat( data[ 0 ] ), parseFloat( data[ 1 ] ), parseFloat( data[ 2 ] ) ] );
  653. endRead = find + 1;
  654. }
  655. break;
  656. }
  657. if ( endRead >= this._currentObject.data.length ) {
  658. break;
  659. }
  660. }
  661. }
  662. }, {
  663. key: '_setMeshTextureCoords',
  664. value: function _setMeshTextureCoords() {
  665. this._tmpUvArray = [];
  666. this._currentGeo.Geometry.faceVertexUvs = [];
  667. this._currentGeo.Geometry.faceVertexUvs.push( [] );
  668. var endRead = 0;
  669. var mode = 0;
  670. var mode_local = 0;
  671. while ( true ) {
  672. switch ( mode ) {
  673. case 0:
  674. if ( mode_local === 0 ) {
  675. var refO = this._readInt1( 0 );
  676. endRead = refO.endRead;
  677. mode_local = 1;
  678. } else {
  679. var find = this._currentObject.data.indexOf( ',', endRead ) + 1;
  680. if ( find === 0 ) {
  681. find = this._currentObject.data.length;
  682. mode = 2;
  683. mode_local = 0;
  684. }
  685. var line = this._currentObject.data.substr( endRead, find - endRead );
  686. var data = this._readLine( line.trim() ).split( ";" );
  687. if ( this.IsUvYReverse ) {
  688. this._tmpUvArray.push( new THREE.Vector2( parseFloat( data[ 0 ] ), 1 - parseFloat( data[ 1 ] ) ) );
  689. } else {
  690. this._tmpUvArray.push( new THREE.Vector2( parseFloat( data[ 0 ] ), parseFloat( data[ 1 ] ) ) );
  691. }
  692. endRead = find + 1;
  693. }
  694. break;
  695. }
  696. if ( endRead >= this._currentObject.data.length ) {
  697. break;
  698. }
  699. }
  700. this._currentGeo.Geometry.faceVertexUvs[ 0 ] = [];
  701. for ( var m = 0; m < this._currentGeo.Geometry.faces.length; m ++ ) {
  702. this._currentGeo.Geometry.faceVertexUvs[ 0 ][ m ] = [];
  703. this._currentGeo.Geometry.faceVertexUvs[ 0 ][ m ].push( this._tmpUvArray[ this._currentGeo.Geometry.faces[ m ].a ] );
  704. this._currentGeo.Geometry.faceVertexUvs[ 0 ][ m ].push( this._tmpUvArray[ this._currentGeo.Geometry.faces[ m ].b ] );
  705. this._currentGeo.Geometry.faceVertexUvs[ 0 ][ m ].push( this._tmpUvArray[ this._currentGeo.Geometry.faces[ m ].c ] );
  706. }
  707. this._currentGeo.Geometry.uvsNeedUpdate = true;
  708. }
  709. }, {
  710. key: '_setMeshMaterialList',
  711. value: function _setMeshMaterialList() {
  712. var endRead = 0;
  713. var mode = 0;
  714. var mode_local = 0;
  715. while ( true ) {
  716. if ( mode_local < 2 ) {
  717. var refO = this._readInt1( endRead );
  718. endRead = refO.endRead;
  719. mode_local ++;
  720. } else {
  721. var find = this._currentObject.data.indexOf( ';', endRead );
  722. if ( find === - 1 ) {
  723. find = this._currentObject.data.length;
  724. mode = 3;
  725. mode_local = 0;
  726. }
  727. var line = this._currentObject.data.substr( endRead, find - endRead );
  728. var data = this._readLine( line.trim() ).split( "," );
  729. for ( var i = 0; i < data.length; i ++ ) {
  730. this._currentGeo.Geometry.faces[ i ].materialIndex = parseInt( data[ i ] );
  731. }
  732. endRead = this._currentObject.data.length;
  733. }
  734. if ( endRead >= this._currentObject.data.length || mode >= 3 ) {
  735. break;
  736. }
  737. }
  738. }
  739. }, {
  740. key: '_setMaterial',
  741. value: function _setMaterial() {
  742. var _nowMat = new THREE.MeshPhongMaterial( {
  743. color: Math.random() * 0xffffff
  744. } );
  745. if ( this.options.zflag ) {
  746. _nowMat.side = THREE.BackSide;
  747. } else {
  748. _nowMat.side = THREE.FrontSide;
  749. }
  750. _nowMat.name = this._currentObject.name;
  751. var endRead = 0;
  752. var find = this._currentObject.data.indexOf( ';;', endRead );
  753. var line = this._currentObject.data.substr( endRead, find - endRead );
  754. var data = this._readLine( line.trim() ).split( ";" );
  755. _nowMat.color.r = parseFloat( data[ 0 ] );
  756. _nowMat.color.g = parseFloat( data[ 1 ] );
  757. _nowMat.color.b = parseFloat( data[ 2 ] );
  758. endRead = find + 2;
  759. find = this._currentObject.data.indexOf( ';', endRead );
  760. line = this._currentObject.data.substr( endRead, find - endRead );
  761. _nowMat.shininess = parseFloat( this._readLine( line ) );
  762. endRead = find + 1;
  763. find = this._currentObject.data.indexOf( ';;', endRead );
  764. line = this._currentObject.data.substr( endRead, find - endRead );
  765. var data2 = this._readLine( line.trim() ).split( ";" );
  766. _nowMat.specular.r = parseFloat( data2[ 0 ] );
  767. _nowMat.specular.g = parseFloat( data2[ 1 ] );
  768. _nowMat.specular.b = parseFloat( data2[ 2 ] );
  769. endRead = find + 2;
  770. find = this._currentObject.data.indexOf( ';;', endRead );
  771. if ( find === - 1 ) {
  772. find = this._currentObject.data.length;
  773. }
  774. line = this._currentObject.data.substr( endRead, find - endRead );
  775. var data3 = this._readLine( line.trim() ).split( ";" );
  776. _nowMat.emissive.r = parseFloat( data3[ 0 ] );
  777. _nowMat.emissive.g = parseFloat( data3[ 1 ] );
  778. _nowMat.emissive.b = parseFloat( data3[ 2 ] );
  779. var localObject = null;
  780. while ( true ) {
  781. if ( this._currentObject.children.length > 0 ) {
  782. localObject = this._currentObject.children.shift();
  783. if ( this.debug ) {
  784. console.log( 'processing ' + localObject.name );
  785. }
  786. var fileName = localObject.data.substr( 1, localObject.data.length - 2 );
  787. switch ( localObject.type ) {
  788. case "TextureFilename":
  789. _nowMat.map = this.texloader.load( this.baseDir + fileName );
  790. break;
  791. case "BumpMapFilename":
  792. _nowMat.bumpMap = this.texloader.load( this.baseDir + fileName );
  793. _nowMat.bumpScale = 0.05;
  794. break;
  795. case "NormalMapFilename":
  796. _nowMat.normalMap = this.texloader.load( this.baseDir + fileName );
  797. _nowMat.normalScale = new THREE.Vector2( 2, 2 );
  798. break;
  799. case "EmissiveMapFilename":
  800. _nowMat.emissiveMap = this.texloader.load( this.baseDir + fileName );
  801. break;
  802. case "LightMapFilename":
  803. _nowMat.lightMap = this.texloader.load( this.baseDir + fileName );
  804. break;
  805. }
  806. } else {
  807. break;
  808. }
  809. }
  810. this._currentGeo.Materials.push( _nowMat );
  811. }
  812. }, {
  813. key: '_setSkinWeights',
  814. value: function _setSkinWeights() {
  815. var boneInf = new XboneInf();
  816. var endRead = 0;
  817. var find = this._currentObject.data.indexOf( ';', endRead );
  818. var line = this._currentObject.data.substr( endRead, find - endRead );
  819. endRead = find + 1;
  820. boneInf.boneName = line.substr( 1, line.length - 2 );
  821. boneInf.BoneIndex = this._currentGeo.BoneInfs.length;
  822. find = this._currentObject.data.indexOf( ';', endRead );
  823. endRead = find + 1;
  824. find = this._currentObject.data.indexOf( ';', endRead );
  825. line = this._currentObject.data.substr( endRead, find - endRead );
  826. var data = this._readLine( line.trim() ).split( "," );
  827. for ( var i = 0; i < data.length; i ++ ) {
  828. boneInf.Indeces.push( parseInt( data[ i ] ) );
  829. }
  830. endRead = find + 1;
  831. find = this._currentObject.data.indexOf( ';', endRead );
  832. line = this._currentObject.data.substr( endRead, find - endRead );
  833. var data2 = this._readLine( line.trim() ).split( "," );
  834. for ( var _i = 0; _i < data2.length; _i ++ ) {
  835. boneInf.Weights.push( parseFloat( data2[ _i ] ) );
  836. }
  837. endRead = find + 1;
  838. find = this._currentObject.data.indexOf( ';', endRead );
  839. if ( find <= 0 ) {
  840. find = this._currentObject.data.length;
  841. }
  842. line = this._currentObject.data.substr( endRead, find - endRead );
  843. var data3 = this._readLine( line.trim() ).split( "," );
  844. boneInf.OffsetMatrix = new THREE.Matrix4();
  845. this._ParseMatrixData( boneInf.OffsetMatrix, data3 );
  846. this._currentGeo.BoneInfs.push( boneInf );
  847. }
  848. }, {
  849. key: '_makePutBoneList',
  850. value: function _makePutBoneList( _RootName, _bones ) {
  851. var putting = false;
  852. for ( var frame in this.HieStack ) {
  853. if ( this.HieStack[ frame ].name === _RootName || putting ) {
  854. putting = true;
  855. var b = new THREE.Bone();
  856. b.name = this.HieStack[ frame ].name;
  857. b.applyMatrix( this.HieStack[ frame ].FrameTransformMatrix );
  858. b.matrixWorld = b.matrix;
  859. b.FrameTransformMatrix = this.HieStack[ frame ].FrameTransformMatrix;
  860. b.pos = new THREE.Vector3().setFromMatrixPosition( b.FrameTransformMatrix ).toArray();
  861. b.rotq = new THREE.Quaternion().setFromRotationMatrix( b.FrameTransformMatrix ).toArray();
  862. b.scl = new THREE.Vector3().setFromMatrixScale( b.FrameTransformMatrix ).toArray();
  863. if ( this.HieStack[ frame ].parentName && this.HieStack[ frame ].parentName.length > 0 ) {
  864. for ( var i = 0; i < _bones.length; i ++ ) {
  865. if ( this.HieStack[ frame ].parentName === _bones[ i ].name ) {
  866. _bones[ i ].add( b );
  867. b.parent = i;
  868. break;
  869. }
  870. }
  871. }
  872. _bones.push( b );
  873. }
  874. }
  875. }
  876. }, {
  877. key: '_makeOutputGeometry',
  878. value: function _makeOutputGeometry() {
  879. this._currentGeo.Geometry.computeBoundingBox();
  880. this._currentGeo.Geometry.computeBoundingSphere();
  881. this._currentGeo.Geometry.verticesNeedUpdate = true;
  882. this._currentGeo.Geometry.normalsNeedUpdate = true;
  883. this._currentGeo.Geometry.colorsNeedUpdate = true;
  884. this._currentGeo.Geometry.uvsNeedUpdate = true;
  885. this._currentGeo.Geometry.groupsNeedUpdate = true;
  886. var mesh = null;
  887. if ( this._currentGeo.BoneInfs.length > 0 ) {
  888. var putBones = [];
  889. this._makePutBoneList( this._currentGeo.baseFrame.parentName, putBones );
  890. for ( var bi = 0; bi < this._currentGeo.BoneInfs.length; bi ++ ) {
  891. var boneIndex = 0;
  892. for ( var bb = 0; bb < putBones.length; bb ++ ) {
  893. if ( putBones[ bb ].name === this._currentGeo.BoneInfs[ bi ].boneName ) {
  894. boneIndex = bb;
  895. putBones[ bb ].OffsetMatrix = new THREE.Matrix4();
  896. putBones[ bb ].OffsetMatrix.copy( this._currentGeo.BoneInfs[ bi ].OffsetMatrix );
  897. break;
  898. }
  899. }
  900. for ( var vi = 0; vi < this._currentGeo.BoneInfs[ bi ].Indeces.length; vi ++ ) {
  901. var nowVertexID = this._currentGeo.BoneInfs[ bi ].Indeces[ vi ];
  902. var nowVal = this._currentGeo.BoneInfs[ bi ].Weights[ vi ];
  903. switch ( this._currentGeo.VertexSetedBoneCount[ nowVertexID ] ) {
  904. case 0:
  905. this._currentGeo.Geometry.skinIndices[ nowVertexID ].x = boneIndex;
  906. this._currentGeo.Geometry.skinWeights[ nowVertexID ].x = nowVal;
  907. break;
  908. case 1:
  909. this._currentGeo.Geometry.skinIndices[ nowVertexID ].y = boneIndex;
  910. this._currentGeo.Geometry.skinWeights[ nowVertexID ].y = nowVal;
  911. break;
  912. case 2:
  913. this._currentGeo.Geometry.skinIndices[ nowVertexID ].z = boneIndex;
  914. this._currentGeo.Geometry.skinWeights[ nowVertexID ].z = nowVal;
  915. break;
  916. case 3:
  917. this._currentGeo.Geometry.skinIndices[ nowVertexID ].w = boneIndex;
  918. this._currentGeo.Geometry.skinWeights[ nowVertexID ].w = nowVal;
  919. break;
  920. }
  921. this._currentGeo.VertexSetedBoneCount[ nowVertexID ] ++;
  922. if ( this._currentGeo.VertexSetedBoneCount[ nowVertexID ] > 4 ) {
  923. console.log( 'warn! over 4 bone weight! :' + nowVertexID );
  924. }
  925. }
  926. }
  927. for ( var sk = 0; sk < this._currentGeo.Materials.length; sk ++ ) {
  928. this._currentGeo.Materials[ sk ].skinning = true;
  929. }
  930. var offsetList = [];
  931. for ( var _bi = 0; _bi < putBones.length; _bi ++ ) {
  932. if ( putBones[ _bi ].OffsetMatrix ) {
  933. offsetList.push( putBones[ _bi ].OffsetMatrix );
  934. } else {
  935. offsetList.push( new THREE.Matrix4() );
  936. }
  937. }
  938. var bufferGeometry = new THREE.BufferGeometry().fromGeometry( this._currentGeo.Geometry );
  939. bufferGeometry.bones = putBones;
  940. mesh = new THREE.SkinnedMesh( bufferGeometry, new THREE.MultiMaterial( this._currentGeo.Materials ) );
  941. mesh.skeleton.boneInverses = offsetList;
  942. } else {
  943. var _bufferGeometry = new THREE.BufferGeometry().fromGeometry( this._currentGeo.Geometry );
  944. mesh = new THREE.Mesh( _bufferGeometry, new THREE.MultiMaterial( this._currentGeo.Materials ) );
  945. }
  946. mesh.name = this._currentGeo.name;
  947. var worldBaseMx = new THREE.Matrix4();
  948. var currentMxFrame = this._currentGeo.baseFrame.putBone;
  949. if ( currentMxFrame.parent ) {
  950. while ( true ) {
  951. currentMxFrame = currentMxFrame.parent;
  952. if ( currentMxFrame ) {
  953. worldBaseMx.multiply( currentMxFrame.FrameTransformMatrix );
  954. } else {
  955. break;
  956. }
  957. }
  958. }
  959. mesh.applyMatrix( worldBaseMx );
  960. this.Meshes.push( mesh );
  961. }
  962. }, {
  963. key: '_readAnimationKey',
  964. value: function _readAnimationKey() {
  965. var endRead = 0;
  966. var find = this._currentObject.data.indexOf( ';', endRead );
  967. var line = this._currentObject.data.substr( endRead, find - endRead );
  968. endRead = find + 1;
  969. var nowKeyType = parseInt( this._readLine( line ) );
  970. find = this._currentObject.data.indexOf( ';', endRead );
  971. endRead = find + 1;
  972. line = this._currentObject.data.substr( endRead );
  973. var data = this._readLine( line.trim() ).split( ";;," );
  974. for ( var i = 0; i < data.length; i ++ ) {
  975. var data2 = data[ i ].split( ";" );
  976. var keyInfo = new XKeyFrameInfo();
  977. keyInfo.type = nowKeyType;
  978. keyInfo.Frame = parseInt( data2[ 0 ] );
  979. keyInfo.index = this._currentAnimeFrames.keyFrames.length;
  980. keyInfo.time = keyInfo.Frame;
  981. if ( nowKeyType != 4 ) {
  982. var frameFound = false;
  983. for ( var mm = 0; mm < this._currentAnimeFrames.keyFrames.length; mm ++ ) {
  984. if ( this._currentAnimeFrames.keyFrames[ mm ].Frame === keyInfo.Frame ) {
  985. keyInfo = this._currentAnimeFrames.keyFrames[ mm ];
  986. frameFound = true;
  987. break;
  988. }
  989. }
  990. var frameValue = data2[ 2 ].split( "," );
  991. switch ( nowKeyType ) {
  992. case 0:
  993. keyInfo.rot = new THREE.Quaternion( parseFloat( frameValue[ 1 ] ), parseFloat( frameValue[ 2 ] ), parseFloat( frameValue[ 3 ] ), parseFloat( frameValue[ 0 ] ) * - 1 );
  994. break;
  995. case 1:
  996. keyInfo.scl = new THREE.Vector3( parseFloat( frameValue[ 0 ] ), parseFloat( frameValue[ 1 ] ), parseFloat( frameValue[ 2 ] ) );
  997. break;
  998. case 2:
  999. keyInfo.pos = new THREE.Vector3( parseFloat( frameValue[ 0 ] ), parseFloat( frameValue[ 1 ] ), parseFloat( frameValue[ 2 ] ) );
  1000. break;
  1001. }
  1002. if ( ! frameFound ) {
  1003. this._currentAnimeFrames.keyFrames.push( keyInfo );
  1004. }
  1005. } else {
  1006. keyInfo.matrix = new THREE.Matrix4();
  1007. this._ParseMatrixData( keyInfo.matrix, data2[ 2 ].split( "," ) );
  1008. this._currentAnimeFrames.keyFrames.push( keyInfo );
  1009. }
  1010. }
  1011. }
  1012. }, {
  1013. key: '_makeOutputAnimation',
  1014. value: function _makeOutputAnimation() {
  1015. var animationObj = new XAnimationObj( this.options );
  1016. animationObj.fps = this.animTicksPerSecond;
  1017. animationObj.name = this._currentAnime.name;
  1018. animationObj.make( this._currentAnime.AnimeFrames );
  1019. this.animations.push( animationObj );
  1020. }
  1021. }, {
  1022. key: 'assignAnimation',
  1023. value: function assignAnimation( _model, _animation, _isBind ) {
  1024. var model = _model;
  1025. var animation = _animation;
  1026. var bindFlag = _isBind ? _isBind : true;
  1027. if ( ! model ) {
  1028. model = this.Meshes[ 0 ];
  1029. }
  1030. if ( ! animation ) {
  1031. animation = this.animations[ 0 ];
  1032. }
  1033. if ( ! model || ! animation ) {
  1034. return null;
  1035. }
  1036. var put = {};
  1037. put.fps = animation.fps;
  1038. put.name = animation.name;
  1039. put.length = animation.length;
  1040. put.hierarchy = [];
  1041. for ( var b = 0; b < model.skeleton.bones.length; b ++ ) {
  1042. var findAnimation = false;
  1043. for ( var i = 0; i < animation.hierarchy.length; i ++ ) {
  1044. if ( model.skeleton.bones[ b ].name === animation.hierarchy[ i ].name ) {
  1045. findAnimation = true;
  1046. var c_key = animation.hierarchy[ i ].copy();
  1047. c_key.parent = - 1;
  1048. if ( model.skeleton.bones[ b ].parent && model.skeleton.bones[ b ].parent.type === "Bone" ) {
  1049. for ( var bb = 0; bb < put.hierarchy.length; bb ++ ) {
  1050. if ( put.hierarchy[ bb ].name === model.skeleton.bones[ b ].parent.name ) {
  1051. c_key.parent = bb;
  1052. c_key.parentName = model.skeleton.bones[ b ].parent.name;
  1053. }
  1054. }
  1055. }
  1056. put.hierarchy.push( c_key );
  1057. break;
  1058. }
  1059. }
  1060. if ( ! findAnimation ) {
  1061. var _c_key = animation.hierarchy[ 0 ].copy();
  1062. _c_key.name = model.skeleton.bones[ b ].name;
  1063. _c_key.parent = - 1;
  1064. for ( var k = 0; k < _c_key.keys.length; k ++ ) {
  1065. if ( _c_key.keys[ k ].pos ) {
  1066. _c_key.keys[ k ].pos.set( 0, 0, 0 );
  1067. }
  1068. if ( _c_key.keys[ k ].scl ) {
  1069. _c_key.keys[ k ].scl.set( 1, 1, 1 );
  1070. }
  1071. if ( _c_key.keys[ k ].rot ) {
  1072. _c_key.keys[ k ].rot.set( 0, 0, 0, 1 );
  1073. }
  1074. }
  1075. put.hierarchy.push( _c_key );
  1076. }
  1077. }
  1078. if ( ! model.geometry.animations ) {
  1079. model.geometry.animations = [];
  1080. }
  1081. if ( bindFlag ) {
  1082. model.geometry.animations.push( THREE.AnimationClip.parseAnimation( put, model.skeleton.bones ) );
  1083. if ( ! model.animationMixer ) {
  1084. model.animationMixer = new THREE.AnimationMixer( model );
  1085. }
  1086. }
  1087. return put;
  1088. }
  1089. }, {
  1090. key: '_readFinalize',
  1091. value: function _readFinalize() {
  1092. if ( this.options.zflag ) {
  1093. for ( var i = 0; i < this.Meshes.length; i ++ ) {
  1094. this.Meshes[ i ].scale.set( - 1, 1, 1 );
  1095. }
  1096. }
  1097. }
  1098. }, {
  1099. key: '_ParseMatrixData',
  1100. value: function _ParseMatrixData( targetMatrix, data ) {
  1101. 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 ] ) );
  1102. }
  1103. } ] );
  1104. return XLoader;
  1105. }();
  1106. return XLoader;
  1107. } ) ) );