phoria2 1.2.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 (50) hide show
  1. package/README.md +2 -3
  2. package/dist/charts.js +476 -459
  3. package/dist/charts.js.map +1 -1
  4. package/dist/core.js +1192 -963
  5. package/dist/core.js.map +1 -1
  6. package/dist/edit.js +75 -75
  7. package/dist/edit.js.map +1 -1
  8. package/dist/explain.js +1 -1
  9. package/dist/gltf.js +84 -84
  10. package/dist/gltf.js.map +1 -1
  11. package/dist/keyboard.js +188 -0
  12. package/dist/keyboard.js.map +1 -0
  13. package/dist/motion.js +35 -35
  14. package/dist/motion.js.map +1 -1
  15. package/dist/particles.js +191 -118
  16. package/dist/particles.js.map +1 -1
  17. package/dist/passes.js +16 -16
  18. package/dist/passes.js.map +1 -1
  19. package/dist/phoria2.js +1 -1
  20. package/dist/picking.js +30 -14
  21. package/dist/picking.js.map +1 -1
  22. package/dist/snapshot.js +1 -1
  23. package/dist/tooltip.js +1 -1
  24. package/dist/types/View.d.ts +11 -0
  25. package/dist/types/area.d.ts +18 -0
  26. package/dist/types/geometry/Geometry.d.ts +16 -0
  27. package/dist/types/index.d.ts +2 -0
  28. package/dist/types/material/Material.d.ts +15 -0
  29. package/dist/types/material/Texture.d.ts +18 -2
  30. package/dist/types/particles/Emitter.d.ts +39 -2
  31. package/dist/types/scene/drawables.d.ts +23 -2
  32. package/dist/types/webgl/resources.d.ts +12 -2
  33. package/dist/types/webgl/shaders.d.ts +7 -2
  34. package/llms-full.txt +48 -1
  35. package/package.json +1 -1
  36. package/schema/scene.schema.json +48 -0
  37. package/src/View.js +16 -0
  38. package/src/area.js +131 -0
  39. package/src/charts/marks.js +29 -2
  40. package/src/geometry/Geometry.js +16 -1
  41. package/src/index.js +1 -0
  42. package/src/material/Material.js +9 -2
  43. package/src/material/Texture.js +55 -2
  44. package/src/particles/Emitter.js +121 -10
  45. package/src/scene/drawables.js +68 -4
  46. package/src/watch.js +8 -1
  47. package/src/webgl/WebGLRenderer.js +36 -5
  48. package/src/webgl/picking.js +22 -1
  49. package/src/webgl/resources.js +168 -14
  50. package/src/webgl/shaders.js +110 -11
package/dist/gltf.js CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as e, F as t, G as n, I as r, K as i, M as a, X as o, at as s, ct as c, et as l, ft as u, jt as d, mt as f, nt as p, ot as m, tt as h, ut as g, wt 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,25 +37,25 @@ 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, c = o === "CUBICSPLINE", l = c ? s * 3 : s, d = (e) => c ? e * l + s : e * l, p = n.length - 1, m = y;
41
- if (t <= n[0] || p === 0) for (let e = 0; e < s; e++) m[e] = r[d(0) + e];
42
- else if (t >= n[p]) for (let e = 0; e < s; e++) m[e] = r[d(p) + 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
- let e = 0, i = p;
44
+ let e = 0, i = f;
45
45
  for (; i - e > 1;) {
46
46
  let r = e + i >> 1;
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++) m[t] = r[d(e) + t];
50
+ if (o === "STEP") for (let t = 0; t < s; t++) p[t] = r[u(e) + t];
51
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, d = n - t, f = e * l, p = i * l;
53
- for (let e = 0; e < s; e++) m[e] = a * r[f + s + e] + o * h * r[f + s * 2 + e] + c * r[p + s + e] + d * h * r[p + e];
54
- s === 4 && u(m, m);
55
- } else if (s === 4) f(m, r.subarray(e * 4, e * 4 + 4), r.subarray(i * 4, i * 4 + 4), g);
56
- else for (let t = 0; t < 3; t++) m[t] = r[e * 3 + t] + (r[i * 3 + t] - r[e * 3 + t]) * g;
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
+ s === 4 && m(p, p);
55
+ } else if (s === 4) d(p, r.subarray(e * 4, e * 4 + 4), r.subarray(i * 4, i * 4 + 4), g);
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
- a === "quaternion" ? i.quaternion.set(m[0], m[1], m[2], m[3]) : i[a].set(m[0], m[1], m[2]);
58
+ a === "quaternion" ? i.quaternion.set(p[0], p[1], p[2], p[3]) : i[a].set(p[0], p[1], p[2]);
59
59
  }
60
60
  // src/gltf/load.js
61
61
  var x = /* @__PURE__ */ new Set([
@@ -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 p {
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 o);
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 d(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 _(`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 _(`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 _(`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 _(`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) || d(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 _("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 _(`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 _(`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 _(`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) => d(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 && d(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) && d(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 p();
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);
@@ -239,13 +239,13 @@ var j = class {
239
239
  let n = this.json.meshes[t];
240
240
  return n.primitives.map((r, i) => {
241
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 h({
242
+ return c = s === 0 ? new _({
243
243
  geometry: a,
244
244
  material: P(o)
245
245
  }) : s === 1 || s === 2 || s === 3 ? new e({
246
246
  geometry: I(a, s),
247
247
  material: P(o)
248
- }) : new l({
248
+ }) : new u({
249
249
  geometry: s === 4 ? a : F(a, s),
250
250
  material: o
251
251
  }), c.name = n.primitives.length > 1 ? `${n.name ?? `mesh ${t}`} ${i}` : n.name ?? `mesh ${t}`, c;
@@ -255,10 +255,10 @@ var j = class {
255
255
  let t = JSON.stringify([e.attributes, e.indices]), n = this.#r.get(t);
256
256
  if (n) return n;
257
257
  let r = e.attributes;
258
- if (r.POSITION === void 0) throw new _("loadGLTF: a mesh primitive has no POSITION");
258
+ if (r.POSITION === void 0) throw new s("loadGLTF: a mesh primitive has no POSITION");
259
259
  let i = { positions: this.#u(r.POSITION) };
260
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 c(i);
261
+ let a = new f(i);
262
262
  return this.#r.set(t, a), a;
263
263
  }
264
264
  #u(e, t = !1) {
@@ -274,52 +274,52 @@ 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 _(`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 n = this.json.materials[e], r = n.pbrMetallicRoughness ?? {}, i = new s({ name: n.name ?? `material ${e}` }), a = r.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
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), c = n.extensions ?? {}, l = c.KHR_materials_transmission, u = c.KHR_materials_clearcoat, d = c.KHR_materials_sheen;
301
- if (l && (i.transmission = o(l.transmissionFactor ?? 0)), u && (i.clearcoat = o(u.clearcoatFactor ?? 0), i.clearcoatRoughness = o(u.clearcoatRoughnessFactor ?? 0)), d) {
302
- let e = d.sheenColorFactor ?? [
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 && (i.sheen = 1, i.sheenColor.setLinear(e[0], e[1], e[2])), i.sheenRoughness = o(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 && (i.ior = c.KHR_materials_ior.ior);
310
- let f = c.KHR_materials_specular;
311
- if (f) {
312
- i.specularIntensity = o(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
318
  i.specularColor.setLinear(e[0], e[1], e[2]);
319
319
  }
320
- let p = c.KHR_materials_anisotropy;
321
- p && (i.anisotropy = o(p.anisotropyStrength ?? 0), i.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
324
  i.translucency = o(m.diffuseTransmissionFactor ?? 0);
325
325
  let e = m.diffuseTransmissionColorFactor ?? [
@@ -333,7 +333,7 @@ var j = class {
333
333
  }
334
334
  #p() {
335
335
  let e = this.#n.get(-1);
336
- return e || this.#n.set(-1, e = new s({
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 && (d(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,25 +351,25 @@ 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 _(`loadGLTF: texture ${e.index} has no image (compressed textures aren't supported)`);
356
- let l;
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
- l = URL.createObjectURL(new Blob([t], { type: c.mimeType ?? "image/png" })), this.#a.push(l);
360
- } else l = this.#o(c.uri);
361
- let u = new m({
362
- url: l,
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],
369
369
  rotation: n?.rotation ?? 0,
370
370
  uvSet: r
371
371
  });
372
- return this.#t.set(i, u), u;
372
+ return this.#t.set(i, f), f;
373
373
  }
374
374
  #h(e) {
375
375
  let t = this.json.cameras[e], r = t.name ?? `camera ${e}`;
@@ -392,7 +392,7 @@ var j = class {
392
392
  }
393
393
  #g(e) {
394
394
  let n = this.json.extensions?.KHR_lights_punctual?.lights?.[e];
395
- if (!n) throw new _(`loadGLTF: KHR_lights_punctual light ${e} doesn't exist`);
395
+ if (!n) throw new s(`loadGLTF: KHR_lights_punctual light ${e} doesn't exist`);
396
396
  let i = n.color ?? [
397
397
  1,
398
398
  1,
@@ -400,8 +400,8 @@ var j = class {
400
400
  ], o = {
401
401
  name: n.name,
402
402
  intensity: (n.intensity ?? 1) / Math.PI
403
- }, s;
404
- if (n.type === "directional") s = new a({
403
+ }, c;
404
+ if (n.type === "directional") c = new a({
405
405
  ...o,
406
406
  direction: [
407
407
  0,
@@ -411,7 +411,7 @@ 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 r({
414
+ c = new r({
415
415
  ...o,
416
416
  direction: [
417
417
  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 t({
425
+ } else c = new t({
426
426
  ...o,
427
427
  range: n.range ?? 0
428
428
  });
429
- return s.color.setLinear(i[0], i[1], i[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
- d(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];
@@ -467,12 +467,12 @@ function M(e, t) {
467
467
  t[8] / i,
468
468
  t[9] / i,
469
469
  t[10] / i
470
- ], o = u([
470
+ ], o = m([
471
471
  0,
472
472
  0,
473
473
  0,
474
474
  1
475
- ], g([
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 s({
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 c({
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,