main.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import Xverse from "./Xverse.js";
  2. import Codes from "./enum/Codes.js";
  3. // import './h264Decoder/index'
  4. const xverse = new Xverse({
  5. env: "DEV",
  6. appId: "10016",
  7. releaseId: "2203181838_1375a0",
  8. });
  9. const l = async () => {
  10. var R;
  11. try {
  12. await ((R = xverse.preload) == null
  13. ? void 0
  14. : R.start("full", (M, x) => {
  15. const I = `(${M}/${x})`;
  16. //s(I)
  17. }));
  18. } catch (M) {
  19. if ((console.error(M), M.code === Codes.PreloadCanceled)) {
  20. toast("\u9884\u52A0\u8F7D\u88AB\u53D6\u6D88");
  21. return;
  22. }
  23. toast("\u8FDB\u5165\u5931\u8D25, \u8BF7\u91CD\u8BD5");
  24. return;
  25. }
  26. nickname = Math.random().toString(16).slice(2)
  27. try {
  28. let room = await xverse.joinRoom({
  29. canvas: document.getElementById("canvas"),
  30. skinId: "10092",
  31. avatarId: "KGe_Boy",
  32. roomId: "e629ef3e-022d-4e64-8654-703bb96410eb",
  33. userId: nickname,
  34. wsServerUrl: "wss://uat-eks.xverse.cn/ws",
  35. appId: "10016",
  36. token: " ",
  37. nickname: nickname,
  38. firends: ["user1"],
  39. viewMode: "full",
  40. resolution: {
  41. width: 1728,
  42. height: 720,
  43. },
  44. pathName: "thirdwalk",
  45. objectFit: null,
  46. hasAvatar: !0,
  47. syncToOthers: !0,
  48. });
  49. window.room = room;
  50. readPointData()
  51. u();
  52. c();
  53. //e(!1);
  54. } catch (M) {
  55. console.error(M);
  56. alert(M);
  57. return;
  58. }
  59. };
  60. const u = () => {
  61. window.room.on("_coreClick", ({ point: f }) => {
  62. window.room._userAvatar.moveTo({
  63. point: f,
  64. });
  65. });
  66. };
  67. const c = () => {
  68. window.room.on("repeatLogin", function () {
  69. toast(
  70. "\u8BE5\u7528\u6237\u5DF2\u7ECF\u5728\u5176\u4ED6\u5730\u70B9\u767B\u5F55",
  71. {
  72. duration: 1e4,
  73. }
  74. );
  75. }),
  76. window.room.on("reconnecting", function ({ count: f }) {
  77. toast(`\u5C1D\u8BD5\u7B2C${f}\u6B21\u91CD\u8FDE`);
  78. }),
  79. window.room.on("reconnected", function () {
  80. toast("\u91CD\u8FDE\u6210\u529F");
  81. }),
  82. window.room.on("disconnected", function () {
  83. const f = toast(
  84. "\u8FDE\u63A5\u5931\u8D25\uFF0C\u624B\u52A8\u70B9\u51FB\u91CD\u8BD5",
  85. {
  86. duration: 1e5,
  87. onClick() {
  88. f.hideToast(), window.room.reconnect();
  89. },
  90. }
  91. );
  92. });
  93. };
  94. l();
  95. const BREATH_POINT_TYPE = "debugBreathPoint"
  96. , TAP_BREATH_POINT_TYPE = "debugTapBreathPoint"
  97. , DEFAULT_SEARCH_RANGE = 1e3;
  98. function xversePosition2Ue4(i){
  99. return {
  100. x: i.x * 100,
  101. y: -1 * i.z * 100,
  102. z: i.y * 100
  103. }
  104. }
  105. function readPointData() {
  106. return fetch("./assets/points.json", {
  107. headers: {
  108. 'content-type': 'application/json'
  109. },
  110. method: 'GET',
  111. })
  112. .then(response => response.json())
  113. .then(response => {
  114. response.forEach(data => {
  115. let ue4Pos = xversePosition2Ue4({x: -data.position.x, y: data.position.y, z: data.position.z})
  116. data.position0 = data.position
  117. data.position = new BABYLON.Vector3(ue4Pos.x, ue4Pos.y, ue4Pos.z)
  118. const a = JSON.stringify(data.position);
  119. window.room.breathPointManager.breathPoints.get(a) || window.room.breathPointManager.addBreathPoint({
  120. id: a,
  121. position: data.position,
  122. type: BREATH_POINT_TYPE,
  123. rotation: {
  124. pitch: 90,
  125. yaw: 0,
  126. roll: 0
  127. },
  128. forceLeaveGround: !0
  129. })
  130. })
  131. window.points = response
  132. })
  133. }
  134. // console.log("tinyh264", tinyh264);
  135. // debugger;