XLoader.js 39 KB

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