phoria2 1.3.0 → 1.4.1
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 +9 -6
- package/dist/bloom.js +4 -4
- package/dist/bloom.js.map +1 -1
- package/dist/charts.js +436 -436
- package/dist/charts.js.map +1 -1
- package/dist/core.js +1240 -862
- package/dist/core.js.map +1 -1
- package/dist/debug.js +297 -0
- package/dist/debug.js.map +1 -0
- package/dist/edit.js +40 -40
- package/dist/edit.js.map +1 -1
- package/dist/explain.js +32 -13
- package/dist/explain.js.map +1 -1
- package/dist/gltf.js +128 -128
- package/dist/gltf.js.map +1 -1
- package/dist/keyboard.js +19 -19
- package/dist/keyboard.js.map +1 -1
- package/dist/motion.js +35 -35
- package/dist/motion.js.map +1 -1
- package/dist/particles.js +36 -36
- package/dist/particles.js.map +1 -1
- package/dist/passes.js +116 -104
- package/dist/passes.js.map +1 -1
- package/dist/phoria2.js +1 -1
- package/dist/picking.js +90 -71
- package/dist/picking.js.map +1 -1
- package/dist/snapshot.js +1 -1
- package/dist/tooltip.js +1 -1
- package/dist/types/View.d.ts +16 -0
- package/dist/types/debug.d.ts +74 -0
- package/dist/types/explain.d.ts +4 -0
- package/dist/types/frame.d.ts +5 -0
- package/dist/types/material/Material.d.ts +52 -0
- package/dist/types/watch.d.ts +8 -1
- package/dist/types/webgl/hooks.d.ts +48 -0
- package/dist/types/webgl/passes.d.ts +4 -0
- package/dist/types/webgl/programs.d.ts +15 -5
- package/dist/types/webgl/shaders.d.ts +36 -5
- package/llms-full.txt +227 -0
- package/llms.txt +1 -1
- package/package.json +1 -1
- package/schema/scene.schema.json +27 -0
- package/src/View.js +105 -7
- package/src/debug.js +283 -0
- package/src/explain.js +19 -0
- package/src/frame.js +7 -2
- package/src/material/Material.js +121 -2
- package/src/scene/drawables.js +21 -4
- package/src/watch.js +18 -2
- package/src/webgl/WebGLRenderer.js +19 -2
- package/src/webgl/hooks.js +121 -0
- package/src/webgl/passes.js +17 -2
- package/src/webgl/picking.js +23 -2
- package/src/webgl/programs.js +20 -9
- package/src/webgl/resources.js +1 -1
- package/src/webgl/shaders.js +443 -35
package/dist/core.js
CHANGED
|
@@ -1311,8 +1311,32 @@ var Ke = [
|
|
|
1311
1311
|
...Ke,
|
|
1312
1312
|
...Je,
|
|
1313
1313
|
...Object.keys(Ye),
|
|
1314
|
-
"blending"
|
|
1315
|
-
|
|
1314
|
+
"blending",
|
|
1315
|
+
"shader"
|
|
1316
|
+
], $e = [
|
|
1317
|
+
"vertex",
|
|
1318
|
+
"fragment",
|
|
1319
|
+
"lit",
|
|
1320
|
+
"uniforms",
|
|
1321
|
+
"bounds"
|
|
1322
|
+
], et = [
|
|
1323
|
+
"hash",
|
|
1324
|
+
"vnoise",
|
|
1325
|
+
"snoise",
|
|
1326
|
+
"snoised",
|
|
1327
|
+
"vfbm",
|
|
1328
|
+
"sfbm",
|
|
1329
|
+
"sfbmd",
|
|
1330
|
+
"voronoi",
|
|
1331
|
+
"srgb",
|
|
1332
|
+
"hsv2rgb",
|
|
1333
|
+
"palette",
|
|
1334
|
+
"fresnel",
|
|
1335
|
+
"rotate2",
|
|
1336
|
+
"rotate3",
|
|
1337
|
+
"remap",
|
|
1338
|
+
"saturate"
|
|
1339
|
+
], tt = RegExp(`^(gl_|phoria)|^(uTime|cameraPosition|${et.join("|")})$`), nt = {
|
|
1316
1340
|
type: "phoria2 has one material - drop 'type' and set 'unlit: true' for a flat colour",
|
|
1317
1341
|
side: "use 'doubleSided: true'",
|
|
1318
1342
|
wireframe: "use new Lines({ geometry: edges(geometry) }) for a wireframe",
|
|
@@ -1330,10 +1354,14 @@ var Ke = [
|
|
|
1330
1354
|
subsurface: "use 'translucency' for light through thin surfaces",
|
|
1331
1355
|
colour: "use 'color'",
|
|
1332
1356
|
emissiveColor: "use 'emissive'",
|
|
1333
|
-
alpha: "use 'opacity'"
|
|
1334
|
-
|
|
1357
|
+
alpha: "use 'opacity'",
|
|
1358
|
+
onBeforeCompile: "use 'shader': { vertex, fragment, lit, uniforms } - GLSL run inside phoria2's own shader",
|
|
1359
|
+
vertexShader: "use 'shader': { vertex: 'local.y += sin(local.x + uTime);' } - a hook, not a whole shader",
|
|
1360
|
+
fragmentShader: "use 'shader': { fragment: 'base.rgb *= 0.5;' } - a hook, not a whole shader",
|
|
1361
|
+
uniforms: "use 'shader': { uniforms: { uAmount: 1 } }"
|
|
1362
|
+
}, rt = class e {
|
|
1335
1363
|
static OPTIONS = Qe;
|
|
1336
|
-
static HINTS =
|
|
1364
|
+
static HINTS = nt;
|
|
1337
1365
|
name;
|
|
1338
1366
|
opacity;
|
|
1339
1367
|
alphaTest;
|
|
@@ -1375,13 +1403,24 @@ var Ke = [
|
|
|
1375
1403
|
#t = !1;
|
|
1376
1404
|
#n = Object.fromEntries(Ke.map((e) => [e, null]));
|
|
1377
1405
|
#r = /* @__PURE__ */ new Set();
|
|
1406
|
+
#i = null;
|
|
1378
1407
|
constructor(e = {}) {
|
|
1379
|
-
A("Material", e, Qe,
|
|
1380
|
-
for (let [t, n] of Object.entries(e)) n !== void 0 && (t in Xe ? this.#e[t].set(n, "Material") : Ke.includes(t) ? this.setMap(t, n) : Je.includes(t) ? this[t] =
|
|
1408
|
+
A("Material", e, Qe, nt), Object.assign(this, Ze);
|
|
1409
|
+
for (let [t, n] of Object.entries(e)) n !== void 0 && (t in Xe ? this.#e[t].set(n, "Material") : Ke.includes(t) ? this.setMap(t, n) : Je.includes(t) ? this[t] = it(t, n) : t in Ye ? this[t] = at(t, n, Ye[t]) : t === "blending" ? this.blending = P("Material", "blending", n, [
|
|
1381
1410
|
"normal",
|
|
1382
1411
|
"additive",
|
|
1383
1412
|
"multiply"
|
|
1384
|
-
]) : t === "name"
|
|
1413
|
+
]) : t === "name" ? this.name = String(n) : t === "shader" && (this.shader = n));
|
|
1414
|
+
}
|
|
1415
|
+
get shader() {
|
|
1416
|
+
return this.#i;
|
|
1417
|
+
}
|
|
1418
|
+
set shader(e) {
|
|
1419
|
+
this.#i = ot(e);
|
|
1420
|
+
}
|
|
1421
|
+
get allTextures() {
|
|
1422
|
+
let e = this.textures, t = this.#i?.uniforms;
|
|
1423
|
+
return t ? [...e, ...Object.entries(t).filter(([, e]) => e instanceof W).map(([e, t]) => [`shader.${e}`, t])] : e;
|
|
1385
1424
|
}
|
|
1386
1425
|
static fromInput(t) {
|
|
1387
1426
|
return t instanceof e ? t : ((!t || typeof t != "object" || Array.isArray(t)) && E("Material", `expected material options such as { color: 'orange' }, got ${j(t)}`), new e(t));
|
|
@@ -1497,10 +1536,10 @@ var Ke = [
|
|
|
1497
1536
|
get variant() {
|
|
1498
1537
|
let e = [this.unlit ? "unlit" : "lit"];
|
|
1499
1538
|
for (let [t] of this.textures) e.push(t);
|
|
1500
|
-
return this.alphaTest > 0 && e.push("cutout"), this.transmission > 0 && e.push("glass"), this.clearcoat > 0 && e.push("clearcoat"), this.sheen > 0 && e.push("sheen"), this.anisotropy > 0 && e.push("brushed"), this.translucency > 0 && e.push("translucent"), this.toon > 0 && e.push("toon"), this.flatShading && e.push("flat"), this.vertexColors && e.push("vcolor"), e.join("+");
|
|
1539
|
+
return this.alphaTest > 0 && e.push("cutout"), this.transmission > 0 && e.push("glass"), this.clearcoat > 0 && e.push("clearcoat"), this.sheen > 0 && e.push("sheen"), this.anisotropy > 0 && e.push("brushed"), this.translucency > 0 && e.push("translucent"), this.toon > 0 && e.push("toon"), this.flatShading && e.push("flat"), this.vertexColors && e.push("vcolor"), this.#i && e.push("hooks"), e.join("+");
|
|
1501
1540
|
}
|
|
1502
1541
|
async ready() {
|
|
1503
|
-
await Promise.all(this.
|
|
1542
|
+
await Promise.all(this.allTextures.map(([, e]) => e.ready));
|
|
1504
1543
|
}
|
|
1505
1544
|
clone() {
|
|
1506
1545
|
let t = new e(this.toJSON(!0));
|
|
@@ -1522,19 +1561,58 @@ var Ke = [
|
|
|
1522
1561
|
let i = e ? r : r.toJSON();
|
|
1523
1562
|
i && (t[n] = i);
|
|
1524
1563
|
}
|
|
1564
|
+
let n = this.#i;
|
|
1565
|
+
if (n) {
|
|
1566
|
+
let r = {};
|
|
1567
|
+
for (let e of [
|
|
1568
|
+
"vertex",
|
|
1569
|
+
"fragment",
|
|
1570
|
+
"lit"
|
|
1571
|
+
]) n[e] && (r[e] = n[e]);
|
|
1572
|
+
let i = Object.entries(n.uniforms).map(([t, n]) => [t, n instanceof W ? e ? n : n.toJSON() : n instanceof H ? n.getStyle() : Array.isArray(n) || ArrayBuffer.isView(n) ? Array.from(n) : n]);
|
|
1573
|
+
i.length && (r.uniforms = Object.fromEntries(i.filter(([, e]) => e != null))), n.bounds !== null && (r.bounds = n.bounds), t.shader = r;
|
|
1574
|
+
}
|
|
1525
1575
|
return t;
|
|
1526
1576
|
}
|
|
1527
1577
|
};
|
|
1528
|
-
function
|
|
1578
|
+
function it(e, t) {
|
|
1529
1579
|
return typeof t != "boolean" && E("Material", `'${e}' must be true or false, got ${j(t)}`), t;
|
|
1530
1580
|
}
|
|
1531
|
-
function
|
|
1581
|
+
function at(e, t, [n, r]) {
|
|
1532
1582
|
M("Material", e, t);
|
|
1533
1583
|
let i = t;
|
|
1534
1584
|
return (i < n || i > r) && E("Material", `'${e}' must be ${r === Infinity ? `${n} or more` : `${n}-${r}`}, got ${i}`), i;
|
|
1535
1585
|
}
|
|
1586
|
+
function ot(e) {
|
|
1587
|
+
if (e == null) return null;
|
|
1588
|
+
(typeof e != "object" || Array.isArray(e)) && E("Material", `'shader' is { vertex, fragment, lit, uniforms, bounds } - GLSL hooks - got ${j(e)}`), A("Material shader", e, $e, {
|
|
1589
|
+
vertexShader: "use 'vertex' - a few lines run on each vertex, not a whole shader",
|
|
1590
|
+
fragmentShader: "use 'fragment' (before lighting) or 'lit' (after) - a few lines, not a whole shader"
|
|
1591
|
+
});
|
|
1592
|
+
for (let t of [
|
|
1593
|
+
"vertex",
|
|
1594
|
+
"fragment",
|
|
1595
|
+
"lit"
|
|
1596
|
+
]) e[t] !== void 0 && typeof e[t] != "string" && E("Material", `shader '${t}' is GLSL as a string, got ${j(e[t])}`);
|
|
1597
|
+
e.vertex || e.fragment || e.lit || E("Material", "'shader' needs at least one of 'vertex', 'fragment' or 'lit'");
|
|
1598
|
+
let t = e.uniforms ?? {};
|
|
1599
|
+
(typeof t != "object" || Array.isArray(t)) && E("Material", `shader 'uniforms' is an object of name: value, got ${j(t)}`);
|
|
1600
|
+
let n = {};
|
|
1601
|
+
for (let [e, r] of Object.entries(t)) /^[A-Za-z_]\w*$/.test(e) || E("Material", `shader uniform '${e}' isn't a GLSL name - letters, digits and _, not starting with a digit`), tt.test(e) && E("Material", `shader uniform '${e}' is a name phoria2 keeps${e === "uTime" ? " - uTime is there already, the View's clock in seconds" : e === "cameraPosition" ? " - cameraPosition is there already, the camera's world position" : et.includes(e) ? ` - ${e}() is a function every hook can call` : ""}`), n[e] = st(e, r);
|
|
1602
|
+
let r = e.bounds === void 0 || e.bounds === null ? null : Math.max(0, M("Material", "shader bounds", e.bounds));
|
|
1603
|
+
return {
|
|
1604
|
+
vertex: e.vertex ?? "",
|
|
1605
|
+
fragment: e.fragment ?? "",
|
|
1606
|
+
lit: e.lit ?? "",
|
|
1607
|
+
uniforms: n,
|
|
1608
|
+
bounds: r
|
|
1609
|
+
};
|
|
1610
|
+
}
|
|
1611
|
+
function st(e, t) {
|
|
1612
|
+
return typeof t == "number" && Number.isFinite(t) ? t : (Array.isArray(t) || ArrayBuffer.isView(t)) && t.length >= 2 && t.length <= 4 && Array.from(t).every((e) => typeof e == "number" && Number.isFinite(e)) ? Array.from(t) : t instanceof W || t instanceof H ? t : t && typeof t == "object" && "url" in t ? new W(t) : typeof t == "string" ? H.fromInput(t, "Material") : E("Material", `shader uniform '${e}' is a number, two to four numbers, a colour or a Texture, got ${j(t)}`);
|
|
1613
|
+
}
|
|
1536
1614
|
// src/resolve.js
|
|
1537
|
-
function
|
|
1615
|
+
function ct(e, t) {
|
|
1538
1616
|
if (e instanceof U) return e;
|
|
1539
1617
|
if ((!e || typeof e != "object" || Array.isArray(e)) && E(t, `'geometry' must be a Geometry such as box(2), got ${j(e)}`), "type" in e) {
|
|
1540
1618
|
let n = e.type;
|
|
@@ -1542,18 +1620,18 @@ function rt(e, t) {
|
|
|
1542
1620
|
}
|
|
1543
1621
|
return new U(e);
|
|
1544
1622
|
}
|
|
1545
|
-
function
|
|
1546
|
-
return e === void 0 ? new
|
|
1623
|
+
function lt(e) {
|
|
1624
|
+
return e === void 0 ? new rt() : rt.fromInput(e);
|
|
1547
1625
|
}
|
|
1548
1626
|
// src/math/mat3.js
|
|
1549
|
-
function
|
|
1627
|
+
function ut(e) {
|
|
1550
1628
|
return e.fill(0), e[0] = e[4] = e[8] = 1, e;
|
|
1551
1629
|
}
|
|
1552
|
-
function
|
|
1630
|
+
function dt(e, t) {
|
|
1553
1631
|
let n = t[0], r = t[1], i = t[2], a = t[3], o = t[4], s = t[5], c = t[6], l = t[7], u = t[8], d = t[9], f = t[10], p = t[11], m = t[12], h = t[13], g = t[14], _ = t[15], v = n * s - r * o, y = n * c - i * o, b = n * l - a * o, x = r * c - i * s, S = r * l - a * s, C = i * l - a * c, w = u * h - d * m, T = u * g - f * m, E = u * _ - p * m, D = d * g - f * h, O = d * _ - p * h, k = f * _ - p * g, A = v * k - y * O + b * D + x * E - S * T + C * w;
|
|
1554
1632
|
return A ? (A = 1 / A, e[0] = (s * k - c * O + l * D) * A, e[1] = (c * E - o * k - l * T) * A, e[2] = (o * O - s * E + l * w) * A, e[3] = (i * O - r * k - a * D) * A, e[4] = (n * k - i * E + a * T) * A, e[5] = (r * E - n * O - a * w) * A, e[6] = (h * C - g * S + _ * x) * A, e[7] = (g * b - m * C - _ * y) * A, e[8] = (m * S - h * b + _ * v) * A, e) : null;
|
|
1555
1633
|
}
|
|
1556
|
-
function
|
|
1634
|
+
function ft(e, t) {
|
|
1557
1635
|
return e[0] = t[0], e[1] = t[1], e[2] = t[2], e[3] = t[4], e[4] = t[5], e[5] = t[6], e[6] = t[8], e[7] = t[9], e[8] = t[10], e;
|
|
1558
1636
|
}
|
|
1559
1637
|
// src/scene/Node.js
|
|
@@ -1578,7 +1656,7 @@ var G = [
|
|
|
1578
1656
|
"clip",
|
|
1579
1657
|
"onDrag",
|
|
1580
1658
|
"outline"
|
|
1581
|
-
],
|
|
1659
|
+
], pt = {
|
|
1582
1660
|
rotationX: "use rotation: [x, y, z] (radians)",
|
|
1583
1661
|
scaleX: "use scale: [x, y, z] or a single number",
|
|
1584
1662
|
translate: "use position: [x, y, z]",
|
|
@@ -1589,14 +1667,14 @@ var G = [
|
|
|
1589
1667
|
onDragStart: "use onDrag - drag.phase is 'start', 'move' or 'end'",
|
|
1590
1668
|
onDragEnd: "use onDrag - drag.phase is 'start', 'move' or 'end'",
|
|
1591
1669
|
selected: "outline what's selected: node.outline = '#ffcc00'"
|
|
1592
|
-
},
|
|
1670
|
+
}, mt = [], ht = new Float32Array([
|
|
1593
1671
|
0,
|
|
1594
1672
|
1,
|
|
1595
1673
|
0
|
|
1596
|
-
]),
|
|
1674
|
+
]), gt = /* @__PURE__ */ new Float32Array(16), _t = /* @__PURE__ */ new Float32Array(9), K = class e {
|
|
1597
1675
|
static type = "node";
|
|
1598
1676
|
static OPTIONS = G;
|
|
1599
|
-
static HINTS =
|
|
1677
|
+
static HINTS = pt;
|
|
1600
1678
|
name = "";
|
|
1601
1679
|
#e = new z();
|
|
1602
1680
|
#t = new z(1, 1, 1);
|
|
@@ -1649,7 +1727,7 @@ var G = [
|
|
|
1649
1727
|
constructor(e = {}) {
|
|
1650
1728
|
let t = new.target;
|
|
1651
1729
|
A(t.name, e, t.OPTIONS, {
|
|
1652
|
-
...
|
|
1730
|
+
...pt,
|
|
1653
1731
|
...t.HINTS
|
|
1654
1732
|
}), this.rotation.onChange = () => Me(this.quaternion, this.rotation.x, this.rotation.y, this.rotation.z), this.quaternion.onChange = () => this.rotation.setFromQuat(this.quaternion);
|
|
1655
1733
|
let n = t.name;
|
|
@@ -1714,7 +1792,7 @@ var G = [
|
|
|
1714
1792
|
}
|
|
1715
1793
|
add(e, ...t) {
|
|
1716
1794
|
e === void 0 && E(this.constructor.name, "add() needs a node to add - add(new Mesh({...})), or add(...nodes) for several");
|
|
1717
|
-
let n = [e, ...t].map((e) =>
|
|
1795
|
+
let n = [e, ...t].map((e) => bt(e));
|
|
1718
1796
|
for (let e of n) {
|
|
1719
1797
|
e === this && E(this.constructor.name, "can't add a node to itself");
|
|
1720
1798
|
for (let t = this.#c; t; t = t.#c) t === e && E(this.constructor.name, "can't add an ancestor as a child - that would make a loop");
|
|
@@ -1771,7 +1849,7 @@ var G = [
|
|
|
1771
1849
|
}
|
|
1772
1850
|
handlersFor(e) {
|
|
1773
1851
|
let t = e === "hover" ? this.onHover : this.onClick, n = this.#s?.[e];
|
|
1774
|
-
return n?.size ? t ? [t, ...n] : [...n] : t ? [t] :
|
|
1852
|
+
return n?.size ? t ? [t, ...n] : [...n] : t ? [t] : mt;
|
|
1775
1853
|
}
|
|
1776
1854
|
runHandlers(e, t) {
|
|
1777
1855
|
for (let n of this.#u) n(this, e, t);
|
|
@@ -1818,19 +1896,19 @@ var G = [
|
|
|
1818
1896
|
], e);
|
|
1819
1897
|
}
|
|
1820
1898
|
lookAt(t, n) {
|
|
1821
|
-
let r = t instanceof e ? t.updateWorld().worldPosition : z.fromInput(t, this.constructor.name), i = n === void 0 ?
|
|
1899
|
+
let r = t instanceof e ? t.updateWorld().worldPosition : z.fromInput(t, this.constructor.name), i = n === void 0 ? ht : z.fromInput(n, `${this.constructor.name}.lookAt() up`).normalize();
|
|
1822
1900
|
this.updateWorld();
|
|
1823
1901
|
let a = this.worldPosition;
|
|
1824
1902
|
if (a.equals(r, 1e-9)) return this;
|
|
1825
1903
|
let o = r.clone().sub(a).normalize();
|
|
1826
|
-
f(
|
|
1904
|
+
f(gt, a, r, Math.abs(o.dot(i)) > .9999 ? Math.abs(i[1]) > .9 ? [
|
|
1827
1905
|
0,
|
|
1828
1906
|
0,
|
|
1829
1907
|
-1
|
|
1830
|
-
] :
|
|
1831
|
-
let s = je(/* @__PURE__ */ new Float32Array(4),
|
|
1908
|
+
] : ht : i);
|
|
1909
|
+
let s = je(/* @__PURE__ */ new Float32Array(4), ft(_t, gt));
|
|
1832
1910
|
if (this.#c) {
|
|
1833
|
-
let e = Oe(/* @__PURE__ */ new Float32Array(4), je(/* @__PURE__ */ new Float32Array(4),
|
|
1911
|
+
let e = Oe(/* @__PURE__ */ new Float32Array(4), je(/* @__PURE__ */ new Float32Array(4), xt(this.#c.worldMatrix)));
|
|
1834
1912
|
De(s, ke(e, e), s);
|
|
1835
1913
|
}
|
|
1836
1914
|
return this.quaternion.copy(Oe(s, s)), this;
|
|
@@ -1855,7 +1933,7 @@ var G = [
|
|
|
1855
1933
|
return this.worldMatrix.getPosition();
|
|
1856
1934
|
}
|
|
1857
1935
|
get worldQuaternion() {
|
|
1858
|
-
let e = je(/* @__PURE__ */ new Float32Array(4),
|
|
1936
|
+
let e = je(/* @__PURE__ */ new Float32Array(4), xt(this.worldMatrix));
|
|
1859
1937
|
return new Ne(e[0], e[1], e[2], e[3]).normalize();
|
|
1860
1938
|
}
|
|
1861
1939
|
get worldScale() {
|
|
@@ -1934,33 +2012,33 @@ var G = [
|
|
|
1934
2012
|
this.traverse((e) => e !== this && e.dispose());
|
|
1935
2013
|
}
|
|
1936
2014
|
};
|
|
1937
|
-
function
|
|
2015
|
+
function vt(e, t, n) {
|
|
1938
2016
|
return t == null ? null : e ? e.copy(t, n) : z.fromInput(t, n);
|
|
1939
2017
|
}
|
|
1940
|
-
function
|
|
2018
|
+
function yt(e, t) {
|
|
1941
2019
|
let n = t instanceof K ? t.updateWorld().worldPosition : z.fromInput(t, `${e.constructor.name}.lookAt()`), r = e.parent;
|
|
1942
2020
|
return r ? n.applyMatrix4(r.updateWorld().worldMatrix.clone().invert()) : n;
|
|
1943
2021
|
}
|
|
1944
|
-
function
|
|
2022
|
+
function bt(e) {
|
|
1945
2023
|
return e instanceof K ? e : e && typeof e == "object" && "type" in e ? E("Node", `add() takes nodes - build one from a description with add(create({ type: '${e.type}', ... }))`) : E("Node", `add() expects nodes, got ${j(e)}`);
|
|
1946
2024
|
}
|
|
1947
|
-
function
|
|
1948
|
-
let t =
|
|
2025
|
+
function xt(e) {
|
|
2026
|
+
let t = ft(/* @__PURE__ */ new Float32Array(9), e);
|
|
1949
2027
|
for (let e = 0; e < 3; e++) {
|
|
1950
2028
|
let n = Math.hypot(t[e * 3], t[e * 3 + 1], t[e * 3 + 2]) || 1;
|
|
1951
2029
|
t[e * 3] /= n, t[e * 3 + 1] /= n, t[e * 3 + 2] /= n;
|
|
1952
2030
|
}
|
|
1953
2031
|
return t;
|
|
1954
2032
|
}
|
|
1955
|
-
var
|
|
2033
|
+
var St = class extends K {
|
|
1956
2034
|
static type = "group";
|
|
1957
|
-
},
|
|
2035
|
+
}, Ct = [
|
|
1958
2036
|
"center",
|
|
1959
2037
|
"above",
|
|
1960
2038
|
"below",
|
|
1961
2039
|
"left",
|
|
1962
2040
|
"right"
|
|
1963
|
-
],
|
|
2041
|
+
], wt = [
|
|
1964
2042
|
"place",
|
|
1965
2043
|
"offset",
|
|
1966
2044
|
"className",
|
|
@@ -1970,7 +2048,7 @@ var _t = class extends K {
|
|
|
1970
2048
|
"leader",
|
|
1971
2049
|
"edge",
|
|
1972
2050
|
"minScale"
|
|
1973
|
-
],
|
|
2051
|
+
], Tt = {
|
|
1974
2052
|
line: "use leader: true - a line from the point to the label",
|
|
1975
2053
|
callout: "use leader: true, with edge: 'left' | 'right' to line the labels up down the side",
|
|
1976
2054
|
column: "use edge: 'left' | 'right' - the label sits at that edge of the view, level with its point",
|
|
@@ -1981,14 +2059,14 @@ var _t = class extends K {
|
|
|
1981
2059
|
minZoom: "use 'minScale': CSS pixels to one world unit at the label's point",
|
|
1982
2060
|
lod: "use 'minScale': the label shows when zoomed in at least this far (CSS pixels to one world unit)",
|
|
1983
2061
|
collision: "use overlap: 'hide' | 'dim' | 'show'"
|
|
1984
|
-
},
|
|
1985
|
-
...
|
|
2062
|
+
}, Et = {
|
|
2063
|
+
...Tt,
|
|
1986
2064
|
position: "labels per instance sit on their instance - offset moves them in pixels"
|
|
1987
2065
|
};
|
|
1988
|
-
function
|
|
2066
|
+
function Dt(e, t) {
|
|
1989
2067
|
let n = t.offset ?? [0, 0];
|
|
1990
2068
|
return Array.isArray(n) && n.length === 2 && n.every(Number.isFinite) || E(e, `'offset' must be [x, y] in pixels, got ${j(n)}`), {
|
|
1991
|
-
place: t.place === void 0 ? "center" : P(e, "place", t.place,
|
|
2069
|
+
place: t.place === void 0 ? "center" : P(e, "place", t.place, Ct),
|
|
1992
2070
|
offset: [n[0], n[1]],
|
|
1993
2071
|
className: t.className ? String(t.className) : "",
|
|
1994
2072
|
priority: t.priority === void 0 ? 0 : M(e, "priority", t.priority),
|
|
@@ -2000,20 +2078,20 @@ function St(e, t) {
|
|
|
2000
2078
|
occlude: !!t.occlude,
|
|
2001
2079
|
leader: !!t.leader,
|
|
2002
2080
|
edge: t.edge == null ? null : P(e, "edge", t.edge, ["left", "right"]),
|
|
2003
|
-
minScale: t.minScale === void 0 ? 0 :
|
|
2081
|
+
minScale: t.minScale === void 0 ? 0 : Ot(e, t.minScale)
|
|
2004
2082
|
};
|
|
2005
2083
|
}
|
|
2006
|
-
function
|
|
2084
|
+
function Ot(e, t) {
|
|
2007
2085
|
let n = M(e, "minScale", t);
|
|
2008
2086
|
return n >= 0 || E(e, `'minScale' is CSS pixels to one world unit, 0 or more, got ${n}`), n;
|
|
2009
2087
|
}
|
|
2010
|
-
function
|
|
2088
|
+
function kt(e, t) {
|
|
2011
2089
|
if (t == null) return null;
|
|
2012
|
-
if (Array.isArray(t)) return t.length || E(e, "'labels' as a list needs at least one { text: (datum, index) => string, ... }"), t.map((t) =>
|
|
2090
|
+
if (Array.isArray(t)) return t.length || E(e, "'labels' as a list needs at least one { text: (datum, index) => string, ... }"), t.map((t) => kt(e, t));
|
|
2013
2091
|
(typeof t != "object" || typeof t.text != "function") && E(e, `'labels' must be { text: (datum, index) => string, ... }, got ${j(t)}`);
|
|
2014
2092
|
let n = t;
|
|
2015
|
-
for (let t of Object.keys(n)) t !== "text" && t !== "at" && !
|
|
2016
|
-
let r = n.at === void 0 ? "top" : P(e, "labels.at", n.at, ["top", "center"]), i = typeof n.priority == "function", a =
|
|
2093
|
+
for (let t of Object.keys(n)) t !== "text" && t !== "at" && !wt.includes(t) && E(e, `unknown labels option '${t}'${Et[t] ? ` - ${Et[t]}` : ` - expected text, at, ${wt.join(", ")}`}`);
|
|
2094
|
+
let r = n.at === void 0 ? "top" : P(e, "labels.at", n.at, ["top", "center"]), i = typeof n.priority == "function", a = Dt(e, i ? {
|
|
2017
2095
|
...n,
|
|
2018
2096
|
priority: 0
|
|
2019
2097
|
} : n);
|
|
@@ -2024,7 +2102,7 @@ function wt(e, t) {
|
|
|
2024
2102
|
priority: i ? n.priority : a.priority
|
|
2025
2103
|
};
|
|
2026
2104
|
}
|
|
2027
|
-
var
|
|
2105
|
+
var At = [
|
|
2028
2106
|
...G,
|
|
2029
2107
|
"geometry",
|
|
2030
2108
|
"material",
|
|
@@ -2033,13 +2111,13 @@ var Tt = [
|
|
|
2033
2111
|
"renderOrder",
|
|
2034
2112
|
"frustumCulled",
|
|
2035
2113
|
"data"
|
|
2036
|
-
],
|
|
2114
|
+
], jt = {
|
|
2037
2115
|
mesh: "pass 'geometry' and 'material' directly",
|
|
2038
2116
|
materials: "one 'material' per node - use a Group of meshes for several",
|
|
2039
2117
|
rows: "use 'data' - one row per instance or point"
|
|
2040
|
-
},
|
|
2041
|
-
static OPTIONS =
|
|
2042
|
-
static HINTS =
|
|
2118
|
+
}, Mt = class extends K {
|
|
2119
|
+
static OPTIONS = At;
|
|
2120
|
+
static HINTS = jt;
|
|
2043
2121
|
#e;
|
|
2044
2122
|
#t;
|
|
2045
2123
|
castShadow = !1;
|
|
@@ -2050,19 +2128,19 @@ var Tt = [
|
|
|
2050
2128
|
constructor(e) {
|
|
2051
2129
|
super(e);
|
|
2052
2130
|
let t = this.constructor.name;
|
|
2053
|
-
e && e.geometry !== void 0 || E(t, `'geometry' is required, e.g. new ${t}({ geometry: box(1), material: { color: 'orange' } })`), this.#e =
|
|
2131
|
+
e && e.geometry !== void 0 || E(t, `'geometry' is required, e.g. new ${t}({ geometry: box(1), material: { color: 'orange' } })`), this.#e = ct(e.geometry, t), this.#t = lt(e.material), e.castShadow !== void 0 && (this.castShadow = !!e.castShadow), e.receiveShadow !== void 0 && (this.receiveShadow = !!e.receiveShadow), e.renderOrder !== void 0 && (this.renderOrder = M(t, "renderOrder", e.renderOrder)), e.frustumCulled !== void 0 && (this.frustumCulled = !!e.frustumCulled), e.data !== void 0 && (this.data = e.data), this.checkGeometry();
|
|
2054
2132
|
}
|
|
2055
2133
|
get geometry() {
|
|
2056
2134
|
return this.#e;
|
|
2057
2135
|
}
|
|
2058
2136
|
set geometry(e) {
|
|
2059
|
-
this.#e =
|
|
2137
|
+
this.#e = ct(e, this.constructor.name), this.checkGeometry();
|
|
2060
2138
|
}
|
|
2061
2139
|
get material() {
|
|
2062
2140
|
return this.#t;
|
|
2063
2141
|
}
|
|
2064
2142
|
set material(e) {
|
|
2065
|
-
this.#t =
|
|
2143
|
+
this.#t = lt(e);
|
|
2066
2144
|
}
|
|
2067
2145
|
datumAt(e) {
|
|
2068
2146
|
return ("instanceMatrices" in this || this.drawMode !== "triangles") && Array.isArray(this.data) ? e === null ? null : this.data[e] ?? null : this.data ?? null;
|
|
@@ -2075,7 +2153,9 @@ var Tt = [
|
|
|
2075
2153
|
}
|
|
2076
2154
|
checkGeometry() {}
|
|
2077
2155
|
expandBounds(e) {
|
|
2078
|
-
|
|
2156
|
+
if (!this.geometry.vertexCount) return e;
|
|
2157
|
+
let t = this.geometry.bounds.clone().applyMatrix4(this.worldMatrix);
|
|
2158
|
+
return e.union(Wt(t, this.material)), e;
|
|
2079
2159
|
}
|
|
2080
2160
|
cloneOptions() {
|
|
2081
2161
|
return {
|
|
@@ -2098,36 +2178,36 @@ var Tt = [
|
|
|
2098
2178
|
}
|
|
2099
2179
|
dispose() {
|
|
2100
2180
|
this.geometry.dispose(), this.material.dispose();
|
|
2101
|
-
for (let [, e] of this.material.
|
|
2181
|
+
for (let [, e] of this.material.allTextures) e.dispose();
|
|
2102
2182
|
super.dispose();
|
|
2103
2183
|
}
|
|
2104
|
-
},
|
|
2184
|
+
}, Nt = class extends Mt {
|
|
2105
2185
|
static type = "mesh";
|
|
2106
2186
|
checkGeometry() {
|
|
2107
2187
|
let e = this.geometry.elementCount;
|
|
2108
2188
|
e % 3 != 0 && E("Mesh", `geometry has ${e} ${this.geometry.indices ? "indices" : "vertices"}, not a multiple of 3 - triangles need three each (use Lines for pairs, Points for single vertices)`);
|
|
2109
2189
|
}
|
|
2110
|
-
},
|
|
2190
|
+
}, Pt = /* @__PURE__ */ new Set([
|
|
2111
2191
|
"position",
|
|
2112
2192
|
"rotation",
|
|
2113
2193
|
"quaternion",
|
|
2114
2194
|
"scale",
|
|
2115
2195
|
"color"
|
|
2116
|
-
]),
|
|
2196
|
+
]), Ft = {
|
|
2117
2197
|
position: new z(),
|
|
2118
2198
|
scale: new z(),
|
|
2119
2199
|
quaternion: new Ne(),
|
|
2120
2200
|
rotation: new Te()
|
|
2121
|
-
},
|
|
2122
|
-
function
|
|
2201
|
+
}, It = new H(), Lt = /* @__PURE__ */ new Float32Array(16);
|
|
2202
|
+
function Rt(e, t) {
|
|
2123
2203
|
let n = t * 16;
|
|
2124
2204
|
return !e[n] && !e[n + 1] && !e[n + 2] && !e[n + 4] && !e[n + 5] && !e[n + 6] && !e[n + 8] && !e[n + 9] && !e[n + 10];
|
|
2125
2205
|
}
|
|
2126
|
-
var
|
|
2206
|
+
var zt = class extends Nt {
|
|
2127
2207
|
static type = "instanced-mesh";
|
|
2128
2208
|
static get OPTIONS() {
|
|
2129
2209
|
return [
|
|
2130
|
-
...
|
|
2210
|
+
...At,
|
|
2131
2211
|
"count",
|
|
2132
2212
|
"instances",
|
|
2133
2213
|
"instanceMatrices",
|
|
@@ -2141,7 +2221,7 @@ var Pt = class extends Ot {
|
|
|
2141
2221
|
version = 0;
|
|
2142
2222
|
labels = null;
|
|
2143
2223
|
constructor(e) {
|
|
2144
|
-
super(e), this.labels =
|
|
2224
|
+
super(e), this.labels = kt("InstancedMesh", e.labels);
|
|
2145
2225
|
let t = e.count ?? e.instances?.length ?? (Array.isArray(e.data) ? e.data.length : void 0);
|
|
2146
2226
|
(!Number.isInteger(t) || t < 0) && E("InstancedMesh", `'count' must be a whole number, got ${j(t)}`), this.count = t, this.instanceMatrices = new Float32Array(t * 16);
|
|
2147
2227
|
let n = this.instanceMatrices;
|
|
@@ -2150,11 +2230,11 @@ var Pt = class extends Ot {
|
|
|
2150
2230
|
}
|
|
2151
2231
|
setInstance(e, t) {
|
|
2152
2232
|
this.#e(e);
|
|
2153
|
-
for (let e in t)
|
|
2154
|
-
let { position: n, scale: r, quaternion: i } =
|
|
2233
|
+
for (let e in t) Pt.has(e) || E("InstancedMesh", `unknown instance option '${e}' - expected position, rotation, quaternion, scale or color`);
|
|
2234
|
+
let { position: n, scale: r, quaternion: i } = Ft;
|
|
2155
2235
|
if (t.position === void 0 ? n.set(0, 0, 0) : n.copy(t.position, "InstancedMesh"), t.scale === void 0 ? r.set(1, 1, 1) : typeof t.scale == "number" ? r.set(t.scale, t.scale, t.scale) : r.copy(t.scale, "InstancedMesh"), i.set(0, 0, 0, 1), t.quaternion) i.copy(t.quaternion, "InstancedMesh").normalize();
|
|
2156
2236
|
else if (t.rotation) {
|
|
2157
|
-
let e = t.rotation instanceof Te ? t.rotation :
|
|
2237
|
+
let e = t.rotation instanceof Te ? t.rotation : Ft.rotation.copy(t.rotation, "InstancedMesh");
|
|
2158
2238
|
i.setFromEuler(e.x, e.y, e.z);
|
|
2159
2239
|
}
|
|
2160
2240
|
return u(this.instanceMatrices.subarray(e * 16, e * 16 + 16), i, n, r), t.color !== void 0 && this.#t(e, t.color), this.version++, this;
|
|
@@ -2169,18 +2249,19 @@ var Pt = class extends Ot {
|
|
|
2169
2249
|
(!Number.isInteger(e) || e < 0 || e >= this.instanceMatrices.length / 16) && E("InstancedMesh", `instance ${j(e)} is out of range 0-${this.instanceMatrices.length / 16 - 1}`);
|
|
2170
2250
|
}
|
|
2171
2251
|
#t(e, t) {
|
|
2172
|
-
this.instanceColors ||= new Float32Array(this.instanceMatrices.length / 16 * 3).fill(1), this.instanceColors.set(
|
|
2252
|
+
this.instanceColors ||= new Float32Array(this.instanceMatrices.length / 16 * 3).fill(1), this.instanceColors.set(It.set(t, "InstancedMesh"), e * 3);
|
|
2173
2253
|
}
|
|
2174
2254
|
expandBounds(e) {
|
|
2175
|
-
|
|
2176
|
-
|
|
2255
|
+
let t = this.material.shader?.vertex ? this.material.shader.bounds ?? 0 : 0;
|
|
2256
|
+
return this.eachInstanceBox((n, r, i, a, o, s) => {
|
|
2257
|
+
e.expandByXYZ(n - t, r - t, i - t), e.expandByXYZ(a + t, o + t, s + t);
|
|
2177
2258
|
}), e;
|
|
2178
2259
|
}
|
|
2179
2260
|
eachInstanceBox(e) {
|
|
2180
2261
|
if (!this.count || !this.geometry.vertexCount) return;
|
|
2181
|
-
let t = this.geometry.bounds, n = (t.min[0] + t.max[0]) / 2, r = (t.min[1] + t.max[1]) / 2, i = (t.min[2] + t.max[2]) / 2, a = (t.max[0] - t.min[0]) / 2, o = (t.max[1] - t.min[1]) / 2, c = (t.max[2] - t.min[2]) / 2, l = this.worldMatrix, u = this.instanceMatrices, d =
|
|
2262
|
+
let t = this.geometry.bounds, n = (t.min[0] + t.max[0]) / 2, r = (t.min[1] + t.max[1]) / 2, i = (t.min[2] + t.max[2]) / 2, a = (t.max[0] - t.min[0]) / 2, o = (t.max[1] - t.min[1]) / 2, c = (t.max[2] - t.min[2]) / 2, l = this.worldMatrix, u = this.instanceMatrices, d = Lt;
|
|
2182
2263
|
for (let t = 0; t < this.count; t++) {
|
|
2183
|
-
if (
|
|
2264
|
+
if (Rt(u, t)) continue;
|
|
2184
2265
|
s(d, l, u.subarray(t * 16, t * 16 + 16));
|
|
2185
2266
|
let f = d[0] * n + d[4] * r + d[8] * i + d[12], p = d[1] * n + d[5] * r + d[9] * i + d[13], m = d[2] * n + d[6] * r + d[10] * i + d[14], h = Math.abs(d[0]) * a + Math.abs(d[4]) * o + Math.abs(d[8]) * c, g = Math.abs(d[1]) * a + Math.abs(d[5]) * o + Math.abs(d[9]) * c, _ = Math.abs(d[2]) * a + Math.abs(d[6]) * o + Math.abs(d[10]) * c;
|
|
2186
2267
|
e(f - h, p - g, m - _, f + h, p + g, m + _);
|
|
@@ -2205,11 +2286,11 @@ var Pt = class extends Ot {
|
|
|
2205
2286
|
...this.instanceColors ? { instanceColors: Array.from(this.instanceColors) } : {}
|
|
2206
2287
|
};
|
|
2207
2288
|
}
|
|
2208
|
-
},
|
|
2289
|
+
}, Bt = class extends Mt {
|
|
2209
2290
|
static type = "points";
|
|
2210
2291
|
static get OPTIONS() {
|
|
2211
2292
|
return [
|
|
2212
|
-
...
|
|
2293
|
+
...At,
|
|
2213
2294
|
"labels",
|
|
2214
2295
|
"sort"
|
|
2215
2296
|
];
|
|
@@ -2217,7 +2298,7 @@ var Pt = class extends Ot {
|
|
|
2217
2298
|
labels = null;
|
|
2218
2299
|
sort = !1;
|
|
2219
2300
|
constructor(e) {
|
|
2220
|
-
super(e), this.labels =
|
|
2301
|
+
super(e), this.labels = kt(this.constructor.name, e?.labels), e?.sort !== void 0 && (typeof e.sort != "boolean" && E(this.constructor.name, `'sort' is true or false, got ${j(e.sort)}`), this.sort = e.sort);
|
|
2221
2302
|
}
|
|
2222
2303
|
get drawsSprites() {
|
|
2223
2304
|
let e = this.geometry;
|
|
@@ -2239,16 +2320,16 @@ var Pt = class extends Ot {
|
|
|
2239
2320
|
get drawMode() {
|
|
2240
2321
|
return "points";
|
|
2241
2322
|
}
|
|
2242
|
-
},
|
|
2323
|
+
}, Vt = [
|
|
2243
2324
|
"none",
|
|
2244
2325
|
"start",
|
|
2245
2326
|
"end",
|
|
2246
2327
|
"both"
|
|
2247
|
-
],
|
|
2328
|
+
], Ht = class extends Mt {
|
|
2248
2329
|
static type = "lines";
|
|
2249
2330
|
static get OPTIONS() {
|
|
2250
2331
|
return [
|
|
2251
|
-
...
|
|
2332
|
+
...At,
|
|
2252
2333
|
"arrows",
|
|
2253
2334
|
"arrowSize"
|
|
2254
2335
|
];
|
|
@@ -2256,10 +2337,10 @@ var Pt = class extends Ot {
|
|
|
2256
2337
|
arrows = "none";
|
|
2257
2338
|
arrowSize = 0;
|
|
2258
2339
|
constructor(e) {
|
|
2259
|
-
super(e), e?.arrows !== void 0 && (this.arrows = P("Lines", "arrows", e.arrows,
|
|
2340
|
+
super(e), e?.arrows !== void 0 && (this.arrows = P("Lines", "arrows", e.arrows, Vt)), e?.arrowSize !== void 0 && (this.arrowSize = Math.max(0, M("Lines", "arrowSize", e.arrowSize)));
|
|
2260
2341
|
}
|
|
2261
2342
|
get arrowBits() {
|
|
2262
|
-
return
|
|
2343
|
+
return Vt.indexOf(this.arrows);
|
|
2263
2344
|
}
|
|
2264
2345
|
arrowPixels(e) {
|
|
2265
2346
|
return this.arrowSize || 6 + e * 3;
|
|
@@ -2285,17 +2366,17 @@ var Pt = class extends Ot {
|
|
|
2285
2366
|
let e = this.geometry.elementCount;
|
|
2286
2367
|
e % 2 != 0 && E("Lines", `geometry has ${e} ${this.geometry.indices ? "indices" : "vertices"} - segments need them in pairs`);
|
|
2287
2368
|
}
|
|
2288
|
-
},
|
|
2369
|
+
}, Ut = class extends K {
|
|
2289
2370
|
static type = "label";
|
|
2290
2371
|
static get OPTIONS() {
|
|
2291
2372
|
return [
|
|
2292
2373
|
...G,
|
|
2293
2374
|
"text",
|
|
2294
|
-
...
|
|
2375
|
+
...wt
|
|
2295
2376
|
];
|
|
2296
2377
|
}
|
|
2297
2378
|
static get HINTS() {
|
|
2298
|
-
return
|
|
2379
|
+
return Tt;
|
|
2299
2380
|
}
|
|
2300
2381
|
text = "";
|
|
2301
2382
|
className = "";
|
|
@@ -2308,7 +2389,7 @@ var Pt = class extends Ot {
|
|
|
2308
2389
|
edge = null;
|
|
2309
2390
|
minScale = 0;
|
|
2310
2391
|
constructor(e) {
|
|
2311
|
-
super(e), typeof e?.text != "string" && typeof e?.text != "number" && E("Label", `'text' is required, got ${j(e?.text)}`), this.text = String(e.text), Object.assign(this,
|
|
2392
|
+
super(e), typeof e?.text != "string" && typeof e?.text != "number" && E("Label", `'text' is required, got ${j(e?.text)}`), this.text = String(e.text), Object.assign(this, Dt("Label", e));
|
|
2312
2393
|
}
|
|
2313
2394
|
get isLabel() {
|
|
2314
2395
|
return !0;
|
|
@@ -2335,13 +2416,19 @@ var Pt = class extends Ot {
|
|
|
2335
2416
|
let e = { text: this.text };
|
|
2336
2417
|
return this.className && (e.className = this.className), this.place !== "center" && (e.place = this.place), (this.offset[0] || this.offset[1]) && (e.offset = [...this.offset]), this.priority && (e.priority = this.priority), this.overlap !== "hide" && (e.overlap = this.overlap), this.occlude && (e.occlude = !0), this.leader && (e.leader = !0), this.edge && (e.edge = this.edge), this.minScale && (e.minScale = this.minScale), e;
|
|
2337
2418
|
}
|
|
2338
|
-
}
|
|
2419
|
+
};
|
|
2420
|
+
function Wt(e, t) {
|
|
2421
|
+
let n = t.shader?.vertex ? t.shader.bounds ?? 0 : 0;
|
|
2422
|
+
return n > 0 && !e.isEmpty() && (e.min.set(e.min[0] - n, e.min[1] - n, e.min[2] - n), e.max.set(e.max[0] + n, e.max[1] + n, e.max[2] + n)), e;
|
|
2423
|
+
}
|
|
2424
|
+
// src/frame.js
|
|
2425
|
+
var Gt = {
|
|
2339
2426
|
punctual: 4,
|
|
2340
2427
|
directional: 2
|
|
2341
2428
|
};
|
|
2342
|
-
function
|
|
2429
|
+
function Kt(e, t) {
|
|
2343
2430
|
t.updateWorld();
|
|
2344
|
-
let n = t.viewMatrix, r = t.projectionMatrix, i = new B().multiplyMatrices(r, n), a =
|
|
2431
|
+
let n = t.viewMatrix, r = t.projectionMatrix, i = new B().multiplyMatrices(r, n), a = tn(i), o = {
|
|
2345
2432
|
camera: {
|
|
2346
2433
|
view: n,
|
|
2347
2434
|
projection: r,
|
|
@@ -2368,6 +2455,7 @@ function Bt(e, t) {
|
|
|
2368
2455
|
drawn: 0,
|
|
2369
2456
|
culled: 0
|
|
2370
2457
|
},
|
|
2458
|
+
time: 0,
|
|
2371
2459
|
highlight: null,
|
|
2372
2460
|
overlays: [],
|
|
2373
2461
|
interactive: !1,
|
|
@@ -2385,14 +2473,14 @@ function Bt(e, t) {
|
|
|
2385
2473
|
items: []
|
|
2386
2474
|
}, o.outlines.push(c)), e.overlay && o.overlays.push(e.overlay), e.onDrag && (o.interactive = o.draggable = !0), e.tooltip ? o.interactive = o.tooltips = !0 : (e.highlight || e.handlersFor("hover").length || e.handlersFor("click").length) && (o.interactive = !0), e.isDrawable) {
|
|
2387
2475
|
e.castShadow && e.drawMode !== "points" && e.drawMode !== "lines" && l.push([e, s]), e.receiveShadow && u.push(e);
|
|
2388
|
-
let t =
|
|
2476
|
+
let t = qt(e, n, a, s);
|
|
2389
2477
|
if (t) {
|
|
2390
2478
|
let a = e.material.transparent || e.drawMode === "points" && e.material.map;
|
|
2391
2479
|
if ((a ? o.transparent : o.opaque).push(t), c && e.drawMode === "triangles" && c.items.push(t), t.clip?.cap && !a) {
|
|
2392
2480
|
let e = d.get(t.clip);
|
|
2393
2481
|
e ? e.push(t) : d.set(t.clip, [t]);
|
|
2394
2482
|
}
|
|
2395
|
-
o.stats.drawn++, e.labels &&
|
|
2483
|
+
o.stats.drawn++, e.labels && Zt(e, i, n, r[5], o.labels);
|
|
2396
2484
|
} else o.stats.culled++;
|
|
2397
2485
|
} else if (e.isLabel) {
|
|
2398
2486
|
let t = e.worldPosition;
|
|
@@ -2403,7 +2491,7 @@ function Bt(e, t) {
|
|
|
2403
2491
|
text: e.text,
|
|
2404
2492
|
style: e,
|
|
2405
2493
|
position: t,
|
|
2406
|
-
...
|
|
2494
|
+
...en(t, i, n, r[5])
|
|
2407
2495
|
});
|
|
2408
2496
|
} else e.lightKind && p(e);
|
|
2409
2497
|
for (let t of e.children) f(t, s, c);
|
|
@@ -2421,14 +2509,14 @@ function Bt(e, t) {
|
|
|
2421
2509
|
color: t.sky,
|
|
2422
2510
|
ground: t.ground,
|
|
2423
2511
|
intensity: t.intensity
|
|
2424
|
-
}) : n === "directional" ? ++c >
|
|
2512
|
+
}) : n === "directional" ? ++c > Gt.directional ? F(e, `more than ${Gt.directional} directional lights - the extras are ignored; use scene.environment for more light`) : o.lights.push({
|
|
2425
2513
|
kind: "directional",
|
|
2426
2514
|
node: t,
|
|
2427
2515
|
color: t.color,
|
|
2428
2516
|
intensity: t.intensity,
|
|
2429
2517
|
direction: t.worldDirection,
|
|
2430
2518
|
castShadow: t.castShadow
|
|
2431
|
-
}) : ++s >
|
|
2519
|
+
}) : ++s > Gt.punctual ? F(e, `more than ${Gt.punctual} point and spot lights - the extras are ignored`) : n === "spot" ? o.lights.push({
|
|
2432
2520
|
kind: "spot",
|
|
2433
2521
|
node: t,
|
|
2434
2522
|
color: t.color,
|
|
@@ -2451,17 +2539,17 @@ function Bt(e, t) {
|
|
|
2451
2539
|
});
|
|
2452
2540
|
};
|
|
2453
2541
|
f(e, null, null), o.outlines = o.outlines.filter((e) => e.items.length);
|
|
2454
|
-
for (let [e, t] of d) o.caps.push(
|
|
2455
|
-
let m = o.lights.findIndex((e) => e.kind === "directional" && e.castShadow), h = o.lights.filter((e) => e.kind === "spot" && e.castShadow), g = o.lights.filter((e) => e.kind === "point" && e.castShadow), _ = m >= 0 || h.length || g.length ? l.map(([e, t]) =>
|
|
2542
|
+
for (let [e, t] of d) o.caps.push(Jt(e, t));
|
|
2543
|
+
let m = o.lights.findIndex((e) => e.kind === "directional" && e.castShadow), h = o.lights.filter((e) => e.kind === "spot" && e.castShadow), g = o.lights.filter((e) => e.kind === "point" && e.castShadow), _ = m >= 0 || h.length || g.length ? l.map(([e, t]) => qt(e, n, null, t)).filter(Boolean) : [];
|
|
2456
2544
|
if (h.length > 4 && F(e, "more than 4 spot lights cast shadows - the extras don't"), g.length > 1 && F(e, "more than one point light casts shadows - only the first does"), _.length && g.length) {
|
|
2457
2545
|
let e = g[0], t = _.map((e) => e.node.expandBounds(new V())), n = le(e.position, e.range ?? 0, t, u.map((e) => e.expandBounds(new V())));
|
|
2458
2546
|
n && (o.pointShadow = {
|
|
2459
2547
|
light: e,
|
|
2460
2548
|
faces: n.viewProjections.map((e) => {
|
|
2461
|
-
let n =
|
|
2549
|
+
let n = tn(e);
|
|
2462
2550
|
return {
|
|
2463
2551
|
viewProjection: e,
|
|
2464
|
-
casters: _.filter((e, r) =>
|
|
2552
|
+
casters: _.filter((e, r) => nn(n, t[r].getCenter(), t[r].getRadius()))
|
|
2465
2553
|
};
|
|
2466
2554
|
}),
|
|
2467
2555
|
near: n.near,
|
|
@@ -2474,10 +2562,10 @@ function Bt(e, t) {
|
|
|
2474
2562
|
for (let n of h.slice(0, 4)) {
|
|
2475
2563
|
let r = n.position, i = e.map((e) => e.containsPoint(r)), a = oe(r, n.direction, n.angle, n.range ?? 0, e.filter((e, t) => !i[t]), t);
|
|
2476
2564
|
if (!a) continue;
|
|
2477
|
-
let s =
|
|
2565
|
+
let s = tn(a.viewProjection), c = _.filter((t, n) => {
|
|
2478
2566
|
if (i[n]) return !1;
|
|
2479
2567
|
let r = e[n];
|
|
2480
|
-
return
|
|
2568
|
+
return nn(s, r.getCenter(), r.getRadius());
|
|
2481
2569
|
});
|
|
2482
2570
|
n.shadowTile = o.spotShadows.length, o.spotShadows.push({
|
|
2483
2571
|
light: n,
|
|
@@ -2498,14 +2586,14 @@ function Bt(e, t) {
|
|
|
2498
2586
|
}
|
|
2499
2587
|
return o.opaque.sort((e, t) => e.node.renderOrder - t.node.renderOrder || (e.material.variant < t.material.variant ? -1 : +(e.material.variant > t.material.variant)) || e.depth - t.depth), o.transparent.sort((e, t) => e.node.renderOrder - t.node.renderOrder || t.depth - e.depth), o;
|
|
2500
2588
|
}
|
|
2501
|
-
function
|
|
2589
|
+
function qt(e, t, n, r) {
|
|
2502
2590
|
let { geometry: i, material: a, worldMatrix: o } = e, s = "instanceMatrices" in e ? e : null;
|
|
2503
2591
|
if (s && s.count === 0 || !i.vertexCount) return null;
|
|
2504
|
-
let c = i.bounds, l = c.getCenter().applyMatrix4(o), u = Math.max(Math.hypot(o[0], o[1], o[2]), Math.hypot(o[4], o[5], o[6]), Math.hypot(o[8], o[9], o[10]));
|
|
2505
|
-
if (n && e.frustumCulled && !s && !
|
|
2506
|
-
let
|
|
2507
|
-
if (
|
|
2508
|
-
let e =
|
|
2592
|
+
let c = i.bounds, l = c.getCenter().applyMatrix4(o), u = Math.max(Math.hypot(o[0], o[1], o[2]), Math.hypot(o[4], o[5], o[6]), Math.hypot(o[8], o[9], o[10])), d = a.shader?.vertex ? a.shader : null, f = d ? d.bounds : 0;
|
|
2593
|
+
if (n && e.frustumCulled && !s && f !== null && !nn(n, l, c.getRadius() * u + f)) return null;
|
|
2594
|
+
let p = r && e.drawMode === "triangles" ? r : null;
|
|
2595
|
+
if (p && !s) {
|
|
2596
|
+
let e = p.plane;
|
|
2509
2597
|
if (e[0] * l[0] + e[1] * l[1] + e[2] * l[2] + e[3] > c.getRadius() * u) return null;
|
|
2510
2598
|
}
|
|
2511
2599
|
return {
|
|
@@ -2515,10 +2603,10 @@ function Vt(e, t, n, r) {
|
|
|
2515
2603
|
worldMatrix: o,
|
|
2516
2604
|
instances: s,
|
|
2517
2605
|
depth: -(t[2] * l[0] + t[6] * l[1] + t[10] * l[2] + t[14]),
|
|
2518
|
-
clip:
|
|
2606
|
+
clip: p
|
|
2519
2607
|
};
|
|
2520
2608
|
}
|
|
2521
|
-
function
|
|
2609
|
+
function Jt(e, t) {
|
|
2522
2610
|
let n = new V();
|
|
2523
2611
|
for (let e of t) e.node.expandBounds(n);
|
|
2524
2612
|
let r = n.getCenter(), i = e.plane, a = i[0] * r[0] + i[1] * r[1] + i[2] * r[2] + i[3], o = new z(r[0] - i[0] * a, r[1] - i[1] * a, r[2] - i[2] * a);
|
|
@@ -2530,13 +2618,13 @@ function Ht(e, t) {
|
|
|
2530
2618
|
radius: n.getRadius()
|
|
2531
2619
|
};
|
|
2532
2620
|
}
|
|
2533
|
-
var
|
|
2534
|
-
function
|
|
2535
|
-
Array.isArray(e.labels) ? e.labels.forEach((a, o) =>
|
|
2621
|
+
var Yt = /* @__PURE__ */ new WeakMap(), Xt = 1;
|
|
2622
|
+
function Zt(e, t, n, r, i) {
|
|
2623
|
+
Array.isArray(e.labels) ? e.labels.forEach((a, o) => Qt(e, a, o, t, n, r, i)) : Qt(e, e.labels, 0, t, n, r, i);
|
|
2536
2624
|
}
|
|
2537
|
-
function
|
|
2538
|
-
let { worldMatrix: s } = e, c =
|
|
2539
|
-
c === void 0 &&
|
|
2625
|
+
function Qt(e, t, n, r, i, a, o) {
|
|
2626
|
+
let { worldMatrix: s } = e, c = Yt.get(e);
|
|
2627
|
+
c === void 0 && Yt.set(e, c = Xt++);
|
|
2540
2628
|
let l = "instanceMatrices" in e, u = l ? e.count : e.geometry.drawnVertices, d = 0, f = 0, p = 0;
|
|
2541
2629
|
if (l) {
|
|
2542
2630
|
let n = e.geometry.bounds, r = n.getCenter();
|
|
@@ -2544,7 +2632,7 @@ function Kt(e, t, n, r, i, a, o) {
|
|
|
2544
2632
|
}
|
|
2545
2633
|
let m = Array.isArray(e.data) ? e.data : null, h = typeof t.priority == "function";
|
|
2546
2634
|
for (let g = 0; g < u; g++) {
|
|
2547
|
-
if (l &&
|
|
2635
|
+
if (l && Rt(e.instanceMatrices, g)) continue;
|
|
2548
2636
|
let u = m ? m[g] : null, _ = t.text(u, g);
|
|
2549
2637
|
if (_ == null || _ === "") continue;
|
|
2550
2638
|
let v, y, b;
|
|
@@ -2566,11 +2654,11 @@ function Kt(e, t, n, r, i, a, o) {
|
|
|
2566
2654
|
text: String(_),
|
|
2567
2655
|
style: S,
|
|
2568
2656
|
position: x,
|
|
2569
|
-
...
|
|
2657
|
+
...en(x, r, i, a)
|
|
2570
2658
|
});
|
|
2571
2659
|
}
|
|
2572
2660
|
}
|
|
2573
|
-
function
|
|
2661
|
+
function $t(e, t) {
|
|
2574
2662
|
let n = t, r = n[0] * e[0] + n[4] * e[1] + n[8] * e[2] + n[12], i = n[1] * e[0] + n[5] * e[1] + n[9] * e[2] + n[13], a = n[2] * e[0] + n[6] * e[1] + n[10] * e[2] + n[14], o = n[3] * e[0] + n[7] * e[1] + n[11] * e[2] + n[15], s = [
|
|
2575
2663
|
r / o,
|
|
2576
2664
|
i / o,
|
|
@@ -2581,8 +2669,8 @@ function qt(e, t) {
|
|
|
2581
2669
|
visible: o > 0 && Math.abs(s[0]) <= 1 && Math.abs(s[1]) <= 1 && Math.abs(s[2]) <= 1
|
|
2582
2670
|
};
|
|
2583
2671
|
}
|
|
2584
|
-
function
|
|
2585
|
-
let { ndc: i, visible: a } =
|
|
2672
|
+
function en(e, t, n, r) {
|
|
2673
|
+
let { ndc: i, visible: a } = $t(e, t), o = -(n[2] * e[0] + n[6] * e[1] + n[10] * e[2] + n[14]), s = t, c = s[3] * e[0] + s[7] * e[1] + s[11] * e[2] + s[15];
|
|
2586
2674
|
return {
|
|
2587
2675
|
ndc: [i[0], i[1]],
|
|
2588
2676
|
depth: o,
|
|
@@ -2590,7 +2678,7 @@ function Jt(e, t, n, r) {
|
|
|
2590
2678
|
scale: c > 0 ? r / c : 0
|
|
2591
2679
|
};
|
|
2592
2680
|
}
|
|
2593
|
-
function
|
|
2681
|
+
function tn(e) {
|
|
2594
2682
|
let t = (t) => [
|
|
2595
2683
|
e[t],
|
|
2596
2684
|
e[4 + t],
|
|
@@ -2644,27 +2732,27 @@ function Yt(e) {
|
|
|
2644
2732
|
]);
|
|
2645
2733
|
});
|
|
2646
2734
|
}
|
|
2647
|
-
function
|
|
2735
|
+
function nn(e, t, n) {
|
|
2648
2736
|
for (let r of e) if (r[0] * t[0] + r[1] * t[1] + r[2] * t[2] + r[3] < -n) return !1;
|
|
2649
2737
|
return !0;
|
|
2650
2738
|
}
|
|
2651
|
-
var
|
|
2739
|
+
var rn = class {
|
|
2652
2740
|
lastFrame = null;
|
|
2653
2741
|
frameCount = 0;
|
|
2654
2742
|
render(e, t) {
|
|
2655
|
-
return e.updateWorldTree(), this.renderFrame(
|
|
2743
|
+
return e.updateWorldTree(), this.renderFrame(Kt(e, t));
|
|
2656
2744
|
}
|
|
2657
2745
|
renderFrame(e) {
|
|
2658
2746
|
return this.lastFrame = e, this.frameCount++, e;
|
|
2659
2747
|
}
|
|
2660
2748
|
dispose() {}
|
|
2661
|
-
},
|
|
2662
|
-
function
|
|
2663
|
-
if (o) return [o === "left" ?
|
|
2749
|
+
}, an = 6, on = 16, sn = 64, cn = .2, ln = .5;
|
|
2750
|
+
function un(e, t, n, r, i, a, o = null, s = 0) {
|
|
2751
|
+
if (o) return [o === "left" ? on + a[0] : s - on - n - a[0], t - r / 2 + a[1]];
|
|
2664
2752
|
let c = e - n / 2, l = t - r / 2;
|
|
2665
|
-
return i === "above" ? l = t - r -
|
|
2753
|
+
return i === "above" ? l = t - r - an : i === "below" ? l = t + an : i === "left" ? c = e - n - an : i === "right" && (c = e + an), [c + a[0], l + a[1]];
|
|
2666
2754
|
}
|
|
2667
|
-
function
|
|
2755
|
+
function dn(e, t, n = 4) {
|
|
2668
2756
|
for (let r of ["left", "right"]) {
|
|
2669
2757
|
let i = e.filter((e) => e.edge === r).sort((e, t) => e.top - t.top), a = [];
|
|
2670
2758
|
for (let e of i) {
|
|
@@ -2696,23 +2784,23 @@ function an(e, t, n = 4) {
|
|
|
2696
2784
|
}
|
|
2697
2785
|
}
|
|
2698
2786
|
}
|
|
2699
|
-
function
|
|
2787
|
+
function fn(e) {
|
|
2700
2788
|
for (let t of ["left", "right"]) {
|
|
2701
2789
|
let n = e.filter((e) => e.edge === t), r = Math.max(0, ...n.map((e) => e.width));
|
|
2702
2790
|
for (let e of n) t === "right" && (e.left -= r - e.width), e.width = r;
|
|
2703
2791
|
}
|
|
2704
2792
|
}
|
|
2705
|
-
function
|
|
2793
|
+
function pn(e, t, n, r = null, i = 0) {
|
|
2706
2794
|
if (r) return [r === "left" ? n.left + n.width : n.left, n.top + n.height - i / 2];
|
|
2707
2795
|
let a = Math.min(Math.max(e, n.left), n.left + n.width), o = Math.min(Math.max(t, n.top), n.top + n.height);
|
|
2708
2796
|
return Math.hypot(a - e, o - t) < 2 ? null : [a, o];
|
|
2709
2797
|
}
|
|
2710
|
-
function
|
|
2798
|
+
function mn(e) {
|
|
2711
2799
|
let t = e.map((e, t) => t).sort((t, n) => {
|
|
2712
2800
|
let r = e[t], i = e[n];
|
|
2713
2801
|
return +(i.overlap === "show") - (r.overlap === "show") || i.priority - r.priority || +!!i.sticky - !!r.sticky || r.depth - i.depth || t - n;
|
|
2714
2802
|
}), n = Array(e.length).fill("hide"), r = /* @__PURE__ */ new Map(), i = (e, t) => {
|
|
2715
|
-
let n = Math.floor(e.left /
|
|
2803
|
+
let n = Math.floor(e.left / sn), r = Math.floor((e.left + e.width) / sn), i = Math.floor(e.top / sn), a = Math.floor((e.top + e.height) / sn);
|
|
2716
2804
|
for (let e = n; e <= r; e++) for (let n = i; n <= a; n++) t(`${e},${n}`);
|
|
2717
2805
|
}, a = (e, t) => {
|
|
2718
2806
|
let n = Math.min(e.left + e.width, t.left + t.width) - Math.max(e.left, t.left), r = Math.min(e.top + e.height, t.top + t.height) - Math.max(e.top, t.top);
|
|
@@ -2721,7 +2809,7 @@ function cn(e) {
|
|
|
2721
2809
|
for (let o of t) {
|
|
2722
2810
|
let t = e[o];
|
|
2723
2811
|
if (t.overlap !== "show") {
|
|
2724
|
-
let e = t.sticky ?
|
|
2812
|
+
let e = t.sticky ? ln : cn, s = !!t.covered;
|
|
2725
2813
|
if (i(t, (n) => {
|
|
2726
2814
|
s ||= (r.get(n) ?? []).some((n) => a(t, n) > e);
|
|
2727
2815
|
}), s) {
|
|
@@ -2737,7 +2825,7 @@ function cn(e) {
|
|
|
2737
2825
|
return n;
|
|
2738
2826
|
}
|
|
2739
2827
|
// src/labels.js
|
|
2740
|
-
var
|
|
2828
|
+
var hn = "http://www.w3.org/2000/svg", gn = "0.4", _n = class {
|
|
2741
2829
|
#e = null;
|
|
2742
2830
|
#t = /* @__PURE__ */ new Map();
|
|
2743
2831
|
shown = [];
|
|
@@ -2776,7 +2864,7 @@ var ln = "http://www.w3.org/2000/svg", un = "0.4", dn = class {
|
|
|
2776
2864
|
for (let { entry: e } of o) e.width < 0 && (e.el.style.display = "");
|
|
2777
2865
|
for (let { entry: e } of o) e.width >= 0 || (e.el.style.minWidth = "", e.width = e.el.offsetWidth, e.height = e.el.offsetHeight);
|
|
2778
2866
|
let s = o.map(({ label: e, entry: t }) => {
|
|
2779
|
-
let n = (e.ndc[0] * .5 + .5) * i.width, r = (.5 - e.ndc[1] * .5) * i.height, [a, o] =
|
|
2867
|
+
let n = (e.ndc[0] * .5 + .5) * i.width, r = (.5 - e.ndc[1] * .5) * i.height, [a, o] = un(n, r, t.width, t.height, e.style.place, e.style.offset, e.style.edge, i.width);
|
|
2780
2868
|
return {
|
|
2781
2869
|
left: a,
|
|
2782
2870
|
top: o,
|
|
@@ -2792,8 +2880,8 @@ var ln = "http://www.w3.org/2000/svg", un = "0.4", dn = class {
|
|
|
2792
2880
|
edge: e.style.edge
|
|
2793
2881
|
};
|
|
2794
2882
|
});
|
|
2795
|
-
|
|
2796
|
-
let c =
|
|
2883
|
+
fn(s), dn(s, i.height);
|
|
2884
|
+
let c = mn(s);
|
|
2797
2885
|
for (let e of this.#t.values()) e.showing = !1;
|
|
2798
2886
|
let l = new Set(this.#t.values());
|
|
2799
2887
|
o.forEach(({ label: e, entry: t }, r) => {
|
|
@@ -2806,7 +2894,7 @@ var ln = "http://www.w3.org/2000/svg", un = "0.4", dn = class {
|
|
|
2806
2894
|
let a = !!this.pointer?.interactive(e);
|
|
2807
2895
|
a !== t.interactive && (t.interactive = a, t.el.style.pointerEvents = a ? "auto" : "", a ? t.el.dataset.interactive = "" : (delete t.el.dataset.interactive, this.#l(t))), i === "dim" ? n.dimmed++ : n.shown++, this.shown.push(t.el);
|
|
2808
2896
|
let o = t.el, u = s[r];
|
|
2809
|
-
o.style.display = "", o.style.opacity = i === "dim" ?
|
|
2897
|
+
o.style.display = "", o.style.opacity = i === "dim" ? gn : "", u.left = Math.round(u.left), u.top = Math.round(u.top), o.style.transform = `translate(${u.left}px, ${u.top}px)`;
|
|
2810
2898
|
let d = e.style.edge, f = d && t.width !== u.width ? `${u.width}px` : "", p = d === "right" ? "right" : "";
|
|
2811
2899
|
(o.style.minWidth !== f || o.style.textAlign !== p) && Object.assign(o.style, {
|
|
2812
2900
|
minWidth: f,
|
|
@@ -2830,8 +2918,8 @@ var ln = "http://www.w3.org/2000/svg", un = "0.4", dn = class {
|
|
|
2830
2918
|
let t = getComputedStyle(e.el);
|
|
2831
2919
|
e.color = t.color, e.rule = t.borderBottomStyle === "none" ? 0 : parseFloat(t.borderBottomWidth) || 0;
|
|
2832
2920
|
}
|
|
2833
|
-
let a =
|
|
2834
|
-
o || (o = document.createElementNS(
|
|
2921
|
+
let a = pn(r, i, t, t.edge, e.rule), o = e.leader;
|
|
2922
|
+
o || (o = document.createElementNS(hn, "g"), o.append(document.createElementNS(hn, "line"), document.createElementNS(hn, "circle")), this.#c().append(o), e.leader = o);
|
|
2835
2923
|
let s = e.color;
|
|
2836
2924
|
o.setAttribute("class", `phoria-leader${e.className.slice(12)}`), o.setAttribute("stroke", s), o.setAttribute("fill", s), o.style.display = "", o.style.opacity = String(n);
|
|
2837
2925
|
let [c, l] = [...o.children];
|
|
@@ -2844,7 +2932,7 @@ var ln = "http://www.w3.org/2000/svg", un = "0.4", dn = class {
|
|
|
2844
2932
|
}
|
|
2845
2933
|
#c() {
|
|
2846
2934
|
if (this.#n) return this.#n;
|
|
2847
|
-
let e = document.createElementNS(
|
|
2935
|
+
let e = document.createElementNS(hn, "svg");
|
|
2848
2936
|
return e.setAttribute("class", "phoria-leaders"), Object.assign(e.style, {
|
|
2849
2937
|
position: "absolute",
|
|
2850
2938
|
left: "0",
|
|
@@ -2925,7 +3013,7 @@ var ln = "http://www.w3.org/2000/svg", un = "0.4", dn = class {
|
|
|
2925
3013
|
let t = this.canvas;
|
|
2926
3014
|
e.style.position = getComputedStyle(t).position === "fixed" ? "fixed" : "absolute", e.style.left = `${t.offsetLeft + t.clientLeft}px`, e.style.top = `${t.offsetTop + t.clientTop}px`, e.style.width = `${t.clientWidth}px`, e.style.height = `${t.clientHeight}px`;
|
|
2927
3015
|
}
|
|
2928
|
-
},
|
|
3016
|
+
}, vn = [
|
|
2929
3017
|
"enabled",
|
|
2930
3018
|
"mode",
|
|
2931
3019
|
"rotateSpeed",
|
|
@@ -2939,7 +3027,7 @@ var ln = "http://www.w3.org/2000/svg", un = "0.4", dn = class {
|
|
|
2939
3027
|
"maxDistance",
|
|
2940
3028
|
"minPitch",
|
|
2941
3029
|
"maxPitch"
|
|
2942
|
-
],
|
|
3030
|
+
], yn = {
|
|
2943
3031
|
enableDamping: "use 'inertia' (0 to turn it off)",
|
|
2944
3032
|
enableRotate: "use mode: 'map' to make dragging pan instead of turning",
|
|
2945
3033
|
rotate: "use mode: 'map' to make dragging pan instead of turning",
|
|
@@ -2948,14 +3036,14 @@ var ln = "http://www.w3.org/2000/svg", un = "0.4", dn = class {
|
|
|
2948
3036
|
screenSpacePanning: "panning always follows the screen",
|
|
2949
3037
|
dampingFactor: "use 'inertia': the fraction of speed kept each 1/60 s (default 0.85)",
|
|
2950
3038
|
target: "set camera.target - the control orbits around it"
|
|
2951
|
-
},
|
|
2952
|
-
function
|
|
3039
|
+
}, bn = Math.PI / 2 - .001, xn = 4;
|
|
3040
|
+
function Sn(e) {
|
|
2953
3041
|
let t = "OrbitControl";
|
|
2954
3042
|
e.mode !== void 0 && P(t, "mode", e.mode, ["orbit", "map"]), e.rotateSpeed !== void 0 && N(t, "rotateSpeed", e.rotateSpeed, 0), e.zoomSpeed !== void 0 && N(t, "zoomSpeed", e.zoomSpeed, 0), e.inertia !== void 0 && N(t, "inertia", e.inertia, 0, .99), e.autoRotate === void 0 || typeof e.autoRotate == "boolean" || typeof e.autoRotate == "number" && Number.isFinite(e.autoRotate) || E(t, `'autoRotate' is true, false or a speed in radians per second, got ${j(e.autoRotate)}`), e.minDistance !== void 0 && N(t, "minDistance", e.minDistance, 0), e.maxDistance !== void 0 && N(t, "maxDistance", e.maxDistance, 0, Infinity, { above: !0 }), e.minPitch !== void 0 && N(t, "minPitch", e.minPitch, -Math.PI / 2, Math.PI / 2), e.maxPitch !== void 0 && N(t, "maxPitch", e.maxPitch, -Math.PI / 2, Math.PI / 2);
|
|
2955
3043
|
}
|
|
2956
|
-
var
|
|
2957
|
-
static OPTIONS =
|
|
2958
|
-
static HINTS =
|
|
3044
|
+
var Cn = class {
|
|
3045
|
+
static OPTIONS = vn;
|
|
3046
|
+
static HINTS = yn;
|
|
2959
3047
|
enabled = !0;
|
|
2960
3048
|
mode = "orbit";
|
|
2961
3049
|
rotateSpeed = .005;
|
|
@@ -2967,8 +3055,8 @@ var _n = class {
|
|
|
2967
3055
|
autoRotate = !1;
|
|
2968
3056
|
minDistance = .1;
|
|
2969
3057
|
maxDistance = Infinity;
|
|
2970
|
-
minPitch = -
|
|
2971
|
-
maxPitch =
|
|
3058
|
+
minPitch = -bn;
|
|
3059
|
+
maxPitch = bn;
|
|
2972
3060
|
camera;
|
|
2973
3061
|
element;
|
|
2974
3062
|
#e = /* @__PURE__ */ new Map();
|
|
@@ -2987,7 +3075,7 @@ var _n = class {
|
|
|
2987
3075
|
#s;
|
|
2988
3076
|
#c = null;
|
|
2989
3077
|
constructor(e, t, n = {}) {
|
|
2990
|
-
A("OrbitControl", n,
|
|
3078
|
+
A("OrbitControl", n, vn, yn), e && "target" in e || E("OrbitControl", "expects a camera, e.g. new OrbitControl(view.camera, view.canvas)"), this.camera = e, this.element = t, Sn(n), Object.assign(this, n), this.minDistance > this.maxDistance && E("OrbitControl", `'minDistance' (${this.minDistance}) is more than 'maxDistance' (${this.maxDistance})`), this.minPitch > this.maxPitch && E("OrbitControl", `'minPitch' (${this.minPitch}) is more than 'maxPitch' (${this.maxPitch})`), e.target ??= new z(), t.style.touchAction = "none";
|
|
2991
3079
|
let r = (e) => this.#f(e), i = (e) => this.#p(e), a = (e) => this.#m(e), o = (e) => this.#h(e), s = (e) => {
|
|
2992
3080
|
this.enabled && this.pan && e.preventDefault();
|
|
2993
3081
|
}, c = (e) => {
|
|
@@ -3112,7 +3200,7 @@ var _n = class {
|
|
|
3112
3200
|
else {
|
|
3113
3201
|
let e = -n * this.rotateSpeed, t = r * this.rotateSpeed;
|
|
3114
3202
|
this.rotate(e, t);
|
|
3115
|
-
let i = performance.now(), a = Math.max(1 / 60, (i - this.#n) / 1e3), o = (e) => Math.max(-4, Math.min(
|
|
3203
|
+
let i = performance.now(), a = Math.max(1 / 60, (i - this.#n) / 1e3), o = (e) => Math.max(-4, Math.min(xn, e / a));
|
|
3116
3204
|
this.#t = {
|
|
3117
3205
|
yaw: o(e),
|
|
3118
3206
|
pitch: o(t)
|
|
@@ -3138,34 +3226,34 @@ var _n = class {
|
|
|
3138
3226
|
let [e, t] = [...this.#e.values()];
|
|
3139
3227
|
return Math.hypot(e.x - t.x, e.y - t.y);
|
|
3140
3228
|
}
|
|
3141
|
-
},
|
|
3229
|
+
}, wn = new Float32Array([
|
|
3142
3230
|
0,
|
|
3143
3231
|
1,
|
|
3144
3232
|
0
|
|
3145
|
-
]),
|
|
3146
|
-
function
|
|
3233
|
+
]), Tn = /* @__PURE__ */ new Float32Array(16), En = /* @__PURE__ */ new Float32Array(9);
|
|
3234
|
+
function Dn(e, t) {
|
|
3147
3235
|
if (e.position.equals(t, 1e-9)) return;
|
|
3148
3236
|
let n = t.clone().sub(e.position).normalize(), r = Math.hypot(n[0], n[2]) < 5e-4 ? [
|
|
3149
3237
|
0,
|
|
3150
3238
|
0,
|
|
3151
3239
|
-1
|
|
3152
|
-
] :
|
|
3153
|
-
f(
|
|
3154
|
-
let i = Oe(/* @__PURE__ */ new Float32Array(4), je(/* @__PURE__ */ new Float32Array(4),
|
|
3240
|
+
] : wn;
|
|
3241
|
+
f(Tn, e.position, t, r);
|
|
3242
|
+
let i = Oe(/* @__PURE__ */ new Float32Array(4), je(/* @__PURE__ */ new Float32Array(4), ft(En, Tn)));
|
|
3155
3243
|
e.quaternion.copy(i);
|
|
3156
3244
|
}
|
|
3157
|
-
var
|
|
3245
|
+
var On = [
|
|
3158
3246
|
...G,
|
|
3159
3247
|
"near",
|
|
3160
3248
|
"far",
|
|
3161
3249
|
"target",
|
|
3162
3250
|
"aspect"
|
|
3163
|
-
],
|
|
3251
|
+
], kn = {
|
|
3164
3252
|
lookAt: "use target: [x, y, z], or call camera.lookAt(...) after creating it",
|
|
3165
3253
|
zoom: "move the camera, or change 'fov' (perspective) or 'height' (orthographic)"
|
|
3166
|
-
},
|
|
3167
|
-
static OPTIONS =
|
|
3168
|
-
static HINTS =
|
|
3254
|
+
}, An = class extends K {
|
|
3255
|
+
static OPTIONS = On;
|
|
3256
|
+
static HINTS = kn;
|
|
3169
3257
|
near = .1;
|
|
3170
3258
|
far = 1e3;
|
|
3171
3259
|
aspect = 1;
|
|
@@ -3179,13 +3267,13 @@ var Sn = [
|
|
|
3179
3267
|
return this.#e;
|
|
3180
3268
|
}
|
|
3181
3269
|
set target(e) {
|
|
3182
|
-
this.#e =
|
|
3270
|
+
this.#e = vt(this.#e, e, this.constructor.name);
|
|
3183
3271
|
}
|
|
3184
3272
|
updateMatrix() {
|
|
3185
|
-
return this.target &&
|
|
3273
|
+
return this.target && Dn(this, this.target), super.updateMatrix();
|
|
3186
3274
|
}
|
|
3187
3275
|
lookAt(e, t) {
|
|
3188
|
-
return this.target ? (this.target.copy(
|
|
3276
|
+
return this.target ? (this.target.copy(yt(this, e)), this) : super.lookAt(e, t);
|
|
3189
3277
|
}
|
|
3190
3278
|
get projectionMatrix() {
|
|
3191
3279
|
return new B();
|
|
@@ -3206,10 +3294,10 @@ var Sn = [
|
|
|
3206
3294
|
let e = {};
|
|
3207
3295
|
return this.near !== .1 && (e.near = this.near), this.far !== 1e3 && (e.far = this.far), this.target && (e.target = this.target.toArray()), e;
|
|
3208
3296
|
}
|
|
3209
|
-
},
|
|
3297
|
+
}, jn = class extends An {
|
|
3210
3298
|
static type = "perspective-camera";
|
|
3211
3299
|
static get OPTIONS() {
|
|
3212
|
-
return [...
|
|
3300
|
+
return [...On, "fov"];
|
|
3213
3301
|
}
|
|
3214
3302
|
fov = 50;
|
|
3215
3303
|
constructor(e = {}) {
|
|
@@ -3230,10 +3318,10 @@ var Sn = [
|
|
|
3230
3318
|
...this.fov === 50 ? {} : { fov: this.fov }
|
|
3231
3319
|
};
|
|
3232
3320
|
}
|
|
3233
|
-
},
|
|
3321
|
+
}, Mn = class extends An {
|
|
3234
3322
|
static type = "orthographic-camera";
|
|
3235
3323
|
static get OPTIONS() {
|
|
3236
|
-
return [...
|
|
3324
|
+
return [...On, "height"];
|
|
3237
3325
|
}
|
|
3238
3326
|
height = 10;
|
|
3239
3327
|
constructor(e = {}) {
|
|
@@ -3255,7 +3343,7 @@ var Sn = [
|
|
|
3255
3343
|
...this.height === 10 ? {} : { height: this.height }
|
|
3256
3344
|
};
|
|
3257
3345
|
}
|
|
3258
|
-
},
|
|
3346
|
+
}, Nn = {
|
|
3259
3347
|
perspective: [
|
|
3260
3348
|
.6,
|
|
3261
3349
|
.45,
|
|
@@ -3281,7 +3369,7 @@ var Sn = [
|
|
|
3281
3369
|
0,
|
|
3282
3370
|
0
|
|
3283
3371
|
]
|
|
3284
|
-
},
|
|
3372
|
+
}, Pn = Object.keys(Nn), Fn = {
|
|
3285
3373
|
ortho: "isometric",
|
|
3286
3374
|
orthographic: "isometric",
|
|
3287
3375
|
iso: "isometric",
|
|
@@ -3295,13 +3383,13 @@ var Sn = [
|
|
|
3295
3383
|
persp: "perspective",
|
|
3296
3384
|
"3d": "perspective"
|
|
3297
3385
|
};
|
|
3298
|
-
function
|
|
3386
|
+
function In(e, { target: t = [
|
|
3299
3387
|
0,
|
|
3300
3388
|
0,
|
|
3301
3389
|
0
|
|
3302
3390
|
], distance: n = 10 } = {}) {
|
|
3303
|
-
let r =
|
|
3304
|
-
return e === "perspective" ? new
|
|
3391
|
+
let r = Ln(e), i = new z(t[0], t[1], t[2]).add(r.multiplyScalar(n));
|
|
3392
|
+
return e === "perspective" ? new jn({
|
|
3305
3393
|
fov: 45,
|
|
3306
3394
|
position: i,
|
|
3307
3395
|
target: [
|
|
@@ -3309,7 +3397,7 @@ function An(e, { target: t = [
|
|
|
3309
3397
|
t[1],
|
|
3310
3398
|
t[2]
|
|
3311
3399
|
]
|
|
3312
|
-
}) : new
|
|
3400
|
+
}) : new Mn({
|
|
3313
3401
|
height: n,
|
|
3314
3402
|
position: i,
|
|
3315
3403
|
target: [
|
|
@@ -3320,15 +3408,15 @@ function An(e, { target: t = [
|
|
|
3320
3408
|
far: Math.max(1e3, n * 20)
|
|
3321
3409
|
});
|
|
3322
3410
|
}
|
|
3323
|
-
function
|
|
3324
|
-
if (!(e in
|
|
3325
|
-
let t =
|
|
3326
|
-
E("View", `camera '${e}' is not a preset - ${t ? `use '${t}'` : `expected one of ${
|
|
3411
|
+
function Ln(e) {
|
|
3412
|
+
if (!(e in Nn)) {
|
|
3413
|
+
let t = Fn[String(e).toLowerCase()];
|
|
3414
|
+
E("View", `camera '${e}' is not a preset - ${t ? `use '${t}'` : `expected one of ${Pn.map((e) => `'${e}'`).join(", ")}${k(String(e), Pn)}`}`);
|
|
3327
3415
|
}
|
|
3328
|
-
return new z(...
|
|
3416
|
+
return new z(...Nn[e]).normalize();
|
|
3329
3417
|
}
|
|
3330
|
-
var
|
|
3331
|
-
function
|
|
3418
|
+
var Rn = .12;
|
|
3419
|
+
function zn(e, t, { aspect: n, fov: r, padding: i = 0 }) {
|
|
3332
3420
|
let a = 1 + i, o = n > 0 ? n : 1, s = new z(-t[0], -t[1], -t[2]), c = s.clone().cross(Math.abs(s[1]) > .9999 ? [
|
|
3333
3421
|
0,
|
|
3334
3422
|
0,
|
|
@@ -3375,7 +3463,7 @@ function Nn(e, t, { aspect: n, fov: r, padding: i = 0 }) {
|
|
|
3375
3463
|
let a = x + i[2] - m[2], o = (i[0] - m[0]) / a / v, s = (i[1] - m[1]) / a / _;
|
|
3376
3464
|
e = Math.min(e, o), t = Math.max(t, o), n = Math.min(n, s), r = Math.max(r, s);
|
|
3377
3465
|
}
|
|
3378
|
-
let i = (e + t) / 2, a = (n + r) / 2 +
|
|
3466
|
+
let i = (e + t) / 2, a = (n + r) / 2 + Rn;
|
|
3379
3467
|
if (Math.abs(i) < 1e-4 && Math.abs(a) < 1e-4) break;
|
|
3380
3468
|
m[0] += i * v * x, m[1] += a * _ * x, x = b();
|
|
3381
3469
|
}
|
|
@@ -3384,18 +3472,18 @@ function Nn(e, t, { aspect: n, fov: r, padding: i = 0 }) {
|
|
|
3384
3472
|
size: x
|
|
3385
3473
|
};
|
|
3386
3474
|
}
|
|
3387
|
-
function
|
|
3475
|
+
function Bn(e, t, n) {
|
|
3388
3476
|
if (e === "height" || !(n > 0) || !(t > 0)) return 1;
|
|
3389
3477
|
let r = t / n;
|
|
3390
3478
|
return e === "width" ? r : Math.max(1, r);
|
|
3391
3479
|
}
|
|
3392
3480
|
// src/ease.js
|
|
3393
|
-
var
|
|
3481
|
+
var Vn = {
|
|
3394
3482
|
linear: (e) => e,
|
|
3395
3483
|
in: (e) => e * e * e,
|
|
3396
3484
|
out: (e) => 1 - (1 - e) ** 3,
|
|
3397
3485
|
inOut: (e) => e < .5 ? 4 * e * e * e : 1 - (-2 * e + 2) ** 3 / 2
|
|
3398
|
-
},
|
|
3486
|
+
}, Hn = new z(), Un = new z(), Wn = new z(), q = new z(), Gn = new z(), Kn = class e {
|
|
3399
3487
|
origin = new z();
|
|
3400
3488
|
direction = new z(0, 0, -1);
|
|
3401
3489
|
constructor(e, t) {
|
|
@@ -3425,17 +3513,17 @@ var Fn = {
|
|
|
3425
3513
|
return r >= 0 ? r : null;
|
|
3426
3514
|
}
|
|
3427
3515
|
intersectTriangle(e, t, n, r) {
|
|
3428
|
-
|
|
3429
|
-
let i =
|
|
3516
|
+
Hn.set(t[0] - e[0], t[1] - e[1], t[2] - e[2]), Un.set(n[0] - e[0], n[1] - e[1], n[2] - e[2]), Wn.copy(this.direction).cross(Un);
|
|
3517
|
+
let i = Hn.dot(Wn);
|
|
3430
3518
|
if (r ? i < 1e-10 : Math.abs(i) < 1e-10) return null;
|
|
3431
3519
|
let a = 1 / i;
|
|
3432
3520
|
q.set(this.origin[0] - e[0], this.origin[1] - e[1], this.origin[2] - e[2]);
|
|
3433
|
-
let o = q.dot(
|
|
3521
|
+
let o = q.dot(Wn) * a;
|
|
3434
3522
|
if (o < 0 || o > 1) return null;
|
|
3435
|
-
|
|
3436
|
-
let s = this.direction.dot(
|
|
3523
|
+
Gn.copy(q).cross(Hn);
|
|
3524
|
+
let s = this.direction.dot(Gn) * a;
|
|
3437
3525
|
if (s < 0 || o + s > 1) return null;
|
|
3438
|
-
let c =
|
|
3526
|
+
let c = Un.dot(Gn) * a;
|
|
3439
3527
|
return c >= 0 ? {
|
|
3440
3528
|
t: c,
|
|
3441
3529
|
u: o,
|
|
@@ -3444,7 +3532,7 @@ var Fn = {
|
|
|
3444
3532
|
}
|
|
3445
3533
|
distanceSqToPoint(e) {
|
|
3446
3534
|
q.set(e[0] - this.origin[0], e[1] - this.origin[1], e[2] - this.origin[2]);
|
|
3447
|
-
let t = Math.max(0, q.dot(this.direction)), n = this.at(t,
|
|
3535
|
+
let t = Math.max(0, q.dot(this.direction)), n = this.at(t, Gn);
|
|
3448
3536
|
return {
|
|
3449
3537
|
distanceSq: (e[0] - n[0]) ** 2 + (e[1] - n[1]) ** 2 + (e[2] - n[2]) ** 2,
|
|
3450
3538
|
t
|
|
@@ -3462,18 +3550,18 @@ var Fn = {
|
|
|
3462
3550
|
s: m
|
|
3463
3551
|
};
|
|
3464
3552
|
}
|
|
3465
|
-
},
|
|
3466
|
-
function
|
|
3467
|
-
let n =
|
|
3553
|
+
}, qn = 8, Jn = /* @__PURE__ */ new WeakMap();
|
|
3554
|
+
function Yn(e, t) {
|
|
3555
|
+
let n = Jn.get(e);
|
|
3468
3556
|
if (n && n.version === e.version && n.count === t) return n.bvh;
|
|
3469
|
-
let r =
|
|
3470
|
-
return
|
|
3557
|
+
let r = Xn(e, t);
|
|
3558
|
+
return Jn.set(e, {
|
|
3471
3559
|
version: e.version,
|
|
3472
3560
|
count: t,
|
|
3473
3561
|
bvh: r
|
|
3474
3562
|
}), r;
|
|
3475
3563
|
}
|
|
3476
|
-
function
|
|
3564
|
+
function Xn(e, t) {
|
|
3477
3565
|
let n = e.positions, r = e.indices, i = (e, t) => (r ? r[e * 3 + t] : e * 3 + t) * 3, a = new Float32Array(t * 9);
|
|
3478
3566
|
for (let e = 0; e < t; e++) {
|
|
3479
3567
|
let t = i(e, 0), r = i(e, 1), o = i(e, 2);
|
|
@@ -3484,7 +3572,7 @@ function Wn(e, t) {
|
|
|
3484
3572
|
}
|
|
3485
3573
|
let o = new Uint32Array(t);
|
|
3486
3574
|
for (let e = 0; e < t; e++) o[e] = e;
|
|
3487
|
-
let s = Math.max(1, 2 * Math.ceil(t /
|
|
3575
|
+
let s = Math.max(1, 2 * Math.ceil(t / qn) * 2), c = new Float32Array(s * 6), l = new Int32Array(s * 2), u = 0, d = () => {
|
|
3488
3576
|
let e = new Float32Array(c.length * 2), t = new Int32Array(l.length * 2);
|
|
3489
3577
|
e.set(c), t.set(l), c = e, l = t;
|
|
3490
3578
|
}, f = () => ((u + 1) * 2 > l.length && d(), u++), p = [[
|
|
@@ -3507,12 +3595,12 @@ function Wn(e, t) {
|
|
|
3507
3595
|
m
|
|
3508
3596
|
], e * 6);
|
|
3509
3597
|
let x = v - h, S = y - g, C = b - _;
|
|
3510
|
-
if (n - t <=
|
|
3598
|
+
if (n - t <= qn || Math.max(x, S, C) <= 0) {
|
|
3511
3599
|
l[e * 2] = t, l[e * 2 + 1] = n - t;
|
|
3512
3600
|
continue;
|
|
3513
3601
|
}
|
|
3514
3602
|
let w = x >= S && x >= C ? 6 : S >= C ? 7 : 8, T = t + n >> 1;
|
|
3515
|
-
|
|
3603
|
+
Zn(o, a, w, t, n, T);
|
|
3516
3604
|
let E = f();
|
|
3517
3605
|
f(), l[e * 2] = E, l[e * 2 + 1] = 0, p.push([
|
|
3518
3606
|
E,
|
|
@@ -3530,7 +3618,7 @@ function Wn(e, t) {
|
|
|
3530
3618
|
order: o
|
|
3531
3619
|
};
|
|
3532
3620
|
}
|
|
3533
|
-
function
|
|
3621
|
+
function Zn(e, t, n, r, i, a) {
|
|
3534
3622
|
let o = r, s = i - 1;
|
|
3535
3623
|
for (; o < s;) {
|
|
3536
3624
|
let r = t[e[o + s >> 1] * 9 + n], i = o, c = s;
|
|
@@ -3547,7 +3635,7 @@ function Gn(e, t, n, r, i, a) {
|
|
|
3547
3635
|
else break;
|
|
3548
3636
|
}
|
|
3549
3637
|
}
|
|
3550
|
-
function
|
|
3638
|
+
function Qn(e, t, n, r) {
|
|
3551
3639
|
let { boxes: i, nodes: a, order: o } = e, s = 1 / n[0], c = 1 / n[1], l = 1 / n[2], u = (e) => {
|
|
3552
3640
|
let n = e * 6, r = (i[n] - t[0]) * s, a = (i[n + 3] - t[0]) * s, o = Math.min(r, a), u = Math.max(r, a);
|
|
3553
3641
|
return r = (i[n + 1] - t[1]) * c, a = (i[n + 4] - t[1]) * c, o = Math.max(o, Math.min(r, a)), u = Math.min(u, Math.max(r, a)), r = (i[n + 2] - t[2]) * l, a = (i[n + 5] - t[2]) * l, o = Math.max(o, Math.min(r, a)), u = Math.min(u, Math.max(r, a)), u >= Math.max(o, 0) || Number.isNaN(o) || Number.isNaN(u) ? Math.max(o, 0) || 0 : Infinity;
|
|
@@ -3567,11 +3655,11 @@ function Kn(e, t, n, r) {
|
|
|
3567
3655
|
}
|
|
3568
3656
|
}
|
|
3569
3657
|
// src/Raycaster.js
|
|
3570
|
-
var
|
|
3658
|
+
var $n = /* @__PURE__ */ new Float32Array(16), er = /* @__PURE__ */ new Float32Array(16), J = new z(), Y = new z(), tr = new z(), nr = /* @__PURE__ */ new Float32Array(4), rr = (e) => e?.clip ? {
|
|
3571
3659
|
plane: Ce(e),
|
|
3572
3660
|
cap: !!e.clip.cap
|
|
3573
|
-
} : null,
|
|
3574
|
-
ray = new
|
|
3661
|
+
} : null, ir = class {
|
|
3662
|
+
ray = new Kn();
|
|
3575
3663
|
near = 0;
|
|
3576
3664
|
far = Infinity;
|
|
3577
3665
|
threshold = .1;
|
|
@@ -3588,7 +3676,7 @@ var qn = /* @__PURE__ */ new Float32Array(16), Jn = /* @__PURE__ */ new Float32A
|
|
|
3588
3676
|
}
|
|
3589
3677
|
intersect(e) {
|
|
3590
3678
|
let t = [];
|
|
3591
|
-
for (let n of [e].flat()) n.updateWorld(), this.#e(n, t,
|
|
3679
|
+
for (let n of [e].flat()) n.updateWorld(), this.#e(n, t, rr(we(n.parent)));
|
|
3592
3680
|
return t.filter((e) => e.distance >= this.near && e.distance <= this.far).sort((e, t) => e.distance - t.distance);
|
|
3593
3681
|
}
|
|
3594
3682
|
intersectDrawn(e) {
|
|
@@ -3600,7 +3688,7 @@ var qn = /* @__PURE__ */ new Float32Array(16), Jn = /* @__PURE__ */ new Float32A
|
|
|
3600
3688
|
plane: n.clip.plane,
|
|
3601
3689
|
cap: !!n.clip.cap
|
|
3602
3690
|
} : null;
|
|
3603
|
-
if (n.instances) for (let i = 0; i < n.instances.count; i++) s(
|
|
3691
|
+
if (n.instances) for (let i = 0; i < n.instances.count; i++) s(er, n.worldMatrix, n.instances.instanceMatrices.subarray(i * 16, i * 16 + 16)), this.#t(e, er, i, t, r);
|
|
3604
3692
|
else this.#t(e, n.worldMatrix, null, t, r);
|
|
3605
3693
|
}
|
|
3606
3694
|
return t.filter((e) => e.distance >= this.near && e.distance <= this.far).sort((e, t) => e.distance - t.distance);
|
|
@@ -3644,10 +3732,10 @@ var qn = /* @__PURE__ */ new Float32Array(16), Jn = /* @__PURE__ */ new Float32A
|
|
|
3644
3732
|
}
|
|
3645
3733
|
intersectElement(e, t) {
|
|
3646
3734
|
e.updateWorld();
|
|
3647
|
-
let n = e, r = [], i =
|
|
3735
|
+
let n = e, r = [], i = rr(we(e));
|
|
3648
3736
|
if (n.drawMode === "triangles" && n.instanceMatrices) {
|
|
3649
3737
|
if (t >= n.count) return null;
|
|
3650
|
-
s(
|
|
3738
|
+
s(er, n.worldMatrix, n.instanceMatrices.subarray(t * 16, t * 16 + 16)), this.#t(n, er, t, r, i);
|
|
3651
3739
|
} else if (n.drawMode === "triangles") this.#t(n, n.worldMatrix, null, r, i);
|
|
3652
3740
|
else if (n.drawMode === "points") {
|
|
3653
3741
|
let e = n.geometry.positions;
|
|
@@ -3683,9 +3771,9 @@ var qn = /* @__PURE__ */ new Float32Array(16), Jn = /* @__PURE__ */ new Float32A
|
|
|
3683
3771
|
}
|
|
3684
3772
|
#e(e, t, n) {
|
|
3685
3773
|
if (!(this.camera ? e.shownTo(this.camera) : e.visible) || !e.pickable) return;
|
|
3686
|
-
e.clip && (n =
|
|
3774
|
+
e.clip && (n = rr(e));
|
|
3687
3775
|
let r = e;
|
|
3688
|
-
if (r.drawMode === "triangles" && r.instanceMatrices) for (let e = 0; e < r.count; e++) s(
|
|
3776
|
+
if (r.drawMode === "triangles" && r.instanceMatrices) for (let e = 0; e < r.count; e++) s(er, r.worldMatrix, r.instanceMatrices.subarray(e * 16, e * 16 + 16)), this.#t(r, er, e, t, n);
|
|
3689
3777
|
else r.drawMode === "triangles" ? this.#t(r, r.worldMatrix, null, t, n) : r.drawMode === "points" ? this.#n(r, t) : r.drawMode === "lines" && this.#r(r, t);
|
|
3690
3778
|
for (let r of e.children) this.#e(r, t, n);
|
|
3691
3779
|
}
|
|
@@ -3693,26 +3781,26 @@ var qn = /* @__PURE__ */ new Float32Array(16), Jn = /* @__PURE__ */ new Float32A
|
|
|
3693
3781
|
let o = e.geometry;
|
|
3694
3782
|
if (!o.vertexCount) return;
|
|
3695
3783
|
let s = o.bounds, c = s.getCenter().applyMatrix4(t), l = Math.max(Math.hypot(t[0], t[1], t[2]), Math.hypot(t[4], t[5], t[6]), Math.hypot(t[8], t[9], t[10]));
|
|
3696
|
-
if (this.ray.intersectSphere(c, s.getRadius() * l) === null || !a(
|
|
3697
|
-
let u = this.ray.clone().applyMatrix4(
|
|
3698
|
-
if (i) for (let e = 0; e < 4; e++)
|
|
3784
|
+
if (this.ray.intersectSphere(c, s.getRadius() * l) === null || !a($n, t)) return;
|
|
3785
|
+
let u = this.ray.clone().applyMatrix4($n), d = o.positions, f = o.indices, p = !e.material.doubleSided && !i?.cap;
|
|
3786
|
+
if (i) for (let e = 0; e < 4; e++) nr[e] = i.plane[0] * t[e * 4] + i.plane[1] * t[e * 4 + 1] + i.plane[2] * t[e * 4 + 2] + i.plane[3] * t[e * 4 + 3];
|
|
3699
3787
|
let m = u.origin, h = u.direction, g = null, _ = Infinity, v = -1, y = (e) => {
|
|
3700
3788
|
let t = f ? f[e * 3] : e * 3, n = f ? f[e * 3 + 1] : e * 3 + 1, r = f ? f[e * 3 + 2] : e * 3 + 2;
|
|
3701
|
-
J.set(d[t * 3], d[t * 3 + 1], d[t * 3 + 2]), Y.set(d[n * 3], d[n * 3 + 1], d[n * 3 + 2]),
|
|
3702
|
-
let a = u.intersectTriangle(J, Y,
|
|
3703
|
-
return a && i &&
|
|
3789
|
+
J.set(d[t * 3], d[t * 3 + 1], d[t * 3 + 2]), Y.set(d[n * 3], d[n * 3 + 1], d[n * 3 + 2]), tr.set(d[r * 3], d[r * 3 + 1], d[r * 3 + 2]);
|
|
3790
|
+
let a = u.intersectTriangle(J, Y, tr, p);
|
|
3791
|
+
return a && i && nr[0] * (m[0] + h[0] * a.t) + nr[1] * (m[1] + h[1] * a.t) + nr[2] * (m[2] + h[2] * a.t) + nr[3] > 0 || a && (a.t < _ || a.t === _ && e < v) && (g = {
|
|
3704
3792
|
...a,
|
|
3705
3793
|
i0: t,
|
|
3706
3794
|
i1: n,
|
|
3707
3795
|
i2: r
|
|
3708
3796
|
}, _ = a.t, v = e), _;
|
|
3709
3797
|
}, b = Math.floor(o.drawnCount / 3);
|
|
3710
|
-
if (b >= 128)
|
|
3798
|
+
if (b >= 128) Qn(Yn(o, b), m, h, y);
|
|
3711
3799
|
else for (let e = 0; e < b; e++) y(e);
|
|
3712
3800
|
if (!g) return;
|
|
3713
3801
|
let x = u.at(g.t).applyMatrix4(t);
|
|
3714
|
-
J.set(d[g.i0 * 3], d[g.i0 * 3 + 1], d[g.i0 * 3 + 2]), Y.set(d[g.i1 * 3], d[g.i1 * 3 + 1], d[g.i1 * 3 + 2]).sub(J),
|
|
3715
|
-
let S = Y.clone().cross(
|
|
3802
|
+
J.set(d[g.i0 * 3], d[g.i0 * 3 + 1], d[g.i0 * 3 + 2]), Y.set(d[g.i1 * 3], d[g.i1 * 3 + 1], d[g.i1 * 3 + 2]).sub(J), tr.set(d[g.i2 * 3], d[g.i2 * 3 + 1], d[g.i2 * 3 + 2]).sub(J);
|
|
3803
|
+
let S = Y.clone().cross(tr), C = dt(/* @__PURE__ */ new Float32Array(9), t), w = C ? new z(C[0] * S[0] + C[3] * S[1] + C[6] * S[2], C[1] * S[0] + C[4] * S[1] + C[7] * S[2], C[2] * S[0] + C[5] * S[1] + C[8] * S[2]).normalize() : null;
|
|
3716
3804
|
if (i?.cap && w && w.dot(this.ray.direction) > 0) {
|
|
3717
3805
|
let e = i.plane, { origin: t, direction: n } = this.ray, r = e[0] * n[0] + e[1] * n[1] + e[2] * n[2];
|
|
3718
3806
|
r < 0 && (x = this.ray.at(-(e[0] * t[0] + e[1] * t[1] + e[2] * t[2] + e[3]) / r)), w = new z(e[0], e[1], e[2]);
|
|
@@ -3777,8 +3865,8 @@ var qn = /* @__PURE__ */ new Float32Array(16), Jn = /* @__PURE__ */ new Float32A
|
|
|
3777
3865
|
}
|
|
3778
3866
|
s && t.push(s);
|
|
3779
3867
|
}
|
|
3780
|
-
},
|
|
3781
|
-
function
|
|
3868
|
+
}, ar = /* @__PURE__ */ new Float32Array(16);
|
|
3869
|
+
function or(e) {
|
|
3782
3870
|
let t;
|
|
3783
3871
|
if (Array.isArray(e)) (e.length < 3 || !e.every((e) => Array.isArray(e) && e.length === 2 && e.every(Number.isFinite))) && E("View", `pickArea() takes a box { x, y, width, height } or a lasso of three or more [x, y] points, got ${j(e)}`), t = e.flat();
|
|
3784
3872
|
else {
|
|
@@ -3809,7 +3897,7 @@ function er(e) {
|
|
|
3809
3897
|
bottom: a
|
|
3810
3898
|
};
|
|
3811
3899
|
}
|
|
3812
|
-
function
|
|
3900
|
+
function sr(e, t, n) {
|
|
3813
3901
|
let r = !1;
|
|
3814
3902
|
for (let i = 0, a = e.length - 2; i < e.length; a = i, i += 2) {
|
|
3815
3903
|
let o = e[i + 1], s = e[a + 1];
|
|
@@ -3817,14 +3905,14 @@ function tr(e, t, n) {
|
|
|
3817
3905
|
}
|
|
3818
3906
|
return r;
|
|
3819
3907
|
}
|
|
3820
|
-
function
|
|
3821
|
-
let o =
|
|
3908
|
+
function cr(e, t, n, r, i, a) {
|
|
3909
|
+
let o = or(a), c = t.worldPosition, l = n, u = [], d = (e, t, n) => {
|
|
3822
3910
|
let a = l[3] * e + l[7] * t + l[11] * n + l[15];
|
|
3823
3911
|
if (a <= 0) return !1;
|
|
3824
3912
|
let s = (l[2] * e + l[6] * t + l[10] * n + l[14]) / a;
|
|
3825
3913
|
if (s < -1 || s > 1) return !1;
|
|
3826
3914
|
let c = ((l[0] * e + l[4] * t + l[8] * n + l[12]) / a * .5 + .5) * r, u = (.5 - (l[1] * e + l[5] * t + l[9] * n + l[13]) / a * .5) * i;
|
|
3827
|
-
return c >= o.left && c <= o.right && u >= o.top && u <= o.bottom &&
|
|
3915
|
+
return c >= o.left && c <= o.right && u >= o.top && u <= o.bottom && sr(o.points, c, u);
|
|
3828
3916
|
}, f = (e, t, n, r, i, a) => {
|
|
3829
3917
|
let o = new z(t, n, r);
|
|
3830
3918
|
u.push({
|
|
@@ -3853,7 +3941,7 @@ function nr(e, t, n, r, i, a) {
|
|
|
3853
3941
|
}
|
|
3854
3942
|
} else if (n.instanceMatrices) {
|
|
3855
3943
|
let r = e.bounds.getCenter();
|
|
3856
|
-
for (let e = 0; e < n.count; e++)
|
|
3944
|
+
for (let e = 0; e < n.count; e++) Rt(n.instanceMatrices, e) || (s(ar, t, n.instanceMatrices.subarray(e * 16, e * 16 + 16)), p.copy(r).applyMatrix4(ar), d(p[0], p[1], p[2]) && f(n, p[0], p[1], p[2], null, e));
|
|
3857
3945
|
} else p.copy(e.bounds.getCenter()).applyMatrix4(t), d(p[0], p[1], p[2]) && f(n, p[0], p[1], p[2], null, null);
|
|
3858
3946
|
}
|
|
3859
3947
|
for (let t of e.children) m(t);
|
|
@@ -3861,27 +3949,28 @@ function nr(e, t, n, r, i, a) {
|
|
|
3861
3949
|
return m(e), u.sort((e, t) => e.distance - t.distance);
|
|
3862
3950
|
}
|
|
3863
3951
|
// src/watch.js
|
|
3864
|
-
var
|
|
3865
|
-
let t =
|
|
3866
|
-
return t === void 0 &&
|
|
3867
|
-
},
|
|
3952
|
+
var lr = /* @__PURE__ */ new WeakMap(), ur = 1, dr = (e) => /\buTime\b/.test(e.vertex + e.fragment + e.lit), X = (e) => {
|
|
3953
|
+
let t = lr.get(e);
|
|
3954
|
+
return t === void 0 && lr.set(e, t = ur++), t;
|
|
3955
|
+
}, fr = class {
|
|
3868
3956
|
#e = /* @__PURE__ */ new Float64Array(256);
|
|
3869
3957
|
#t = /* @__PURE__ */ new Float64Array(256);
|
|
3870
3958
|
#n = 0;
|
|
3871
3959
|
#r = -1;
|
|
3872
3960
|
#i = [];
|
|
3873
3961
|
#a = [];
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
for (let e = 0; !
|
|
3879
|
-
|
|
3962
|
+
#o = 0;
|
|
3963
|
+
changed(e, t, n = 0) {
|
|
3964
|
+
this.#o = n, this.#n = 0, this.#i = [], this.#l(t), this.#u(e, t);
|
|
3965
|
+
let r = this.#n !== this.#r || this.#i.length !== this.#a.length;
|
|
3966
|
+
for (let e = 0; !r && e < this.#n; e++) r = this.#e[e] !== this.#t[e];
|
|
3967
|
+
for (let e = 0; !r && e < this.#i.length; e++) r = this.#i[e] !== this.#a[e];
|
|
3968
|
+
return [this.#t, this.#e] = [this.#e, this.#t], this.#r = this.#n, this.#a = this.#i, r;
|
|
3880
3969
|
}
|
|
3881
3970
|
reset() {
|
|
3882
3971
|
this.#r = -1;
|
|
3883
3972
|
}
|
|
3884
|
-
#
|
|
3973
|
+
#s(e) {
|
|
3885
3974
|
if (this.#n === this.#e.length) {
|
|
3886
3975
|
let e = new Float64Array(this.#e.length * 2);
|
|
3887
3976
|
e.set(this.#e), this.#e = e;
|
|
@@ -3890,63 +3979,69 @@ var rr = /* @__PURE__ */ new WeakMap(), ir = 1, X = (e) => {
|
|
|
3890
3979
|
}
|
|
3891
3980
|
this.#e[this.#n++] = e;
|
|
3892
3981
|
}
|
|
3893
|
-
#s(e) {
|
|
3894
|
-
for (let t = 0; t < e.length; t++) this.#o(e[t]);
|
|
3895
|
-
}
|
|
3896
3982
|
#c(e) {
|
|
3897
|
-
|
|
3983
|
+
for (let t = 0; t < e.length; t++) this.#s(e[t]);
|
|
3984
|
+
}
|
|
3985
|
+
#l(e) {
|
|
3986
|
+
this.#s(X(e)), this.#c(e.position), this.#c(e.quaternion), e.target && this.#c(e.target), this.#s(e.fov ?? e.height), this.#s(e.near), this.#s(e.far), this.#s(e.aspect);
|
|
3898
3987
|
}
|
|
3899
|
-
#
|
|
3988
|
+
#u(e, t) {
|
|
3900
3989
|
let n = e.background;
|
|
3901
|
-
n ? "getHex" in n ? this.#
|
|
3990
|
+
n ? "getHex" in n ? this.#c(n) : this.#p(n) : this.#s(-1);
|
|
3902
3991
|
let r = e.environment;
|
|
3903
|
-
typeof r == "string" ? this.#i.push(r) : this.#
|
|
3992
|
+
typeof r == "string" ? this.#i.push(r) : this.#p(r), this.#s(e.environmentIntensity), this.#s(e.backgroundBlur);
|
|
3904
3993
|
let i = e.fog;
|
|
3905
|
-
i ? (this.#
|
|
3994
|
+
i ? (this.#c(i.color), this.#s(i.density), this.#s(i.near), this.#s(i.far)) : this.#s(-1), this.#d(e, t);
|
|
3906
3995
|
}
|
|
3907
|
-
#
|
|
3908
|
-
this.#
|
|
3996
|
+
#d(e, t) {
|
|
3997
|
+
this.#s(X(e));
|
|
3909
3998
|
let n = e.shownTo(t);
|
|
3910
|
-
if (this.#
|
|
3911
|
-
this.#
|
|
3999
|
+
if (this.#s(+!!n), !n) return;
|
|
4000
|
+
this.#s(e.overlay ? X(e.overlay) : 0);
|
|
3912
4001
|
let r = e.clip;
|
|
3913
|
-
r ? (this.#
|
|
4002
|
+
r ? (this.#c(r.normal), this.#s(r.offset), this.#s(r.cap ? r.cap.getHex() : -1)) : this.#s(-2), this.#s(+!!e.handlersFor("click").length | (e.handlersFor("hover").length ? 2 : 0) | (e.tooltip ? 4 : 0) | (e.onDrag ? 8 : 0) | (e.highlightWhole ? 16 : 0)), e.highlight ? this.#c(e.highlight) : this.#s(e.highlight === !1 ? -5 : -4);
|
|
3914
4003
|
let i = e.outline;
|
|
3915
|
-
i ? (this.#
|
|
3916
|
-
for (let n of e.children) this.#
|
|
3917
|
-
}
|
|
3918
|
-
#d(e) {
|
|
3919
|
-
let t = e.geometry, n = e.material;
|
|
3920
|
-
this.#o(X(t)), this.#o(t.version), this.#o(t.drawCount ?? -1), this.#o(e.renderOrder), this.#o(+!!e.castShadow | (e.receiveShadow ? 2 : 0) | (e.sort ? 4 : 0)), "arrowBits" in e && (this.#o(e.arrowBits), this.#o(e.arrowSize)), this.#o(e.labels ? X(e.labels) : 0), this.#o(e.data && typeof e.data == "object" ? X(e.data) : 0), "instanceMatrices" in e && (this.#o(e.count), this.#o(e.version)), this.#o(X(n)), this.#s(n.color), this.#s(n.emissive), this.#o(n.emissiveIntensity), this.#o(n.opacity), this.#o(n.roughness), this.#o(n.metalness), this.#o(n.size), this.#o(n.width), this.#o(n.dash), this.#o(n.gap), this.#o(n.dashOffset), this.#o(n.alphaTest), this.#o(n.normalScale), this.#o(n.aoMapIntensity), this.#o(n.triplanar), this.#o(n.bumpScale), this.#o(n.transmission), this.#o(n.clearcoat), this.#o(n.clearcoatRoughness), this.#o(n.sheen), this.#s(n.sheenColor), this.#o(n.sheenRoughness), this.#o(n.ior), this.#o(n.specularIntensity), this.#s(n.specularColor), this.#o(n.anisotropy), this.#o(n.anisotropyRotation), this.#o(n.translucency), this.#o(n.toon), this.#o(n.lightMapIntensity), this.#o(n.environmentIntensity), this.#s(n.translucencyColor), this.#o(+!!n.unlit | (n.flatShading ? 2 : 0) | (n.doubleSided ? 4 : 0) | (n.vertexColors ? 8 : 0) | (n.depthWrite ? 16 : 0) | (n.depthTest ? 32 : 0) | (n.sizeAttenuation ? 64 : 0) | (n.blending === "additive" ? 128 : n.blending === "multiply" ? 1024 : 0) | (n.transparent ? 256 : 0) | (n.fog ? 512 : 0));
|
|
3921
|
-
for (let [, e] of n.textures) this.#f(e);
|
|
4004
|
+
i ? (this.#c(i.color), this.#s(i.width)) : this.#s(-3), this.#c(e.position), this.#c(e.quaternion), this.#c(e.scale), e.matrixAutoUpdate || this.#c(e.matrix), e.isDrawable ? this.#f(e) : e.isLabel ? this.#m(e) : e.lightKind && this.#h(e);
|
|
4005
|
+
for (let n of e.children) this.#d(n, t);
|
|
3922
4006
|
}
|
|
3923
4007
|
#f(e) {
|
|
3924
|
-
|
|
4008
|
+
let t = e.geometry, n = e.material;
|
|
4009
|
+
this.#s(X(t)), this.#s(t.version), this.#s(t.drawCount ?? -1), this.#s(e.renderOrder), this.#s(+!!e.castShadow | (e.receiveShadow ? 2 : 0) | (e.sort ? 4 : 0)), "arrowBits" in e && (this.#s(e.arrowBits), this.#s(e.arrowSize)), this.#s(e.labels ? X(e.labels) : 0), this.#s(e.data && typeof e.data == "object" ? X(e.data) : 0), "instanceMatrices" in e && (this.#s(e.count), this.#s(e.version)), this.#s(X(n)), this.#c(n.color), this.#c(n.emissive), this.#s(n.emissiveIntensity), this.#s(n.opacity), this.#s(n.roughness), this.#s(n.metalness), this.#s(n.size), this.#s(n.width), this.#s(n.dash), this.#s(n.gap), this.#s(n.dashOffset), this.#s(n.alphaTest), this.#s(n.normalScale), this.#s(n.aoMapIntensity), this.#s(n.triplanar), this.#s(n.bumpScale), this.#s(n.transmission), this.#s(n.clearcoat), this.#s(n.clearcoatRoughness), this.#s(n.sheen), this.#c(n.sheenColor), this.#s(n.sheenRoughness), this.#s(n.ior), this.#s(n.specularIntensity), this.#c(n.specularColor), this.#s(n.anisotropy), this.#s(n.anisotropyRotation), this.#s(n.translucency), this.#s(n.toon), this.#s(n.lightMapIntensity), this.#s(n.environmentIntensity), this.#c(n.translucencyColor), this.#s(+!!n.unlit | (n.flatShading ? 2 : 0) | (n.doubleSided ? 4 : 0) | (n.vertexColors ? 8 : 0) | (n.depthWrite ? 16 : 0) | (n.depthTest ? 32 : 0) | (n.sizeAttenuation ? 64 : 0) | (n.blending === "additive" ? 128 : n.blending === "multiply" ? 1024 : 0) | (n.transparent ? 256 : 0) | (n.fog ? 512 : 0));
|
|
4010
|
+
for (let [, e] of n.allTextures) this.#p(e);
|
|
4011
|
+
let r = n.shader;
|
|
4012
|
+
if (r) {
|
|
4013
|
+
this.#s(X(r));
|
|
4014
|
+
for (let e of Object.values(r.uniforms)) typeof e == "number" ? this.#s(e) : (Array.isArray(e) || ArrayBuffer.isView(e)) && this.#c(e);
|
|
4015
|
+
dr(r) && this.#s(this.#o);
|
|
4016
|
+
}
|
|
3925
4017
|
}
|
|
3926
4018
|
#p(e) {
|
|
3927
|
-
this.#
|
|
4019
|
+
this.#s(X(e)), this.#s(e.version), this.#c(e.repeat), this.#s(e.rotation), this.#c(e.center), this.#s(e.uvSet), this.#c(e.offset);
|
|
3928
4020
|
}
|
|
3929
4021
|
#m(e) {
|
|
3930
|
-
this.#
|
|
4022
|
+
this.#i.push(e.text, e.className, e.place, e.overlap, e.edge ?? ""), this.#c(e.offset), this.#s(e.priority), this.#s(+!!e.occlude), this.#s(+!!e.leader), this.#s(e.minScale);
|
|
3931
4023
|
}
|
|
3932
|
-
|
|
4024
|
+
#h(e) {
|
|
4025
|
+
this.#c(e.color), this.#s(e.intensity), e.ground && this.#c(e.ground), e.direction && this.#c(e.direction), e.target && this.#c(e.target), e.castShadow && this.#s(1), e.shadowBounds && (this.#c(e.shadowBounds.min), this.#c(e.shadowBounds.max)), "range" in e && this.#s(e.range), "angle" in e && (this.#s(e.angle), this.#s(e.penumbra));
|
|
4026
|
+
}
|
|
4027
|
+
}, pr = [
|
|
3933
4028
|
"color",
|
|
3934
4029
|
"density",
|
|
3935
4030
|
"near",
|
|
3936
4031
|
"far"
|
|
3937
|
-
],
|
|
4032
|
+
], mr = {
|
|
3938
4033
|
start: "use 'near' for where linear fog starts",
|
|
3939
4034
|
end: "use 'far' for where linear fog is complete",
|
|
3940
4035
|
type: "give 'density' for exponential fog, or 'near' and 'far' for linear",
|
|
3941
4036
|
exp2: "give 'density' for exponential fog",
|
|
3942
4037
|
colour: "use 'color'"
|
|
3943
|
-
},
|
|
4038
|
+
}, hr = class e {
|
|
3944
4039
|
color = new H(8421504);
|
|
3945
4040
|
density = .05;
|
|
3946
4041
|
near = 0;
|
|
3947
4042
|
far = 100;
|
|
3948
4043
|
constructor(e = {}) {
|
|
3949
|
-
A("fog", e,
|
|
4044
|
+
A("fog", e, pr, mr), e.color !== void 0 && this.color.set(e.color, "fog");
|
|
3950
4045
|
let t = e.near !== void 0 || e.far !== void 0;
|
|
3951
4046
|
t && e.density !== void 0 && E("fog", "give 'density' for exponential fog, or 'near' and 'far' for linear - not both"), t ? (this.density = 0, e.near !== void 0 && (this.near = M("fog", "near", e.near)), e.far !== void 0 && (this.far = M("fog", "far", e.far)), this.near >= 0 && this.far > this.near || E("fog", `'near' must be 0 or more and 'far' beyond it, got near ${this.near}, far ${this.far}`)) : e.density !== void 0 && (this.density = M("fog", "density", e.density), this.density > 0 || E("fog", `'density' must be more than 0, got ${this.density}`));
|
|
3952
4047
|
}
|
|
@@ -3967,7 +4062,7 @@ var rr = /* @__PURE__ */ new WeakMap(), ir = 1, X = (e) => {
|
|
|
3967
4062
|
density: this.density
|
|
3968
4063
|
};
|
|
3969
4064
|
}
|
|
3970
|
-
},
|
|
4065
|
+
}, gr = class extends K {
|
|
3971
4066
|
static type = "scene";
|
|
3972
4067
|
static get OPTIONS() {
|
|
3973
4068
|
return [
|
|
@@ -3993,13 +4088,13 @@ var rr = /* @__PURE__ */ new WeakMap(), ir = 1, X = (e) => {
|
|
|
3993
4088
|
motionReduced = !1;
|
|
3994
4089
|
#n = null;
|
|
3995
4090
|
constructor(e = {}) {
|
|
3996
|
-
super(e), e.background !== void 0 && this.#r(e.background), e.environment !== void 0 && this.#i(e.environment), e.environmentIntensity !== void 0 && (this.environmentIntensity = M("Scene", "environmentIntensity", e.environmentIntensity)), e.backgroundBlur !== void 0 && (this.backgroundBlur = M("Scene", "backgroundBlur", e.backgroundBlur)), e.fog != null && (this.#n =
|
|
4091
|
+
super(e), e.background !== void 0 && this.#r(e.background), e.environment !== void 0 && this.#i(e.environment), e.environmentIntensity !== void 0 && (this.environmentIntensity = M("Scene", "environmentIntensity", e.environmentIntensity)), e.backgroundBlur !== void 0 && (this.backgroundBlur = M("Scene", "backgroundBlur", e.backgroundBlur)), e.fog != null && (this.#n = hr.fromInput(e.fog, "Scene"));
|
|
3997
4092
|
}
|
|
3998
4093
|
get fog() {
|
|
3999
4094
|
return this.#n;
|
|
4000
4095
|
}
|
|
4001
4096
|
set fog(e) {
|
|
4002
|
-
this.#n = e == null ? null :
|
|
4097
|
+
this.#n = e == null ? null : hr.fromInput(e, "Scene");
|
|
4003
4098
|
}
|
|
4004
4099
|
get background() {
|
|
4005
4100
|
return this.#e;
|
|
@@ -4028,7 +4123,7 @@ var rr = /* @__PURE__ */ new WeakMap(), ir = 1, X = (e) => {
|
|
|
4028
4123
|
}) : E("Scene", `'environment' must be 'studio', 'none', an .hdr url or a texture, got ${j(e)}`);
|
|
4029
4124
|
}
|
|
4030
4125
|
update(e, t) {
|
|
4031
|
-
return
|
|
4126
|
+
return _r(this, e, t, /* @__PURE__ */ new Set()), this.updateWorldTree(), this;
|
|
4032
4127
|
}
|
|
4033
4128
|
get ready() {
|
|
4034
4129
|
let e = [];
|
|
@@ -4057,24 +4152,24 @@ var rr = /* @__PURE__ */ new WeakMap(), ir = 1, X = (e) => {
|
|
|
4057
4152
|
return this.environmentIntensity !== 1 && (e.environmentIntensity = this.environmentIntensity), this.backgroundBlur && (e.backgroundBlur = this.backgroundBlur), this.#n && (e.fog = this.#n.toJSON()), e;
|
|
4058
4153
|
}
|
|
4059
4154
|
};
|
|
4060
|
-
function
|
|
4155
|
+
function _r(e, t, n, r) {
|
|
4061
4156
|
e.hasHandlers && !r.has(e) && (r.add(e), e.runHandlers(t, n));
|
|
4062
4157
|
let i = e.children;
|
|
4063
|
-
if (i.length) for (let e of [...i])
|
|
4158
|
+
if (i.length) for (let e of [...i]) _r(e, t, n, r);
|
|
4064
4159
|
}
|
|
4065
4160
|
// src/scene/lights.js
|
|
4066
|
-
var
|
|
4161
|
+
var vr = [
|
|
4067
4162
|
...G,
|
|
4068
4163
|
"color",
|
|
4069
4164
|
"intensity"
|
|
4070
|
-
],
|
|
4165
|
+
], yr = {
|
|
4071
4166
|
distance: "use 'range' (0 = infinite)",
|
|
4072
4167
|
decay: "falloff is physical (inverse square), as in glTF - limit it with range",
|
|
4073
4168
|
attenuation: "use 'range' - falloff is physical (inverse square)",
|
|
4074
4169
|
shadow: "use 'castShadow: true' (directional, spot and point lights)"
|
|
4075
|
-
},
|
|
4076
|
-
static OPTIONS =
|
|
4077
|
-
static HINTS =
|
|
4170
|
+
}, br = class extends K {
|
|
4171
|
+
static OPTIONS = vr;
|
|
4172
|
+
static HINTS = yr;
|
|
4078
4173
|
static kind = "ambient";
|
|
4079
4174
|
get lightKind() {
|
|
4080
4175
|
return this.constructor.kind;
|
|
@@ -4103,10 +4198,10 @@ var dr = [
|
|
|
4103
4198
|
let e = {};
|
|
4104
4199
|
return this.#e.getHex() !== 16777215 && (e.color = this.#e.getStyle()), this.intensity !== 1 && (e.intensity = this.intensity), e;
|
|
4105
4200
|
}
|
|
4106
|
-
},
|
|
4201
|
+
}, xr = class extends br {
|
|
4107
4202
|
static type = "ambient-light";
|
|
4108
4203
|
static kind = "ambient";
|
|
4109
|
-
},
|
|
4204
|
+
}, Sr = class extends br {
|
|
4110
4205
|
static type = "hemisphere-light";
|
|
4111
4206
|
static kind = "hemisphere";
|
|
4112
4207
|
static get OPTIONS() {
|
|
@@ -4154,7 +4249,7 @@ var dr = [
|
|
|
4154
4249
|
...this.#e.getHex() === 4473924 ? {} : { ground: this.#e.getStyle() }
|
|
4155
4250
|
};
|
|
4156
4251
|
}
|
|
4157
|
-
},
|
|
4252
|
+
}, Cr = class extends br {
|
|
4158
4253
|
#e = new z(0, -1, 0);
|
|
4159
4254
|
#t = null;
|
|
4160
4255
|
get direction() {
|
|
@@ -4168,7 +4263,7 @@ var dr = [
|
|
|
4168
4263
|
return this.#t;
|
|
4169
4264
|
}
|
|
4170
4265
|
set target(e) {
|
|
4171
|
-
this.#t =
|
|
4266
|
+
this.#t = vt(this.#t, e, this.constructor.name);
|
|
4172
4267
|
}
|
|
4173
4268
|
constructor(e = {}) {
|
|
4174
4269
|
super(e);
|
|
@@ -4176,7 +4271,7 @@ var dr = [
|
|
|
4176
4271
|
e.direction !== void 0 && e.target !== void 0 && E(t, "give 'direction' or 'target', not both"), e.direction !== void 0 && (this.direction = e.direction), e.target !== void 0 && (this.target = e.target);
|
|
4177
4272
|
}
|
|
4178
4273
|
lookAt(e) {
|
|
4179
|
-
let t =
|
|
4274
|
+
let t = yt(this, e);
|
|
4180
4275
|
return this.target ? this.target.copy(t) : t.equals(this.position, 1e-9) || this.direction.copy(t.sub(this.position).normalize()), this;
|
|
4181
4276
|
}
|
|
4182
4277
|
get worldDirection() {
|
|
@@ -4199,12 +4294,12 @@ var dr = [
|
|
|
4199
4294
|
...this.target ? { target: this.target.toArray() } : { direction: this.direction.toArray() }
|
|
4200
4295
|
};
|
|
4201
4296
|
}
|
|
4202
|
-
},
|
|
4297
|
+
}, wr = class extends Cr {
|
|
4203
4298
|
static type = "directional-light";
|
|
4204
4299
|
static kind = "directional";
|
|
4205
4300
|
static get OPTIONS() {
|
|
4206
4301
|
return [
|
|
4207
|
-
...
|
|
4302
|
+
...vr,
|
|
4208
4303
|
"direction",
|
|
4209
4304
|
"target",
|
|
4210
4305
|
"castShadow",
|
|
@@ -4250,12 +4345,12 @@ var dr = [
|
|
|
4250
4345
|
} } : {}
|
|
4251
4346
|
};
|
|
4252
4347
|
}
|
|
4253
|
-
},
|
|
4348
|
+
}, Tr = class extends br {
|
|
4254
4349
|
static type = "point-light";
|
|
4255
4350
|
static kind = "point";
|
|
4256
4351
|
static get OPTIONS() {
|
|
4257
4352
|
return [
|
|
4258
|
-
...
|
|
4353
|
+
...vr,
|
|
4259
4354
|
"range",
|
|
4260
4355
|
"castShadow"
|
|
4261
4356
|
];
|
|
@@ -4263,7 +4358,7 @@ var dr = [
|
|
|
4263
4358
|
range = 0;
|
|
4264
4359
|
castShadow = !1;
|
|
4265
4360
|
constructor(e = {}) {
|
|
4266
|
-
super(e), e.range !== void 0 && (this.range =
|
|
4361
|
+
super(e), e.range !== void 0 && (this.range = Dr(this.constructor.name, e.range)), e.castShadow !== void 0 && (this.castShadow = !!e.castShadow);
|
|
4267
4362
|
}
|
|
4268
4363
|
cloneOptions() {
|
|
4269
4364
|
return {
|
|
@@ -4279,12 +4374,12 @@ var dr = [
|
|
|
4279
4374
|
...this.castShadow ? { castShadow: !0 } : {}
|
|
4280
4375
|
};
|
|
4281
4376
|
}
|
|
4282
|
-
},
|
|
4377
|
+
}, Er = class extends Cr {
|
|
4283
4378
|
static type = "spot-light";
|
|
4284
4379
|
static kind = "spot";
|
|
4285
4380
|
static get OPTIONS() {
|
|
4286
4381
|
return [
|
|
4287
|
-
...
|
|
4382
|
+
...vr,
|
|
4288
4383
|
"direction",
|
|
4289
4384
|
"target",
|
|
4290
4385
|
"range",
|
|
@@ -4298,7 +4393,7 @@ var dr = [
|
|
|
4298
4393
|
angle = Math.PI / 6;
|
|
4299
4394
|
penumbra = .1;
|
|
4300
4395
|
constructor(e = {}) {
|
|
4301
|
-
super(e), e.castShadow !== void 0 && (this.castShadow = !!e.castShadow), e.range !== void 0 && (this.range =
|
|
4396
|
+
super(e), e.castShadow !== void 0 && (this.castShadow = !!e.castShadow), e.range !== void 0 && (this.range = Dr("SpotLight", e.range)), e.angle !== void 0 && (this.angle = M("SpotLight", "angle", e.angle), (this.angle <= 0 || this.angle > Math.PI / 2) && E("SpotLight", `'angle' is the cone's half-angle in radians, above 0 and up to PI/2, got ${this.angle}`)), e.penumbra !== void 0 && (this.penumbra = M("SpotLight", "penumbra", e.penumbra), (this.penumbra < 0 || this.penumbra > 1) && E("SpotLight", `'penumbra' must be 0-1, got ${this.penumbra}`));
|
|
4302
4397
|
}
|
|
4303
4398
|
cloneOptions() {
|
|
4304
4399
|
return {
|
|
@@ -4314,7 +4409,7 @@ var dr = [
|
|
|
4314
4409
|
return this.range && (e.range = this.range), this.angle !== Math.PI / 6 && (e.angle = this.angle), this.penumbra !== .1 && (e.penumbra = this.penumbra), this.castShadow && (e.castShadow = !0), e;
|
|
4315
4410
|
}
|
|
4316
4411
|
};
|
|
4317
|
-
function
|
|
4412
|
+
function Dr(e, t) {
|
|
4318
4413
|
let n = M(e, "range", t);
|
|
4319
4414
|
return n < 0 && E(e, `'range' can't be negative (0 means unlimited), got ${n}`), n;
|
|
4320
4415
|
}
|
|
@@ -4338,7 +4433,7 @@ var Z = {
|
|
|
4338
4433
|
segmentColorEnd: 3,
|
|
4339
4434
|
corner: 4,
|
|
4340
4435
|
segmentInfo: 5
|
|
4341
|
-
},
|
|
4436
|
+
}, Or = "#ifdef CLIP\nuniform vec4 uClipPlane;\nvoid clipAway(vec3 p) {\nif (dot(uClipPlane.xyz, p) + uClipPlane.w > 0.0) discard;\n}\n#else\nvoid clipAway(vec3 p) {}\n#endif\n", kr = "#ifdef FOG\nuniform vec3 uFogColor;\nuniform vec2 uFogRange;\nuniform float uFogDensity;\nin float vFogDepth;\nvec3 fogged(vec3 c) {\n#ifdef FOG_LINEAR\nfloat f = clamp((vFogDepth - uFogRange.x) / max(uFogRange.y - uFogRange.x, 1e-4), 0.0, 1.0);\n#else\nfloat d = uFogDensity * vFogDepth;\nfloat f = 1.0 - exp(-d * d);\n#endif\n#ifdef FOG_ADD\nreturn c * (1.0 - f);\n#elif defined(FOG_MULTIPLY)\nreturn mix(c, vec3(1.0), f);\n#else\nreturn mix(c, uFogColor, f);\n#endif\n}\n#else\nvec3 fogged(vec3 c) { return c; }\n#endif\n", Ar = [
|
|
4342
4437
|
"uMap",
|
|
4343
4438
|
"uRoughnessMap",
|
|
4344
4439
|
"uMetalnessMap",
|
|
@@ -4347,10 +4442,10 @@ var Z = {
|
|
|
4347
4442
|
"uAoMap",
|
|
4348
4443
|
"uEmissiveMap",
|
|
4349
4444
|
"uLightMap"
|
|
4350
|
-
],
|
|
4445
|
+
], jr = `#ifdef UV2
|
|
4351
4446
|
in vec2 vUv2;
|
|
4352
4447
|
#endif
|
|
4353
|
-
${
|
|
4448
|
+
${Ar.map((e) => `uniform mat3 ${e}Uv;
|
|
4354
4449
|
#ifndef ${e}Set
|
|
4355
4450
|
#define ${e}Set vUv
|
|
4356
4451
|
#endif
|
|
@@ -4376,25 +4471,41 @@ vec4 triplanar(sampler2D s, mat3 t) {
|
|
|
4376
4471
|
vec3 p = vObjectPosition * uTriplanar, w = triplanarWeights(normalize(vObjectNormal));
|
|
4377
4472
|
return texture(s, projected(p.zy, t)) * w.x + texture(s, projected(p.xz, t)) * w.y + texture(s, projected(p.xy, t)) * w.z;
|
|
4378
4473
|
}
|
|
4379
|
-
${
|
|
4474
|
+
${Ar.map((e) => `#define ${e}Texel triplanar(${e}, ${e}Uv)`).join("\n")}
|
|
4380
4475
|
#else
|
|
4381
|
-
${
|
|
4476
|
+
${Ar.map((e) => `#define ${e}Texel texture(${e}, ${e}Coord)`).join("\n")}
|
|
4382
4477
|
#endif
|
|
4383
|
-
`,
|
|
4478
|
+
`, Mr = `precision highp float;
|
|
4384
4479
|
in vec3 vWorldPosition;
|
|
4385
4480
|
out vec4 fragColor;
|
|
4386
|
-
#
|
|
4481
|
+
#if defined(ALPHA_TEST) || defined(HOOK_FRAGMENT)
|
|
4387
4482
|
in vec2 vUv;
|
|
4483
|
+
#endif
|
|
4484
|
+
#ifdef HOOK_FRAGMENT
|
|
4485
|
+
in vec3 vNormal;
|
|
4486
|
+
in vec3 vColor;
|
|
4487
|
+
//@hook uniforms
|
|
4488
|
+
#endif
|
|
4489
|
+
#ifdef ALPHA_TEST
|
|
4388
4490
|
uniform float uOpacity;
|
|
4389
4491
|
uniform float uAlphaTest;
|
|
4390
4492
|
#ifdef MAP
|
|
4391
4493
|
uniform sampler2D uMap;
|
|
4392
|
-
${
|
|
4494
|
+
${jr}
|
|
4393
4495
|
#endif
|
|
4394
4496
|
#endif
|
|
4395
|
-
${
|
|
4497
|
+
${Or}
|
|
4396
4498
|
void main() {
|
|
4397
4499
|
clipAway(vWorldPosition);
|
|
4500
|
+
#ifdef HOOK_FRAGMENT
|
|
4501
|
+
{
|
|
4502
|
+
vec4 base = vec4(vColor, 1.0);
|
|
4503
|
+
vec3 emissive = vec3(0.0);
|
|
4504
|
+
vec3 normal = normalize(vNormal);
|
|
4505
|
+
//@hook fragment
|
|
4506
|
+
if (base.a <= 0.0) discard;
|
|
4507
|
+
}
|
|
4508
|
+
#endif
|
|
4398
4509
|
#ifdef ALPHA_TEST
|
|
4399
4510
|
float alpha = uOpacity;
|
|
4400
4511
|
#ifdef MAP
|
|
@@ -4404,7 +4515,7 @@ if (alpha < uAlphaTest) discard;
|
|
|
4404
4515
|
#endif
|
|
4405
4516
|
fragColor = vec4(1.0);
|
|
4406
4517
|
}
|
|
4407
|
-
`,
|
|
4518
|
+
`, Nr = "vec3 srgbToLinear(vec3 c) {\nreturn mix(c / 12.92, pow((c + 0.055) / 1.055, vec3(2.4)), step(0.04045, c));\n}\nvec3 linearToSrgb(vec3 c) {\nc = clamp(c, 0.0, 1.0);\nreturn mix(c * 12.92, 1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055, step(0.0031308, c));\n}\n", Pr = "vec2 equirectUv(vec3 d) {\nreturn vec2(atan(d.z, d.x) * 0.15915494 + 0.5, acos(clamp(d.y, -1.0, 1.0)) * 0.31830989);\n}\nvec3 equirectDirection(vec2 uv) {\nfloat phi = (uv.x - 0.5) * 6.28318531, theta = uv.y * 3.14159265;\nreturn vec3(cos(phi) * sin(theta), cos(theta), sin(phi) * sin(theta));\n}\n", Fr = "out vec2 vUv;\nvoid main() {\nvec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));\nvUv = p;\ngl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);\n}\n", Ir = "uniform float uExposure;\nuniform int uToneMapping;\nvec3 toneMap(vec3 c) {\nc *= uExposure;\nif (uToneMapping == 1) {\nc = clamp((c * (2.51 * c + 0.03)) / (c * (2.43 * c + 0.59) + 0.14), 0.0, 1.0);\n} else if (uToneMapping == 2) {\nfloat x = min(c.r, min(c.g, c.b));\nfloat offset = x < 0.08 ? x - 6.25 * x * x : 0.04;\nc -= offset;\nfloat peak = max(c.r, max(c.g, c.b));\nif (peak > 0.8) {\nfloat d = 0.2;\nfloat newPeak = 1.0 - d * d / (peak + d - 0.8);\nc *= newPeak / peak;\nfloat g = 1.0 - 1.0 / (0.15 * (peak - newPeak) + 1.0);\nc = mix(c, vec3(newPeak), g);\n}\n}\nreturn c;\n}\n", Lr = `layout(location = 0) in vec3 position;
|
|
4408
4519
|
layout(location = 1) in vec3 normal;
|
|
4409
4520
|
layout(location = 2) in vec2 uv;
|
|
4410
4521
|
layout(location = 3) in vec3 color;
|
|
@@ -4428,6 +4539,7 @@ uniform int uHighlightIndex;
|
|
|
4428
4539
|
uniform mat4 uView;
|
|
4429
4540
|
out float vFogDepth;
|
|
4430
4541
|
#endif
|
|
4542
|
+
//@hook uniforms
|
|
4431
4543
|
out vec3 vWorldPosition;
|
|
4432
4544
|
out vec3 vNormal;
|
|
4433
4545
|
out vec2 vUv;
|
|
@@ -4441,27 +4553,35 @@ out mat3 vObjectToWorld;
|
|
|
4441
4553
|
#ifdef PICK
|
|
4442
4554
|
flat out uint vPickElement;
|
|
4443
4555
|
#endif
|
|
4444
|
-
${
|
|
4556
|
+
${Nr}
|
|
4445
4557
|
void main() {
|
|
4446
4558
|
vColor = vec3(1.0);
|
|
4447
4559
|
vHighlight = uHighlightIndex == -1 ? 1.0 : 0.0;
|
|
4560
|
+
vec3 local = position;
|
|
4561
|
+
vec3 n = normal;
|
|
4562
|
+
#ifdef HOOK_VERTEX
|
|
4563
|
+
{
|
|
4564
|
+
int index = gl_InstanceID;
|
|
4565
|
+
//@hook vertex
|
|
4566
|
+
}
|
|
4567
|
+
#endif
|
|
4448
4568
|
#ifdef INSTANCED
|
|
4449
|
-
vec4
|
|
4569
|
+
vec4 placed = instanceMatrix * vec4(local, 1.0);
|
|
4450
4570
|
mat3 m = mat3(instanceMatrix);
|
|
4451
4571
|
mat3 instanceNormal = mat3(cross(m[1], m[2]), cross(m[2], m[0]), cross(m[0], m[1])) * sign(dot(m[0], cross(m[1], m[2])));
|
|
4452
|
-
vec3
|
|
4572
|
+
vec3 placedNormal = instanceNormal * n;
|
|
4453
4573
|
vColor *= instanceColor;
|
|
4454
4574
|
if (gl_InstanceID == uHighlightIndex) vHighlight = 1.0;
|
|
4455
4575
|
#else
|
|
4456
|
-
vec4
|
|
4457
|
-
vec3
|
|
4576
|
+
vec4 placed = vec4(local, 1.0);
|
|
4577
|
+
vec3 placedNormal = n;
|
|
4458
4578
|
#endif
|
|
4459
4579
|
#ifdef VERTEX_COLORS
|
|
4460
4580
|
vColor *= srgbToLinear(color);
|
|
4461
4581
|
#endif
|
|
4462
|
-
vec4 world = uModel *
|
|
4582
|
+
vec4 world = uModel * placed;
|
|
4463
4583
|
vWorldPosition = world.xyz;
|
|
4464
|
-
vNormal = uNormalMatrix *
|
|
4584
|
+
vNormal = uNormalMatrix * placedNormal;
|
|
4465
4585
|
vUv = uv;
|
|
4466
4586
|
#ifdef UV2
|
|
4467
4587
|
vUv2 = uv2;
|
|
@@ -4474,8 +4594,8 @@ vTangent = vec4(mat3(uModel) * tangent.xyz, tangent.w);
|
|
|
4474
4594
|
#endif
|
|
4475
4595
|
#endif
|
|
4476
4596
|
#ifdef TRIPLANAR
|
|
4477
|
-
vObjectPosition =
|
|
4478
|
-
vObjectNormal =
|
|
4597
|
+
vObjectPosition = local;
|
|
4598
|
+
vObjectNormal = n;
|
|
4479
4599
|
#ifdef INSTANCED
|
|
4480
4600
|
vObjectToWorld = uNormalMatrix * instanceNormal;
|
|
4481
4601
|
#else
|
|
@@ -4490,7 +4610,7 @@ vFogDepth = -(uView * world).z;
|
|
|
4490
4610
|
vPickElement = uint(gl_InstanceID);
|
|
4491
4611
|
#endif
|
|
4492
4612
|
}
|
|
4493
|
-
`,
|
|
4613
|
+
`, Rr = `precision highp float;
|
|
4494
4614
|
precision highp sampler2DShadow;
|
|
4495
4615
|
precision highp samplerCubeShadow;
|
|
4496
4616
|
in vec3 vWorldPosition;
|
|
@@ -4511,7 +4631,8 @@ uniform float uAlphaTest;
|
|
|
4511
4631
|
#ifdef EMISSIVE_MAP
|
|
4512
4632
|
uniform sampler2D uEmissiveMap;
|
|
4513
4633
|
#endif
|
|
4514
|
-
|
|
4634
|
+
//@hook uniforms
|
|
4635
|
+
${jr}
|
|
4515
4636
|
#ifdef LIT
|
|
4516
4637
|
uniform vec3 uCameraPosition;
|
|
4517
4638
|
uniform float uRoughness;
|
|
@@ -4609,10 +4730,10 @@ uniform float uPointShadowBias;
|
|
|
4609
4730
|
#endif
|
|
4610
4731
|
#endif
|
|
4611
4732
|
out vec4 fragColor;
|
|
4612
|
-
${
|
|
4613
|
-
${
|
|
4614
|
-
${Sr}
|
|
4733
|
+
${Nr}
|
|
4734
|
+
${Or}
|
|
4615
4735
|
${kr}
|
|
4736
|
+
${Ir}
|
|
4616
4737
|
#ifdef LIT
|
|
4617
4738
|
const float PI = 3.14159265359;
|
|
4618
4739
|
float D_GGX(float NoH, float a) {
|
|
@@ -4721,7 +4842,7 @@ vec2 ab = vec2(-1.04, 1.04) * a004 + r.zw;
|
|
|
4721
4842
|
return f0 * ab.x + ab.y * f90;
|
|
4722
4843
|
}
|
|
4723
4844
|
#ifdef ENV_MAP
|
|
4724
|
-
${
|
|
4845
|
+
${Pr}
|
|
4725
4846
|
vec3 envIrradiance(vec3 n) {
|
|
4726
4847
|
return uEnvSH[0]
|
|
4727
4848
|
+ uEnvSH[1] * n.y + uEnvSH[2] * n.z + uEnvSH[3] * n.x
|
|
@@ -4854,22 +4975,37 @@ vec4 base = vec4(uColor * vColor, uOpacity);
|
|
|
4854
4975
|
#ifdef MAP
|
|
4855
4976
|
base *= uMapTexel;
|
|
4856
4977
|
#endif
|
|
4978
|
+
vec3 emissive = uEmissive;
|
|
4979
|
+
#ifdef EMISSIVE_MAP
|
|
4980
|
+
emissive *= uEmissiveMapTexel.rgb;
|
|
4981
|
+
#endif
|
|
4982
|
+
#ifdef HOOK_FRAGMENT
|
|
4983
|
+
#ifdef FLAT_SHADING
|
|
4984
|
+
vec3 normal = normalize(cross(dFdx(vWorldPosition), dFdy(vWorldPosition)));
|
|
4985
|
+
#else
|
|
4986
|
+
vec3 normal = normalize(vNormal);
|
|
4987
|
+
#ifdef DOUBLE_SIDED
|
|
4988
|
+
if (!gl_FrontFacing) normal = -normal;
|
|
4989
|
+
#endif
|
|
4990
|
+
#endif
|
|
4991
|
+
{
|
|
4992
|
+
//@hook fragment
|
|
4993
|
+
}
|
|
4994
|
+
#endif
|
|
4857
4995
|
#ifdef ALPHA_TEST
|
|
4858
4996
|
if (base.a < uAlphaTest) discard;
|
|
4859
4997
|
base.a = 1.0;
|
|
4860
4998
|
#endif
|
|
4861
4999
|
float coverage = base.a;
|
|
4862
|
-
vec3 emissive = uEmissive;
|
|
4863
|
-
#ifdef EMISSIVE_MAP
|
|
4864
|
-
emissive *= uEmissiveMapTexel.rgb;
|
|
4865
|
-
#endif
|
|
4866
5000
|
#ifdef LIT
|
|
4867
|
-
#ifdef
|
|
5001
|
+
#ifdef HOOK_FRAGMENT
|
|
5002
|
+
vec3 n = normalize(normal);
|
|
5003
|
+
#elif defined(FLAT_SHADING)
|
|
4868
5004
|
vec3 n = normalize(cross(dFdx(vWorldPosition), dFdy(vWorldPosition)));
|
|
4869
5005
|
#else
|
|
4870
5006
|
vec3 n = normalize(vNormal);
|
|
4871
5007
|
#endif
|
|
4872
|
-
#if defined(DOUBLE_SIDED) && !defined(FLAT_SHADING)
|
|
5008
|
+
#if defined(DOUBLE_SIDED) && !defined(FLAT_SHADING) && !defined(HOOK_FRAGMENT)
|
|
4873
5009
|
if (!gl_FrontFacing) n = -n;
|
|
4874
5010
|
#endif
|
|
4875
5011
|
vec3 surfaceNormal = n;
|
|
@@ -5042,12 +5178,19 @@ color = toneMap(color);
|
|
|
5042
5178
|
#else
|
|
5043
5179
|
vec3 color = base.rgb + emissive;
|
|
5044
5180
|
#endif
|
|
5181
|
+
#ifdef HOOK_LIT
|
|
5182
|
+
{
|
|
5183
|
+
float before = max(base.a, 1e-5);
|
|
5184
|
+
//@hook lit
|
|
5185
|
+
coverage *= clamp(base.a / before, 0.0, 1.0);
|
|
5186
|
+
}
|
|
5187
|
+
#endif
|
|
5045
5188
|
color = mix(color, uHighlight.rgb, vHighlight * uHighlight.a);
|
|
5046
5189
|
coverage = mix(coverage, base.a, vHighlight * uHighlight.a);
|
|
5047
5190
|
color = fogged(color);
|
|
5048
5191
|
fragColor = vec4(linearToSrgb(color) * base.a, coverage);
|
|
5049
5192
|
}
|
|
5050
|
-
`,
|
|
5193
|
+
`, zr = `layout(location = 0) in vec3 position;
|
|
5051
5194
|
layout(location = 3) in vec3 color;
|
|
5052
5195
|
#ifdef SPRITES
|
|
5053
5196
|
layout(location = 4) in vec2 corner;
|
|
@@ -5065,35 +5208,54 @@ uniform mat4 uProjection;
|
|
|
5065
5208
|
uniform float uSize;
|
|
5066
5209
|
uniform float uScale;
|
|
5067
5210
|
uniform int uHighlightIndex;
|
|
5211
|
+
//@hook uniforms
|
|
5068
5212
|
out vec3 vColor;
|
|
5069
5213
|
flat out float vHighlight;
|
|
5214
|
+
#ifdef HOOK_FRAGMENT
|
|
5215
|
+
flat out float vPointIndex;
|
|
5216
|
+
#endif
|
|
5070
5217
|
#ifdef PICK
|
|
5071
5218
|
flat out uint vPickElement;
|
|
5072
5219
|
#endif
|
|
5073
5220
|
#ifdef FOG
|
|
5074
5221
|
out float vFogDepth;
|
|
5075
5222
|
#endif
|
|
5076
|
-
${
|
|
5223
|
+
${Nr}
|
|
5077
5224
|
void main() {
|
|
5078
|
-
|
|
5225
|
+
vec3 local = position;
|
|
5226
|
+
#ifdef SPRITES
|
|
5227
|
+
int self = int(pointIndex + 0.5);
|
|
5228
|
+
float size = pointSize;
|
|
5229
|
+
#else
|
|
5230
|
+
int self = gl_VertexID;
|
|
5231
|
+
float size = 1.0;
|
|
5232
|
+
#endif
|
|
5233
|
+
#ifdef HOOK_VERTEX
|
|
5234
|
+
{
|
|
5235
|
+
int index = self;
|
|
5236
|
+
//@hook vertex
|
|
5237
|
+
}
|
|
5238
|
+
#endif
|
|
5239
|
+
#ifdef HOOK_FRAGMENT
|
|
5240
|
+
vPointIndex = float(self);
|
|
5241
|
+
#endif
|
|
5242
|
+
vec4 viewPosition = uView * (uModel * vec4(local, 1.0));
|
|
5079
5243
|
#ifdef SPRITES
|
|
5080
5244
|
vec2 c = vec2(corner.x * 2.0 - 1.0, corner.y);
|
|
5081
5245
|
float s = sin(pointAngle), k = cos(pointAngle);
|
|
5082
5246
|
vec2 turned = vec2(c.x * k - c.y * s, c.x * s + c.y * k);
|
|
5083
|
-
float
|
|
5247
|
+
float across = uSize * size;
|
|
5084
5248
|
#ifdef SIZE_ATTENUATION
|
|
5085
|
-
viewPosition.xy += turned *
|
|
5249
|
+
viewPosition.xy += turned * across * 0.5;
|
|
5086
5250
|
gl_Position = uProjection * viewPosition;
|
|
5087
5251
|
#else
|
|
5088
5252
|
gl_Position = uProjection * viewPosition;
|
|
5089
|
-
gl_Position.xy += turned *
|
|
5253
|
+
gl_Position.xy += turned * across / uResolution * gl_Position.w;
|
|
5090
5254
|
#endif
|
|
5091
5255
|
vUv = vec2(c.x * 0.5 + 0.5, 0.5 - c.y * 0.5);
|
|
5092
5256
|
vOpacity = pointOpacity;
|
|
5093
|
-
int self = int(pointIndex + 0.5);
|
|
5094
5257
|
#else
|
|
5095
5258
|
gl_Position = uProjection * viewPosition;
|
|
5096
|
-
int self = gl_VertexID;
|
|
5097
5259
|
#endif
|
|
5098
5260
|
#ifdef FOG
|
|
5099
5261
|
vFogDepth = -viewPosition.z;
|
|
@@ -5101,9 +5263,9 @@ vFogDepth = -viewPosition.z;
|
|
|
5101
5263
|
#ifdef SPRITES
|
|
5102
5264
|
#elif defined(SIZE_ATTENUATION)
|
|
5103
5265
|
float depth = uProjection[3][3] == 1.0 ? 1.0 : max(-viewPosition.z, 1e-4);
|
|
5104
|
-
gl_PointSize = uSize * uScale / depth;
|
|
5266
|
+
gl_PointSize = uSize * size * uScale / depth;
|
|
5105
5267
|
#else
|
|
5106
|
-
gl_PointSize = uSize;
|
|
5268
|
+
gl_PointSize = uSize * size;
|
|
5107
5269
|
#endif
|
|
5108
5270
|
vColor = vec3(1.0);
|
|
5109
5271
|
#ifdef VERTEX_COLORS
|
|
@@ -5114,7 +5276,7 @@ vHighlight = uHighlightIndex == -1 || self == uHighlightIndex ? 1.0 : 0.0;
|
|
|
5114
5276
|
vPickElement = uint(self);
|
|
5115
5277
|
#endif
|
|
5116
5278
|
}
|
|
5117
|
-
`,
|
|
5279
|
+
`, Br = `precision highp float;
|
|
5118
5280
|
in vec3 vColor;
|
|
5119
5281
|
flat in float vHighlight;
|
|
5120
5282
|
#ifdef SPRITES
|
|
@@ -5127,9 +5289,13 @@ uniform float uOpacity;
|
|
|
5127
5289
|
#ifdef MAP
|
|
5128
5290
|
uniform sampler2D uMap;
|
|
5129
5291
|
#endif
|
|
5292
|
+
#ifdef HOOK_FRAGMENT
|
|
5293
|
+
flat in float vPointIndex;
|
|
5294
|
+
#endif
|
|
5295
|
+
//@hook uniforms
|
|
5130
5296
|
out vec4 fragColor;
|
|
5131
|
-
${
|
|
5132
|
-
${
|
|
5297
|
+
${Nr}
|
|
5298
|
+
${kr}
|
|
5133
5299
|
void main() {
|
|
5134
5300
|
#ifdef SPRITES
|
|
5135
5301
|
vec2 at = vUv;
|
|
@@ -5146,11 +5312,23 @@ float r = dot(p, p);
|
|
|
5146
5312
|
float edge = fwidth(r);
|
|
5147
5313
|
base.a *= 1.0 - smoothstep(1.0 - edge, 1.0, r);
|
|
5148
5314
|
#endif
|
|
5315
|
+
#ifdef HOOK_FRAGMENT
|
|
5316
|
+
{
|
|
5317
|
+
vec2 pointUv = at;
|
|
5318
|
+
int index = int(vPointIndex + 0.5);
|
|
5319
|
+
//@hook fragment
|
|
5320
|
+
}
|
|
5321
|
+
#endif
|
|
5149
5322
|
if (base.a <= 0.0) discard;
|
|
5150
|
-
|
|
5151
|
-
|
|
5323
|
+
vec3 color = fogged(mix(base.rgb, uHighlight.rgb, vHighlight * uHighlight.a));
|
|
5324
|
+
#ifdef HOOK_LIT
|
|
5325
|
+
{
|
|
5326
|
+
//@hook lit
|
|
5327
|
+
}
|
|
5328
|
+
#endif
|
|
5329
|
+
fragColor = vec4(linearToSrgb(color) * base.a, base.a);
|
|
5152
5330
|
}
|
|
5153
|
-
`,
|
|
5331
|
+
`, Vr = `layout(location = 0) in vec3 segmentStart;
|
|
5154
5332
|
layout(location = 1) in vec3 segmentEnd;
|
|
5155
5333
|
layout(location = 2) in vec3 segmentColorStart;
|
|
5156
5334
|
layout(location = 3) in vec3 segmentColorEnd;
|
|
@@ -5163,10 +5341,16 @@ uniform float uWidth;
|
|
|
5163
5341
|
uniform float uNear;
|
|
5164
5342
|
uniform int uArrows;
|
|
5165
5343
|
uniform float uArrowSize;
|
|
5344
|
+
//@hook uniforms
|
|
5166
5345
|
const vec2 QUAD[6] = vec2[6](vec2(0.0, -1.0), vec2(0.0, 1.0), vec2(1.0, -1.0), vec2(1.0, -1.0), vec2(0.0, 1.0), vec2(1.0, 1.0));
|
|
5167
5346
|
out vec3 vColor;
|
|
5168
|
-
#
|
|
5347
|
+
#if defined(DASHED) || defined(HOOK_FRAGMENT)
|
|
5169
5348
|
out float vDistance;
|
|
5349
|
+
#endif
|
|
5350
|
+
#ifdef HOOK_FRAGMENT
|
|
5351
|
+
flat out float vSegment;
|
|
5352
|
+
#endif
|
|
5353
|
+
#ifdef DASHED
|
|
5170
5354
|
flat out float vArrow;
|
|
5171
5355
|
#endif
|
|
5172
5356
|
#ifdef PICK
|
|
@@ -5175,10 +5359,21 @@ flat out uint vPickElement;
|
|
|
5175
5359
|
#ifdef FOG
|
|
5176
5360
|
out float vFogDepth;
|
|
5177
5361
|
#endif
|
|
5178
|
-
${
|
|
5362
|
+
${Nr}
|
|
5363
|
+
#ifdef HOOK_VERTEX
|
|
5364
|
+
vec3 hookVertex(vec3 local, float along, int index) {
|
|
5365
|
+
//@hook vertex
|
|
5366
|
+
return local;
|
|
5367
|
+
}
|
|
5368
|
+
#endif
|
|
5179
5369
|
void main() {
|
|
5180
|
-
|
|
5181
|
-
|
|
5370
|
+
vec3 start = segmentStart, end = segmentEnd;
|
|
5371
|
+
#ifdef HOOK_VERTEX
|
|
5372
|
+
start = hookVertex(segmentStart, 0.0, gl_InstanceID);
|
|
5373
|
+
end = hookVertex(segmentEnd, 1.0, gl_InstanceID);
|
|
5374
|
+
#endif
|
|
5375
|
+
vec4 a = uView * (uModel * vec4(start, 1.0));
|
|
5376
|
+
vec4 b = uView * (uModel * vec4(end, 1.0));
|
|
5182
5377
|
float clipZ = -uNear;
|
|
5183
5378
|
if (a.z > clipZ && b.z > clipZ) {
|
|
5184
5379
|
gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
@@ -5222,8 +5417,13 @@ vFogDepth = -mix(a.z, b.z, along);
|
|
|
5222
5417
|
#endif
|
|
5223
5418
|
clip.xy += offset / (uResolution * 0.5) * clip.w;
|
|
5224
5419
|
gl_Position = clip;
|
|
5420
|
+
#if defined(DASHED) || defined(HOOK_FRAGMENT)
|
|
5421
|
+
vDistance = segmentInfo.x + length(end - start) * along;
|
|
5422
|
+
#endif
|
|
5423
|
+
#ifdef HOOK_FRAGMENT
|
|
5424
|
+
vSegment = float(gl_InstanceID);
|
|
5425
|
+
#endif
|
|
5225
5426
|
#ifdef DASHED
|
|
5226
|
-
vDistance = segmentInfo.x + length(segmentEnd - segmentStart) * along;
|
|
5227
5427
|
vArrow = arrow;
|
|
5228
5428
|
#endif
|
|
5229
5429
|
#ifdef PICK
|
|
@@ -5234,38 +5434,143 @@ vColor = vec3(1.0);
|
|
|
5234
5434
|
vColor = srgbToLinear(mix(segmentColorStart, segmentColorEnd, along));
|
|
5235
5435
|
#endif
|
|
5236
5436
|
}
|
|
5237
|
-
`,
|
|
5437
|
+
`, Hr = `precision highp float;
|
|
5238
5438
|
in vec3 vColor;
|
|
5239
5439
|
uniform vec3 uColor;
|
|
5240
5440
|
uniform float uOpacity;
|
|
5241
|
-
#
|
|
5441
|
+
#if defined(DASHED) || defined(HOOK_FRAGMENT)
|
|
5242
5442
|
in float vDistance;
|
|
5443
|
+
#endif
|
|
5444
|
+
#ifdef HOOK_FRAGMENT
|
|
5445
|
+
flat in float vSegment;
|
|
5446
|
+
#endif
|
|
5447
|
+
//@hook uniforms
|
|
5448
|
+
#ifdef DASHED
|
|
5243
5449
|
flat in float vArrow;
|
|
5244
5450
|
uniform float uDash;
|
|
5245
5451
|
uniform float uGap;
|
|
5246
5452
|
uniform float uDashOffset;
|
|
5247
5453
|
#endif
|
|
5248
5454
|
out vec4 fragColor;
|
|
5249
|
-
${
|
|
5250
|
-
${
|
|
5455
|
+
${Nr}
|
|
5456
|
+
${kr}
|
|
5251
5457
|
void main() {
|
|
5252
5458
|
#ifdef DASHED
|
|
5253
5459
|
if (vArrow < 0.5 && mod(vDistance - uDashOffset, uDash + uGap) >= uDash) discard;
|
|
5254
5460
|
#endif
|
|
5255
|
-
|
|
5256
|
-
|
|
5461
|
+
vec4 base = vec4(uColor * vColor, uOpacity);
|
|
5462
|
+
#ifdef HOOK_FRAGMENT
|
|
5463
|
+
{
|
|
5464
|
+
float distance = vDistance;
|
|
5465
|
+
int index = int(vSegment + 0.5);
|
|
5466
|
+
//@hook fragment
|
|
5257
5467
|
}
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5468
|
+
if (base.a <= 0.0) discard;
|
|
5469
|
+
#endif
|
|
5470
|
+
vec3 color = fogged(base.rgb);
|
|
5471
|
+
#ifdef HOOK_LIT
|
|
5472
|
+
{
|
|
5473
|
+
//@hook lit
|
|
5474
|
+
}
|
|
5475
|
+
#endif
|
|
5476
|
+
fragColor = vec4(linearToSrgb(color) * base.a, base.a);
|
|
5477
|
+
}
|
|
5478
|
+
`, Ur = {
|
|
5479
|
+
mesh: [Lr, Rr],
|
|
5480
|
+
points: [zr, Br],
|
|
5481
|
+
lines: [Vr, Hr]
|
|
5482
|
+
}, Wr = "highp uint phoriaMix(highp uint h) {\nh ^= h >> 16u; h *= 0x7feb352du; h ^= h >> 15u; h *= 0x846ca68bu; h ^= h >> 16u;\nreturn h;\n}\nfloat phoriaUnit(highp uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }\nfloat hash(float x) { return phoriaUnit(phoriaMix(floatBitsToUint(x))); }\nfloat hash(vec2 p) { highp uvec2 u = floatBitsToUint(p); return phoriaUnit(phoriaMix(u.x ^ phoriaMix(u.y + 0x9e3779b9u))); }\nfloat hash(vec3 p) { highp uvec3 u = floatBitsToUint(p); return phoriaUnit(phoriaMix(u.x ^ phoriaMix(u.y ^ phoriaMix(u.z + 0x9e3779b9u)))); }\nhighp uint phoriaCell(highp ivec3 c) {\nhighp uvec3 u = uvec3(c) * uvec3(0x8da6b343u, 0xd8163841u, 0xcb1ab31fu);\nreturn phoriaMix(u.x ^ u.y ^ u.z);\n}\nfloat vnoise(vec3 p) {\nvec3 i = floor(p), f = p - i;\nvec3 s = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\nhighp ivec3 c = ivec3(i);\nfloat a = mix(phoriaUnit(phoriaCell(c)), phoriaUnit(phoriaCell(c + ivec3(1, 0, 0))), s.x);\nfloat b = mix(phoriaUnit(phoriaCell(c + ivec3(0, 1, 0))), phoriaUnit(phoriaCell(c + ivec3(1, 1, 0))), s.x);\nfloat d = mix(phoriaUnit(phoriaCell(c + ivec3(0, 0, 1))), phoriaUnit(phoriaCell(c + ivec3(1, 0, 1))), s.x);\nfloat e = mix(phoriaUnit(phoriaCell(c + ivec3(0, 1, 1))), phoriaUnit(phoriaCell(c + ivec3(1, 1, 1))), s.x);\nreturn mix(mix(a, b, s.y), mix(d, e, s.y), s.z);\n}\nfloat vnoise(vec2 p) {\nvec2 i = floor(p), f = p - i;\nvec2 s = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\nhighp ivec3 c = ivec3(ivec2(i), 0);\nreturn mix(mix(phoriaUnit(phoriaCell(c)), phoriaUnit(phoriaCell(c + ivec3(1, 0, 0))), s.x),\nmix(phoriaUnit(phoriaCell(c + ivec3(0, 1, 0))), phoriaUnit(phoriaCell(c + ivec3(1, 1, 0))), s.x), s.y);\n}\nvec2 phoriaGrad2(highp ivec2 c) {\nfloat a = phoriaUnit(phoriaCell(ivec3(c, 7))) * 6.28318530718;\nreturn vec2(cos(a), sin(a));\n}\nvoid phoriaCorner2(vec2 x, highp ivec2 c, inout float n, inout vec2 d) {\nfloat t = 0.5 - dot(x, x);\nif (t <= 0.0) return;\nvec2 g = phoriaGrad2(c);\nfloat t2 = t * t, gx = dot(g, x);\nn += t2 * t2 * gx;\nd += t2 * t2 * g - 8.0 * t2 * t * gx * x;\n}\nvec3 snoised(vec2 p) {\nconst float F = 0.366025403784, G = 0.211324865405;\nvec2 i = floor(p + (p.x + p.y) * F);\nvec2 x0 = p - i + (i.x + i.y) * G;\nvec2 o = x0.x > x0.y ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\nhighp ivec2 c = ivec2(i);\nfloat n = 0.0;\nvec2 d = vec2(0.0);\nphoriaCorner2(x0, c, n, d);\nphoriaCorner2(x0 - o + G, c + ivec2(o), n, d);\nphoriaCorner2(x0 - 1.0 + 2.0 * G, c + 1, n, d);\nreturn vec3(0.5 + 35.0 * n, 35.0 * d);\n}\nfloat snoise(vec2 p) { return snoised(p).x; }\nconst vec3 PHORIA_EDGES[12] = vec3[12](vec3(1, 1, 0), vec3(-1, 1, 0), vec3(1, -1, 0), vec3(-1, -1, 0),\nvec3(1, 0, 1), vec3(-1, 0, 1), vec3(1, 0, -1), vec3(-1, 0, -1), vec3(0, 1, 1), vec3(0, -1, 1), vec3(0, 1, -1), vec3(0, -1, -1));\nvoid phoriaCorner3(vec3 x, highp ivec3 c, inout float n, inout vec3 d) {\nfloat t = 0.6 - dot(x, x);\nif (t <= 0.0) return;\nvec3 g = PHORIA_EDGES[phoriaCell(c) % 12u];\nfloat t2 = t * t, gx = dot(g, x);\nn += t2 * t2 * gx;\nd += t2 * t2 * g - 8.0 * t2 * t * gx * x;\n}\nvec4 snoised(vec3 p) {\nconst float F = 1.0 / 3.0, G = 1.0 / 6.0;\nvec3 i = floor(p + dot(p, vec3(F)));\nvec3 x0 = p - i + dot(i, vec3(G));\nvec3 g = step(x0.yzx, x0.xyz), l = 1.0 - g;\nvec3 i1 = min(g, l.zxy), i2 = max(g, l.zxy);\nhighp ivec3 c = ivec3(i);\nfloat n = 0.0;\nvec3 d = vec3(0.0);\nphoriaCorner3(x0, c, n, d);\nphoriaCorner3(x0 - i1 + G, c + ivec3(i1), n, d);\nphoriaCorner3(x0 - i2 + 2.0 * G, c + ivec3(i2), n, d);\nphoriaCorner3(x0 - 1.0 + 3.0 * G, c + 1, n, d);\nreturn vec4(0.5 + 16.0 * n, 16.0 * d);\n}\nfloat snoise(vec3 p) { return snoised(p).x; }\nconst mat2 PHORIA_TURN2 = mat2(0.8, 0.6, -0.6, 0.8);\nconst mat3 PHORIA_TURN3 = mat3(0.00, 0.80, 0.60, -0.80, 0.36, -0.48, -0.60, -0.48, 0.64);\nfloat vfbm(vec2 p, int octaves) {\nfloat v = 0.0, a = 0.5, sum = 0.0;\nfor (int i = 0; i < clamp(octaves, 1, 12); i++) { v += a * vnoise(p); sum += a; p = PHORIA_TURN2 * p * 2.03 + 17.0; a *= 0.5; }\nreturn v / sum;\n}\nfloat vfbm(vec3 p, int octaves) {\nfloat v = 0.0, a = 0.5, sum = 0.0;\nfor (int i = 0; i < clamp(octaves, 1, 12); i++) { v += a * vnoise(p); sum += a; p = PHORIA_TURN3 * p * 2.03 + 17.0; a *= 0.5; }\nreturn v / sum;\n}\nfloat sfbm(vec2 p, int octaves) {\nfloat v = 0.0, a = 0.5, sum = 0.0;\nfor (int i = 0; i < clamp(octaves, 1, 12); i++) { v += a * snoise(p); sum += a; p = PHORIA_TURN2 * p * 2.03 + 17.0; a *= 0.5; }\nreturn v / sum;\n}\nfloat sfbm(vec3 p, int octaves) {\nfloat v = 0.0, a = 0.5, sum = 0.0;\nfor (int i = 0; i < clamp(octaves, 1, 12); i++) { v += a * snoise(p); sum += a; p = PHORIA_TURN3 * p * 2.03 + 17.0; a *= 0.5; }\nreturn v / sum;\n}\nvec3 sfbmd(vec2 p, int octaves) {\nfloat v = 0.0, a = 0.5, sum = 0.0;\nvec2 d = vec2(0.0);\nmat2 m = mat2(1.0);\nfor (int i = 0; i < clamp(octaves, 1, 12); i++) {\nvec3 n = snoised(p);\nv += a * n.x;\nd += a * (transpose(m) * n.yz);\nsum += a;\np = PHORIA_TURN2 * p * 2.03 + 17.0;\nm = PHORIA_TURN2 * m * 2.03;\na *= 0.5;\n}\nreturn vec3(v, d) / sum;\n}\nvec4 sfbmd(vec3 p, int octaves) {\nfloat v = 0.0, a = 0.5, sum = 0.0;\nvec3 d = vec3(0.0);\nmat3 m = mat3(1.0);\nfor (int i = 0; i < clamp(octaves, 1, 12); i++) {\nvec4 n = snoised(p);\nv += a * n.x;\nd += a * (transpose(m) * n.yzw);\nsum += a;\np = PHORIA_TURN3 * p * 2.03 + 17.0;\nm = PHORIA_TURN3 * m * 2.03;\na *= 0.5;\n}\nreturn vec4(v, d) / sum;\n}\nfloat vfbm(vec2 p) { return vfbm(p, 5); }\nfloat vfbm(vec3 p) { return vfbm(p, 5); }\nfloat sfbm(vec2 p) { return sfbm(p, 5); }\nfloat sfbm(vec3 p) { return sfbm(p, 5); }\nvec3 sfbmd(vec2 p) { return sfbmd(p, 5); }\nvec4 sfbmd(vec3 p) { return sfbmd(p, 5); }\nvec3 voronoi(vec2 p) {\nvec2 i = floor(p), f = p - i;\nhighp ivec2 c = ivec2(i);\nfloat f1 = 8.0, f2 = 8.0, id = 0.0;\nfor (int y = -1; y <= 1; y++) {\nfor (int x = -1; x <= 1; x++) {\nhighp uint h = phoriaCell(ivec3(c + ivec2(x, y), 11));\nvec2 o = vec2(float(x), float(y)) + vec2(phoriaUnit(h), phoriaUnit(phoriaMix(h ^ 0x68e31da4u))) - f;\nfloat d = dot(o, o);\nif (d < f1) { f2 = f1; f1 = d; id = phoriaUnit(phoriaMix(h + 0x1b56c4e9u)); }\nelse if (d < f2) f2 = d;\n}\n}\nreturn vec3(sqrt(f1), sqrt(f2), id);\n}\nvec3 voronoi(vec3 p) {\nvec3 i = floor(p), f = p - i;\nhighp ivec3 c = ivec3(i);\nfloat f1 = 8.0, f2 = 8.0, id = 0.0;\nfor (int z = -1; z <= 1; z++) {\nfor (int y = -1; y <= 1; y++) {\nfor (int x = -1; x <= 1; x++) {\nhighp uint h = phoriaCell(c + ivec3(x, y, z)) ^ 0x2545f491u;\nh = phoriaMix(h);\nvec3 o = vec3(float(x), float(y), float(z)) - f\n+ vec3(phoriaUnit(h), phoriaUnit(phoriaMix(h ^ 0x68e31da4u)), phoriaUnit(phoriaMix(h ^ 0xb5297a4du)));\nfloat d = dot(o, o);\nif (d < f1) { f2 = f1; f1 = d; id = phoriaUnit(phoriaMix(h + 0x1b56c4e9u)); }\nelse if (d < f2) f2 = d;\n}\n}\n}\nreturn vec3(sqrt(f1), sqrt(f2), id);\n}\nvec3 srgb(vec3 c) { return mix(c / 12.92, pow((c + 0.055) / 1.055, vec3(2.4)), step(vec3(0.04045), c)); }\nvec3 hsv2rgb(vec3 hsv) {\nvec3 k = clamp(abs(mod(hsv.x * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0);\nreturn srgb(hsv.z * mix(vec3(1.0), k, hsv.y));\n}\nvec3 hsv2rgb(float h, float s, float v) { return hsv2rgb(vec3(h, s, v)); }\nvec3 palette(float t, vec3 a, vec3 b, vec3 c, vec3 d) { return srgb(clamp(a + b * cos(6.28318530718 * (c * t + d)), 0.0, 1.0)); }\nfloat fresnel(vec3 normal, vec3 position, float power) {\nvec3 v = normalize(cameraPosition - position);\nreturn pow(1.0 - clamp(abs(dot(normalize(normal), v)), 0.0, 1.0), power);\n}\nmat2 rotate2(float a) { float s = sin(a), c = cos(a); return mat2(c, s, -s, c); }\nmat3 rotate3(vec3 axis, float a) {\nvec3 u = normalize(axis);\nfloat s = sin(a), c = cos(a), t = 1.0 - c;\nreturn mat3(t * u.x * u.x + c, t * u.x * u.y + s * u.z, t * u.x * u.z - s * u.y,\nt * u.x * u.y - s * u.z, t * u.y * u.y + c, t * u.y * u.z + s * u.x,\nt * u.x * u.z + s * u.y, t * u.y * u.z - s * u.x, t * u.z * u.z + c);\n}\nfloat remap(float x, float a, float b, float c, float d) { return c + (x - a) * (d - c) / (b - a); }\nvec2 remap(vec2 x, float a, float b, float c, float d) { return c + (x - a) * (d - c) / (b - a); }\nvec3 remap(vec3 x, float a, float b, float c, float d) { return c + (x - a) * (d - c) / (b - a); }\nfloat saturate(float x) { return clamp(x, 0.0, 1.0); }\nvec2 saturate(vec2 x) { return clamp(x, 0.0, 1.0); }\nvec3 saturate(vec3 x) { return clamp(x, 0.0, 1.0); }\nvec4 saturate(vec4 x) { return clamp(x, 0.0, 1.0); }\n", Gr = {
|
|
5483
|
+
vertex: 101,
|
|
5484
|
+
fragment: 102,
|
|
5485
|
+
lit: 103
|
|
5262
5486
|
};
|
|
5263
|
-
function
|
|
5264
|
-
let
|
|
5265
|
-
return [
|
|
5487
|
+
function Kr(e, t, n = null) {
|
|
5488
|
+
let r = `#version 300 es\n${t.map((e) => `#define ${e}\n`).join("")}`, [i, a] = typeof e == "string" ? Ur[e] : e;
|
|
5489
|
+
if (!n) return [r + i, r + a];
|
|
5490
|
+
let o = 2 + t.length;
|
|
5491
|
+
return [r + qr(i, n, o), r + qr(a, n, o)];
|
|
5492
|
+
}
|
|
5493
|
+
function qr(e, t, n) {
|
|
5494
|
+
return e.split("\n").map((e, r) => {
|
|
5495
|
+
let i = /^\s*\/\/@hook (\w+)$/.exec(e);
|
|
5496
|
+
if (!i) return e;
|
|
5497
|
+
let a = i[1], o = `#line ${n + r + 1} 0`;
|
|
5498
|
+
return a === "uniforms" ? `${t.uniforms}\n${t.helpers ?? ""}\n${o}` : `#line 1 ${Gr[a]}\n${t[a]}\n${o}`;
|
|
5499
|
+
}).join("\n");
|
|
5500
|
+
}
|
|
5501
|
+
// src/webgl/hooks.js
|
|
5502
|
+
var Jr = /* @__PURE__ */ new Map(), Yr = /* @__PURE__ */ new Set(), Xr = /* @__PURE__ */ new WeakMap();
|
|
5503
|
+
function Zr(e) {
|
|
5504
|
+
return typeof e == "number" ? "float" : e instanceof W ? "sampler2D" : `vec${e.length}`;
|
|
5505
|
+
}
|
|
5506
|
+
var Qr = null, $r = () => Qr ??= new Set([
|
|
5507
|
+
Lr,
|
|
5508
|
+
zr,
|
|
5509
|
+
Vr,
|
|
5510
|
+
Mr,
|
|
5511
|
+
...[
|
|
5512
|
+
"mesh",
|
|
5513
|
+
"points",
|
|
5514
|
+
"lines"
|
|
5515
|
+
].flatMap((e) => Kr(e, []))
|
|
5516
|
+
].flatMap((e) => [...e.matchAll(/uniform\s+\w+\s+(\w+)/g)].map((e) => e[1])));
|
|
5517
|
+
function ei(e) {
|
|
5518
|
+
let t = e.shader;
|
|
5519
|
+
if (!t) return null;
|
|
5520
|
+
let n = Object.entries(t.uniforms).map(([e, t]) => `${Zr(t)} ${e}`).join(";"), r = Xr.get(t);
|
|
5521
|
+
if (r && r.types === n) return r.hook;
|
|
5522
|
+
let i = JSON.stringify([
|
|
5523
|
+
t.vertex,
|
|
5524
|
+
t.fragment,
|
|
5525
|
+
t.lit,
|
|
5526
|
+
n
|
|
5527
|
+
]), a = Yr.has(i) ? null : Jr.get(i) ?? null;
|
|
5528
|
+
if (!a && !Yr.has(i)) {
|
|
5529
|
+
let r = Object.keys(t.uniforms).find((e) => $r().has(e));
|
|
5530
|
+
r ? (Yr.add(i), F(e, `shader uniform '${r}' is one of phoria2's own - give it another name; the material is drawn without its shader hooks`)) : (a = {
|
|
5531
|
+
signature: i,
|
|
5532
|
+
defines: [
|
|
5533
|
+
...t.vertex ? ["HOOK_VERTEX"] : [],
|
|
5534
|
+
...t.fragment ? ["HOOK_FRAGMENT"] : [],
|
|
5535
|
+
...t.lit ? ["HOOK_LIT"] : [],
|
|
5536
|
+
`HOOKS ${Jr.size + 1}`
|
|
5537
|
+
],
|
|
5538
|
+
source: {
|
|
5539
|
+
uniforms: [
|
|
5540
|
+
"uniform float uTime;",
|
|
5541
|
+
"uniform vec3 cameraPosition;",
|
|
5542
|
+
...n.split(";").filter(Boolean).map((e) => `uniform ${e};`)
|
|
5543
|
+
].join("\n"),
|
|
5544
|
+
helpers: Wr,
|
|
5545
|
+
vertex: t.vertex,
|
|
5546
|
+
fragment: t.fragment,
|
|
5547
|
+
lit: t.lit
|
|
5548
|
+
},
|
|
5549
|
+
moves: !!t.vertex
|
|
5550
|
+
}, Jr.set(i, a));
|
|
5551
|
+
}
|
|
5552
|
+
return Xr.set(t, {
|
|
5553
|
+
types: n,
|
|
5554
|
+
hook: a
|
|
5555
|
+
}), a;
|
|
5266
5556
|
}
|
|
5267
|
-
|
|
5268
|
-
|
|
5557
|
+
function ti(e, t) {
|
|
5558
|
+
return e.defines.filter((e) => e !== "HOOK_LIT" && (t || e !== "HOOK_FRAGMENT"));
|
|
5559
|
+
}
|
|
5560
|
+
function ni(e, t, n, r, i) {
|
|
5561
|
+
e.set("uTime", n), e.set("cameraPosition", r);
|
|
5562
|
+
let a = t.shader.uniforms;
|
|
5563
|
+
for (let t in a) {
|
|
5564
|
+
let n = a[t];
|
|
5565
|
+
e.set(t, n instanceof W ? i(n) : n);
|
|
5566
|
+
}
|
|
5567
|
+
}
|
|
5568
|
+
function ri(e, t, n) {
|
|
5569
|
+
Yr.add(t.signature), Xr.delete(e.shader);
|
|
5570
|
+
let r = Object.fromEntries(Object.entries(Gr).map(([e, t]) => [t, e])), i = n.split("\n").map((e) => /ERROR:\s*(\d+):(\d+):\s*(.*)/.exec(e)).filter((e) => !!e), a = i.filter((e) => r[e[1]]), o = a.length ? a.map((e) => `shader.${r[e[1]]} line ${e[2]}: ${e[3]}`).join("; ") : `in phoria2's shader around the hook: ${i[0]?.[3] ?? n.trim().split("\n")[0]}`, s = Object.keys(e.shader.uniforms);
|
|
5571
|
+
F(e, `a shader hook doesn't compile - ${o}. Hooks can use ${ii}, uTime${s.length ? `, ${s.join(", ")}` : ""}, cameraPosition, and call hash, vnoise, snoise, snoised, vfbm, sfbm, sfbmd, voronoi, srgb, hsv2rgb, palette, fresnel, rotate2, rotate3, remap and saturate. The material is drawn without its hooks`);
|
|
5572
|
+
}
|
|
5573
|
+
var ii = "local, n, uv, index, size, along (vertex); base, emissive, normal, vUv, vWorldPosition, vNormal, vColor, pointUv, distance (fragment); color, base (lit)", ai = class {
|
|
5269
5574
|
#e = /* @__PURE__ */ new Map();
|
|
5270
5575
|
#t;
|
|
5271
5576
|
#n = null;
|
|
@@ -5280,13 +5585,13 @@ var Rr = class {
|
|
|
5280
5585
|
for (let t of this.#e.values()) !t.ready && !this.isReady(t) && e++;
|
|
5281
5586
|
return e;
|
|
5282
5587
|
}
|
|
5283
|
-
get(e, t, n) {
|
|
5284
|
-
let
|
|
5285
|
-
return
|
|
5588
|
+
get(e, t, n, r = null) {
|
|
5589
|
+
let i = `${e}|${t.join(",")}`, a = this.#e.get(i);
|
|
5590
|
+
return a || (a = this.#r(i, Kr(n ?? e, t, r), !!r), this.#e.set(i, a)), a;
|
|
5286
5591
|
}
|
|
5287
|
-
ready(e, t, n) {
|
|
5288
|
-
let
|
|
5289
|
-
return
|
|
5592
|
+
ready(e, t, n, r = null) {
|
|
5593
|
+
let i = this.get(e, t, n, r);
|
|
5594
|
+
return i.ready || this.#i(i), i;
|
|
5290
5595
|
}
|
|
5291
5596
|
isReady(e) {
|
|
5292
5597
|
return e.ready ? !0 : this.#t && !this.gl.getProgramParameter(e.program, 37297) ? !1 : (this.#i(e), !0);
|
|
@@ -5302,38 +5607,45 @@ var Rr = class {
|
|
|
5302
5607
|
for (let e of this.#e.values()) this.gl.deleteProgram(e.program);
|
|
5303
5608
|
this.#e.clear(), this.#n && this.gl.deleteVertexArray(this.#n), this.#n = null;
|
|
5304
5609
|
}
|
|
5305
|
-
#r(e, t) {
|
|
5306
|
-
let
|
|
5307
|
-
let
|
|
5308
|
-
return
|
|
5309
|
-
},
|
|
5310
|
-
|
|
5311
|
-
let
|
|
5312
|
-
program:
|
|
5610
|
+
#r(e, t, n = !1) {
|
|
5611
|
+
let r = this.gl, i = (e, t) => {
|
|
5612
|
+
let n = r.createShader(e);
|
|
5613
|
+
return r.shaderSource(n, t), r.compileShader(n), n;
|
|
5614
|
+
}, a = r.createProgram(), o = i(r.VERTEX_SHADER, t[0]), s = i(r.FRAGMENT_SHADER, t[1]);
|
|
5615
|
+
r.attachShader(a, o), r.attachShader(a, s), r.linkProgram(a);
|
|
5616
|
+
let c = {
|
|
5617
|
+
program: a,
|
|
5313
5618
|
key: e,
|
|
5314
5619
|
frame: -1,
|
|
5315
5620
|
ready: !1,
|
|
5316
5621
|
set() {},
|
|
5317
|
-
shaders: [
|
|
5318
|
-
sources: t
|
|
5622
|
+
shaders: [o, s],
|
|
5623
|
+
sources: t,
|
|
5624
|
+
hooked: n
|
|
5319
5625
|
};
|
|
5320
|
-
return this.#t || this.#i(
|
|
5626
|
+
return this.#t || this.#i(c), c;
|
|
5321
5627
|
}
|
|
5322
5628
|
#i(e) {
|
|
5323
5629
|
let t = this.gl, { program: n, key: r, shaders: i, sources: a } = e;
|
|
5324
|
-
if (!t.getProgramParameter(n, t.LINK_STATUS) && !t.isContextLost())
|
|
5325
|
-
if (
|
|
5326
|
-
|
|
5630
|
+
if (!t.getProgramParameter(n, t.LINK_STATUS) && !t.isContextLost()) {
|
|
5631
|
+
if (e.hooked) {
|
|
5632
|
+
e.failed = i.map((e) => t.getShaderParameter(e, t.COMPILE_STATUS) ? "" : t.getShaderInfoLog(e) ?? "").join("\n") || (t.getProgramInfoLog(n) ?? "failed to link"), e.ready = !0;
|
|
5633
|
+
return;
|
|
5634
|
+
}
|
|
5635
|
+
throw i.forEach((e, n) => {
|
|
5636
|
+
if (!t.getShaderParameter(e, t.COMPILE_STATUS)) throw Error(`phoria2: ${n ? "fragment" : "vertex"} shader '${r}' failed to compile:\n${t.getShaderInfoLog(e)}\n${si(a[n])}`);
|
|
5637
|
+
}), Error(`phoria2: shader program '${r}' failed to link: ${t.getProgramInfoLog(n)}`);
|
|
5638
|
+
}
|
|
5327
5639
|
for (let e of i) t.deleteShader(e);
|
|
5328
5640
|
let o = /* @__PURE__ */ new Map(), s = t.getProgramParameter(n, t.ACTIVE_UNIFORMS), c = 0;
|
|
5329
5641
|
for (let e = 0; e < s; e++) {
|
|
5330
5642
|
let r = t.getActiveUniform(n, e), i = r.name.replace(/\[0\]$/, ""), a = t.getUniformLocation(n, r.name), s = r.type === t.SAMPLER_2D || r.type === t.SAMPLER_2D_SHADOW || r.type === t.SAMPLER_CUBE_SHADOW;
|
|
5331
|
-
o.set(i,
|
|
5643
|
+
o.set(i, oi(t, r.type, a, s ? c++ : 0));
|
|
5332
5644
|
}
|
|
5333
5645
|
e.set = (e, t) => o.get(e)?.(t), e.ready = !0;
|
|
5334
5646
|
}
|
|
5335
5647
|
};
|
|
5336
|
-
function
|
|
5648
|
+
function oi(e, t, n, r) {
|
|
5337
5649
|
switch (t) {
|
|
5338
5650
|
case e.FLOAT: return (t) => typeof t == "number" ? e.uniform1f(n, t) : e.uniform1fv(n, t);
|
|
5339
5651
|
case e.FLOAT_VEC2: return (t) => e.uniform2fv(n, t);
|
|
@@ -5354,8 +5666,8 @@ function zr(e, t, n, r) {
|
|
|
5354
5666
|
default: return () => {};
|
|
5355
5667
|
}
|
|
5356
5668
|
}
|
|
5357
|
-
var
|
|
5358
|
-
function
|
|
5669
|
+
var si = (e) => e.split("\n").map((e, t) => `${String(t + 1).padStart(4)} ${e}`).join("\n"), ci = 15, li = 16, ui = 4;
|
|
5670
|
+
function di(e, t, n, r) {
|
|
5359
5671
|
return [
|
|
5360
5672
|
e.positions.length,
|
|
5361
5673
|
n,
|
|
@@ -5368,7 +5680,7 @@ function Wr(e, t, n, r) {
|
|
|
5368
5680
|
r
|
|
5369
5681
|
].join();
|
|
5370
5682
|
}
|
|
5371
|
-
function
|
|
5683
|
+
function fi(e) {
|
|
5372
5684
|
let t = e.positions, n = e.normals, r = e.uvs, i = t.length / 3, a = new Float32Array(i * 4), o = new Float32Array(i * 3), s = new Float32Array(i * 3);
|
|
5373
5685
|
if (r) {
|
|
5374
5686
|
let n = e.indices, a = (n ? n.length : i) / 3;
|
|
@@ -5398,12 +5710,12 @@ function Gr(e) {
|
|
|
5398
5710
|
}
|
|
5399
5711
|
return a;
|
|
5400
5712
|
}
|
|
5401
|
-
var
|
|
5402
|
-
function
|
|
5403
|
-
let t = Math.cos(e.rotation), n = Math.sin(e.rotation), [r, i] = e.repeat, [a, o] = e.center, s =
|
|
5713
|
+
var pi = /* @__PURE__ */ new Float32Array(9);
|
|
5714
|
+
function mi(e) {
|
|
5715
|
+
let t = Math.cos(e.rotation), n = Math.sin(e.rotation), [r, i] = e.repeat, [a, o] = e.center, s = pi;
|
|
5404
5716
|
return s[0] = t * r, s[1] = -n * r, s[2] = 0, s[3] = n * i, s[4] = t * i, s[5] = 0, s[6] = a - t * a - n * o + e.offset[0], s[7] = o + n * a - t * o + e.offset[1], s[8] = 1, s;
|
|
5405
5717
|
}
|
|
5406
|
-
var
|
|
5718
|
+
var hi = new Float32Array([
|
|
5407
5719
|
0,
|
|
5408
5720
|
-1,
|
|
5409
5721
|
0,
|
|
@@ -5412,7 +5724,7 @@ var Jr = new Float32Array([
|
|
|
5412
5724
|
-1,
|
|
5413
5725
|
1,
|
|
5414
5726
|
1
|
|
5415
|
-
]),
|
|
5727
|
+
]), gi = [
|
|
5416
5728
|
[
|
|
5417
5729
|
Z.position,
|
|
5418
5730
|
3,
|
|
@@ -5443,7 +5755,7 @@ var Jr = new Float32Array([
|
|
|
5443
5755
|
1,
|
|
5444
5756
|
9
|
|
5445
5757
|
]
|
|
5446
|
-
],
|
|
5758
|
+
], _i = 10, vi = class {
|
|
5447
5759
|
gl;
|
|
5448
5760
|
#e = /* @__PURE__ */ new WeakMap();
|
|
5449
5761
|
#t = /* @__PURE__ */ new WeakMap();
|
|
@@ -5475,11 +5787,11 @@ var Jr = new Float32Array([
|
|
|
5475
5787
|
this.#d(i);
|
|
5476
5788
|
let a = n ? this.#e : this.#t, o = a.get(i), s = o?.geometry === e;
|
|
5477
5789
|
if (r = n && (r || s && !!o?.attributes?.tangent), o && s && o.version === e.version && (!t || o.instanceVersion === t.version) && r === !!o.attributes?.tangent) return o;
|
|
5478
|
-
let c =
|
|
5790
|
+
let c = di(e, t, n, r);
|
|
5479
5791
|
if (o && s && o.layout === c) {
|
|
5480
5792
|
if (o.version !== e.version) {
|
|
5481
5793
|
let t = o.attributes;
|
|
5482
|
-
this.#u(t.position, e.positions), n && this.#u(t.normal, e.normals), e.uvs && this.#u(t.uv, e.uvs), e.uvs2 && this.#u(t.uv2, e.uvs2), e.colors && this.#u(t.color, e.colors), r && this.#u(t.tangent,
|
|
5794
|
+
this.#u(t.position, e.positions), n && this.#u(t.normal, e.normals), e.uvs && this.#u(t.uv, e.uvs), e.uvs2 && this.#u(t.uv2, e.uvs2), e.colors && this.#u(t.color, e.colors), r && this.#u(t.tangent, fi(e)), e.indices && (this.gl.bindVertexArray(o.vao), this.gl.bufferSubData(this.gl.ELEMENT_ARRAY_BUFFER, 0, e.indices), this.gl.bindVertexArray(null)), o.version = e.version;
|
|
5483
5795
|
}
|
|
5484
5796
|
return t && o.instanceVersion !== t.version && (this.#u(o.matrixBuffer, t.instanceMatrices), t.instanceColors && this.#u(o.colorBuffer, t.instanceColors), o.instanceVersion = t.version), o;
|
|
5485
5797
|
}
|
|
@@ -5490,7 +5802,7 @@ var Jr = new Float32Array([
|
|
|
5490
5802
|
let i = l.createBuffer();
|
|
5491
5803
|
return l.bindBuffer(l.ARRAY_BUFFER, i), l.bufferData(l.ARRAY_BUFFER, t, l.STATIC_DRAW), l.enableVertexAttribArray(e), l.vertexAttribPointer(e, n, l.FLOAT, !1, 0, 0), r && l.vertexAttribDivisor(e, r), d.push(i), i;
|
|
5492
5804
|
}, p = {};
|
|
5493
|
-
p.position = f(Z.position, e.positions, 3), n && (p.normal = f(Z.normal, e.normals, 3)), e.uvs ? p.uv = f(Z.uv, e.uvs, 2) : l.vertexAttrib2f(Z.uv, 0, 0), e.uvs2 && (p.uv2 = f(Z.uv2, e.uvs2, 2)), e.colors ? p.color = f(Z.color, e.colors, 3) : l.vertexAttrib3f(Z.color, 1, 1, 1), r && (p.tangent = f(Z.tangent,
|
|
5805
|
+
p.position = f(Z.position, e.positions, 3), n && (p.normal = f(Z.normal, e.normals, 3)), e.uvs ? p.uv = f(Z.uv, e.uvs, 2) : l.vertexAttrib2f(Z.uv, 0, 0), e.uvs2 && (p.uv2 = f(Z.uv2, e.uvs2, 2)), e.colors ? p.color = f(Z.color, e.colors, 3) : l.vertexAttrib3f(Z.color, 1, 1, 1), r && (p.tangent = f(Z.tangent, fi(e), 4));
|
|
5494
5806
|
let m = null, h = null;
|
|
5495
5807
|
if (t) {
|
|
5496
5808
|
m = l.createBuffer(), l.bindBuffer(l.ARRAY_BUFFER, m), l.bufferData(l.ARRAY_BUFFER, t.instanceMatrices, l.STATIC_DRAW);
|
|
@@ -5573,8 +5885,8 @@ var Jr = new Float32Array([
|
|
|
5573
5885
|
width: 0,
|
|
5574
5886
|
height: 0,
|
|
5575
5887
|
internal: 0
|
|
5576
|
-
}, this.#i.set(e, n), this.counts.textures++, e.onDispose(() => this.#f(e))), t.activeTexture(t.TEXTURE0 +
|
|
5577
|
-
let r = e.image, i = "data" in r ? r : null, a = !!i && i.data instanceof Float32Array, o = a ? t.RGBA16F : e.colorSpace === "srgb" ? t.SRGB8_ALPHA8 : t.RGBA8, s = a ? t.FLOAT : t.UNSIGNED_BYTE, [c, l] =
|
|
5888
|
+
}, this.#i.set(e, n), this.counts.textures++, e.onDispose(() => this.#f(e))), t.activeTexture(t.TEXTURE0 + ci), t.bindTexture(t.TEXTURE_2D, n.texture), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, e.flipY), t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1);
|
|
5889
|
+
let r = e.image, i = "data" in r ? r : null, a = !!i && i.data instanceof Float32Array, o = a ? t.RGBA16F : e.colorSpace === "srgb" ? t.SRGB8_ALPHA8 : t.RGBA8, s = a ? t.FLOAT : t.UNSIGNED_BYTE, [c, l] = yi(r);
|
|
5578
5890
|
if (n.version < 0 || n.width !== c || n.height !== l || n.internal !== o) i ? t.texImage2D(t.TEXTURE_2D, 0, o, c, l, 0, t.RGBA, s, i.data) : t.texImage2D(t.TEXTURE_2D, 0, o, t.RGBA, s, r), Object.assign(n, {
|
|
5579
5891
|
width: c,
|
|
5580
5892
|
height: l,
|
|
@@ -5582,7 +5894,7 @@ var Jr = new Float32Array([
|
|
|
5582
5894
|
});
|
|
5583
5895
|
else {
|
|
5584
5896
|
let a = e.flipY ? null : e.changedSince(n.version);
|
|
5585
|
-
a && a.length >
|
|
5897
|
+
a && a.length > li && (a = bi(a, c, l));
|
|
5586
5898
|
for (let e of a ?? [{
|
|
5587
5899
|
x: 0,
|
|
5588
5900
|
y: 0,
|
|
@@ -5614,7 +5926,7 @@ var Jr = new Float32Array([
|
|
|
5614
5926
|
let t = e;
|
|
5615
5927
|
if (t.isDrawable) {
|
|
5616
5928
|
n.add(t.geometry), "instanceMatrices" in t && n.add(t);
|
|
5617
|
-
for (let [, e] of t.material.
|
|
5929
|
+
for (let [, e] of t.material.allTextures) n.add(e);
|
|
5618
5930
|
}
|
|
5619
5931
|
});
|
|
5620
5932
|
for (let t of n) {
|
|
@@ -5649,8 +5961,8 @@ var Jr = new Float32Array([
|
|
|
5649
5961
|
let t = n.createVertexArray();
|
|
5650
5962
|
n.bindVertexArray(t);
|
|
5651
5963
|
let i = n.createBuffer();
|
|
5652
|
-
n.bindBuffer(n.ARRAY_BUFFER, i), n.bufferData(n.ARRAY_BUFFER, o *
|
|
5653
|
-
for (let [e, t, r] of
|
|
5964
|
+
n.bindBuffer(n.ARRAY_BUFFER, i), n.bufferData(n.ARRAY_BUFFER, o * _i * 4, n.DYNAMIC_DRAW);
|
|
5965
|
+
for (let [e, t, r] of gi) n.enableVertexAttribArray(e), n.vertexAttribPointer(e, t, n.FLOAT, !1, 40, r * 4), n.vertexAttribDivisor(e, 1);
|
|
5654
5966
|
n.bindBuffer(n.ARRAY_BUFFER, this.#g()), n.enableVertexAttribArray(Z.corner), n.vertexAttribPointer(Z.corner, 2, n.FLOAT, !1, 0, 0), n.bindVertexArray(null), r = {
|
|
5655
5967
|
vao: t,
|
|
5656
5968
|
buffers: [i],
|
|
@@ -5661,15 +5973,15 @@ var Jr = new Float32Array([
|
|
|
5661
5973
|
instanceVersion: 0,
|
|
5662
5974
|
capacity: o,
|
|
5663
5975
|
sorted: !1,
|
|
5664
|
-
data: new Float32Array(o *
|
|
5976
|
+
data: new Float32Array(o * _i)
|
|
5665
5977
|
}, this.#r.set(e, r);
|
|
5666
5978
|
}
|
|
5667
|
-
let s = i ?
|
|
5979
|
+
let s = i ? xi(e.positions, a, t) : null, c = e.positions, l = e.colors, u = e.sizes, d = e.opacities, f = e.angles, p = r.data;
|
|
5668
5980
|
for (let e = 0; e < a; e++) {
|
|
5669
|
-
let t = s ? s[e] : e, n = e *
|
|
5981
|
+
let t = s ? s[e] : e, n = e * _i;
|
|
5670
5982
|
p[n] = c[t * 3], p[n + 1] = c[t * 3 + 1], p[n + 2] = c[t * 3 + 2], p[n + 3] = l ? l[t * 3] : 1, p[n + 4] = l ? l[t * 3 + 1] : 1, p[n + 5] = l ? l[t * 3 + 2] : 1, p[n + 6] = u ? u[t] : 1, p[n + 7] = d ? d[t] : 1, p[n + 8] = f ? f[t] : 0, p[n + 9] = t;
|
|
5671
5983
|
}
|
|
5672
|
-
return n.bindBuffer(n.ARRAY_BUFFER, r.buffers[0]), n.bufferSubData(n.ARRAY_BUFFER, 0, p, 0, a *
|
|
5984
|
+
return n.bindBuffer(n.ARRAY_BUFFER, r.buffers[0]), n.bufferSubData(n.ARRAY_BUFFER, 0, p, 0, a * _i), Object.assign(r, {
|
|
5673
5985
|
count: a,
|
|
5674
5986
|
version: e.version,
|
|
5675
5987
|
sorted: i
|
|
@@ -5699,7 +6011,7 @@ var Jr = new Float32Array([
|
|
|
5699
6011
|
#h() {
|
|
5700
6012
|
if (this.#a) return this.#a;
|
|
5701
6013
|
let e = this.gl;
|
|
5702
|
-
return this.#a = e.createTexture(), e.activeTexture(e.TEXTURE0 +
|
|
6014
|
+
return this.#a = e.createTexture(), e.activeTexture(e.TEXTURE0 + ci), e.bindTexture(e.TEXTURE_2D, this.#a), e.texImage2D(e.TEXTURE_2D, 0, e.RGBA8, 1, 1, 0, e.RGBA, e.UNSIGNED_BYTE, new Uint8Array([
|
|
5703
6015
|
255,
|
|
5704
6016
|
255,
|
|
5705
6017
|
255,
|
|
@@ -5709,16 +6021,16 @@ var Jr = new Float32Array([
|
|
|
5709
6021
|
#g() {
|
|
5710
6022
|
if (this.#o) return this.#o;
|
|
5711
6023
|
let e = this.gl;
|
|
5712
|
-
return this.#o = e.createBuffer(), e.bindBuffer(e.ARRAY_BUFFER, this.#o), e.bufferData(e.ARRAY_BUFFER,
|
|
6024
|
+
return this.#o = e.createBuffer(), e.bindBuffer(e.ARRAY_BUFFER, this.#o), e.bufferData(e.ARRAY_BUFFER, hi, e.STATIC_DRAW), this.#o;
|
|
5713
6025
|
}
|
|
5714
6026
|
};
|
|
5715
|
-
function
|
|
6027
|
+
function yi(e) {
|
|
5716
6028
|
return He(e) ? [e.videoWidth, e.videoHeight] : "naturalWidth" in e ? [e.naturalWidth, e.naturalHeight] : [e.width, e.height];
|
|
5717
6029
|
}
|
|
5718
|
-
function
|
|
6030
|
+
function bi(e, t, n) {
|
|
5719
6031
|
let r = /* @__PURE__ */ new Map();
|
|
5720
6032
|
for (let i of e) {
|
|
5721
|
-
let e = Math.min(3, Math.max(0, Math.floor((i.x + i.width / 2) / t *
|
|
6033
|
+
let e = Math.min(3, Math.max(0, Math.floor((i.x + i.width / 2) / t * ui))), a = Math.min(3, Math.max(0, Math.floor((i.y + i.height / 2) / n * ui))) * ui + e, o = r.get(a);
|
|
5722
6034
|
o ? (o[0] = Math.min(o[0], i.x), o[1] = Math.min(o[1], i.y), o[2] = Math.max(o[2], i.x + i.width), o[3] = Math.max(o[3], i.y + i.height)) : r.set(a, [
|
|
5723
6035
|
i.x,
|
|
5724
6036
|
i.y,
|
|
@@ -5733,13 +6045,13 @@ function $r(e, t, n) {
|
|
|
5733
6045
|
height: r - t
|
|
5734
6046
|
}));
|
|
5735
6047
|
}
|
|
5736
|
-
function
|
|
6048
|
+
function xi(e, t, n) {
|
|
5737
6049
|
let r = new Float32Array(t), i = new Uint32Array(t);
|
|
5738
6050
|
for (let a = 0; a < t; a++) r[a] = n[2] * e[a * 3] + n[6] * e[a * 3 + 1] + n[10] * e[a * 3 + 2] + n[14], i[a] = a;
|
|
5739
6051
|
return i.sort((e, t) => r[e] - r[t]);
|
|
5740
6052
|
}
|
|
5741
6053
|
// src/webgl/context.js
|
|
5742
|
-
var
|
|
6054
|
+
var Si = null, Ci = class e {
|
|
5743
6055
|
canvas;
|
|
5744
6056
|
gl;
|
|
5745
6057
|
programs;
|
|
@@ -5758,8 +6070,8 @@ var ti = null, ni = class e {
|
|
|
5758
6070
|
#i;
|
|
5759
6071
|
constructor(e, { antialias: t = !0, shared: n = !1 } = {}) {
|
|
5760
6072
|
this.canvas = e, this.isShared = n;
|
|
5761
|
-
let r =
|
|
5762
|
-
r && (clearTimeout(r.timer),
|
|
6073
|
+
let r = wi.get(e);
|
|
6074
|
+
r && (clearTimeout(r.timer), wi.delete(e));
|
|
5763
6075
|
let i = e.getContext("webgl2", {
|
|
5764
6076
|
antialias: t,
|
|
5765
6077
|
alpha: !0,
|
|
@@ -5767,7 +6079,7 @@ var ti = null, ni = class e {
|
|
|
5767
6079
|
stencil: !0,
|
|
5768
6080
|
powerPreference: "high-performance"
|
|
5769
6081
|
});
|
|
5770
|
-
i || E("WebGLRenderer", "WebGL 2 is not available in this browser or on this device"), this.gl = i, this.programs = new
|
|
6082
|
+
i || E("WebGLRenderer", "WebGL 2 is not available in this browser or on this device"), this.gl = i, this.programs = new ai(this.gl), this.resources = new vi(this.gl);
|
|
5771
6083
|
let a = (e) => {
|
|
5772
6084
|
e.preventDefault(), this.lost = !0;
|
|
5773
6085
|
}, o = () => {
|
|
@@ -5779,11 +6091,11 @@ var ti = null, ni = class e {
|
|
|
5779
6091
|
}, r && i.isContextLost() && (this.lost = !0, r.lose?.restoreContext());
|
|
5780
6092
|
}
|
|
5781
6093
|
static shared() {
|
|
5782
|
-
if (!
|
|
6094
|
+
if (!Si) {
|
|
5783
6095
|
let t = typeof document < "u" ? document.createElement("canvas") : new OffscreenCanvas(1, 1);
|
|
5784
|
-
|
|
6096
|
+
Si = new e(t, { shared: !0 });
|
|
5785
6097
|
}
|
|
5786
|
-
return
|
|
6098
|
+
return Si;
|
|
5787
6099
|
}
|
|
5788
6100
|
fit(e, t) {
|
|
5789
6101
|
let n = this.canvas;
|
|
@@ -5824,12 +6136,12 @@ var ti = null, ni = class e {
|
|
|
5824
6136
|
if (this.users.delete(e), t && this.resources.release(e, t), this.users.size) return;
|
|
5825
6137
|
this.programs.dispose(), this.resources.reset(), this.passes?.reset(), this.bloom?.dispose(), this.#i();
|
|
5826
6138
|
let n = this.gl.getExtension("WEBGL_lose_context");
|
|
5827
|
-
this ===
|
|
6139
|
+
this === Si ? (n?.loseContext(), Si = null) : wi.set(this.canvas, {
|
|
5828
6140
|
lose: n,
|
|
5829
6141
|
timer: setTimeout(() => n?.loseContext())
|
|
5830
6142
|
});
|
|
5831
6143
|
}
|
|
5832
|
-
},
|
|
6144
|
+
}, wi = /* @__PURE__ */ new WeakMap(), Ti = [
|
|
5833
6145
|
"canvas",
|
|
5834
6146
|
"shared",
|
|
5835
6147
|
"antialias",
|
|
@@ -5838,40 +6150,40 @@ var ti = null, ni = class e {
|
|
|
5838
6150
|
"exposure",
|
|
5839
6151
|
"pixelRatio",
|
|
5840
6152
|
"bloom"
|
|
5841
|
-
],
|
|
6153
|
+
], Ei = {
|
|
5842
6154
|
strength: 1,
|
|
5843
6155
|
radius: .6,
|
|
5844
6156
|
threshold: .6
|
|
5845
|
-
},
|
|
6157
|
+
}, Di = Object.keys(Ei), Oi = {
|
|
5846
6158
|
intensity: "use 'strength'",
|
|
5847
6159
|
amount: "use 'strength'",
|
|
5848
6160
|
size: "use 'radius'",
|
|
5849
6161
|
blur: "use 'radius'"
|
|
5850
|
-
},
|
|
5851
|
-
function
|
|
6162
|
+
}, ki = { alpha: "the canvas is always transparent where the scene has no background" };
|
|
6163
|
+
function Ai(e, t) {
|
|
5852
6164
|
if (t == null || t === !1) return null;
|
|
5853
|
-
if (t === !0) return { ...
|
|
5854
|
-
typeof t != "object" && E(e, `bloom is true, false or { strength, radius, threshold }, got ${j(t)}`), A(`${e} bloom`, t,
|
|
5855
|
-
let n = { ...
|
|
5856
|
-
for (let r of Object.keys(
|
|
6165
|
+
if (t === !0) return { ...Ei };
|
|
6166
|
+
typeof t != "object" && E(e, `bloom is true, false or { strength, radius, threshold }, got ${j(t)}`), A(`${e} bloom`, t, Di, Oi);
|
|
6167
|
+
let n = { ...Ei };
|
|
6168
|
+
for (let r of Object.keys(Ei)) t[r] !== void 0 && (n[r] = M(`${e} bloom`, r, t[r]));
|
|
5857
6169
|
return n;
|
|
5858
6170
|
}
|
|
5859
|
-
var
|
|
6171
|
+
var ji = {
|
|
5860
6172
|
none: 0,
|
|
5861
6173
|
aces: 1,
|
|
5862
6174
|
neutral: 2
|
|
5863
|
-
},
|
|
6175
|
+
}, Mi = [], Ni = {
|
|
5864
6176
|
roughnessMap: "ROUGHNESS_MAP",
|
|
5865
6177
|
metalnessMap: "METALNESS_MAP",
|
|
5866
6178
|
normalMap: "NORMAL_MAP",
|
|
5867
6179
|
bumpMap: "BUMP_MAP",
|
|
5868
6180
|
aoMap: "AO_MAP",
|
|
5869
6181
|
lightMap: "LIGHT_MAP"
|
|
5870
|
-
},
|
|
6182
|
+
}, Pi = [
|
|
5871
6183
|
"map",
|
|
5872
6184
|
"emissiveMap",
|
|
5873
|
-
...Object.keys(
|
|
5874
|
-
],
|
|
6185
|
+
...Object.keys(Ni)
|
|
6186
|
+
], Fi = {
|
|
5875
6187
|
matcap: "uMatcap",
|
|
5876
6188
|
map: "uMap",
|
|
5877
6189
|
roughnessMap: "uRoughnessMap",
|
|
@@ -5881,7 +6193,7 @@ var ui = {
|
|
|
5881
6193
|
aoMap: "uAoMap",
|
|
5882
6194
|
emissiveMap: "uEmissiveMap",
|
|
5883
6195
|
lightMap: "uLightMap"
|
|
5884
|
-
},
|
|
6196
|
+
}, Ii = [Lr, Mr], Li = new U({
|
|
5885
6197
|
positions: [
|
|
5886
6198
|
-1,
|
|
5887
6199
|
0,
|
|
@@ -5928,14 +6240,14 @@ var ui = {
|
|
|
5928
6240
|
3,
|
|
5929
6241
|
2
|
|
5930
6242
|
]
|
|
5931
|
-
}),
|
|
6243
|
+
}), Ri = {
|
|
5932
6244
|
drawMode: "triangles",
|
|
5933
6245
|
receiveShadow: !0,
|
|
5934
6246
|
castShadow: !1,
|
|
5935
6247
|
renderOrder: 0
|
|
5936
|
-
},
|
|
5937
|
-
static OPTIONS =
|
|
5938
|
-
static HINTS =
|
|
6248
|
+
}, zi = class {
|
|
6249
|
+
static OPTIONS = Ti;
|
|
6250
|
+
static HINTS = ki;
|
|
5939
6251
|
canvas;
|
|
5940
6252
|
toneMapping = "neutral";
|
|
5941
6253
|
exposure = 1;
|
|
@@ -5963,22 +6275,22 @@ var ui = {
|
|
|
5963
6275
|
#u = !1;
|
|
5964
6276
|
#d = /* @__PURE__ */ new Map();
|
|
5965
6277
|
constructor(e) {
|
|
5966
|
-
if (A("WebGLRenderer", e,
|
|
6278
|
+
if (A("WebGLRenderer", e, Ti, ki), e?.canvas || E("WebGLRenderer", "'canvas' is required"), this.canvas = e.canvas, e.toneMapping !== void 0 && (this.toneMapping = P("WebGLRenderer", "toneMapping", e.toneMapping, [
|
|
5967
6279
|
"aces",
|
|
5968
6280
|
"neutral",
|
|
5969
6281
|
"none"
|
|
5970
|
-
])), e.exposure !== void 0 && (this.exposure = N("WebGLRenderer", "exposure", e.exposure, 0)), e.pixelRatio !== void 0 && (this.pixelRatio = N("WebGLRenderer", "pixelRatio", e.pixelRatio, 0, Infinity, { above: !0 })), this.#e =
|
|
5971
|
-
this.#t =
|
|
6282
|
+
])), e.exposure !== void 0 && (this.exposure = N("WebGLRenderer", "exposure", e.exposure, 0)), e.pixelRatio !== void 0 && (this.pixelRatio = N("WebGLRenderer", "pixelRatio", e.pixelRatio, 0, Infinity, { above: !0 })), this.#e = Ai("WebGLRenderer", e.bloom), this.outlineAntialias = e.outlineAntialias === void 0 ? e.shared || e.antialias !== !1 : !!e.outlineAntialias, e.shared) {
|
|
6283
|
+
this.#t = Ci.shared();
|
|
5972
6284
|
let e = this.canvas.getContext("2d");
|
|
5973
6285
|
e || E("WebGLRenderer", "a shared renderer's canvas needs a 2D context - give it a canvas that has no WebGL context yet"), this.#n = e;
|
|
5974
|
-
} else this.#t = new
|
|
6286
|
+
} else this.#t = new Ci(this.canvas, { antialias: e.antialias });
|
|
5975
6287
|
this.#t.users.add(this);
|
|
5976
6288
|
}
|
|
5977
6289
|
get bloom() {
|
|
5978
6290
|
return this.#e;
|
|
5979
6291
|
}
|
|
5980
6292
|
set bloom(e) {
|
|
5981
|
-
this.#e =
|
|
6293
|
+
this.#e = Ai("WebGLRenderer", e);
|
|
5982
6294
|
}
|
|
5983
6295
|
get gl() {
|
|
5984
6296
|
return this.#t.gl;
|
|
@@ -5990,7 +6302,7 @@ var ui = {
|
|
|
5990
6302
|
this.pixelRatio = n, this.canvas.width = Math.max(1, Math.round(e * n)), this.canvas.height = Math.max(1, Math.round(t * n));
|
|
5991
6303
|
}
|
|
5992
6304
|
render(e, t) {
|
|
5993
|
-
return e.updateWorldTree(), this.renderFrame(
|
|
6305
|
+
return e.updateWorldTree(), this.renderFrame(Kt(e, t));
|
|
5994
6306
|
}
|
|
5995
6307
|
renderFrame(e, { wait: t = !1 } = {}) {
|
|
5996
6308
|
let n = this.#t;
|
|
@@ -6000,7 +6312,7 @@ var ui = {
|
|
|
6000
6312
|
let i = this.canvas.width, a = this.canvas.height;
|
|
6001
6313
|
n.isShared && n.fit(i, a);
|
|
6002
6314
|
let o = e.environment, s = e.background, c = n.loadPasses(!!e.shadow || e.spotShadows.length > 0 || !!e.pointShadow || e.outlines.length > 0 || typeof o == "object" && !!o.image || !!s && !("getHex" in s) && !!s.image);
|
|
6003
|
-
this.#r = c && typeof o == "object" ? c.environment(o) : null, c && typeof o == "object" && o.image && !this.#r && F(o, o.isHDR ? "this device can't render to float textures, which HDR environments need - lighting without it" : "'environment' needs an HDR image (a .hdr file) - lighting without it"), c && s && !("getHex" in s) && s.isHDR && c.environment(s), this.#i = c ? [
|
|
6315
|
+
c && (c.time = e.time ?? 0, c.cameraPosition = e.camera.position), this.#r = c && typeof o == "object" ? c.environment(o) : null, c && typeof o == "object" && o.image && !this.#r && F(o, o.isHDR ? "this device can't render to float textures, which HDR environments need - lighting without it" : "'environment' needs an HDR image (a .hdr file) - lighting without it"), c && s && !("getHex" in s) && s.isHDR && c.environment(s), this.#i = c ? [
|
|
6004
6316
|
e.shadow && c.shadowMap(e.shadow),
|
|
6005
6317
|
e.spotShadows.length > 0 && c.spotShadowMaps(e.spotShadows),
|
|
6006
6318
|
e.pointShadow && c.pointShadowMap(e.pointShadow)
|
|
@@ -6012,7 +6324,7 @@ var ui = {
|
|
|
6012
6324
|
} else r.clearColor(0, 0, 0, 0);
|
|
6013
6325
|
r.depthMask(!0), r.enable(r.SCISSOR_TEST), r.scissor(0, 0, i, a), r.clear(r.COLOR_BUFFER_BIT | r.DEPTH_BUFFER_BIT), r.disable(r.SCISSOR_TEST), c && s && !("getHex" in s) && s.image && c.background(e, s, {
|
|
6014
6326
|
exposure: this.exposure,
|
|
6015
|
-
toneMapping:
|
|
6327
|
+
toneMapping: ji[this.toneMapping]
|
|
6016
6328
|
}), r.enable(r.DEPTH_TEST), r.depthFunc(r.LEQUAL), this.#f(e), r.disable(r.BLEND);
|
|
6017
6329
|
for (let t of e.opaque) this.#p(t, e, !1);
|
|
6018
6330
|
for (let t of e.caps) this.#m(t, e, i, a);
|
|
@@ -6094,81 +6406,87 @@ var ui = {
|
|
|
6094
6406
|
};
|
|
6095
6407
|
}
|
|
6096
6408
|
#p(e, t, n) {
|
|
6097
|
-
let r = this.gl, { node: i, geometry: a, material: c, worldMatrix: l, instances: u } = e, d = i.drawMode, f = d === "points" ? "points" : d === "lines" ? "lines" : "mesh", p = f === "mesh" && i.receiveShadow && !c.unlit ? this.#i :
|
|
6409
|
+
let r = this.gl, { node: i, geometry: a, material: c, worldMatrix: l, instances: u } = e, d = i.drawMode, f = d === "points" ? "points" : d === "lines" ? "lines" : "mesh", p = f === "mesh" && i.receiveShadow && !c.unlit ? this.#i : Mi, m = f === "mesh" ? e.clip : null, h = this.#g(f, c, a.colors !== null, !!u, a.uvs2 !== null);
|
|
6098
6410
|
f === "points" && i.drawsSprites && h.push("SPRITES");
|
|
6099
6411
|
for (let e of p) h.push(e.define);
|
|
6100
6412
|
let g = c.fog ? t.fog : null;
|
|
6101
6413
|
g && (h.push("FOG"), g.linear && h.push("FOG_LINEAR"), c.blending === "additive" ? h.push("FOG_ADD") : c.blending === "multiply" && h.push("FOG_MULTIPLY")), m && h.push("CLIP");
|
|
6102
|
-
let _ =
|
|
6103
|
-
|
|
6414
|
+
let _ = ei(c);
|
|
6415
|
+
_ && h.push(..._.defines);
|
|
6416
|
+
let v = this.#t.programs, y = v.get(f, h, void 0, _?.source);
|
|
6417
|
+
if (!v.isReady(y)) {
|
|
6104
6418
|
if (!this.#c) {
|
|
6105
6419
|
this.info.compiling++;
|
|
6106
6420
|
return;
|
|
6107
6421
|
}
|
|
6108
|
-
|
|
6422
|
+
v.ready(f, h, void 0, _?.source);
|
|
6109
6423
|
}
|
|
6110
|
-
if (
|
|
6111
|
-
|
|
6424
|
+
if (y.failed) {
|
|
6425
|
+
ri(c, _, y.failed), this.info.compiling++;
|
|
6426
|
+
return;
|
|
6427
|
+
}
|
|
6428
|
+
if (r.useProgram(y.program), y.frame !== this.#t.frame && (y.frame = this.#t.frame, y.set("uView", t.camera.view), y.set("uProjection", t.camera.projection), y.set("uViewProjection", t.camera.viewProjection), y.set("uCameraPosition", t.camera.position), y.set("uExposure", this.exposure), y.set("uToneMapping", ji[this.toneMapping]), y.set("uResolution", [this.canvas.width, this.canvas.height]), y.set("uNear", t.camera.near), y.set("uScale", t.camera.projection[5] * this.canvas.height / 2), f === "mesh" && !c.unlit)) {
|
|
6429
|
+
for (let [e, t] of Object.entries(this.#s)) y.set(e, t);
|
|
6112
6430
|
let e = this.#r;
|
|
6113
|
-
e && (
|
|
6114
|
-
for (let e of p) for (let [t, n] of Object.entries(e.uniforms))
|
|
6431
|
+
e && (y.set("uEnvMaxLod", e.maxLod), y.set("uEnvSH", e.sh), y.set("uEnvIntensity", t.environmentIntensity));
|
|
6432
|
+
for (let e of p) for (let [t, n] of Object.entries(e.uniforms)) y.set(t, n);
|
|
6115
6433
|
}
|
|
6116
6434
|
if (f === "mesh" && !c.unlit) {
|
|
6117
|
-
this.#r &&
|
|
6118
|
-
for (let e of p)
|
|
6119
|
-
}
|
|
6120
|
-
|
|
6121
|
-
let
|
|
6122
|
-
|
|
6123
|
-
|
|
6124
|
-
|
|
6125
|
-
|
|
6126
|
-
|
|
6127
|
-
])) :
|
|
6128
|
-
let
|
|
6129
|
-
|
|
6130
|
-
|
|
6131
|
-
|
|
6132
|
-
|
|
6133
|
-
]),
|
|
6134
|
-
let
|
|
6135
|
-
if (
|
|
6136
|
-
Math.min(
|
|
6137
|
-
Math.min(
|
|
6138
|
-
Math.min(
|
|
6139
|
-
|
|
6435
|
+
this.#r && y.set("uEnvMap", this.#r.prefiltered);
|
|
6436
|
+
for (let e of p) y.set(e.sampler, e.texture);
|
|
6437
|
+
}
|
|
6438
|
+
y.set("uModel", l);
|
|
6439
|
+
let b = t.highlight;
|
|
6440
|
+
b && (b.nodes ? b.nodes.has(i) : b.node === i) ? (y.set("uHighlightIndex", b.index ?? -1), y.set("uHighlight", [
|
|
6441
|
+
b.color[0],
|
|
6442
|
+
b.color[1],
|
|
6443
|
+
b.color[2],
|
|
6444
|
+
b.amount
|
|
6445
|
+
])) : y.set("uHighlightIndex", -2), y.set("uColor", c.color), y.set("uOpacity", c.opacity), _ && ni(y, c, t.time ?? 0, t.camera.position, (e) => this.#t.resources.texture(e)), g && (y.set("uFogColor", g.color), y.set("uFogRange", [g.near, g.far]), y.set("uFogDensity", g.density)), m && y.set("uClipPlane", m.plane);
|
|
6446
|
+
let x = c.emissive, S = c.emissiveIntensity;
|
|
6447
|
+
y.set("uEmissive", [
|
|
6448
|
+
x[0] * S,
|
|
6449
|
+
x[1] * S,
|
|
6450
|
+
x[2] * S
|
|
6451
|
+
]), y.set("uRoughness", c.roughness), y.set("uMetalness", c.metalness), y.set("uNormalScale", c.normalScale), c.bumpMap && y.set("uBumpScale", c.bumpScale), c.triplanar > 0 && y.set("uTriplanar", c.triplanar), y.set("uAoMapIntensity", c.aoMapIntensity), c.transmission > 0 && y.set("uTransmission", c.transmission), c.clearcoat > 0 && (y.set("uClearcoat", c.clearcoat), y.set("uClearcoatRoughness", c.clearcoatRoughness));
|
|
6452
|
+
let C = (c.ior - 1) / (c.ior + 1), w = c.specularColor, T = c.specularIntensity;
|
|
6453
|
+
if (y.set("uSpecular", [
|
|
6454
|
+
Math.min(C * C * w[0], 1) * T,
|
|
6455
|
+
Math.min(C * C * w[1], 1) * T,
|
|
6456
|
+
Math.min(C * C * w[2], 1) * T,
|
|
6457
|
+
T
|
|
6140
6458
|
]), c.sheen > 0) {
|
|
6141
6459
|
let e = c.sheenColor, t = c.sheen;
|
|
6142
|
-
|
|
6460
|
+
y.set("uSheenColor", [
|
|
6143
6461
|
e[0] * t,
|
|
6144
6462
|
e[1] * t,
|
|
6145
6463
|
e[2] * t
|
|
6146
|
-
]),
|
|
6464
|
+
]), y.set("uSheenRoughness", c.sheenRoughness);
|
|
6147
6465
|
}
|
|
6148
|
-
if (c.anisotropy > 0 && (
|
|
6466
|
+
if (c.anisotropy > 0 && (y.set("uAnisotropy", c.anisotropy), y.set("uAnisotropyDirection", [Math.cos(c.anisotropyRotation), Math.sin(c.anisotropyRotation)])), c.translucency > 0) {
|
|
6149
6467
|
let e = c.translucencyColor, t = c.translucency;
|
|
6150
|
-
|
|
6468
|
+
y.set("uTranslucency", [
|
|
6151
6469
|
e[0] * t,
|
|
6152
6470
|
e[1] * t,
|
|
6153
6471
|
e[2] * t,
|
|
6154
6472
|
t
|
|
6155
6473
|
]);
|
|
6156
6474
|
}
|
|
6157
|
-
c.toon > 0 &&
|
|
6158
|
-
let
|
|
6159
|
-
for (let [e, t] of
|
|
6160
|
-
for (let [e, t] of
|
|
6161
|
-
if (c.lightMap &&
|
|
6162
|
-
r.disable(r.CULL_FACE),
|
|
6475
|
+
c.toon > 0 && y.set("uToon", Math.max(2, Math.round(c.toon))), y.set("uAlphaTest", c.alphaTest);
|
|
6476
|
+
let E = f === "mesh" ? c.textures : c.map ? [["map", c.map]] : [], D = E.map(([e, t]) => [Fi[e], this.#t.resources.texture(t)]);
|
|
6477
|
+
for (let [e, t] of D) y.set(e, t);
|
|
6478
|
+
for (let [e, t] of E) e !== "matcap" && y.set(`${Fi[e]}Uv`, mi(t));
|
|
6479
|
+
if (c.lightMap && y.set("uLightMapIntensity", c.lightMapIntensity), y.set("uEnvStrength", c.environmentIntensity), r.depthMask(!n && c.depthWrite), c.depthTest ? r.enable(r.DEPTH_TEST) : r.disable(r.DEPTH_TEST), n && (c.blending === "additive" ? r.blendFunc(r.ONE, r.ONE) : c.blending === "multiply" ? r.blendFunc(r.DST_COLOR, r.ONE_MINUS_SRC_ALPHA) : r.blendFunc(r.ONE, r.ONE_MINUS_SRC_ALPHA)), f === "lines") {
|
|
6480
|
+
r.disable(r.CULL_FACE), y.set("uWidth", c.width * this.pixelRatio);
|
|
6163
6481
|
let e = i.arrowBits ?? 0;
|
|
6164
|
-
|
|
6482
|
+
y.set("uArrows", e), y.set("uArrowSize", i.arrowPixels?.(c.width) * this.pixelRatio || 0), c.dash > 0 && (y.set("uDash", c.dash), y.set("uGap", c.gap || c.dash), y.set("uDashOffset", c.dashOffset));
|
|
6165
6483
|
let t = this.#t.resources.lines(a);
|
|
6166
6484
|
r.bindVertexArray(t.vao), r.drawArraysInstanced(r.TRIANGLES, 0, e ? 12 : 6, Math.min(t.count, Math.floor(a.drawnCount / 2))), this.info.drawCalls++;
|
|
6167
6485
|
} else if (f === "points") {
|
|
6168
|
-
r.disable(r.CULL_FACE),
|
|
6486
|
+
r.disable(r.CULL_FACE), y.set("uSize", c.sizeAttenuation ? c.size : c.size * this.pixelRatio);
|
|
6169
6487
|
let e = !n && !c.map;
|
|
6170
6488
|
if (e && (r.enable(r.BLEND), r.blendFunc(r.ONE, r.ONE_MINUS_SRC_ALPHA)), i.drawsSprites) {
|
|
6171
|
-
|
|
6489
|
+
y.set("uResolution", [this.canvas.width, this.canvas.height]);
|
|
6172
6490
|
let e = i.sort ? s(this.#o, t.camera.view, l) : null, n = this.#t.resources.sprites(a, e);
|
|
6173
6491
|
r.bindVertexArray(n.vao), r.drawArraysInstanced(r.TRIANGLE_STRIP, 0, 4, n.count);
|
|
6174
6492
|
} else {
|
|
@@ -6176,16 +6494,16 @@ var ui = {
|
|
|
6176
6494
|
r.bindVertexArray(e.vao), r.drawArrays(r.POINTS, 0, a.drawnVertices);
|
|
6177
6495
|
}
|
|
6178
6496
|
e && r.disable(r.BLEND), this.info.drawCalls++;
|
|
6179
|
-
} else
|
|
6497
|
+
} else dt(this.#a, l) || ut(this.#a), y.set("uNormalMatrix", this.#a), r.frontFace(o(l) < 0 ? r.CW : r.CCW), c.doubleSided ? r.disable(r.CULL_FACE) : (r.enable(r.CULL_FACE), r.cullFace(r.BACK)), r.enable(r.POLYGON_OFFSET_FILL), r.polygonOffset(1, 2), this.info.triangles += this.#t.resources.drawTriangles(a, u, c.anisotropy > 0 && !c.unlit), r.disable(r.POLYGON_OFFSET_FILL), this.info.drawCalls++;
|
|
6180
6498
|
}
|
|
6181
6499
|
#m(e, t, n, r) {
|
|
6182
|
-
let i = this.gl, a = this.#t.programs, s = [!1, !0].map((e) => a.get("clip-mask", e ? ["INSTANCED", "CLIP"] : ["CLIP"],
|
|
6500
|
+
let i = this.gl, a = this.#t.programs, s = [!1, !0].map((e) => a.get("clip-mask", e ? ["INSTANCED", "CLIP"] : ["CLIP"], Ii));
|
|
6183
6501
|
if (!s.every((e) => a.isReady(e))) {
|
|
6184
6502
|
if (!this.#c) {
|
|
6185
6503
|
this.info.compiling++;
|
|
6186
6504
|
return;
|
|
6187
6505
|
}
|
|
6188
|
-
for (let e of [!1, !0]) a.ready("clip-mask", e ? ["INSTANCED", "CLIP"] : ["CLIP"],
|
|
6506
|
+
for (let e of [!1, !0]) a.ready("clip-mask", e ? ["INSTANCED", "CLIP"] : ["CLIP"], Ii);
|
|
6189
6507
|
}
|
|
6190
6508
|
i.enable(i.STENCIL_TEST), i.enable(i.SCISSOR_TEST), i.scissor(0, 0, n, r), i.clearStencil(0), i.clear(i.STENCIL_BUFFER_BIT), i.disable(i.SCISSOR_TEST), i.colorMask(!1, !1, !1, !1), i.depthMask(!1), i.disable(i.DEPTH_TEST), i.disable(i.CULL_FACE), i.stencilFunc(i.ALWAYS, 0, 255), i.stencilOpSeparate(i.BACK, i.KEEP, i.KEEP, i.INCR_WRAP), i.stencilOpSeparate(i.FRONT, i.KEEP, i.KEEP, i.DECR_WRAP);
|
|
6191
6509
|
for (let n of e.items) {
|
|
@@ -6196,7 +6514,7 @@ var ui = {
|
|
|
6196
6514
|
}
|
|
6197
6515
|
#h(e) {
|
|
6198
6516
|
let t = e.color.getHex(), n = this.#d.get(t);
|
|
6199
|
-
n || this.#d.set(t, n = new
|
|
6517
|
+
n || this.#d.set(t, n = new rt({
|
|
6200
6518
|
color: e.color.getStyle(),
|
|
6201
6519
|
roughness: .6
|
|
6202
6520
|
}));
|
|
@@ -6229,8 +6547,8 @@ var ui = {
|
|
|
6229
6547
|
1
|
|
6230
6548
|
]);
|
|
6231
6549
|
return {
|
|
6232
|
-
node:
|
|
6233
|
-
geometry:
|
|
6550
|
+
node: Ri,
|
|
6551
|
+
geometry: Li,
|
|
6234
6552
|
material: n,
|
|
6235
6553
|
worldMatrix: g,
|
|
6236
6554
|
instances: null,
|
|
@@ -6243,16 +6561,16 @@ var ui = {
|
|
|
6243
6561
|
if (t.vertexColors && n && a.push("VERTEX_COLORS"), e === "mesh") {
|
|
6244
6562
|
if (!t.unlit) {
|
|
6245
6563
|
a.push("LIT");
|
|
6246
|
-
for (let [e, n] of Object.entries(
|
|
6564
|
+
for (let [e, n] of Object.entries(Ni)) t[e] && a.push(n);
|
|
6247
6565
|
a.push(...this.#l), this.#r ? a.push("ENV_MAP") : this.#u && a.push("STUDIO"), t.transmission > 0 && a.push("TRANSMISSION"), t.clearcoat > 0 && a.push("CLEARCOAT"), t.sheen > 0 && a.push("SHEEN"), t.anisotropy > 0 && a.push("ANISOTROPY"), t.translucency > 0 && a.push("TRANSLUCENCY"), t.matcap && a.push("MATCAP"), t.toon > 0 && a.push("TOON");
|
|
6248
6566
|
}
|
|
6249
|
-
t.map && a.push("MAP"), t.emissiveMap && a.push("EMISSIVE_MAP"), t.alphaTest > 0 && a.push("ALPHA_TEST"), t.flatShading && a.push("FLAT_SHADING"), t.doubleSided && a.push("DOUBLE_SIDED"), t.triplanar > 0 &&
|
|
6567
|
+
t.map && a.push("MAP"), t.emissiveMap && a.push("EMISSIVE_MAP"), t.alphaTest > 0 && a.push("ALPHA_TEST"), t.flatShading && a.push("FLAT_SHADING"), t.doubleSided && a.push("DOUBLE_SIDED"), t.triplanar > 0 && Pi.some((e) => t[e]) && a.push("TRIPLANAR");
|
|
6250
6568
|
let e = i ? t.textures.filter(([e, t]) => t.uvSet === 1 && e !== "matcap") : [];
|
|
6251
|
-
e.length && a.push("UV2", ...e.map(([e]) => `${
|
|
6569
|
+
e.length && a.push("UV2", ...e.map(([e]) => `${Fi[e]}Set vUv2`)), r && a.push("INSTANCED");
|
|
6252
6570
|
} else e === "points" ? (t.map && a.push("MAP"), t.sizeAttenuation && a.push("SIZE_ATTENUATION")) : t.dash > 0 && a.push("DASHED");
|
|
6253
6571
|
return a;
|
|
6254
6572
|
}
|
|
6255
|
-
},
|
|
6573
|
+
}, Bi = [
|
|
6256
6574
|
"canvas",
|
|
6257
6575
|
"scene",
|
|
6258
6576
|
"camera",
|
|
@@ -6273,8 +6591,22 @@ var ui = {
|
|
|
6273
6591
|
"maxDelta",
|
|
6274
6592
|
"reducedMotion",
|
|
6275
6593
|
"keyboard",
|
|
6276
|
-
"description"
|
|
6277
|
-
|
|
6594
|
+
"description",
|
|
6595
|
+
"debug"
|
|
6596
|
+
], Vi = {
|
|
6597
|
+
lights: !0,
|
|
6598
|
+
shadows: !0,
|
|
6599
|
+
bounds: !0,
|
|
6600
|
+
normals: !1,
|
|
6601
|
+
axes: !0,
|
|
6602
|
+
camera: !0,
|
|
6603
|
+
stats: "top-left"
|
|
6604
|
+
}, Hi = Object.keys(Vi), Ui = [
|
|
6605
|
+
"top-left",
|
|
6606
|
+
"top-right",
|
|
6607
|
+
"bottom-left",
|
|
6608
|
+
"bottom-right"
|
|
6609
|
+
], Wi = ["keep", "aspect"], Gi = {
|
|
6278
6610
|
renderer: "the View makes its renderer - read it from view.renderer",
|
|
6279
6611
|
controls: "use orbit: true (or orbit options); the control is then view.controls",
|
|
6280
6612
|
container: "use canvas: an element or selector (a full-window canvas is made when omitted)",
|
|
@@ -6284,7 +6616,7 @@ var ui = {
|
|
|
6284
6616
|
keep: "use framing: { keep: 'width' | 'height' | 'both' }",
|
|
6285
6617
|
fit: "use framing: { keep: 'both' } to keep everything framed in view as the canvas changes shape",
|
|
6286
6618
|
aspect: "the canvas sets the aspect; framing: { aspect } says which shape the camera was set up for"
|
|
6287
|
-
},
|
|
6619
|
+
}, Ki = {
|
|
6288
6620
|
mouseover: "hover",
|
|
6289
6621
|
mouseenter: "hover",
|
|
6290
6622
|
mousemove: "hover",
|
|
@@ -6298,10 +6630,10 @@ var ui = {
|
|
|
6298
6630
|
select: "click",
|
|
6299
6631
|
pointerdown: "click",
|
|
6300
6632
|
mousedown: "click"
|
|
6301
|
-
},
|
|
6302
|
-
static OPTIONS =
|
|
6303
|
-
static HINTS =
|
|
6304
|
-
static FRAMING_OPTIONS =
|
|
6633
|
+
}, qi = .45, Ji = H.fromInput("#ffcc00"), Yi = 4, Xi = 5e3, Zi = 0, Qi = class {
|
|
6634
|
+
static OPTIONS = Bi;
|
|
6635
|
+
static HINTS = Gi;
|
|
6636
|
+
static FRAMING_OPTIONS = Wi;
|
|
6305
6637
|
canvas;
|
|
6306
6638
|
scene;
|
|
6307
6639
|
#e;
|
|
@@ -6330,7 +6662,7 @@ var ui = {
|
|
|
6330
6662
|
#g = "height";
|
|
6331
6663
|
#_ = 0;
|
|
6332
6664
|
#v = 1;
|
|
6333
|
-
#y = new
|
|
6665
|
+
#y = new fr();
|
|
6334
6666
|
#b = [];
|
|
6335
6667
|
#x;
|
|
6336
6668
|
#S = null;
|
|
@@ -6347,24 +6679,29 @@ var ui = {
|
|
|
6347
6679
|
#A = null;
|
|
6348
6680
|
#j = null;
|
|
6349
6681
|
#M = null;
|
|
6350
|
-
#N =
|
|
6351
|
-
#P =
|
|
6352
|
-
#F =
|
|
6353
|
-
#I =
|
|
6354
|
-
#L =
|
|
6682
|
+
#N = null;
|
|
6683
|
+
#P = null;
|
|
6684
|
+
#F = !1;
|
|
6685
|
+
#I = 0;
|
|
6686
|
+
#L = 0;
|
|
6355
6687
|
#R = !1;
|
|
6356
|
-
#z =
|
|
6688
|
+
#z = !1;
|
|
6357
6689
|
#B = null;
|
|
6358
|
-
#V =
|
|
6359
|
-
#H =
|
|
6360
|
-
#U =
|
|
6690
|
+
#V = !1;
|
|
6691
|
+
#H = !1;
|
|
6692
|
+
#U = !1;
|
|
6361
6693
|
#W = null;
|
|
6362
|
-
#G =
|
|
6694
|
+
#G = null;
|
|
6695
|
+
#K = null;
|
|
6696
|
+
#q = null;
|
|
6697
|
+
#J = null;
|
|
6698
|
+
#Y = null;
|
|
6699
|
+
#X = new Sr({
|
|
6363
6700
|
sky: "#ffffff",
|
|
6364
6701
|
ground: "#444444",
|
|
6365
6702
|
intensity: .5
|
|
6366
6703
|
});
|
|
6367
|
-
#
|
|
6704
|
+
#Z = new wr({
|
|
6368
6705
|
direction: [
|
|
6369
6706
|
-.5,
|
|
6370
6707
|
-1,
|
|
@@ -6372,9 +6709,9 @@ var ui = {
|
|
|
6372
6709
|
],
|
|
6373
6710
|
intensity: 1.5
|
|
6374
6711
|
});
|
|
6375
|
-
#
|
|
6712
|
+
#Q = !1;
|
|
6376
6713
|
constructor(e = {}) {
|
|
6377
|
-
A("View", e,
|
|
6714
|
+
A("View", e, Bi, Gi), this.canvas = da(e.canvas), this.#a = e.canvas === void 0, e.scene === void 0 ? this.scene = new gr() : e.scene instanceof gr ? this.scene = e.scene : E("View", `'scene' must be a Scene${e.scene && typeof e.scene == "object" && "type" in e.scene ? " - build one from a description with create({ type: 'scene', ... })" : `, got ${j(e.scene)}`}`), e.background !== void 0 && (this.scene.background = e.background), e.camera instanceof An ? this.#e = e.camera : typeof e.camera == "string" ? (this.#e = In(e.camera), this.#m = !0) : e.camera === void 0 ? (this.#e = In("perspective"), this.#m = !0) : this.#e = new jn({
|
|
6378
6715
|
position: [
|
|
6379
6716
|
0,
|
|
6380
6717
|
1.5,
|
|
@@ -6386,15 +6723,15 @@ var ui = {
|
|
|
6386
6723
|
0
|
|
6387
6724
|
],
|
|
6388
6725
|
...e.camera
|
|
6389
|
-
}), this.#m && (this.#h =
|
|
6726
|
+
}), this.#m && (this.#h = $i(this.#e));
|
|
6390
6727
|
let t = e.context === void 0 ? "auto" : P("View", "context", e.context, [
|
|
6391
6728
|
"auto",
|
|
6392
6729
|
"own",
|
|
6393
6730
|
"shared"
|
|
6394
6731
|
]);
|
|
6395
6732
|
e.exposure !== void 0 && N("View", "exposure", e.exposure, 0);
|
|
6396
|
-
let n = t === "shared" || t === "auto" &&
|
|
6397
|
-
if (this.renderer = new
|
|
6733
|
+
let n = t === "shared" || t === "auto" && Zi >= Yi;
|
|
6734
|
+
if (this.renderer = new zi({
|
|
6398
6735
|
canvas: this.canvas,
|
|
6399
6736
|
shared: n,
|
|
6400
6737
|
antialias: e.antialias,
|
|
@@ -6402,31 +6739,31 @@ var ui = {
|
|
|
6402
6739
|
toneMapping: e.toneMapping,
|
|
6403
6740
|
exposure: e.exposure,
|
|
6404
6741
|
bloom: e.bloom
|
|
6405
|
-
}), n || (this.#i = !0,
|
|
6406
|
-
this.#
|
|
6407
|
-
}, e.autoLight !== void 0 && (this.autoLight = !!e.autoLight), e.reducedMotion !== void 0 && this.#
|
|
6742
|
+
}), n || (this.#i = !0, Zi++), this.renderer.onReady = () => {
|
|
6743
|
+
this.#V = !0, this.invalidate();
|
|
6744
|
+
}, e.autoLight !== void 0 && (this.autoLight = !!e.autoLight), e.reducedMotion !== void 0 && this.#ee(e.reducedMotion), e.maxDelta !== void 0 && (this.maxDelta = N("View", "maxDelta", e.maxDelta, 0, Infinity, { above: !0 })), e.renderMode !== void 0 && (this.renderMode = P("View", "renderMode", e.renderMode, [
|
|
6408
6745
|
"auto",
|
|
6409
6746
|
"always",
|
|
6410
6747
|
"manual"
|
|
6411
6748
|
])), e.pixelRatio !== void 0 && (this.#f = N("View", "pixelRatio", e.pixelRatio, 0, Infinity, { above: !0 }), this.#p = !0), e.orbit !== void 0 && e.orbit !== !1 && e.orbit !== !0 && (typeof e.orbit != "object" || Array.isArray(e.orbit) || e.orbit === null) && E("View", `'orbit' must be true, false or orbit options such as { autoRotate: true }, got ${j(e.orbit)}`), e.orbit) {
|
|
6412
6749
|
let t = e.orbit === !0 ? {} : e.orbit, n = t.mode ?? (e.camera === "top" ? "map" : void 0);
|
|
6413
|
-
this.controls = new
|
|
6750
|
+
this.controls = new Cn(this.camera, this.canvas, n ? {
|
|
6414
6751
|
...t,
|
|
6415
6752
|
mode: n
|
|
6416
|
-
} : t), this.#
|
|
6753
|
+
} : t), this.#G = this.controls.handOverPointer();
|
|
6417
6754
|
}
|
|
6418
|
-
if (e.highlight !== void 0 && this
|
|
6419
|
-
interactive: (e) =>
|
|
6420
|
-
on: (e, t, n) => this.#
|
|
6421
|
-
}), e.framing !== void 0) {
|
|
6755
|
+
if (e.highlight !== void 0 && this.#$(e.highlight), e.tooltip !== void 0 && this.tooltip(e.tooltip), e.description !== void 0 && (this.description = e.description), e.keyboard !== void 0 && e.keyboard !== !1 && this.#ue(e.keyboard), this.#x = new _n(this.canvas, {
|
|
6756
|
+
interactive: (e) => la(e, "click").length > 0 || la(e, "hover").length > 0,
|
|
6757
|
+
on: (e, t, n) => this.#be(e, t, n)
|
|
6758
|
+
}), e.debug !== void 0 && (this.debug = e.debug), e.framing !== void 0) {
|
|
6422
6759
|
let t = typeof e.framing == "string" ? { keep: e.framing } : e.framing;
|
|
6423
|
-
A("View", t,
|
|
6760
|
+
A("View", t, Wi, {}, "framing"), t.keep !== void 0 && (this.#g = P("View", "framing.keep", t.keep, [
|
|
6424
6761
|
"height",
|
|
6425
6762
|
"width",
|
|
6426
6763
|
"both"
|
|
6427
6764
|
])), t.aspect !== void 0 && (t.aspect > 0 || E("View", `framing.aspect is a width / height above 0, got ${j(t.aspect)}`), this.#_ = t.aspect);
|
|
6428
6765
|
}
|
|
6429
|
-
this.resize(), this.#
|
|
6766
|
+
this.resize(), this.#we(), this.#me();
|
|
6430
6767
|
}
|
|
6431
6768
|
get camera() {
|
|
6432
6769
|
return this.#e;
|
|
@@ -6434,12 +6771,12 @@ var ui = {
|
|
|
6434
6771
|
set camera(e) {
|
|
6435
6772
|
if (typeof e == "string") {
|
|
6436
6773
|
let t = this.#e, n = t.target ?? new z();
|
|
6437
|
-
e =
|
|
6774
|
+
e = In(e, {
|
|
6438
6775
|
target: n,
|
|
6439
6776
|
distance: Math.max(.001, t.position.distanceTo(n))
|
|
6440
6777
|
}), this.#m = !0;
|
|
6441
6778
|
} else this.#m = !1;
|
|
6442
|
-
e instanceof
|
|
6779
|
+
e instanceof An || E("View", `'camera' must be a camera or a preset name, got ${j(e)}`), this.#J = null, this.#e = e, this.#d && (e.aspect = this.#u / this.#d), this.#_ = e.aspect, this.#v = 1, this.controls && (e.target ??= this.controls.target.clone(), this.controls.camera = e), this.#m && (this.#h = $i(e)), this.invalidate();
|
|
6443
6780
|
}
|
|
6444
6781
|
get bloom() {
|
|
6445
6782
|
return this.renderer.bloom;
|
|
@@ -6451,20 +6788,28 @@ var ui = {
|
|
|
6451
6788
|
return this.#O;
|
|
6452
6789
|
}
|
|
6453
6790
|
set highlight(e) {
|
|
6454
|
-
this
|
|
6791
|
+
this.#$(e);
|
|
6455
6792
|
}
|
|
6456
|
-
|
|
6457
|
-
this.#O = e == null ? null : H.fromInput(e, "View"), this.#
|
|
6793
|
+
#$(e) {
|
|
6794
|
+
this.#O = e == null ? null : H.fromInput(e, "View"), this.#V = !0, this.invalidate();
|
|
6458
6795
|
}
|
|
6459
6796
|
get reducedMotion() {
|
|
6460
|
-
return this.#k === "auto" ? this.#
|
|
6797
|
+
return this.#k === "auto" ? this.#z : this.#k;
|
|
6461
6798
|
}
|
|
6462
6799
|
set reducedMotion(e) {
|
|
6463
|
-
this.#
|
|
6800
|
+
this.#ee(e);
|
|
6464
6801
|
}
|
|
6465
|
-
#
|
|
6802
|
+
#ee(e) {
|
|
6466
6803
|
e !== "auto" && typeof e != "boolean" && E("View", `'reducedMotion' is 'auto' (as the system's setting), true or false, got ${j(e)}`), this.#k = e, this.invalidate();
|
|
6467
6804
|
}
|
|
6805
|
+
get debug() {
|
|
6806
|
+
return this.#N ?? !1;
|
|
6807
|
+
}
|
|
6808
|
+
set debug(e) {
|
|
6809
|
+
this.#N = fa(e), this.#N && !this.#P && !this.#F && (this.#F = !0, import("./debug.js").then(({ DebugDraw: e }) => {
|
|
6810
|
+
this.#F = !1, !this.#r && (this.#P = new e(this.#x.root), this.invalidate());
|
|
6811
|
+
})), this.#N && (this.#N.bounds === "hovered" || this.#N.normals === "hovered") && (this.#V = !0), this.#N || this.#P?.stats(!1, {}, 0, 0), this.invalidate();
|
|
6812
|
+
}
|
|
6468
6813
|
get description() {
|
|
6469
6814
|
return this.#M;
|
|
6470
6815
|
}
|
|
@@ -6474,7 +6819,7 @@ var ui = {
|
|
|
6474
6819
|
return;
|
|
6475
6820
|
}
|
|
6476
6821
|
let t = this.canvas;
|
|
6477
|
-
e === null ? (t.removeAttribute("aria-label"), this.#
|
|
6822
|
+
e === null ? (t.removeAttribute("aria-label"), this.#R && t.removeAttribute("role"), this.#R = !1) : (t.setAttribute("aria-label", e), t.hasAttribute("role") || (t.setAttribute("role", "img"), this.#R = !0));
|
|
6478
6823
|
}
|
|
6479
6824
|
get width() {
|
|
6480
6825
|
return this.#u;
|
|
@@ -6486,13 +6831,13 @@ var ui = {
|
|
|
6486
6831
|
return this.scene.ready;
|
|
6487
6832
|
}
|
|
6488
6833
|
get hovered() {
|
|
6489
|
-
return this.#
|
|
6834
|
+
return this.#q;
|
|
6490
6835
|
}
|
|
6491
6836
|
get overlay() {
|
|
6492
6837
|
return this.#x.root;
|
|
6493
6838
|
}
|
|
6494
6839
|
start(e) {
|
|
6495
|
-
return e && (this.#t = e), this.#n || (this.#n = !0, this.#s = 0), this.#
|
|
6840
|
+
return e && (this.#t = e), this.#n || (this.#n = !0, this.#s = 0), this.#me(), this;
|
|
6496
6841
|
}
|
|
6497
6842
|
stop() {
|
|
6498
6843
|
return this.#n = !1, this;
|
|
@@ -6501,29 +6846,39 @@ var ui = {
|
|
|
6501
6846
|
return this.#n;
|
|
6502
6847
|
}
|
|
6503
6848
|
invalidate() {
|
|
6504
|
-
return this.#c = !0, this.#
|
|
6849
|
+
return this.#c = !0, this.#me(), this;
|
|
6505
6850
|
}
|
|
6506
6851
|
step(e) {
|
|
6507
|
-
return this.time += e, this.#t?.(e, this.time), this.scene.motionReduced = this.reducedMotion, this.scene.update(e, this.time), this.#
|
|
6852
|
+
return this.time += e, this.#t?.(e, this.time), this.scene.motionReduced = this.reducedMotion, this.scene.update(e, this.time), this.#te(e), this.#ne(!0);
|
|
6508
6853
|
}
|
|
6509
|
-
#
|
|
6510
|
-
if (this.#
|
|
6854
|
+
#te(e) {
|
|
6855
|
+
if (this.#J) return this.#ie(e);
|
|
6511
6856
|
if (!this.controls) return;
|
|
6512
|
-
let t = this.#m &&
|
|
6513
|
-
this.controls.update(e, this.reducedMotion), t && (this.#h =
|
|
6857
|
+
let t = this.#m && ea($i(this.camera), this.#h);
|
|
6858
|
+
this.controls.update(e, this.reducedMotion), t && (this.#h = $i(this.camera));
|
|
6514
6859
|
}
|
|
6515
6860
|
render() {
|
|
6516
|
-
return this.#
|
|
6861
|
+
return this.#ne(!1);
|
|
6517
6862
|
}
|
|
6518
|
-
#
|
|
6863
|
+
#ne(e) {
|
|
6519
6864
|
if (this.#m) {
|
|
6520
6865
|
this.resize();
|
|
6521
6866
|
let e = this.scene.bounds;
|
|
6522
|
-
|
|
6867
|
+
ea($i(this.camera), this.#h) ? e.isEmpty() || this.frame(this.scene) : this.#m = !1;
|
|
6523
6868
|
}
|
|
6524
6869
|
this.scene.updateWorldTree();
|
|
6525
|
-
let t =
|
|
6526
|
-
|
|
6870
|
+
let t = Kt(this.scene, this.camera);
|
|
6871
|
+
this.autoLight && t.lights.length === 0 && this.#De(t), t.time = this.time, t.highlight = this.#Se(this.#q), this.#Ce(t);
|
|
6872
|
+
let n = this.#N && this.#P ? this.#P.add(t, this.#N, {
|
|
6873
|
+
camera: this.camera,
|
|
6874
|
+
hovered: this.#q,
|
|
6875
|
+
bounds: this.scene.boundsFrom(this.camera)
|
|
6876
|
+
}) : null, r = performance.now();
|
|
6877
|
+
if (this.renderer.renderFrame(t, { wait: e }), n && (t.opaque.length -= n.opaque, t.transparent.length -= n.transparent), this.#P) {
|
|
6878
|
+
let e = performance.now(), t = this.#I ? e - this.#I : 0;
|
|
6879
|
+
this.#L = t > 0 && t < 250 ? this.#L * .9 + t * .1 : 0, this.#I = e, this.#P.stats(this.#N?.stats ?? !1, this.renderer.info, this.#L, e - r);
|
|
6880
|
+
}
|
|
6881
|
+
return this.#S = this.#x.update(t.labels, t.overlays), t.tooltips && !this.#w && this.#le(), this.lastFrame = t, this.#c = !1, this.renderMode === "auto" && this.#y.changed(this.scene, this.camera, this.time), (this.#B || this.#j) && this.#ge() && (this.#V = !0), t;
|
|
6527
6882
|
}
|
|
6528
6883
|
resize() {
|
|
6529
6884
|
let e = this.canvas.clientWidth, t = this.canvas.clientHeight;
|
|
@@ -6534,23 +6889,23 @@ var ui = {
|
|
|
6534
6889
|
}
|
|
6535
6890
|
let n = e || this.canvas.width || 1, r = t || this.canvas.height || 1;
|
|
6536
6891
|
this.#p || (this.#f = Math.min(globalThis.devicePixelRatio || 1, 2)), this.#u = n, this.#d = r, this.renderer.setSize(n, r, this.#f), this.camera.aspect = n / r;
|
|
6537
|
-
let i = this.#m &&
|
|
6538
|
-
this.#
|
|
6892
|
+
let i = this.#m && ea($i(this.camera), this.#h);
|
|
6893
|
+
this.#pe(), i && (this.#h = $i(this.camera)), this.#c = !0;
|
|
6539
6894
|
}
|
|
6540
6895
|
frame(e = this.scene, { padding: t = .2, direction: n, duration: r = 0 } = {}) {
|
|
6541
6896
|
N("View", "frame() duration", r, 0);
|
|
6542
|
-
let i = this.camera, a =
|
|
6543
|
-
this.#
|
|
6544
|
-
let o = this.#
|
|
6545
|
-
return this.#m = !1, o && (
|
|
6897
|
+
let i = this.camera, a = aa(i);
|
|
6898
|
+
this.#J = null;
|
|
6899
|
+
let o = this.#re("frame", e, t, n);
|
|
6900
|
+
return this.#m = !1, o && (oa(i, o.place), i.near = o.near ?? i.near, i.far = Math.max(i.far, o.far), this.#_ = i.aspect, this.#v = 1, r > 0 && !this.reducedMotion && (this.#J = {
|
|
6546
6901
|
from: a,
|
|
6547
|
-
to:
|
|
6902
|
+
to: aa(i),
|
|
6548
6903
|
time: 0,
|
|
6549
6904
|
duration: r
|
|
6550
|
-
},
|
|
6905
|
+
}, oa(i, a)), this.invalidate()), this;
|
|
6551
6906
|
}
|
|
6552
6907
|
framing(e = this.scene, { padding: t = .2, direction: n } = {}) {
|
|
6553
|
-
let r = this.#
|
|
6908
|
+
let r = this.#re("framing", e, t, n);
|
|
6554
6909
|
if (!r) return null;
|
|
6555
6910
|
let { position: i, target: a, height: o } = r.place;
|
|
6556
6911
|
return o === void 0 ? {
|
|
@@ -6562,13 +6917,13 @@ var ui = {
|
|
|
6562
6917
|
height: o
|
|
6563
6918
|
};
|
|
6564
6919
|
}
|
|
6565
|
-
#
|
|
6920
|
+
#re(e, t, n, r) {
|
|
6566
6921
|
n >= 0 || E("View", `${e}() padding is the margin around, as a fraction of the size (0.2 = 20%), got ${j(n)}`), n >= 1 && F(this, `${e}() padding ${n} leaves a margin of ${Math.round(n * 100)}% - it is a fraction of the size (0.2 = 20%)`);
|
|
6567
|
-
let i = this.camera, a = r === void 0 ? i.position.clone().sub(i.target ?? new z()).normalize() : typeof r == "string" ?
|
|
6922
|
+
let i = this.camera, a = r === void 0 ? i.position.clone().sub(i.target ?? new z()).normalize() : typeof r == "string" ? Ln(r) : z.fromInput(r, "View").normalize();
|
|
6568
6923
|
r !== void 0 && !(a.len() > 0) && E("View", `${e}() direction is a preset name or a vector from the target towards the camera, got ${j(r)}`), a.len() === 0 && a.set(0, .3, 1).normalize();
|
|
6569
|
-
let o = t instanceof V ?
|
|
6924
|
+
let o = t instanceof V ? ta(t) : this.#ae(t, a);
|
|
6570
6925
|
if (!o.length) return null;
|
|
6571
|
-
let s = i.constructor.type === "orthographic-camera", { center: c, size: l } =
|
|
6926
|
+
let s = i.constructor.type === "orthographic-camera", { center: c, size: l } = zn(o, a, {
|
|
6572
6927
|
aspect: i.aspect,
|
|
6573
6928
|
fov: s ? void 0 : i.fov,
|
|
6574
6929
|
padding: n
|
|
@@ -6592,27 +6947,27 @@ var ui = {
|
|
|
6592
6947
|
far: d * 10
|
|
6593
6948
|
};
|
|
6594
6949
|
}
|
|
6595
|
-
|
|
6596
|
-
let t = this.#
|
|
6950
|
+
#ie(e) {
|
|
6951
|
+
let t = this.#J;
|
|
6597
6952
|
t.time = Math.min(t.duration, t.time + e);
|
|
6598
|
-
let n =
|
|
6599
|
-
|
|
6953
|
+
let n = Vn.inOut(t.time / t.duration), r = this.camera, i = t.from.target.clone().lerp(t.to.target, n), a = t.from.position.clone().sub(t.from.target), o = t.to.position.clone().sub(t.to.target), s = a.len() || 1e-6, c = o.len() || 1e-6, l = ca(a.multiplyScalar(1 / s), o.multiplyScalar(1 / c), n);
|
|
6954
|
+
sa(r, i), r.position.copy(i).add(l.multiplyScalar(s * (c / s) ** n)), t.to.height !== void 0 && (r.height = t.from.height * (t.to.height / t.from.height) ** n), t.time >= t.duration && (oa(r, t.to), this.#J = null), this.invalidate();
|
|
6600
6955
|
}
|
|
6601
|
-
#
|
|
6956
|
+
#ae(e, t) {
|
|
6602
6957
|
let n = e.bounds;
|
|
6603
6958
|
if (n.isEmpty()) return [];
|
|
6604
6959
|
let r = this.camera, i = r.position.clone();
|
|
6605
6960
|
r.position.copy(n.getCenter()).add(t.clone().multiplyScalar(Math.max(n.getRadius(), .001) * 3)), r.updateWorld();
|
|
6606
|
-
let a =
|
|
6607
|
-
return r.position.copy(i), r.updateWorld(), a.length ? a :
|
|
6961
|
+
let a = ra(e, r);
|
|
6962
|
+
return r.position.copy(i), r.updateWorld(), a.length ? a : ta(n);
|
|
6608
6963
|
}
|
|
6609
6964
|
pick(e, t) {
|
|
6610
6965
|
if (typeof e == "object") {
|
|
6611
6966
|
let n = this.canvas.getBoundingClientRect();
|
|
6612
6967
|
t = e.clientY - n.top, e = e.clientX - n.left;
|
|
6613
6968
|
}
|
|
6614
|
-
let n = this.#
|
|
6615
|
-
return r === void 0 ? this.pickAll(e, t)[0] ?? null : r && this.#
|
|
6969
|
+
let n = this.#oe(), r = n ? this.renderer.pick(n, e, t) : void 0;
|
|
6970
|
+
return r === void 0 ? this.pickAll(e, t)[0] ?? null : r && this.#se(r, n);
|
|
6616
6971
|
}
|
|
6617
6972
|
rayAt(e, t) {
|
|
6618
6973
|
if (typeof e == "object") {
|
|
@@ -6620,20 +6975,21 @@ var ui = {
|
|
|
6620
6975
|
t = e.clientY - n.top, e = e.clientX - n.left;
|
|
6621
6976
|
}
|
|
6622
6977
|
let n = [e / (this.#u || 1) * 2 - 1, 1 - t / (this.#d || 1) * 2];
|
|
6623
|
-
return new
|
|
6978
|
+
return new ir().setFromCamera(n, this.camera).ray;
|
|
6624
6979
|
}
|
|
6625
|
-
#
|
|
6980
|
+
#oe() {
|
|
6626
6981
|
let e = this.lastFrame;
|
|
6627
6982
|
if (!e) return null;
|
|
6628
6983
|
let t = 0;
|
|
6629
|
-
for (let { node: n, geometry: r, instances: i } of [...e.opaque, ...e.transparent]) {
|
|
6630
|
-
|
|
6631
|
-
|
|
6984
|
+
for (let { node: n, geometry: r, instances: i, material: a } of [...e.opaque, ...e.transparent]) {
|
|
6985
|
+
if (a.shader?.vertex) return e;
|
|
6986
|
+
let o = n.drawMode;
|
|
6987
|
+
t += i ? i.count : o === "points" ? r.drawnVertices : o === "lines" ? r.drawnCount / 2 : r.drawnCount / 3;
|
|
6632
6988
|
}
|
|
6633
|
-
return t >
|
|
6989
|
+
return t > Xi ? e : null;
|
|
6634
6990
|
}
|
|
6635
|
-
#
|
|
6636
|
-
let n = e.item.node, r = new
|
|
6991
|
+
#se(e, t) {
|
|
6992
|
+
let n = e.item.node, r = new ir().setFromCamera(e.ndc, this.camera), i = n.material.shader?.vertex ? null : r.intersectElement(n, e.element);
|
|
6637
6993
|
if (i) return i;
|
|
6638
6994
|
let a = new B().copy(t.camera.viewProjection).invert(), o = new z(e.ndc[0], e.ndc[1], e.ndc[2]).applyMatrix4(a), s = "instanceMatrices" in n, c = e.element, l = s || n.drawMode !== "triangles";
|
|
6639
6995
|
return {
|
|
@@ -6648,7 +7004,7 @@ var ui = {
|
|
|
6648
7004
|
};
|
|
6649
7005
|
}
|
|
6650
7006
|
project(e) {
|
|
6651
|
-
let { ndc: [t, n, r], visible: i } =
|
|
7007
|
+
let { ndc: [t, n, r], visible: i } = $t(z.fromInput(e, "View"), this.#ce());
|
|
6652
7008
|
return {
|
|
6653
7009
|
x: (t * .5 + .5) * this.#u,
|
|
6654
7010
|
y: (.5 - n * .5) * this.#d,
|
|
@@ -6657,7 +7013,7 @@ var ui = {
|
|
|
6657
7013
|
};
|
|
6658
7014
|
}
|
|
6659
7015
|
screenBounds(e = this.scene) {
|
|
6660
|
-
let t = e instanceof V ?
|
|
7016
|
+
let t = e instanceof V ? ta(e) : ra(e, this.camera);
|
|
6661
7017
|
if (!t.length) return null;
|
|
6662
7018
|
let n = Infinity, r = Infinity, i = -Infinity, a = -Infinity;
|
|
6663
7019
|
for (let e of t) {
|
|
@@ -6674,19 +7030,19 @@ var ui = {
|
|
|
6674
7030
|
height: a - r
|
|
6675
7031
|
};
|
|
6676
7032
|
}
|
|
6677
|
-
#
|
|
7033
|
+
#ce() {
|
|
6678
7034
|
let e = this.camera;
|
|
6679
7035
|
return e.updateWorld(), new B().multiplyMatrices(e.projectionMatrix, e.viewMatrix);
|
|
6680
7036
|
}
|
|
6681
7037
|
pickArea(e) {
|
|
6682
|
-
return this.scene.updateWorldTree(),
|
|
7038
|
+
return this.scene.updateWorldTree(), cr(this.scene, this.camera, this.#ce(), this.#u, this.#d, e);
|
|
6683
7039
|
}
|
|
6684
7040
|
pickAll(e, t) {
|
|
6685
7041
|
if (typeof e == "object") {
|
|
6686
7042
|
let n = this.canvas.getBoundingClientRect();
|
|
6687
7043
|
t = e.clientY - n.top, e = e.clientX - n.left;
|
|
6688
7044
|
}
|
|
6689
|
-
let n = [e / this.#u * 2 - 1, 1 - t / this.#d * 2], r = new
|
|
7045
|
+
let n = [e / this.#u * 2 - 1, 1 - t / this.#d * 2], r = new ir().setFromCamera(n, this.camera), i = this.camera, a = i.position.distanceTo(i.target ?? [
|
|
6690
7046
|
0,
|
|
6691
7047
|
0,
|
|
6692
7048
|
0
|
|
@@ -6695,22 +7051,22 @@ var ui = {
|
|
|
6695
7051
|
}
|
|
6696
7052
|
on(e, t) {
|
|
6697
7053
|
if (!(e in this.#C)) {
|
|
6698
|
-
let t =
|
|
7054
|
+
let t = Ki[e];
|
|
6699
7055
|
t && E("View", `on('${e}') - use '${t}'${t === "hover" ? ", which fires as the thing under the pointer changes (null when it leaves)" : ""}`), P("View", "event", e, ["click", "hover"]);
|
|
6700
7056
|
}
|
|
6701
7057
|
typeof t != "function" && E("View", `on('${e}', fn) needs a function, got ${j(t)}`);
|
|
6702
7058
|
let n = this.#C[e];
|
|
6703
|
-
return n.add(t), this.#
|
|
7059
|
+
return n.add(t), this.#V = !0, () => n.delete(t);
|
|
6704
7060
|
}
|
|
6705
7061
|
tooltip(e, { className: t } = {}) {
|
|
6706
|
-
return e !== null && typeof e != "function" && E("View", `tooltip() takes a function (hit) => text, or null, got ${j(e)}`), this.#T = e, t !== void 0 && (this.#E = t), this.#w && (this.#w.el.className = `phoria-tooltip${this.#E ? ` ${this.#E}` : ""}`), e && this.#
|
|
7062
|
+
return e !== null && typeof e != "function" && E("View", `tooltip() takes a function (hit) => text, or null, got ${j(e)}`), this.#T = e, t !== void 0 && (this.#E = t), this.#w && (this.#w.el.className = `phoria-tooltip${this.#E ? ` ${this.#E}` : ""}`), e && this.#le(), this.#V = !0, this;
|
|
6707
7063
|
}
|
|
6708
|
-
#
|
|
7064
|
+
#le() {
|
|
6709
7065
|
this.#D || (this.#D = !0, import("./tooltip.js").then(({ Tooltip: e }) => {
|
|
6710
|
-
this.#r || (this.#w = new e((e) => this.#
|
|
7066
|
+
this.#r || (this.#w = new e((e) => this.#fe(e)?.(e), this.#E), this.#V = !0, this.#me());
|
|
6711
7067
|
}));
|
|
6712
7068
|
}
|
|
6713
|
-
#
|
|
7069
|
+
#ue(e) {
|
|
6714
7070
|
e !== !0 && (typeof e != "object" || !e || Array.isArray(e)) && E("View", `'keyboard' is true, false or { label: (hit) => text }, got ${j(e)}`);
|
|
6715
7071
|
let t = e === !0 ? {} : e;
|
|
6716
7072
|
A("View", t, ["label"], {
|
|
@@ -6719,18 +7075,18 @@ var ui = {
|
|
|
6719
7075
|
}, "keyboard"), t.label !== void 0 && typeof t.label != "function" && E("View", `keyboard.label is a function (hit) => text, got ${j(t.label)}`), import("./keyboard.js").then(({ Keyboard: e }) => {
|
|
6720
7076
|
this.#r || (this.#A = new e(this, {
|
|
6721
7077
|
focus: (e) => {
|
|
6722
|
-
this.#j = e, this.#
|
|
7078
|
+
this.#j = e, this.#V = !0, this.invalidate();
|
|
6723
7079
|
},
|
|
6724
7080
|
press: (e) => {
|
|
6725
|
-
for (let t of
|
|
7081
|
+
for (let t of ua(e.node, "click")) t(e);
|
|
6726
7082
|
for (let t of this.#C.click) t(e, null);
|
|
6727
7083
|
},
|
|
6728
|
-
tooltip: (e) => this.#
|
|
7084
|
+
tooltip: (e) => this.#fe(e)?.(e),
|
|
6729
7085
|
viewWide: () => this.#C.hover.size > 0 || this.#C.click.size > 0 || !!this.#T
|
|
6730
7086
|
}, t), this.#A.setDescription(this.#M));
|
|
6731
7087
|
});
|
|
6732
7088
|
}
|
|
6733
|
-
#
|
|
7089
|
+
#de(e) {
|
|
6734
7090
|
let { x: t, y: n } = this.project(e.point), r = this.canvas.getBoundingClientRect();
|
|
6735
7091
|
return {
|
|
6736
7092
|
x: t,
|
|
@@ -6740,13 +7096,13 @@ var ui = {
|
|
|
6740
7096
|
event: null
|
|
6741
7097
|
};
|
|
6742
7098
|
}
|
|
6743
|
-
#
|
|
7099
|
+
#fe(e) {
|
|
6744
7100
|
for (let t = e.node; t; t = t.parent) if (t.tooltip) return t.tooltip;
|
|
6745
7101
|
return this.#T;
|
|
6746
7102
|
}
|
|
6747
7103
|
async toImage(e) {
|
|
6748
7104
|
let { snapshot: t } = await import("./snapshot.js");
|
|
6749
|
-
return this.#
|
|
7105
|
+
return this.#ne(!0), t(this.canvas, this.#x.shown, e ?? {}, this.#x.leaders);
|
|
6750
7106
|
}
|
|
6751
7107
|
async explain() {
|
|
6752
7108
|
let { explain: e } = await import("./explain.js"), t = this.render(), n = 0, r = [];
|
|
@@ -6780,20 +7136,21 @@ var ui = {
|
|
|
6780
7136
|
keyboard: !!this.#A,
|
|
6781
7137
|
reducedMotion: this.reducedMotion,
|
|
6782
7138
|
description: this.canvas.getAttribute?.("aria-label") ?? this.#M
|
|
6783
|
-
}
|
|
7139
|
+
},
|
|
7140
|
+
debug: this.#N
|
|
6784
7141
|
});
|
|
6785
7142
|
}
|
|
6786
7143
|
dispose() {
|
|
6787
7144
|
if (!this.#r) {
|
|
6788
7145
|
this.#r = !0, this.#n = !1, cancelAnimationFrame(this.#o);
|
|
6789
7146
|
for (let e of this.#b) e();
|
|
6790
|
-
this.controls?.dispose(), this.#x.dispose(), this.#w?.dispose(), this.#A?.dispose(), this.#M !== null && !this.#A && (this.description = null), this.renderer.dispose(this.scene), this.#i &&
|
|
7147
|
+
this.controls?.dispose(), this.#x.dispose(), this.#w?.dispose(), this.#A?.dispose(), this.#P?.dispose(), this.#M !== null && !this.#A && (this.description = null), this.renderer.dispose(this.scene), this.#i && Zi--, this.#a && this.canvas.remove();
|
|
6791
7148
|
}
|
|
6792
7149
|
}
|
|
6793
|
-
#
|
|
7150
|
+
#pe() {
|
|
6794
7151
|
let e = this.#e;
|
|
6795
7152
|
this.#_ ||= e.aspect;
|
|
6796
|
-
let t =
|
|
7153
|
+
let t = Bn(this.#g, this.#_, e.aspect), n = t / this.#v;
|
|
6797
7154
|
if (this.#v = t, !(Math.abs(n - 1) < 1e-9)) {
|
|
6798
7155
|
if (e.constructor.type === "orthographic-camera") e.height *= n;
|
|
6799
7156
|
else if (e.target) {
|
|
@@ -6802,49 +7159,52 @@ var ui = {
|
|
|
6802
7159
|
} else e.fov = Math.min(170, 2 * Math.atan(Math.tan(e.fov * Math.PI / 360) * n) * 360 / Math.PI);
|
|
6803
7160
|
}
|
|
6804
7161
|
}
|
|
6805
|
-
#
|
|
6806
|
-
this.#o || this.#r || !this.#l || (this.renderMode !== "manual" || this.#n && this.#t || this.#c || this.#
|
|
7162
|
+
#me() {
|
|
7163
|
+
this.#o || this.#r || !this.#l || (this.renderMode !== "manual" || this.#n && this.#t || this.#c || this.#V) && (this.#o = requestAnimationFrame(this.#he));
|
|
6807
7164
|
}
|
|
6808
|
-
#
|
|
7165
|
+
#he = (e) => {
|
|
6809
7166
|
this.#o = 0;
|
|
6810
7167
|
let t = this.#s ? Math.min(this.maxDelta, (e - this.#s) / 1e3) : 0;
|
|
6811
7168
|
this.#s = e;
|
|
6812
7169
|
try {
|
|
6813
|
-
this.#n && (this.time += t, this.#t?.(t, this.time), this.scene.motionReduced = this.reducedMotion, this.scene.update(t, this.time)), this.#
|
|
7170
|
+
this.#n && (this.time += t, this.#t?.(t, this.time), this.scene.motionReduced = this.reducedMotion, this.scene.update(t, this.time)), this.#te(t), this.#V && this.#ve(), (this.#c || this.renderMode === "always" || this.renderMode === "auto" && this.#y.changed(this.scene, this.camera, this.time)) && this.render();
|
|
6814
7171
|
} finally {
|
|
6815
|
-
(this.renderMode !== "manual" || this.#n && this.#t || this.#c || this.#
|
|
7172
|
+
(this.renderMode !== "manual" || this.#n && this.#t || this.#c || this.#V) && this.#me();
|
|
6816
7173
|
}
|
|
6817
7174
|
};
|
|
6818
|
-
#
|
|
6819
|
-
return this.#C.hover.size > 0 || !!this.#T || !!this.#O || this.#C.click.size > 0 || !!this.lastFrame?.interactive;
|
|
6820
|
-
}
|
|
6821
|
-
#
|
|
6822
|
-
|
|
6823
|
-
|
|
6824
|
-
|
|
6825
|
-
if (this.#
|
|
6826
|
-
|
|
6827
|
-
|
|
6828
|
-
if (
|
|
6829
|
-
|
|
7175
|
+
#ge() {
|
|
7176
|
+
return this.#C.hover.size > 0 || !!this.#T || !!this.#O || this.#C.click.size > 0 || !!this.lastFrame?.interactive || this.#_e();
|
|
7177
|
+
}
|
|
7178
|
+
#_e() {
|
|
7179
|
+
return !!this.#N && (this.#N.bounds === "hovered" || this.#N.normals === "hovered");
|
|
7180
|
+
}
|
|
7181
|
+
#ve() {
|
|
7182
|
+
if (this.#V = !1, !this.#ge()) return;
|
|
7183
|
+
let e = this.#B;
|
|
7184
|
+
if (this.#j) return this.#ye(this.#j, this.#de(this.#j));
|
|
7185
|
+
if (this.#Y) return this.#ye(this.#Y);
|
|
7186
|
+
if (!e || this.#U) return this.#ye(null);
|
|
7187
|
+
let t = this.#oe();
|
|
7188
|
+
if (t && this.#H) {
|
|
7189
|
+
this.#V = !0;
|
|
6830
7190
|
return;
|
|
6831
7191
|
}
|
|
6832
7192
|
let n = t ? this.renderer.pickAsync(t, e.x, e.y) : void 0;
|
|
6833
|
-
if (!n) return this.#
|
|
6834
|
-
this.#
|
|
6835
|
-
this.#
|
|
7193
|
+
if (!n) return this.#ye(this.pick(e.x, e.y));
|
|
7194
|
+
this.#H = !0, n.then((e) => {
|
|
7195
|
+
this.#H = !1, !this.#r && (this.#ye(this.#Y ?? (e && this.#B ? this.#se(e, t) : null)), this.#me());
|
|
6836
7196
|
});
|
|
6837
7197
|
}
|
|
6838
|
-
#
|
|
6839
|
-
let n = this.#
|
|
6840
|
-
if (this.#
|
|
6841
|
-
(this.#
|
|
6842
|
-
let i =
|
|
7198
|
+
#ye(e, t = this.#B) {
|
|
7199
|
+
let n = this.#q, r = n === e || n && e && n.node === e.node && n.instance === e.instance && n.datum === e.datum && (e.node.drawMode !== "points" || n.face === e.face);
|
|
7200
|
+
if (this.#q = e, t && e && this.#w ? this.#w.show(e, t.clientX, t.clientY) : this.#w?.hide(), r) return;
|
|
7201
|
+
(this.#Se(n) || this.#Se(e) || this.#_e()) && this.invalidate(), (this.#C.click.size || this.lastFrame?.interactive) && (this.canvas.style.cursor = e && ia(e.node, "onDrag") ? "grab" : e && this.#xe(e) ? "pointer" : "");
|
|
7202
|
+
let i = ua(n?.node, "hover"), a = ua(e?.node, "hover");
|
|
6843
7203
|
for (let e of i) a.includes(e) || e(null);
|
|
6844
7204
|
for (let t of a) t(e);
|
|
6845
7205
|
for (let n of this.#C.hover) n(e, t?.event ?? null);
|
|
6846
7206
|
}
|
|
6847
|
-
#
|
|
7207
|
+
#be(e, t, n) {
|
|
6848
7208
|
let r = t.node, i = t.index, a = i !== null && r.drawMode === "points", o = {
|
|
6849
7209
|
node: r,
|
|
6850
7210
|
point: t.position.clone(),
|
|
@@ -6856,12 +7216,12 @@ var ui = {
|
|
|
6856
7216
|
datum: r.datumAt?.(i) ?? null
|
|
6857
7217
|
};
|
|
6858
7218
|
if (e === "click") {
|
|
6859
|
-
for (let e of
|
|
7219
|
+
for (let e of ua(r, "click")) e(o);
|
|
6860
7220
|
for (let e of this.#C.click) e(o, n);
|
|
6861
7221
|
} else {
|
|
6862
|
-
if (this.#
|
|
7222
|
+
if (this.#Y = e === "over" ? o : null, n) {
|
|
6863
7223
|
let e = this.canvas.getBoundingClientRect();
|
|
6864
|
-
this.#
|
|
7224
|
+
this.#B = {
|
|
6865
7225
|
x: n.clientX - e.left,
|
|
6866
7226
|
y: n.clientY - e.top,
|
|
6867
7227
|
clientX: n.clientX,
|
|
@@ -6869,17 +7229,17 @@ var ui = {
|
|
|
6869
7229
|
event: n
|
|
6870
7230
|
};
|
|
6871
7231
|
}
|
|
6872
|
-
e === "out" && (this.#
|
|
7232
|
+
e === "out" && (this.#B = null), this.#V = !0, this.#me();
|
|
6873
7233
|
}
|
|
6874
7234
|
}
|
|
6875
|
-
#
|
|
6876
|
-
return this.#C.click.size > 0 ||
|
|
7235
|
+
#xe(e) {
|
|
7236
|
+
return this.#C.click.size > 0 || ua(e.node, "click").length > 0;
|
|
6877
7237
|
}
|
|
6878
|
-
#
|
|
7238
|
+
#Se(e) {
|
|
6879
7239
|
if (!e) return null;
|
|
6880
7240
|
let t = null, n = null;
|
|
6881
7241
|
for (let r = e.node; r; r = r.parent) t ??= r.highlight, n ??= r.highlightWhole ? r : null;
|
|
6882
|
-
if (t ??= this.#O, !t && e === this.#j && (t =
|
|
7242
|
+
if (t ??= this.#O, !t && e === this.#j && (t = Ji), !t) return null;
|
|
6883
7243
|
let r = e.node;
|
|
6884
7244
|
if (n) {
|
|
6885
7245
|
let e = /* @__PURE__ */ new Set();
|
|
@@ -6890,27 +7250,27 @@ var ui = {
|
|
|
6890
7250
|
index: null,
|
|
6891
7251
|
nodes: e,
|
|
6892
7252
|
color: t,
|
|
6893
|
-
amount:
|
|
7253
|
+
amount: qi
|
|
6894
7254
|
};
|
|
6895
7255
|
}
|
|
6896
7256
|
return {
|
|
6897
7257
|
node: r,
|
|
6898
7258
|
index: e.instance ?? (r.drawMode === "points" ? e.face : null),
|
|
6899
7259
|
color: t,
|
|
6900
|
-
amount:
|
|
7260
|
+
amount: qi
|
|
6901
7261
|
};
|
|
6902
7262
|
}
|
|
6903
|
-
#
|
|
7263
|
+
#Ce(e) {
|
|
6904
7264
|
let t = e.labels, n = this.height / 2, r = t.filter((e) => e.style.occlude && e.visible && !(e.style.minScale && e.scale * n < e.style.minScale));
|
|
6905
7265
|
if (!r.length) return;
|
|
6906
|
-
let i =
|
|
7266
|
+
let i = ir.solids([...e.opaque, ...e.transparent]), a = new ir();
|
|
6907
7267
|
for (let e of r) {
|
|
6908
7268
|
a.setFromCamera(e.ndc, this.camera);
|
|
6909
7269
|
let t = e.position.distanceTo(a.ray.origin);
|
|
6910
7270
|
e.occluded = a.blocked(i, t * .995, e.node, e.index);
|
|
6911
7271
|
}
|
|
6912
7272
|
}
|
|
6913
|
-
#
|
|
7273
|
+
#we() {
|
|
6914
7274
|
let e = this.canvas, t = (t) => {
|
|
6915
7275
|
let n = e.getBoundingClientRect();
|
|
6916
7276
|
return {
|
|
@@ -6921,26 +7281,26 @@ var ui = {
|
|
|
6921
7281
|
event: t
|
|
6922
7282
|
};
|
|
6923
7283
|
}, n = (e) => {
|
|
6924
|
-
this.#j && this.#A?.clear(), this.#
|
|
6925
|
-
let n = this.#
|
|
6926
|
-
n && n.id === e.pointerId && !n.moved && Math.hypot(this.#
|
|
7284
|
+
this.#j && this.#A?.clear(), this.#B = t(e);
|
|
7285
|
+
let n = this.#K;
|
|
7286
|
+
n && n.id === e.pointerId && !n.moved && Math.hypot(this.#B.x - n.x, this.#B.y - n.y) >= 4 && (n.moved = !0), this.#W ? this.#Te(e, this.#B) : this.#G?.move(e), this.#U = e.buttons !== 0, this.#U ? this.#w?.hide() : this.#w?.move(e.clientX, e.clientY), this.#ge() && (this.#V = !0, this.#me());
|
|
6927
7287
|
}, r = () => {
|
|
6928
|
-
this.#
|
|
7288
|
+
this.#B = null, this.#V = !0, this.#me();
|
|
6929
7289
|
}, i = (e) => {
|
|
6930
|
-
this.#
|
|
7290
|
+
this.#W ? this.#Ee(e) : this.#G?.up(e), this.#U = !1, this.#V = !0, this.#me();
|
|
6931
7291
|
}, a = (n) => {
|
|
6932
|
-
if (this.#
|
|
6933
|
-
this.#
|
|
7292
|
+
if (this.#W?.id === n.pointerId) return;
|
|
7293
|
+
this.#J = null, this.#W = null;
|
|
6934
7294
|
let r = t(n);
|
|
6935
|
-
this.#
|
|
7295
|
+
this.#K = {
|
|
6936
7296
|
id: n.pointerId,
|
|
6937
7297
|
x: r.x,
|
|
6938
7298
|
y: r.y,
|
|
6939
7299
|
moved: !1
|
|
6940
7300
|
};
|
|
6941
|
-
let i = this.lastFrame?.draggable && (n.pointerType !== "mouse" || n.button === 0) ? this.pick(n) : null, a = i &&
|
|
7301
|
+
let i = this.lastFrame?.draggable && (n.pointerType !== "mouse" || n.button === 0) ? this.pick(n) : null, a = i && ia(i.node, "onDrag");
|
|
6942
7302
|
if (!i || !a) {
|
|
6943
|
-
this.#
|
|
7303
|
+
this.#G?.down(n);
|
|
6944
7304
|
return;
|
|
6945
7305
|
}
|
|
6946
7306
|
try {
|
|
@@ -6960,7 +7320,7 @@ var ui = {
|
|
|
6960
7320
|
delta: new z(),
|
|
6961
7321
|
event: n
|
|
6962
7322
|
};
|
|
6963
|
-
this.#
|
|
7323
|
+
this.#W = {
|
|
6964
7324
|
drag: c,
|
|
6965
7325
|
id: n.pointerId,
|
|
6966
7326
|
x: o.x,
|
|
@@ -6969,18 +7329,18 @@ var ui = {
|
|
|
6969
7329
|
started: !1
|
|
6970
7330
|
};
|
|
6971
7331
|
}, o = (e) => {
|
|
6972
|
-
if (this.#
|
|
6973
|
-
this.#
|
|
7332
|
+
if (this.#K?.moved) {
|
|
7333
|
+
this.#K = null;
|
|
6974
7334
|
return;
|
|
6975
7335
|
}
|
|
6976
7336
|
if (!this.#C.click.size && !this.lastFrame?.interactive) return;
|
|
6977
7337
|
let t = this.pick(e);
|
|
6978
|
-
if (t) for (let e of
|
|
7338
|
+
if (t) for (let e of ua(t.node, "click")) e(t);
|
|
6979
7339
|
for (let n of this.#C.click) n(t, e);
|
|
6980
7340
|
};
|
|
6981
7341
|
e.addEventListener("pointerdown", a), e.addEventListener("pointermove", n), e.addEventListener("pointerleave", r), e.addEventListener("pointerup", i), e.addEventListener("pointercancel", i), e.addEventListener("click", o);
|
|
6982
7342
|
let s = () => {
|
|
6983
|
-
this.#
|
|
7343
|
+
this.#J = null;
|
|
6984
7344
|
};
|
|
6985
7345
|
if (e.addEventListener("wheel", s, { passive: !0 }), this.#b.push(() => {
|
|
6986
7346
|
e.removeEventListener("wheel", s), e.removeEventListener("pointerdown", a), e.removeEventListener("pointermove", n), e.removeEventListener("pointerleave", r), e.removeEventListener("pointerup", i), e.removeEventListener("pointercancel", i), e.removeEventListener("click", o);
|
|
@@ -6993,9 +7353,9 @@ var ui = {
|
|
|
6993
7353
|
let c = globalThis.matchMedia?.("(prefers-reduced-motion: reduce)");
|
|
6994
7354
|
if (c) {
|
|
6995
7355
|
let e = () => {
|
|
6996
|
-
this.#
|
|
7356
|
+
this.#z = c.matches, this.invalidate();
|
|
6997
7357
|
};
|
|
6998
|
-
this.#
|
|
7358
|
+
this.#z = c.matches, c.addEventListener?.("change", e), this.#b.push(() => c.removeEventListener?.("change", e));
|
|
6999
7359
|
}
|
|
7000
7360
|
if (typeof IntersectionObserver < "u") {
|
|
7001
7361
|
let t = new IntersectionObserver(([e]) => {
|
|
@@ -7004,8 +7364,8 @@ var ui = {
|
|
|
7004
7364
|
t.observe(e), this.#b.push(() => t.disconnect());
|
|
7005
7365
|
}
|
|
7006
7366
|
}
|
|
7007
|
-
#
|
|
7008
|
-
let n = this.#
|
|
7367
|
+
#Te(e, t) {
|
|
7368
|
+
let n = this.#W;
|
|
7009
7369
|
if (!n || e.pointerId !== n.id) return;
|
|
7010
7370
|
let { drag: r } = n;
|
|
7011
7371
|
if (r.event = e, r.ray = this.rayAt(t.x, t.y), !n.started) {
|
|
@@ -7025,19 +7385,19 @@ var ui = {
|
|
|
7025
7385
|
let i = r.ray.intersectPlane(r.plane.normal, r.plane.point);
|
|
7026
7386
|
i === null ? r.point = null : (r.point = r.ray.at(i), r.delta.copy(r.point).sub(r.start)), r.node.onDrag?.(r), this.invalidate();
|
|
7027
7387
|
}
|
|
7028
|
-
#
|
|
7029
|
-
let t = this.#
|
|
7388
|
+
#Ee(e) {
|
|
7389
|
+
let t = this.#W;
|
|
7030
7390
|
if (t && e.pointerId === t.id) {
|
|
7031
|
-
this.#
|
|
7391
|
+
this.#W = null;
|
|
7032
7392
|
try {
|
|
7033
7393
|
this.canvas.releasePointerCapture(e.pointerId);
|
|
7034
7394
|
} catch {}
|
|
7035
7395
|
t.started && (t.drag.phase = "end", t.drag.event = e, t.drag.node.onDrag?.(t.drag), this.canvas.style.cursor = "", this.invalidate());
|
|
7036
7396
|
}
|
|
7037
7397
|
}
|
|
7038
|
-
#
|
|
7039
|
-
this.#
|
|
7040
|
-
let t = this.#
|
|
7398
|
+
#De(e) {
|
|
7399
|
+
this.#Q || (this.#Q = !0, console.info("phoria2: the scene has no lights, so the View is lighting it (autoLight: false turns this off)"));
|
|
7400
|
+
let t = this.#X, n = this.#Z;
|
|
7041
7401
|
e.lights.push({
|
|
7042
7402
|
kind: "hemisphere",
|
|
7043
7403
|
node: t,
|
|
@@ -7053,15 +7413,15 @@ var ui = {
|
|
|
7053
7413
|
});
|
|
7054
7414
|
}
|
|
7055
7415
|
};
|
|
7056
|
-
function
|
|
7416
|
+
function $i(e) {
|
|
7057
7417
|
return [
|
|
7058
7418
|
...e.position,
|
|
7059
7419
|
...e.target ?? [],
|
|
7060
7420
|
e.fov ?? e.height
|
|
7061
7421
|
];
|
|
7062
7422
|
}
|
|
7063
|
-
var
|
|
7064
|
-
function
|
|
7423
|
+
var ea = (e, t) => !!t && e.length === t.length && e.every((e, n) => e === t[n]);
|
|
7424
|
+
function ta(e) {
|
|
7065
7425
|
if (e.isEmpty()) return [];
|
|
7066
7426
|
if (e.min.equals(e.max)) return [e.min.toArray()];
|
|
7067
7427
|
let t = [];
|
|
@@ -7072,14 +7432,14 @@ function ji(e) {
|
|
|
7072
7432
|
]);
|
|
7073
7433
|
return t;
|
|
7074
7434
|
}
|
|
7075
|
-
var
|
|
7076
|
-
function
|
|
7435
|
+
var na = 4e3;
|
|
7436
|
+
function ra(e, t) {
|
|
7077
7437
|
e.updateWorld();
|
|
7078
7438
|
let n = [];
|
|
7079
7439
|
return e.eachShownTo(t, (e) => {
|
|
7080
7440
|
let t = e;
|
|
7081
|
-
if ("instanceMatrices" in t && t.count <=
|
|
7082
|
-
n.push(...
|
|
7441
|
+
if ("instanceMatrices" in t && t.count <= na) t.eachInstanceBox((e, t, r, i, a, o) => {
|
|
7442
|
+
n.push(...ta(new V([
|
|
7083
7443
|
e,
|
|
7084
7444
|
t,
|
|
7085
7445
|
r
|
|
@@ -7089,7 +7449,7 @@ function Ni(e, t) {
|
|
|
7089
7449
|
o
|
|
7090
7450
|
])));
|
|
7091
7451
|
});
|
|
7092
|
-
else if ((t.drawMode === "lines" || t.drawMode === "points") && t.geometry.vertexCount <=
|
|
7452
|
+
else if ((t.drawMode === "lines" || t.drawMode === "points") && t.geometry.vertexCount <= na) {
|
|
7093
7453
|
let e = t.geometry, r = e.positions, i = t.worldMatrix, a = e.indices ? e.vertexCount : e.drawnVertices;
|
|
7094
7454
|
for (let e = 0; e < a; e++) {
|
|
7095
7455
|
let t = r[e * 3], a = r[e * 3 + 1], o = r[e * 3 + 2];
|
|
@@ -7099,45 +7459,45 @@ function Ni(e, t) {
|
|
|
7099
7459
|
i[2] * t + i[6] * a + i[10] * o + i[14]
|
|
7100
7460
|
]);
|
|
7101
7461
|
}
|
|
7102
|
-
} else n.push(...
|
|
7462
|
+
} else n.push(...ta(e.expandBounds(new V())));
|
|
7103
7463
|
}), n;
|
|
7104
7464
|
}
|
|
7105
|
-
function
|
|
7465
|
+
function ia(e, t) {
|
|
7106
7466
|
for (let n = e; n; n = n.parent) if (n[t]) return n;
|
|
7107
7467
|
return null;
|
|
7108
7468
|
}
|
|
7109
|
-
function
|
|
7469
|
+
function aa(e) {
|
|
7110
7470
|
return {
|
|
7111
7471
|
position: e.position.clone(),
|
|
7112
7472
|
target: (e.target ?? new z()).clone(),
|
|
7113
7473
|
height: e.height
|
|
7114
7474
|
};
|
|
7115
7475
|
}
|
|
7116
|
-
function
|
|
7117
|
-
e.position.copy(t.position),
|
|
7476
|
+
function oa(e, t) {
|
|
7477
|
+
e.position.copy(t.position), sa(e, t.target), t.height !== void 0 && (e.height = t.height);
|
|
7118
7478
|
}
|
|
7119
|
-
function
|
|
7479
|
+
function sa(e, t) {
|
|
7120
7480
|
e.target ? e.target.copy(t) : e.target = t.clone();
|
|
7121
7481
|
}
|
|
7122
|
-
function
|
|
7482
|
+
function ca(e, t, n) {
|
|
7123
7483
|
let r = Math.max(-1, Math.min(1, e.dot(t)));
|
|
7124
7484
|
if (r > .9999) return e.clone().lerp(t, n).normalize();
|
|
7125
7485
|
if (r < -.9999) {
|
|
7126
7486
|
let r = Math.abs(e[1]) < .9 ? new z(0, 1, 0) : new z(1, 0, 0), i = e.clone().cross(r).normalize();
|
|
7127
|
-
return n < .5 ?
|
|
7487
|
+
return n < .5 ? ca(e, i, n * 2) : ca(i, t, n * 2 - 1);
|
|
7128
7488
|
}
|
|
7129
7489
|
let i = Math.acos(r), a = Math.sin(i);
|
|
7130
7490
|
return e.clone().multiplyScalar(Math.sin((1 - n) * i) / a).add(t.clone().multiplyScalar(Math.sin(n * i) / a));
|
|
7131
7491
|
}
|
|
7132
|
-
function
|
|
7133
|
-
return e.index === null && !e.node.handlersFor(t).length ? [] :
|
|
7492
|
+
function la(e, t) {
|
|
7493
|
+
return e.index === null && !e.node.handlersFor(t).length ? [] : ua(e.node, t);
|
|
7134
7494
|
}
|
|
7135
|
-
function
|
|
7495
|
+
function ua(e, t) {
|
|
7136
7496
|
let n = [];
|
|
7137
7497
|
for (let r = e; r; r = r.parent) n.push(...r.handlersFor(t));
|
|
7138
7498
|
return n;
|
|
7139
7499
|
}
|
|
7140
|
-
function
|
|
7500
|
+
function da(e) {
|
|
7141
7501
|
if (e === void 0) {
|
|
7142
7502
|
let e = document.createElement("canvas");
|
|
7143
7503
|
return Object.assign(e.style, {
|
|
@@ -7154,26 +7514,44 @@ function Vi(e) {
|
|
|
7154
7514
|
}
|
|
7155
7515
|
return e instanceof HTMLCanvasElement || E("View", `'canvas' must be a <canvas> element or a selector, got ${j(e)}`), e;
|
|
7156
7516
|
}
|
|
7517
|
+
function fa(e) {
|
|
7518
|
+
if (e === !1 || e === null) return null;
|
|
7519
|
+
if (e === !0) return { ...Vi };
|
|
7520
|
+
(!e || typeof e != "object" || Array.isArray(e)) && E("View", `'debug' is true, false or { ${Hi.join(", ")} }, got ${j(e)}`), A("View", e, Hi, {
|
|
7521
|
+
helpers: "list what to draw: { lights: true, bounds: true, ... }",
|
|
7522
|
+
fps: "use 'stats: true'",
|
|
7523
|
+
wireframe: "use new Lines({ geometry: edges(geometry) }) for a wireframe"
|
|
7524
|
+
}, "debug");
|
|
7525
|
+
let t = {};
|
|
7526
|
+
for (let n of Hi) {
|
|
7527
|
+
let r = e[n];
|
|
7528
|
+
t[n] = r === void 0 ? !1 : n === "bounds" || n === "normals" ? r === "hovered" ? "hovered" : pa(n, r, "true, false or 'hovered'") : n === "stats" ? r === !0 ? "top-left" : r !== !1 && P("View", "debug.stats", r, Ui) : pa(n, r, "true or false");
|
|
7529
|
+
}
|
|
7530
|
+
return t;
|
|
7531
|
+
}
|
|
7532
|
+
function pa(e, t, n) {
|
|
7533
|
+
return typeof t != "boolean" && E("View", `debug.${e} is ${n}, got ${j(t)}`), t;
|
|
7534
|
+
}
|
|
7157
7535
|
// src/geometry/triangulate.js
|
|
7158
|
-
function
|
|
7536
|
+
function ma(e) {
|
|
7159
7537
|
let t = 0;
|
|
7160
7538
|
for (let n = 0, r = e.length - 1; n < e.length; r = n++) t += (e[r][0] - e[n][0]) * (e[r][1] + e[n][1]);
|
|
7161
7539
|
return t;
|
|
7162
7540
|
}
|
|
7163
|
-
function
|
|
7541
|
+
function ha(e, t = []) {
|
|
7164
7542
|
let n = [...e], r = e.map((e, t) => t);
|
|
7165
|
-
|
|
7543
|
+
ma(e) < 0 && r.reverse();
|
|
7166
7544
|
let i = t.map((e) => {
|
|
7167
7545
|
let t = n.length;
|
|
7168
7546
|
n.push(...e);
|
|
7169
7547
|
let r = e.map((e, n) => t + n);
|
|
7170
|
-
return
|
|
7171
|
-
}).sort((e, t) =>
|
|
7172
|
-
for (let e of i) r =
|
|
7173
|
-
return
|
|
7548
|
+
return ma(e) > 0 && r.reverse(), r;
|
|
7549
|
+
}).sort((e, t) => ga(n, t) - ga(n, e));
|
|
7550
|
+
for (let e of i) r = _a(n, r, e, i);
|
|
7551
|
+
return ba(n, r);
|
|
7174
7552
|
}
|
|
7175
|
-
var
|
|
7176
|
-
function
|
|
7553
|
+
var ga = (e, t) => Math.max(...t.map((t) => e[t][0]));
|
|
7554
|
+
function _a(e, t, n, r) {
|
|
7177
7555
|
let i = 0;
|
|
7178
7556
|
n.forEach((t, r) => {
|
|
7179
7557
|
e[t][0] > e[n[i]][0] && (i = r);
|
|
@@ -7183,7 +7561,7 @@ function Gi(e, t, n, r) {
|
|
|
7183
7561
|
let s = -1, c = Infinity;
|
|
7184
7562
|
t.forEach((t, n) => {
|
|
7185
7563
|
let r = e[t], i = ((r[0] - a[0]) ** 2 + (r[1] - a[1]) ** 2) * (r[0] >= a[0] ? 1 : 4);
|
|
7186
|
-
i >= c || o.some(([e, t]) =>
|
|
7564
|
+
i >= c || o.some(([e, t]) => va(a, r, e, t)) || (s = n, c = i);
|
|
7187
7565
|
}), s < 0 && (s = 0);
|
|
7188
7566
|
let l = [...n.slice(i), ...n.slice(0, i)];
|
|
7189
7567
|
return [
|
|
@@ -7194,52 +7572,52 @@ function Gi(e, t, n, r) {
|
|
|
7194
7572
|
...t.slice(s + 1)
|
|
7195
7573
|
];
|
|
7196
7574
|
}
|
|
7197
|
-
function
|
|
7198
|
-
if (
|
|
7575
|
+
function va(e, t, n, r) {
|
|
7576
|
+
if (ya(e, n) || ya(e, r) || ya(t, n) || ya(t, r)) return !1;
|
|
7199
7577
|
let i = Q(n, r, e), a = Q(n, r, t), o = Q(e, t, n), s = Q(e, t, r);
|
|
7200
7578
|
return i * a < 0 && o * s < 0;
|
|
7201
7579
|
}
|
|
7202
|
-
var
|
|
7203
|
-
function
|
|
7580
|
+
var ya = (e, t) => e[0] === t[0] && e[1] === t[1], Q = (e, t, n) => (t[0] - e[0]) * (n[1] - e[1]) - (t[1] - e[1]) * (n[0] - e[0]);
|
|
7581
|
+
function ba(e, t) {
|
|
7204
7582
|
let n = [...t], r = [];
|
|
7205
7583
|
for (; n.length > 3;) {
|
|
7206
7584
|
let t = -1;
|
|
7207
|
-
for (let r = 0; r < n.length && t < 0; r++)
|
|
7208
|
-
if (t < 0) for (let r = 0; r < n.length && t < 0; r++)
|
|
7585
|
+
for (let r = 0; r < n.length && t < 0; r++) Sa(e, n, r) && (t = r);
|
|
7586
|
+
if (t < 0) for (let r = 0; r < n.length && t < 0; r++) xa(e, n, r) && (t = r);
|
|
7209
7587
|
t < 0 && (t = 0);
|
|
7210
7588
|
let i = n.length;
|
|
7211
7589
|
r.push(n[(t + i - 1) % i], n[t], n[(t + 1) % i]), n.splice(t, 1);
|
|
7212
7590
|
}
|
|
7213
7591
|
return n.length === 3 && r.push(...n), r;
|
|
7214
7592
|
}
|
|
7215
|
-
function
|
|
7593
|
+
function xa(e, t, n) {
|
|
7216
7594
|
let r = t.length;
|
|
7217
7595
|
return Q(e[t[(n + r - 1) % r]], e[t[n]], e[t[(n + 1) % r]]) > 0;
|
|
7218
7596
|
}
|
|
7219
|
-
function
|
|
7220
|
-
if (!
|
|
7597
|
+
function Sa(e, t, n) {
|
|
7598
|
+
if (!xa(e, t, n)) return !1;
|
|
7221
7599
|
let r = t.length, i = e[t[(n + r - 1) % r]], a = e[t[n]], o = e[t[(n + 1) % r]];
|
|
7222
7600
|
for (let n of t) {
|
|
7223
7601
|
let t = e[n];
|
|
7224
|
-
if (!(
|
|
7602
|
+
if (!(ya(t, i) || ya(t, a) || ya(t, o)) && Q(i, a, t) >= 0 && Q(a, o, t) >= 0 && Q(o, i, t) >= 0) return !1;
|
|
7225
7603
|
}
|
|
7226
7604
|
return !0;
|
|
7227
7605
|
}
|
|
7228
7606
|
// src/geometry/generators.js
|
|
7229
|
-
var
|
|
7607
|
+
var Ca = /* @__PURE__ */ t({
|
|
7230
7608
|
GENERATOR_OPTIONS: () => $,
|
|
7231
|
-
axes: () =>
|
|
7232
|
-
box: () =>
|
|
7233
|
-
cylinder: () =>
|
|
7234
|
-
edges: () =>
|
|
7235
|
-
extrude: () =>
|
|
7236
|
-
grid: () =>
|
|
7237
|
-
icosphere: () =>
|
|
7238
|
-
lathe: () =>
|
|
7239
|
-
plane: () =>
|
|
7240
|
-
sphere: () =>
|
|
7241
|
-
torus: () =>
|
|
7242
|
-
}),
|
|
7609
|
+
axes: () => Ba,
|
|
7610
|
+
box: () => Ea,
|
|
7611
|
+
cylinder: () => Aa,
|
|
7612
|
+
edges: () => za,
|
|
7613
|
+
extrude: () => Fa,
|
|
7614
|
+
grid: () => Va,
|
|
7615
|
+
icosphere: () => Na,
|
|
7616
|
+
lathe: () => Pa,
|
|
7617
|
+
plane: () => ka,
|
|
7618
|
+
sphere: () => Oa,
|
|
7619
|
+
torus: () => Ma
|
|
7620
|
+
}), wa = Math.PI * 2, $ = {
|
|
7243
7621
|
box: [
|
|
7244
7622
|
"size",
|
|
7245
7623
|
"width",
|
|
@@ -7286,18 +7664,18 @@ var Zi = /* @__PURE__ */ t({
|
|
|
7286
7664
|
],
|
|
7287
7665
|
axes: ["size"],
|
|
7288
7666
|
grid: ["size", "divisions"]
|
|
7289
|
-
},
|
|
7290
|
-
function
|
|
7667
|
+
}, Ta = "has one 'segments' option, used for every face";
|
|
7668
|
+
function Ea(e) {
|
|
7291
7669
|
let t = "box()", n = I(t, e, $.box, (e) => ({ size: e }), {
|
|
7292
|
-
widthSegments: `box() ${
|
|
7293
|
-
heightSegments: `box() ${
|
|
7294
|
-
depthSegments: `box() ${
|
|
7670
|
+
widthSegments: `box() ${Ta}`,
|
|
7671
|
+
heightSegments: `box() ${Ta}`,
|
|
7672
|
+
depthSegments: `box() ${Ta}`
|
|
7295
7673
|
}), r = L(t, "size", n.size, 1), i = L(t, "width", n.width, r), a = L(t, "height", n.height, r), o = L(t, "depth", n.depth, r), s = R(t, "segments", n.segments, 1), c = [
|
|
7296
7674
|
i,
|
|
7297
7675
|
a,
|
|
7298
7676
|
o
|
|
7299
|
-
], l = new
|
|
7300
|
-
for (let [e, t, n] of
|
|
7677
|
+
], l = new Ha();
|
|
7678
|
+
for (let [e, t, n] of Da) {
|
|
7301
7679
|
let r = l.count;
|
|
7302
7680
|
for (let r = 0; r <= s; r++) {
|
|
7303
7681
|
let i = r / s;
|
|
@@ -7320,7 +7698,7 @@ function ea(e) {
|
|
|
7320
7698
|
segments: s
|
|
7321
7699
|
});
|
|
7322
7700
|
}
|
|
7323
|
-
var
|
|
7701
|
+
var Da = [
|
|
7324
7702
|
[
|
|
7325
7703
|
[
|
|
7326
7704
|
1,
|
|
@@ -7424,15 +7802,15 @@ var ta = [
|
|
|
7424
7802
|
]
|
|
7425
7803
|
]
|
|
7426
7804
|
];
|
|
7427
|
-
function
|
|
7805
|
+
function Oa(e) {
|
|
7428
7806
|
let t = "sphere()", n = I(t, e, $.sphere, (e) => ({ radius: e }), {
|
|
7429
7807
|
widthSegments: "sphere(): use 'segments' for the divisions around the sphere",
|
|
7430
7808
|
heightSegments: "sphere(): use 'rings' for the divisions from pole to pole"
|
|
7431
|
-
}), r = L(t, "radius", n.radius, 1), i = R(t, "segments", n.segments, 32, 3), a = R(t, "rings", n.rings, 16, 2), o = new
|
|
7809
|
+
}), r = L(t, "radius", n.radius, 1), i = R(t, "segments", n.segments, 32, 3), a = R(t, "rings", n.rings, 16, 2), o = new Ha();
|
|
7432
7810
|
for (let e = 0; e <= a; e++) {
|
|
7433
7811
|
let t = e / a, n = e === 0 || e === a, s = n ? 0 : Math.sin(t * Math.PI), c = e === 0 ? 1 : e === a ? -1 : Math.cos(t * Math.PI);
|
|
7434
7812
|
for (let e = 0; e <= i; e++) {
|
|
7435
|
-
let a = n && e < i ? (e + .5) / i : e / i, l = e % i / i *
|
|
7813
|
+
let a = n && e < i ? (e + .5) / i : e / i, l = e % i / i * wa, u = -Math.cos(l) * s, d = c, f = Math.sin(l) * s;
|
|
7436
7814
|
o.vertex(u * r, d * r, f * r, u, d, f, a, t);
|
|
7437
7815
|
}
|
|
7438
7816
|
}
|
|
@@ -7446,12 +7824,12 @@ function na(e) {
|
|
|
7446
7824
|
rings: a
|
|
7447
7825
|
});
|
|
7448
7826
|
}
|
|
7449
|
-
function
|
|
7827
|
+
function ka(e) {
|
|
7450
7828
|
let t = "plane()", n = I(t, e, $.plane, (e) => ({ size: e }), {
|
|
7451
7829
|
height: "plane() lies in the x-z plane - use 'depth' rather than 'height'",
|
|
7452
|
-
widthSegments: `plane() ${
|
|
7453
|
-
heightSegments: `plane() ${
|
|
7454
|
-
}), r = L(t, "size", n.size, 1), i = L(t, "width", n.width, r), a = L(t, "depth", n.depth, r), o = R(t, "segments", n.segments, 1), s = new
|
|
7830
|
+
widthSegments: `plane() ${Ta}`,
|
|
7831
|
+
heightSegments: `plane() ${Ta}`
|
|
7832
|
+
}), r = L(t, "size", n.size, 1), i = L(t, "width", n.width, r), a = L(t, "depth", n.depth, r), o = R(t, "segments", n.segments, 1), s = new Ha();
|
|
7455
7833
|
for (let e = 0; e <= o; e++) {
|
|
7456
7834
|
let t = e / o;
|
|
7457
7835
|
for (let e = 0; e <= o; e++) {
|
|
@@ -7466,7 +7844,7 @@ function ra(e) {
|
|
|
7466
7844
|
segments: o
|
|
7467
7845
|
});
|
|
7468
7846
|
}
|
|
7469
|
-
function
|
|
7847
|
+
function Aa(e) {
|
|
7470
7848
|
let t = "cylinder()", n = I(t, e, $.cylinder, null, {
|
|
7471
7849
|
radiusBottom: "cylinder(): use 'radius' for the bottom radius",
|
|
7472
7850
|
radialSegments: "cylinder(): use 'segments' for the divisions around the cylinder",
|
|
@@ -7475,18 +7853,18 @@ function ia(e) {
|
|
|
7475
7853
|
r === 0 && i === 0 && E(t, "'radius' and 'radiusTop' can't both be 0");
|
|
7476
7854
|
let a = L(t, "height", n.height, 1), o = R(t, "segments", n.segments, 32, 3), s = n.caps ?? !0;
|
|
7477
7855
|
typeof s != "boolean" && E(t, `'caps' must be true or false, got ${j(s)}`);
|
|
7478
|
-
let c =
|
|
7856
|
+
let c = Wa(t, n.axis, "y"), l = new Ha(), u = r - i, d = Math.hypot(a, u), f = a / d, p = u / d;
|
|
7479
7857
|
for (let e = 0; e <= 1; e++) {
|
|
7480
7858
|
let t = e === 0 ? i : r, n = e === 0 ? a / 2 : -a / 2;
|
|
7481
7859
|
for (let r = 0; r <= o; r++) {
|
|
7482
|
-
let i = t === 0 && r < o ? (r + .5) / o : r / o, a = t === 0 ? i *
|
|
7860
|
+
let i = t === 0 && r < o ? (r + .5) / o : r / o, a = t === 0 ? i * wa : r % o / o * wa, s = Math.sin(a), c = Math.cos(a);
|
|
7483
7861
|
l.vertex(t * s, n, t * c, f * s, p, f * c, i, e);
|
|
7484
7862
|
}
|
|
7485
7863
|
}
|
|
7486
7864
|
return l.grid(0, o, 1, {
|
|
7487
7865
|
pinchTop: i === 0,
|
|
7488
7866
|
pinchBottom: r === 0
|
|
7489
|
-
}), s && (i > 0 &&
|
|
7867
|
+
}), s && (i > 0 && ja(l, i, a / 2, 1, o), r > 0 && ja(l, r, -a / 2, -1, o)), l.turn("y", c), l.build({
|
|
7490
7868
|
type: "cylinder",
|
|
7491
7869
|
radius: r,
|
|
7492
7870
|
radiusTop: i,
|
|
@@ -7496,10 +7874,10 @@ function ia(e) {
|
|
|
7496
7874
|
...c !== "y" && { axis: c }
|
|
7497
7875
|
});
|
|
7498
7876
|
}
|
|
7499
|
-
function
|
|
7877
|
+
function ja(e, t, n, r, i) {
|
|
7500
7878
|
let a = e.vertex(0, n, 0, 0, r, 0, .5, .5);
|
|
7501
7879
|
for (let a = 0; a < i; a++) {
|
|
7502
|
-
let o = a / i *
|
|
7880
|
+
let o = a / i * wa, s = Math.sin(o), c = Math.cos(o);
|
|
7503
7881
|
e.vertex(t * s, n, t * c, 0, r, 0, .5 + s / 2, .5 + r * c / 2);
|
|
7504
7882
|
}
|
|
7505
7883
|
for (let t = 0; t < i; t++) {
|
|
@@ -7507,15 +7885,15 @@ function aa(e, t, n, r, i) {
|
|
|
7507
7885
|
r > 0 ? e.indices.push(a, n, o) : e.indices.push(a, o, n);
|
|
7508
7886
|
}
|
|
7509
7887
|
}
|
|
7510
|
-
function
|
|
7888
|
+
function Ma(e) {
|
|
7511
7889
|
let t = "torus()", n = I(t, e, $.torus, null, {
|
|
7512
7890
|
tubularSegments: "torus(): use 'segments' for the divisions around the ring",
|
|
7513
7891
|
radialSegments: "torus(): use 'tubeSegments' for the divisions around the tube"
|
|
7514
|
-
}), r = L(t, "radius", n.radius, 1), i = L(t, "tube", n.tube, .4), a = R(t, "segments", n.segments, 48, 3), o = R(t, "tubeSegments", n.tubeSegments, 16, 3), s = new
|
|
7892
|
+
}), r = L(t, "radius", n.radius, 1), i = L(t, "tube", n.tube, .4), a = R(t, "segments", n.segments, 48, 3), o = R(t, "tubeSegments", n.tubeSegments, 16, 3), s = new Ha();
|
|
7515
7893
|
for (let e = 0; e <= o; e++) {
|
|
7516
|
-
let t = e / o, n = -(e % o / o) *
|
|
7894
|
+
let t = e / o, n = -(e % o / o) * wa, c = Math.cos(n), l = Math.sin(n);
|
|
7517
7895
|
for (let e = 0; e <= a; e++) {
|
|
7518
|
-
let n = e / a, o = e % a / a *
|
|
7896
|
+
let n = e / a, o = e % a / a * wa, u = Math.sin(o), d = Math.cos(o), f = c * u, p = l, m = c * d;
|
|
7519
7897
|
s.vertex(r * u + i * f, i * p, r * d + i * m, f, p, m, n, t);
|
|
7520
7898
|
}
|
|
7521
7899
|
}
|
|
@@ -7527,7 +7905,7 @@ function oa(e) {
|
|
|
7527
7905
|
tubeSegments: o
|
|
7528
7906
|
});
|
|
7529
7907
|
}
|
|
7530
|
-
function
|
|
7908
|
+
function Na(e) {
|
|
7531
7909
|
let t = "icosphere()", n = I(t, e, $.icosphere, (e) => ({ radius: e }), { subdivisions: "icosphere(): use 'detail' (0-6) for the subdivision level" }), r = L(t, "radius", n.radius, 1), i = R(t, "detail", n.detail, 2, 0, 6), a = (1 + Math.sqrt(5)) / 2, o = [], s = (e, t, n) => {
|
|
7532
7910
|
let r = Math.hypot(e, t, n);
|
|
7533
7911
|
return o.push(e / r, t / r, n / r), o.length / 3 - 1;
|
|
@@ -7678,14 +8056,14 @@ function sa(e) {
|
|
|
7678
8056
|
detail: i
|
|
7679
8057
|
}, l;
|
|
7680
8058
|
}
|
|
7681
|
-
function
|
|
8059
|
+
function Pa(e) {
|
|
7682
8060
|
let t = "lathe()", n = I(t, e, $.lathe, null, {
|
|
7683
8061
|
divisions: "lathe(): use 'segments' for the divisions around the axis",
|
|
7684
8062
|
phiSegments: "lathe(): use 'segments' for the divisions around the axis",
|
|
7685
8063
|
profile: "lathe(): use 'points' for the profile, as [radius, y] pairs"
|
|
7686
|
-
}), r =
|
|
8064
|
+
}), r = Ra(t, "points", n.points, 2).map(([e, t]) => [Math.abs(e) < 1e-9 ? 0 : e, t]);
|
|
7687
8065
|
r.some(([e]) => e < 0) && E(t, "'points' are [radius, y] pairs - a radius can't be below 0");
|
|
7688
|
-
let i = R(t, "segments", n.segments, 32, 3), a =
|
|
8066
|
+
let i = R(t, "segments", n.segments, 32, 3), a = Wa(t, n.axis, "y"), o = [];
|
|
7689
8067
|
for (let e = 0; e + 1 < r.length; e++) {
|
|
7690
8068
|
let [t, n] = r[e], [i, a] = r[e + 1], s = Math.hypot(i - t, a - n);
|
|
7691
8069
|
s !== 0 && o.push({
|
|
@@ -7696,9 +8074,9 @@ function ca(e) {
|
|
|
7696
8074
|
});
|
|
7697
8075
|
}
|
|
7698
8076
|
o.length || E(t, "'points' need at least two different points");
|
|
7699
|
-
let s = o.reduce((e, t) => e + t.len, 0), c = new
|
|
8077
|
+
let s = o.reduce((e, t) => e + t.len, 0), c = new Ha(), l = 0;
|
|
7700
8078
|
return o.forEach((e, t) => {
|
|
7701
|
-
let n =
|
|
8079
|
+
let n = La(o[t - 1]?.normal, e.normal), r = La(o[t + 1]?.normal, e.normal), a = c.count;
|
|
7702
8080
|
for (let [[t, a], [o, u], d] of [[
|
|
7703
8081
|
e.to,
|
|
7704
8082
|
r,
|
|
@@ -7708,7 +8086,7 @@ function ca(e) {
|
|
|
7708
8086
|
n,
|
|
7709
8087
|
1 - l / s
|
|
7710
8088
|
]]) for (let e = 0; e <= i; e++) {
|
|
7711
|
-
let n = e % i / i *
|
|
8089
|
+
let n = e % i / i * wa, r = Math.sin(n), s = Math.cos(n);
|
|
7712
8090
|
c.vertex(t * r, a, t * s, o * r, u, o * s, e / i, d);
|
|
7713
8091
|
}
|
|
7714
8092
|
c.grid(a, i, 1, {
|
|
@@ -7722,17 +8100,17 @@ function ca(e) {
|
|
|
7722
8100
|
...a !== "y" && { axis: a }
|
|
7723
8101
|
});
|
|
7724
8102
|
}
|
|
7725
|
-
function
|
|
8103
|
+
function Fa(e) {
|
|
7726
8104
|
let t = "extrude()", n = I(t, e, $.extrude, null, {
|
|
7727
8105
|
amount: "extrude(): use 'depth'",
|
|
7728
8106
|
points: "extrude(): use 'shape' for the outline, as [x, y] pairs",
|
|
7729
8107
|
outline: "extrude(): use 'shape' for the outline, as [x, y] pairs",
|
|
7730
8108
|
bevelEnabled: "extrude() has no bevel - round the shape's corners instead"
|
|
7731
|
-
}), r =
|
|
8109
|
+
}), r = Ga(Ra(t, "shape", n.shape, 3));
|
|
7732
8110
|
n.holes !== void 0 && !Array.isArray(n.holes) && E(t, `'holes' must be a list of outlines, got ${j(n.holes)}`), typeof n.holes?.[0]?.[0] == "number" && E(t, "'holes' is a list of outlines - for one hole, holes: [outline]");
|
|
7733
|
-
let i = (n.holes ?? []).map((e, n) =>
|
|
8111
|
+
let i = (n.holes ?? []).map((e, n) => Ga(Ra(t, `holes[${n}]`, e, 3))), a = L(t, "depth", n.depth, 1), o = Wa(t, n.axis, "z"), s = a / 2, c = ma(r) < 0 ? [...r].reverse() : r, l = i.map((e) => ma(e) > 0 ? [...e].reverse() : e), u = [c, ...l].flat(), d = Infinity, f = -Infinity, p = Infinity, m = -Infinity;
|
|
7734
8112
|
for (let [e, t] of u) d = Math.min(d, e), f = Math.max(f, e), p = Math.min(p, t), m = Math.max(m, t);
|
|
7735
|
-
let h = f - d || 1, g = m - p || 1, _ = new
|
|
8113
|
+
let h = f - d || 1, g = m - p || 1, _ = new Ha(), v = ha(c, l);
|
|
7736
8114
|
for (let [e, t] of [[s, 1], [-s, -1]]) {
|
|
7737
8115
|
let n = _.count;
|
|
7738
8116
|
for (let [n, r] of u) _.vertex(n, r, e, 0, 0, t, t > 0 ? (n - d) / h : (f - n) / h, (m - r) / g);
|
|
@@ -7744,7 +8122,7 @@ function la(e) {
|
|
|
7744
8122
|
return [(s - i) / c, -(o - r) / c];
|
|
7745
8123
|
}), i = n.reduce((e, t) => e + t, 0) || 1, a = 0;
|
|
7746
8124
|
for (let o = 0; o < t; o++) {
|
|
7747
|
-
let c = r[o], [l, u] = [
|
|
8125
|
+
let c = r[o], [l, u] = [La(r[(o + t - 1) % t], c), La(r[(o + 1) % t], c)], [d, f] = e[o], [p, m] = e[(o + 1) % t], h = a / i, g = (a + n[o]) / i, v = _.vertex(d, f, s, l[0], l[1], 0, h, 0), y = _.vertex(d, f, -s, l[0], l[1], 0, h, 1), b = _.vertex(p, m, -s, u[0], u[1], 0, g, 1), x = _.vertex(p, m, s, u[0], u[1], 0, g, 0);
|
|
7748
8126
|
_.indices.push(v, y, b, v, b, x), a += n[o];
|
|
7749
8127
|
}
|
|
7750
8128
|
}
|
|
@@ -7756,13 +8134,13 @@ function la(e) {
|
|
|
7756
8134
|
...o !== "z" && { axis: o }
|
|
7757
8135
|
});
|
|
7758
8136
|
}
|
|
7759
|
-
var
|
|
7760
|
-
function
|
|
7761
|
-
if (!e || e[0] * t[0] + e[1] * t[1] <
|
|
8137
|
+
var Ia = Math.cos(Math.PI / 6);
|
|
8138
|
+
function La(e, t) {
|
|
8139
|
+
if (!e || e[0] * t[0] + e[1] * t[1] < Ia) return t;
|
|
7762
8140
|
let n = e[0] + t[0], r = e[1] + t[1], i = Math.hypot(n, r) || 1;
|
|
7763
8141
|
return [n / i, r / i];
|
|
7764
8142
|
}
|
|
7765
|
-
function
|
|
8143
|
+
function Ra(e, t, n, r) {
|
|
7766
8144
|
Array.isArray(n) || E(e, `'${t}' must be a list of [x, y] pairs, got ${j(n)}`);
|
|
7767
8145
|
let i = n;
|
|
7768
8146
|
return i.length < r && E(e, `'${t}' needs at least ${r} points, got ${i.length}`), i.map((n, r) => {
|
|
@@ -7771,7 +8149,7 @@ function fa(e, t, n, r) {
|
|
|
7771
8149
|
return typeof i == "number" && typeof a == "number" && Number.isFinite(i) && Number.isFinite(a) || E(e, `'${t}' point ${r} must be two finite numbers, got ${j(n)}`), [i, a];
|
|
7772
8150
|
});
|
|
7773
8151
|
}
|
|
7774
|
-
function
|
|
8152
|
+
function za(e, t = {}) {
|
|
7775
8153
|
e instanceof U || E("edges()", `expected a Geometry, got ${j(e)}`);
|
|
7776
8154
|
let { angle: n = 1 } = I("edges()", t, ["angle"], null);
|
|
7777
8155
|
n >= 0 && n < 180 || E("edges()", `'angle' is in degrees, 0 to under 180, got ${j(n)}`);
|
|
@@ -7813,7 +8191,7 @@ function pa(e, t = {}) {
|
|
|
7813
8191
|
indices: p
|
|
7814
8192
|
});
|
|
7815
8193
|
}
|
|
7816
|
-
function
|
|
8194
|
+
function Ba(e) {
|
|
7817
8195
|
let t = "axes()", n = L(t, "size", I(t, e, $.axes, (e) => ({ size: e })).size, 1), r = new U({
|
|
7818
8196
|
positions: [
|
|
7819
8197
|
0,
|
|
@@ -7861,7 +8239,7 @@ function ma(e) {
|
|
|
7861
8239
|
size: n
|
|
7862
8240
|
}, r;
|
|
7863
8241
|
}
|
|
7864
|
-
function
|
|
8242
|
+
function Va(e) {
|
|
7865
8243
|
let t = "grid()", n = I(t, e, $.grid, (e) => ({ size: e }), { segments: "grid() uses 'divisions' for the number of squares along each side" }), r = L(t, "size", n.size, 10), i = R(t, "divisions", n.divisions, 10), a = r / 2, o = [];
|
|
7866
8244
|
for (let e = 0; e <= i; e++) {
|
|
7867
8245
|
let t = -a + r * e / i;
|
|
@@ -7874,7 +8252,7 @@ function ha(e) {
|
|
|
7874
8252
|
divisions: i
|
|
7875
8253
|
}, s;
|
|
7876
8254
|
}
|
|
7877
|
-
var
|
|
8255
|
+
var Ha = class {
|
|
7878
8256
|
positions = [];
|
|
7879
8257
|
normals = [];
|
|
7880
8258
|
uvs = [];
|
|
@@ -7894,7 +8272,7 @@ var ga = class {
|
|
|
7894
8272
|
}
|
|
7895
8273
|
turn(e, t) {
|
|
7896
8274
|
if (e === t) return;
|
|
7897
|
-
let n =
|
|
8275
|
+
let n = Ua[e][t];
|
|
7898
8276
|
for (let e of [this.positions, this.normals]) for (let t = 0; t < e.length; t += 3) {
|
|
7899
8277
|
let [r, i, a] = n(e[t], e[t + 1], e[t + 2]);
|
|
7900
8278
|
e[t] = r, e[t + 1] = i, e[t + 2] = a;
|
|
@@ -7909,7 +8287,7 @@ var ga = class {
|
|
|
7909
8287
|
});
|
|
7910
8288
|
return a.source = e, a;
|
|
7911
8289
|
}
|
|
7912
|
-
},
|
|
8290
|
+
}, Ua = {
|
|
7913
8291
|
y: {
|
|
7914
8292
|
x: (e, t, n) => [
|
|
7915
8293
|
t,
|
|
@@ -7935,14 +8313,14 @@ var ga = class {
|
|
|
7935
8313
|
]
|
|
7936
8314
|
}
|
|
7937
8315
|
};
|
|
7938
|
-
function
|
|
8316
|
+
function Wa(e, t, n) {
|
|
7939
8317
|
return t === void 0 ? n : P(e, "axis", t, [
|
|
7940
8318
|
"x",
|
|
7941
8319
|
"y",
|
|
7942
8320
|
"z"
|
|
7943
8321
|
]);
|
|
7944
8322
|
}
|
|
7945
|
-
function
|
|
8323
|
+
function Ga(e) {
|
|
7946
8324
|
let t = e.filter((t, n) => {
|
|
7947
8325
|
let r = e[(n + e.length - 1) % e.length];
|
|
7948
8326
|
return t[0] !== r[0] || t[1] !== r[1];
|
|
@@ -7950,7 +8328,7 @@ function ya(e) {
|
|
|
7950
8328
|
return t.length >= 3 ? t : e;
|
|
7951
8329
|
}
|
|
7952
8330
|
// src/geometry/outline.js
|
|
7953
|
-
var
|
|
8331
|
+
var Ka = Math.PI * 2, qa = {
|
|
7954
8332
|
circle: [
|
|
7955
8333
|
"radius",
|
|
7956
8334
|
"segments",
|
|
@@ -7983,7 +8361,7 @@ var ba = Math.PI * 2, xa = {
|
|
|
7983
8361
|
"depth",
|
|
7984
8362
|
"center"
|
|
7985
8363
|
]
|
|
7986
|
-
},
|
|
8364
|
+
}, Ja = {
|
|
7987
8365
|
r: "use 'radius'",
|
|
7988
8366
|
x: "use center: [x, y]",
|
|
7989
8367
|
y: "use center: [x, y]",
|
|
@@ -7993,17 +8371,17 @@ var ba = Math.PI * 2, xa = {
|
|
|
7993
8371
|
cornerRadius: "use 'radius' for the corners' rounding",
|
|
7994
8372
|
n: "use 'sides' (polygon) or 'segments'"
|
|
7995
8373
|
};
|
|
7996
|
-
function
|
|
7997
|
-
let t = "outline.circle()", n =
|
|
8374
|
+
function Ya(e) {
|
|
8375
|
+
let t = "outline.circle()", n = to(t, e, qa.circle, (e) => ({ radius: e })), r = L(t, "radius", n.radius, 1), i = R(t, "segments", n.segments, 32, 3), [a, o] = no(t, "center", n.center);
|
|
7998
8376
|
return Array.from({ length: i }, (e, t) => {
|
|
7999
|
-
let n = t / i *
|
|
8377
|
+
let n = t / i * Ka;
|
|
8000
8378
|
return [a + Math.cos(n) * r, o + Math.sin(n) * r];
|
|
8001
8379
|
});
|
|
8002
8380
|
}
|
|
8003
|
-
function
|
|
8004
|
-
let t = "outline.rect()", n =
|
|
8381
|
+
function Xa(e) {
|
|
8382
|
+
let t = "outline.rect()", n = to(t, e, qa.rect, (e) => ({ size: e })), r = L(t, "size", n.size, 1), i = L(t, "width", n.width, r), a = L(t, "height", n.height, r), o = n.radius === void 0 ? 0 : M(t, "radius", n.radius);
|
|
8005
8383
|
(o < 0 || o > Math.min(i, a) / 2) && E(t, `'radius' must be from 0 to half the shorter side (${Math.min(i, a) / 2}), got ${o}`);
|
|
8006
|
-
let s = R(t, "segments", n.segments, 8, 1), [c, l] =
|
|
8384
|
+
let s = R(t, "segments", n.segments, 8, 1), [c, l] = no(t, "center", n.center), u = i / 2, d = a / 2;
|
|
8007
8385
|
if (o === 0) return [
|
|
8008
8386
|
[c - u, l - d],
|
|
8009
8387
|
[c + u, l - d],
|
|
@@ -8038,26 +8416,26 @@ function wa(e) {
|
|
|
8038
8416
|
}
|
|
8039
8417
|
return f;
|
|
8040
8418
|
}
|
|
8041
|
-
function
|
|
8042
|
-
let t = "outline.polygon()", n =
|
|
8419
|
+
function Za(e) {
|
|
8420
|
+
let t = "outline.polygon()", n = to(t, e, qa.polygon, (e) => ({ radius: e })), r = L(t, "radius", n.radius, 1), i = R(t, "sides", n.sides, 6, 3), a = n.angle === void 0 ? 0 : M(t, "angle", n.angle), [o, s] = no(t, "center", n.center);
|
|
8043
8421
|
return Array.from({ length: i }, (e, t) => {
|
|
8044
|
-
let n = a + t / i *
|
|
8422
|
+
let n = a + t / i * Ka;
|
|
8045
8423
|
return [o + Math.cos(n) * r, s + Math.sin(n) * r];
|
|
8046
8424
|
});
|
|
8047
8425
|
}
|
|
8048
|
-
function
|
|
8049
|
-
let t = "outline.arc()", n =
|
|
8426
|
+
function Qa(e) {
|
|
8427
|
+
let t = "outline.arc()", n = to(t, e, qa.arc, null), r = L(t, "radius", n.radius, 1), i = n.from === void 0 ? 0 : M(t, "from", n.from), a = n.to === void 0 ? i + Ka : M(t, "to", n.to);
|
|
8050
8428
|
a === i && E(t, "'from' and 'to' are the same angle - there's no arc between them");
|
|
8051
|
-
let o = R(t, "segments", n.segments, Math.max(1, Math.ceil(Math.abs(a - i) /
|
|
8429
|
+
let o = R(t, "segments", n.segments, Math.max(1, Math.ceil(Math.abs(a - i) / Ka * 32)), 1), [s, c] = no(t, "center", n.center);
|
|
8052
8430
|
return Array.from({ length: o + 1 }, (e, t) => {
|
|
8053
8431
|
let n = i + (a - i) * t / o;
|
|
8054
8432
|
return [s + Math.cos(n) * r, c + Math.sin(n) * r];
|
|
8055
8433
|
});
|
|
8056
8434
|
}
|
|
8057
|
-
function
|
|
8058
|
-
let t = "outline.gear()", n =
|
|
8435
|
+
function $a(e) {
|
|
8436
|
+
let t = "outline.gear()", n = to(t, e, qa.gear, (e) => ({ radius: e })), r = L(t, "radius", n.radius, 1), i = R(t, "teeth", n.teeth, 24, 3), a = L(t, "depth", n.depth, Math.min(r / 2, r * Math.PI / i));
|
|
8059
8437
|
a >= r && E(t, `'depth' must be less than the radius (${r}), got ${a}`);
|
|
8060
|
-
let [o, s] =
|
|
8438
|
+
let [o, s] = no(t, "center", n.center), c = r - a, l = Ka / i, u = [];
|
|
8061
8439
|
for (let e = 0; e < i; e++) for (let [t, n] of [
|
|
8062
8440
|
[0, c],
|
|
8063
8441
|
[.12, r],
|
|
@@ -8069,43 +8447,43 @@ function Da(e) {
|
|
|
8069
8447
|
}
|
|
8070
8448
|
return u;
|
|
8071
8449
|
}
|
|
8072
|
-
var
|
|
8073
|
-
circle:
|
|
8074
|
-
rect:
|
|
8075
|
-
polygon:
|
|
8076
|
-
arc:
|
|
8077
|
-
gear:
|
|
8078
|
-
},
|
|
8079
|
-
function
|
|
8450
|
+
var eo = {
|
|
8451
|
+
circle: Ya,
|
|
8452
|
+
rect: Xa,
|
|
8453
|
+
polygon: Za,
|
|
8454
|
+
arc: Qa,
|
|
8455
|
+
gear: $a
|
|
8456
|
+
}, to = (e, t, n, r) => I(e, t, n, r, Ja);
|
|
8457
|
+
function no(e, t, n) {
|
|
8080
8458
|
if (n === void 0) return [0, 0];
|
|
8081
8459
|
let r = n;
|
|
8082
8460
|
return r && typeof r == "object" && typeof r[0] == "number" && typeof r[1] == "number" && Number.isFinite(r[0]) && Number.isFinite(r[1]) || E(e, `'${t}' must be [x, y], got ${j(n)}`), [r[0], r[1]];
|
|
8083
8461
|
}
|
|
8084
8462
|
// src/geometry/fromPolygons.js
|
|
8085
|
-
var
|
|
8086
|
-
function
|
|
8087
|
-
A(
|
|
8463
|
+
var ro = "fromPolygons()";
|
|
8464
|
+
function io(e) {
|
|
8465
|
+
A(ro, e, [
|
|
8088
8466
|
"points",
|
|
8089
8467
|
"polygons",
|
|
8090
8468
|
"edges",
|
|
8091
8469
|
"smooth"
|
|
8092
8470
|
]);
|
|
8093
8471
|
let { points: t, polygons: n } = e ?? {};
|
|
8094
|
-
Array.isArray(t) || E(
|
|
8472
|
+
Array.isArray(t) || E(ro, `'points' must be an array of { x, y, z } or [x, y, z], got ${j(t)}`), Array.isArray(n) || E(ro, `'polygons' must be an array of { vertices: [...] }, got ${j(n)}`);
|
|
8095
8473
|
let r = t.map((e, t) => {
|
|
8096
8474
|
let n = Array.isArray(e) ? e : e && typeof e == "object" ? [
|
|
8097
8475
|
e.x,
|
|
8098
8476
|
e.y,
|
|
8099
8477
|
e.z
|
|
8100
8478
|
] : null;
|
|
8101
|
-
return n && n.length === 3 && n.every(Number.isFinite) || E(
|
|
8479
|
+
return n && n.length === 3 && n.every(Number.isFinite) || E(ro, `point ${t} must be { x, y, z } or [x, y, z] numbers, got ${j(e)}`), n;
|
|
8102
8480
|
});
|
|
8103
8481
|
n.forEach((e, t) => {
|
|
8104
8482
|
let n = e?.vertices;
|
|
8105
|
-
(!Array.isArray(n) || n.length < 3) && E(
|
|
8106
|
-
for (let e of n) (!Number.isInteger(e) || e < 0 || e >= r.length) && E(
|
|
8483
|
+
(!Array.isArray(n) || n.length < 3) && E(ro, `polygon ${t} needs 'vertices' with 3 or more point indices, got ${j(n)}`);
|
|
8484
|
+
for (let e of n) (!Number.isInteger(e) || e < 0 || e >= r.length) && E(ro, `polygon ${t} refers to point ${j(e)} but there are only ${r.length} points`);
|
|
8107
8485
|
let i = e.uvs;
|
|
8108
|
-
i === void 0 || Array.isArray(i) && i.length === n.length * 2 && i.every(Number.isFinite) || E(
|
|
8486
|
+
i === void 0 || Array.isArray(i) && i.length === n.length * 2 && i.every(Number.isFinite) || E(ro, `polygon ${t} 'uvs' must be ${n.length * 2} numbers (a u, v pair per vertex), got ${j(i)}`);
|
|
8109
8487
|
});
|
|
8110
8488
|
let i = [];
|
|
8111
8489
|
n.forEach(({ vertices: e }, t) => {
|
|
@@ -8129,29 +8507,29 @@ function Ma(e) {
|
|
|
8129
8507
|
return a.computeNormals({ flat: !(e.smooth && !o) });
|
|
8130
8508
|
}
|
|
8131
8509
|
// src/geometry/Curve.js
|
|
8132
|
-
var
|
|
8510
|
+
var ao = ["closed", "tension"], oo = {
|
|
8133
8511
|
loop: "use 'closed: true'",
|
|
8134
8512
|
smooth: "the curve is always smooth - 'tension' (0-1) sets how tight"
|
|
8135
|
-
},
|
|
8513
|
+
}, so = ["segments", "dash"], co = { dashed: "use 'dash: [on, off]' - lengths in the curve's units" }, lo = [
|
|
8136
8514
|
"radius",
|
|
8137
8515
|
"segments",
|
|
8138
8516
|
"sides"
|
|
8139
|
-
],
|
|
8517
|
+
], uo = {
|
|
8140
8518
|
tubularSegments: "use 'segments'",
|
|
8141
8519
|
radialSegments: "use 'sides'"
|
|
8142
|
-
},
|
|
8520
|
+
}, fo = [
|
|
8143
8521
|
"plane",
|
|
8144
8522
|
"radius",
|
|
8145
8523
|
"center",
|
|
8146
8524
|
"tilt"
|
|
8147
|
-
],
|
|
8525
|
+
], po = 48, mo = class {
|
|
8148
8526
|
#e;
|
|
8149
8527
|
#t;
|
|
8150
8528
|
#n;
|
|
8151
8529
|
#r;
|
|
8152
8530
|
constructor(e, t = {}) {
|
|
8153
|
-
(!Array.isArray(e) || e.length < 2) && E("curve()", `needs an array of two or more points, got ${j(e)}`), A("curve()", t,
|
|
8154
|
-
let n = this.#i() *
|
|
8531
|
+
(!Array.isArray(e) || e.length < 2) && E("curve()", `needs an array of two or more points, got ${j(e)}`), A("curve()", t, ao, oo), this.#e = e.map((e) => z.fromInput(e, "curve()")), this.#t = !!t.closed, this.#n = t.tension === void 0 ? 0 : M("curve()", "tension", t.tension);
|
|
8532
|
+
let n = this.#i() * po;
|
|
8155
8533
|
this.#r = new Float64Array(n + 1);
|
|
8156
8534
|
let r = this.#s(0);
|
|
8157
8535
|
for (let e = 1; e <= n; e++) {
|
|
@@ -8177,7 +8555,7 @@ var Na = ["closed", "tension"], Pa = {
|
|
|
8177
8555
|
return Array.from({ length: t }, (e, t) => this.at(t / n));
|
|
8178
8556
|
}
|
|
8179
8557
|
line(e = {}) {
|
|
8180
|
-
A("curve.line()", e,
|
|
8558
|
+
A("curve.line()", e, so, co);
|
|
8181
8559
|
let t = this.#a("curve.line()", e.segments), n = this.length / t, r = [], i = (e, t) => {
|
|
8182
8560
|
let i = Math.max(1, Math.ceil((t - e) / n - 1e-9)), a = this.at(e / this.length);
|
|
8183
8561
|
for (let n = 1; n <= i; n++) {
|
|
@@ -8194,7 +8572,7 @@ var Na = ["closed", "tension"], Pa = {
|
|
|
8194
8572
|
return new U({ positions: r });
|
|
8195
8573
|
}
|
|
8196
8574
|
tube(e = {}) {
|
|
8197
|
-
A("curve.tube()", e,
|
|
8575
|
+
A("curve.tube()", e, lo, uo);
|
|
8198
8576
|
let t = e.radius === void 0 ? .1 : M("curve.tube()", "radius", e.radius), n = R("curve.tube()", "sides", e.sides, 8, 3), r = this.#a("curve.tube()", e.segments), i = this.#t ? r : r + 1, a = [], o = [], s = this.tangentAt(0), c = new z(...Math.abs(s[1]) < .9 ? [
|
|
8199
8577
|
0,
|
|
8200
8578
|
1,
|
|
@@ -8249,17 +8627,17 @@ var Na = ["closed", "tension"], Pa = {
|
|
|
8249
8627
|
return t;
|
|
8250
8628
|
}
|
|
8251
8629
|
};
|
|
8252
|
-
function
|
|
8253
|
-
return new
|
|
8630
|
+
function ho(e, t) {
|
|
8631
|
+
return new mo(e, t);
|
|
8254
8632
|
}
|
|
8255
|
-
function
|
|
8633
|
+
function go(e = {}) {
|
|
8256
8634
|
let t = e.plane === void 0 ? "xz" : P("ellipse()", "plane", e.plane, [
|
|
8257
8635
|
"xz",
|
|
8258
8636
|
"xy",
|
|
8259
8637
|
"yz"
|
|
8260
8638
|
]), [n, r] = [...t].map((e) => "xyz".indexOf(e)), i = (e) => `radius${"XYZ"[e]}`, a = i(3 - n - r);
|
|
8261
8639
|
A("ellipse()", e, [
|
|
8262
|
-
...
|
|
8640
|
+
...fo,
|
|
8263
8641
|
i(n),
|
|
8264
8642
|
i(r)
|
|
8265
8643
|
], { [a]: `an ellipse in '${t}' has '${i(n)}' and '${i(r)}' - set plane for another` });
|
|
@@ -8274,21 +8652,21 @@ function Ua(e = {}) {
|
|
|
8274
8652
|
];
|
|
8275
8653
|
f[n] = 1;
|
|
8276
8654
|
let p = Ee(/* @__PURE__ */ new Float32Array(4), f, d);
|
|
8277
|
-
return new
|
|
8655
|
+
return new mo(Array.from({ length: 64 }, (e, t) => {
|
|
8278
8656
|
let i = t / 64 * Math.PI * 2, a = new z();
|
|
8279
8657
|
return a[n] = Math.cos(i) * c, a[r] = Math.sin(i) * l, a.applyQuaternion(p).add(u);
|
|
8280
8658
|
}), { closed: !0 });
|
|
8281
8659
|
}
|
|
8282
8660
|
// src/registry.js
|
|
8283
|
-
var
|
|
8284
|
-
function
|
|
8285
|
-
|
|
8661
|
+
var _o = /* @__PURE__ */ new Map();
|
|
8662
|
+
function vo(e) {
|
|
8663
|
+
_o.set(e.type, e);
|
|
8286
8664
|
}
|
|
8287
|
-
function
|
|
8288
|
-
return
|
|
8665
|
+
function yo() {
|
|
8666
|
+
return _o;
|
|
8289
8667
|
}
|
|
8290
8668
|
// src/describe.js
|
|
8291
|
-
var
|
|
8669
|
+
var bo = [
|
|
8292
8670
|
"box",
|
|
8293
8671
|
"sphere",
|
|
8294
8672
|
"plane",
|
|
@@ -8299,27 +8677,27 @@ var qa = [
|
|
|
8299
8677
|
"extrude",
|
|
8300
8678
|
"axes",
|
|
8301
8679
|
"grid"
|
|
8302
|
-
],
|
|
8303
|
-
|
|
8680
|
+
], xo = null, So = () => {
|
|
8681
|
+
xo ??= new Map([
|
|
8304
8682
|
K,
|
|
8305
|
-
|
|
8306
|
-
|
|
8307
|
-
|
|
8308
|
-
|
|
8309
|
-
|
|
8310
|
-
|
|
8311
|
-
|
|
8312
|
-
|
|
8313
|
-
|
|
8314
|
-
|
|
8315
|
-
|
|
8316
|
-
|
|
8317
|
-
|
|
8318
|
-
|
|
8683
|
+
St,
|
|
8684
|
+
gr,
|
|
8685
|
+
Nt,
|
|
8686
|
+
zt,
|
|
8687
|
+
Bt,
|
|
8688
|
+
Ht,
|
|
8689
|
+
Ut,
|
|
8690
|
+
jn,
|
|
8691
|
+
Mn,
|
|
8692
|
+
xr,
|
|
8693
|
+
Sr,
|
|
8694
|
+
wr,
|
|
8695
|
+
Tr,
|
|
8696
|
+
Er
|
|
8319
8697
|
].map((e) => [e.type, e]));
|
|
8320
|
-
for (let [e, t] of
|
|
8321
|
-
return
|
|
8322
|
-
},
|
|
8698
|
+
for (let [e, t] of yo()) xo.set(e, t);
|
|
8699
|
+
return xo;
|
|
8700
|
+
}, Co = {
|
|
8323
8701
|
Mesh: "mesh",
|
|
8324
8702
|
Group: "group",
|
|
8325
8703
|
Object3D: "node",
|
|
@@ -8337,10 +8715,10 @@ var qa = [
|
|
|
8337
8715
|
Scene: "scene",
|
|
8338
8716
|
light: "directional-light",
|
|
8339
8717
|
camera: "perspective-camera"
|
|
8340
|
-
},
|
|
8718
|
+
}, wo = {
|
|
8341
8719
|
chart: "import { chart } from 'phoria2/charts' first, which registers 'chart'",
|
|
8342
8720
|
emitter: "'emitter' descriptions aren't supported yet - use new Emitter() from 'phoria2/particles'"
|
|
8343
|
-
},
|
|
8721
|
+
}, To = {
|
|
8344
8722
|
cube: "box",
|
|
8345
8723
|
ball: "sphere",
|
|
8346
8724
|
globe: "sphere",
|
|
@@ -8360,29 +8738,29 @@ var qa = [
|
|
|
8360
8738
|
ExtrudeGeometry: "extrude",
|
|
8361
8739
|
ShapeGeometry: "extrude"
|
|
8362
8740
|
};
|
|
8363
|
-
function
|
|
8741
|
+
function Eo(e) {
|
|
8364
8742
|
if (/Material$/.test(e)) return "materials aren't nodes - give a mesh material: { color, roughness, metalness, ... }";
|
|
8365
|
-
let t =
|
|
8743
|
+
let t = To[e];
|
|
8366
8744
|
return t ? `geometry isn't a node - give a mesh geometry: { type: '${t}', ... }` : null;
|
|
8367
8745
|
}
|
|
8368
|
-
function
|
|
8746
|
+
function Do(e) {
|
|
8369
8747
|
if (e instanceof K) return e;
|
|
8370
8748
|
(!e || typeof e != "object" || Array.isArray(e)) && E("create()", `expected a description such as { type: 'mesh', ... }, got ${j(e)}`);
|
|
8371
8749
|
let { type: t, ...n } = e;
|
|
8372
|
-
typeof t != "string" && E("create()", `a description needs a 'type': one of ${[...
|
|
8373
|
-
let r =
|
|
8750
|
+
typeof t != "string" && E("create()", `a description needs a 'type': one of ${[...So().keys()].join(", ")}`);
|
|
8751
|
+
let r = So().get(t);
|
|
8374
8752
|
if (!r) {
|
|
8375
|
-
let e =
|
|
8376
|
-
E("create()", `unknown type '${t}' - ${e ? `use '${e}'` : n ?? `expected one of ${[...
|
|
8753
|
+
let e = Co[t], n = Eo(t) ?? wo[t];
|
|
8754
|
+
E("create()", `unknown type '${t}' - ${e ? `use '${e}'` : n ?? `expected one of ${[...So().keys()].join(", ")}${k(t, So().keys())}`}`);
|
|
8377
8755
|
}
|
|
8378
|
-
return Array.isArray(n.children) && (n.children = n.children.map((e) =>
|
|
8756
|
+
return Array.isArray(n.children) && (n.children = n.children.map((e) => Do(e))), n.geometry && !(n.geometry instanceof U) && typeof n.geometry == "object" && "type" in n.geometry && (n.geometry = Oo(n.geometry, `create({ type: '${t}' })`)), new r(n);
|
|
8379
8757
|
}
|
|
8380
|
-
function
|
|
8381
|
-
let { type: n, ...r } = e, i =
|
|
8382
|
-
i && E(t, `geometry type '${n}' - use '${i}'`), P(t, "geometry.type", n,
|
|
8383
|
-
let a =
|
|
8758
|
+
function Oo(e, t = "createGeometry()") {
|
|
8759
|
+
let { type: n, ...r } = e, i = To[n];
|
|
8760
|
+
i && E(t, `geometry type '${n}' - use '${i}'`), P(t, "geometry.type", n, bo);
|
|
8761
|
+
let a = Ca[n];
|
|
8384
8762
|
return a(Object.keys(r).length ? r : void 0);
|
|
8385
8763
|
}
|
|
8386
|
-
export {
|
|
8764
|
+
export { Kt as $, Vr as A, M as At, gr as B, a as Bt, ti as C, se as Ct, Nr as D, B as Dt, Mr as E, V as Et, wr as F, E as Ft, Pn as G, ir as H, Sr as I, F as It, Mn as J, In as K, br as L, x as Lt, zr as M, A as Mt, Ir as N, j as Nt, Pr as O, z as Ot, xr as P, k as Pt, rn as Q, Tr as R, r as Rt, ei as S, H as St, Or as T, ae as Tt, Kn as U, hr as V, s as Vt, Vn as W, Cn as X, jn as Y, Gt as Z, Oa as _, Oe as _t, go as a, Bt as at, zi as b, Te as bt, Ba as c, G as ct, za as d, W as dt, Mt as et, Fa as f, We as ft, ka as g, De as gt, Pa as h, je as ht, ho as i, Nt as it, Lr as j, P as jt, Fr as k, T as kt, Ea as l, K as lt, Na as m, Ne as mt, vo as n, Ut as nt, io as o, Rt as ot, Va as p, U as pt, An as q, mo as r, Ht as rt, eo as s, St as st, Do as t, zt as tt, Aa as u, rt as ut, Ma as v, Ee as vt, ni as w, ne as wt, mi as x, Se as xt, Qi as y, Ae as yt, Er as z, o as zt };
|
|
8387
8765
|
|
|
8388
8766
|
//# sourceMappingURL=core.js.map
|