XLoader.js 39 KB

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