phoria2 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +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 +1223 -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 +88 -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,39 @@ 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
|
+
#endif
|
|
4488
|
+
#ifdef ALPHA_TEST
|
|
4388
4489
|
uniform float uOpacity;
|
|
4389
4490
|
uniform float uAlphaTest;
|
|
4390
4491
|
#ifdef MAP
|
|
4391
4492
|
uniform sampler2D uMap;
|
|
4392
|
-
${
|
|
4493
|
+
${jr}
|
|
4393
4494
|
#endif
|
|
4394
4495
|
#endif
|
|
4395
|
-
${
|
|
4496
|
+
${Or}
|
|
4396
4497
|
void main() {
|
|
4397
4498
|
clipAway(vWorldPosition);
|
|
4499
|
+
#ifdef HOOK_FRAGMENT
|
|
4500
|
+
{
|
|
4501
|
+
vec4 base = vec4(vColor, 1.0);
|
|
4502
|
+
vec3 emissive = vec3(0.0);
|
|
4503
|
+
vec3 normal = normalize(vNormal);
|
|
4504
|
+
if (base.a <= 0.0) discard;
|
|
4505
|
+
}
|
|
4506
|
+
#endif
|
|
4398
4507
|
#ifdef ALPHA_TEST
|
|
4399
4508
|
float alpha = uOpacity;
|
|
4400
4509
|
#ifdef MAP
|
|
@@ -4404,7 +4513,7 @@ if (alpha < uAlphaTest) discard;
|
|
|
4404
4513
|
#endif
|
|
4405
4514
|
fragColor = vec4(1.0);
|
|
4406
4515
|
}
|
|
4407
|
-
`,
|
|
4516
|
+
`, 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
4517
|
layout(location = 1) in vec3 normal;
|
|
4409
4518
|
layout(location = 2) in vec2 uv;
|
|
4410
4519
|
layout(location = 3) in vec3 color;
|
|
@@ -4441,27 +4550,34 @@ out mat3 vObjectToWorld;
|
|
|
4441
4550
|
#ifdef PICK
|
|
4442
4551
|
flat out uint vPickElement;
|
|
4443
4552
|
#endif
|
|
4444
|
-
${
|
|
4553
|
+
${Nr}
|
|
4445
4554
|
void main() {
|
|
4446
4555
|
vColor = vec3(1.0);
|
|
4447
4556
|
vHighlight = uHighlightIndex == -1 ? 1.0 : 0.0;
|
|
4557
|
+
vec3 local = position;
|
|
4558
|
+
vec3 n = normal;
|
|
4559
|
+
#ifdef HOOK_VERTEX
|
|
4560
|
+
{
|
|
4561
|
+
int index = gl_InstanceID;
|
|
4562
|
+
}
|
|
4563
|
+
#endif
|
|
4448
4564
|
#ifdef INSTANCED
|
|
4449
|
-
vec4
|
|
4565
|
+
vec4 placed = instanceMatrix * vec4(local, 1.0);
|
|
4450
4566
|
mat3 m = mat3(instanceMatrix);
|
|
4451
4567
|
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
|
|
4568
|
+
vec3 placedNormal = instanceNormal * n;
|
|
4453
4569
|
vColor *= instanceColor;
|
|
4454
4570
|
if (gl_InstanceID == uHighlightIndex) vHighlight = 1.0;
|
|
4455
4571
|
#else
|
|
4456
|
-
vec4
|
|
4457
|
-
vec3
|
|
4572
|
+
vec4 placed = vec4(local, 1.0);
|
|
4573
|
+
vec3 placedNormal = n;
|
|
4458
4574
|
#endif
|
|
4459
4575
|
#ifdef VERTEX_COLORS
|
|
4460
4576
|
vColor *= srgbToLinear(color);
|
|
4461
4577
|
#endif
|
|
4462
|
-
vec4 world = uModel *
|
|
4578
|
+
vec4 world = uModel * placed;
|
|
4463
4579
|
vWorldPosition = world.xyz;
|
|
4464
|
-
vNormal = uNormalMatrix *
|
|
4580
|
+
vNormal = uNormalMatrix * placedNormal;
|
|
4465
4581
|
vUv = uv;
|
|
4466
4582
|
#ifdef UV2
|
|
4467
4583
|
vUv2 = uv2;
|
|
@@ -4474,8 +4590,8 @@ vTangent = vec4(mat3(uModel) * tangent.xyz, tangent.w);
|
|
|
4474
4590
|
#endif
|
|
4475
4591
|
#endif
|
|
4476
4592
|
#ifdef TRIPLANAR
|
|
4477
|
-
vObjectPosition =
|
|
4478
|
-
vObjectNormal =
|
|
4593
|
+
vObjectPosition = local;
|
|
4594
|
+
vObjectNormal = n;
|
|
4479
4595
|
#ifdef INSTANCED
|
|
4480
4596
|
vObjectToWorld = uNormalMatrix * instanceNormal;
|
|
4481
4597
|
#else
|
|
@@ -4490,7 +4606,7 @@ vFogDepth = -(uView * world).z;
|
|
|
4490
4606
|
vPickElement = uint(gl_InstanceID);
|
|
4491
4607
|
#endif
|
|
4492
4608
|
}
|
|
4493
|
-
`,
|
|
4609
|
+
`, Rr = `precision highp float;
|
|
4494
4610
|
precision highp sampler2DShadow;
|
|
4495
4611
|
precision highp samplerCubeShadow;
|
|
4496
4612
|
in vec3 vWorldPosition;
|
|
@@ -4511,7 +4627,7 @@ uniform float uAlphaTest;
|
|
|
4511
4627
|
#ifdef EMISSIVE_MAP
|
|
4512
4628
|
uniform sampler2D uEmissiveMap;
|
|
4513
4629
|
#endif
|
|
4514
|
-
${
|
|
4630
|
+
${jr}
|
|
4515
4631
|
#ifdef LIT
|
|
4516
4632
|
uniform vec3 uCameraPosition;
|
|
4517
4633
|
uniform float uRoughness;
|
|
@@ -4609,10 +4725,10 @@ uniform float uPointShadowBias;
|
|
|
4609
4725
|
#endif
|
|
4610
4726
|
#endif
|
|
4611
4727
|
out vec4 fragColor;
|
|
4612
|
-
${
|
|
4613
|
-
${
|
|
4614
|
-
${Sr}
|
|
4728
|
+
${Nr}
|
|
4729
|
+
${Or}
|
|
4615
4730
|
${kr}
|
|
4731
|
+
${Ir}
|
|
4616
4732
|
#ifdef LIT
|
|
4617
4733
|
const float PI = 3.14159265359;
|
|
4618
4734
|
float D_GGX(float NoH, float a) {
|
|
@@ -4721,7 +4837,7 @@ vec2 ab = vec2(-1.04, 1.04) * a004 + r.zw;
|
|
|
4721
4837
|
return f0 * ab.x + ab.y * f90;
|
|
4722
4838
|
}
|
|
4723
4839
|
#ifdef ENV_MAP
|
|
4724
|
-
${
|
|
4840
|
+
${Pr}
|
|
4725
4841
|
vec3 envIrradiance(vec3 n) {
|
|
4726
4842
|
return uEnvSH[0]
|
|
4727
4843
|
+ uEnvSH[1] * n.y + uEnvSH[2] * n.z + uEnvSH[3] * n.x
|
|
@@ -4854,22 +4970,36 @@ vec4 base = vec4(uColor * vColor, uOpacity);
|
|
|
4854
4970
|
#ifdef MAP
|
|
4855
4971
|
base *= uMapTexel;
|
|
4856
4972
|
#endif
|
|
4973
|
+
vec3 emissive = uEmissive;
|
|
4974
|
+
#ifdef EMISSIVE_MAP
|
|
4975
|
+
emissive *= uEmissiveMapTexel.rgb;
|
|
4976
|
+
#endif
|
|
4977
|
+
#ifdef HOOK_FRAGMENT
|
|
4978
|
+
#ifdef FLAT_SHADING
|
|
4979
|
+
vec3 normal = normalize(cross(dFdx(vWorldPosition), dFdy(vWorldPosition)));
|
|
4980
|
+
#else
|
|
4981
|
+
vec3 normal = normalize(vNormal);
|
|
4982
|
+
#ifdef DOUBLE_SIDED
|
|
4983
|
+
if (!gl_FrontFacing) normal = -normal;
|
|
4984
|
+
#endif
|
|
4985
|
+
#endif
|
|
4986
|
+
{
|
|
4987
|
+
}
|
|
4988
|
+
#endif
|
|
4857
4989
|
#ifdef ALPHA_TEST
|
|
4858
4990
|
if (base.a < uAlphaTest) discard;
|
|
4859
4991
|
base.a = 1.0;
|
|
4860
4992
|
#endif
|
|
4861
4993
|
float coverage = base.a;
|
|
4862
|
-
vec3 emissive = uEmissive;
|
|
4863
|
-
#ifdef EMISSIVE_MAP
|
|
4864
|
-
emissive *= uEmissiveMapTexel.rgb;
|
|
4865
|
-
#endif
|
|
4866
4994
|
#ifdef LIT
|
|
4867
|
-
#ifdef
|
|
4995
|
+
#ifdef HOOK_FRAGMENT
|
|
4996
|
+
vec3 n = normalize(normal);
|
|
4997
|
+
#elif defined(FLAT_SHADING)
|
|
4868
4998
|
vec3 n = normalize(cross(dFdx(vWorldPosition), dFdy(vWorldPosition)));
|
|
4869
4999
|
#else
|
|
4870
5000
|
vec3 n = normalize(vNormal);
|
|
4871
5001
|
#endif
|
|
4872
|
-
#if defined(DOUBLE_SIDED) && !defined(FLAT_SHADING)
|
|
5002
|
+
#if defined(DOUBLE_SIDED) && !defined(FLAT_SHADING) && !defined(HOOK_FRAGMENT)
|
|
4873
5003
|
if (!gl_FrontFacing) n = -n;
|
|
4874
5004
|
#endif
|
|
4875
5005
|
vec3 surfaceNormal = n;
|
|
@@ -5042,12 +5172,18 @@ color = toneMap(color);
|
|
|
5042
5172
|
#else
|
|
5043
5173
|
vec3 color = base.rgb + emissive;
|
|
5044
5174
|
#endif
|
|
5175
|
+
#ifdef HOOK_LIT
|
|
5176
|
+
{
|
|
5177
|
+
float before = max(base.a, 1e-5);
|
|
5178
|
+
coverage *= clamp(base.a / before, 0.0, 1.0);
|
|
5179
|
+
}
|
|
5180
|
+
#endif
|
|
5045
5181
|
color = mix(color, uHighlight.rgb, vHighlight * uHighlight.a);
|
|
5046
5182
|
coverage = mix(coverage, base.a, vHighlight * uHighlight.a);
|
|
5047
5183
|
color = fogged(color);
|
|
5048
5184
|
fragColor = vec4(linearToSrgb(color) * base.a, coverage);
|
|
5049
5185
|
}
|
|
5050
|
-
`,
|
|
5186
|
+
`, zr = `layout(location = 0) in vec3 position;
|
|
5051
5187
|
layout(location = 3) in vec3 color;
|
|
5052
5188
|
#ifdef SPRITES
|
|
5053
5189
|
layout(location = 4) in vec2 corner;
|
|
@@ -5067,33 +5203,50 @@ uniform float uScale;
|
|
|
5067
5203
|
uniform int uHighlightIndex;
|
|
5068
5204
|
out vec3 vColor;
|
|
5069
5205
|
flat out float vHighlight;
|
|
5206
|
+
#ifdef HOOK_FRAGMENT
|
|
5207
|
+
flat out float vPointIndex;
|
|
5208
|
+
#endif
|
|
5070
5209
|
#ifdef PICK
|
|
5071
5210
|
flat out uint vPickElement;
|
|
5072
5211
|
#endif
|
|
5073
5212
|
#ifdef FOG
|
|
5074
5213
|
out float vFogDepth;
|
|
5075
5214
|
#endif
|
|
5076
|
-
${
|
|
5215
|
+
${Nr}
|
|
5077
5216
|
void main() {
|
|
5078
|
-
|
|
5217
|
+
vec3 local = position;
|
|
5218
|
+
#ifdef SPRITES
|
|
5219
|
+
int self = int(pointIndex + 0.5);
|
|
5220
|
+
float size = pointSize;
|
|
5221
|
+
#else
|
|
5222
|
+
int self = gl_VertexID;
|
|
5223
|
+
float size = 1.0;
|
|
5224
|
+
#endif
|
|
5225
|
+
#ifdef HOOK_VERTEX
|
|
5226
|
+
{
|
|
5227
|
+
int index = self;
|
|
5228
|
+
}
|
|
5229
|
+
#endif
|
|
5230
|
+
#ifdef HOOK_FRAGMENT
|
|
5231
|
+
vPointIndex = float(self);
|
|
5232
|
+
#endif
|
|
5233
|
+
vec4 viewPosition = uView * (uModel * vec4(local, 1.0));
|
|
5079
5234
|
#ifdef SPRITES
|
|
5080
5235
|
vec2 c = vec2(corner.x * 2.0 - 1.0, corner.y);
|
|
5081
5236
|
float s = sin(pointAngle), k = cos(pointAngle);
|
|
5082
5237
|
vec2 turned = vec2(c.x * k - c.y * s, c.x * s + c.y * k);
|
|
5083
|
-
float
|
|
5238
|
+
float across = uSize * size;
|
|
5084
5239
|
#ifdef SIZE_ATTENUATION
|
|
5085
|
-
viewPosition.xy += turned *
|
|
5240
|
+
viewPosition.xy += turned * across * 0.5;
|
|
5086
5241
|
gl_Position = uProjection * viewPosition;
|
|
5087
5242
|
#else
|
|
5088
5243
|
gl_Position = uProjection * viewPosition;
|
|
5089
|
-
gl_Position.xy += turned *
|
|
5244
|
+
gl_Position.xy += turned * across / uResolution * gl_Position.w;
|
|
5090
5245
|
#endif
|
|
5091
5246
|
vUv = vec2(c.x * 0.5 + 0.5, 0.5 - c.y * 0.5);
|
|
5092
5247
|
vOpacity = pointOpacity;
|
|
5093
|
-
int self = int(pointIndex + 0.5);
|
|
5094
5248
|
#else
|
|
5095
5249
|
gl_Position = uProjection * viewPosition;
|
|
5096
|
-
int self = gl_VertexID;
|
|
5097
5250
|
#endif
|
|
5098
5251
|
#ifdef FOG
|
|
5099
5252
|
vFogDepth = -viewPosition.z;
|
|
@@ -5101,9 +5254,9 @@ vFogDepth = -viewPosition.z;
|
|
|
5101
5254
|
#ifdef SPRITES
|
|
5102
5255
|
#elif defined(SIZE_ATTENUATION)
|
|
5103
5256
|
float depth = uProjection[3][3] == 1.0 ? 1.0 : max(-viewPosition.z, 1e-4);
|
|
5104
|
-
gl_PointSize = uSize * uScale / depth;
|
|
5257
|
+
gl_PointSize = uSize * size * uScale / depth;
|
|
5105
5258
|
#else
|
|
5106
|
-
gl_PointSize = uSize;
|
|
5259
|
+
gl_PointSize = uSize * size;
|
|
5107
5260
|
#endif
|
|
5108
5261
|
vColor = vec3(1.0);
|
|
5109
5262
|
#ifdef VERTEX_COLORS
|
|
@@ -5114,7 +5267,7 @@ vHighlight = uHighlightIndex == -1 || self == uHighlightIndex ? 1.0 : 0.0;
|
|
|
5114
5267
|
vPickElement = uint(self);
|
|
5115
5268
|
#endif
|
|
5116
5269
|
}
|
|
5117
|
-
`,
|
|
5270
|
+
`, Br = `precision highp float;
|
|
5118
5271
|
in vec3 vColor;
|
|
5119
5272
|
flat in float vHighlight;
|
|
5120
5273
|
#ifdef SPRITES
|
|
@@ -5127,9 +5280,12 @@ uniform float uOpacity;
|
|
|
5127
5280
|
#ifdef MAP
|
|
5128
5281
|
uniform sampler2D uMap;
|
|
5129
5282
|
#endif
|
|
5283
|
+
#ifdef HOOK_FRAGMENT
|
|
5284
|
+
flat in float vPointIndex;
|
|
5285
|
+
#endif
|
|
5130
5286
|
out vec4 fragColor;
|
|
5131
|
-
${
|
|
5132
|
-
${
|
|
5287
|
+
${Nr}
|
|
5288
|
+
${kr}
|
|
5133
5289
|
void main() {
|
|
5134
5290
|
#ifdef SPRITES
|
|
5135
5291
|
vec2 at = vUv;
|
|
@@ -5146,11 +5302,21 @@ float r = dot(p, p);
|
|
|
5146
5302
|
float edge = fwidth(r);
|
|
5147
5303
|
base.a *= 1.0 - smoothstep(1.0 - edge, 1.0, r);
|
|
5148
5304
|
#endif
|
|
5305
|
+
#ifdef HOOK_FRAGMENT
|
|
5306
|
+
{
|
|
5307
|
+
vec2 pointUv = at;
|
|
5308
|
+
int index = int(vPointIndex + 0.5);
|
|
5309
|
+
}
|
|
5310
|
+
#endif
|
|
5149
5311
|
if (base.a <= 0.0) discard;
|
|
5150
|
-
|
|
5151
|
-
|
|
5312
|
+
vec3 color = fogged(mix(base.rgb, uHighlight.rgb, vHighlight * uHighlight.a));
|
|
5313
|
+
#ifdef HOOK_LIT
|
|
5314
|
+
{
|
|
5315
|
+
}
|
|
5316
|
+
#endif
|
|
5317
|
+
fragColor = vec4(linearToSrgb(color) * base.a, base.a);
|
|
5152
5318
|
}
|
|
5153
|
-
`,
|
|
5319
|
+
`, Vr = `layout(location = 0) in vec3 segmentStart;
|
|
5154
5320
|
layout(location = 1) in vec3 segmentEnd;
|
|
5155
5321
|
layout(location = 2) in vec3 segmentColorStart;
|
|
5156
5322
|
layout(location = 3) in vec3 segmentColorEnd;
|
|
@@ -5165,8 +5331,13 @@ uniform int uArrows;
|
|
|
5165
5331
|
uniform float uArrowSize;
|
|
5166
5332
|
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
5333
|
out vec3 vColor;
|
|
5168
|
-
#
|
|
5334
|
+
#if defined(DASHED) || defined(HOOK_FRAGMENT)
|
|
5169
5335
|
out float vDistance;
|
|
5336
|
+
#endif
|
|
5337
|
+
#ifdef HOOK_FRAGMENT
|
|
5338
|
+
flat out float vSegment;
|
|
5339
|
+
#endif
|
|
5340
|
+
#ifdef DASHED
|
|
5170
5341
|
flat out float vArrow;
|
|
5171
5342
|
#endif
|
|
5172
5343
|
#ifdef PICK
|
|
@@ -5175,10 +5346,20 @@ flat out uint vPickElement;
|
|
|
5175
5346
|
#ifdef FOG
|
|
5176
5347
|
out float vFogDepth;
|
|
5177
5348
|
#endif
|
|
5178
|
-
${
|
|
5349
|
+
${Nr}
|
|
5350
|
+
#ifdef HOOK_VERTEX
|
|
5351
|
+
vec3 hookVertex(vec3 local, float along, int index) {
|
|
5352
|
+
return local;
|
|
5353
|
+
}
|
|
5354
|
+
#endif
|
|
5179
5355
|
void main() {
|
|
5180
|
-
|
|
5181
|
-
|
|
5356
|
+
vec3 start = segmentStart, end = segmentEnd;
|
|
5357
|
+
#ifdef HOOK_VERTEX
|
|
5358
|
+
start = hookVertex(segmentStart, 0.0, gl_InstanceID);
|
|
5359
|
+
end = hookVertex(segmentEnd, 1.0, gl_InstanceID);
|
|
5360
|
+
#endif
|
|
5361
|
+
vec4 a = uView * (uModel * vec4(start, 1.0));
|
|
5362
|
+
vec4 b = uView * (uModel * vec4(end, 1.0));
|
|
5182
5363
|
float clipZ = -uNear;
|
|
5183
5364
|
if (a.z > clipZ && b.z > clipZ) {
|
|
5184
5365
|
gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
@@ -5222,8 +5403,13 @@ vFogDepth = -mix(a.z, b.z, along);
|
|
|
5222
5403
|
#endif
|
|
5223
5404
|
clip.xy += offset / (uResolution * 0.5) * clip.w;
|
|
5224
5405
|
gl_Position = clip;
|
|
5406
|
+
#if defined(DASHED) || defined(HOOK_FRAGMENT)
|
|
5407
|
+
vDistance = segmentInfo.x + length(end - start) * along;
|
|
5408
|
+
#endif
|
|
5409
|
+
#ifdef HOOK_FRAGMENT
|
|
5410
|
+
vSegment = float(gl_InstanceID);
|
|
5411
|
+
#endif
|
|
5225
5412
|
#ifdef DASHED
|
|
5226
|
-
vDistance = segmentInfo.x + length(segmentEnd - segmentStart) * along;
|
|
5227
5413
|
vArrow = arrow;
|
|
5228
5414
|
#endif
|
|
5229
5415
|
#ifdef PICK
|
|
@@ -5234,38 +5420,140 @@ vColor = vec3(1.0);
|
|
|
5234
5420
|
vColor = srgbToLinear(mix(segmentColorStart, segmentColorEnd, along));
|
|
5235
5421
|
#endif
|
|
5236
5422
|
}
|
|
5237
|
-
`,
|
|
5423
|
+
`, Hr = `precision highp float;
|
|
5238
5424
|
in vec3 vColor;
|
|
5239
5425
|
uniform vec3 uColor;
|
|
5240
5426
|
uniform float uOpacity;
|
|
5241
|
-
#
|
|
5427
|
+
#if defined(DASHED) || defined(HOOK_FRAGMENT)
|
|
5242
5428
|
in float vDistance;
|
|
5429
|
+
#endif
|
|
5430
|
+
#ifdef HOOK_FRAGMENT
|
|
5431
|
+
flat in float vSegment;
|
|
5432
|
+
#endif
|
|
5433
|
+
#ifdef DASHED
|
|
5243
5434
|
flat in float vArrow;
|
|
5244
5435
|
uniform float uDash;
|
|
5245
5436
|
uniform float uGap;
|
|
5246
5437
|
uniform float uDashOffset;
|
|
5247
5438
|
#endif
|
|
5248
5439
|
out vec4 fragColor;
|
|
5249
|
-
${
|
|
5250
|
-
${
|
|
5440
|
+
${Nr}
|
|
5441
|
+
${kr}
|
|
5251
5442
|
void main() {
|
|
5252
5443
|
#ifdef DASHED
|
|
5253
5444
|
if (vArrow < 0.5 && mod(vDistance - uDashOffset, uDash + uGap) >= uDash) discard;
|
|
5254
5445
|
#endif
|
|
5255
|
-
|
|
5256
|
-
|
|
5446
|
+
vec4 base = vec4(uColor * vColor, uOpacity);
|
|
5447
|
+
#ifdef HOOK_FRAGMENT
|
|
5448
|
+
{
|
|
5449
|
+
float distance = vDistance;
|
|
5450
|
+
int index = int(vSegment + 0.5);
|
|
5257
5451
|
}
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5452
|
+
if (base.a <= 0.0) discard;
|
|
5453
|
+
#endif
|
|
5454
|
+
vec3 color = fogged(base.rgb);
|
|
5455
|
+
#ifdef HOOK_LIT
|
|
5456
|
+
{
|
|
5457
|
+
}
|
|
5458
|
+
#endif
|
|
5459
|
+
fragColor = vec4(linearToSrgb(color) * base.a, base.a);
|
|
5460
|
+
}
|
|
5461
|
+
`, Ur = {
|
|
5462
|
+
mesh: [Lr, Rr],
|
|
5463
|
+
points: [zr, Br],
|
|
5464
|
+
lines: [Vr, Hr]
|
|
5465
|
+
}, 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 = {
|
|
5466
|
+
vertex: 101,
|
|
5467
|
+
fragment: 102,
|
|
5468
|
+
lit: 103
|
|
5262
5469
|
};
|
|
5263
|
-
function
|
|
5264
|
-
let
|
|
5265
|
-
return [
|
|
5470
|
+
function Kr(e, t, n = null) {
|
|
5471
|
+
let r = `#version 300 es\n${t.map((e) => `#define ${e}\n`).join("")}`, [i, a] = typeof e == "string" ? Ur[e] : e;
|
|
5472
|
+
if (!n) return [r + i, r + a];
|
|
5473
|
+
let o = 2 + t.length;
|
|
5474
|
+
return [r + qr(i, n, o), r + qr(a, n, o)];
|
|
5475
|
+
}
|
|
5476
|
+
function qr(e, t, n) {
|
|
5477
|
+
return e.split("\n").map((e, r) => {
|
|
5478
|
+
let i = /^\s*\/\/@hook (\w+)$/.exec(e);
|
|
5479
|
+
if (!i) return e;
|
|
5480
|
+
let a = i[1], o = `#line ${n + r + 1} 0`;
|
|
5481
|
+
return a === "uniforms" ? `${t.uniforms}\n${t.helpers ?? ""}\n${o}` : `#line 1 ${Gr[a]}\n${t[a]}\n${o}`;
|
|
5482
|
+
}).join("\n");
|
|
5483
|
+
}
|
|
5484
|
+
// src/webgl/hooks.js
|
|
5485
|
+
var Jr = /* @__PURE__ */ new Map(), Yr = /* @__PURE__ */ new Set(), Xr = /* @__PURE__ */ new WeakMap();
|
|
5486
|
+
function Zr(e) {
|
|
5487
|
+
return typeof e == "number" ? "float" : e instanceof W ? "sampler2D" : `vec${e.length}`;
|
|
5488
|
+
}
|
|
5489
|
+
var Qr = null, $r = () => Qr ??= new Set([
|
|
5490
|
+
Lr,
|
|
5491
|
+
zr,
|
|
5492
|
+
Vr,
|
|
5493
|
+
Mr,
|
|
5494
|
+
...[
|
|
5495
|
+
"mesh",
|
|
5496
|
+
"points",
|
|
5497
|
+
"lines"
|
|
5498
|
+
].flatMap((e) => Kr(e, []))
|
|
5499
|
+
].flatMap((e) => [...e.matchAll(/uniform\s+\w+\s+(\w+)/g)].map((e) => e[1])));
|
|
5500
|
+
function ei(e) {
|
|
5501
|
+
let t = e.shader;
|
|
5502
|
+
if (!t) return null;
|
|
5503
|
+
let n = Object.entries(t.uniforms).map(([e, t]) => `${Zr(t)} ${e}`).join(";"), r = Xr.get(t);
|
|
5504
|
+
if (r && r.types === n) return r.hook;
|
|
5505
|
+
let i = JSON.stringify([
|
|
5506
|
+
t.vertex,
|
|
5507
|
+
t.fragment,
|
|
5508
|
+
t.lit,
|
|
5509
|
+
n
|
|
5510
|
+
]), a = Yr.has(i) ? null : Jr.get(i) ?? null;
|
|
5511
|
+
if (!a && !Yr.has(i)) {
|
|
5512
|
+
let r = Object.keys(t.uniforms).find((e) => $r().has(e));
|
|
5513
|
+
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 = {
|
|
5514
|
+
signature: i,
|
|
5515
|
+
defines: [
|
|
5516
|
+
...t.vertex ? ["HOOK_VERTEX"] : [],
|
|
5517
|
+
...t.fragment ? ["HOOK_FRAGMENT"] : [],
|
|
5518
|
+
...t.lit ? ["HOOK_LIT"] : [],
|
|
5519
|
+
`HOOKS ${Jr.size + 1}`
|
|
5520
|
+
],
|
|
5521
|
+
source: {
|
|
5522
|
+
uniforms: [
|
|
5523
|
+
"uniform float uTime;",
|
|
5524
|
+
"uniform vec3 cameraPosition;",
|
|
5525
|
+
...n.split(";").filter(Boolean).map((e) => `uniform ${e};`)
|
|
5526
|
+
].join("\n"),
|
|
5527
|
+
helpers: Wr,
|
|
5528
|
+
vertex: t.vertex,
|
|
5529
|
+
fragment: t.fragment,
|
|
5530
|
+
lit: t.lit
|
|
5531
|
+
},
|
|
5532
|
+
moves: !!t.vertex
|
|
5533
|
+
}, Jr.set(i, a));
|
|
5534
|
+
}
|
|
5535
|
+
return Xr.set(t, {
|
|
5536
|
+
types: n,
|
|
5537
|
+
hook: a
|
|
5538
|
+
}), a;
|
|
5266
5539
|
}
|
|
5267
|
-
|
|
5268
|
-
|
|
5540
|
+
function ti(e, t) {
|
|
5541
|
+
return e.defines.filter((e) => e !== "HOOK_LIT" && (t || e !== "HOOK_FRAGMENT"));
|
|
5542
|
+
}
|
|
5543
|
+
function ni(e, t, n, r, i) {
|
|
5544
|
+
e.set("uTime", n), e.set("cameraPosition", r);
|
|
5545
|
+
let a = t.shader.uniforms;
|
|
5546
|
+
for (let t in a) {
|
|
5547
|
+
let n = a[t];
|
|
5548
|
+
e.set(t, n instanceof W ? i(n) : n);
|
|
5549
|
+
}
|
|
5550
|
+
}
|
|
5551
|
+
function ri(e, t, n) {
|
|
5552
|
+
Yr.add(t.signature), Xr.delete(e.shader);
|
|
5553
|
+
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);
|
|
5554
|
+
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`);
|
|
5555
|
+
}
|
|
5556
|
+
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
5557
|
#e = /* @__PURE__ */ new Map();
|
|
5270
5558
|
#t;
|
|
5271
5559
|
#n = null;
|
|
@@ -5280,13 +5568,13 @@ var Rr = class {
|
|
|
5280
5568
|
for (let t of this.#e.values()) !t.ready && !this.isReady(t) && e++;
|
|
5281
5569
|
return e;
|
|
5282
5570
|
}
|
|
5283
|
-
get(e, t, n) {
|
|
5284
|
-
let
|
|
5285
|
-
return
|
|
5571
|
+
get(e, t, n, r = null) {
|
|
5572
|
+
let i = `${e}|${t.join(",")}`, a = this.#e.get(i);
|
|
5573
|
+
return a || (a = this.#r(i, Kr(n ?? e, t, r), !!r), this.#e.set(i, a)), a;
|
|
5286
5574
|
}
|
|
5287
|
-
ready(e, t, n) {
|
|
5288
|
-
let
|
|
5289
|
-
return
|
|
5575
|
+
ready(e, t, n, r = null) {
|
|
5576
|
+
let i = this.get(e, t, n, r);
|
|
5577
|
+
return i.ready || this.#i(i), i;
|
|
5290
5578
|
}
|
|
5291
5579
|
isReady(e) {
|
|
5292
5580
|
return e.ready ? !0 : this.#t && !this.gl.getProgramParameter(e.program, 37297) ? !1 : (this.#i(e), !0);
|
|
@@ -5302,38 +5590,45 @@ var Rr = class {
|
|
|
5302
5590
|
for (let e of this.#e.values()) this.gl.deleteProgram(e.program);
|
|
5303
5591
|
this.#e.clear(), this.#n && this.gl.deleteVertexArray(this.#n), this.#n = null;
|
|
5304
5592
|
}
|
|
5305
|
-
#r(e, t) {
|
|
5306
|
-
let
|
|
5307
|
-
let
|
|
5308
|
-
return
|
|
5309
|
-
},
|
|
5310
|
-
|
|
5311
|
-
let
|
|
5312
|
-
program:
|
|
5593
|
+
#r(e, t, n = !1) {
|
|
5594
|
+
let r = this.gl, i = (e, t) => {
|
|
5595
|
+
let n = r.createShader(e);
|
|
5596
|
+
return r.shaderSource(n, t), r.compileShader(n), n;
|
|
5597
|
+
}, a = r.createProgram(), o = i(r.VERTEX_SHADER, t[0]), s = i(r.FRAGMENT_SHADER, t[1]);
|
|
5598
|
+
r.attachShader(a, o), r.attachShader(a, s), r.linkProgram(a);
|
|
5599
|
+
let c = {
|
|
5600
|
+
program: a,
|
|
5313
5601
|
key: e,
|
|
5314
5602
|
frame: -1,
|
|
5315
5603
|
ready: !1,
|
|
5316
5604
|
set() {},
|
|
5317
|
-
shaders: [
|
|
5318
|
-
sources: t
|
|
5605
|
+
shaders: [o, s],
|
|
5606
|
+
sources: t,
|
|
5607
|
+
hooked: n
|
|
5319
5608
|
};
|
|
5320
|
-
return this.#t || this.#i(
|
|
5609
|
+
return this.#t || this.#i(c), c;
|
|
5321
5610
|
}
|
|
5322
5611
|
#i(e) {
|
|
5323
5612
|
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
|
-
|
|
5613
|
+
if (!t.getProgramParameter(n, t.LINK_STATUS) && !t.isContextLost()) {
|
|
5614
|
+
if (e.hooked) {
|
|
5615
|
+
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;
|
|
5616
|
+
return;
|
|
5617
|
+
}
|
|
5618
|
+
throw i.forEach((e, n) => {
|
|
5619
|
+
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])}`);
|
|
5620
|
+
}), Error(`phoria2: shader program '${r}' failed to link: ${t.getProgramInfoLog(n)}`);
|
|
5621
|
+
}
|
|
5327
5622
|
for (let e of i) t.deleteShader(e);
|
|
5328
5623
|
let o = /* @__PURE__ */ new Map(), s = t.getProgramParameter(n, t.ACTIVE_UNIFORMS), c = 0;
|
|
5329
5624
|
for (let e = 0; e < s; e++) {
|
|
5330
5625
|
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,
|
|
5626
|
+
o.set(i, oi(t, r.type, a, s ? c++ : 0));
|
|
5332
5627
|
}
|
|
5333
5628
|
e.set = (e, t) => o.get(e)?.(t), e.ready = !0;
|
|
5334
5629
|
}
|
|
5335
5630
|
};
|
|
5336
|
-
function
|
|
5631
|
+
function oi(e, t, n, r) {
|
|
5337
5632
|
switch (t) {
|
|
5338
5633
|
case e.FLOAT: return (t) => typeof t == "number" ? e.uniform1f(n, t) : e.uniform1fv(n, t);
|
|
5339
5634
|
case e.FLOAT_VEC2: return (t) => e.uniform2fv(n, t);
|
|
@@ -5354,8 +5649,8 @@ function zr(e, t, n, r) {
|
|
|
5354
5649
|
default: return () => {};
|
|
5355
5650
|
}
|
|
5356
5651
|
}
|
|
5357
|
-
var
|
|
5358
|
-
function
|
|
5652
|
+
var si = (e) => e.split("\n").map((e, t) => `${String(t + 1).padStart(4)} ${e}`).join("\n"), ci = 15, li = 16, ui = 4;
|
|
5653
|
+
function di(e, t, n, r) {
|
|
5359
5654
|
return [
|
|
5360
5655
|
e.positions.length,
|
|
5361
5656
|
n,
|
|
@@ -5368,7 +5663,7 @@ function Wr(e, t, n, r) {
|
|
|
5368
5663
|
r
|
|
5369
5664
|
].join();
|
|
5370
5665
|
}
|
|
5371
|
-
function
|
|
5666
|
+
function fi(e) {
|
|
5372
5667
|
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
5668
|
if (r) {
|
|
5374
5669
|
let n = e.indices, a = (n ? n.length : i) / 3;
|
|
@@ -5398,12 +5693,12 @@ function Gr(e) {
|
|
|
5398
5693
|
}
|
|
5399
5694
|
return a;
|
|
5400
5695
|
}
|
|
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 =
|
|
5696
|
+
var pi = /* @__PURE__ */ new Float32Array(9);
|
|
5697
|
+
function mi(e) {
|
|
5698
|
+
let t = Math.cos(e.rotation), n = Math.sin(e.rotation), [r, i] = e.repeat, [a, o] = e.center, s = pi;
|
|
5404
5699
|
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
5700
|
}
|
|
5406
|
-
var
|
|
5701
|
+
var hi = new Float32Array([
|
|
5407
5702
|
0,
|
|
5408
5703
|
-1,
|
|
5409
5704
|
0,
|
|
@@ -5412,7 +5707,7 @@ var Jr = new Float32Array([
|
|
|
5412
5707
|
-1,
|
|
5413
5708
|
1,
|
|
5414
5709
|
1
|
|
5415
|
-
]),
|
|
5710
|
+
]), gi = [
|
|
5416
5711
|
[
|
|
5417
5712
|
Z.position,
|
|
5418
5713
|
3,
|
|
@@ -5443,7 +5738,7 @@ var Jr = new Float32Array([
|
|
|
5443
5738
|
1,
|
|
5444
5739
|
9
|
|
5445
5740
|
]
|
|
5446
|
-
],
|
|
5741
|
+
], _i = 10, vi = class {
|
|
5447
5742
|
gl;
|
|
5448
5743
|
#e = /* @__PURE__ */ new WeakMap();
|
|
5449
5744
|
#t = /* @__PURE__ */ new WeakMap();
|
|
@@ -5475,11 +5770,11 @@ var Jr = new Float32Array([
|
|
|
5475
5770
|
this.#d(i);
|
|
5476
5771
|
let a = n ? this.#e : this.#t, o = a.get(i), s = o?.geometry === e;
|
|
5477
5772
|
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 =
|
|
5773
|
+
let c = di(e, t, n, r);
|
|
5479
5774
|
if (o && s && o.layout === c) {
|
|
5480
5775
|
if (o.version !== e.version) {
|
|
5481
5776
|
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,
|
|
5777
|
+
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
5778
|
}
|
|
5484
5779
|
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
5780
|
}
|
|
@@ -5490,7 +5785,7 @@ var Jr = new Float32Array([
|
|
|
5490
5785
|
let i = l.createBuffer();
|
|
5491
5786
|
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
5787
|
}, 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,
|
|
5788
|
+
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
5789
|
let m = null, h = null;
|
|
5495
5790
|
if (t) {
|
|
5496
5791
|
m = l.createBuffer(), l.bindBuffer(l.ARRAY_BUFFER, m), l.bufferData(l.ARRAY_BUFFER, t.instanceMatrices, l.STATIC_DRAW);
|
|
@@ -5573,8 +5868,8 @@ var Jr = new Float32Array([
|
|
|
5573
5868
|
width: 0,
|
|
5574
5869
|
height: 0,
|
|
5575
5870
|
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] =
|
|
5871
|
+
}, 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);
|
|
5872
|
+
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
5873
|
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
5874
|
width: c,
|
|
5580
5875
|
height: l,
|
|
@@ -5582,7 +5877,7 @@ var Jr = new Float32Array([
|
|
|
5582
5877
|
});
|
|
5583
5878
|
else {
|
|
5584
5879
|
let a = e.flipY ? null : e.changedSince(n.version);
|
|
5585
|
-
a && a.length >
|
|
5880
|
+
a && a.length > li && (a = bi(a, c, l));
|
|
5586
5881
|
for (let e of a ?? [{
|
|
5587
5882
|
x: 0,
|
|
5588
5883
|
y: 0,
|
|
@@ -5614,7 +5909,7 @@ var Jr = new Float32Array([
|
|
|
5614
5909
|
let t = e;
|
|
5615
5910
|
if (t.isDrawable) {
|
|
5616
5911
|
n.add(t.geometry), "instanceMatrices" in t && n.add(t);
|
|
5617
|
-
for (let [, e] of t.material.
|
|
5912
|
+
for (let [, e] of t.material.allTextures) n.add(e);
|
|
5618
5913
|
}
|
|
5619
5914
|
});
|
|
5620
5915
|
for (let t of n) {
|
|
@@ -5649,8 +5944,8 @@ var Jr = new Float32Array([
|
|
|
5649
5944
|
let t = n.createVertexArray();
|
|
5650
5945
|
n.bindVertexArray(t);
|
|
5651
5946
|
let i = n.createBuffer();
|
|
5652
|
-
n.bindBuffer(n.ARRAY_BUFFER, i), n.bufferData(n.ARRAY_BUFFER, o *
|
|
5653
|
-
for (let [e, t, r] of
|
|
5947
|
+
n.bindBuffer(n.ARRAY_BUFFER, i), n.bufferData(n.ARRAY_BUFFER, o * _i * 4, n.DYNAMIC_DRAW);
|
|
5948
|
+
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
5949
|
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
5950
|
vao: t,
|
|
5656
5951
|
buffers: [i],
|
|
@@ -5661,15 +5956,15 @@ var Jr = new Float32Array([
|
|
|
5661
5956
|
instanceVersion: 0,
|
|
5662
5957
|
capacity: o,
|
|
5663
5958
|
sorted: !1,
|
|
5664
|
-
data: new Float32Array(o *
|
|
5959
|
+
data: new Float32Array(o * _i)
|
|
5665
5960
|
}, this.#r.set(e, r);
|
|
5666
5961
|
}
|
|
5667
|
-
let s = i ?
|
|
5962
|
+
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
5963
|
for (let e = 0; e < a; e++) {
|
|
5669
|
-
let t = s ? s[e] : e, n = e *
|
|
5964
|
+
let t = s ? s[e] : e, n = e * _i;
|
|
5670
5965
|
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
5966
|
}
|
|
5672
|
-
return n.bindBuffer(n.ARRAY_BUFFER, r.buffers[0]), n.bufferSubData(n.ARRAY_BUFFER, 0, p, 0, a *
|
|
5967
|
+
return n.bindBuffer(n.ARRAY_BUFFER, r.buffers[0]), n.bufferSubData(n.ARRAY_BUFFER, 0, p, 0, a * _i), Object.assign(r, {
|
|
5673
5968
|
count: a,
|
|
5674
5969
|
version: e.version,
|
|
5675
5970
|
sorted: i
|
|
@@ -5699,7 +5994,7 @@ var Jr = new Float32Array([
|
|
|
5699
5994
|
#h() {
|
|
5700
5995
|
if (this.#a) return this.#a;
|
|
5701
5996
|
let e = this.gl;
|
|
5702
|
-
return this.#a = e.createTexture(), e.activeTexture(e.TEXTURE0 +
|
|
5997
|
+
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
5998
|
255,
|
|
5704
5999
|
255,
|
|
5705
6000
|
255,
|
|
@@ -5709,16 +6004,16 @@ var Jr = new Float32Array([
|
|
|
5709
6004
|
#g() {
|
|
5710
6005
|
if (this.#o) return this.#o;
|
|
5711
6006
|
let e = this.gl;
|
|
5712
|
-
return this.#o = e.createBuffer(), e.bindBuffer(e.ARRAY_BUFFER, this.#o), e.bufferData(e.ARRAY_BUFFER,
|
|
6007
|
+
return this.#o = e.createBuffer(), e.bindBuffer(e.ARRAY_BUFFER, this.#o), e.bufferData(e.ARRAY_BUFFER, hi, e.STATIC_DRAW), this.#o;
|
|
5713
6008
|
}
|
|
5714
6009
|
};
|
|
5715
|
-
function
|
|
6010
|
+
function yi(e) {
|
|
5716
6011
|
return He(e) ? [e.videoWidth, e.videoHeight] : "naturalWidth" in e ? [e.naturalWidth, e.naturalHeight] : [e.width, e.height];
|
|
5717
6012
|
}
|
|
5718
|
-
function
|
|
6013
|
+
function bi(e, t, n) {
|
|
5719
6014
|
let r = /* @__PURE__ */ new Map();
|
|
5720
6015
|
for (let i of e) {
|
|
5721
|
-
let e = Math.min(3, Math.max(0, Math.floor((i.x + i.width / 2) / t *
|
|
6016
|
+
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
6017
|
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
6018
|
i.x,
|
|
5724
6019
|
i.y,
|
|
@@ -5733,13 +6028,13 @@ function $r(e, t, n) {
|
|
|
5733
6028
|
height: r - t
|
|
5734
6029
|
}));
|
|
5735
6030
|
}
|
|
5736
|
-
function
|
|
6031
|
+
function xi(e, t, n) {
|
|
5737
6032
|
let r = new Float32Array(t), i = new Uint32Array(t);
|
|
5738
6033
|
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
6034
|
return i.sort((e, t) => r[e] - r[t]);
|
|
5740
6035
|
}
|
|
5741
6036
|
// src/webgl/context.js
|
|
5742
|
-
var
|
|
6037
|
+
var Si = null, Ci = class e {
|
|
5743
6038
|
canvas;
|
|
5744
6039
|
gl;
|
|
5745
6040
|
programs;
|
|
@@ -5758,8 +6053,8 @@ var ti = null, ni = class e {
|
|
|
5758
6053
|
#i;
|
|
5759
6054
|
constructor(e, { antialias: t = !0, shared: n = !1 } = {}) {
|
|
5760
6055
|
this.canvas = e, this.isShared = n;
|
|
5761
|
-
let r =
|
|
5762
|
-
r && (clearTimeout(r.timer),
|
|
6056
|
+
let r = wi.get(e);
|
|
6057
|
+
r && (clearTimeout(r.timer), wi.delete(e));
|
|
5763
6058
|
let i = e.getContext("webgl2", {
|
|
5764
6059
|
antialias: t,
|
|
5765
6060
|
alpha: !0,
|
|
@@ -5767,7 +6062,7 @@ var ti = null, ni = class e {
|
|
|
5767
6062
|
stencil: !0,
|
|
5768
6063
|
powerPreference: "high-performance"
|
|
5769
6064
|
});
|
|
5770
|
-
i || E("WebGLRenderer", "WebGL 2 is not available in this browser or on this device"), this.gl = i, this.programs = new
|
|
6065
|
+
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
6066
|
let a = (e) => {
|
|
5772
6067
|
e.preventDefault(), this.lost = !0;
|
|
5773
6068
|
}, o = () => {
|
|
@@ -5779,11 +6074,11 @@ var ti = null, ni = class e {
|
|
|
5779
6074
|
}, r && i.isContextLost() && (this.lost = !0, r.lose?.restoreContext());
|
|
5780
6075
|
}
|
|
5781
6076
|
static shared() {
|
|
5782
|
-
if (!
|
|
6077
|
+
if (!Si) {
|
|
5783
6078
|
let t = typeof document < "u" ? document.createElement("canvas") : new OffscreenCanvas(1, 1);
|
|
5784
|
-
|
|
6079
|
+
Si = new e(t, { shared: !0 });
|
|
5785
6080
|
}
|
|
5786
|
-
return
|
|
6081
|
+
return Si;
|
|
5787
6082
|
}
|
|
5788
6083
|
fit(e, t) {
|
|
5789
6084
|
let n = this.canvas;
|
|
@@ -5824,12 +6119,12 @@ var ti = null, ni = class e {
|
|
|
5824
6119
|
if (this.users.delete(e), t && this.resources.release(e, t), this.users.size) return;
|
|
5825
6120
|
this.programs.dispose(), this.resources.reset(), this.passes?.reset(), this.bloom?.dispose(), this.#i();
|
|
5826
6121
|
let n = this.gl.getExtension("WEBGL_lose_context");
|
|
5827
|
-
this ===
|
|
6122
|
+
this === Si ? (n?.loseContext(), Si = null) : wi.set(this.canvas, {
|
|
5828
6123
|
lose: n,
|
|
5829
6124
|
timer: setTimeout(() => n?.loseContext())
|
|
5830
6125
|
});
|
|
5831
6126
|
}
|
|
5832
|
-
},
|
|
6127
|
+
}, wi = /* @__PURE__ */ new WeakMap(), Ti = [
|
|
5833
6128
|
"canvas",
|
|
5834
6129
|
"shared",
|
|
5835
6130
|
"antialias",
|
|
@@ -5838,40 +6133,40 @@ var ti = null, ni = class e {
|
|
|
5838
6133
|
"exposure",
|
|
5839
6134
|
"pixelRatio",
|
|
5840
6135
|
"bloom"
|
|
5841
|
-
],
|
|
6136
|
+
], Ei = {
|
|
5842
6137
|
strength: 1,
|
|
5843
6138
|
radius: .6,
|
|
5844
6139
|
threshold: .6
|
|
5845
|
-
},
|
|
6140
|
+
}, Di = Object.keys(Ei), Oi = {
|
|
5846
6141
|
intensity: "use 'strength'",
|
|
5847
6142
|
amount: "use 'strength'",
|
|
5848
6143
|
size: "use 'radius'",
|
|
5849
6144
|
blur: "use 'radius'"
|
|
5850
|
-
},
|
|
5851
|
-
function
|
|
6145
|
+
}, ki = { alpha: "the canvas is always transparent where the scene has no background" };
|
|
6146
|
+
function Ai(e, t) {
|
|
5852
6147
|
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(
|
|
6148
|
+
if (t === !0) return { ...Ei };
|
|
6149
|
+
typeof t != "object" && E(e, `bloom is true, false or { strength, radius, threshold }, got ${j(t)}`), A(`${e} bloom`, t, Di, Oi);
|
|
6150
|
+
let n = { ...Ei };
|
|
6151
|
+
for (let r of Object.keys(Ei)) t[r] !== void 0 && (n[r] = M(`${e} bloom`, r, t[r]));
|
|
5857
6152
|
return n;
|
|
5858
6153
|
}
|
|
5859
|
-
var
|
|
6154
|
+
var ji = {
|
|
5860
6155
|
none: 0,
|
|
5861
6156
|
aces: 1,
|
|
5862
6157
|
neutral: 2
|
|
5863
|
-
},
|
|
6158
|
+
}, Mi = [], Ni = {
|
|
5864
6159
|
roughnessMap: "ROUGHNESS_MAP",
|
|
5865
6160
|
metalnessMap: "METALNESS_MAP",
|
|
5866
6161
|
normalMap: "NORMAL_MAP",
|
|
5867
6162
|
bumpMap: "BUMP_MAP",
|
|
5868
6163
|
aoMap: "AO_MAP",
|
|
5869
6164
|
lightMap: "LIGHT_MAP"
|
|
5870
|
-
},
|
|
6165
|
+
}, Pi = [
|
|
5871
6166
|
"map",
|
|
5872
6167
|
"emissiveMap",
|
|
5873
|
-
...Object.keys(
|
|
5874
|
-
],
|
|
6168
|
+
...Object.keys(Ni)
|
|
6169
|
+
], Fi = {
|
|
5875
6170
|
matcap: "uMatcap",
|
|
5876
6171
|
map: "uMap",
|
|
5877
6172
|
roughnessMap: "uRoughnessMap",
|
|
@@ -5881,7 +6176,7 @@ var ui = {
|
|
|
5881
6176
|
aoMap: "uAoMap",
|
|
5882
6177
|
emissiveMap: "uEmissiveMap",
|
|
5883
6178
|
lightMap: "uLightMap"
|
|
5884
|
-
},
|
|
6179
|
+
}, Ii = [Lr, Mr], Li = new U({
|
|
5885
6180
|
positions: [
|
|
5886
6181
|
-1,
|
|
5887
6182
|
0,
|
|
@@ -5928,14 +6223,14 @@ var ui = {
|
|
|
5928
6223
|
3,
|
|
5929
6224
|
2
|
|
5930
6225
|
]
|
|
5931
|
-
}),
|
|
6226
|
+
}), Ri = {
|
|
5932
6227
|
drawMode: "triangles",
|
|
5933
6228
|
receiveShadow: !0,
|
|
5934
6229
|
castShadow: !1,
|
|
5935
6230
|
renderOrder: 0
|
|
5936
|
-
},
|
|
5937
|
-
static OPTIONS =
|
|
5938
|
-
static HINTS =
|
|
6231
|
+
}, zi = class {
|
|
6232
|
+
static OPTIONS = Ti;
|
|
6233
|
+
static HINTS = ki;
|
|
5939
6234
|
canvas;
|
|
5940
6235
|
toneMapping = "neutral";
|
|
5941
6236
|
exposure = 1;
|
|
@@ -5963,22 +6258,22 @@ var ui = {
|
|
|
5963
6258
|
#u = !1;
|
|
5964
6259
|
#d = /* @__PURE__ */ new Map();
|
|
5965
6260
|
constructor(e) {
|
|
5966
|
-
if (A("WebGLRenderer", e,
|
|
6261
|
+
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
6262
|
"aces",
|
|
5968
6263
|
"neutral",
|
|
5969
6264
|
"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 =
|
|
6265
|
+
])), 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) {
|
|
6266
|
+
this.#t = Ci.shared();
|
|
5972
6267
|
let e = this.canvas.getContext("2d");
|
|
5973
6268
|
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
|
|
6269
|
+
} else this.#t = new Ci(this.canvas, { antialias: e.antialias });
|
|
5975
6270
|
this.#t.users.add(this);
|
|
5976
6271
|
}
|
|
5977
6272
|
get bloom() {
|
|
5978
6273
|
return this.#e;
|
|
5979
6274
|
}
|
|
5980
6275
|
set bloom(e) {
|
|
5981
|
-
this.#e =
|
|
6276
|
+
this.#e = Ai("WebGLRenderer", e);
|
|
5982
6277
|
}
|
|
5983
6278
|
get gl() {
|
|
5984
6279
|
return this.#t.gl;
|
|
@@ -5990,7 +6285,7 @@ var ui = {
|
|
|
5990
6285
|
this.pixelRatio = n, this.canvas.width = Math.max(1, Math.round(e * n)), this.canvas.height = Math.max(1, Math.round(t * n));
|
|
5991
6286
|
}
|
|
5992
6287
|
render(e, t) {
|
|
5993
|
-
return e.updateWorldTree(), this.renderFrame(
|
|
6288
|
+
return e.updateWorldTree(), this.renderFrame(Kt(e, t));
|
|
5994
6289
|
}
|
|
5995
6290
|
renderFrame(e, { wait: t = !1 } = {}) {
|
|
5996
6291
|
let n = this.#t;
|
|
@@ -6000,7 +6295,7 @@ var ui = {
|
|
|
6000
6295
|
let i = this.canvas.width, a = this.canvas.height;
|
|
6001
6296
|
n.isShared && n.fit(i, a);
|
|
6002
6297
|
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 ? [
|
|
6298
|
+
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
6299
|
e.shadow && c.shadowMap(e.shadow),
|
|
6005
6300
|
e.spotShadows.length > 0 && c.spotShadowMaps(e.spotShadows),
|
|
6006
6301
|
e.pointShadow && c.pointShadowMap(e.pointShadow)
|
|
@@ -6012,7 +6307,7 @@ var ui = {
|
|
|
6012
6307
|
} else r.clearColor(0, 0, 0, 0);
|
|
6013
6308
|
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
6309
|
exposure: this.exposure,
|
|
6015
|
-
toneMapping:
|
|
6310
|
+
toneMapping: ji[this.toneMapping]
|
|
6016
6311
|
}), r.enable(r.DEPTH_TEST), r.depthFunc(r.LEQUAL), this.#f(e), r.disable(r.BLEND);
|
|
6017
6312
|
for (let t of e.opaque) this.#p(t, e, !1);
|
|
6018
6313
|
for (let t of e.caps) this.#m(t, e, i, a);
|
|
@@ -6094,81 +6389,87 @@ var ui = {
|
|
|
6094
6389
|
};
|
|
6095
6390
|
}
|
|
6096
6391
|
#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 :
|
|
6392
|
+
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
6393
|
f === "points" && i.drawsSprites && h.push("SPRITES");
|
|
6099
6394
|
for (let e of p) h.push(e.define);
|
|
6100
6395
|
let g = c.fog ? t.fog : null;
|
|
6101
6396
|
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
|
-
|
|
6397
|
+
let _ = ei(c);
|
|
6398
|
+
_ && h.push(..._.defines);
|
|
6399
|
+
let v = this.#t.programs, y = v.get(f, h, void 0, _?.source);
|
|
6400
|
+
if (!v.isReady(y)) {
|
|
6104
6401
|
if (!this.#c) {
|
|
6105
6402
|
this.info.compiling++;
|
|
6106
6403
|
return;
|
|
6107
6404
|
}
|
|
6108
|
-
|
|
6405
|
+
v.ready(f, h, void 0, _?.source);
|
|
6109
6406
|
}
|
|
6110
|
-
if (
|
|
6111
|
-
|
|
6407
|
+
if (y.failed) {
|
|
6408
|
+
ri(c, _, y.failed), this.info.compiling++;
|
|
6409
|
+
return;
|
|
6410
|
+
}
|
|
6411
|
+
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)) {
|
|
6412
|
+
for (let [e, t] of Object.entries(this.#s)) y.set(e, t);
|
|
6112
6413
|
let e = this.#r;
|
|
6113
|
-
e && (
|
|
6114
|
-
for (let e of p) for (let [t, n] of Object.entries(e.uniforms))
|
|
6414
|
+
e && (y.set("uEnvMaxLod", e.maxLod), y.set("uEnvSH", e.sh), y.set("uEnvIntensity", t.environmentIntensity));
|
|
6415
|
+
for (let e of p) for (let [t, n] of Object.entries(e.uniforms)) y.set(t, n);
|
|
6115
6416
|
}
|
|
6116
6417
|
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
|
-
|
|
6418
|
+
this.#r && y.set("uEnvMap", this.#r.prefiltered);
|
|
6419
|
+
for (let e of p) y.set(e.sampler, e.texture);
|
|
6420
|
+
}
|
|
6421
|
+
y.set("uModel", l);
|
|
6422
|
+
let b = t.highlight;
|
|
6423
|
+
b && (b.nodes ? b.nodes.has(i) : b.node === i) ? (y.set("uHighlightIndex", b.index ?? -1), y.set("uHighlight", [
|
|
6424
|
+
b.color[0],
|
|
6425
|
+
b.color[1],
|
|
6426
|
+
b.color[2],
|
|
6427
|
+
b.amount
|
|
6428
|
+
])) : 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);
|
|
6429
|
+
let x = c.emissive, S = c.emissiveIntensity;
|
|
6430
|
+
y.set("uEmissive", [
|
|
6431
|
+
x[0] * S,
|
|
6432
|
+
x[1] * S,
|
|
6433
|
+
x[2] * S
|
|
6434
|
+
]), 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));
|
|
6435
|
+
let C = (c.ior - 1) / (c.ior + 1), w = c.specularColor, T = c.specularIntensity;
|
|
6436
|
+
if (y.set("uSpecular", [
|
|
6437
|
+
Math.min(C * C * w[0], 1) * T,
|
|
6438
|
+
Math.min(C * C * w[1], 1) * T,
|
|
6439
|
+
Math.min(C * C * w[2], 1) * T,
|
|
6440
|
+
T
|
|
6140
6441
|
]), c.sheen > 0) {
|
|
6141
6442
|
let e = c.sheenColor, t = c.sheen;
|
|
6142
|
-
|
|
6443
|
+
y.set("uSheenColor", [
|
|
6143
6444
|
e[0] * t,
|
|
6144
6445
|
e[1] * t,
|
|
6145
6446
|
e[2] * t
|
|
6146
|
-
]),
|
|
6447
|
+
]), y.set("uSheenRoughness", c.sheenRoughness);
|
|
6147
6448
|
}
|
|
6148
|
-
if (c.anisotropy > 0 && (
|
|
6449
|
+
if (c.anisotropy > 0 && (y.set("uAnisotropy", c.anisotropy), y.set("uAnisotropyDirection", [Math.cos(c.anisotropyRotation), Math.sin(c.anisotropyRotation)])), c.translucency > 0) {
|
|
6149
6450
|
let e = c.translucencyColor, t = c.translucency;
|
|
6150
|
-
|
|
6451
|
+
y.set("uTranslucency", [
|
|
6151
6452
|
e[0] * t,
|
|
6152
6453
|
e[1] * t,
|
|
6153
6454
|
e[2] * t,
|
|
6154
6455
|
t
|
|
6155
6456
|
]);
|
|
6156
6457
|
}
|
|
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),
|
|
6458
|
+
c.toon > 0 && y.set("uToon", Math.max(2, Math.round(c.toon))), y.set("uAlphaTest", c.alphaTest);
|
|
6459
|
+
let E = f === "mesh" ? c.textures : c.map ? [["map", c.map]] : [], D = E.map(([e, t]) => [Fi[e], this.#t.resources.texture(t)]);
|
|
6460
|
+
for (let [e, t] of D) y.set(e, t);
|
|
6461
|
+
for (let [e, t] of E) e !== "matcap" && y.set(`${Fi[e]}Uv`, mi(t));
|
|
6462
|
+
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") {
|
|
6463
|
+
r.disable(r.CULL_FACE), y.set("uWidth", c.width * this.pixelRatio);
|
|
6163
6464
|
let e = i.arrowBits ?? 0;
|
|
6164
|
-
|
|
6465
|
+
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
6466
|
let t = this.#t.resources.lines(a);
|
|
6166
6467
|
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
6468
|
} else if (f === "points") {
|
|
6168
|
-
r.disable(r.CULL_FACE),
|
|
6469
|
+
r.disable(r.CULL_FACE), y.set("uSize", c.sizeAttenuation ? c.size : c.size * this.pixelRatio);
|
|
6169
6470
|
let e = !n && !c.map;
|
|
6170
6471
|
if (e && (r.enable(r.BLEND), r.blendFunc(r.ONE, r.ONE_MINUS_SRC_ALPHA)), i.drawsSprites) {
|
|
6171
|
-
|
|
6472
|
+
y.set("uResolution", [this.canvas.width, this.canvas.height]);
|
|
6172
6473
|
let e = i.sort ? s(this.#o, t.camera.view, l) : null, n = this.#t.resources.sprites(a, e);
|
|
6173
6474
|
r.bindVertexArray(n.vao), r.drawArraysInstanced(r.TRIANGLE_STRIP, 0, 4, n.count);
|
|
6174
6475
|
} else {
|
|
@@ -6176,16 +6477,16 @@ var ui = {
|
|
|
6176
6477
|
r.bindVertexArray(e.vao), r.drawArrays(r.POINTS, 0, a.drawnVertices);
|
|
6177
6478
|
}
|
|
6178
6479
|
e && r.disable(r.BLEND), this.info.drawCalls++;
|
|
6179
|
-
} else
|
|
6480
|
+
} 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
6481
|
}
|
|
6181
6482
|
#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"],
|
|
6483
|
+
let i = this.gl, a = this.#t.programs, s = [!1, !0].map((e) => a.get("clip-mask", e ? ["INSTANCED", "CLIP"] : ["CLIP"], Ii));
|
|
6183
6484
|
if (!s.every((e) => a.isReady(e))) {
|
|
6184
6485
|
if (!this.#c) {
|
|
6185
6486
|
this.info.compiling++;
|
|
6186
6487
|
return;
|
|
6187
6488
|
}
|
|
6188
|
-
for (let e of [!1, !0]) a.ready("clip-mask", e ? ["INSTANCED", "CLIP"] : ["CLIP"],
|
|
6489
|
+
for (let e of [!1, !0]) a.ready("clip-mask", e ? ["INSTANCED", "CLIP"] : ["CLIP"], Ii);
|
|
6189
6490
|
}
|
|
6190
6491
|
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
6492
|
for (let n of e.items) {
|
|
@@ -6196,7 +6497,7 @@ var ui = {
|
|
|
6196
6497
|
}
|
|
6197
6498
|
#h(e) {
|
|
6198
6499
|
let t = e.color.getHex(), n = this.#d.get(t);
|
|
6199
|
-
n || this.#d.set(t, n = new
|
|
6500
|
+
n || this.#d.set(t, n = new rt({
|
|
6200
6501
|
color: e.color.getStyle(),
|
|
6201
6502
|
roughness: .6
|
|
6202
6503
|
}));
|
|
@@ -6229,8 +6530,8 @@ var ui = {
|
|
|
6229
6530
|
1
|
|
6230
6531
|
]);
|
|
6231
6532
|
return {
|
|
6232
|
-
node:
|
|
6233
|
-
geometry:
|
|
6533
|
+
node: Ri,
|
|
6534
|
+
geometry: Li,
|
|
6234
6535
|
material: n,
|
|
6235
6536
|
worldMatrix: g,
|
|
6236
6537
|
instances: null,
|
|
@@ -6243,16 +6544,16 @@ var ui = {
|
|
|
6243
6544
|
if (t.vertexColors && n && a.push("VERTEX_COLORS"), e === "mesh") {
|
|
6244
6545
|
if (!t.unlit) {
|
|
6245
6546
|
a.push("LIT");
|
|
6246
|
-
for (let [e, n] of Object.entries(
|
|
6547
|
+
for (let [e, n] of Object.entries(Ni)) t[e] && a.push(n);
|
|
6247
6548
|
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
6549
|
}
|
|
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 &&
|
|
6550
|
+
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
6551
|
let e = i ? t.textures.filter(([e, t]) => t.uvSet === 1 && e !== "matcap") : [];
|
|
6251
|
-
e.length && a.push("UV2", ...e.map(([e]) => `${
|
|
6552
|
+
e.length && a.push("UV2", ...e.map(([e]) => `${Fi[e]}Set vUv2`)), r && a.push("INSTANCED");
|
|
6252
6553
|
} else e === "points" ? (t.map && a.push("MAP"), t.sizeAttenuation && a.push("SIZE_ATTENUATION")) : t.dash > 0 && a.push("DASHED");
|
|
6253
6554
|
return a;
|
|
6254
6555
|
}
|
|
6255
|
-
},
|
|
6556
|
+
}, Bi = [
|
|
6256
6557
|
"canvas",
|
|
6257
6558
|
"scene",
|
|
6258
6559
|
"camera",
|
|
@@ -6273,8 +6574,22 @@ var ui = {
|
|
|
6273
6574
|
"maxDelta",
|
|
6274
6575
|
"reducedMotion",
|
|
6275
6576
|
"keyboard",
|
|
6276
|
-
"description"
|
|
6277
|
-
|
|
6577
|
+
"description",
|
|
6578
|
+
"debug"
|
|
6579
|
+
], Vi = {
|
|
6580
|
+
lights: !0,
|
|
6581
|
+
shadows: !0,
|
|
6582
|
+
bounds: !0,
|
|
6583
|
+
normals: !1,
|
|
6584
|
+
axes: !0,
|
|
6585
|
+
camera: !0,
|
|
6586
|
+
stats: "top-left"
|
|
6587
|
+
}, Hi = Object.keys(Vi), Ui = [
|
|
6588
|
+
"top-left",
|
|
6589
|
+
"top-right",
|
|
6590
|
+
"bottom-left",
|
|
6591
|
+
"bottom-right"
|
|
6592
|
+
], Wi = ["keep", "aspect"], Gi = {
|
|
6278
6593
|
renderer: "the View makes its renderer - read it from view.renderer",
|
|
6279
6594
|
controls: "use orbit: true (or orbit options); the control is then view.controls",
|
|
6280
6595
|
container: "use canvas: an element or selector (a full-window canvas is made when omitted)",
|
|
@@ -6284,7 +6599,7 @@ var ui = {
|
|
|
6284
6599
|
keep: "use framing: { keep: 'width' | 'height' | 'both' }",
|
|
6285
6600
|
fit: "use framing: { keep: 'both' } to keep everything framed in view as the canvas changes shape",
|
|
6286
6601
|
aspect: "the canvas sets the aspect; framing: { aspect } says which shape the camera was set up for"
|
|
6287
|
-
},
|
|
6602
|
+
}, Ki = {
|
|
6288
6603
|
mouseover: "hover",
|
|
6289
6604
|
mouseenter: "hover",
|
|
6290
6605
|
mousemove: "hover",
|
|
@@ -6298,10 +6613,10 @@ var ui = {
|
|
|
6298
6613
|
select: "click",
|
|
6299
6614
|
pointerdown: "click",
|
|
6300
6615
|
mousedown: "click"
|
|
6301
|
-
},
|
|
6302
|
-
static OPTIONS =
|
|
6303
|
-
static HINTS =
|
|
6304
|
-
static FRAMING_OPTIONS =
|
|
6616
|
+
}, qi = .45, Ji = H.fromInput("#ffcc00"), Yi = 4, Xi = 5e3, Zi = 0, Qi = class {
|
|
6617
|
+
static OPTIONS = Bi;
|
|
6618
|
+
static HINTS = Gi;
|
|
6619
|
+
static FRAMING_OPTIONS = Wi;
|
|
6305
6620
|
canvas;
|
|
6306
6621
|
scene;
|
|
6307
6622
|
#e;
|
|
@@ -6330,7 +6645,7 @@ var ui = {
|
|
|
6330
6645
|
#g = "height";
|
|
6331
6646
|
#_ = 0;
|
|
6332
6647
|
#v = 1;
|
|
6333
|
-
#y = new
|
|
6648
|
+
#y = new fr();
|
|
6334
6649
|
#b = [];
|
|
6335
6650
|
#x;
|
|
6336
6651
|
#S = null;
|
|
@@ -6347,24 +6662,29 @@ var ui = {
|
|
|
6347
6662
|
#A = null;
|
|
6348
6663
|
#j = null;
|
|
6349
6664
|
#M = null;
|
|
6350
|
-
#N =
|
|
6351
|
-
#P =
|
|
6352
|
-
#F =
|
|
6353
|
-
#I =
|
|
6354
|
-
#L =
|
|
6665
|
+
#N = null;
|
|
6666
|
+
#P = null;
|
|
6667
|
+
#F = !1;
|
|
6668
|
+
#I = 0;
|
|
6669
|
+
#L = 0;
|
|
6355
6670
|
#R = !1;
|
|
6356
|
-
#z =
|
|
6671
|
+
#z = !1;
|
|
6357
6672
|
#B = null;
|
|
6358
|
-
#V =
|
|
6359
|
-
#H =
|
|
6360
|
-
#U =
|
|
6673
|
+
#V = !1;
|
|
6674
|
+
#H = !1;
|
|
6675
|
+
#U = !1;
|
|
6361
6676
|
#W = null;
|
|
6362
|
-
#G =
|
|
6677
|
+
#G = null;
|
|
6678
|
+
#K = null;
|
|
6679
|
+
#q = null;
|
|
6680
|
+
#J = null;
|
|
6681
|
+
#Y = null;
|
|
6682
|
+
#X = new Sr({
|
|
6363
6683
|
sky: "#ffffff",
|
|
6364
6684
|
ground: "#444444",
|
|
6365
6685
|
intensity: .5
|
|
6366
6686
|
});
|
|
6367
|
-
#
|
|
6687
|
+
#Z = new wr({
|
|
6368
6688
|
direction: [
|
|
6369
6689
|
-.5,
|
|
6370
6690
|
-1,
|
|
@@ -6372,9 +6692,9 @@ var ui = {
|
|
|
6372
6692
|
],
|
|
6373
6693
|
intensity: 1.5
|
|
6374
6694
|
});
|
|
6375
|
-
#
|
|
6695
|
+
#Q = !1;
|
|
6376
6696
|
constructor(e = {}) {
|
|
6377
|
-
A("View", e,
|
|
6697
|
+
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
6698
|
position: [
|
|
6379
6699
|
0,
|
|
6380
6700
|
1.5,
|
|
@@ -6386,15 +6706,15 @@ var ui = {
|
|
|
6386
6706
|
0
|
|
6387
6707
|
],
|
|
6388
6708
|
...e.camera
|
|
6389
|
-
}), this.#m && (this.#h =
|
|
6709
|
+
}), this.#m && (this.#h = $i(this.#e));
|
|
6390
6710
|
let t = e.context === void 0 ? "auto" : P("View", "context", e.context, [
|
|
6391
6711
|
"auto",
|
|
6392
6712
|
"own",
|
|
6393
6713
|
"shared"
|
|
6394
6714
|
]);
|
|
6395
6715
|
e.exposure !== void 0 && N("View", "exposure", e.exposure, 0);
|
|
6396
|
-
let n = t === "shared" || t === "auto" &&
|
|
6397
|
-
if (this.renderer = new
|
|
6716
|
+
let n = t === "shared" || t === "auto" && Zi >= Yi;
|
|
6717
|
+
if (this.renderer = new zi({
|
|
6398
6718
|
canvas: this.canvas,
|
|
6399
6719
|
shared: n,
|
|
6400
6720
|
antialias: e.antialias,
|
|
@@ -6402,31 +6722,31 @@ var ui = {
|
|
|
6402
6722
|
toneMapping: e.toneMapping,
|
|
6403
6723
|
exposure: e.exposure,
|
|
6404
6724
|
bloom: e.bloom
|
|
6405
|
-
}), n || (this.#i = !0,
|
|
6406
|
-
this.#
|
|
6407
|
-
}, e.autoLight !== void 0 && (this.autoLight = !!e.autoLight), e.reducedMotion !== void 0 && this.#
|
|
6725
|
+
}), n || (this.#i = !0, Zi++), this.renderer.onReady = () => {
|
|
6726
|
+
this.#V = !0, this.invalidate();
|
|
6727
|
+
}, 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
6728
|
"auto",
|
|
6409
6729
|
"always",
|
|
6410
6730
|
"manual"
|
|
6411
6731
|
])), 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
6732
|
let t = e.orbit === !0 ? {} : e.orbit, n = t.mode ?? (e.camera === "top" ? "map" : void 0);
|
|
6413
|
-
this.controls = new
|
|
6733
|
+
this.controls = new Cn(this.camera, this.canvas, n ? {
|
|
6414
6734
|
...t,
|
|
6415
6735
|
mode: n
|
|
6416
|
-
} : t), this.#
|
|
6736
|
+
} : t), this.#G = this.controls.handOverPointer();
|
|
6417
6737
|
}
|
|
6418
|
-
if (e.highlight !== void 0 && this
|
|
6419
|
-
interactive: (e) =>
|
|
6420
|
-
on: (e, t, n) => this.#
|
|
6421
|
-
}), e.framing !== void 0) {
|
|
6738
|
+
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, {
|
|
6739
|
+
interactive: (e) => la(e, "click").length > 0 || la(e, "hover").length > 0,
|
|
6740
|
+
on: (e, t, n) => this.#be(e, t, n)
|
|
6741
|
+
}), e.debug !== void 0 && (this.debug = e.debug), e.framing !== void 0) {
|
|
6422
6742
|
let t = typeof e.framing == "string" ? { keep: e.framing } : e.framing;
|
|
6423
|
-
A("View", t,
|
|
6743
|
+
A("View", t, Wi, {}, "framing"), t.keep !== void 0 && (this.#g = P("View", "framing.keep", t.keep, [
|
|
6424
6744
|
"height",
|
|
6425
6745
|
"width",
|
|
6426
6746
|
"both"
|
|
6427
6747
|
])), 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
6748
|
}
|
|
6429
|
-
this.resize(), this.#
|
|
6749
|
+
this.resize(), this.#we(), this.#me();
|
|
6430
6750
|
}
|
|
6431
6751
|
get camera() {
|
|
6432
6752
|
return this.#e;
|
|
@@ -6434,12 +6754,12 @@ var ui = {
|
|
|
6434
6754
|
set camera(e) {
|
|
6435
6755
|
if (typeof e == "string") {
|
|
6436
6756
|
let t = this.#e, n = t.target ?? new z();
|
|
6437
|
-
e =
|
|
6757
|
+
e = In(e, {
|
|
6438
6758
|
target: n,
|
|
6439
6759
|
distance: Math.max(.001, t.position.distanceTo(n))
|
|
6440
6760
|
}), this.#m = !0;
|
|
6441
6761
|
} else this.#m = !1;
|
|
6442
|
-
e instanceof
|
|
6762
|
+
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
6763
|
}
|
|
6444
6764
|
get bloom() {
|
|
6445
6765
|
return this.renderer.bloom;
|
|
@@ -6451,20 +6771,28 @@ var ui = {
|
|
|
6451
6771
|
return this.#O;
|
|
6452
6772
|
}
|
|
6453
6773
|
set highlight(e) {
|
|
6454
|
-
this
|
|
6774
|
+
this.#$(e);
|
|
6455
6775
|
}
|
|
6456
|
-
|
|
6457
|
-
this.#O = e == null ? null : H.fromInput(e, "View"), this.#
|
|
6776
|
+
#$(e) {
|
|
6777
|
+
this.#O = e == null ? null : H.fromInput(e, "View"), this.#V = !0, this.invalidate();
|
|
6458
6778
|
}
|
|
6459
6779
|
get reducedMotion() {
|
|
6460
|
-
return this.#k === "auto" ? this.#
|
|
6780
|
+
return this.#k === "auto" ? this.#z : this.#k;
|
|
6461
6781
|
}
|
|
6462
6782
|
set reducedMotion(e) {
|
|
6463
|
-
this.#
|
|
6783
|
+
this.#ee(e);
|
|
6464
6784
|
}
|
|
6465
|
-
#
|
|
6785
|
+
#ee(e) {
|
|
6466
6786
|
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
6787
|
}
|
|
6788
|
+
get debug() {
|
|
6789
|
+
return this.#N ?? !1;
|
|
6790
|
+
}
|
|
6791
|
+
set debug(e) {
|
|
6792
|
+
this.#N = fa(e), this.#N && !this.#P && !this.#F && (this.#F = !0, import("./debug.js").then(({ DebugDraw: e }) => {
|
|
6793
|
+
this.#F = !1, !this.#r && (this.#P = new e(this.#x.root), this.invalidate());
|
|
6794
|
+
})), this.#N && (this.#N.bounds === "hovered" || this.#N.normals === "hovered") && (this.#V = !0), this.#N || this.#P?.stats(!1, {}, 0, 0), this.invalidate();
|
|
6795
|
+
}
|
|
6468
6796
|
get description() {
|
|
6469
6797
|
return this.#M;
|
|
6470
6798
|
}
|
|
@@ -6474,7 +6802,7 @@ var ui = {
|
|
|
6474
6802
|
return;
|
|
6475
6803
|
}
|
|
6476
6804
|
let t = this.canvas;
|
|
6477
|
-
e === null ? (t.removeAttribute("aria-label"), this.#
|
|
6805
|
+
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
6806
|
}
|
|
6479
6807
|
get width() {
|
|
6480
6808
|
return this.#u;
|
|
@@ -6486,13 +6814,13 @@ var ui = {
|
|
|
6486
6814
|
return this.scene.ready;
|
|
6487
6815
|
}
|
|
6488
6816
|
get hovered() {
|
|
6489
|
-
return this.#
|
|
6817
|
+
return this.#q;
|
|
6490
6818
|
}
|
|
6491
6819
|
get overlay() {
|
|
6492
6820
|
return this.#x.root;
|
|
6493
6821
|
}
|
|
6494
6822
|
start(e) {
|
|
6495
|
-
return e && (this.#t = e), this.#n || (this.#n = !0, this.#s = 0), this.#
|
|
6823
|
+
return e && (this.#t = e), this.#n || (this.#n = !0, this.#s = 0), this.#me(), this;
|
|
6496
6824
|
}
|
|
6497
6825
|
stop() {
|
|
6498
6826
|
return this.#n = !1, this;
|
|
@@ -6501,29 +6829,39 @@ var ui = {
|
|
|
6501
6829
|
return this.#n;
|
|
6502
6830
|
}
|
|
6503
6831
|
invalidate() {
|
|
6504
|
-
return this.#c = !0, this.#
|
|
6832
|
+
return this.#c = !0, this.#me(), this;
|
|
6505
6833
|
}
|
|
6506
6834
|
step(e) {
|
|
6507
|
-
return this.time += e, this.#t?.(e, this.time), this.scene.motionReduced = this.reducedMotion, this.scene.update(e, this.time), this.#
|
|
6835
|
+
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
6836
|
}
|
|
6509
|
-
#
|
|
6510
|
-
if (this.#
|
|
6837
|
+
#te(e) {
|
|
6838
|
+
if (this.#J) return this.#ie(e);
|
|
6511
6839
|
if (!this.controls) return;
|
|
6512
|
-
let t = this.#m &&
|
|
6513
|
-
this.controls.update(e, this.reducedMotion), t && (this.#h =
|
|
6840
|
+
let t = this.#m && ea($i(this.camera), this.#h);
|
|
6841
|
+
this.controls.update(e, this.reducedMotion), t && (this.#h = $i(this.camera));
|
|
6514
6842
|
}
|
|
6515
6843
|
render() {
|
|
6516
|
-
return this.#
|
|
6844
|
+
return this.#ne(!1);
|
|
6517
6845
|
}
|
|
6518
|
-
#
|
|
6846
|
+
#ne(e) {
|
|
6519
6847
|
if (this.#m) {
|
|
6520
6848
|
this.resize();
|
|
6521
6849
|
let e = this.scene.bounds;
|
|
6522
|
-
|
|
6850
|
+
ea($i(this.camera), this.#h) ? e.isEmpty() || this.frame(this.scene) : this.#m = !1;
|
|
6523
6851
|
}
|
|
6524
6852
|
this.scene.updateWorldTree();
|
|
6525
|
-
let t =
|
|
6526
|
-
|
|
6853
|
+
let t = Kt(this.scene, this.camera);
|
|
6854
|
+
this.autoLight && t.lights.length === 0 && this.#De(t), t.time = this.time, t.highlight = this.#Se(this.#q), this.#Ce(t);
|
|
6855
|
+
let n = this.#N && this.#P ? this.#P.add(t, this.#N, {
|
|
6856
|
+
camera: this.camera,
|
|
6857
|
+
hovered: this.#q,
|
|
6858
|
+
bounds: this.scene.boundsFrom(this.camera)
|
|
6859
|
+
}) : null, r = performance.now();
|
|
6860
|
+
if (this.renderer.renderFrame(t, { wait: e }), n && (t.opaque.length -= n.opaque, t.transparent.length -= n.transparent), this.#P) {
|
|
6861
|
+
let e = performance.now(), t = this.#I ? e - this.#I : 0;
|
|
6862
|
+
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);
|
|
6863
|
+
}
|
|
6864
|
+
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
6865
|
}
|
|
6528
6866
|
resize() {
|
|
6529
6867
|
let e = this.canvas.clientWidth, t = this.canvas.clientHeight;
|
|
@@ -6534,23 +6872,23 @@ var ui = {
|
|
|
6534
6872
|
}
|
|
6535
6873
|
let n = e || this.canvas.width || 1, r = t || this.canvas.height || 1;
|
|
6536
6874
|
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.#
|
|
6875
|
+
let i = this.#m && ea($i(this.camera), this.#h);
|
|
6876
|
+
this.#pe(), i && (this.#h = $i(this.camera)), this.#c = !0;
|
|
6539
6877
|
}
|
|
6540
6878
|
frame(e = this.scene, { padding: t = .2, direction: n, duration: r = 0 } = {}) {
|
|
6541
6879
|
N("View", "frame() duration", r, 0);
|
|
6542
|
-
let i = this.camera, a =
|
|
6543
|
-
this.#
|
|
6544
|
-
let o = this.#
|
|
6545
|
-
return this.#m = !1, o && (
|
|
6880
|
+
let i = this.camera, a = aa(i);
|
|
6881
|
+
this.#J = null;
|
|
6882
|
+
let o = this.#re("frame", e, t, n);
|
|
6883
|
+
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
6884
|
from: a,
|
|
6547
|
-
to:
|
|
6885
|
+
to: aa(i),
|
|
6548
6886
|
time: 0,
|
|
6549
6887
|
duration: r
|
|
6550
|
-
},
|
|
6888
|
+
}, oa(i, a)), this.invalidate()), this;
|
|
6551
6889
|
}
|
|
6552
6890
|
framing(e = this.scene, { padding: t = .2, direction: n } = {}) {
|
|
6553
|
-
let r = this.#
|
|
6891
|
+
let r = this.#re("framing", e, t, n);
|
|
6554
6892
|
if (!r) return null;
|
|
6555
6893
|
let { position: i, target: a, height: o } = r.place;
|
|
6556
6894
|
return o === void 0 ? {
|
|
@@ -6562,13 +6900,13 @@ var ui = {
|
|
|
6562
6900
|
height: o
|
|
6563
6901
|
};
|
|
6564
6902
|
}
|
|
6565
|
-
#
|
|
6903
|
+
#re(e, t, n, r) {
|
|
6566
6904
|
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" ?
|
|
6905
|
+
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
6906
|
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 ?
|
|
6907
|
+
let o = t instanceof V ? ta(t) : this.#ae(t, a);
|
|
6570
6908
|
if (!o.length) return null;
|
|
6571
|
-
let s = i.constructor.type === "orthographic-camera", { center: c, size: l } =
|
|
6909
|
+
let s = i.constructor.type === "orthographic-camera", { center: c, size: l } = zn(o, a, {
|
|
6572
6910
|
aspect: i.aspect,
|
|
6573
6911
|
fov: s ? void 0 : i.fov,
|
|
6574
6912
|
padding: n
|
|
@@ -6592,27 +6930,27 @@ var ui = {
|
|
|
6592
6930
|
far: d * 10
|
|
6593
6931
|
};
|
|
6594
6932
|
}
|
|
6595
|
-
|
|
6596
|
-
let t = this.#
|
|
6933
|
+
#ie(e) {
|
|
6934
|
+
let t = this.#J;
|
|
6597
6935
|
t.time = Math.min(t.duration, t.time + e);
|
|
6598
|
-
let n =
|
|
6599
|
-
|
|
6936
|
+
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);
|
|
6937
|
+
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
6938
|
}
|
|
6601
|
-
#
|
|
6939
|
+
#ae(e, t) {
|
|
6602
6940
|
let n = e.bounds;
|
|
6603
6941
|
if (n.isEmpty()) return [];
|
|
6604
6942
|
let r = this.camera, i = r.position.clone();
|
|
6605
6943
|
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 :
|
|
6944
|
+
let a = ra(e, r);
|
|
6945
|
+
return r.position.copy(i), r.updateWorld(), a.length ? a : ta(n);
|
|
6608
6946
|
}
|
|
6609
6947
|
pick(e, t) {
|
|
6610
6948
|
if (typeof e == "object") {
|
|
6611
6949
|
let n = this.canvas.getBoundingClientRect();
|
|
6612
6950
|
t = e.clientY - n.top, e = e.clientX - n.left;
|
|
6613
6951
|
}
|
|
6614
|
-
let n = this.#
|
|
6615
|
-
return r === void 0 ? this.pickAll(e, t)[0] ?? null : r && this.#
|
|
6952
|
+
let n = this.#oe(), r = n ? this.renderer.pick(n, e, t) : void 0;
|
|
6953
|
+
return r === void 0 ? this.pickAll(e, t)[0] ?? null : r && this.#se(r, n);
|
|
6616
6954
|
}
|
|
6617
6955
|
rayAt(e, t) {
|
|
6618
6956
|
if (typeof e == "object") {
|
|
@@ -6620,20 +6958,21 @@ var ui = {
|
|
|
6620
6958
|
t = e.clientY - n.top, e = e.clientX - n.left;
|
|
6621
6959
|
}
|
|
6622
6960
|
let n = [e / (this.#u || 1) * 2 - 1, 1 - t / (this.#d || 1) * 2];
|
|
6623
|
-
return new
|
|
6961
|
+
return new ir().setFromCamera(n, this.camera).ray;
|
|
6624
6962
|
}
|
|
6625
|
-
#
|
|
6963
|
+
#oe() {
|
|
6626
6964
|
let e = this.lastFrame;
|
|
6627
6965
|
if (!e) return null;
|
|
6628
6966
|
let t = 0;
|
|
6629
|
-
for (let { node: n, geometry: r, instances: i } of [...e.opaque, ...e.transparent]) {
|
|
6630
|
-
|
|
6631
|
-
|
|
6967
|
+
for (let { node: n, geometry: r, instances: i, material: a } of [...e.opaque, ...e.transparent]) {
|
|
6968
|
+
if (a.shader?.vertex) return e;
|
|
6969
|
+
let o = n.drawMode;
|
|
6970
|
+
t += i ? i.count : o === "points" ? r.drawnVertices : o === "lines" ? r.drawnCount / 2 : r.drawnCount / 3;
|
|
6632
6971
|
}
|
|
6633
|
-
return t >
|
|
6972
|
+
return t > Xi ? e : null;
|
|
6634
6973
|
}
|
|
6635
|
-
#
|
|
6636
|
-
let n = e.item.node, r = new
|
|
6974
|
+
#se(e, t) {
|
|
6975
|
+
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
6976
|
if (i) return i;
|
|
6638
6977
|
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
6978
|
return {
|
|
@@ -6648,7 +6987,7 @@ var ui = {
|
|
|
6648
6987
|
};
|
|
6649
6988
|
}
|
|
6650
6989
|
project(e) {
|
|
6651
|
-
let { ndc: [t, n, r], visible: i } =
|
|
6990
|
+
let { ndc: [t, n, r], visible: i } = $t(z.fromInput(e, "View"), this.#ce());
|
|
6652
6991
|
return {
|
|
6653
6992
|
x: (t * .5 + .5) * this.#u,
|
|
6654
6993
|
y: (.5 - n * .5) * this.#d,
|
|
@@ -6657,7 +6996,7 @@ var ui = {
|
|
|
6657
6996
|
};
|
|
6658
6997
|
}
|
|
6659
6998
|
screenBounds(e = this.scene) {
|
|
6660
|
-
let t = e instanceof V ?
|
|
6999
|
+
let t = e instanceof V ? ta(e) : ra(e, this.camera);
|
|
6661
7000
|
if (!t.length) return null;
|
|
6662
7001
|
let n = Infinity, r = Infinity, i = -Infinity, a = -Infinity;
|
|
6663
7002
|
for (let e of t) {
|
|
@@ -6674,19 +7013,19 @@ var ui = {
|
|
|
6674
7013
|
height: a - r
|
|
6675
7014
|
};
|
|
6676
7015
|
}
|
|
6677
|
-
#
|
|
7016
|
+
#ce() {
|
|
6678
7017
|
let e = this.camera;
|
|
6679
7018
|
return e.updateWorld(), new B().multiplyMatrices(e.projectionMatrix, e.viewMatrix);
|
|
6680
7019
|
}
|
|
6681
7020
|
pickArea(e) {
|
|
6682
|
-
return this.scene.updateWorldTree(),
|
|
7021
|
+
return this.scene.updateWorldTree(), cr(this.scene, this.camera, this.#ce(), this.#u, this.#d, e);
|
|
6683
7022
|
}
|
|
6684
7023
|
pickAll(e, t) {
|
|
6685
7024
|
if (typeof e == "object") {
|
|
6686
7025
|
let n = this.canvas.getBoundingClientRect();
|
|
6687
7026
|
t = e.clientY - n.top, e = e.clientX - n.left;
|
|
6688
7027
|
}
|
|
6689
|
-
let n = [e / this.#u * 2 - 1, 1 - t / this.#d * 2], r = new
|
|
7028
|
+
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
7029
|
0,
|
|
6691
7030
|
0,
|
|
6692
7031
|
0
|
|
@@ -6695,22 +7034,22 @@ var ui = {
|
|
|
6695
7034
|
}
|
|
6696
7035
|
on(e, t) {
|
|
6697
7036
|
if (!(e in this.#C)) {
|
|
6698
|
-
let t =
|
|
7037
|
+
let t = Ki[e];
|
|
6699
7038
|
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
7039
|
}
|
|
6701
7040
|
typeof t != "function" && E("View", `on('${e}', fn) needs a function, got ${j(t)}`);
|
|
6702
7041
|
let n = this.#C[e];
|
|
6703
|
-
return n.add(t), this.#
|
|
7042
|
+
return n.add(t), this.#V = !0, () => n.delete(t);
|
|
6704
7043
|
}
|
|
6705
7044
|
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.#
|
|
7045
|
+
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
7046
|
}
|
|
6708
|
-
#
|
|
7047
|
+
#le() {
|
|
6709
7048
|
this.#D || (this.#D = !0, import("./tooltip.js").then(({ Tooltip: e }) => {
|
|
6710
|
-
this.#r || (this.#w = new e((e) => this.#
|
|
7049
|
+
this.#r || (this.#w = new e((e) => this.#fe(e)?.(e), this.#E), this.#V = !0, this.#me());
|
|
6711
7050
|
}));
|
|
6712
7051
|
}
|
|
6713
|
-
#
|
|
7052
|
+
#ue(e) {
|
|
6714
7053
|
e !== !0 && (typeof e != "object" || !e || Array.isArray(e)) && E("View", `'keyboard' is true, false or { label: (hit) => text }, got ${j(e)}`);
|
|
6715
7054
|
let t = e === !0 ? {} : e;
|
|
6716
7055
|
A("View", t, ["label"], {
|
|
@@ -6719,18 +7058,18 @@ var ui = {
|
|
|
6719
7058
|
}, "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
7059
|
this.#r || (this.#A = new e(this, {
|
|
6721
7060
|
focus: (e) => {
|
|
6722
|
-
this.#j = e, this.#
|
|
7061
|
+
this.#j = e, this.#V = !0, this.invalidate();
|
|
6723
7062
|
},
|
|
6724
7063
|
press: (e) => {
|
|
6725
|
-
for (let t of
|
|
7064
|
+
for (let t of ua(e.node, "click")) t(e);
|
|
6726
7065
|
for (let t of this.#C.click) t(e, null);
|
|
6727
7066
|
},
|
|
6728
|
-
tooltip: (e) => this.#
|
|
7067
|
+
tooltip: (e) => this.#fe(e)?.(e),
|
|
6729
7068
|
viewWide: () => this.#C.hover.size > 0 || this.#C.click.size > 0 || !!this.#T
|
|
6730
7069
|
}, t), this.#A.setDescription(this.#M));
|
|
6731
7070
|
});
|
|
6732
7071
|
}
|
|
6733
|
-
#
|
|
7072
|
+
#de(e) {
|
|
6734
7073
|
let { x: t, y: n } = this.project(e.point), r = this.canvas.getBoundingClientRect();
|
|
6735
7074
|
return {
|
|
6736
7075
|
x: t,
|
|
@@ -6740,13 +7079,13 @@ var ui = {
|
|
|
6740
7079
|
event: null
|
|
6741
7080
|
};
|
|
6742
7081
|
}
|
|
6743
|
-
#
|
|
7082
|
+
#fe(e) {
|
|
6744
7083
|
for (let t = e.node; t; t = t.parent) if (t.tooltip) return t.tooltip;
|
|
6745
7084
|
return this.#T;
|
|
6746
7085
|
}
|
|
6747
7086
|
async toImage(e) {
|
|
6748
7087
|
let { snapshot: t } = await import("./snapshot.js");
|
|
6749
|
-
return this.#
|
|
7088
|
+
return this.#ne(!0), t(this.canvas, this.#x.shown, e ?? {}, this.#x.leaders);
|
|
6750
7089
|
}
|
|
6751
7090
|
async explain() {
|
|
6752
7091
|
let { explain: e } = await import("./explain.js"), t = this.render(), n = 0, r = [];
|
|
@@ -6780,20 +7119,21 @@ var ui = {
|
|
|
6780
7119
|
keyboard: !!this.#A,
|
|
6781
7120
|
reducedMotion: this.reducedMotion,
|
|
6782
7121
|
description: this.canvas.getAttribute?.("aria-label") ?? this.#M
|
|
6783
|
-
}
|
|
7122
|
+
},
|
|
7123
|
+
debug: this.#N
|
|
6784
7124
|
});
|
|
6785
7125
|
}
|
|
6786
7126
|
dispose() {
|
|
6787
7127
|
if (!this.#r) {
|
|
6788
7128
|
this.#r = !0, this.#n = !1, cancelAnimationFrame(this.#o);
|
|
6789
7129
|
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 &&
|
|
7130
|
+
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
7131
|
}
|
|
6792
7132
|
}
|
|
6793
|
-
#
|
|
7133
|
+
#pe() {
|
|
6794
7134
|
let e = this.#e;
|
|
6795
7135
|
this.#_ ||= e.aspect;
|
|
6796
|
-
let t =
|
|
7136
|
+
let t = Bn(this.#g, this.#_, e.aspect), n = t / this.#v;
|
|
6797
7137
|
if (this.#v = t, !(Math.abs(n - 1) < 1e-9)) {
|
|
6798
7138
|
if (e.constructor.type === "orthographic-camera") e.height *= n;
|
|
6799
7139
|
else if (e.target) {
|
|
@@ -6802,49 +7142,52 @@ var ui = {
|
|
|
6802
7142
|
} else e.fov = Math.min(170, 2 * Math.atan(Math.tan(e.fov * Math.PI / 360) * n) * 360 / Math.PI);
|
|
6803
7143
|
}
|
|
6804
7144
|
}
|
|
6805
|
-
#
|
|
6806
|
-
this.#o || this.#r || !this.#l || (this.renderMode !== "manual" || this.#n && this.#t || this.#c || this.#
|
|
7145
|
+
#me() {
|
|
7146
|
+
this.#o || this.#r || !this.#l || (this.renderMode !== "manual" || this.#n && this.#t || this.#c || this.#V) && (this.#o = requestAnimationFrame(this.#he));
|
|
6807
7147
|
}
|
|
6808
|
-
#
|
|
7148
|
+
#he = (e) => {
|
|
6809
7149
|
this.#o = 0;
|
|
6810
7150
|
let t = this.#s ? Math.min(this.maxDelta, (e - this.#s) / 1e3) : 0;
|
|
6811
7151
|
this.#s = e;
|
|
6812
7152
|
try {
|
|
6813
|
-
this.#n && (this.time += t, this.#t?.(t, this.time), this.scene.motionReduced = this.reducedMotion, this.scene.update(t, this.time)), this.#
|
|
7153
|
+
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
7154
|
} finally {
|
|
6815
|
-
(this.renderMode !== "manual" || this.#n && this.#t || this.#c || this.#
|
|
7155
|
+
(this.renderMode !== "manual" || this.#n && this.#t || this.#c || this.#V) && this.#me();
|
|
6816
7156
|
}
|
|
6817
7157
|
};
|
|
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
|
-
|
|
7158
|
+
#ge() {
|
|
7159
|
+
return this.#C.hover.size > 0 || !!this.#T || !!this.#O || this.#C.click.size > 0 || !!this.lastFrame?.interactive || this.#_e();
|
|
7160
|
+
}
|
|
7161
|
+
#_e() {
|
|
7162
|
+
return !!this.#N && (this.#N.bounds === "hovered" || this.#N.normals === "hovered");
|
|
7163
|
+
}
|
|
7164
|
+
#ve() {
|
|
7165
|
+
if (this.#V = !1, !this.#ge()) return;
|
|
7166
|
+
let e = this.#B;
|
|
7167
|
+
if (this.#j) return this.#ye(this.#j, this.#de(this.#j));
|
|
7168
|
+
if (this.#Y) return this.#ye(this.#Y);
|
|
7169
|
+
if (!e || this.#U) return this.#ye(null);
|
|
7170
|
+
let t = this.#oe();
|
|
7171
|
+
if (t && this.#H) {
|
|
7172
|
+
this.#V = !0;
|
|
6830
7173
|
return;
|
|
6831
7174
|
}
|
|
6832
7175
|
let n = t ? this.renderer.pickAsync(t, e.x, e.y) : void 0;
|
|
6833
|
-
if (!n) return this.#
|
|
6834
|
-
this.#
|
|
6835
|
-
this.#
|
|
7176
|
+
if (!n) return this.#ye(this.pick(e.x, e.y));
|
|
7177
|
+
this.#H = !0, n.then((e) => {
|
|
7178
|
+
this.#H = !1, !this.#r && (this.#ye(this.#Y ?? (e && this.#B ? this.#se(e, t) : null)), this.#me());
|
|
6836
7179
|
});
|
|
6837
7180
|
}
|
|
6838
|
-
#
|
|
6839
|
-
let n = this.#
|
|
6840
|
-
if (this.#
|
|
6841
|
-
(this.#
|
|
6842
|
-
let i =
|
|
7181
|
+
#ye(e, t = this.#B) {
|
|
7182
|
+
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);
|
|
7183
|
+
if (this.#q = e, t && e && this.#w ? this.#w.show(e, t.clientX, t.clientY) : this.#w?.hide(), r) return;
|
|
7184
|
+
(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" : "");
|
|
7185
|
+
let i = ua(n?.node, "hover"), a = ua(e?.node, "hover");
|
|
6843
7186
|
for (let e of i) a.includes(e) || e(null);
|
|
6844
7187
|
for (let t of a) t(e);
|
|
6845
7188
|
for (let n of this.#C.hover) n(e, t?.event ?? null);
|
|
6846
7189
|
}
|
|
6847
|
-
#
|
|
7190
|
+
#be(e, t, n) {
|
|
6848
7191
|
let r = t.node, i = t.index, a = i !== null && r.drawMode === "points", o = {
|
|
6849
7192
|
node: r,
|
|
6850
7193
|
point: t.position.clone(),
|
|
@@ -6856,12 +7199,12 @@ var ui = {
|
|
|
6856
7199
|
datum: r.datumAt?.(i) ?? null
|
|
6857
7200
|
};
|
|
6858
7201
|
if (e === "click") {
|
|
6859
|
-
for (let e of
|
|
7202
|
+
for (let e of ua(r, "click")) e(o);
|
|
6860
7203
|
for (let e of this.#C.click) e(o, n);
|
|
6861
7204
|
} else {
|
|
6862
|
-
if (this.#
|
|
7205
|
+
if (this.#Y = e === "over" ? o : null, n) {
|
|
6863
7206
|
let e = this.canvas.getBoundingClientRect();
|
|
6864
|
-
this.#
|
|
7207
|
+
this.#B = {
|
|
6865
7208
|
x: n.clientX - e.left,
|
|
6866
7209
|
y: n.clientY - e.top,
|
|
6867
7210
|
clientX: n.clientX,
|
|
@@ -6869,17 +7212,17 @@ var ui = {
|
|
|
6869
7212
|
event: n
|
|
6870
7213
|
};
|
|
6871
7214
|
}
|
|
6872
|
-
e === "out" && (this.#
|
|
7215
|
+
e === "out" && (this.#B = null), this.#V = !0, this.#me();
|
|
6873
7216
|
}
|
|
6874
7217
|
}
|
|
6875
|
-
#
|
|
6876
|
-
return this.#C.click.size > 0 ||
|
|
7218
|
+
#xe(e) {
|
|
7219
|
+
return this.#C.click.size > 0 || ua(e.node, "click").length > 0;
|
|
6877
7220
|
}
|
|
6878
|
-
#
|
|
7221
|
+
#Se(e) {
|
|
6879
7222
|
if (!e) return null;
|
|
6880
7223
|
let t = null, n = null;
|
|
6881
7224
|
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 =
|
|
7225
|
+
if (t ??= this.#O, !t && e === this.#j && (t = Ji), !t) return null;
|
|
6883
7226
|
let r = e.node;
|
|
6884
7227
|
if (n) {
|
|
6885
7228
|
let e = /* @__PURE__ */ new Set();
|
|
@@ -6890,27 +7233,27 @@ var ui = {
|
|
|
6890
7233
|
index: null,
|
|
6891
7234
|
nodes: e,
|
|
6892
7235
|
color: t,
|
|
6893
|
-
amount:
|
|
7236
|
+
amount: qi
|
|
6894
7237
|
};
|
|
6895
7238
|
}
|
|
6896
7239
|
return {
|
|
6897
7240
|
node: r,
|
|
6898
7241
|
index: e.instance ?? (r.drawMode === "points" ? e.face : null),
|
|
6899
7242
|
color: t,
|
|
6900
|
-
amount:
|
|
7243
|
+
amount: qi
|
|
6901
7244
|
};
|
|
6902
7245
|
}
|
|
6903
|
-
#
|
|
7246
|
+
#Ce(e) {
|
|
6904
7247
|
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
7248
|
if (!r.length) return;
|
|
6906
|
-
let i =
|
|
7249
|
+
let i = ir.solids([...e.opaque, ...e.transparent]), a = new ir();
|
|
6907
7250
|
for (let e of r) {
|
|
6908
7251
|
a.setFromCamera(e.ndc, this.camera);
|
|
6909
7252
|
let t = e.position.distanceTo(a.ray.origin);
|
|
6910
7253
|
e.occluded = a.blocked(i, t * .995, e.node, e.index);
|
|
6911
7254
|
}
|
|
6912
7255
|
}
|
|
6913
|
-
#
|
|
7256
|
+
#we() {
|
|
6914
7257
|
let e = this.canvas, t = (t) => {
|
|
6915
7258
|
let n = e.getBoundingClientRect();
|
|
6916
7259
|
return {
|
|
@@ -6921,26 +7264,26 @@ var ui = {
|
|
|
6921
7264
|
event: t
|
|
6922
7265
|
};
|
|
6923
7266
|
}, n = (e) => {
|
|
6924
|
-
this.#j && this.#A?.clear(), this.#
|
|
6925
|
-
let n = this.#
|
|
6926
|
-
n && n.id === e.pointerId && !n.moved && Math.hypot(this.#
|
|
7267
|
+
this.#j && this.#A?.clear(), this.#B = t(e);
|
|
7268
|
+
let n = this.#K;
|
|
7269
|
+
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
7270
|
}, r = () => {
|
|
6928
|
-
this.#
|
|
7271
|
+
this.#B = null, this.#V = !0, this.#me();
|
|
6929
7272
|
}, i = (e) => {
|
|
6930
|
-
this.#
|
|
7273
|
+
this.#W ? this.#Ee(e) : this.#G?.up(e), this.#U = !1, this.#V = !0, this.#me();
|
|
6931
7274
|
}, a = (n) => {
|
|
6932
|
-
if (this.#
|
|
6933
|
-
this.#
|
|
7275
|
+
if (this.#W?.id === n.pointerId) return;
|
|
7276
|
+
this.#J = null, this.#W = null;
|
|
6934
7277
|
let r = t(n);
|
|
6935
|
-
this.#
|
|
7278
|
+
this.#K = {
|
|
6936
7279
|
id: n.pointerId,
|
|
6937
7280
|
x: r.x,
|
|
6938
7281
|
y: r.y,
|
|
6939
7282
|
moved: !1
|
|
6940
7283
|
};
|
|
6941
|
-
let i = this.lastFrame?.draggable && (n.pointerType !== "mouse" || n.button === 0) ? this.pick(n) : null, a = i &&
|
|
7284
|
+
let i = this.lastFrame?.draggable && (n.pointerType !== "mouse" || n.button === 0) ? this.pick(n) : null, a = i && ia(i.node, "onDrag");
|
|
6942
7285
|
if (!i || !a) {
|
|
6943
|
-
this.#
|
|
7286
|
+
this.#G?.down(n);
|
|
6944
7287
|
return;
|
|
6945
7288
|
}
|
|
6946
7289
|
try {
|
|
@@ -6960,7 +7303,7 @@ var ui = {
|
|
|
6960
7303
|
delta: new z(),
|
|
6961
7304
|
event: n
|
|
6962
7305
|
};
|
|
6963
|
-
this.#
|
|
7306
|
+
this.#W = {
|
|
6964
7307
|
drag: c,
|
|
6965
7308
|
id: n.pointerId,
|
|
6966
7309
|
x: o.x,
|
|
@@ -6969,18 +7312,18 @@ var ui = {
|
|
|
6969
7312
|
started: !1
|
|
6970
7313
|
};
|
|
6971
7314
|
}, o = (e) => {
|
|
6972
|
-
if (this.#
|
|
6973
|
-
this.#
|
|
7315
|
+
if (this.#K?.moved) {
|
|
7316
|
+
this.#K = null;
|
|
6974
7317
|
return;
|
|
6975
7318
|
}
|
|
6976
7319
|
if (!this.#C.click.size && !this.lastFrame?.interactive) return;
|
|
6977
7320
|
let t = this.pick(e);
|
|
6978
|
-
if (t) for (let e of
|
|
7321
|
+
if (t) for (let e of ua(t.node, "click")) e(t);
|
|
6979
7322
|
for (let n of this.#C.click) n(t, e);
|
|
6980
7323
|
};
|
|
6981
7324
|
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
7325
|
let s = () => {
|
|
6983
|
-
this.#
|
|
7326
|
+
this.#J = null;
|
|
6984
7327
|
};
|
|
6985
7328
|
if (e.addEventListener("wheel", s, { passive: !0 }), this.#b.push(() => {
|
|
6986
7329
|
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 +7336,9 @@ var ui = {
|
|
|
6993
7336
|
let c = globalThis.matchMedia?.("(prefers-reduced-motion: reduce)");
|
|
6994
7337
|
if (c) {
|
|
6995
7338
|
let e = () => {
|
|
6996
|
-
this.#
|
|
7339
|
+
this.#z = c.matches, this.invalidate();
|
|
6997
7340
|
};
|
|
6998
|
-
this.#
|
|
7341
|
+
this.#z = c.matches, c.addEventListener?.("change", e), this.#b.push(() => c.removeEventListener?.("change", e));
|
|
6999
7342
|
}
|
|
7000
7343
|
if (typeof IntersectionObserver < "u") {
|
|
7001
7344
|
let t = new IntersectionObserver(([e]) => {
|
|
@@ -7004,8 +7347,8 @@ var ui = {
|
|
|
7004
7347
|
t.observe(e), this.#b.push(() => t.disconnect());
|
|
7005
7348
|
}
|
|
7006
7349
|
}
|
|
7007
|
-
#
|
|
7008
|
-
let n = this.#
|
|
7350
|
+
#Te(e, t) {
|
|
7351
|
+
let n = this.#W;
|
|
7009
7352
|
if (!n || e.pointerId !== n.id) return;
|
|
7010
7353
|
let { drag: r } = n;
|
|
7011
7354
|
if (r.event = e, r.ray = this.rayAt(t.x, t.y), !n.started) {
|
|
@@ -7025,19 +7368,19 @@ var ui = {
|
|
|
7025
7368
|
let i = r.ray.intersectPlane(r.plane.normal, r.plane.point);
|
|
7026
7369
|
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
7370
|
}
|
|
7028
|
-
#
|
|
7029
|
-
let t = this.#
|
|
7371
|
+
#Ee(e) {
|
|
7372
|
+
let t = this.#W;
|
|
7030
7373
|
if (t && e.pointerId === t.id) {
|
|
7031
|
-
this.#
|
|
7374
|
+
this.#W = null;
|
|
7032
7375
|
try {
|
|
7033
7376
|
this.canvas.releasePointerCapture(e.pointerId);
|
|
7034
7377
|
} catch {}
|
|
7035
7378
|
t.started && (t.drag.phase = "end", t.drag.event = e, t.drag.node.onDrag?.(t.drag), this.canvas.style.cursor = "", this.invalidate());
|
|
7036
7379
|
}
|
|
7037
7380
|
}
|
|
7038
|
-
#
|
|
7039
|
-
this.#
|
|
7040
|
-
let t = this.#
|
|
7381
|
+
#De(e) {
|
|
7382
|
+
this.#Q || (this.#Q = !0, console.info("phoria2: the scene has no lights, so the View is lighting it (autoLight: false turns this off)"));
|
|
7383
|
+
let t = this.#X, n = this.#Z;
|
|
7041
7384
|
e.lights.push({
|
|
7042
7385
|
kind: "hemisphere",
|
|
7043
7386
|
node: t,
|
|
@@ -7053,15 +7396,15 @@ var ui = {
|
|
|
7053
7396
|
});
|
|
7054
7397
|
}
|
|
7055
7398
|
};
|
|
7056
|
-
function
|
|
7399
|
+
function $i(e) {
|
|
7057
7400
|
return [
|
|
7058
7401
|
...e.position,
|
|
7059
7402
|
...e.target ?? [],
|
|
7060
7403
|
e.fov ?? e.height
|
|
7061
7404
|
];
|
|
7062
7405
|
}
|
|
7063
|
-
var
|
|
7064
|
-
function
|
|
7406
|
+
var ea = (e, t) => !!t && e.length === t.length && e.every((e, n) => e === t[n]);
|
|
7407
|
+
function ta(e) {
|
|
7065
7408
|
if (e.isEmpty()) return [];
|
|
7066
7409
|
if (e.min.equals(e.max)) return [e.min.toArray()];
|
|
7067
7410
|
let t = [];
|
|
@@ -7072,14 +7415,14 @@ function ji(e) {
|
|
|
7072
7415
|
]);
|
|
7073
7416
|
return t;
|
|
7074
7417
|
}
|
|
7075
|
-
var
|
|
7076
|
-
function
|
|
7418
|
+
var na = 4e3;
|
|
7419
|
+
function ra(e, t) {
|
|
7077
7420
|
e.updateWorld();
|
|
7078
7421
|
let n = [];
|
|
7079
7422
|
return e.eachShownTo(t, (e) => {
|
|
7080
7423
|
let t = e;
|
|
7081
|
-
if ("instanceMatrices" in t && t.count <=
|
|
7082
|
-
n.push(...
|
|
7424
|
+
if ("instanceMatrices" in t && t.count <= na) t.eachInstanceBox((e, t, r, i, a, o) => {
|
|
7425
|
+
n.push(...ta(new V([
|
|
7083
7426
|
e,
|
|
7084
7427
|
t,
|
|
7085
7428
|
r
|
|
@@ -7089,7 +7432,7 @@ function Ni(e, t) {
|
|
|
7089
7432
|
o
|
|
7090
7433
|
])));
|
|
7091
7434
|
});
|
|
7092
|
-
else if ((t.drawMode === "lines" || t.drawMode === "points") && t.geometry.vertexCount <=
|
|
7435
|
+
else if ((t.drawMode === "lines" || t.drawMode === "points") && t.geometry.vertexCount <= na) {
|
|
7093
7436
|
let e = t.geometry, r = e.positions, i = t.worldMatrix, a = e.indices ? e.vertexCount : e.drawnVertices;
|
|
7094
7437
|
for (let e = 0; e < a; e++) {
|
|
7095
7438
|
let t = r[e * 3], a = r[e * 3 + 1], o = r[e * 3 + 2];
|
|
@@ -7099,45 +7442,45 @@ function Ni(e, t) {
|
|
|
7099
7442
|
i[2] * t + i[6] * a + i[10] * o + i[14]
|
|
7100
7443
|
]);
|
|
7101
7444
|
}
|
|
7102
|
-
} else n.push(...
|
|
7445
|
+
} else n.push(...ta(e.expandBounds(new V())));
|
|
7103
7446
|
}), n;
|
|
7104
7447
|
}
|
|
7105
|
-
function
|
|
7448
|
+
function ia(e, t) {
|
|
7106
7449
|
for (let n = e; n; n = n.parent) if (n[t]) return n;
|
|
7107
7450
|
return null;
|
|
7108
7451
|
}
|
|
7109
|
-
function
|
|
7452
|
+
function aa(e) {
|
|
7110
7453
|
return {
|
|
7111
7454
|
position: e.position.clone(),
|
|
7112
7455
|
target: (e.target ?? new z()).clone(),
|
|
7113
7456
|
height: e.height
|
|
7114
7457
|
};
|
|
7115
7458
|
}
|
|
7116
|
-
function
|
|
7117
|
-
e.position.copy(t.position),
|
|
7459
|
+
function oa(e, t) {
|
|
7460
|
+
e.position.copy(t.position), sa(e, t.target), t.height !== void 0 && (e.height = t.height);
|
|
7118
7461
|
}
|
|
7119
|
-
function
|
|
7462
|
+
function sa(e, t) {
|
|
7120
7463
|
e.target ? e.target.copy(t) : e.target = t.clone();
|
|
7121
7464
|
}
|
|
7122
|
-
function
|
|
7465
|
+
function ca(e, t, n) {
|
|
7123
7466
|
let r = Math.max(-1, Math.min(1, e.dot(t)));
|
|
7124
7467
|
if (r > .9999) return e.clone().lerp(t, n).normalize();
|
|
7125
7468
|
if (r < -.9999) {
|
|
7126
7469
|
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 ?
|
|
7470
|
+
return n < .5 ? ca(e, i, n * 2) : ca(i, t, n * 2 - 1);
|
|
7128
7471
|
}
|
|
7129
7472
|
let i = Math.acos(r), a = Math.sin(i);
|
|
7130
7473
|
return e.clone().multiplyScalar(Math.sin((1 - n) * i) / a).add(t.clone().multiplyScalar(Math.sin(n * i) / a));
|
|
7131
7474
|
}
|
|
7132
|
-
function
|
|
7133
|
-
return e.index === null && !e.node.handlersFor(t).length ? [] :
|
|
7475
|
+
function la(e, t) {
|
|
7476
|
+
return e.index === null && !e.node.handlersFor(t).length ? [] : ua(e.node, t);
|
|
7134
7477
|
}
|
|
7135
|
-
function
|
|
7478
|
+
function ua(e, t) {
|
|
7136
7479
|
let n = [];
|
|
7137
7480
|
for (let r = e; r; r = r.parent) n.push(...r.handlersFor(t));
|
|
7138
7481
|
return n;
|
|
7139
7482
|
}
|
|
7140
|
-
function
|
|
7483
|
+
function da(e) {
|
|
7141
7484
|
if (e === void 0) {
|
|
7142
7485
|
let e = document.createElement("canvas");
|
|
7143
7486
|
return Object.assign(e.style, {
|
|
@@ -7154,26 +7497,44 @@ function Vi(e) {
|
|
|
7154
7497
|
}
|
|
7155
7498
|
return e instanceof HTMLCanvasElement || E("View", `'canvas' must be a <canvas> element or a selector, got ${j(e)}`), e;
|
|
7156
7499
|
}
|
|
7500
|
+
function fa(e) {
|
|
7501
|
+
if (e === !1 || e === null) return null;
|
|
7502
|
+
if (e === !0) return { ...Vi };
|
|
7503
|
+
(!e || typeof e != "object" || Array.isArray(e)) && E("View", `'debug' is true, false or { ${Hi.join(", ")} }, got ${j(e)}`), A("View", e, Hi, {
|
|
7504
|
+
helpers: "list what to draw: { lights: true, bounds: true, ... }",
|
|
7505
|
+
fps: "use 'stats: true'",
|
|
7506
|
+
wireframe: "use new Lines({ geometry: edges(geometry) }) for a wireframe"
|
|
7507
|
+
}, "debug");
|
|
7508
|
+
let t = {};
|
|
7509
|
+
for (let n of Hi) {
|
|
7510
|
+
let r = e[n];
|
|
7511
|
+
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");
|
|
7512
|
+
}
|
|
7513
|
+
return t;
|
|
7514
|
+
}
|
|
7515
|
+
function pa(e, t, n) {
|
|
7516
|
+
return typeof t != "boolean" && E("View", `debug.${e} is ${n}, got ${j(t)}`), t;
|
|
7517
|
+
}
|
|
7157
7518
|
// src/geometry/triangulate.js
|
|
7158
|
-
function
|
|
7519
|
+
function ma(e) {
|
|
7159
7520
|
let t = 0;
|
|
7160
7521
|
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
7522
|
return t;
|
|
7162
7523
|
}
|
|
7163
|
-
function
|
|
7524
|
+
function ha(e, t = []) {
|
|
7164
7525
|
let n = [...e], r = e.map((e, t) => t);
|
|
7165
|
-
|
|
7526
|
+
ma(e) < 0 && r.reverse();
|
|
7166
7527
|
let i = t.map((e) => {
|
|
7167
7528
|
let t = n.length;
|
|
7168
7529
|
n.push(...e);
|
|
7169
7530
|
let r = e.map((e, n) => t + n);
|
|
7170
|
-
return
|
|
7171
|
-
}).sort((e, t) =>
|
|
7172
|
-
for (let e of i) r =
|
|
7173
|
-
return
|
|
7531
|
+
return ma(e) > 0 && r.reverse(), r;
|
|
7532
|
+
}).sort((e, t) => ga(n, t) - ga(n, e));
|
|
7533
|
+
for (let e of i) r = _a(n, r, e, i);
|
|
7534
|
+
return ba(n, r);
|
|
7174
7535
|
}
|
|
7175
|
-
var
|
|
7176
|
-
function
|
|
7536
|
+
var ga = (e, t) => Math.max(...t.map((t) => e[t][0]));
|
|
7537
|
+
function _a(e, t, n, r) {
|
|
7177
7538
|
let i = 0;
|
|
7178
7539
|
n.forEach((t, r) => {
|
|
7179
7540
|
e[t][0] > e[n[i]][0] && (i = r);
|
|
@@ -7183,7 +7544,7 @@ function Gi(e, t, n, r) {
|
|
|
7183
7544
|
let s = -1, c = Infinity;
|
|
7184
7545
|
t.forEach((t, n) => {
|
|
7185
7546
|
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]) =>
|
|
7547
|
+
i >= c || o.some(([e, t]) => va(a, r, e, t)) || (s = n, c = i);
|
|
7187
7548
|
}), s < 0 && (s = 0);
|
|
7188
7549
|
let l = [...n.slice(i), ...n.slice(0, i)];
|
|
7189
7550
|
return [
|
|
@@ -7194,52 +7555,52 @@ function Gi(e, t, n, r) {
|
|
|
7194
7555
|
...t.slice(s + 1)
|
|
7195
7556
|
];
|
|
7196
7557
|
}
|
|
7197
|
-
function
|
|
7198
|
-
if (
|
|
7558
|
+
function va(e, t, n, r) {
|
|
7559
|
+
if (ya(e, n) || ya(e, r) || ya(t, n) || ya(t, r)) return !1;
|
|
7199
7560
|
let i = Q(n, r, e), a = Q(n, r, t), o = Q(e, t, n), s = Q(e, t, r);
|
|
7200
7561
|
return i * a < 0 && o * s < 0;
|
|
7201
7562
|
}
|
|
7202
|
-
var
|
|
7203
|
-
function
|
|
7563
|
+
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]);
|
|
7564
|
+
function ba(e, t) {
|
|
7204
7565
|
let n = [...t], r = [];
|
|
7205
7566
|
for (; n.length > 3;) {
|
|
7206
7567
|
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++)
|
|
7568
|
+
for (let r = 0; r < n.length && t < 0; r++) Sa(e, n, r) && (t = r);
|
|
7569
|
+
if (t < 0) for (let r = 0; r < n.length && t < 0; r++) xa(e, n, r) && (t = r);
|
|
7209
7570
|
t < 0 && (t = 0);
|
|
7210
7571
|
let i = n.length;
|
|
7211
7572
|
r.push(n[(t + i - 1) % i], n[t], n[(t + 1) % i]), n.splice(t, 1);
|
|
7212
7573
|
}
|
|
7213
7574
|
return n.length === 3 && r.push(...n), r;
|
|
7214
7575
|
}
|
|
7215
|
-
function
|
|
7576
|
+
function xa(e, t, n) {
|
|
7216
7577
|
let r = t.length;
|
|
7217
7578
|
return Q(e[t[(n + r - 1) % r]], e[t[n]], e[t[(n + 1) % r]]) > 0;
|
|
7218
7579
|
}
|
|
7219
|
-
function
|
|
7220
|
-
if (!
|
|
7580
|
+
function Sa(e, t, n) {
|
|
7581
|
+
if (!xa(e, t, n)) return !1;
|
|
7221
7582
|
let r = t.length, i = e[t[(n + r - 1) % r]], a = e[t[n]], o = e[t[(n + 1) % r]];
|
|
7222
7583
|
for (let n of t) {
|
|
7223
7584
|
let t = e[n];
|
|
7224
|
-
if (!(
|
|
7585
|
+
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
7586
|
}
|
|
7226
7587
|
return !0;
|
|
7227
7588
|
}
|
|
7228
7589
|
// src/geometry/generators.js
|
|
7229
|
-
var
|
|
7590
|
+
var Ca = /* @__PURE__ */ t({
|
|
7230
7591
|
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
|
-
}),
|
|
7592
|
+
axes: () => Ba,
|
|
7593
|
+
box: () => Ea,
|
|
7594
|
+
cylinder: () => Aa,
|
|
7595
|
+
edges: () => za,
|
|
7596
|
+
extrude: () => Fa,
|
|
7597
|
+
grid: () => Va,
|
|
7598
|
+
icosphere: () => Na,
|
|
7599
|
+
lathe: () => Pa,
|
|
7600
|
+
plane: () => ka,
|
|
7601
|
+
sphere: () => Oa,
|
|
7602
|
+
torus: () => Ma
|
|
7603
|
+
}), wa = Math.PI * 2, $ = {
|
|
7243
7604
|
box: [
|
|
7244
7605
|
"size",
|
|
7245
7606
|
"width",
|
|
@@ -7286,18 +7647,18 @@ var Zi = /* @__PURE__ */ t({
|
|
|
7286
7647
|
],
|
|
7287
7648
|
axes: ["size"],
|
|
7288
7649
|
grid: ["size", "divisions"]
|
|
7289
|
-
},
|
|
7290
|
-
function
|
|
7650
|
+
}, Ta = "has one 'segments' option, used for every face";
|
|
7651
|
+
function Ea(e) {
|
|
7291
7652
|
let t = "box()", n = I(t, e, $.box, (e) => ({ size: e }), {
|
|
7292
|
-
widthSegments: `box() ${
|
|
7293
|
-
heightSegments: `box() ${
|
|
7294
|
-
depthSegments: `box() ${
|
|
7653
|
+
widthSegments: `box() ${Ta}`,
|
|
7654
|
+
heightSegments: `box() ${Ta}`,
|
|
7655
|
+
depthSegments: `box() ${Ta}`
|
|
7295
7656
|
}), 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
7657
|
i,
|
|
7297
7658
|
a,
|
|
7298
7659
|
o
|
|
7299
|
-
], l = new
|
|
7300
|
-
for (let [e, t, n] of
|
|
7660
|
+
], l = new Ha();
|
|
7661
|
+
for (let [e, t, n] of Da) {
|
|
7301
7662
|
let r = l.count;
|
|
7302
7663
|
for (let r = 0; r <= s; r++) {
|
|
7303
7664
|
let i = r / s;
|
|
@@ -7320,7 +7681,7 @@ function ea(e) {
|
|
|
7320
7681
|
segments: s
|
|
7321
7682
|
});
|
|
7322
7683
|
}
|
|
7323
|
-
var
|
|
7684
|
+
var Da = [
|
|
7324
7685
|
[
|
|
7325
7686
|
[
|
|
7326
7687
|
1,
|
|
@@ -7424,15 +7785,15 @@ var ta = [
|
|
|
7424
7785
|
]
|
|
7425
7786
|
]
|
|
7426
7787
|
];
|
|
7427
|
-
function
|
|
7788
|
+
function Oa(e) {
|
|
7428
7789
|
let t = "sphere()", n = I(t, e, $.sphere, (e) => ({ radius: e }), {
|
|
7429
7790
|
widthSegments: "sphere(): use 'segments' for the divisions around the sphere",
|
|
7430
7791
|
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
|
|
7792
|
+
}), 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
7793
|
for (let e = 0; e <= a; e++) {
|
|
7433
7794
|
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
7795
|
for (let e = 0; e <= i; e++) {
|
|
7435
|
-
let a = n && e < i ? (e + .5) / i : e / i, l = e % i / i *
|
|
7796
|
+
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
7797
|
o.vertex(u * r, d * r, f * r, u, d, f, a, t);
|
|
7437
7798
|
}
|
|
7438
7799
|
}
|
|
@@ -7446,12 +7807,12 @@ function na(e) {
|
|
|
7446
7807
|
rings: a
|
|
7447
7808
|
});
|
|
7448
7809
|
}
|
|
7449
|
-
function
|
|
7810
|
+
function ka(e) {
|
|
7450
7811
|
let t = "plane()", n = I(t, e, $.plane, (e) => ({ size: e }), {
|
|
7451
7812
|
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
|
|
7813
|
+
widthSegments: `plane() ${Ta}`,
|
|
7814
|
+
heightSegments: `plane() ${Ta}`
|
|
7815
|
+
}), 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
7816
|
for (let e = 0; e <= o; e++) {
|
|
7456
7817
|
let t = e / o;
|
|
7457
7818
|
for (let e = 0; e <= o; e++) {
|
|
@@ -7466,7 +7827,7 @@ function ra(e) {
|
|
|
7466
7827
|
segments: o
|
|
7467
7828
|
});
|
|
7468
7829
|
}
|
|
7469
|
-
function
|
|
7830
|
+
function Aa(e) {
|
|
7470
7831
|
let t = "cylinder()", n = I(t, e, $.cylinder, null, {
|
|
7471
7832
|
radiusBottom: "cylinder(): use 'radius' for the bottom radius",
|
|
7472
7833
|
radialSegments: "cylinder(): use 'segments' for the divisions around the cylinder",
|
|
@@ -7475,18 +7836,18 @@ function ia(e) {
|
|
|
7475
7836
|
r === 0 && i === 0 && E(t, "'radius' and 'radiusTop' can't both be 0");
|
|
7476
7837
|
let a = L(t, "height", n.height, 1), o = R(t, "segments", n.segments, 32, 3), s = n.caps ?? !0;
|
|
7477
7838
|
typeof s != "boolean" && E(t, `'caps' must be true or false, got ${j(s)}`);
|
|
7478
|
-
let c =
|
|
7839
|
+
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
7840
|
for (let e = 0; e <= 1; e++) {
|
|
7480
7841
|
let t = e === 0 ? i : r, n = e === 0 ? a / 2 : -a / 2;
|
|
7481
7842
|
for (let r = 0; r <= o; r++) {
|
|
7482
|
-
let i = t === 0 && r < o ? (r + .5) / o : r / o, a = t === 0 ? i *
|
|
7843
|
+
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
7844
|
l.vertex(t * s, n, t * c, f * s, p, f * c, i, e);
|
|
7484
7845
|
}
|
|
7485
7846
|
}
|
|
7486
7847
|
return l.grid(0, o, 1, {
|
|
7487
7848
|
pinchTop: i === 0,
|
|
7488
7849
|
pinchBottom: r === 0
|
|
7489
|
-
}), s && (i > 0 &&
|
|
7850
|
+
}), 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
7851
|
type: "cylinder",
|
|
7491
7852
|
radius: r,
|
|
7492
7853
|
radiusTop: i,
|
|
@@ -7496,10 +7857,10 @@ function ia(e) {
|
|
|
7496
7857
|
...c !== "y" && { axis: c }
|
|
7497
7858
|
});
|
|
7498
7859
|
}
|
|
7499
|
-
function
|
|
7860
|
+
function ja(e, t, n, r, i) {
|
|
7500
7861
|
let a = e.vertex(0, n, 0, 0, r, 0, .5, .5);
|
|
7501
7862
|
for (let a = 0; a < i; a++) {
|
|
7502
|
-
let o = a / i *
|
|
7863
|
+
let o = a / i * wa, s = Math.sin(o), c = Math.cos(o);
|
|
7503
7864
|
e.vertex(t * s, n, t * c, 0, r, 0, .5 + s / 2, .5 + r * c / 2);
|
|
7504
7865
|
}
|
|
7505
7866
|
for (let t = 0; t < i; t++) {
|
|
@@ -7507,15 +7868,15 @@ function aa(e, t, n, r, i) {
|
|
|
7507
7868
|
r > 0 ? e.indices.push(a, n, o) : e.indices.push(a, o, n);
|
|
7508
7869
|
}
|
|
7509
7870
|
}
|
|
7510
|
-
function
|
|
7871
|
+
function Ma(e) {
|
|
7511
7872
|
let t = "torus()", n = I(t, e, $.torus, null, {
|
|
7512
7873
|
tubularSegments: "torus(): use 'segments' for the divisions around the ring",
|
|
7513
7874
|
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
|
|
7875
|
+
}), 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
7876
|
for (let e = 0; e <= o; e++) {
|
|
7516
|
-
let t = e / o, n = -(e % o / o) *
|
|
7877
|
+
let t = e / o, n = -(e % o / o) * wa, c = Math.cos(n), l = Math.sin(n);
|
|
7517
7878
|
for (let e = 0; e <= a; e++) {
|
|
7518
|
-
let n = e / a, o = e % a / a *
|
|
7879
|
+
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
7880
|
s.vertex(r * u + i * f, i * p, r * d + i * m, f, p, m, n, t);
|
|
7520
7881
|
}
|
|
7521
7882
|
}
|
|
@@ -7527,7 +7888,7 @@ function oa(e) {
|
|
|
7527
7888
|
tubeSegments: o
|
|
7528
7889
|
});
|
|
7529
7890
|
}
|
|
7530
|
-
function
|
|
7891
|
+
function Na(e) {
|
|
7531
7892
|
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
7893
|
let r = Math.hypot(e, t, n);
|
|
7533
7894
|
return o.push(e / r, t / r, n / r), o.length / 3 - 1;
|
|
@@ -7678,14 +8039,14 @@ function sa(e) {
|
|
|
7678
8039
|
detail: i
|
|
7679
8040
|
}, l;
|
|
7680
8041
|
}
|
|
7681
|
-
function
|
|
8042
|
+
function Pa(e) {
|
|
7682
8043
|
let t = "lathe()", n = I(t, e, $.lathe, null, {
|
|
7683
8044
|
divisions: "lathe(): use 'segments' for the divisions around the axis",
|
|
7684
8045
|
phiSegments: "lathe(): use 'segments' for the divisions around the axis",
|
|
7685
8046
|
profile: "lathe(): use 'points' for the profile, as [radius, y] pairs"
|
|
7686
|
-
}), r =
|
|
8047
|
+
}), r = Ra(t, "points", n.points, 2).map(([e, t]) => [Math.abs(e) < 1e-9 ? 0 : e, t]);
|
|
7687
8048
|
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 =
|
|
8049
|
+
let i = R(t, "segments", n.segments, 32, 3), a = Wa(t, n.axis, "y"), o = [];
|
|
7689
8050
|
for (let e = 0; e + 1 < r.length; e++) {
|
|
7690
8051
|
let [t, n] = r[e], [i, a] = r[e + 1], s = Math.hypot(i - t, a - n);
|
|
7691
8052
|
s !== 0 && o.push({
|
|
@@ -7696,9 +8057,9 @@ function ca(e) {
|
|
|
7696
8057
|
});
|
|
7697
8058
|
}
|
|
7698
8059
|
o.length || E(t, "'points' need at least two different points");
|
|
7699
|
-
let s = o.reduce((e, t) => e + t.len, 0), c = new
|
|
8060
|
+
let s = o.reduce((e, t) => e + t.len, 0), c = new Ha(), l = 0;
|
|
7700
8061
|
return o.forEach((e, t) => {
|
|
7701
|
-
let n =
|
|
8062
|
+
let n = La(o[t - 1]?.normal, e.normal), r = La(o[t + 1]?.normal, e.normal), a = c.count;
|
|
7702
8063
|
for (let [[t, a], [o, u], d] of [[
|
|
7703
8064
|
e.to,
|
|
7704
8065
|
r,
|
|
@@ -7708,7 +8069,7 @@ function ca(e) {
|
|
|
7708
8069
|
n,
|
|
7709
8070
|
1 - l / s
|
|
7710
8071
|
]]) for (let e = 0; e <= i; e++) {
|
|
7711
|
-
let n = e % i / i *
|
|
8072
|
+
let n = e % i / i * wa, r = Math.sin(n), s = Math.cos(n);
|
|
7712
8073
|
c.vertex(t * r, a, t * s, o * r, u, o * s, e / i, d);
|
|
7713
8074
|
}
|
|
7714
8075
|
c.grid(a, i, 1, {
|
|
@@ -7722,17 +8083,17 @@ function ca(e) {
|
|
|
7722
8083
|
...a !== "y" && { axis: a }
|
|
7723
8084
|
});
|
|
7724
8085
|
}
|
|
7725
|
-
function
|
|
8086
|
+
function Fa(e) {
|
|
7726
8087
|
let t = "extrude()", n = I(t, e, $.extrude, null, {
|
|
7727
8088
|
amount: "extrude(): use 'depth'",
|
|
7728
8089
|
points: "extrude(): use 'shape' for the outline, as [x, y] pairs",
|
|
7729
8090
|
outline: "extrude(): use 'shape' for the outline, as [x, y] pairs",
|
|
7730
8091
|
bevelEnabled: "extrude() has no bevel - round the shape's corners instead"
|
|
7731
|
-
}), r =
|
|
8092
|
+
}), r = Ga(Ra(t, "shape", n.shape, 3));
|
|
7732
8093
|
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) =>
|
|
8094
|
+
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
8095
|
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
|
|
8096
|
+
let h = f - d || 1, g = m - p || 1, _ = new Ha(), v = ha(c, l);
|
|
7736
8097
|
for (let [e, t] of [[s, 1], [-s, -1]]) {
|
|
7737
8098
|
let n = _.count;
|
|
7738
8099
|
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 +8105,7 @@ function la(e) {
|
|
|
7744
8105
|
return [(s - i) / c, -(o - r) / c];
|
|
7745
8106
|
}), i = n.reduce((e, t) => e + t, 0) || 1, a = 0;
|
|
7746
8107
|
for (let o = 0; o < t; o++) {
|
|
7747
|
-
let c = r[o], [l, u] = [
|
|
8108
|
+
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
8109
|
_.indices.push(v, y, b, v, b, x), a += n[o];
|
|
7749
8110
|
}
|
|
7750
8111
|
}
|
|
@@ -7756,13 +8117,13 @@ function la(e) {
|
|
|
7756
8117
|
...o !== "z" && { axis: o }
|
|
7757
8118
|
});
|
|
7758
8119
|
}
|
|
7759
|
-
var
|
|
7760
|
-
function
|
|
7761
|
-
if (!e || e[0] * t[0] + e[1] * t[1] <
|
|
8120
|
+
var Ia = Math.cos(Math.PI / 6);
|
|
8121
|
+
function La(e, t) {
|
|
8122
|
+
if (!e || e[0] * t[0] + e[1] * t[1] < Ia) return t;
|
|
7762
8123
|
let n = e[0] + t[0], r = e[1] + t[1], i = Math.hypot(n, r) || 1;
|
|
7763
8124
|
return [n / i, r / i];
|
|
7764
8125
|
}
|
|
7765
|
-
function
|
|
8126
|
+
function Ra(e, t, n, r) {
|
|
7766
8127
|
Array.isArray(n) || E(e, `'${t}' must be a list of [x, y] pairs, got ${j(n)}`);
|
|
7767
8128
|
let i = n;
|
|
7768
8129
|
return i.length < r && E(e, `'${t}' needs at least ${r} points, got ${i.length}`), i.map((n, r) => {
|
|
@@ -7771,7 +8132,7 @@ function fa(e, t, n, r) {
|
|
|
7771
8132
|
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
8133
|
});
|
|
7773
8134
|
}
|
|
7774
|
-
function
|
|
8135
|
+
function za(e, t = {}) {
|
|
7775
8136
|
e instanceof U || E("edges()", `expected a Geometry, got ${j(e)}`);
|
|
7776
8137
|
let { angle: n = 1 } = I("edges()", t, ["angle"], null);
|
|
7777
8138
|
n >= 0 && n < 180 || E("edges()", `'angle' is in degrees, 0 to under 180, got ${j(n)}`);
|
|
@@ -7813,7 +8174,7 @@ function pa(e, t = {}) {
|
|
|
7813
8174
|
indices: p
|
|
7814
8175
|
});
|
|
7815
8176
|
}
|
|
7816
|
-
function
|
|
8177
|
+
function Ba(e) {
|
|
7817
8178
|
let t = "axes()", n = L(t, "size", I(t, e, $.axes, (e) => ({ size: e })).size, 1), r = new U({
|
|
7818
8179
|
positions: [
|
|
7819
8180
|
0,
|
|
@@ -7861,7 +8222,7 @@ function ma(e) {
|
|
|
7861
8222
|
size: n
|
|
7862
8223
|
}, r;
|
|
7863
8224
|
}
|
|
7864
|
-
function
|
|
8225
|
+
function Va(e) {
|
|
7865
8226
|
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
8227
|
for (let e = 0; e <= i; e++) {
|
|
7867
8228
|
let t = -a + r * e / i;
|
|
@@ -7874,7 +8235,7 @@ function ha(e) {
|
|
|
7874
8235
|
divisions: i
|
|
7875
8236
|
}, s;
|
|
7876
8237
|
}
|
|
7877
|
-
var
|
|
8238
|
+
var Ha = class {
|
|
7878
8239
|
positions = [];
|
|
7879
8240
|
normals = [];
|
|
7880
8241
|
uvs = [];
|
|
@@ -7894,7 +8255,7 @@ var ga = class {
|
|
|
7894
8255
|
}
|
|
7895
8256
|
turn(e, t) {
|
|
7896
8257
|
if (e === t) return;
|
|
7897
|
-
let n =
|
|
8258
|
+
let n = Ua[e][t];
|
|
7898
8259
|
for (let e of [this.positions, this.normals]) for (let t = 0; t < e.length; t += 3) {
|
|
7899
8260
|
let [r, i, a] = n(e[t], e[t + 1], e[t + 2]);
|
|
7900
8261
|
e[t] = r, e[t + 1] = i, e[t + 2] = a;
|
|
@@ -7909,7 +8270,7 @@ var ga = class {
|
|
|
7909
8270
|
});
|
|
7910
8271
|
return a.source = e, a;
|
|
7911
8272
|
}
|
|
7912
|
-
},
|
|
8273
|
+
}, Ua = {
|
|
7913
8274
|
y: {
|
|
7914
8275
|
x: (e, t, n) => [
|
|
7915
8276
|
t,
|
|
@@ -7935,14 +8296,14 @@ var ga = class {
|
|
|
7935
8296
|
]
|
|
7936
8297
|
}
|
|
7937
8298
|
};
|
|
7938
|
-
function
|
|
8299
|
+
function Wa(e, t, n) {
|
|
7939
8300
|
return t === void 0 ? n : P(e, "axis", t, [
|
|
7940
8301
|
"x",
|
|
7941
8302
|
"y",
|
|
7942
8303
|
"z"
|
|
7943
8304
|
]);
|
|
7944
8305
|
}
|
|
7945
|
-
function
|
|
8306
|
+
function Ga(e) {
|
|
7946
8307
|
let t = e.filter((t, n) => {
|
|
7947
8308
|
let r = e[(n + e.length - 1) % e.length];
|
|
7948
8309
|
return t[0] !== r[0] || t[1] !== r[1];
|
|
@@ -7950,7 +8311,7 @@ function ya(e) {
|
|
|
7950
8311
|
return t.length >= 3 ? t : e;
|
|
7951
8312
|
}
|
|
7952
8313
|
// src/geometry/outline.js
|
|
7953
|
-
var
|
|
8314
|
+
var Ka = Math.PI * 2, qa = {
|
|
7954
8315
|
circle: [
|
|
7955
8316
|
"radius",
|
|
7956
8317
|
"segments",
|
|
@@ -7983,7 +8344,7 @@ var ba = Math.PI * 2, xa = {
|
|
|
7983
8344
|
"depth",
|
|
7984
8345
|
"center"
|
|
7985
8346
|
]
|
|
7986
|
-
},
|
|
8347
|
+
}, Ja = {
|
|
7987
8348
|
r: "use 'radius'",
|
|
7988
8349
|
x: "use center: [x, y]",
|
|
7989
8350
|
y: "use center: [x, y]",
|
|
@@ -7993,17 +8354,17 @@ var ba = Math.PI * 2, xa = {
|
|
|
7993
8354
|
cornerRadius: "use 'radius' for the corners' rounding",
|
|
7994
8355
|
n: "use 'sides' (polygon) or 'segments'"
|
|
7995
8356
|
};
|
|
7996
|
-
function
|
|
7997
|
-
let t = "outline.circle()", n =
|
|
8357
|
+
function Ya(e) {
|
|
8358
|
+
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
8359
|
return Array.from({ length: i }, (e, t) => {
|
|
7999
|
-
let n = t / i *
|
|
8360
|
+
let n = t / i * Ka;
|
|
8000
8361
|
return [a + Math.cos(n) * r, o + Math.sin(n) * r];
|
|
8001
8362
|
});
|
|
8002
8363
|
}
|
|
8003
|
-
function
|
|
8004
|
-
let t = "outline.rect()", n =
|
|
8364
|
+
function Xa(e) {
|
|
8365
|
+
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
8366
|
(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] =
|
|
8367
|
+
let s = R(t, "segments", n.segments, 8, 1), [c, l] = no(t, "center", n.center), u = i / 2, d = a / 2;
|
|
8007
8368
|
if (o === 0) return [
|
|
8008
8369
|
[c - u, l - d],
|
|
8009
8370
|
[c + u, l - d],
|
|
@@ -8038,26 +8399,26 @@ function wa(e) {
|
|
|
8038
8399
|
}
|
|
8039
8400
|
return f;
|
|
8040
8401
|
}
|
|
8041
|
-
function
|
|
8042
|
-
let t = "outline.polygon()", n =
|
|
8402
|
+
function Za(e) {
|
|
8403
|
+
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
8404
|
return Array.from({ length: i }, (e, t) => {
|
|
8044
|
-
let n = a + t / i *
|
|
8405
|
+
let n = a + t / i * Ka;
|
|
8045
8406
|
return [o + Math.cos(n) * r, s + Math.sin(n) * r];
|
|
8046
8407
|
});
|
|
8047
8408
|
}
|
|
8048
|
-
function
|
|
8049
|
-
let t = "outline.arc()", n =
|
|
8409
|
+
function Qa(e) {
|
|
8410
|
+
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
8411
|
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) /
|
|
8412
|
+
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
8413
|
return Array.from({ length: o + 1 }, (e, t) => {
|
|
8053
8414
|
let n = i + (a - i) * t / o;
|
|
8054
8415
|
return [s + Math.cos(n) * r, c + Math.sin(n) * r];
|
|
8055
8416
|
});
|
|
8056
8417
|
}
|
|
8057
|
-
function
|
|
8058
|
-
let t = "outline.gear()", n =
|
|
8418
|
+
function $a(e) {
|
|
8419
|
+
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
8420
|
a >= r && E(t, `'depth' must be less than the radius (${r}), got ${a}`);
|
|
8060
|
-
let [o, s] =
|
|
8421
|
+
let [o, s] = no(t, "center", n.center), c = r - a, l = Ka / i, u = [];
|
|
8061
8422
|
for (let e = 0; e < i; e++) for (let [t, n] of [
|
|
8062
8423
|
[0, c],
|
|
8063
8424
|
[.12, r],
|
|
@@ -8069,43 +8430,43 @@ function Da(e) {
|
|
|
8069
8430
|
}
|
|
8070
8431
|
return u;
|
|
8071
8432
|
}
|
|
8072
|
-
var
|
|
8073
|
-
circle:
|
|
8074
|
-
rect:
|
|
8075
|
-
polygon:
|
|
8076
|
-
arc:
|
|
8077
|
-
gear:
|
|
8078
|
-
},
|
|
8079
|
-
function
|
|
8433
|
+
var eo = {
|
|
8434
|
+
circle: Ya,
|
|
8435
|
+
rect: Xa,
|
|
8436
|
+
polygon: Za,
|
|
8437
|
+
arc: Qa,
|
|
8438
|
+
gear: $a
|
|
8439
|
+
}, to = (e, t, n, r) => I(e, t, n, r, Ja);
|
|
8440
|
+
function no(e, t, n) {
|
|
8080
8441
|
if (n === void 0) return [0, 0];
|
|
8081
8442
|
let r = n;
|
|
8082
8443
|
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
8444
|
}
|
|
8084
8445
|
// src/geometry/fromPolygons.js
|
|
8085
|
-
var
|
|
8086
|
-
function
|
|
8087
|
-
A(
|
|
8446
|
+
var ro = "fromPolygons()";
|
|
8447
|
+
function io(e) {
|
|
8448
|
+
A(ro, e, [
|
|
8088
8449
|
"points",
|
|
8089
8450
|
"polygons",
|
|
8090
8451
|
"edges",
|
|
8091
8452
|
"smooth"
|
|
8092
8453
|
]);
|
|
8093
8454
|
let { points: t, polygons: n } = e ?? {};
|
|
8094
|
-
Array.isArray(t) || E(
|
|
8455
|
+
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
8456
|
let r = t.map((e, t) => {
|
|
8096
8457
|
let n = Array.isArray(e) ? e : e && typeof e == "object" ? [
|
|
8097
8458
|
e.x,
|
|
8098
8459
|
e.y,
|
|
8099
8460
|
e.z
|
|
8100
8461
|
] : null;
|
|
8101
|
-
return n && n.length === 3 && n.every(Number.isFinite) || E(
|
|
8462
|
+
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
8463
|
});
|
|
8103
8464
|
n.forEach((e, t) => {
|
|
8104
8465
|
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(
|
|
8466
|
+
(!Array.isArray(n) || n.length < 3) && E(ro, `polygon ${t} needs 'vertices' with 3 or more point indices, got ${j(n)}`);
|
|
8467
|
+
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
8468
|
let i = e.uvs;
|
|
8108
|
-
i === void 0 || Array.isArray(i) && i.length === n.length * 2 && i.every(Number.isFinite) || E(
|
|
8469
|
+
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
8470
|
});
|
|
8110
8471
|
let i = [];
|
|
8111
8472
|
n.forEach(({ vertices: e }, t) => {
|
|
@@ -8129,29 +8490,29 @@ function Ma(e) {
|
|
|
8129
8490
|
return a.computeNormals({ flat: !(e.smooth && !o) });
|
|
8130
8491
|
}
|
|
8131
8492
|
// src/geometry/Curve.js
|
|
8132
|
-
var
|
|
8493
|
+
var ao = ["closed", "tension"], oo = {
|
|
8133
8494
|
loop: "use 'closed: true'",
|
|
8134
8495
|
smooth: "the curve is always smooth - 'tension' (0-1) sets how tight"
|
|
8135
|
-
},
|
|
8496
|
+
}, so = ["segments", "dash"], co = { dashed: "use 'dash: [on, off]' - lengths in the curve's units" }, lo = [
|
|
8136
8497
|
"radius",
|
|
8137
8498
|
"segments",
|
|
8138
8499
|
"sides"
|
|
8139
|
-
],
|
|
8500
|
+
], uo = {
|
|
8140
8501
|
tubularSegments: "use 'segments'",
|
|
8141
8502
|
radialSegments: "use 'sides'"
|
|
8142
|
-
},
|
|
8503
|
+
}, fo = [
|
|
8143
8504
|
"plane",
|
|
8144
8505
|
"radius",
|
|
8145
8506
|
"center",
|
|
8146
8507
|
"tilt"
|
|
8147
|
-
],
|
|
8508
|
+
], po = 48, mo = class {
|
|
8148
8509
|
#e;
|
|
8149
8510
|
#t;
|
|
8150
8511
|
#n;
|
|
8151
8512
|
#r;
|
|
8152
8513
|
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() *
|
|
8514
|
+
(!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);
|
|
8515
|
+
let n = this.#i() * po;
|
|
8155
8516
|
this.#r = new Float64Array(n + 1);
|
|
8156
8517
|
let r = this.#s(0);
|
|
8157
8518
|
for (let e = 1; e <= n; e++) {
|
|
@@ -8177,7 +8538,7 @@ var Na = ["closed", "tension"], Pa = {
|
|
|
8177
8538
|
return Array.from({ length: t }, (e, t) => this.at(t / n));
|
|
8178
8539
|
}
|
|
8179
8540
|
line(e = {}) {
|
|
8180
|
-
A("curve.line()", e,
|
|
8541
|
+
A("curve.line()", e, so, co);
|
|
8181
8542
|
let t = this.#a("curve.line()", e.segments), n = this.length / t, r = [], i = (e, t) => {
|
|
8182
8543
|
let i = Math.max(1, Math.ceil((t - e) / n - 1e-9)), a = this.at(e / this.length);
|
|
8183
8544
|
for (let n = 1; n <= i; n++) {
|
|
@@ -8194,7 +8555,7 @@ var Na = ["closed", "tension"], Pa = {
|
|
|
8194
8555
|
return new U({ positions: r });
|
|
8195
8556
|
}
|
|
8196
8557
|
tube(e = {}) {
|
|
8197
|
-
A("curve.tube()", e,
|
|
8558
|
+
A("curve.tube()", e, lo, uo);
|
|
8198
8559
|
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
8560
|
0,
|
|
8200
8561
|
1,
|
|
@@ -8249,17 +8610,17 @@ var Na = ["closed", "tension"], Pa = {
|
|
|
8249
8610
|
return t;
|
|
8250
8611
|
}
|
|
8251
8612
|
};
|
|
8252
|
-
function
|
|
8253
|
-
return new
|
|
8613
|
+
function ho(e, t) {
|
|
8614
|
+
return new mo(e, t);
|
|
8254
8615
|
}
|
|
8255
|
-
function
|
|
8616
|
+
function go(e = {}) {
|
|
8256
8617
|
let t = e.plane === void 0 ? "xz" : P("ellipse()", "plane", e.plane, [
|
|
8257
8618
|
"xz",
|
|
8258
8619
|
"xy",
|
|
8259
8620
|
"yz"
|
|
8260
8621
|
]), [n, r] = [...t].map((e) => "xyz".indexOf(e)), i = (e) => `radius${"XYZ"[e]}`, a = i(3 - n - r);
|
|
8261
8622
|
A("ellipse()", e, [
|
|
8262
|
-
...
|
|
8623
|
+
...fo,
|
|
8263
8624
|
i(n),
|
|
8264
8625
|
i(r)
|
|
8265
8626
|
], { [a]: `an ellipse in '${t}' has '${i(n)}' and '${i(r)}' - set plane for another` });
|
|
@@ -8274,21 +8635,21 @@ function Ua(e = {}) {
|
|
|
8274
8635
|
];
|
|
8275
8636
|
f[n] = 1;
|
|
8276
8637
|
let p = Ee(/* @__PURE__ */ new Float32Array(4), f, d);
|
|
8277
|
-
return new
|
|
8638
|
+
return new mo(Array.from({ length: 64 }, (e, t) => {
|
|
8278
8639
|
let i = t / 64 * Math.PI * 2, a = new z();
|
|
8279
8640
|
return a[n] = Math.cos(i) * c, a[r] = Math.sin(i) * l, a.applyQuaternion(p).add(u);
|
|
8280
8641
|
}), { closed: !0 });
|
|
8281
8642
|
}
|
|
8282
8643
|
// src/registry.js
|
|
8283
|
-
var
|
|
8284
|
-
function
|
|
8285
|
-
|
|
8644
|
+
var _o = /* @__PURE__ */ new Map();
|
|
8645
|
+
function vo(e) {
|
|
8646
|
+
_o.set(e.type, e);
|
|
8286
8647
|
}
|
|
8287
|
-
function
|
|
8288
|
-
return
|
|
8648
|
+
function yo() {
|
|
8649
|
+
return _o;
|
|
8289
8650
|
}
|
|
8290
8651
|
// src/describe.js
|
|
8291
|
-
var
|
|
8652
|
+
var bo = [
|
|
8292
8653
|
"box",
|
|
8293
8654
|
"sphere",
|
|
8294
8655
|
"plane",
|
|
@@ -8299,27 +8660,27 @@ var qa = [
|
|
|
8299
8660
|
"extrude",
|
|
8300
8661
|
"axes",
|
|
8301
8662
|
"grid"
|
|
8302
|
-
],
|
|
8303
|
-
|
|
8663
|
+
], xo = null, So = () => {
|
|
8664
|
+
xo ??= new Map([
|
|
8304
8665
|
K,
|
|
8305
|
-
|
|
8306
|
-
|
|
8307
|
-
|
|
8308
|
-
|
|
8309
|
-
|
|
8310
|
-
|
|
8311
|
-
|
|
8312
|
-
|
|
8313
|
-
|
|
8314
|
-
|
|
8315
|
-
|
|
8316
|
-
|
|
8317
|
-
|
|
8318
|
-
|
|
8666
|
+
St,
|
|
8667
|
+
gr,
|
|
8668
|
+
Nt,
|
|
8669
|
+
zt,
|
|
8670
|
+
Bt,
|
|
8671
|
+
Ht,
|
|
8672
|
+
Ut,
|
|
8673
|
+
jn,
|
|
8674
|
+
Mn,
|
|
8675
|
+
xr,
|
|
8676
|
+
Sr,
|
|
8677
|
+
wr,
|
|
8678
|
+
Tr,
|
|
8679
|
+
Er
|
|
8319
8680
|
].map((e) => [e.type, e]));
|
|
8320
|
-
for (let [e, t] of
|
|
8321
|
-
return
|
|
8322
|
-
},
|
|
8681
|
+
for (let [e, t] of yo()) xo.set(e, t);
|
|
8682
|
+
return xo;
|
|
8683
|
+
}, Co = {
|
|
8323
8684
|
Mesh: "mesh",
|
|
8324
8685
|
Group: "group",
|
|
8325
8686
|
Object3D: "node",
|
|
@@ -8337,10 +8698,10 @@ var qa = [
|
|
|
8337
8698
|
Scene: "scene",
|
|
8338
8699
|
light: "directional-light",
|
|
8339
8700
|
camera: "perspective-camera"
|
|
8340
|
-
},
|
|
8701
|
+
}, wo = {
|
|
8341
8702
|
chart: "import { chart } from 'phoria2/charts' first, which registers 'chart'",
|
|
8342
8703
|
emitter: "'emitter' descriptions aren't supported yet - use new Emitter() from 'phoria2/particles'"
|
|
8343
|
-
},
|
|
8704
|
+
}, To = {
|
|
8344
8705
|
cube: "box",
|
|
8345
8706
|
ball: "sphere",
|
|
8346
8707
|
globe: "sphere",
|
|
@@ -8360,29 +8721,29 @@ var qa = [
|
|
|
8360
8721
|
ExtrudeGeometry: "extrude",
|
|
8361
8722
|
ShapeGeometry: "extrude"
|
|
8362
8723
|
};
|
|
8363
|
-
function
|
|
8724
|
+
function Eo(e) {
|
|
8364
8725
|
if (/Material$/.test(e)) return "materials aren't nodes - give a mesh material: { color, roughness, metalness, ... }";
|
|
8365
|
-
let t =
|
|
8726
|
+
let t = To[e];
|
|
8366
8727
|
return t ? `geometry isn't a node - give a mesh geometry: { type: '${t}', ... }` : null;
|
|
8367
8728
|
}
|
|
8368
|
-
function
|
|
8729
|
+
function Do(e) {
|
|
8369
8730
|
if (e instanceof K) return e;
|
|
8370
8731
|
(!e || typeof e != "object" || Array.isArray(e)) && E("create()", `expected a description such as { type: 'mesh', ... }, got ${j(e)}`);
|
|
8371
8732
|
let { type: t, ...n } = e;
|
|
8372
|
-
typeof t != "string" && E("create()", `a description needs a 'type': one of ${[...
|
|
8373
|
-
let r =
|
|
8733
|
+
typeof t != "string" && E("create()", `a description needs a 'type': one of ${[...So().keys()].join(", ")}`);
|
|
8734
|
+
let r = So().get(t);
|
|
8374
8735
|
if (!r) {
|
|
8375
|
-
let e =
|
|
8376
|
-
E("create()", `unknown type '${t}' - ${e ? `use '${e}'` : n ?? `expected one of ${[...
|
|
8736
|
+
let e = Co[t], n = Eo(t) ?? wo[t];
|
|
8737
|
+
E("create()", `unknown type '${t}' - ${e ? `use '${e}'` : n ?? `expected one of ${[...So().keys()].join(", ")}${k(t, So().keys())}`}`);
|
|
8377
8738
|
}
|
|
8378
|
-
return Array.isArray(n.children) && (n.children = n.children.map((e) =>
|
|
8739
|
+
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
8740
|
}
|
|
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 =
|
|
8741
|
+
function Oo(e, t = "createGeometry()") {
|
|
8742
|
+
let { type: n, ...r } = e, i = To[n];
|
|
8743
|
+
i && E(t, `geometry type '${n}' - use '${i}'`), P(t, "geometry.type", n, bo);
|
|
8744
|
+
let a = Ca[n];
|
|
8384
8745
|
return a(Object.keys(r).length ? r : void 0);
|
|
8385
8746
|
}
|
|
8386
|
-
export {
|
|
8747
|
+
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
8748
|
|
|
8388
8749
|
//# sourceMappingURL=core.js.map
|