XLoader.js 40 KB

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