XLoader.js 40 KB

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