XLoader.js 39 KB

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