XLoader.js 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100
  1. /**
  2. * @author Jey-en https://github.com/adrs2002
  3. *
  4. * this loader repo -> https://github.com/adrs2002/threeXLoader
  5. *
  6. * This loader is load model (and animation) from .X file format. (for old DirectX).
  7. * ! this version are load from TEXT format .X only ! not a Binary.
  8. *
  9. * Support
  10. * - mesh
  11. * - texture
  12. * - normal / uv
  13. * - material
  14. * - skinning
  15. *
  16. * Not Support
  17. * - template
  18. * - material(ditail)
  19. * - morph
  20. * - scene
  21. */
  22. var XfileLoadMode$1 = XfileLoadMode = {
  23. none: -1,
  24. Element: 1,
  25. FrameTransformMatrix_Read: 3,
  26. Mesh: 5,
  27. Vartex_init: 10,
  28. Vartex_Read: 11,
  29. Index_init: 20,
  30. index_Read: 21,
  31. Uv_init: 30,
  32. Uv_Read: 31,
  33. Normal_V_init: 40,
  34. Normal_V_Read: 41,
  35. Normal_I_init: 42,
  36. Normal_I_Read: 43,
  37. Mat_Face_init: 101,
  38. Mat_Face_len_Read: 102,
  39. Mat_Face_Set: 103,
  40. Mat_Set: 111,
  41. Mat_Set_Texture: 121,
  42. Mat_Set_LightTex: 122,
  43. Mat_Set_EmissiveTex: 123,
  44. Mat_Set_BumpTex: 124,
  45. Mat_Set_NormalTex: 125,
  46. Mat_Set_EnvTex: 126,
  47. Weit_init: 201,
  48. Weit_IndexLength: 202,
  49. Weit_Read_Index: 203,
  50. Weit_Read_Value: 204,
  51. Weit_Read_Matrx: 205,
  52. Anim_init: 1001,
  53. Anim_Reading: 1002,
  54. Anim_KeyValueTypeRead: 1003,
  55. Anim_KeyValueLength: 1004,
  56. Anime_ReadKeyFrame: 1005
  57. };
  58. var classCallCheck = function (instance, Constructor) {
  59. if (!(instance instanceof Constructor)) {
  60. throw new TypeError("Cannot call a class as a function");
  61. }
  62. };
  63. var createClass = function () {
  64. function defineProperties(target, props) {
  65. for (var i = 0; i < props.length; i++) {
  66. var descriptor = props[i];
  67. descriptor.enumerable = descriptor.enumerable || false;
  68. descriptor.configurable = true;
  69. if ("value" in descriptor) descriptor.writable = true;
  70. Object.defineProperty(target, descriptor.key, descriptor);
  71. }
  72. }
  73. return function (Constructor, protoProps, staticProps) {
  74. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  75. if (staticProps) defineProperties(Constructor, staticProps);
  76. return Constructor;
  77. };
  78. }();
  79. var XAnimationObj = function () {
  80. function XAnimationObj() {
  81. classCallCheck(this, XAnimationObj);
  82. this.fps = 30;
  83. this.name = 'xanimation';
  84. this.length = 0;
  85. this.hierarchy = [];
  86. }
  87. createClass(XAnimationObj, [{
  88. key: 'make',
  89. value: function make(XAnimationInfoArray, mesh) {
  90. var keys = Object.keys(XAnimationInfoArray);
  91. var hierarchy_tmp = [];
  92. for (var i = 0; i < keys.length; i++) {
  93. var bone = null;
  94. var parent = -1;
  95. var baseIndex = -1;
  96. for (var m = 0; m < mesh.skeleton.bones.length; m++) {
  97. if (mesh.skeleton.bones[m].name == XAnimationInfoArray[keys[i]].boneName) {
  98. bone = XAnimationInfoArray[keys[i]].boneName;
  99. parent = mesh.skeleton.bones[m].parent.name;
  100. baseIndex = m;
  101. break;
  102. }
  103. }
  104. hierarchy_tmp[baseIndex] = this.makeBonekeys(XAnimationInfoArray[keys[i]], bone, parent);
  105. }
  106. var keys2 = Object.keys(hierarchy_tmp);
  107. for (var _i = 0; _i < keys2.length; _i++) {
  108. this.hierarchy.push(hierarchy_tmp[_i]);
  109. var parentId = -1;
  110. for (var _m = 0; _m < this.hierarchy.length; _m++) {
  111. if (_i != _m && this.hierarchy[_i].parent === this.hierarchy[_m].name) {
  112. parentId = _m;
  113. break;
  114. }
  115. }
  116. this.hierarchy[_i].parent = parentId;
  117. }
  118. }
  119. }, {
  120. key: 'makeBonekeys',
  121. value: function makeBonekeys(XAnimationInfo, bone, parent) {
  122. var refObj = {};
  123. refObj.name = bone;
  124. refObj.parent = parent;
  125. refObj.keys = [];
  126. for (var i = 0; i < XAnimationInfo.keyFrames.length; i++) {
  127. var keyframe = {};
  128. keyframe.time = XAnimationInfo.keyFrames[i].time * this.fps;
  129. keyframe.matrix = XAnimationInfo.keyFrames[i].matrix;
  130. keyframe.pos = new THREE.Vector3().setFromMatrixPosition(keyframe.matrix);
  131. keyframe.rot = new THREE.Quaternion().setFromRotationMatrix(keyframe.matrix);
  132. keyframe.scl = new THREE.Vector3().setFromMatrixScale(keyframe.matrix);
  133. refObj.keys.push(keyframe);
  134. }
  135. return refObj;
  136. }
  137. }]);
  138. return XAnimationObj;
  139. }();
  140. var Xdata = function Xdata() {
  141. classCallCheck(this, Xdata);
  142. this.FrameInfo = [];
  143. this.FrameInfo_Raw = [];
  144. this.AnimationSetInfo = [];
  145. this.AnimTicksPerSecond = 60;
  146. this.XAnimationObj = null;
  147. };
  148. var XboneInf = function XboneInf() {
  149. classCallCheck(this, XboneInf);
  150. this.boneName = "";
  151. this.BoneIndex = 0;
  152. this.Indeces = [];
  153. this.Weights = [];
  154. this.initMatrix = null;
  155. this.OffsetMatrix = null;
  156. };
  157. var XAnimationInfo$1 = XAnimationInfo = function XAnimationInfo() {
  158. this.animeName = "";
  159. this.boneName = "";
  160. this.targetBone = null;
  161. this.frameStartLv = 0;
  162. this.keyFrames = [];
  163. this.InverseMx = null;
  164. };
  165. var XFrameInfo$1 = XFrameInfo = function XFrameInfo() {
  166. this.Mesh = null;
  167. this.Geometry = null;
  168. this.FrameName = "";
  169. this.ParentName = "";
  170. this.frameStartLv = 0;
  171. this.FrameTransformMatrix = null;
  172. this.children = [];
  173. this.BoneInfs = [];
  174. this.VertexSetedBoneCount = [];
  175. this.Materials = [];
  176. };
  177. var XKeyFrameInfo = function XKeyFrameInfo() {
  178. classCallCheck(this, XKeyFrameInfo);
  179. this.index = 0;
  180. this.Frame = 0;
  181. this.time = 0.0;
  182. this.matrix = null;
  183. };
  184. THREE.XLoader = function () {
  185. function XLoader(manager, Texloader, _zflg) {
  186. classCallCheck(this, XLoader);
  187. this.manager = manager !== undefined ? manager : new THREE.LoadingManager();
  188. this.Texloader = Texloader !== undefined ? Texloader : new THREE.TextureLoader();
  189. this.zflg = _zflg === undefined ? false : _zflg;
  190. this.url = "";
  191. this.baseDir = "";
  192. this.nowReadMode = XfileLoadMode$1.none;
  193. this.nowAnimationKeyType = 4;
  194. this.tgtLength = 0;
  195. this.nowReaded = 0;
  196. this.elementLv = 0;
  197. this.geoStartLv = Number.MAX_VALUE;
  198. this.frameStartLv = Number.MAX_VALUE;
  199. this.matReadLine = 0;
  200. this.putMatLength = 0;
  201. this.nowMat = null;
  202. this.BoneInf = new XboneInf();
  203. this.tmpUvArray = [];
  204. this.normalVectors = [];
  205. this.facesNormal = [];
  206. this.nowFrameName = "";
  207. this.nowAnimationSetName = "";
  208. this.frameHierarchie = [];
  209. this.endLineCount = 0;
  210. this.geometry = null;
  211. this.loadingXdata = null;
  212. this.lines = null;
  213. this.keyInfo = null;
  214. this.animeKeyNames = null;
  215. this.data = null;
  216. this.onLoad = null;
  217. }
  218. createClass(XLoader, [{
  219. key: 'load',
  220. value: function load(_arg, onLoad, onProgress, onError) {
  221. var _this = this;
  222. var loader = new THREE.FileLoader(this.manager);
  223. loader.setResponseType('arraybuffer');
  224. for (var i = 0; i < _arg.length; i++) {
  225. switch (i) {
  226. case 0:
  227. this.url = _arg[i];break;
  228. case 1:
  229. this.zflg = _arg[i];break;
  230. }
  231. }
  232. loader.load(this.url, function (response) {
  233. _this.parse(response, onLoad);
  234. }, onProgress, onError);
  235. }
  236. }, {
  237. key: 'isBinary',
  238. value: function isBinary(binData) {
  239. var reader = new DataView(binData);
  240. var face_size = 32 / 8 * 3 + 32 / 8 * 3 * 3 + 16 / 8;
  241. var n_faces = reader.getUint32(80, true);
  242. var expect = 80 + 32 / 8 + n_faces * face_size;
  243. if (expect === reader.byteLength) {
  244. return true;
  245. }
  246. var fileLength = reader.byteLength;
  247. for (var index = 0; index < fileLength; index++) {
  248. if (reader.getUint8(index, false) > 127) {
  249. return true;
  250. }
  251. }
  252. return false;
  253. }
  254. }, {
  255. key: 'ensureBinary',
  256. value: function ensureBinary(buf) {
  257. if (typeof buf === "string") {
  258. var array_buffer = new Uint8Array(buf.length);
  259. for (var i = 0; i < buf.length; i++) {
  260. array_buffer[i] = buf.charCodeAt(i) & 0xff;
  261. }
  262. return array_buffer.buffer || array_buffer;
  263. } else {
  264. return buf;
  265. }
  266. }
  267. }, {
  268. key: 'ensureString',
  269. value: function ensureString(buf) {
  270. if (typeof buf !== "string") {
  271. var array_buffer = new Uint8Array(buf);
  272. var str = '';
  273. for (var i = 0; i < buf.byteLength; i++) {
  274. str += String.fromCharCode(array_buffer[i]);
  275. }
  276. return str;
  277. } else {
  278. return buf;
  279. }
  280. }
  281. }, {
  282. key: 'parse',
  283. value: function parse(data, onLoad) {
  284. var binData = this.ensureBinary(data);
  285. this.data = this.ensureString(data);
  286. this.onLoad = onLoad;
  287. return this.isBinary(binData) ? this.parseBinary(binData) : this.parseASCII();
  288. }
  289. }, {
  290. key: 'parseBinary',
  291. value: function parseBinary(data) {
  292. return parseASCII(String.fromCharCode.apply(null, data));
  293. }
  294. }, {
  295. key: 'parseASCII',
  296. value: function parseASCII() {
  297. var baseDir = "";
  298. if (this.url.lastIndexOf("/") > 0) {
  299. this.baseDir = this.url.substr(0, this.url.lastIndexOf("/") + 1);
  300. }
  301. this.loadingXdata = new Xdata();
  302. this.lines = this.data.split("\n");
  303. this.mainloop();
  304. }
  305. }, {
  306. key: 'mainloop',
  307. value: function mainloop() {
  308. var _this2 = this;
  309. var EndFlg = false;
  310. for (var i = 0; i < 100; i++) {
  311. this.lineRead(this.lines[this.endLineCount].trim());
  312. this.endLineCount++;
  313. if (this.endLineCount >= this.lines.length - 1) {
  314. EndFlg = true;
  315. this.readFinalize();
  316. setTimeout(function () {
  317. _this2.animationFinalize();
  318. }, 1);
  319. break;
  320. }
  321. }
  322. if (!EndFlg) {
  323. setTimeout(function () {
  324. _this2.mainloop();
  325. }, 1);
  326. }
  327. }
  328. }, {
  329. key: 'lineRead',
  330. value: function lineRead(line) {
  331. if (line.indexOf("template ") > -1) {
  332. return;
  333. }
  334. if (line.length === 0) {
  335. return;
  336. }
  337. if (line.indexOf("{") > -1) {
  338. this.elementLv++;
  339. }
  340. if (line.indexOf("AnimTicksPerSecond") > -1) {
  341. var findA = line.indexOf("{");
  342. this.loadingXdata.AnimTicksPerSecond = parseInt(line.substr(findA + 1, line.indexOf(";") - findA + 1), 10);
  343. }
  344. if (line.indexOf("}") > -1) {
  345. if (this.elementLv < 1 || this.nowFrameName === "") {
  346. this.elementLv = 0;return;
  347. }
  348. this.endElement();
  349. return;
  350. }
  351. if (line.indexOf("Frame ") > -1) {
  352. this.beginFrame(line);
  353. return;
  354. }
  355. if (line.indexOf("FrameTransformMatrix") > -1) {
  356. this.nowReadMode = XfileLoadMode$1.FrameTransformMatrix_Read;
  357. return;
  358. }
  359. if (this.nowReadMode === XfileLoadMode$1.FrameTransformMatrix_Read) {
  360. var data = line.split(",");
  361. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].FrameTransformMatrix = new THREE.Matrix4();
  362. this.ParseMatrixData(this.loadingXdata.FrameInfo_Raw[this.nowFrameName].FrameTransformMatrix, data);
  363. this.nowReadMode = XfileLoadMode$1.Element;
  364. return;
  365. }
  366. if (line.indexOf("Mesh ") > -1) {
  367. this.beginReadMesh(line);return;
  368. }
  369. if (this.nowReadMode === XfileLoadMode$1.Vartex_init) {
  370. this.readVertexCount(line);return;
  371. }
  372. if (this.nowReadMode === XfileLoadMode$1.Vartex_Read) {
  373. if (this.readVertex(line)) {
  374. return;
  375. }
  376. }
  377. if (this.nowReadMode === XfileLoadMode$1.Index_init) {
  378. this.readIndexLength(line);return;
  379. }
  380. if (this.nowReadMode === XfileLoadMode$1.index_Read) {
  381. if (this.readVertexIndex(line)) {
  382. return;
  383. }
  384. }
  385. if (line.indexOf("MeshNormals ") > -1) {
  386. this.beginMeshNormal(line);return;
  387. }
  388. if (this.nowReadMode === XfileLoadMode$1.Normal_V_init) {
  389. this.readMeshNormalCount(line);return;
  390. }
  391. if (this.nowReadMode === XfileLoadMode$1.Normal_V_Read) {
  392. if (this.readMeshNormalVertex(line)) {
  393. return;
  394. }
  395. }
  396. if (this.nowReadMode === XfileLoadMode$1.Normal_I_init) {
  397. this.readMeshNormalIndexCount(line);return;
  398. }
  399. if (this.nowReadMode === XfileLoadMode$1.Normal_I_Read) {
  400. if (this.readMeshNormalIndex(line)) {
  401. return;
  402. }
  403. }
  404. if (line.indexOf("MeshTextureCoords ") > -1) {
  405. this.nowReadMode = XfileLoadMode$1.Uv_init;return;
  406. }
  407. if (this.nowReadMode === XfileLoadMode$1.Uv_init) {
  408. this.readUvInit(line);return;
  409. }
  410. if (this.nowReadMode === XfileLoadMode$1.Uv_Read) {
  411. if (this.readUv(line)) {
  412. return;
  413. }
  414. }
  415. if (line.indexOf("MeshMaterialList ") > -1) {
  416. this.nowReadMode = XfileLoadMode$1.Mat_Face_init;
  417. return;
  418. }
  419. if (this.nowReadMode === XfileLoadMode$1.Mat_Face_init) {
  420. this.nowReadMode = XfileLoadMode$1.Mat_Face_len_Read;
  421. return;
  422. }
  423. if (this.nowReadMode === XfileLoadMode$1.Mat_Face_len_Read) {
  424. this.readMatrixSetLength(line);return;
  425. }
  426. if (this.nowReadMode === XfileLoadMode$1.Mat_Face_Set) {
  427. if (this.readMaterialBind(line)) {
  428. return;
  429. }
  430. }
  431. if (line.indexOf("Material ") > -1) {
  432. this.readMaterialInit(line);return;
  433. }
  434. if (this.nowReadMode === XfileLoadMode$1.Mat_Set) {
  435. this.readandSetMaterial(line);return;
  436. }
  437. if (this.nowReadMode >= XfileLoadMode$1.Mat_Set_Texture && this.nowReadMode < XfileLoadMode$1.Weit_init) {
  438. this.readandSetMaterialTexture(line);return;
  439. }
  440. if (line.indexOf("SkinWeights ") > -1 && this.nowReadMode >= XfileLoadMode$1.Element) {
  441. this.readBoneInit(line);return;
  442. }
  443. if (this.nowReadMode === XfileLoadMode$1.Weit_init) {
  444. this.readBoneName(line);return;
  445. }
  446. if (this.nowReadMode === XfileLoadMode$1.Weit_IndexLength) {
  447. this.readBoneVertexLength(line);return;
  448. }
  449. if (this.nowReadMode === XfileLoadMode$1.Weit_Read_Index) {
  450. this.readandSetBoneVertex(line);return;
  451. }
  452. if (this.nowReadMode === XfileLoadMode$1.Weit_Read_Value) {
  453. this.readandSetBoneWeightValue(line);return;
  454. }
  455. if (this.nowReadMode === XfileLoadMode$1.Weit_Read_Matrx) {
  456. this.readandSetBoneOffsetMatrixValue(line);return;
  457. }
  458. if (line.indexOf("AnimationSet ") > -1) {
  459. this.readandCreateAnimationSet(line);return;
  460. }
  461. if (line.indexOf("Animation ") > -1 && this.nowReadMode === XfileLoadMode$1.Anim_init) {
  462. this.readAndCreateAnimation(line);return;
  463. }
  464. if (line.indexOf("AnimationKey ") > -1) {
  465. this.nowReadMode = XfileLoadMode$1.Anim_KeyValueTypeRead;return;
  466. }
  467. if (this.nowReadMode === XfileLoadMode$1.Anim_KeyValueTypeRead) {
  468. this.nowAnimationKeyType = parseInt(line.substr(0, line.length - 1), 10);
  469. this.nowReadMode = XfileLoadMode$1.Anim_KeyValueLength;
  470. return;
  471. }
  472. if (this.nowReadMode === XfileLoadMode$1.Anim_KeyValueLength) {
  473. this.tgtLength = parseInt(line.substr(0, line.length - 1), 10);
  474. this.nowReaded = 0;
  475. this.nowReadMode = XfileLoadMode$1.Anime_ReadKeyFrame;
  476. return;
  477. }
  478. if (this.nowReadMode === XfileLoadMode$1.Anime_ReadKeyFrame) {
  479. this.readAnimationKeyFrame(line);return;
  480. }
  481. }
  482. }, {
  483. key: 'endElement',
  484. value: function endElement(line) {
  485. if (this.nowReadMode < XfileLoadMode$1.Anim_init && this.loadingXdata.FrameInfo_Raw[this.nowFrameName].FrameStartLv === this.elementLv && this.nowReadMode > XfileLoadMode$1.none) {
  486. if (this.frameHierarchie.length > 0) {
  487. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].children = [];
  488. var keys = Object.keys(this.loadingXdata.FrameInfo_Raw);
  489. for (var m = 0; m < keys.length; m++) {
  490. if (this.loadingXdata.FrameInfo_Raw[keys[m]].ParentName === this.nowFrameName) {
  491. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].children.push(keys[m]);
  492. }
  493. }
  494. this.frameHierarchie.pop();
  495. }
  496. this.MakeOutputGeometry(this.nowFrameName, this.zflg);
  497. this.frameStartLv = this.loadingXdata.FrameInfo_Raw[this.nowFrameName].FrameStartLv;
  498. if (this.frameHierarchie.length > 0) {
  499. this.nowFrameName = this.frameHierarchie[this.frameHierarchie.length - 1];
  500. this.frameStartLv = this.loadingXdata.FrameInfo_Raw[this.nowFrameName].FrameStartLv;
  501. } else {
  502. this.nowFrameName = "";
  503. }
  504. }
  505. if (this.nowReadMode === XfileLoadMode$1.Mat_Set) {
  506. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Materials.push(this.nowMat);
  507. this.nowReadMode = XfileLoadMode$1.Element;
  508. }
  509. this.elementLv--;
  510. }
  511. }, {
  512. key: 'beginFrame',
  513. value: function beginFrame(line) {
  514. this.frameStartLv = this.elementLv;
  515. this.nowReadMode = XfileLoadMode$1.Element;
  516. this.nowFrameName = line.substr(6, line.length - 8);
  517. this.loadingXdata.FrameInfo_Raw[this.nowFrameName] = new XFrameInfo$1();
  518. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].FrameName = this.nowFrameName;
  519. if (this.frameHierarchie.length > 0) {
  520. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].ParentName = this.frameHierarchie[this.frameHierarchie.length - 1];
  521. }
  522. this.frameHierarchie.push(this.nowFrameName);
  523. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].FrameStartLv = this.frameStartLv;
  524. }
  525. }, {
  526. key: 'beginReadMesh',
  527. value: function beginReadMesh(line) {
  528. if (this.nowFrameName === "") {
  529. this.frameStartLv = this.elementLv;
  530. this.nowFrameName = line.substr(5, line.length - 6);
  531. if (this.nowFrameName === "") {
  532. this.nowFrameName = "mesh_" + this.loadingXdata.FrameInfo_Raw.length;
  533. }
  534. this.loadingXdata.FrameInfo_Raw[this.nowFrameName] = new XFrameInfo$1();
  535. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].FrameName = this.nowFrameName;
  536. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].FrameStartLv = this.frameStartLv;
  537. }
  538. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Geometry = new THREE.Geometry();
  539. this.geoStartLv = this.elementLv;
  540. this.nowReadMode = XfileLoadMode$1.Vartex_init;
  541. Bones = [];
  542. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Materials = [];
  543. }
  544. }, {
  545. key: 'readVertexCount',
  546. value: function readVertexCount(line) {
  547. this.nowReadMode = XfileLoadMode$1.Vartex_Read;
  548. this.tgtLength = parseInt(line.substr(0, line.length - 1), 10);
  549. this.nowReaded = 0;
  550. }
  551. }, {
  552. key: 'readVertex',
  553. value: function readVertex(line) {
  554. var data = line.substr(0, line.length - 2).split(";");
  555. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Geometry.vertices.push(new THREE.Vector3(parseFloat(data[0]), parseFloat(data[1]), parseFloat(data[2])));
  556. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Geometry.skinIndices.push(new THREE.Vector4(0, 0, 0, 0));
  557. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Geometry.skinWeights.push(new THREE.Vector4(1, 0, 0, 0));
  558. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].VertexSetedBoneCount.push(0);
  559. this.nowReaded++;
  560. if (this.nowReaded >= this.tgtLength) {
  561. this.nowReadMode = XfileLoadMode$1.Index_init;
  562. return true;
  563. }
  564. return false;
  565. }
  566. }, {
  567. key: 'readIndexLength',
  568. value: function readIndexLength(line) {
  569. this.nowReadMode = XfileLoadMode$1.index_Read;
  570. this.tgtLength = parseInt(line.substr(0, line.length - 1), 10);
  571. this.nowReaded = 0;
  572. }
  573. }, {
  574. key: 'readVertexIndex',
  575. value: function readVertexIndex(line) {
  576. var data = line.substr(2, line.length - 4).split(",");
  577. if (this.zflg) {
  578. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Geometry.faces.push(new THREE.Face3(parseInt(data[2], 10), parseInt(data[1], 10), parseInt(data[0], 10), new THREE.Vector3(1, 1, 1).normalize()));
  579. } else {
  580. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Geometry.faces.push(new THREE.Face3(parseInt(data[0], 10), parseInt(data[1], 10), parseInt(data[2], 10), new THREE.Vector3(1, 1, 1).normalize()));
  581. }
  582. this.nowReaded++;
  583. if (this.nowReaded >= this.tgtLength) {
  584. this.nowReadMode = XfileLoadMode$1.Element;
  585. return true;
  586. }
  587. return false;
  588. }
  589. }, {
  590. key: 'beginMeshNormal',
  591. value: function beginMeshNormal(line) {
  592. this.nowReadMode = XfileLoadMode$1.Normal_V_init;
  593. this.normalVectors = [];
  594. this.facesNormal = [];
  595. }
  596. }, {
  597. key: 'readMeshNormalCount',
  598. value: function readMeshNormalCount(line) {
  599. this.nowReadMode = XfileLoadMode$1.Normal_V_Read;
  600. this.tgtLength = parseInt(line.substr(0, line.length - 1), 10);
  601. this.nowReaded = 0;
  602. }
  603. }, {
  604. key: 'readMeshNormalVertex',
  605. value: function readMeshNormalVertex(line) {
  606. var data = line.split(";");
  607. this.normalVectors.push([parseFloat(data[0]), parseFloat(data[1]), parseFloat(data[2])]);
  608. this.nowReaded++;
  609. if (this.nowReaded >= this.tgtLength) {
  610. this.nowReadMode = XfileLoadMode$1.Normal_I_init;
  611. return true;
  612. }
  613. return false;
  614. }
  615. }, {
  616. key: 'readMeshNormalIndexCount',
  617. value: function readMeshNormalIndexCount(line) {
  618. this.nowReadMode = XfileLoadMode$1.Normal_I_Read;
  619. this.tgtLength = parseInt(line.substr(0, line.length - 1), 10);
  620. this.nowReaded = 0;
  621. }
  622. }, {
  623. key: 'readMeshNormalIndex',
  624. value: function readMeshNormalIndex(line) {
  625. var data = line.substr(2, line.length - 4).split(",");
  626. var nowID = parseInt(data[0], 10);
  627. var v1 = new THREE.Vector3(this.normalVectors[nowID][0], this.normalVectors[nowID][1], this.normalVectors[nowID][2]);
  628. nowID = parseInt(data[1], 10);
  629. var v2 = new THREE.Vector3(this.normalVectors[nowID][0], this.normalVectors[nowID][1], this.normalVectors[nowID][2]);
  630. nowID = parseInt(data[2], 10);
  631. var v3 = new THREE.Vector3(this.normalVectors[nowID][0], this.normalVectors[nowID][1], this.normalVectors[nowID][2]);
  632. if (this.zflg) {
  633. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Geometry.faces[this.nowReaded].vertexNormals = [v3, v2, v1];
  634. } else {
  635. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Geometry.faces[this.nowReaded].vertexNormals = [v1, v2, v3];
  636. }
  637. this.facesNormal.push(v1.normalize());
  638. this.nowReaded++;
  639. if (this.nowReaded >= this.tgtLength) {
  640. this.nowReadMode = XfileLoadMode$1.Element;
  641. return true;
  642. }
  643. return false;
  644. }
  645. }, {
  646. key: 'readUvInit',
  647. value: function readUvInit(line) {
  648. this.nowReadMode = XfileLoadMode$1.Uv_Read;
  649. this.tgtLength = parseInt(line.substr(0, line.length - 1), 10);
  650. this.nowReaded = 0;
  651. this.tmpUvArray = [];
  652. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Geometry.faceVertexUvs[0] = [];
  653. }
  654. }, {
  655. key: 'readUv',
  656. value: function readUv(line) {
  657. var data = line.split(";");
  658. if (THREE.XLoader.IsUvYReverse) {
  659. this.tmpUvArray.push(new THREE.Vector2(parseFloat(data[0]), 1 - parseFloat(data[1])));
  660. } else {
  661. this.tmpUvArray.push(new THREE.Vector2(parseFloat(data[0]), parseFloat(data[1])));
  662. }
  663. this.nowReaded++;
  664. if (this.nowReaded >= this.tgtLength) {
  665. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Geometry.faceVertexUvs[0] = [];
  666. for (var m = 0; m < this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Geometry.faces.length; m++) {
  667. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Geometry.faceVertexUvs[0][m] = [];
  668. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Geometry.faceVertexUvs[0][m].push(this.tmpUvArray[this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Geometry.faces[m].a]);
  669. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Geometry.faceVertexUvs[0][m].push(this.tmpUvArray[this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Geometry.faces[m].b]);
  670. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Geometry.faceVertexUvs[0][m].push(this.tmpUvArray[this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Geometry.faces[m].c]);
  671. }
  672. this.nowReadMode = XfileLoadMode$1.Element;
  673. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Geometry.uvsNeedUpdate = true;
  674. return true;
  675. }
  676. return false;
  677. }
  678. }, {
  679. key: 'readMatrixSetLength',
  680. value: function readMatrixSetLength(line) {
  681. this.nowReadMode = XfileLoadMode$1.Mat_Face_Set;
  682. this.tgtLength = parseInt(line.substr(0, line.length - 1), 10);
  683. this.nowReaded = 0;
  684. }
  685. }, {
  686. key: 'readMaterialBind',
  687. value: function readMaterialBind(line) {
  688. var data = line.split(",");
  689. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].Geometry.faces[this.nowReaded].materialIndex = parseInt(data[0]);
  690. this.nowReaded++;
  691. if (this.nowReaded >= this.tgtLength) {
  692. this.nowReadMode = XfileLoadMode$1.Element;
  693. return true;
  694. }
  695. return false;
  696. }
  697. }, {
  698. key: 'readMaterialInit',
  699. value: function readMaterialInit(line) {
  700. this.nowReadMode = XfileLoadMode$1.Mat_Set;
  701. this.matReadLine = 0;
  702. this.nowMat = new THREE.MeshPhongMaterial({ color: Math.random() * 0xffffff });
  703. var matName = line.substr(9, line.length - 10);
  704. if (matName !== "") {
  705. this.nowMat.name = matName;
  706. }
  707. if (this.zflg) {
  708. this.nowMat.side = THREE.BackSide;
  709. } else {
  710. this.nowMat.side = THREE.FrontSide;
  711. }
  712. this.nowMat.side = THREE.FrontSide;
  713. }
  714. }, {
  715. key: 'readandSetMaterial',
  716. value: function readandSetMaterial(line) {
  717. var data = line.split(";");
  718. this.matReadLine++;
  719. switch (this.matReadLine) {
  720. case 1:
  721. this.nowMat.color.r = data[0];
  722. this.nowMat.color.g = data[1];
  723. this.nowMat.color.b = data[2];
  724. break;
  725. case 2:
  726. this.nowMat.shininess = data[0];
  727. break;
  728. case 3:
  729. this.nowMat.specular.r = data[0];
  730. this.nowMat.specular.g = data[1];
  731. this.nowMat.specular.b = data[2];
  732. break;
  733. case 4:
  734. this.nowMat.emissive.r = data[0];
  735. this.nowMat.emissive.g = data[1];
  736. this.nowMat.emissive.b = data[2];
  737. break;
  738. }
  739. if (line.indexOf("TextureFilename") > -1) {
  740. this.nowReadMode = XfileLoadMode$1.Mat_Set_Texture;
  741. } else if (line.indexOf("BumpMapFilename") > -1) {
  742. this.nowReadMode = XfileLoadMode$1.Mat_Set_BumpTex;
  743. this.nowMat.bumpScale = 0.05;
  744. } else if (line.indexOf("NormalMapFilename") > -1) {
  745. this.nowReadMode = XfileLoadMode$1.Mat_Set_NormalTex;
  746. this.nowMat.normalScale = new THREE.Vector2(2, 2);
  747. } else if (line.indexOf("EmissiveMapFilename") > -1) {
  748. this.nowReadMode = XfileLoadMode$1.Mat_Set_EmissiveTex;
  749. } else if (line.indexOf("LightMapFilename") > -1) {
  750. this.nowReadMode = XfileLoadMode$1.Mat_Set_LightTex;
  751. }
  752. }
  753. }, {
  754. key: 'readandSetMaterialTexture',
  755. value: function readandSetMaterialTexture(line) {
  756. var data = line.substr(1, line.length - 3);
  757. if (data != undefined && data.length > 0) {
  758. switch (this.nowReadMode) {
  759. case XfileLoadMode$1.Mat_Set_Texture:
  760. this.nowMat.map = this.Texloader.load(this.baseDir + data);
  761. break;
  762. case XfileLoadMode$1.Mat_Set_BumpTex:
  763. this.nowMat.bumpMap = this.Texloader.load(this.baseDir + data);
  764. break;
  765. case XfileLoadMode$1.Mat_Set_NormalTex:
  766. this.nowMat.normalMap = this.Texloader.load(this.baseDir + data);
  767. break;
  768. case XfileLoadMode$1.Mat_Set_EmissiveTex:
  769. this.nowMat.emissiveMap = this.Texloader.load(this.baseDir + data);
  770. break;
  771. case XfileLoadMode$1.Mat_Set_LightTex:
  772. this.nowMat.lightMap = this.Texloader.load(this.baseDir + data);
  773. break;
  774. case XfileLoadMode$1.Mat_Set_EnvTex:
  775. this.nowMat.envMap = this.Texloader.load(this.baseDir + data);
  776. break;
  777. }
  778. }
  779. this.nowReadMode = XfileLoadMode$1.Mat_Set;
  780. this.endLineCount++;
  781. this.elementLv--;
  782. }
  783. }, {
  784. key: 'readBoneInit',
  785. value: function readBoneInit(line) {
  786. this.nowReadMode = XfileLoadMode$1.Weit_init;
  787. this.BoneInf = new XboneInf();
  788. }
  789. }, {
  790. key: 'readBoneName',
  791. value: function readBoneName(line) {
  792. this.nowReadMode = XfileLoadMode$1.Weit_IndexLength;
  793. this.BoneInf.boneName = line.substr(1, line.length - 3);
  794. this.BoneInf.BoneIndex = this.loadingXdata.FrameInfo_Raw[this.nowFrameName].BoneInfs.length;
  795. this.nowReaded = 0;
  796. }
  797. }, {
  798. key: 'readBoneVertexLength',
  799. value: function readBoneVertexLength(line) {
  800. this.nowReadMode = XfileLoadMode$1.Weit_Read_Index;
  801. this.tgtLength = parseInt(line.substr(0, line.length - 1), 10);
  802. this.nowReaded = 0;
  803. }
  804. }, {
  805. key: 'readandSetBoneVertex',
  806. value: function readandSetBoneVertex(line) {
  807. this.BoneInf.Indeces.push(parseInt(line.substr(0, line.length - 1), 10));
  808. this.nowReaded++;
  809. if (this.nowReaded >= this.tgtLength || line.indexOf(";") > -1) {
  810. this.nowReadMode = XfileLoadMode$1.Weit_Read_Value;
  811. this.nowReaded = 0;
  812. }
  813. }
  814. }, {
  815. key: 'readandSetBoneWeightValue',
  816. value: function readandSetBoneWeightValue(line) {
  817. var nowVal = parseFloat(line.substr(0, line.length - 1));
  818. this.BoneInf.Weights.push(nowVal);
  819. this.nowReaded++;
  820. if (this.nowReaded >= this.tgtLength || line.indexOf(";") > -1) {
  821. this.nowReadMode = XfileLoadMode$1.Weit_Read_Matrx;
  822. }
  823. }
  824. }, {
  825. key: 'readandSetBoneOffsetMatrixValue',
  826. value: function readandSetBoneOffsetMatrixValue(line) {
  827. var data = line.split(",");
  828. this.BoneInf.initMatrix = new THREE.Matrix4();
  829. this.ParseMatrixData(this.BoneInf.initMatrix, data);
  830. this.BoneInf.OffsetMatrix = new THREE.Matrix4();
  831. this.BoneInf.OffsetMatrix.getInverse(this.BoneInf.initMatrix);
  832. this.loadingXdata.FrameInfo_Raw[this.nowFrameName].BoneInfs.push(this.BoneInf);
  833. this.nowReadMode = XfileLoadMode$1.Element;
  834. }
  835. }, {
  836. key: 'readandCreateAnimationSet',
  837. value: function readandCreateAnimationSet(line) {
  838. this.frameStartLv = this.elementLv;
  839. this.nowReadMode = XfileLoadMode$1.Anim_init;
  840. this.nowAnimationSetName = line.substr(13, line.length - 14).trim();
  841. this.loadingXdata.AnimationSetInfo[this.nowAnimationSetName] = [];
  842. }
  843. }, {
  844. key: 'readAndCreateAnimation',
  845. value: function readAndCreateAnimation(line) {
  846. this.nowFrameName = line.substr(10, line.length - 11).trim();
  847. this.loadingXdata.AnimationSetInfo[this.nowAnimationSetName][this.nowFrameName] = new XAnimationInfo$1();
  848. this.loadingXdata.AnimationSetInfo[this.nowAnimationSetName][this.nowFrameName].animeName = this.nowFrameName;
  849. this.loadingXdata.AnimationSetInfo[this.nowAnimationSetName][this.nowFrameName].FrameStartLv = this.frameStartLv;
  850. while (true) {
  851. this.endLineCount++;
  852. line = this.lines[this.endLineCount].trim();
  853. if (line.indexOf("{") > -1 && line.indexOf("}") > -1) {
  854. this.loadingXdata.AnimationSetInfo[this.nowAnimationSetName][this.nowFrameName].boneName = line.replace(/{/g, "").replace(/}/g, "").trim();
  855. break;
  856. }
  857. }
  858. }
  859. }, {
  860. key: 'readAnimationKeyFrame',
  861. value: function readAnimationKeyFrame(line) {
  862. this.keyInfo = null;
  863. var data = line.split(";");
  864. var nowKeyframe = parseInt(data[0], 10);
  865. var frameFound = false;
  866. var tmpM = new THREE.Matrix4();
  867. if (this.nowAnimationKeyType != 4) {
  868. for (var mm = 0; mm < this.loadingXdata.AnimationSetInfo[this.nowAnimationSetName][this.nowFrameName].keyFrames.length; mm++) {
  869. if (this.loadingXdata.AnimationSetInfo[this.nowAnimationSetName][this.nowFrameName].keyFrames[mm].Frame === nowKeyframe) {
  870. this.keyInfo = this.loadingXdata.AnimationSetInfo[this.nowAnimationSetName][this.nowFrameName].keyFrames[mm];
  871. frameFound = true;
  872. break;
  873. }
  874. }
  875. }
  876. if (!frameFound) {
  877. this.keyInfo = new XKeyFrameInfo();
  878. this.keyInfo.matrix = new THREE.Matrix4();
  879. this.keyInfo.Frame = nowKeyframe;
  880. }
  881. var data2 = data[2].split(",");
  882. switch (this.nowAnimationKeyType) {
  883. case 0:
  884. tmpM.makeRotationFromQuaternion(new THREE.Quaternion(parseFloat(data2[0]), parseFloat(data2[1]), parseFloat(data2[2])));
  885. this.keyInfo.matrix.multiply(tmpM);
  886. break;
  887. case 1:
  888. tmpM.makeScale(parseFloat(data2[0]), parseFloat(data2[1]), parseFloat(data2[2]));
  889. this.keyInfo.matrix.multiply(tmpM);
  890. break;
  891. case 2:
  892. tmpM.makeTranslation(parseFloat(data2[0]), parseFloat(data2[1]), parseFloat(data2[2]));
  893. this.keyInfo.matrix.multiply(tmpM);
  894. break;
  895. case 4:
  896. this.ParseMatrixData(this.keyInfo.matrix, data2);
  897. break;
  898. }
  899. if (!frameFound) {
  900. this.keyInfo.index = this.loadingXdata.AnimationSetInfo[this.nowAnimationSetName][this.nowFrameName].keyFrames.length;
  901. this.keyInfo.time = /*1.0 / this.loadingXdata.AnimTicksPerSecond * */this.keyInfo.Frame;
  902. this.loadingXdata.AnimationSetInfo[this.nowAnimationSetName][this.nowFrameName].keyFrames.push(this.keyInfo);
  903. }
  904. this.nowReaded++;
  905. if (this.nowReaded >= this.tgtLength || line.indexOf(";;;") > -1) {
  906. this.nowReadMode = XfileLoadMode$1.Anim_init;
  907. }
  908. }
  909. }, {
  910. key: 'readFinalize',
  911. value: function readFinalize() {
  912. this.loadingXdata.FrameInfo = [];
  913. var keys = Object.keys(this.loadingXdata.FrameInfo_Raw);
  914. for (var i = 0; i < keys.length; i++) {
  915. if (this.loadingXdata.FrameInfo_Raw[keys[i]].Mesh != null) {
  916. this.loadingXdata.FrameInfo.push(this.loadingXdata.FrameInfo_Raw[keys[i]].Mesh);
  917. }
  918. }
  919. if (this.loadingXdata.FrameInfo != null & this.loadingXdata.FrameInfo.length > 0) {
  920. for (var _i = 0; _i < this.loadingXdata.FrameInfo.length; _i++) {
  921. if (this.loadingXdata.FrameInfo[_i].parent == null) {
  922. this.loadingXdata.FrameInfo[_i].zflag = this.zflg;
  923. if (this.zflg) {
  924. this.loadingXdata.FrameInfo[_i].scale.set(-1, 1, 1);
  925. }
  926. }
  927. }
  928. }
  929. }
  930. }, {
  931. key: 'ParseMatrixData',
  932. value: function ParseMatrixData(targetMatrix, data) {
  933. 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]));
  934. }
  935. }, {
  936. key: 'MakeOutputGeometry',
  937. value: function MakeOutputGeometry(nowFrameName, _zflg) {
  938. if (this.loadingXdata.FrameInfo_Raw[nowFrameName].Geometry != null) {
  939. this.loadingXdata.FrameInfo_Raw[nowFrameName].Geometry.computeBoundingBox();
  940. this.loadingXdata.FrameInfo_Raw[nowFrameName].Geometry.computeBoundingSphere();
  941. this.loadingXdata.FrameInfo_Raw[nowFrameName].Geometry.verticesNeedUpdate = true;
  942. this.loadingXdata.FrameInfo_Raw[nowFrameName].Geometry.normalsNeedUpdate = true;
  943. this.loadingXdata.FrameInfo_Raw[nowFrameName].Geometry.colorsNeedUpdate = true;
  944. this.loadingXdata.FrameInfo_Raw[nowFrameName].Geometry.uvsNeedUpdate = true;
  945. this.loadingXdata.FrameInfo_Raw[nowFrameName].Geometry.groupsNeedUpdate = true;
  946. var putBones = [];
  947. var BoneDics = [];
  948. var rootBone = new THREE.Bone();
  949. if (this.loadingXdata.FrameInfo_Raw[nowFrameName].BoneInfs != null && this.loadingXdata.FrameInfo_Raw[nowFrameName].BoneInfs.length) {
  950. var keys = Object.keys(this.loadingXdata.FrameInfo_Raw);
  951. var BoneDics_Name = [];
  952. for (var m = 0; m < keys.length; m++) {
  953. if (this.loadingXdata.FrameInfo_Raw[keys[m]].FrameStartLv <= this.loadingXdata.FrameInfo_Raw[nowFrameName].FrameStartLv && nowFrameName != keys[m]) {
  954. continue;
  955. }
  956. var b = new THREE.Bone();
  957. b.name = keys[m];
  958. b.applyMatrix(this.loadingXdata.FrameInfo_Raw[keys[m]].FrameTransformMatrix);
  959. b.matrixWorld = b.matrix;
  960. b.FrameTransformMatrix = this.loadingXdata.FrameInfo_Raw[keys[m]].FrameTransformMatrix;
  961. BoneDics_Name[b.name] = putBones.length;
  962. putBones.push(b);
  963. }
  964. for (var _m = 0; _m < putBones.length; _m++) {
  965. for (var dx = 0; dx < this.loadingXdata.FrameInfo_Raw[putBones[_m].name].children.length; dx++) {
  966. var nowBoneIndex = BoneDics_Name[this.loadingXdata.FrameInfo_Raw[putBones[_m].name].children[dx]];
  967. if (putBones[nowBoneIndex] != null) {
  968. putBones[_m].add(putBones[nowBoneIndex]);
  969. }
  970. }
  971. }
  972. }
  973. var mesh = null;
  974. var bufferGeometry = new THREE.BufferGeometry();
  975. if (putBones.length > 0) {
  976. if (this.loadingXdata.FrameInfo_Raw[putBones[0].name].children.length === 0 && nowFrameName != putBones[0].name) {
  977. putBones[0].add(putBones[1]);
  978. putBones[0].zflag = _zflg;
  979. }
  980. for (var _m2 = 0; _m2 < putBones.length; _m2++) {
  981. if (putBones[_m2].parent === null) {
  982. putBones[_m2].zflag = _zflg;
  983. }
  984. for (var bi = 0; bi < this.loadingXdata.FrameInfo_Raw[nowFrameName].BoneInfs.length; bi++) {
  985. if (putBones[_m2].name === this.loadingXdata.FrameInfo_Raw[nowFrameName].BoneInfs[bi].boneName) {
  986. for (var vi = 0; vi < this.loadingXdata.FrameInfo_Raw[nowFrameName].BoneInfs[bi].Indeces.length; vi++) {
  987. var nowVertexID = this.loadingXdata.FrameInfo_Raw[nowFrameName].BoneInfs[bi].Indeces[vi];
  988. var nowVal = this.loadingXdata.FrameInfo_Raw[nowFrameName].BoneInfs[bi].Weights[vi];
  989. switch (this.loadingXdata.FrameInfo_Raw[nowFrameName].VertexSetedBoneCount[nowVertexID]) {
  990. case 0:
  991. this.loadingXdata.FrameInfo_Raw[nowFrameName].Geometry.skinIndices[nowVertexID].x = _m2;
  992. this.loadingXdata.FrameInfo_Raw[nowFrameName].Geometry.skinWeights[nowVertexID].x = nowVal;
  993. break;
  994. case 1:
  995. this.loadingXdata.FrameInfo_Raw[nowFrameName].Geometry.skinIndices[nowVertexID].y = _m2;
  996. this.loadingXdata.FrameInfo_Raw[nowFrameName].Geometry.skinWeights[nowVertexID].y = nowVal;
  997. break;
  998. case 2:
  999. this.loadingXdata.FrameInfo_Raw[nowFrameName].Geometry.skinIndices[nowVertexID].z = _m2;
  1000. this.loadingXdata.FrameInfo_Raw[nowFrameName].Geometry.skinWeights[nowVertexID].z = nowVal;
  1001. break;
  1002. case 3:
  1003. this.loadingXdata.FrameInfo_Raw[nowFrameName].Geometry.skinIndices[nowVertexID].w = _m2;
  1004. this.loadingXdata.FrameInfo_Raw[nowFrameName].Geometry.skinWeights[nowVertexID].w = nowVal;
  1005. break;
  1006. }
  1007. this.loadingXdata.FrameInfo_Raw[nowFrameName].VertexSetedBoneCount[nowVertexID]++;
  1008. }
  1009. }
  1010. }
  1011. }
  1012. for (var sk = 0; sk < this.loadingXdata.FrameInfo_Raw[nowFrameName].Materials.length; sk++) {
  1013. this.loadingXdata.FrameInfo_Raw[nowFrameName].Materials[sk].skinning = true;
  1014. }
  1015. mesh = new THREE.SkinnedMesh(bufferGeometry.fromGeometry(this.loadingXdata.FrameInfo_Raw[nowFrameName].Geometry), new THREE.MultiMaterial(this.loadingXdata.FrameInfo_Raw[nowFrameName].Materials));
  1016. var skeleton = new THREE.Skeleton(putBones);
  1017. mesh.add(putBones[0]);
  1018. mesh.bind(skeleton);
  1019. } else {
  1020. mesh = new THREE.Mesh(bufferGeometry.fromGeometry(this.loadingXdata.FrameInfo_Raw[nowFrameName].Geometry), new THREE.MultiMaterial(this.loadingXdata.FrameInfo_Raw[nowFrameName].Materials));
  1021. }
  1022. mesh.name = nowFrameName;
  1023. this.loadingXdata.FrameInfo_Raw[nowFrameName].Mesh = mesh;
  1024. this.loadingXdata.FrameInfo_Raw[nowFrameName].Geometry = null;
  1025. }
  1026. }
  1027. }, {
  1028. key: 'animationFinalize',
  1029. value: function animationFinalize() {
  1030. this.animeKeyNames = Object.keys(this.loadingXdata.AnimationSetInfo);
  1031. if (this.animeKeyNames != null && this.animeKeyNames.length > 0) {
  1032. this.nowReaded = 0;
  1033. this.loadingXdata.XAnimationObj = [];
  1034. this.animationFinalize_step();
  1035. } else {
  1036. this.finalproc();
  1037. }
  1038. }
  1039. }, {
  1040. key: 'animationFinalize_step',
  1041. value: function animationFinalize_step() {
  1042. var i = this.nowReaded;
  1043. var keys = Object.keys(this.loadingXdata.FrameInfo_Raw);
  1044. var tgtModel = null;
  1045. for (var m = 0; m < this.loadingXdata.FrameInfo.length; m++) {
  1046. var keys2 = Object.keys(this.loadingXdata.AnimationSetInfo[this.animeKeyNames[i]]);
  1047. if (this.loadingXdata.AnimationSetInfo[this.animeKeyNames[i]][keys2[0]].boneName == this.loadingXdata.FrameInfo[m].name) {
  1048. tgtModel = this.loadingXdata.FrameInfo[m];
  1049. }
  1050. }
  1051. if (tgtModel != null) {
  1052. this.loadingXdata.XAnimationObj[i] = new XAnimationObj();
  1053. this.loadingXdata.XAnimationObj[i].fps = this.loadingXdata.AnimTicksPerSecond;
  1054. this.loadingXdata.XAnimationObj[i].name = this.animeKeyNames[i];
  1055. this.loadingXdata.XAnimationObj[i].make(this.loadingXdata.AnimationSetInfo[this.animeKeyNames[i]], tgtModel);
  1056. }
  1057. this.nowReaded++;
  1058. if (this.nowReaded >= this.animeKeyNames.length) {
  1059. this.loadingXdata.AnimationSetInfo = null;
  1060. this.finalproc();
  1061. } else {
  1062. this.animationFinalize_step();
  1063. }
  1064. }
  1065. }, {
  1066. key: 'finalproc',
  1067. value: function finalproc() {
  1068. var _this3 = this;
  1069. setTimeout(function () {
  1070. _this3.onLoad(_this3.loadingXdata);
  1071. }, 1);
  1072. }
  1073. }]);
  1074. return XLoader;
  1075. }();
  1076. THREE.XLoader.IsUvYReverse = true;