phoria2 1.1.0 → 1.3.0

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 (81) hide show
  1. package/README.md +70 -13
  2. package/dist/bloom.js +4 -4
  3. package/dist/bloom.js.map +1 -1
  4. package/dist/charts.js +538 -508
  5. package/dist/charts.js.map +1 -1
  6. package/dist/core.js +4270 -3652
  7. package/dist/core.js.map +1 -1
  8. package/dist/edit.js +65 -65
  9. package/dist/edit.js.map +1 -1
  10. package/dist/explain.js +6 -2
  11. package/dist/explain.js.map +1 -1
  12. package/dist/gltf.js +116 -116
  13. package/dist/gltf.js.map +1 -1
  14. package/dist/keyboard.js +188 -0
  15. package/dist/keyboard.js.map +1 -0
  16. package/dist/motion.js +35 -35
  17. package/dist/motion.js.map +1 -1
  18. package/dist/particles.js +188 -115
  19. package/dist/particles.js.map +1 -1
  20. package/dist/passes.js +29 -29
  21. package/dist/passes.js.map +1 -1
  22. package/dist/phoria2.js +1 -1
  23. package/dist/picking.js +32 -16
  24. package/dist/picking.js.map +1 -1
  25. package/dist/snapshot.js +1 -1
  26. package/dist/tooltip.js +1 -1
  27. package/dist/types/OrbitControl.d.ts +6 -2
  28. package/dist/types/Raycaster.d.ts +10 -0
  29. package/dist/types/View.d.ts +70 -1
  30. package/dist/types/area.d.ts +18 -0
  31. package/dist/types/charts/Chart.d.ts +7 -0
  32. package/dist/types/explain.d.ts +3 -0
  33. package/dist/types/frame.d.ts +7 -0
  34. package/dist/types/geometry/Geometry.d.ts +24 -2
  35. package/dist/types/index.d.ts +2 -0
  36. package/dist/types/keyboard.d.ts +48 -0
  37. package/dist/types/labels.d.ts +4 -0
  38. package/dist/types/material/Material.d.ts +15 -0
  39. package/dist/types/material/Texture.d.ts +18 -2
  40. package/dist/types/particles/Emitter.d.ts +39 -2
  41. package/dist/types/scene/Node.d.ts +19 -14
  42. package/dist/types/scene/drawables.d.ts +54 -15
  43. package/dist/types/scene/lights.d.ts +16 -2
  44. package/dist/types/shadow.d.ts +2 -1
  45. package/dist/types/types.d.ts +14 -0
  46. package/dist/types/value/Color.d.ts +0 -4
  47. package/dist/types/value/Quat.d.ts +4 -2
  48. package/dist/types/webgl/resources.d.ts +12 -2
  49. package/dist/types/webgl/shaders.d.ts +7 -2
  50. package/llms-full.txt +106 -10
  51. package/package.json +4 -1
  52. package/schema/scene.schema.json +67 -1
  53. package/src/OrbitControl.js +7 -3
  54. package/src/Raycaster.js +58 -0
  55. package/src/View.js +220 -41
  56. package/src/area.js +131 -0
  57. package/src/charts/Chart.js +20 -2
  58. package/src/charts/marks.js +29 -2
  59. package/src/explain.js +6 -2
  60. package/src/frame.js +29 -9
  61. package/src/geometry/Geometry.js +32 -4
  62. package/src/index.js +1 -0
  63. package/src/keyboard.js +298 -0
  64. package/src/labels.js +4 -1
  65. package/src/material/Material.js +9 -2
  66. package/src/material/Texture.js +55 -2
  67. package/src/particles/Emitter.js +121 -10
  68. package/src/scene/Node.js +20 -9
  69. package/src/scene/Scene.js +2 -0
  70. package/src/scene/cameras.js +4 -1
  71. package/src/scene/drawables.js +115 -15
  72. package/src/scene/lights.js +40 -6
  73. package/src/shadow.js +27 -4
  74. package/src/types.js +6 -0
  75. package/src/value/Color.js +21 -0
  76. package/src/value/Quat.js +15 -6
  77. package/src/watch.js +14 -2
  78. package/src/webgl/WebGLRenderer.js +36 -5
  79. package/src/webgl/picking.js +22 -1
  80. package/src/webgl/resources.js +168 -14
  81. package/src/webgl/shaders.js +110 -11
package/dist/gltf.js CHANGED
@@ -1,4 +1,4 @@
1
- import { B as e, C as t, L as n, R as r, S as i, U as a, W as o, ct as s, ft as c, jt as l, nt as u, q as d, rt as f, tt as p, ut as m, w as h, wt as g, y as _ } from "./core.js";
1
+ import { $ as e, F as t, G as n, I as r, K as i, M as a, Mt as o, Tt as s, X as c, dt as l, et as u, ht as d, lt as f, ot as p, pt as m, rt as h, st as g, tt as _ } from "./core.js";
2
2
  // src/gltf/Animation.js
3
3
  var v = class {
4
4
  name;
@@ -37,9 +37,9 @@ var v = class {
37
37
  }
38
38
  }, y = /* @__PURE__ */ new Float32Array(4);
39
39
  function b(e, t) {
40
- let { times: n, values: r, node: i, path: a, interpolation: o } = e, s = a === "quaternion" ? 4 : 3, l = o === "CUBICSPLINE", u = l ? s * 3 : s, d = (e) => l ? e * u + s : e * u, f = n.length - 1, p = y;
41
- if (t <= n[0] || f === 0) for (let e = 0; e < s; e++) p[e] = r[d(0) + e];
42
- else if (t >= n[f]) for (let e = 0; e < s; e++) p[e] = r[d(f) + e];
40
+ let { times: n, values: r, node: i, path: a, interpolation: o } = e, s = a === "quaternion" ? 4 : 3, c = o === "CUBICSPLINE", l = c ? s * 3 : s, u = (e) => c ? e * l + s : e * l, f = n.length - 1, p = y;
41
+ if (t <= n[0] || f === 0) for (let e = 0; e < s; e++) p[e] = r[u(0) + e];
42
+ else if (t >= n[f]) for (let e = 0; e < s; e++) p[e] = r[u(f) + e];
43
43
  else {
44
44
  let e = 0, i = f;
45
45
  for (; i - e > 1;) {
@@ -47,12 +47,12 @@ function b(e, t) {
47
47
  n[r] <= t ? e = r : i = r;
48
48
  }
49
49
  let a = n[e], h = n[i] - a, g = h > 0 ? (t - a) / h : 0;
50
- if (o === "STEP") for (let t = 0; t < s; t++) p[t] = r[d(e) + t];
51
- else if (l) {
52
- let t = g * g, n = t * g, a = 2 * n - 3 * t + 1, o = n - 2 * t + g, c = -2 * n + 3 * t, l = n - t, d = e * u, f = i * u;
53
- for (let e = 0; e < s; e++) p[e] = a * r[d + s + e] + o * h * r[d + s * 2 + e] + c * r[f + s + e] + l * h * r[f + e];
50
+ if (o === "STEP") for (let t = 0; t < s; t++) p[t] = r[u(e) + t];
51
+ else if (c) {
52
+ let t = g * g, n = t * g, a = 2 * n - 3 * t + 1, o = n - 2 * t + g, c = -2 * n + 3 * t, u = n - t, d = e * l, f = i * l;
53
+ for (let e = 0; e < s; e++) p[e] = a * r[d + s + e] + o * h * r[d + s * 2 + e] + c * r[f + s + e] + u * h * r[f + e];
54
54
  s === 4 && m(p, p);
55
- } else if (s === 4) c(p, r.subarray(e * 4, e * 4 + 4), r.subarray(i * 4, i * 4 + 4), g);
55
+ } else if (s === 4) d(p, r.subarray(e * 4, e * 4 + 4), r.subarray(i * 4, i * 4 + 4), g);
56
56
  else for (let t = 0; t < 3; t++) p[t] = r[e * 3 + t] + (r[i * 3 + t] - r[e * 3 + t]) * g;
57
57
  }
58
58
  a === "quaternion" ? i.quaternion.set(p[0], p[1], p[2], p[3]) : i[a].set(p[0], p[1], p[2]);
@@ -100,18 +100,18 @@ var x = /* @__PURE__ */ new Set([
100
100
  33071: "clamp",
101
101
  33648: "mirror",
102
102
  10497: "repeat"
103
- }, D = class extends f {
103
+ }, D = class extends h {
104
104
  static type = "model";
105
105
  animations = [];
106
106
  cameras = [];
107
107
  get meshes() {
108
- return this.findAll((e) => e instanceof _);
108
+ return this.findAll((e) => e instanceof c);
109
109
  }
110
110
  play(e = 0) {
111
111
  let t = typeof e == "number" ? this.animations[e] : this.animations.find((t) => t.name === e);
112
112
  if (!t) {
113
113
  let t = this.animations.map((e) => `'${e.name}'`).join(", ");
114
- return l(this, `no animation ${typeof e == "number" ? e : `'${e}'`} - this model has ${t || "none"}`), null;
114
+ return o(this, `no animation ${typeof e == "number" ? e : `'${e}'`} - this model has ${t || "none"}`), null;
115
115
  }
116
116
  return t.play();
117
117
  }
@@ -124,9 +124,9 @@ var x = /* @__PURE__ */ new Set([
124
124
  };
125
125
  async function O(e, t = {}) {
126
126
  let n = await fetch(e).catch((t) => {
127
- throw new g(`loadGLTF: couldn't fetch '${e}' - ${t.message}`);
127
+ throw new s(`loadGLTF: couldn't fetch '${e}' - ${t.message}`);
128
128
  });
129
- if (!n.ok) throw new g(`loadGLTF: couldn't fetch '${e}' (${n.status} ${n.statusText})`);
129
+ if (!n.ok) throw new s(`loadGLTF: couldn't fetch '${e}' (${n.status} ${n.statusText})`);
130
130
  let r = t.baseUrl ?? new URL(e, globalThis.location?.href ?? "file:///").href;
131
131
  return k(await n.arrayBuffer(), {
132
132
  ...t,
@@ -135,18 +135,18 @@ async function O(e, t = {}) {
135
135
  }
136
136
  async function k(e, t = {}) {
137
137
  let { json: n, bin: r } = A(e), i = String(n.asset?.version ?? "");
138
- if (!i.startsWith("2.")) throw new g(`loadGLTF: glTF ${i || "(no version)"} isn't supported - only glTF 2.0`);
138
+ if (!i.startsWith("2.")) throw new s(`loadGLTF: glTF ${i || "(no version)"} isn't supported - only glTF 2.0`);
139
139
  for (let e of n.extensionsRequired ?? []) {
140
140
  if (x.has(e)) continue;
141
141
  let t = S.has(e) ? " - export the model without compression for now" : "";
142
- throw new g(`loadGLTF: the model requires '${e}', which isn't supported${t}`);
142
+ throw new s(`loadGLTF: the model requires '${e}', which isn't supported${t}`);
143
143
  }
144
144
  let a = new D({ name: n.scenes?.[n.scene ?? 0]?.name ?? "model" });
145
- for (let e of n.extensionsUsed ?? []) x.has(e) || l(a, `the model uses '${e}', which isn't supported - it is ignored`);
146
- let o = new j(n, r, t.baseUrl ?? "", a);
147
- await o.buffers(), o.scene();
148
- let s = o.textures();
149
- return (t.waitForTextures ?? !0) && await s, a;
145
+ for (let e of n.extensionsUsed ?? []) x.has(e) || o(a, `the model uses '${e}', which isn't supported - it is ignored`);
146
+ let c = new j(n, r, t.baseUrl ?? "", a);
147
+ await c.buffers(), c.scene();
148
+ let l = c.textures();
149
+ return (t.waitForTextures ?? !0) && await l, a;
150
150
  }
151
151
  function A(e) {
152
152
  if (typeof e == "string") return {
@@ -164,7 +164,7 @@ function A(e) {
164
164
  let a = n.getUint32(i, !0), o = n.getUint32(i + 4, !0), s = t.subarray(i + 8, i + 8 + a);
165
165
  o === 1313821514 ? e = JSON.parse(new TextDecoder().decode(s)) : o === 5130562 && (r = s), i += 8 + a;
166
166
  }
167
- if (!e) throw new g("loadGLTF: the .glb file has no JSON chunk");
167
+ if (!e) throw new s("loadGLTF: the .glb file has no JSON chunk");
168
168
  return {
169
169
  json: e,
170
170
  bin: r
@@ -195,18 +195,18 @@ var j = class {
195
195
  async buffers() {
196
196
  this.#e = await Promise.all((this.json.buffers ?? []).map(async (e, t) => {
197
197
  if (e.uri === void 0) {
198
- if (t !== 0 || !this.bin) throw new g(`loadGLTF: buffer ${t} has no uri and there is no binary chunk`);
198
+ if (t !== 0 || !this.bin) throw new s(`loadGLTF: buffer ${t} has no uri and there is no binary chunk`);
199
199
  return this.bin;
200
200
  }
201
201
  let n = this.#o(e.uri), r = await fetch(n).catch((t) => {
202
- throw new g(`loadGLTF: couldn't fetch buffer '${e.uri}' - ${t.message}`);
202
+ throw new s(`loadGLTF: couldn't fetch buffer '${e.uri}' - ${t.message}`);
203
203
  });
204
- if (!r.ok) throw new g(`loadGLTF: couldn't fetch buffer '${e.uri}' (${r.status})`);
204
+ if (!r.ok) throw new s(`loadGLTF: couldn't fetch buffer '${e.uri}' (${r.status})`);
205
205
  return new Uint8Array(await r.arrayBuffer());
206
206
  }));
207
207
  }
208
208
  async textures() {
209
- await Promise.all([...this.#t.values()].map((e) => e.ready.catch((e) => l(this.model, e.message))));
209
+ await Promise.all([...this.#t.values()].map((e) => e.ready.catch((e) => o(this.model, e.message))));
210
210
  for (let e of this.#a) URL.revokeObjectURL(e);
211
211
  }
212
212
  scene() {
@@ -225,8 +225,8 @@ var j = class {
225
225
  }
226
226
  #s(e) {
227
227
  let t = this.json.nodes[e], n = t.name ?? `node ${e}`;
228
- t.skin !== void 0 && l(this.model, `skinned meshes aren't supported - '${n}' is drawn in its bind pose`), (t.weights || t.mesh !== void 0 && this.json.meshes[t.mesh].weights) && l(this.model, "morph targets aren't supported - meshes are drawn without them");
229
- let r = t.mesh === void 0 ? [] : this.#c(t.mesh), i = r.length === 1 ? r[0] : new f();
228
+ t.skin !== void 0 && o(this.model, `skinned meshes aren't supported - '${n}' is drawn in its bind pose`), (t.weights || t.mesh !== void 0 && this.json.meshes[t.mesh].weights) && o(this.model, "morph targets aren't supported - meshes are drawn without them");
229
+ let r = t.mesh === void 0 ? [] : this.#c(t.mesh), i = r.length === 1 ? r[0] : new h();
230
230
  for (let e of r.length > 1 ? r : []) i.add(e);
231
231
  if (i.name = n, t.matrix ? M(i, t.matrix) : (t.translation && i.position.set(t.translation[0], t.translation[1], t.translation[2]), t.rotation && i.quaternion.set(t.rotation[0], t.rotation[1], t.rotation[2], t.rotation[3]), t.scale && i.scale.set(t.scale[0], t.scale[1], t.scale[2])), t.camera !== void 0) {
232
232
  let e = this.#h(t.camera);
@@ -235,31 +235,31 @@ var j = class {
235
235
  let a = t.extensions?.KHR_lights_punctual?.light;
236
236
  return a !== void 0 && i.add(this.#g(a)), t.extras && typeof t.extras == "object" && (i.userData = { ...t.extras }), i;
237
237
  }
238
- #c(e) {
239
- let n = this.json.meshes[e];
240
- return n.primitives.map((r, a) => {
241
- let o = this.#l(r), s = r.material === void 0 ? this.#p() : this.#f(r.material), c = r.mode ?? 4, l;
242
- return l = c === 0 ? new h({
243
- geometry: o,
244
- material: P(s)
245
- }) : c === 1 || c === 2 || c === 3 ? new i({
246
- geometry: I(o, c),
247
- material: P(s)
248
- }) : new t({
249
- geometry: c === 4 ? o : F(o, c),
250
- material: s
251
- }), l.name = n.primitives.length > 1 ? `${n.name ?? `mesh ${e}`} ${a}` : n.name ?? `mesh ${e}`, l;
238
+ #c(t) {
239
+ let n = this.json.meshes[t];
240
+ return n.primitives.map((r, i) => {
241
+ let a = this.#l(r), o = r.material === void 0 ? this.#p() : this.#f(r.material), s = r.mode ?? 4, c;
242
+ return c = s === 0 ? new _({
243
+ geometry: a,
244
+ material: P(o)
245
+ }) : s === 1 || s === 2 || s === 3 ? new e({
246
+ geometry: I(a, s),
247
+ material: P(o)
248
+ }) : new u({
249
+ geometry: s === 4 ? a : F(a, s),
250
+ material: o
251
+ }), c.name = n.primitives.length > 1 ? `${n.name ?? `mesh ${t}`} ${i}` : n.name ?? `mesh ${t}`, c;
252
252
  });
253
253
  }
254
254
  #l(e) {
255
255
  let t = JSON.stringify([e.attributes, e.indices]), n = this.#r.get(t);
256
256
  if (n) return n;
257
- let i = e.attributes;
258
- if (i.POSITION === void 0) throw new g("loadGLTF: a mesh primitive has no POSITION");
259
- let a = { positions: this.#u(i.POSITION) };
260
- i.NORMAL !== void 0 && (a.normals = this.#u(i.NORMAL)), i.TEXCOORD_0 !== void 0 && (a.uvs = this.#u(i.TEXCOORD_0)), i.TEXCOORD_1 !== void 0 && (a.uvs2 = this.#u(i.TEXCOORD_1)), i.COLOR_0 !== void 0 && (a.colors = N(this.#u(i.COLOR_0), C[this.json.accessors[i.COLOR_0].type])), e.indices !== void 0 && (a.indices = this.#u(e.indices, !0));
261
- let o = new r(a);
262
- return this.#r.set(t, o), o;
257
+ let r = e.attributes;
258
+ if (r.POSITION === void 0) throw new s("loadGLTF: a mesh primitive has no POSITION");
259
+ let i = { positions: this.#u(r.POSITION) };
260
+ r.NORMAL !== void 0 && (i.normals = this.#u(r.NORMAL)), r.TEXCOORD_0 !== void 0 && (i.uvs = this.#u(r.TEXCOORD_0)), r.TEXCOORD_1 !== void 0 && (i.uvs2 = this.#u(r.TEXCOORD_1)), r.COLOR_0 !== void 0 && (i.colors = N(this.#u(r.COLOR_0), C[this.json.accessors[r.COLOR_0].type])), e.indices !== void 0 && (i.indices = this.#u(e.indices, !0));
261
+ let a = new f(i);
262
+ return this.#r.set(t, a), a;
263
263
  }
264
264
  #u(e, t = !1) {
265
265
  let n = this.json.accessors[e], r = C[n.type], i = n.count * r, a = t ? new Uint32Array(i) : new Float32Array(i), o = n.normalized && !t ? 1 / T[n.componentType] : 1;
@@ -274,66 +274,66 @@ var j = class {
274
274
  return a;
275
275
  }
276
276
  #d(e, t, n, r, i, a, o) {
277
- let s = this.json.bufferViews[e], c = this.#e[s.buffer], l = w[n];
278
- if (!l) throw new g(`loadGLTF: unknown component type ${n}`);
279
- let u = l.BYTES_PER_ELEMENT, d = s.byteStride || r * u, f = c.byteOffset + (s.byteOffset ?? 0) + t, p = new DataView(c.buffer), m = {
280
- 5120: (e) => p.getInt8(e),
281
- 5121: (e) => p.getUint8(e),
282
- 5122: (e) => p.getInt16(e, !0),
283
- 5123: (e) => p.getUint16(e, !0),
284
- 5125: (e) => p.getUint32(e, !0),
285
- 5126: (e) => p.getFloat32(e, !0)
277
+ let c = this.json.bufferViews[e], l = this.#e[c.buffer], u = w[n];
278
+ if (!u) throw new s(`loadGLTF: unknown component type ${n}`);
279
+ let d = u.BYTES_PER_ELEMENT, f = c.byteStride || r * d, p = l.byteOffset + (c.byteOffset ?? 0) + t, m = new DataView(l.buffer), h = {
280
+ 5120: (e) => m.getInt8(e),
281
+ 5121: (e) => m.getUint8(e),
282
+ 5122: (e) => m.getInt16(e, !0),
283
+ 5123: (e) => m.getUint16(e, !0),
284
+ 5125: (e) => m.getUint32(e, !0),
285
+ 5126: (e) => m.getFloat32(e, !0)
286
286
  }[n];
287
- if (n === 5126 && d === r * 4 && f % 4 == 0 && o === 1 && a instanceof Float32Array) a.set(new Float32Array(c.buffer, f, i * r));
288
- else for (let e = 0; e < i; e++) for (let t = 0; t < r; t++) a[e * r + t] = m(f + e * d + t * u) * o;
287
+ if (n === 5126 && f === r * 4 && p % 4 == 0 && o === 1 && a instanceof Float32Array) a.set(new Float32Array(l.buffer, p, i * r));
288
+ else for (let e = 0; e < i; e++) for (let t = 0; t < r; t++) a[e * r + t] = h(p + e * f + t * d) * o;
289
289
  }
290
290
  #f(e) {
291
291
  let t = this.#n.get(e);
292
292
  if (t) return t;
293
- let r = this.json.materials[e], i = r.pbrMetallicRoughness ?? {}, a = new n({ name: r.name ?? `material ${e}` }), o = i.baseColorFactor ?? [
293
+ let n = this.json.materials[e], r = n.pbrMetallicRoughness ?? {}, i = new p({ name: n.name ?? `material ${e}` }), a = r.baseColorFactor ?? [
294
294
  1,
295
295
  1,
296
296
  1,
297
297
  1
298
298
  ];
299
- a.color.setLinear(o[0], o[1], o[2]), a.metalness = i.metallicFactor ?? 1, a.roughness = i.roughnessFactor ?? 1, i.baseColorTexture && (a.map = this.#m(i.baseColorTexture, "srgb")), i.metallicRoughnessTexture && (a.roughnessMap = a.metalnessMap = this.#m(i.metallicRoughnessTexture, "linear")), r.normalTexture && (a.normalMap = this.#m(r.normalTexture, "linear"), a.normalScale = r.normalTexture.scale ?? 1), r.occlusionTexture && (a.aoMap = this.#m(r.occlusionTexture, "linear"), a.aoMapIntensity = Math.min(Math.max(r.occlusionTexture.strength ?? 1, 0), 1)), r.emissiveFactor && a.emissive.setLinear(r.emissiveFactor[0], r.emissiveFactor[1], r.emissiveFactor[2]), r.emissiveTexture && (a.emissiveMap = this.#m(r.emissiveTexture, "srgb"), r.emissiveFactor || a.emissive.setLinear(1, 1, 1)), a.emissiveIntensity = r.extensions?.KHR_materials_emissive_strength?.emissiveStrength ?? 1, r.extensions?.KHR_materials_unlit && (a.unlit = !0);
300
- let s = (e) => Math.min(Math.max(e, 0), 1), c = r.extensions ?? {}, l = c.KHR_materials_transmission, u = c.KHR_materials_clearcoat, d = c.KHR_materials_sheen;
301
- if (l && (a.transmission = s(l.transmissionFactor ?? 0)), u && (a.clearcoat = s(u.clearcoatFactor ?? 0), a.clearcoatRoughness = s(u.clearcoatRoughnessFactor ?? 0)), d) {
302
- let e = d.sheenColorFactor ?? [
299
+ i.color.setLinear(a[0], a[1], a[2]), i.metalness = r.metallicFactor ?? 1, i.roughness = r.roughnessFactor ?? 1, r.baseColorTexture && (i.map = this.#m(r.baseColorTexture, "srgb")), r.metallicRoughnessTexture && (i.roughnessMap = i.metalnessMap = this.#m(r.metallicRoughnessTexture, "linear")), n.normalTexture && (i.normalMap = this.#m(n.normalTexture, "linear"), i.normalScale = n.normalTexture.scale ?? 1), n.occlusionTexture && (i.aoMap = this.#m(n.occlusionTexture, "linear"), i.aoMapIntensity = Math.min(Math.max(n.occlusionTexture.strength ?? 1, 0), 1)), n.emissiveFactor && i.emissive.setLinear(n.emissiveFactor[0], n.emissiveFactor[1], n.emissiveFactor[2]), n.emissiveTexture && (i.emissiveMap = this.#m(n.emissiveTexture, "srgb"), n.emissiveFactor || i.emissive.setLinear(1, 1, 1)), i.emissiveIntensity = n.extensions?.KHR_materials_emissive_strength?.emissiveStrength ?? 1, n.extensions?.KHR_materials_unlit && (i.unlit = !0);
300
+ let o = (e) => Math.min(Math.max(e, 0), 1), s = n.extensions ?? {}, c = s.KHR_materials_transmission, l = s.KHR_materials_clearcoat, u = s.KHR_materials_sheen;
301
+ if (c && (i.transmission = o(c.transmissionFactor ?? 0)), l && (i.clearcoat = o(l.clearcoatFactor ?? 0), i.clearcoatRoughness = o(l.clearcoatRoughnessFactor ?? 0)), u) {
302
+ let e = u.sheenColorFactor ?? [
303
303
  0,
304
304
  0,
305
305
  0
306
306
  ];
307
- Math.max(e[0], e[1], e[2]) > 0 && (a.sheen = 1, a.sheenColor.setLinear(e[0], e[1], e[2])), a.sheenRoughness = s(d.sheenRoughnessFactor ?? 0);
307
+ Math.max(e[0], e[1], e[2]) > 0 && (i.sheen = 1, i.sheenColor.setLinear(e[0], e[1], e[2])), i.sheenRoughness = o(u.sheenRoughnessFactor ?? 0);
308
308
  }
309
- c.KHR_materials_ior?.ior >= 1 && (a.ior = c.KHR_materials_ior.ior);
310
- let f = c.KHR_materials_specular;
311
- if (f) {
312
- a.specularIntensity = s(f.specularFactor ?? 1);
313
- let e = f.specularColorFactor ?? [
309
+ s.KHR_materials_ior?.ior >= 1 && (i.ior = s.KHR_materials_ior.ior);
310
+ let d = s.KHR_materials_specular;
311
+ if (d) {
312
+ i.specularIntensity = o(d.specularFactor ?? 1);
313
+ let e = d.specularColorFactor ?? [
314
314
  1,
315
315
  1,
316
316
  1
317
317
  ];
318
- a.specularColor.setLinear(e[0], e[1], e[2]);
318
+ i.specularColor.setLinear(e[0], e[1], e[2]);
319
319
  }
320
- let p = c.KHR_materials_anisotropy;
321
- p && (a.anisotropy = s(p.anisotropyStrength ?? 0), a.anisotropyRotation = p.anisotropyRotation ?? 0);
322
- let m = c.KHR_materials_diffuse_transmission;
320
+ let f = s.KHR_materials_anisotropy;
321
+ f && (i.anisotropy = o(f.anisotropyStrength ?? 0), i.anisotropyRotation = f.anisotropyRotation ?? 0);
322
+ let m = s.KHR_materials_diffuse_transmission;
323
323
  if (m) {
324
- a.translucency = s(m.diffuseTransmissionFactor ?? 0);
324
+ i.translucency = o(m.diffuseTransmissionFactor ?? 0);
325
325
  let e = m.diffuseTransmissionColorFactor ?? [
326
326
  1,
327
327
  1,
328
328
  1
329
329
  ];
330
- a.translucencyColor.setLinear(e[0], e[1], e[2]);
330
+ i.translucencyColor.setLinear(e[0], e[1], e[2]);
331
331
  }
332
- return r.alphaMode === "BLEND" ? (a.opacity = o[3], a.transparent = !0, a.depthWrite = !1) : r.alphaMode === "MASK" && (a.alphaTest = r.alphaCutoff ?? .5), a.doubleSided = !!r.doubleSided, this.#n.set(e, a), a;
332
+ return n.alphaMode === "BLEND" ? (i.opacity = a[3], i.transparent = !0, i.depthWrite = !1) : n.alphaMode === "MASK" && (i.alphaTest = n.alphaCutoff ?? .5), i.doubleSided = !!n.doubleSided, this.#n.set(e, i), i;
333
333
  }
334
334
  #p() {
335
335
  let e = this.#n.get(-1);
336
- return e || this.#n.set(-1, e = new n({
336
+ return e || this.#n.set(-1, e = new p({
337
337
  name: "default",
338
338
  metalness: 1,
339
339
  roughness: 1
@@ -341,7 +341,7 @@ var j = class {
341
341
  }
342
342
  #m(e, t) {
343
343
  let n = e.extensions?.KHR_texture_transform, r = n?.texCoord ?? e.texCoord ?? 0;
344
- r > 1 && (l(this.model, `textures on a third UV set or later (TEXCOORD_${r}) are drawn with the first`), r = 0);
344
+ r > 1 && (o(this.model, `textures on a third UV set or later (TEXCOORD_${r}) are drawn with the first`), r = 0);
345
345
  let i = JSON.stringify([
346
346
  e.index,
347
347
  t,
@@ -351,18 +351,18 @@ var j = class {
351
351
  r
352
352
  ]), a = this.#t.get(i);
353
353
  if (a) return a;
354
- let o = this.json.textures[e.index], s = this.json.samplers?.[o.sampler] ?? {}, c = this.json.images[o.source];
355
- if (o.source === void 0 || !c) throw new g(`loadGLTF: texture ${e.index} has no image (compressed textures aren't supported)`);
356
- let u;
357
- if (c.bufferView !== void 0) {
358
- let e = this.json.bufferViews[c.bufferView], t = this.#e[e.buffer].subarray(e.byteOffset ?? 0, (e.byteOffset ?? 0) + e.byteLength);
359
- u = URL.createObjectURL(new Blob([t], { type: c.mimeType ?? "image/png" })), this.#a.push(u);
360
- } else u = this.#o(c.uri);
361
- let f = new d({
362
- url: u,
354
+ let c = this.json.textures[e.index], l = this.json.samplers?.[c.sampler] ?? {}, u = this.json.images[c.source];
355
+ if (c.source === void 0 || !u) throw new s(`loadGLTF: texture ${e.index} has no image (compressed textures aren't supported)`);
356
+ let d;
357
+ if (u.bufferView !== void 0) {
358
+ let e = this.json.bufferViews[u.bufferView], t = this.#e[e.buffer].subarray(e.byteOffset ?? 0, (e.byteOffset ?? 0) + e.byteLength);
359
+ d = URL.createObjectURL(new Blob([t], { type: u.mimeType ?? "image/png" })), this.#a.push(d);
360
+ } else d = this.#o(u.uri);
361
+ let f = new g({
362
+ url: d,
363
363
  colorSpace: t,
364
- wrap: E[s.wrapS ?? 10497] ?? "repeat",
365
- filter: s.magFilter === 9728 ? "nearest" : "linear",
364
+ wrap: E[l.wrapS ?? 10497] ?? "repeat",
365
+ filter: l.magFilter === 9728 ? "nearest" : "linear",
366
366
  flipY: !1,
367
367
  repeat: n?.scale ?? [1, 1],
368
368
  offset: n?.offset ?? [0, 0],
@@ -372,37 +372,37 @@ var j = class {
372
372
  return this.#t.set(i, f), f;
373
373
  }
374
374
  #h(e) {
375
- let t = this.json.cameras[e], n = t.name ?? `camera ${e}`;
375
+ let t = this.json.cameras[e], r = t.name ?? `camera ${e}`;
376
376
  if (t.type === "orthographic") {
377
377
  let e = t.orthographic;
378
- return new p({
379
- name: n,
378
+ return new n({
379
+ name: r,
380
380
  height: e.ymag * 2,
381
381
  near: e.znear,
382
382
  far: e.zfar
383
383
  });
384
384
  }
385
- let r = t.perspective;
386
- return new u({
387
- name: n,
388
- fov: r.yfov * 180 / Math.PI,
389
- near: r.znear,
390
- far: r.zfar ?? 1e6
385
+ let a = t.perspective;
386
+ return new i({
387
+ name: r,
388
+ fov: a.yfov * 180 / Math.PI,
389
+ near: a.znear,
390
+ far: a.zfar ?? 1e6
391
391
  });
392
392
  }
393
- #g(t) {
394
- let n = this.json.extensions?.KHR_lights_punctual?.lights?.[t];
395
- if (!n) throw new g(`loadGLTF: KHR_lights_punctual light ${t} doesn't exist`);
396
- let r = n.color ?? [
393
+ #g(e) {
394
+ let n = this.json.extensions?.KHR_lights_punctual?.lights?.[e];
395
+ if (!n) throw new s(`loadGLTF: KHR_lights_punctual light ${e} doesn't exist`);
396
+ let i = n.color ?? [
397
397
  1,
398
398
  1,
399
399
  1
400
- ], i = {
400
+ ], o = {
401
401
  name: n.name,
402
402
  intensity: (n.intensity ?? 1) / Math.PI
403
- }, s;
404
- if (n.type === "directional") s = new e({
405
- ...i,
403
+ }, c;
404
+ if (n.type === "directional") c = new a({
405
+ ...o,
406
406
  direction: [
407
407
  0,
408
408
  0,
@@ -411,8 +411,8 @@ var j = class {
411
411
  });
412
412
  else if (n.type === "spot") {
413
413
  let e = n.spot?.outerConeAngle ?? Math.PI / 4, t = n.spot?.innerConeAngle ?? 0;
414
- s = new o({
415
- ...i,
414
+ c = new r({
415
+ ...o,
416
416
  direction: [
417
417
  0,
418
418
  0,
@@ -422,11 +422,11 @@ var j = class {
422
422
  angle: e,
423
423
  penumbra: e > 0 ? 1 - t / e : 0
424
424
  });
425
- } else s = new a({
426
- ...i,
425
+ } else c = new t({
426
+ ...o,
427
427
  range: n.range ?? 0
428
428
  });
429
- return s.color.setLinear(r[0], r[1], r[2]), s;
429
+ return c.color.setLinear(i[0], i[1], i[2]), c;
430
430
  }
431
431
  #_(e, t) {
432
432
  let n = [];
@@ -437,7 +437,7 @@ var j = class {
437
437
  scale: "scale"
438
438
  }[t.target.path];
439
439
  if (!r) {
440
- l(this.model, `'${t.target.path}' animations aren't supported - only translation, rotation and scale`);
440
+ o(this.model, `'${t.target.path}' animations aren't supported - only translation, rotation and scale`);
441
441
  continue;
442
442
  }
443
443
  let i = this.#i[t.target.node];
@@ -472,7 +472,7 @@ function M(e, t) {
472
472
  0,
473
473
  0,
474
474
  1
475
- ], s([
475
+ ], l([
476
476
  0,
477
477
  0,
478
478
  0,
@@ -489,7 +489,7 @@ function N(e, t) {
489
489
  return r;
490
490
  }
491
491
  function P(e) {
492
- return new n({
492
+ return new p({
493
493
  name: e.name,
494
494
  color: e.color.getStyle(),
495
495
  opacity: e.opacity,
@@ -511,7 +511,7 @@ function I(e, t) {
511
511
  return t === 2 && n.length > 2 && r.push(n[n.length - 1], n[0]), L(e, r, !1);
512
512
  }
513
513
  function L(e, t, n) {
514
- return new r({
514
+ return new f({
515
515
  positions: e.positions,
516
516
  normals: n && e.hasNormals ? e.normals : void 0,
517
517
  uvs: e.uvs ?? void 0,