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.
- package/README.md +71 -13
- package/dist/bloom.js +1 -1
- package/dist/charts.js +397 -384
- package/dist/charts.js.map +1 -1
- package/dist/core.js +4451 -3568
- package/dist/core.js.map +1 -1
- package/dist/edit.js +67 -67
- package/dist/edit.js.map +1 -1
- package/dist/explain.js +6 -2
- package/dist/explain.js.map +1 -1
- package/dist/gltf.js +211 -166
- package/dist/gltf.js.map +1 -1
- package/dist/motion.js +26 -26
- package/dist/motion.js.map +1 -1
- package/dist/particles.js +49 -49
- package/dist/particles.js.map +1 -1
- package/dist/passes.js +188 -86
- package/dist/passes.js.map +1 -1
- package/dist/phoria2.js +1 -1
- package/dist/picking.js +8 -13
- package/dist/picking.js.map +1 -1
- package/dist/snapshot.js +1 -1
- package/dist/tooltip.js +3 -3
- package/dist/tooltip.js.map +1 -1
- package/dist/types/OrbitControl.d.ts +6 -2
- package/dist/types/Raycaster.d.ts +10 -0
- package/dist/types/View.d.ts +64 -1
- package/dist/types/charts/Chart.d.ts +7 -0
- package/dist/types/explain.d.ts +3 -0
- package/dist/types/frame.d.ts +7 -0
- package/dist/types/geometry/Geometry.d.ts +14 -2
- package/dist/types/keyboard.d.ts +48 -0
- package/dist/types/labels.d.ts +4 -0
- package/dist/types/material/Material.d.ts +125 -0
- package/dist/types/material/Texture.d.ts +37 -5
- package/dist/types/scene/Node.d.ts +19 -14
- package/dist/types/scene/drawables.d.ts +32 -14
- package/dist/types/scene/lights.d.ts +16 -2
- package/dist/types/shadow.d.ts +2 -1
- package/dist/types/types.d.ts +14 -0
- package/dist/types/value/Color.d.ts +0 -4
- package/dist/types/value/Quat.d.ts +4 -2
- package/dist/types/webgl/WebGLRenderer.d.ts +6 -0
- package/dist/types/webgl/passes.d.ts +37 -13
- package/dist/types/webgl/resources.d.ts +24 -2
- package/dist/types/webgl/shaders.d.ts +4 -2
- package/llms-full.txt +153 -15
- package/package.json +4 -1
- package/schema/scene.schema.json +146 -1
- package/src/OrbitControl.js +7 -3
- package/src/Raycaster.js +58 -0
- package/src/View.js +207 -42
- package/src/charts/Chart.js +20 -2
- package/src/explain.js +6 -2
- package/src/frame.js +29 -9
- package/src/geometry/Geometry.js +24 -4
- package/src/gltf/load.js +50 -6
- package/src/keyboard.js +298 -0
- package/src/labels.js +4 -1
- package/src/material/Material.js +104 -19
- package/src/material/Texture.js +116 -11
- package/src/scene/Node.js +20 -9
- package/src/scene/Scene.js +2 -0
- package/src/scene/cameras.js +4 -1
- package/src/scene/drawables.js +48 -12
- package/src/scene/lights.js +40 -6
- package/src/shadow.js +27 -4
- package/src/types.js +6 -0
- package/src/value/Color.js +21 -0
- package/src/value/Quat.js +15 -6
- package/src/watch.js +25 -1
- package/src/webgl/WebGLRenderer.js +51 -12
- package/src/webgl/passes.js +190 -32
- package/src/webgl/picking.js +0 -1
- package/src/webgl/resources.js +89 -8
- package/src/webgl/shaders.js +350 -48
package/dist/gltf.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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",
|
|
41
|
-
if (t <= n[0] || p === 0) for (let e = 0; e < s; e++) m[e] = r[
|
|
42
|
-
else if (t >= n[p]) for (let e = 0; e < s; e++) m[e] = r[
|
|
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[
|
|
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,
|
|
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] +
|
|
54
|
-
s === 4 &&
|
|
55
|
-
} else if (s === 4)
|
|
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
|
|
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
|
|
108
|
+
return this.findAll((e) => e instanceof o);
|
|
102
109
|
}
|
|
103
|
-
play(
|
|
104
|
-
let
|
|
105
|
-
if (!
|
|
106
|
-
let
|
|
107
|
-
return
|
|
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
|
|
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
|
|
120
|
-
throw new
|
|
126
|
+
let n = await fetch(e).catch((t) => {
|
|
127
|
+
throw new _(`loadGLTF: couldn't fetch '${e}' - ${t.message}`);
|
|
121
128
|
});
|
|
122
|
-
if (!
|
|
123
|
-
let
|
|
124
|
-
return k(await
|
|
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:
|
|
133
|
+
baseUrl: r
|
|
127
134
|
});
|
|
128
135
|
}
|
|
129
|
-
async function k(
|
|
130
|
-
let { json:
|
|
131
|
-
if (!
|
|
132
|
-
for (let e of
|
|
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
|
|
142
|
+
throw new _(`loadGLTF: the model requires '${e}', which isn't supported${t}`);
|
|
136
143
|
}
|
|
137
|
-
let
|
|
138
|
-
for (let
|
|
139
|
-
let
|
|
140
|
-
await
|
|
141
|
-
let
|
|
142
|
-
return (
|
|
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),
|
|
154
|
-
if (t.length >= 12 &&
|
|
155
|
-
let e = null,
|
|
156
|
-
for (let
|
|
157
|
-
let a =
|
|
158
|
-
o === 1313821514 ? e = JSON.parse(new TextDecoder().decode(s)) : o === 5130562 && (
|
|
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
|
|
167
|
+
if (!e) throw new _("loadGLTF: the .glb file has no JSON chunk");
|
|
161
168
|
return {
|
|
162
169
|
json: e,
|
|
163
|
-
bin:
|
|
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
|
|
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
|
|
195
|
-
throw new
|
|
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 (!
|
|
198
|
-
return new Uint8Array(await
|
|
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((
|
|
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(
|
|
220
|
-
let
|
|
221
|
-
|
|
222
|
-
let
|
|
223
|
-
for (let e of
|
|
224
|
-
if (
|
|
225
|
-
let e = this.#h(
|
|
226
|
-
|
|
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
|
|
229
|
-
return
|
|
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(
|
|
232
|
-
let n = this.json.meshes[
|
|
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),
|
|
235
|
-
return
|
|
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
|
-
}) :
|
|
239
|
-
geometry: I(a,
|
|
245
|
+
}) : s === 1 || s === 2 || s === 3 ? new e({
|
|
246
|
+
geometry: I(a, s),
|
|
240
247
|
material: P(o)
|
|
241
|
-
}) : new
|
|
242
|
-
geometry:
|
|
248
|
+
}) : new l({
|
|
249
|
+
geometry: s === 4 ? a : F(a, s),
|
|
243
250
|
material: o
|
|
244
|
-
}),
|
|
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]),
|
|
249
|
-
if (
|
|
250
|
-
let
|
|
251
|
-
if (
|
|
252
|
-
let
|
|
253
|
-
|
|
254
|
-
let
|
|
255
|
-
return this.#r.set(t,
|
|
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
|
|
270
|
-
let
|
|
271
|
-
if (!
|
|
272
|
-
let
|
|
273
|
-
5120: (e) =>
|
|
274
|
-
5121: (e) =>
|
|
275
|
-
5122: (e) =>
|
|
276
|
-
5123: (e) =>
|
|
277
|
-
5125: (e) =>
|
|
278
|
-
5126: (e) =>
|
|
279
|
-
}[
|
|
280
|
-
if (
|
|
281
|
-
else for (let e = 0; e <
|
|
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 ?? {},
|
|
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
|
-
|
|
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
|
|
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(
|
|
303
|
-
let
|
|
304
|
-
|
|
305
|
-
let
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
if (
|
|
314
|
-
let
|
|
315
|
-
if (
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
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:
|
|
326
|
-
offset:
|
|
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(
|
|
372
|
+
return this.#t.set(i, u), u;
|
|
329
373
|
}
|
|
330
374
|
#h(e) {
|
|
331
|
-
let t = this.json.cameras[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
|
|
335
|
-
name:
|
|
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
|
|
342
|
-
return new
|
|
343
|
-
name:
|
|
344
|
-
fov:
|
|
345
|
-
near:
|
|
346
|
-
far:
|
|
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
|
|
351
|
-
if (!
|
|
352
|
-
let i =
|
|
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
|
-
],
|
|
357
|
-
name:
|
|
358
|
-
intensity: (
|
|
359
|
-
},
|
|
360
|
-
if (
|
|
361
|
-
...
|
|
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 (
|
|
369
|
-
let e =
|
|
370
|
-
|
|
371
|
-
...
|
|
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:
|
|
421
|
+
range: n.range ?? 0,
|
|
378
422
|
angle: e,
|
|
379
|
-
penumbra: e > 0 ? 1 -
|
|
423
|
+
penumbra: e > 0 ? 1 - t / e : 0
|
|
380
424
|
});
|
|
381
|
-
} else
|
|
382
|
-
...
|
|
383
|
-
range:
|
|
425
|
+
} else s = new t({
|
|
426
|
+
...o,
|
|
427
|
+
range: n.range ?? 0
|
|
384
428
|
});
|
|
385
|
-
return
|
|
429
|
+
return s.color.setLinear(i[0], i[1], i[2]), s;
|
|
386
430
|
}
|
|
387
|
-
#_(
|
|
388
|
-
let
|
|
389
|
-
for (let
|
|
390
|
-
let
|
|
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
|
-
}[
|
|
395
|
-
if (!
|
|
396
|
-
|
|
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
|
|
400
|
-
if (!
|
|
401
|
-
let
|
|
402
|
-
|
|
403
|
-
node:
|
|
404
|
-
path:
|
|
405
|
-
times: this.#u(
|
|
406
|
-
values: this.#u(
|
|
407
|
-
interpolation:
|
|
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(
|
|
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 =
|
|
470
|
+
], o = u([
|
|
427
471
|
0,
|
|
428
472
|
0,
|
|
429
473
|
0,
|
|
430
474
|
1
|
|
431
|
-
],
|
|
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
|
|
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
|
|
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
|
});
|