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