topazcube 0.1.30 → 0.1.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/LICENSE.txt +0 -0
  2. package/README.md +0 -0
  3. package/dist/Renderer.cjs +18200 -0
  4. package/dist/Renderer.cjs.map +1 -0
  5. package/dist/Renderer.js +18183 -0
  6. package/dist/Renderer.js.map +1 -0
  7. package/dist/client.cjs +94 -260
  8. package/dist/client.cjs.map +1 -1
  9. package/dist/client.js +71 -215
  10. package/dist/client.js.map +1 -1
  11. package/dist/server.cjs +165 -432
  12. package/dist/server.cjs.map +1 -1
  13. package/dist/server.js +117 -370
  14. package/dist/server.js.map +1 -1
  15. package/dist/terminal.cjs +113 -200
  16. package/dist/terminal.cjs.map +1 -1
  17. package/dist/terminal.js +50 -51
  18. package/dist/terminal.js.map +1 -1
  19. package/dist/utils-CRhi1BDa.cjs +259 -0
  20. package/dist/utils-CRhi1BDa.cjs.map +1 -0
  21. package/dist/utils-D7tXt6-2.js +260 -0
  22. package/dist/utils-D7tXt6-2.js.map +1 -0
  23. package/package.json +19 -15
  24. package/src/{client.ts → network/client.js} +173 -403
  25. package/src/{compress-browser.ts → network/compress-browser.js} +2 -4
  26. package/src/{compress-node.ts → network/compress-node.js} +8 -14
  27. package/src/{server.ts → network/server.js} +229 -317
  28. package/src/{terminal.js → network/terminal.js} +0 -0
  29. package/src/{topazcube.ts → network/topazcube.js} +2 -2
  30. package/src/network/utils.js +375 -0
  31. package/src/renderer/Camera.js +191 -0
  32. package/src/renderer/DebugUI.js +572 -0
  33. package/src/renderer/Geometry.js +1049 -0
  34. package/src/renderer/Material.js +61 -0
  35. package/src/renderer/Mesh.js +211 -0
  36. package/src/renderer/Node.js +112 -0
  37. package/src/renderer/Pipeline.js +643 -0
  38. package/src/renderer/Renderer.js +1324 -0
  39. package/src/renderer/Skin.js +792 -0
  40. package/src/renderer/Texture.js +584 -0
  41. package/src/renderer/core/AssetManager.js +359 -0
  42. package/src/renderer/core/CullingSystem.js +307 -0
  43. package/src/renderer/core/EntityManager.js +541 -0
  44. package/src/renderer/core/InstanceManager.js +343 -0
  45. package/src/renderer/core/ParticleEmitter.js +358 -0
  46. package/src/renderer/core/ParticleSystem.js +564 -0
  47. package/src/renderer/core/SpriteSystem.js +349 -0
  48. package/src/renderer/gltf.js +546 -0
  49. package/src/renderer/math.js +161 -0
  50. package/src/renderer/rendering/HistoryBufferManager.js +333 -0
  51. package/src/renderer/rendering/ProbeCapture.js +1495 -0
  52. package/src/renderer/rendering/ReflectionProbeManager.js +352 -0
  53. package/src/renderer/rendering/RenderGraph.js +2064 -0
  54. package/src/renderer/rendering/passes/AOPass.js +308 -0
  55. package/src/renderer/rendering/passes/AmbientCapturePass.js +593 -0
  56. package/src/renderer/rendering/passes/BasePass.js +101 -0
  57. package/src/renderer/rendering/passes/BloomPass.js +417 -0
  58. package/src/renderer/rendering/passes/FogPass.js +419 -0
  59. package/src/renderer/rendering/passes/GBufferPass.js +706 -0
  60. package/src/renderer/rendering/passes/HiZPass.js +714 -0
  61. package/src/renderer/rendering/passes/LightingPass.js +739 -0
  62. package/src/renderer/rendering/passes/ParticlePass.js +835 -0
  63. package/src/renderer/rendering/passes/PlanarReflectionPass.js +456 -0
  64. package/src/renderer/rendering/passes/PostProcessPass.js +282 -0
  65. package/src/renderer/rendering/passes/ReflectionPass.js +157 -0
  66. package/src/renderer/rendering/passes/RenderPostPass.js +364 -0
  67. package/src/renderer/rendering/passes/SSGIPass.js +265 -0
  68. package/src/renderer/rendering/passes/SSGITilePass.js +296 -0
  69. package/src/renderer/rendering/passes/ShadowPass.js +1822 -0
  70. package/src/renderer/rendering/passes/TransparentPass.js +831 -0
  71. package/src/renderer/rendering/shaders/ao.wgsl +182 -0
  72. package/src/renderer/rendering/shaders/bloom.wgsl +97 -0
  73. package/src/renderer/rendering/shaders/bloom_blur.wgsl +80 -0
  74. package/src/renderer/rendering/shaders/depth_copy.wgsl +17 -0
  75. package/src/renderer/rendering/shaders/geometry.wgsl +550 -0
  76. package/src/renderer/rendering/shaders/hiz_reduce.wgsl +114 -0
  77. package/src/renderer/rendering/shaders/light_culling.wgsl +204 -0
  78. package/src/renderer/rendering/shaders/lighting.wgsl +932 -0
  79. package/src/renderer/rendering/shaders/lighting_common.wgsl +143 -0
  80. package/src/renderer/rendering/shaders/particle_render.wgsl +525 -0
  81. package/src/renderer/rendering/shaders/particle_simulate.wgsl +440 -0
  82. package/src/renderer/rendering/shaders/postproc.wgsl +272 -0
  83. package/src/renderer/rendering/shaders/render_post.wgsl +289 -0
  84. package/src/renderer/rendering/shaders/shadow.wgsl +76 -0
  85. package/src/renderer/rendering/shaders/ssgi.wgsl +266 -0
  86. package/src/renderer/rendering/shaders/ssgi_accumulate.wgsl +114 -0
  87. package/src/renderer/rendering/shaders/ssgi_propagate.wgsl +132 -0
  88. package/src/renderer/utils/BoundingSphere.js +439 -0
  89. package/src/renderer/utils/Frustum.js +281 -0
  90. package/dist/client.d.cts +0 -211
  91. package/dist/client.d.ts +0 -211
  92. package/dist/server.d.cts +0 -120
  93. package/dist/server.d.ts +0 -120
  94. package/dist/terminal.d.cts +0 -64
  95. package/dist/terminal.d.ts +0 -64
  96. package/src/utils.ts +0 -403
package/dist/client.cjs CHANGED
@@ -1,160 +1,8 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/client.ts
21
- var client_exports = {};
22
- __export(client_exports, {
23
- default: () => TopazCubeClient
24
- });
25
- module.exports = __toCommonJS(client_exports);
26
- var import_fast_json_patch = require("fast-json-patch");
27
-
28
- // src/utils.ts
29
- var import_msgpackr = require("msgpackr");
30
- var import_msgpackr2 = require("msgpackr");
31
- var { ALWAYS } = import_msgpackr2.FLOAT32_OPTIONS;
32
- var packr = new import_msgpackr.Packr({
33
- useFloat32: ALWAYS
34
- });
35
- function encode(obj) {
36
- return packr.pack(obj);
37
- }
38
- function decode(data) {
39
- return packr.unpack(data);
40
- }
41
- function reactive(name, object, callback, path = "", excludedProperties = false) {
42
- if (object === null || typeof object !== "object") {
43
- return object;
44
- }
45
- function isReactive(p) {
46
- let r = true;
47
- if (p.startsWith("_")) {
48
- r = false;
49
- }
50
- if (excludedProperties) {
51
- if (excludedProperties[p]) {
52
- r = false;
53
- }
54
- }
55
- if (path == "/entities") {
56
- r = false;
57
- }
58
- return r;
59
- }
60
- for (const property in object) {
61
- if (isReactive(property)) {
62
- object[property] = reactive(
63
- name,
64
- object[property],
65
- callback,
66
- path + "/" + property,
67
- excludedProperties
68
- );
69
- } else {
70
- }
71
- }
72
- return new Proxy(object, {
73
- get(target, property, receiver) {
74
- return Reflect.get(target, property, receiver);
75
- },
76
- set(target, property, value) {
77
- let newvalue;
78
- let pn = path + "/" + String(property);
79
- if (isReactive(String(property))) {
80
- newvalue = reactive(name, value, callback, pn, excludedProperties);
81
- callback(name, "replace", target, pn, newvalue);
82
- } else {
83
- newvalue = value;
84
- }
85
- return Reflect.set(target, property, newvalue);
86
- },
87
- deleteProperty(target, property) {
88
- let pn = path + "/" + String(property);
89
- if (isReactive(String(property))) {
90
- callback(name, "remove", target, pn, null);
91
- }
92
- delete target[property];
93
- return true;
94
- }
95
- });
96
- }
97
- function msgop(op) {
98
- let nop = {};
99
- if (!op.o) {
100
- nop.op = "replace";
101
- } else {
102
- nop.op = {
103
- a: "add",
104
- r: "remove",
105
- d: "delete",
106
- t: "test"
107
- }[op.o];
108
- }
109
- nop.path = op.p;
110
- nop.value = op.v;
111
- return nop;
112
- }
113
- function opmsg(op, target, path, value) {
114
- let c = { p: path, v: value };
115
- if (op != "replace") {
116
- c.o = {
117
- add: "a",
118
- remove: "r",
119
- delete: "d",
120
- test: "t"
121
- }[op];
122
- }
123
- return c;
124
- }
125
- function decode_uint32(byteArray, offset = 0) {
126
- let p = offset;
127
- return (byteArray[p++] & 127) << 24 | byteArray[p++] << 16 | byteArray[p++] << 8 | byteArray[p];
128
- }
129
- function decode_uint24(byteArray, offset = 0) {
130
- let p = offset;
131
- return byteArray[p++] << 16 | byteArray[p++] << 8 | byteArray[p];
132
- }
133
- function decode_uint16(byteArray, offset = 0) {
134
- let p = offset;
135
- return byteArray[p++] << 8 | byteArray[p];
136
- }
137
- function decode_fp168(byteArray, offset = 0) {
138
- const divider = (byteArray[offset] & 128) === 128 ? -256 : 256;
139
- byteArray[offset] &= 127;
140
- const fp = decode_uint24(byteArray, offset);
141
- return fp / divider;
142
- }
143
- function decode_fp1616(byteArray, offset = 0) {
144
- const divider = (byteArray[offset] & 128) === 128 ? -65536 : 65536;
145
- byteArray[offset] &= 127;
146
- const fp = decode_uint32(byteArray, offset);
147
- return fp / divider;
148
- }
149
- function decode_fp412(byteArray, offset = 0) {
150
- const divider = (byteArray[offset] & 128) === 128 ? -4096 : 4096;
151
- byteArray[offset] &= 127;
152
- const fp = decode_uint16(byteArray, offset);
153
- return fp / divider;
154
- }
155
-
156
- // src/compress-browser.ts
157
- var browserFormat = "gzip";
2
+ const fastjsonpatch = require("fast-json-patch");
3
+ const utils = require("./utils-CRhi1BDa.cjs");
4
+ const glMatrix = require("gl-matrix");
5
+ const browserFormat = "gzip";
158
6
  async function decompress(buffer) {
159
7
  if (typeof DecompressionStream !== "undefined") {
160
8
  try {
@@ -170,13 +18,9 @@ async function decompress(buffer) {
170
18
  throw new Error("DecompressionStream not supported");
171
19
  }
172
20
  }
173
-
174
- // src/client.ts
175
- var import_gl_matrix = require("gl-matrix");
176
- var TopazCubeClient = class {
21
+ class TopazCubeClient {
177
22
  DEBUG = false;
178
23
  CYCLE = 200;
179
- // update/patch rate in ms
180
24
  url = "";
181
25
  documents = {};
182
26
  autoReconnect = true;
@@ -194,13 +38,11 @@ var TopazCubeClient = class {
194
38
  recRTCBps: 0,
195
39
  ping: 0,
196
40
  stdiff: 0
197
- // server time difference
198
41
  };
199
42
  lastFullState = 0;
200
43
  lastPatch = 0;
201
44
  _chunks = {};
202
45
  le = true;
203
- // Server is little endian
204
46
  _documentChanges = {};
205
47
  ID = 0;
206
48
  socket = null;
@@ -209,9 +51,7 @@ var TopazCubeClient = class {
209
51
  _remoteCandidates = [];
210
52
  _offerSent = false;
211
53
  _dataChannel = null;
212
- // our data channel
213
54
  _serverDataChannel = null;
214
- // server data channel
215
55
  _webRTCConnected = false;
216
56
  isInterpolated = false;
217
57
  _lastInterpolate = Date.now();
@@ -226,11 +66,8 @@ var TopazCubeClient = class {
226
66
  _pingiv = null;
227
67
  constructor({
228
68
  url,
229
- // server url
230
69
  autoReconnect = true,
231
- // auto reconnect on disconnect
232
70
  allowSync = true,
233
- // allow sync on connect
234
71
  allowWebRTC = false,
235
72
  DEBUG = false
236
73
  }) {
@@ -256,7 +93,6 @@ var TopazCubeClient = class {
256
93
  error(...args) {
257
94
  console.error(...args);
258
95
  }
259
- /*= UPDATE ===================================================================*/
260
96
  _startLoop() {
261
97
  if (this._loopiv) {
262
98
  clearInterval(this._loopiv);
@@ -302,53 +138,51 @@ var TopazCubeClient = class {
302
138
  this.isPatched = false;
303
139
  this.le = true;
304
140
  }
305
- /*= INTERPOLATION ============================================================*/
306
- // to be called in display rate (like 60fps) to interpolate .position, .rotation and .scale
307
141
  interpolate() {
308
- let now = Date.now();
309
- let dt = now - this._lastInterpolate;
142
+ const now = Date.now();
143
+ const dt = now - this._lastInterpolate;
310
144
  this._lastInterpolate = now;
311
145
  if (dt <= 0 || dt > 200) {
312
146
  return;
313
147
  }
314
148
  this.isInterpolated = true;
315
- for (let name in this.documents) {
316
- let doc = this.documents[name];
317
- let entities = doc?.entities;
149
+ for (const name in this.documents) {
150
+ const doc = this.documents[name];
151
+ const entities = doc?.entities;
318
152
  if (!entities) {
319
153
  continue;
320
154
  }
321
- for (let id in entities) {
322
- let e = entities[id];
155
+ for (const id in entities) {
156
+ const e = entities[id];
323
157
  if (e._lpostime1 && e._lpostime2) {
324
- let t1 = e._lpostime1;
325
- let t2 = e._lpostime2;
158
+ const t1 = e._lpostime1;
159
+ const t2 = e._lpostime2;
326
160
  const interval = t2 - t1;
327
161
  const elapsed = now - t1;
328
162
  e.pelapsed = elapsed;
329
163
  if (elapsed > 1e3) {
330
- import_gl_matrix.vec3.copy(e.position, e._lpos2);
164
+ glMatrix.vec3.copy(e.position, e._lpos2);
331
165
  e._changed_position = now;
332
166
  } else {
333
167
  const alpha = Math.max(0, elapsed / interval);
334
- import_gl_matrix.vec3.lerp(this._dpos, e._lpos1, e._lpos2, alpha);
335
- import_gl_matrix.vec3.lerp(e.position, e.position, this._dpos, 0.07);
168
+ glMatrix.vec3.lerp(this._dpos, e._lpos1, e._lpos2, alpha);
169
+ glMatrix.vec3.lerp(e.position, e.position, this._dpos, 0.07);
336
170
  e._changed_position = now;
337
171
  }
338
172
  }
339
173
  if (e._lrottime1 && e._lrottime2) {
340
- let t1 = e._lrottime1;
341
- let t2 = e._lrottime2;
174
+ const t1 = e._lrottime1;
175
+ const t2 = e._lrottime2;
342
176
  const interval = t2 - t1;
343
177
  const elapsed = now - t1;
344
178
  e.relapsed = elapsed;
345
179
  if (elapsed > 1e3) {
346
- import_gl_matrix.quat.copy(e.rotation, e._lrot2);
180
+ glMatrix.quat.copy(e.rotation, e._lrot2);
347
181
  e._changed_rotation = now;
348
182
  } else {
349
183
  const alpha = Math.max(0, elapsed / interval);
350
- import_gl_matrix.quat.slerp(this._drot, e._lrot1, e._lrot2, alpha);
351
- import_gl_matrix.quat.slerp(e.rotation, e.rotation, this._drot, 0.07);
184
+ glMatrix.quat.slerp(this._drot, e._lrot1, e._lrot2, alpha);
185
+ glMatrix.quat.slerp(e.rotation, e.rotation, this._drot, 0.07);
352
186
  e._changed_rotation = now;
353
187
  }
354
188
  }
@@ -356,7 +190,6 @@ var TopazCubeClient = class {
356
190
  }
357
191
  this.isInterpolated = false;
358
192
  }
359
- /*= CONNECTION ===============================================================*/
360
193
  subscribe(name) {
361
194
  this.documents[name] = {};
362
195
  this.send({ c: "sub", n: name });
@@ -374,11 +207,11 @@ var TopazCubeClient = class {
374
207
  this.log("connecting...");
375
208
  this.socket = new WebSocket(this.url);
376
209
  this.socket.onmessage = async (event) => {
377
- let buffer = await event.data.arrayBuffer();
210
+ const buffer = await event.data.arrayBuffer();
378
211
  this.stats.rec += buffer.byteLength;
379
- let dec = await decompress(buffer);
380
- let decu = new Uint8Array(dec);
381
- let message = decode(decu);
212
+ const dec = await decompress(buffer);
213
+ const decu = new Uint8Array(dec);
214
+ const message = utils.decode(decu);
382
215
  this._onMessage(message);
383
216
  };
384
217
  this.socket.onclose = (_event) => {
@@ -465,14 +298,16 @@ var TopazCubeClient = class {
465
298
  this.send({ c: "ping", ct: Date.now() });
466
299
  }
467
300
  }
468
- /*= MESSAGES =================================================================*/
469
301
  onChange(_name, _doc, patch) {
470
302
  }
471
303
  onMessage(_message) {
472
304
  }
473
305
  send(operation) {
306
+ if (!this.isConnected) {
307
+ return;
308
+ }
474
309
  try {
475
- let enc = encode(operation);
310
+ const enc = utils.encode(operation);
476
311
  this.stats.send += enc.byteLength;
477
312
  if (this.socket) {
478
313
  this.socket.send(enc);
@@ -482,19 +317,19 @@ var TopazCubeClient = class {
482
317
  }
483
318
  }
484
319
  get document() {
485
- let names = "" + Object.keys(this.documents);
320
+ const names = "" + Object.keys(this.documents);
486
321
  return this.documents["" + names[0]];
487
322
  }
488
323
  async _onMessage(message) {
489
324
  let time = Date.now();
490
325
  if (message.c == "full") {
491
- let name = "" + message.n;
492
- let doc = message.doc;
326
+ const name = "" + message.n;
327
+ const doc = message.doc;
493
328
  this.documents[name] = doc;
494
329
  this._decodeFastChanges(message);
495
330
  this.isPatched = false;
496
331
  if (this.allowSync) {
497
- this.documents[name] = reactive(
332
+ this.documents[name] = utils.reactive(
498
333
  name,
499
334
  this.documents[name],
500
335
  this._onDocumentChange.bind(this)
@@ -508,17 +343,17 @@ var TopazCubeClient = class {
508
343
  }
509
344
  } else if (message.c == "patch") {
510
345
  this.lastPatch = message.t;
511
- let name = message.n;
346
+ const name = message.n;
512
347
  if (!this.documents[name]) {
513
348
  this.warn("Patch for unknown document", name);
514
349
  return;
515
350
  }
516
351
  if (message.doc) {
517
352
  this.isPatched = true;
518
- for (let op of message.doc) {
519
- let dop = msgop(op);
353
+ for (const op of message.doc) {
354
+ const dop = utils.msgop(op);
520
355
  try {
521
- (0, import_fast_json_patch.applyOperation)(this.documents[name], dop);
356
+ fastjsonpatch.applyOperation(this.documents[name], dop);
522
357
  } catch (e) {
523
358
  this.warn("applyOperation failed for", name, "with op", dop, e);
524
359
  }
@@ -532,13 +367,13 @@ var TopazCubeClient = class {
532
367
  this._chunks[message.mid + "-" + message.seq] = message;
533
368
  if (message.last) {
534
369
  let cfound = 0;
535
- let ts = message.ts;
536
- let cdata = new Uint8Array(ts);
370
+ const ts = message.ts;
371
+ const cdata = new Uint8Array(ts);
537
372
  for (const cid in this._chunks) {
538
- let chunk = this._chunks[cid];
373
+ const chunk = this._chunks[cid];
539
374
  if (chunk.mid == message.mid) {
540
- let offset = chunk.ofs;
541
- let _csize = chunk.chs;
375
+ const offset = chunk.ofs;
376
+ chunk.chs;
542
377
  cdata.set(new Uint8Array(chunk.data), offset);
543
378
  cfound++;
544
379
  delete this._chunks[cid];
@@ -546,9 +381,9 @@ var TopazCubeClient = class {
546
381
  }
547
382
  if (cfound == message.seq + 1) {
548
383
  try {
549
- let cdec = await decompress(cdata);
550
- let cdecu = new Uint8Array(cdec);
551
- let nmessage = decode(cdecu);
384
+ const cdec = await decompress(cdata);
385
+ const cdecu = new Uint8Array(cdec);
386
+ const nmessage = utils.decode(cdecu);
552
387
  this._onMessage(nmessage);
553
388
  } catch (error) {
554
389
  this.error("Error decoding chunks:", error);
@@ -559,13 +394,13 @@ var TopazCubeClient = class {
559
394
  }
560
395
  } else if (message.c == "fpatch") {
561
396
  time = Date.now();
562
- let name = message.n;
397
+ const name = message.n;
563
398
  let doPatch = true;
564
399
  if (!this._lastUpdateId[name]) {
565
400
  this._lastUpdateId[name] = message.u;
566
401
  } else {
567
402
  if (this._lastUpdateId[name] < message.u) {
568
- let lp = message.u - this._lastUpdateId[name] - 1;
403
+ const lp = message.u - this._lastUpdateId[name] - 1;
569
404
  if (lp > 0) {
570
405
  this.warn("Lost " + lp + " updates");
571
406
  }
@@ -581,9 +416,9 @@ var TopazCubeClient = class {
581
416
  } else if (message.c == "pong") {
582
417
  this.ID = message.ID;
583
418
  time = Date.now();
584
- let lastct = message.ct;
585
- let ping = time - lastct;
586
- let stime = message.t;
419
+ const lastct = message.ct;
420
+ const ping = time - lastct;
421
+ const stime = message.t;
587
422
  this.send({ c: "peng", ct: Date.now(), st: stime });
588
423
  this.stats.stdiff = stime + ping / 2 - time;
589
424
  this.stats.ping = ping;
@@ -601,7 +436,7 @@ var TopazCubeClient = class {
601
436
  await this._peerConnection.setRemoteDescription(sessionDesc);
602
437
  }
603
438
  this.log("RTC: Remote description set successfully");
604
- for (let candidate of this._remoteCandidates) {
439
+ for (const candidate of this._remoteCandidates) {
605
440
  try {
606
441
  await this._peerConnection?.addIceCandidate(candidate);
607
442
  this.log("RTC: Added remote ICE candidate:", candidate);
@@ -634,15 +469,15 @@ var TopazCubeClient = class {
634
469
  if (!this._documentChanges[name]) {
635
470
  this._documentChanges[name] = [];
636
471
  }
637
- this._documentChanges[name].push(opmsg(op, target, path, value));
472
+ this._documentChanges[name].push(utils.opmsg(op, target, path, value));
638
473
  }
639
474
  _sendPatches() {
640
- for (let name in this._documentChanges) {
641
- let dc = this._documentChanges[name];
475
+ for (const name in this._documentChanges) {
476
+ const dc = this._documentChanges[name];
642
477
  if (!dc || dc.length == 0) {
643
478
  continue;
644
479
  }
645
- let record = {
480
+ const record = {
646
481
  n: name,
647
482
  c: "sync",
648
483
  ct: Date.now(),
@@ -659,17 +494,17 @@ var TopazCubeClient = class {
659
494
  }
660
495
  }
661
496
  _decodeFastChanges(message) {
662
- let time = Date.now();
663
- let name = message.n;
664
- let fdata = message.fdata;
497
+ const time = Date.now();
498
+ const name = message.n;
499
+ const fdata = message.fdata;
665
500
  if (!fdata) {
666
501
  return;
667
502
  }
668
- let doc = this.documents[name];
503
+ const doc = this.documents[name];
669
504
  if (!doc) {
670
505
  return;
671
506
  }
672
- let entities = doc.entities;
507
+ const entities = doc.entities;
673
508
  if (!entities) {
674
509
  return;
675
510
  }
@@ -677,34 +512,34 @@ var TopazCubeClient = class {
677
512
  if (!origin) {
678
513
  origin = [0, 0, 0];
679
514
  }
680
- for (let key in fdata) {
681
- let changes = fdata[key];
515
+ for (const key in fdata) {
516
+ const changes = fdata[key];
682
517
  if (changes.dict) {
683
- let pdata = changes.pdata;
684
- let dict = changes.dict;
685
- let rdict = {};
686
- for (let key2 in dict) {
518
+ const pdata = changes.pdata;
519
+ const dict = changes.dict;
520
+ const rdict = {};
521
+ for (const key2 in dict) {
687
522
  rdict[dict[key2]] = key2;
688
523
  }
689
524
  let offset = 0;
690
525
  while (offset < pdata.byteLength) {
691
- let id = "" + decode_uint32(pdata, offset);
526
+ const id = "" + utils.decode_uint32(pdata, offset);
692
527
  offset += 4;
693
- let did = "" + decode_uint32(pdata, offset);
528
+ const did = "" + utils.decode_uint32(pdata, offset);
694
529
  offset += 4;
695
- let e = entities[id];
530
+ const e = entities[id];
696
531
  if (!e) {
697
532
  continue;
698
533
  }
699
- let value = rdict[did];
534
+ const value = rdict[did];
700
535
  e[key] = value;
701
536
  e["_changed_" + key] = time;
702
537
  }
703
538
  } else {
704
- let pdata = changes.pdata;
539
+ const pdata = changes.pdata;
705
540
  let offset = 0;
706
541
  while (offset < pdata.byteLength) {
707
- let id = "" + decode_uint32(pdata, offset);
542
+ const id = "" + utils.decode_uint32(pdata, offset);
708
543
  let e = entities[id];
709
544
  if (!e) {
710
545
  if (key == "position") {
@@ -728,11 +563,11 @@ var TopazCubeClient = class {
728
563
  e._lpostime1 = e._lpostime2;
729
564
  }
730
565
  e._lpostime2 = time;
731
- e._lpos2[0] = origin[0] + decode_fp168(pdata, offset);
566
+ e._lpos2[0] = origin[0] + utils.decode_fp168(pdata, offset);
732
567
  offset += 3;
733
- e._lpos2[1] = origin[1] + decode_fp168(pdata, offset);
568
+ e._lpos2[1] = origin[1] + utils.decode_fp168(pdata, offset);
734
569
  offset += 3;
735
- e._lpos2[2] = origin[2] + decode_fp168(pdata, offset);
570
+ e._lpos2[2] = origin[2] + utils.decode_fp168(pdata, offset);
736
571
  offset += 3;
737
572
  if (!e.position) {
738
573
  e.position = [
@@ -753,15 +588,15 @@ var TopazCubeClient = class {
753
588
  e._lrottime1 = e._lrottime2;
754
589
  }
755
590
  e._lrottime2 = time;
756
- e._lrot2[0] = decode_fp412(pdata, offset);
591
+ e._lrot2[0] = utils.decode_fp412(pdata, offset);
757
592
  offset += 2;
758
- e._lrot2[1] = decode_fp412(pdata, offset);
593
+ e._lrot2[1] = utils.decode_fp412(pdata, offset);
759
594
  offset += 2;
760
- e._lrot2[2] = decode_fp412(pdata, offset);
595
+ e._lrot2[2] = utils.decode_fp412(pdata, offset);
761
596
  offset += 2;
762
- e._lrot2[3] = decode_fp412(pdata, offset);
597
+ e._lrot2[3] = utils.decode_fp412(pdata, offset);
763
598
  offset += 2;
764
- import_gl_matrix.quat.normalize(e._lrot2, e._lrot2);
599
+ glMatrix.quat.normalize(e._lrot2, e._lrot2);
765
600
  if (!e.rotation) {
766
601
  e.rotation = [
767
602
  e._lrot2[0],
@@ -781,11 +616,11 @@ var TopazCubeClient = class {
781
616
  e._lscatime1 = e._lscatime2;
782
617
  }
783
618
  e._lscatime2 = time;
784
- e._lsca2[0] = decode_fp1616(pdata, offset);
619
+ e._lsca2[0] = utils.decode_fp1616(pdata, offset);
785
620
  offset += 4;
786
- e._lsca2[1] = decode_fp1616(pdata, offset);
621
+ e._lsca2[1] = utils.decode_fp1616(pdata, offset);
787
622
  offset += 4;
788
- e._lsca2[2] = decode_fp1616(pdata, offset);
623
+ e._lsca2[2] = utils.decode_fp1616(pdata, offset);
789
624
  offset += 4;
790
625
  if (!e.sca) {
791
626
  e.sca = [
@@ -799,10 +634,9 @@ var TopazCubeClient = class {
799
634
  }
800
635
  }
801
636
  }
802
- /*= WEBRTC ===================================================================*/
803
637
  sendRTC(message) {
804
638
  if (this._dataChannel && this._dataChannel.readyState === "open") {
805
- this._dataChannel.send(encode(message));
639
+ this._dataChannel.send(utils.encode(message));
806
640
  }
807
641
  }
808
642
  _onRTCConnect() {
@@ -815,10 +649,10 @@ var TopazCubeClient = class {
815
649
  }
816
650
  async _onRTCMessage(data) {
817
651
  this.stats.recRTC += data.byteLength;
818
- let datau = new Uint8Array(data);
819
- let dec = await decompress(datau);
820
- let decu = new Uint8Array(dec);
821
- let message = decode(decu);
652
+ const datau = new Uint8Array(data);
653
+ const dec = await decompress(datau);
654
+ const decu = new Uint8Array(dec);
655
+ const message = utils.decode(decu);
822
656
  this._onMessage(message);
823
657
  }
824
658
  async _initializeWebRTC() {
@@ -854,7 +688,7 @@ var TopazCubeClient = class {
854
688
  this._peerConnection.onicegatheringstatechange = () => {
855
689
  this.log(`RTC: ICE gathering state. _candidates:`, this._candidates.length, this._peerConnection?.iceGatheringState);
856
690
  if (this._peerConnection?.iceGatheringState == "complete" && this._offerSent) {
857
- for (let candidate of this._candidates) {
691
+ for (const candidate of this._candidates) {
858
692
  this.send({
859
693
  c: "rtc-candidate",
860
694
  type: "ice-candidate",
@@ -904,7 +738,7 @@ var TopazCubeClient = class {
904
738
  const offer = await this._peerConnection.createOffer(offerOptions);
905
739
  await this._peerConnection.setLocalDescription(offer);
906
740
  await new Promise((resolve) => setTimeout(resolve, 100));
907
- let ld = this._peerConnection.localDescription;
741
+ const ld = this._peerConnection.localDescription;
908
742
  if (ld) {
909
743
  const offerPayload = {
910
744
  c: "rtc-offer",
@@ -926,7 +760,6 @@ var TopazCubeClient = class {
926
760
  this.error("RTC: error:", error);
927
761
  }
928
762
  }
929
- // Add this method to restart ICE if needed
930
763
  async _restartIce() {
931
764
  try {
932
765
  const offerOptions = {
@@ -959,5 +792,6 @@ var TopazCubeClient = class {
959
792
  }
960
793
  this._webRTCConnected = false;
961
794
  }
962
- };
963
- //# sourceMappingURL=client.cjs.map
795
+ }
796
+ module.exports = TopazCubeClient;
797
+ //# sourceMappingURL=client.cjs.map