index.html 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <!-- <link rel="stylesheet" href="./index.css" /> -->
  9. <link rel="stylesheet" href="./css/toastify.min.css" />
  10. <style>
  11. .loading {
  12. position: absolute;
  13. width: 100%;
  14. height: 100%;
  15. background: #fff url("./assets/loading.gif") center;
  16. background-repeat: no-repeat;
  17. background-size: 600px 600px;
  18. }
  19. .tip {
  20. position: absolute;
  21. top: 2rem;
  22. left: 50%;
  23. transform: translateX(-50%);
  24. padding: 1rem 1.6rem;
  25. background-color: #5bc1d1;
  26. color: white;
  27. z-index: 9999;
  28. border-radius: 0.2rem;
  29. opacity: 1;
  30. transition: opacity .2s;
  31. }
  32. </style>
  33. </head>
  34. <body>
  35. <!-- Babylon.js -->
  36. <script src="./libs/jquery-1.10.2.min.js"></script>
  37. <script src="./libs/dat.gui.min.js"></script>
  38. <script src="./libs/ammo.js"></script>
  39. <script src="./libs/cannon.js"></script>
  40. <script src="./libs/Oimo.js"></script>
  41. <script src="./libs/earcut.min.js"></script>
  42. <script src="./libs/recast.js"></script>
  43. <script src="./libs/babylon.js"></script>
  44. <script src="./libs/babylonjs.materials.min.js"></script>
  45. <script src="./libs/babylonjs.proceduralTextures.min.js"></script>
  46. <script src="./libs/babylonjs.postProcess.min.js"></script>
  47. <script src="./libs/babylonjs.loaders.js"></script>
  48. <script src="./libs/babylonjs.serializers.min.js"></script>
  49. <script src="./libs/babylon.gui.min.js"></script>
  50. <script src="./libs/babylon.inspector.bundle.js"></script>
  51. <script src="./libs/socket.2.3.js"></script>
  52. <script src="./libs/events.js"></script>
  53. <script src="./libs/axios.min.js"></script>
  54. <script src="./libs/VisibilityChangeHandler.js"></script>
  55. <script src="./libs/decoder.js"></script>
  56. <script src="./libs/nipplejs.min.js"></script>
  57. <script src="./shader.js"></script>
  58. <!-- <script src="./webrtc//adapter-7.4.0.min.js"></script>
  59. <script src="./webrtc/srs.sdk.js"></script> -->
  60. <link rel="stylesheet" href="./css/index.cb1a6e05.css" />
  61. <script>
  62. const SERVER_URLS = {
  63. DEV: "wss://sit-eks.xverse.cn/ws",
  64. PROD: "wss://eks.xverse.cn/ws"
  65. }
  66. , REPORT_URL = {
  67. DEV: "https://xa.xverse.cn:6680/collect1",
  68. PROD: "https://xa.xverse.cn/collect1"
  69. }
  70. , MAX_RECONNECT_COUNT = 3
  71. , DEFAULT_JOINROOM_TIMEOUT = 15e3
  72. , DEFAULT_MAIN_CAMERA_FOV = 50
  73. , DEFAULT_AVATAR_SCALE = 1
  74. , REPORT_NUM_PER_REQUEST = 20
  75. , DEFAULT_OPEN_TIMEOUT_MS = 6e3
  76. , WS_CLOSE_NORMAL = 1e3
  77. , WS_CLOSE_RECONNECT = 3008
  78. , PING_INTERVAL_MS = 1e3
  79. , TEXTURE_URL = "https://static.xverse.cn/qqktv/texture.png"
  80. , REPORT_MODULE_TYPE = "xverse-js"
  81. , authenticationErrorCodes = [3001, 3002, 3003, 3005]
  82. , RTT_MAX_VALUE = 200
  83. , HB_MAX_VALUE = 500
  84. , DURATION = 10
  85. , NET_INTERVAL = 1;
  86. const VERSION$1 = "1.0.75"
  87. , ENV = "production";
  88. const COMPONENT_LIST_PREFIX = "/component_list.json";
  89. const debugMode = location.href.indexOf("debug") > -1 // true
  90. // 角色相关设置
  91. const avatarSetting = {
  92. fileType: ".glb",
  93. lodType: "_lod",
  94. lod: [{
  95. level: "lod0",
  96. fileName: ".glb",
  97. quota: 5,
  98. dist: 1e3
  99. }, {
  100. level: "lod1",
  101. fileName: "_lod2.glb",
  102. quota: 5,
  103. dist: 2e3
  104. }, {
  105. level: "lod2",
  106. fileName: "_lod4.glb",
  107. quota: 0,
  108. dist: 7500
  109. }],
  110. isRayCastEnable: !0,
  111. maxAvatarNum: 40, // 角色数量上限
  112. maxBillBoardDist: 7500,
  113. body: "body",
  114. head: "head",
  115. hair: "hair",
  116. suit: "suit",
  117. pants: "pants",
  118. shoes: "shoes",
  119. clothes: "clothes",
  120. animations: "animations",
  121. defaultIdle: "Idle",
  122. cullingDistance: 200,
  123. defaultMove: "Walking"
  124. }
  125. , avatarResources = {
  126. ygb: {
  127. name: "ygb",
  128. mat: "NM_ygb",
  129. mesh: "ygb"
  130. }
  131. }
  132. , action = {
  133. GiftClap: {
  134. animName: "GiftClap",
  135. keyTime: 1760
  136. },
  137. Cheering: {
  138. animName: "Cheering",
  139. attachPair: [{
  140. bone: "mixamorig_MiddleFinger2_R",
  141. obj: "ygb",
  142. offset: {
  143. x: 0,
  144. y: 0,
  145. z: 0
  146. },
  147. rotate: {
  148. x: 0,
  149. y: 3.84,
  150. z: 0
  151. },
  152. scale: {
  153. x: 1,
  154. y: 1,
  155. z: 1
  156. }
  157. }, {
  158. bone: "mixamorig_MiddleFinger2_L",
  159. obj: "ygb",
  160. offset: {
  161. x: 0,
  162. y: 0,
  163. z: 0
  164. },
  165. rotate: {
  166. x: 0,
  167. y: 3.49,
  168. z: 0
  169. },
  170. scale: {
  171. x: 1,
  172. y: 1,
  173. z: 1
  174. }
  175. }]
  176. }
  177. }
  178. const WASM_Version = "h264"
  179. , DECODER_VERSION = "v0.9.3"
  180. , WASM_URLS = {
  181. h264: "https://metaverse.4dage.com/wasm/lib_ff264dec_no_idb_with_wasm_tbundle.js",
  182. xv265: "https://metaverse.4dage.com/wasm/libxv265dec.js",
  183. h265: ""
  184. }
  185. , STUCK_STAGE_GOOD = 45
  186. , STUCK_STAGE_WELL = 85
  187. , STUCK_STAGE_FAIR = 125
  188. , STUCK_STAGE_BAD = 165
  189. , DECODER_PASSIVE_JITTER = 0;
  190. /**
  191. * 公共方法
  192. **/
  193. const isFunction = i=>typeof i == "function";
  194. const isSuit = i=>i === "suit"
  195. // 随机获取数组内某一元素,或字符串内某一字符
  196. const getRandomItem = (i) =>i.length === 0 ? null : i[Math.floor(Math.random() * i.length)]
  197. const getAnimationKey = (i,e)=>e + "_" + i
  198. const blobToDataURI = async i=>new Promise((e,t)=>{
  199. const r = new FileReader;
  200. r.readAsDataURL(i),
  201. r.onload = function(n) {
  202. var o;
  203. e((o = n.target) == null ? void 0 : o.result)
  204. }
  205. ,
  206. r.onerror = function(n) {
  207. t(n)
  208. }
  209. });
  210. // 系统检测
  211. const checkOS = ()=>{
  212. const i = navigator.userAgent
  213. , e = /(?:Windows Phone)/.test(i)
  214. , t = /(?:SymbianOS)/.test(i) || e
  215. , r = /(?:Android)/.test(i)
  216. , n = /(?:Firefox)/.test(i);
  217. /(?:Chrome|CriOS)/.test(i);
  218. const o = /(?:iPad|PlayBook)/.test(i) || r && !/(?:Mobile)/.test(i) || n && /(?:Tablet)/.test(i)
  219. , a = /(?:iPhone|ipad|ipod)/.test(i) && !o
  220. , s = !a && !r && !t;
  221. return {
  222. isTablet: o,
  223. isPhone: a,
  224. isIOS: /iPhone|iPod|iPad/.test(navigator.userAgent),
  225. isAndroid: r,
  226. isPc: s
  227. }
  228. }
  229. var De = Object.defineProperty
  230. , Ne = Object.defineProperties;
  231. var we = Object.getOwnPropertyDescriptors;
  232. var be = Object.getOwnPropertySymbols;
  233. var Me = Object.prototype.hasOwnProperty
  234. , Ie = Object.prototype.propertyIsEnumerable;
  235. var Se = (obj, key, value) =>
  236. key in obj ? Object.defineProperty(obj, key, {
  237. enumerable: true,
  238. configurable: true,
  239. writable: true,
  240. value: value
  241. }) : obj[key] = value
  242. , oe = (obj, propsObj)=>{
  243. for (var t in propsObj || (propsObj = {}))
  244. Me.call(propsObj, t) && Se(obj, t, propsObj[t]);
  245. if (Object.getOwnPropertySymbols) {
  246. for (var t of Object.getOwnPropertySymbols(propsObj))
  247. Ie.call(propsObj, t) && Se(obj, t, propsObj[t]);
  248. }
  249. return obj
  250. }
  251. // 将propsObj的所有属性拷贝到obj
  252. , le = (obj, propsObj) => Object.defineProperties(obj, Object.getOwnPropertyDescriptors(propsObj));
  253. var Oe = (i,e)=>{
  254. var t = {};
  255. for (var r in i)
  256. Me.call(i, r) && e.indexOf(r) < 0 && (t[r] = i[r]);
  257. if (i != null && be)
  258. for (var r of be(i))
  259. e.indexOf(r) < 0 && Ie.call(i, r) && (t[r] = i[r]);
  260. return t
  261. };
  262. var E = (i,e,t)=>(Se(i, typeof e != "symbol" ? e + "" : e, t),t);
  263. // 自定义Promise超时
  264. Promise.prototype._timeout = function(timeLimit, e) {
  265. let handle;
  266. return new Promise((resolve, reject) => (
  267. handle = window.setTimeout(()=>{
  268. reject(e)
  269. }, timeLimit),
  270. this.then(
  271. o=>{
  272. clearTimeout(handle),
  273. resolve(o)
  274. },
  275. o=>{
  276. clearTimeout(handle),
  277. reject(o)
  278. }
  279. )
  280. ))
  281. };
  282. function toast(i, e) {
  283. const {onClick: t, duration: r} = e || {};
  284. // return window.Toastify({
  285. return (new Toastify({
  286. text: i,
  287. duration: r || 3e3,
  288. position: "center",
  289. onClick: function() {
  290. t && t()
  291. }
  292. })).showToast()
  293. // }).showToast()
  294. }
  295. class Toastify {
  296. constructor(options) {
  297. this.text = options.text
  298. this.duration = options.duration
  299. this.onClick = options.onClick
  300. }
  301. showToast() {
  302. setTimeout(() => {
  303. let res = confirm(this.text)
  304. if(res) {
  305. this.onClick()
  306. }
  307. }, this.duration)
  308. return this
  309. }
  310. hideToast() {
  311. return this
  312. }
  313. }
  314. // 将原json里的值全部转成float,并返回一个新json
  315. const objectParseFloat = (i) => {
  316. const e = {};
  317. i && Object.keys(i).forEach((t) => {
  318. e[t] = parseFloat(i[t]);
  319. })
  320. return e;
  321. }
  322. const safelyJsonParse = i=> {
  323. let e = {};
  324. try {
  325. e = JSON.parse(i)
  326. } catch {}
  327. return e
  328. }
  329. const safeParseComponents = i=>{
  330. let e = [];
  331. try {
  332. e = JSON.parse(i || "[]")
  333. } catch {
  334. e = [],
  335. log$2.error(`avatarComponents parse error: ${i}`)
  336. }
  337. return e
  338. }
  339. const safeDecodeURIComponent = i=>{
  340. let e = "";
  341. try {
  342. e = decodeURIComponent(i)
  343. } catch {
  344. e = i
  345. }
  346. return e
  347. }
  348. // 坐标和旋转数值保护,保留2位小数
  349. const positionPrecisionProtect = i=>{
  350. const {x: e, y: t, z: r} = i;
  351. return {
  352. x: +e.toFixed(2),
  353. y: +t.toFixed(2),
  354. z: +r.toFixed(2)
  355. }
  356. }
  357. const rotationPrecisionProtect = i=>{
  358. const {pitch: e, yaw: t, roll: r} = i;
  359. return {
  360. pitch: +e.toFixed(2),
  361. yaw: +t.toFixed(2),
  362. roll: +r.toFixed(2)
  363. }
  364. }
  365. const avatarComponentsModify = (i,e)=>new Promise((t,r)=>{
  366. var l;
  367. let n = [];
  368. const o = []
  369. , a = [];
  370. let s = e.some(u=>isSuit(u.type));
  371. if ((l = i == null ? void 0 : i.components) == null || l.forEach(u=>{
  372. var f;
  373. const c = e.find(d=>d.type === u.type)
  374. , h = c && ((f = i == null ? void 0 : i.components) == null ? void 0 : f.find(d=>d.type === c.type && d.units.some(_=>_.id === c.id))) !== void 0;
  375. if (c)
  376. if (h)
  377. n.push(c);
  378. else {
  379. const d = u.units.find(_=>_.isDefault) || u.units[0];
  380. d ? n.push({
  381. type: u.type,
  382. id: d.id
  383. }) : o.push(`component with type: ${u.type} without default and available unit`)
  384. }
  385. else if (isSuit(u.type)) {
  386. const d = u.units.find(_=>_.isDefault);
  387. d && n.push({
  388. type: u.type,
  389. id: d.id
  390. })
  391. } else {
  392. const d = u.units.find(_=>_.isDefault) || u.units[0];
  393. d ? n.push({
  394. type: u.type,
  395. id: d.id
  396. }) : o.push(`component with type: ${u.type} without default and available unit`)
  397. }
  398. }
  399. ),
  400. s = n.some(u=>isSuit(u.type)),
  401. s) {
  402. const u = i == null ? void 0 : i.components.find(c=>isSuit(c.type));
  403. n = n.filter(c=>(u == null ? void 0 : u.suitComb.indexOf(c.type)) === -1)
  404. }
  405. o.length > 0 && (log$2.error(o.join(", ")),
  406. r(o.join(", "))),
  407. a.length > 0 && log$2.warn(a.join(", ")),
  408. t(n)
  409. })
  410. const avatarComponentsParser = async(i=null,e,t=[])=>new Promise(async(r,n)=>{
  411. var u, c;
  412. if (e.find(h=>isSuit(h.type))) {
  413. const h = (c = (u = i == null ? void 0 : i.components) == null ? void 0 : u.find(f=>isSuit(f.type))) == null ? void 0 : c.suitComb;
  414. e = e.filter(f=>(h == null ? void 0 : h.indexOf(f.type)) === -1)
  415. }
  416. const a = e.filter(h=>!t.some(f=>f.id === h.id));
  417. a.length === 0 && r([]);
  418. const s = [];
  419. a.forEach(async h=>{
  420. var _;
  421. let f = (_ = i == null ? void 0 : i.components) == null ? void 0 : _.find(g=>g.type === h.type);
  422. if (!f) {
  423. const g = `changeComponents, no such component with type: ${h.type}`;
  424. log$2.error(g),
  425. n(g)
  426. }
  427. f = JSON.parse(JSON.stringify(f));
  428. let d = f == null ? void 0 : f.units.find(g=>g.id === h.id);
  429. d || (log$2.warn(`changeComponents, no unit with type: ${h.type}, id: ${h.id}`),
  430. d = f == null ? void 0 : f.units.find(g=>g.isDefault),
  431. !d && log$2.warn(`changeComponents, no default unit with type: ${h.type}`)),
  432. d && s.push({
  433. id: d.id,
  434. url: d.url,
  435. suitComb: (f == null ? void 0 : f.suitComb) || [],
  436. type: h.type
  437. })
  438. });
  439. const l = [];
  440. Promise.all(l).then(h=>{
  441. s.forEach((f,d)=>{
  442. var _, g;
  443. if (!isSuit(f.type)) {
  444. const m = ((g = (_ = i == null ? void 0 : i.components) == null ? void 0 : _.find(v=>isSuit(v.type))) == null ? void 0 : g.suitComb) || [];
  445. m.length > 0 && (m == null ? void 0 : m.indexOf(f.type)) !== -1 && (f.suitComb = ["suit"])
  446. }
  447. f.url = h[d]
  448. }
  449. ),
  450. r(s)
  451. }).catch(h=>{
  452. n(h)
  453. })
  454. })
  455. /**
  456. * 坐标转换相关
  457. **/
  458. // UE4 to Xverse
  459. const ue4Rotation2Xverse = i=>isRotationCorrect() ? (
  460. i.pitch >= 89.5 ? i.pitch = 89.5 : i.pitch <= -89.5 && (i.pitch = -89.5),
  461. new BABYLON.Vector3(-1 * Math.PI * i.pitch / 180,Math.PI * i.yaw / 180 - Math.PI * 27 / 18,Math.PI * i.roll / 180 < .001 ? 0 : Math.PI * i.roll / 180)
  462. ) : null
  463. const ue4Rotation2Xverse_mesh = i=>isRotationCorrect() ? new BABYLON.Vector3(Math.PI * i.pitch / 180,Math.PI * i.yaw / 180,Math.abs(Math.PI * i.roll) / 180 < .001 ? 0 : -1 * (Math.PI * i.roll) / 180) : null
  464. const scaleFromUE4toXverse = 100;
  465. const ue4Scaling2Xverse = i=>isScalingCorrect() ? new BABYLON.Vector3(i.x,i.z,-1 * i.y) : null
  466. const ue4Position2Xverse = i=>isPositionCorrect() ? new BABYLON.Vector3(i.x * .01,i.z * .01,-1 * i.y * .01) : null
  467. // Xverse to Ue4
  468. const xversePosition2Ue4 = i=>isPositionCorrect() ? {
  469. x: i.x * 100,
  470. y: -1 * i.z * 100,
  471. z: i.y * 100
  472. } : null
  473. const xverseRotation2Ue4 = i=>{
  474. if (isPositionCorrect()) {
  475. let e = 0;
  476. return i.z == 0 ? e = 0 : e = 180 * i.z / Math.PI,
  477. {
  478. pitch: 180 * i.x * -1 / Math.PI,
  479. yaw: (i.y + Math.PI * 27 / 18) * 180 / Math.PI,
  480. roll: e
  481. }
  482. } else
  483. return null
  484. }
  485. // 计算两个向量间的距离或角度
  486. const calcDistance3D = (i,e)=>Math.sqrt((i.x - e.x) * (i.x - e.x) + (i.y - e.y) * (i.y - e.y) + (i.z - e.z) * (i.z - e.z))
  487. const calcDistance3DVector = (i,e)=>Math.sqrt((i.x - e.x) * (i.x - e.x) + (i.y - e.y) * (i.y - e.y) + (i.z - e.z) * (i.z - e.z))
  488. const calcDistance3DAngle = (i,e)=>Math.sqrt((i.roll - e.roll) * (i.roll - e.roll) + (i.pitch - e.pitch) * (i.pitch - e.pitch) + (i.yaw - e.yaw) * (i.yaw - e.yaw))
  489. const isPositionCorrect = i=>!0
  490. const isScalingCorrect = i=>!0
  491. const isRotationCorrect = i=>!0
  492. const getStringBoundaries = (i,e,t=new Map)=>{
  493. let r = 0
  494. , n = ""
  495. , o = -1
  496. , a = 0;
  497. const s = [0];
  498. for (let l = 0; l < i.length; l++) {
  499. const u = i.codePointAt(l);
  500. let c = t.get(u);
  501. if (c)
  502. r += c,
  503. n += i[l],
  504. u > 64 && u < 91 || u > 96 && u < 123 ? (o == -1 && (o = l),
  505. a += c) : (o = -1,
  506. a = 0);
  507. else if (u < 975 || u > 1024 && u < 1920)
  508. c = 1,
  509. r++,
  510. n += i[l],
  511. u > 64 && u < 91 || u > 96 && u < 123 ? (o == -1 && (o = l),
  512. a += c) : (o = -1,
  513. a = 0);
  514. else if (u > 4499 && u < 4600 || u > 8207 && u < 8232 || u > 8238 && u < 8287 || u > 8238 && u < 8287 || u > 8304 && u < 8384 || u > 8447 && u < 9211 || u > 11263 && u < 11624 || u > 11646 && u < 11671 || u > 11679 && u < 11845 || u > 11903 && u < 12020 || u > 12031 && u < 12246 || u > 12287 && u < 12544 || u > 12548 && u < 12728 || u > 12735 && u < 12772 || u > 12783 && u < 19894 || u > 19967 && u < 40918 || u > 42191 && u < 42240 || u > 44031 && u < 55204 || u > 59276 && u < 59287 || u > 59412 && u < 59493 || u > 63743 && u < 64207 || u > 65039 && u < 65050 || u > 65071 && u < 65510)
  515. c = 2,
  516. r += 2,
  517. o = -1,
  518. a = 0,
  519. n += i[l];
  520. else if (u > 9311 && u < 11158) {
  521. c = 2,
  522. r += 2,
  523. o = -1,
  524. a = 0,
  525. n += i[l];
  526. const h = i.codePointAt(l + 1);
  527. h > 65023 && h < 65040 && (n += i[l + 1],
  528. l++)
  529. } else
  530. u > 126979 && u < 129783 && (c = 2,
  531. r += 2,
  532. o = -1,
  533. a = 0,
  534. l++,
  535. n += String.fromCodePoint(u));
  536. if (l == s[s.length - 1] + 1 && o > 0 ? (s[s.length - 1] = o,
  537. r = 0 + a) : r > e && (s.push(l),
  538. a >= r && (a = 0 + c,
  539. o = 0),
  540. r = 0 + c),
  541. l >= i.length - 1)
  542. break
  543. }
  544. return s[s.length - 1] != i.length && s.push(i.length),
  545. [n, s]
  546. }
  547. var Observer = function() {
  548. function i(e, t, r) {
  549. r === void 0 && (r = null),
  550. this.callback = e,
  551. this.mask = t,
  552. this.scope = r,
  553. this._willBeUnregistered = !1,
  554. this.unregisterOnNextCall = !1
  555. }
  556. return i
  557. }()
  558. var Observable = function() {
  559. function i(e) {
  560. this._observers = new Array,
  561. this._eventState = new BABYLON.EventState(0),
  562. e && (this._onObserverAdded = e)
  563. }
  564. i.FromPromise = function(e, t) {
  565. var r = new i;
  566. return e.then(function(n) {
  567. r.notifyObservers(n)
  568. }).catch(function(n) {
  569. if (t)
  570. t.notifyObservers(n);
  571. else
  572. throw n
  573. }),
  574. r
  575. }
  576. ,
  577. Object.defineProperty(i.prototype, "observers", {
  578. get: function() {
  579. return this._observers
  580. },
  581. enumerable: !1,
  582. configurable: !0
  583. }),
  584. i.prototype.add = function(e, t, r, n, o) {
  585. if (t === void 0 && (t = -1),
  586. r === void 0 && (r = !1),
  587. n === void 0 && (n = null),
  588. o === void 0 && (o = !1),
  589. !e)
  590. return null;
  591. var a = new Observer(e,t,n);
  592. return a.unregisterOnNextCall = o,
  593. r ? this._observers.unshift(a) : this._observers.push(a),
  594. this._onObserverAdded && this._onObserverAdded(a),
  595. a
  596. }
  597. ,
  598. i.prototype.addOnce = function(e) {
  599. return this.add(e, void 0, void 0, void 0, !0)
  600. }
  601. ,
  602. i.prototype.remove = function(e) {
  603. if (!e)
  604. return !1;
  605. var t = this._observers.indexOf(e);
  606. return t !== -1 ? (this._deferUnregister(e),
  607. !0) : !1
  608. }
  609. ,
  610. i.prototype.removeCallback = function(e, t) {
  611. for (var r = 0; r < this._observers.length; r++) {
  612. var n = this._observers[r];
  613. if (!n._willBeUnregistered && n.callback === e && (!t || t === n.scope))
  614. return this._deferUnregister(n),
  615. !0
  616. }
  617. return !1
  618. }
  619. ,
  620. i.prototype._deferUnregister = function(e) {
  621. var t = this;
  622. e.unregisterOnNextCall = !1,
  623. e._willBeUnregistered = !0,
  624. setTimeout(function() {
  625. t._remove(e)
  626. }, 0)
  627. }
  628. ,
  629. i.prototype._remove = function(e) {
  630. if (!e)
  631. return !1;
  632. var t = this._observers.indexOf(e);
  633. return t !== -1 ? (this._observers.splice(t, 1),
  634. !0) : !1
  635. }
  636. ,
  637. i.prototype.makeObserverTopPriority = function(e) {
  638. this._remove(e),
  639. this._observers.unshift(e)
  640. }
  641. ,
  642. i.prototype.makeObserverBottomPriority = function(e) {
  643. this._remove(e),
  644. this._observers.push(e)
  645. }
  646. ,
  647. i.prototype.notifyObservers = function(e, t, r, n, o) {
  648. if (t === void 0 && (t = -1),
  649. !this._observers.length)
  650. return !0;
  651. var a = this._eventState;
  652. a.mask = t,
  653. a.target = r,
  654. a.currentTarget = n,
  655. a.skipNextObservers = !1,
  656. a.lastReturnValue = e,
  657. a.userInfo = o;
  658. for (var s = 0, l = this._observers; s < l.length; s++) {
  659. var u = l[s];
  660. if (!u._willBeUnregistered && (u.mask & t && (u.scope ? a.lastReturnValue = u.callback.apply(u.scope, [e, a]) : a.lastReturnValue = u.callback(e, a),
  661. u.unregisterOnNextCall && this._deferUnregister(u)),
  662. a.skipNextObservers))
  663. return !1
  664. }
  665. return !0
  666. }
  667. ,
  668. i.prototype.notifyObserversWithPromise = function(e, t, r, n, o) {
  669. var a = this;
  670. t === void 0 && (t = -1);
  671. var s = Promise.resolve(e);
  672. if (!this._observers.length)
  673. return s;
  674. var l = this._eventState;
  675. return l.mask = t,
  676. l.target = r,
  677. l.currentTarget = n,
  678. l.skipNextObservers = !1,
  679. l.userInfo = o,
  680. this._observers.forEach(function(u) {
  681. l.skipNextObservers || u._willBeUnregistered || u.mask & t && (u.scope ? s = s.then(function(c) {
  682. return l.lastReturnValue = c,
  683. u.callback.apply(u.scope, [e, l])
  684. }) : s = s.then(function(c) {
  685. return l.lastReturnValue = c,
  686. u.callback(e, l)
  687. }),
  688. u.unregisterOnNextCall && a._deferUnregister(u))
  689. }),
  690. s.then(function() {
  691. return e
  692. })
  693. }
  694. ,
  695. i.prototype.notifyObserver = function(e, t, r) {
  696. if (r === void 0 && (r = -1),
  697. !e._willBeUnregistered) {
  698. var n = this._eventState;
  699. n.mask = r,
  700. n.skipNextObservers = !1,
  701. e.callback(t, n),
  702. e.unregisterOnNextCall && this._deferUnregister(e)
  703. }
  704. }
  705. ,
  706. i.prototype.hasObservers = function() {
  707. return this._observers.length > 0
  708. }
  709. ,
  710. i.prototype.clear = function() {
  711. this._observers = new Array,
  712. this._onObserverAdded = null
  713. }
  714. ,
  715. i.prototype.clone = function() {
  716. var e = new i;
  717. return e._observers = this._observers.slice(0),
  718. e
  719. }
  720. ,
  721. i.prototype.hasSpecificMask = function(e) {
  722. e === void 0 && (e = -1);
  723. for (var t = 0, r = this._observers; t < r.length; t++) {
  724. var n = r[t];
  725. if (n.mask & e || n.mask === e)
  726. return !0
  727. }
  728. return !1
  729. }
  730. return i
  731. }();
  732. </script>
  733. <div id="root">
  734. <div class="loading" style="z-index: 9999"></div>
  735. <div class = "App">
  736. <canvas id = "canvas" class = "stream unselect">
  737. </canvas>
  738. </div>
  739. <div class="debug_control_btns">
  740. <button class="debugger1">Toggle Stats</button>
  741. <button class="debugger2">取消低模着色</button>
  742. <button class="debugger3">画质:高</button>
  743. <button class="font-size-small debugger4" onclick="room.debug.toggleNearbyBreathPoint">Toggle周边呼吸点</button>
  744. <button class="font-size-small debugger5" onclick="room.debug.toggleTapBreathPoint">Toggle点击呼吸点</button>
  745. <button class="font-size-small debugger6" >录制码流(10s)</button>
  746. </div>
  747. </div>
  748. <script type="module">
  749. document.querySelector('.debugger1').onclick = ()=>{
  750. var y, b;
  751. (y = window.room.stats) != null && y.isShow
  752. ? window.room.stats.hide()
  753. : (b = window.room.stats) == null || b.show();
  754. }
  755. document.querySelector('.debugger2').onclick = ()=>{
  756. window.room.debug.toggleSceneshading() //, r(room.debug.isSceneShading);
  757. }
  758. document.querySelector('.debugger3').onclick = ()=>{
  759. let y = "average";
  760. n === "high"
  761. ? (y = "average")
  762. : n === "average"
  763. ? (y = "low")
  764. : n === "low"
  765. ? (y = "high")
  766. : (y = "average"),
  767. o(y),
  768. window.room.setPictureQualityLevel(y);
  769. }
  770. document.querySelector('.debugger4').onclick = ()=>{
  771. window.room.debug.toggleNearbyBreathPoint();
  772. }
  773. document.querySelector('.debugger5').onclick = ()=>{
  774. window.room.debug.toggleTapBreathPoint();
  775. }
  776. document.querySelector('.debugger6').onclick = ()=>{
  777. window.room.debug.dumpStream(() => {
  778. // toast("\u5F55\u5236\u5B8C\u6210");
  779. });
  780. // toast("\u5F00\u59CB\u5F55\u5236");
  781. }
  782. // 只在调试时显示control面板
  783. debugMode || (document.querySelector(".debug_control_btns").style.display = "none")
  784. </script>
  785. <script src="js/index.js"></script>
  786. </body>
  787. </html>