Mike0021's picture
CLOUDLINE: new renderer and city, remade sounds, social thumbnail
4a0989d verified
Raw History Blame Contribute Delete
36.7 kB
// First-person body rig, base scene builder and the SFX engine. // Extracted verbatim from the published EDGERUNNERS build (index-1sq5vsxc.js). // Generated by tools/extract-core.mjs — do not edit by hand. import { Object3D as B8, SRGBColorSpace as D9, Mesh as H8, ShapeUtils as I9, Fog as J7, Scene as K$, CylinderGeometry as K7, BoxGeometry as L6, Float32BufferAttribute as M8, CanvasTexture as N$, HemisphereLight as O$, DirectionalLight as R$, ShaderMaterial as X6, CapsuleGeometry as Z7, BufferGeometry as b8, Color as e0, SphereGeometry as e6, DoubleSide as e8, RepeatWrapping as n7, MeshStandardMaterial as n8, Vector2 as r0, BackSide as t8, Group as u8, Quaternion as w6, Vector3 as x, PlaneGeometry as xJ, } from "../vendor/three.module.min.js"; import { bodyPose as C$, BODY as D8, handPose as KX, CFG as k } from "./sim.js"; var W6 = new x(); class M7 extends b8 { type = "LoftGeometry"; parameters; constructor(J = [], $ = {}) { super(); let { closed: Q = !0, capStart: Z = !1, capEnd: K = !1 } = $; this.parameters = { sections: J, closed: Q, capStart: Z, capEnd: K }; let Y = J.length; if (Y < 2) { console.error("THREE.LoftGeometry: At least two sections are required."); return; } let U = J[0].length; for (let N = 1; N < Y; N++) if (J[N].length !== U) { console.error("THREE.LoftGeometry: All sections must have the same number of points."); return; } let X = Q ? U + 1 : U, W = [], H = [], q = []; for (let N = 0; N < Y; N++) { let O = J[N]; for (let M = 0; M < X; M++) { let V = O[M % U]; (H.push(V.x, V.y, V.z), q.push(N / (Y - 1), M / (X - 1))); } } for (let N = 0; N < Y - 1; N++) for (let O = 0; O < X - 1; O++) { let M = N * X + O, V = N * X + O + 1, G = (N + 1) * X + O + 1, R = (N + 1) * X + O; (W.push(M, V, R), W.push(V, G, R)); } if (Z === !0) F(0); if (K === !0) F(Y - 1); if ( (this.setIndex(W), this.setAttribute("position", new M8(H, 3)), this.setAttribute("uv", new M8(q, 2)), this.computeVertexNormals(), Q === !0) ) { let N = this.getAttribute("normal"); for (let O = 0; O < Y; O++) { let M = O * X, V = O * X + (X - 1); (W6.set(N.getX(M) + N.getX(V), N.getY(M) + N.getY(V), N.getZ(M) + N.getZ(V)).normalize(), N.setXYZ(M, W6.x, W6.y, W6.z), N.setXYZ(V, W6.x, W6.y, W6.z)); } } function F(N) { let O = J[N], M = new x(), V = new x(); for (let A = 0; A < U; A++) { let v = O[A], u = O[(A + 1) % U]; (M.add(v), (V.x += (v.y - u.y) * (v.z + u.z)), (V.y += (v.z - u.z) * (v.x + u.x)), (V.z += (v.x - u.x) * (v.y + u.y))); } (M.divideScalar(U), V.normalize()); let G = J[N === 0 ? 1 : Y - 2]; W6.set(0, 0, 0); for (let A = 0; A < U; A++) W6.add(G[A]); if ((W6.divideScalar(U).sub(M), V.dot(W6) > 0)) V.negate(); let R = new x(1, 0, 0); if (Math.abs(V.x) > 0.9) R.set(0, 1, 0); let B = new x().crossVectors(V, R).normalize(); R.crossVectors(B, V); let I = [], L = O.slice(); for (let A = 0; A < U; A++) (W6.subVectors(L[A], M), I.push(new r0(W6.dot(R), W6.dot(B)))); if (I9.isClockWise(I) === !0) (I.reverse(), L.reverse()); let w = I9.triangulateShape(I, []), z = new r0(1 / 0, 1 / 0), S = new r0(-1 / 0, -1 / 0); for (let A = 0; A < U; A++) (z.min(I[A]), S.max(I[A])); let E = Math.max(S.x - z.x, Number.EPSILON), _ = Math.max(S.y - z.y, Number.EPSILON), c = H.length / 3; for (let A = 0; A < U; A++) { let v = L[A]; (H.push(v.x, v.y, v.z), q.push((I[A].x - z.x) / E, (I[A].y - z.y) / _)); } for (let A = 0; A < w.length; A++) { let v = w[A]; W.push(c + v[0], c + v[1], c + v[2]); } } } copy(J) { return (super.copy(J), (this.parameters = Object.assign({}, J.parameters)), this); } } var R7 = D8.hand, m$ = 0.5 * R7; var bX = ["index", "middle", "ring", "pinky"], HG = { index: 0.41 * R7 * 0.93, middle: 0.41 * R7, ring: 0.41 * R7 * 0.95, pinky: 0.41 * R7 * 0.76 }, WG = { index: 0.0105, middle: 0.0108, ring: 0.0102, pinky: 0.0088 }, NG = [0.42, 0.32, 0.26], FK = [1, 0.88, 0.78], pX = { index: [0.0335, 0.003, -0.003], middle: [0.0112, -0.003, -0.004], ring: [-0.0112, 0, -0.003], pinky: [-0.0335, 0.0035, 0.0015], }, qG = { index: 0.1, middle: 0.02, ring: -0.06, pinky: -0.16 }, FG = { index: 0.85, middle: 0.95, ring: 1.1, pinky: 1.22 }, GG = { index: 0.03, middle: -0.02, ring: 0.015, pinky: -0.025 }, GK = [0.38, 0.52, 0.21], OK = [1.36, 1.75, 0.87], MK = [-0.07, 0.03, 0], g$ = [0.041, 0.03], p$ = [0.0128, 0.0108], hX = [0.76, 0.5, 0.25, 0, -0.25, -0.5, -0.76], OG = [0.82, 0.94, 1, 1, 1, 0.94, 0.82], MG = [!0, !1, !0, !1, !0, !1, !0]; function RG() { let J = ($, Q, Z, K, Y = 0) => { let U = [ [-Q, $, K * 0.55], [-Q * 0.5, $, K], [Q * 0.5, $, K], [Q, $, K * 0.55], [Q, $, -Z * 0.45], ]; for (let X = 0; X < hX.length; X++) U.push([Q * hX[X], $ - (MG[X] ? Y : 0), -Z * OG[X]]); return (U.push([-Q, $, -Z * 0.45]), U.map(([X, W, H]) => new x(X, W, H))); }; return new M7( [ J(-0.004, 0.044, 0.0165, 0.013, 0.0075), J(0.022, 0.0458, 0.019, 0.016), J(0.06, 0.038, 0.0155, 0.0145), J(0.082, 0.03, 0.0135, 0.0125), J(m$ + 0.002, 0.0215, 0.01, 0.01), ], { capStart: !0, capEnd: !0 }, ); } var VK = [0, 1, 2, 3, 4, 5].map((J) => { let $ = (J * Math.PI) / 3; return [Math.cos($), Math.sin($)]; }), ZJ = (J, $) => VK.map(([Q, Z]) => new x(J * Q, $, J * Z)), xX = (J, $, Q) => VK.map(([Z, K]) => new x(J * Z, $, J * K * (K < 0 ? Q : 1))); function RK(J, $, Q, Z) { let K = Z.mcp ? [ZJ(0.95 * J, 0.9 * J), xX(J, 0.15 * J, 1.35)] : [ZJ(0.9 * J, 0.3 * J), xX(J, 0.02 * J, 1.12)]; if ((K.push(ZJ(J, -0.7 * J), ZJ($, -(Q - 0.55 * $))), Z.tip)) K.push(ZJ(0.92 * $, -Q + 0.1 * $), ZJ(0.62 * $, -Q - 0.28 * $), ZJ(0.34 * $, -Q - 0.55 * $)); else K.push(ZJ(0.85 * $, -Q + 0.12 * $), ZJ(0.5 * $, -Q - 0.4 * $)); return new M7(K, { capStart: !0, capEnd: !0 }); } function gX() { let J = new x(0.016, 0.09, 0.003), $ = new x(0.048, 0.042, 0.01), Q = $.clone().sub(J).normalize(), Z = new x(0, 0, 1).cross(Q).normalize(), K = Q.clone().cross(Z), Y = [0.0055, 0.0125, 0.0135, 0.0075], U = Y.map((X, W) => { let H = J.clone().lerp($, W / (Y.length - 1)); return VK.map(([q, F]) => H.clone() .addScaledVector(Z, X * q) .addScaledVector(K, X * F), ); }); return new M7(U, { capStart: !0, capEnd: !0 }); } function VG(J) { let $ = J.attributes.position; for (let Z = 0; Z < $.count; Z++) $.setX(Z, -$.getX(Z)); let Q = J.index; for (let Z = 0; Z < Q.count; Z += 3) { let K = Q.getX(Z + 1); (Q.setX(Z + 1, Q.getX(Z + 2)), Q.setX(Z + 2, K)); } return (J.computeVertexNormals(), J); } function EG(J, $, Q) { let Z = HG[$], K = WG[$], Y = J === "L" ? 1 : -1, U = pX[$], X = new u8(); ((X.name = `f:${J}:${$}:mcp`), X.position.set(Y * U[0], U[1], U[2])); let W = X, H, q; for (let F = 0; F < 3; F++) { let N = Z * NG[F], O = K * FK[F], M = K * (FK[F + 1] ?? FK[2] * 0.82), V = new H8(RK(O, M, N, { mcp: F === 0, tip: F === 2 }), Q); if (((V.castShadow = !0), W.add(V), F < 2)) { let G = new u8(); if (((G.name = `f:${J}:${$}:${F === 0 ? "pip" : "dip"}`), G.position.set(0, -N, 0), W.add(G), F === 0)) H = G; else q = G; W = G; } else { let G = new B8(); ((G.name = `tip:${J}:${$}`), G.position.set(0, -N, 0), W.add(G)); } } return { root: X, pip: H, dip: q }; } function mX(J, $) { let Q = J === "L" ? 1 : -1, Z = new u8(); ((Z.name = `fist:hand${J}`), Z.scale.setScalar(1.07)); let K = new u8(); ((K.name = `palmframe:${J}`), Z.add(K)); let Y = new u8(); K.add(Y); let U = new H8(RG(), $); ((U.name = `palm:${J}`), (U.castShadow = !0), K.add(U)); let X = new H8(J === "L" ? gX() : VG(gX()), $); ((X.castShadow = !0), Y.add(X)); let W = new Map(); for (let B of bX) { let I = EG(J, B, $); (W.set(B, I), Z.add(I.root)); } let H = new u8(); ((H.name = `f:${J}:thumb:mcp`), H.position.set(Q * 0.045, 0.06, 0.006)); let q = new H8(RK(p$[0], p$[1] * 0.95, g$[0], { mcp: !0 }), $); ((q.castShadow = !0), H.add(q)); let F = new u8(); ((F.name = `f:${J}:thumb:pip`), F.position.set(0, -g$[0], 0), H.add(F)); let N = new H8(RK(p$[1], p$[1] * 0.78, g$[1], { tip: !0 }), $); ((N.castShadow = !0), F.add(N)); let O = new B8(); ((O.name = `tip:${J}:thumb`), O.position.set(0, -g$[1], 0), F.add(O), Y.add(H)); let M = (B, I) => { let L = Math.min(Math.max(B, -1), 1), w = Math.min(Math.max(I, 0), 1), z = Math.max(L, 0), S = Math.max(-L, 0), E = w * (1 - 0.8 * z), _ = -0.012 * S; K.position.z = _; for (let v of bX) { let u = W.get(v); u.root.position.z = pX[v][2] + _; let f = FG[v], n = GG[v], p = GK[0] * f + n, l = GK[1] * f + n * 0.5, Y0 = GK[2] * f + n * 0.5, q0 = L >= 0 ? p + (OK[0] - p) * z : p + (MK[0] - p) * S, V0 = L >= 0 ? l + (OK[1] - l) * z : l + (MK[1] - l) * S, w0 = L >= 0 ? Y0 + (OK[2] - Y0) * z : Y0 + (MK[2] - Y0) * S; (u.root.rotation.set(-q0, 0, Q * qG[v] * E), (u.pip.rotation.x = -V0), (u.dip.rotation.x = -w0)); } let c = -0.5 + 0.15 * z + 0.18 * S, A = Q * (0.88 - 0.78 * z + 0.18 * S); (H.rotation.set(c, Q * (-0.3 - 0.3 * z), A), (F.rotation.x = -(0.15 + 0.45 * z + 0.2 * S))); }; M(0.25, 0.5); let V = new x(0, 1, 0), G = new x(); return { group: Z, palm: U, side: J, setPose: M, aimPalm: (B, I) => { if (I < 0.00001) return; (G.copy(B).normalize(), K.quaternion.setFromUnitVectors(V, G)); let L = Math.min(Math.max(I / m$, 0.8), 1.4); ((U.scale.y = L), (Y.position.y = (L - 1) * m$)); }, nominalKnuckleLen: m$, }; } var Q8 = { length: 0.228, height: 0.142, soleH: 0.04, soleHalfW: 0.0485, upperHalfW: 0.0455, toeZ: -0.131, heelZ: 0.097, collarTopY: 0.142, collarHalfW: 0.031, patch: { w: 0.032, h: 0.026, d: 0.005, centerYFrac: 0.5 }, }, uX = new x(0, -0.027, 0.054), z9 = (J, $, Q, Z, K) => [ [-$, K, J], [-$ * 0.97, K + Q * 0.52, J], [-$ * Z, K + Q, J], [$ * Z, K + Q, J], [$ * 0.97, K + Q * 0.52, J], [$, K, J], ]; function kG(J, $, Q) { let Z = [], K = (X, W, H, q) => Z.push(...X, ...W, ...H, ...X, ...H, ...q); for (let X = 0; X < J.length - 1; X++) { let W = J[X], H = J[X + 1]; for (let q = 0; q < W.length - 1; q++) K(W[q], W[q + 1], H[q + 1], H[q]); K(W[W.length - 1], W[0], H[0], H[H.length - 1]); } let Y = (X, W) => { let H = X.reduce((O, M) => O + M[0], 0) / X.length, q = X.reduce((O, M) => O + M[1], 0) / X.length, F = X.reduce((O, M) => O + M[2], 0) / X.length, N = [H, q, F]; for (let O = 0; O < X.length; O++) { let M = (O + 1) % X.length; if (W) Z.push(...N, ...X[M], ...X[O]); else Z.push(...N, ...X[O], ...X[M]); } }; if ($) Y(J[0], !1); if (Q) Y(J[J.length - 1], !0); let U = new b8(); return (U.setAttribute("position", new M8(Z, 3)), U.computeVertexNormals(), U); } function DG() { let { soleHalfW: J, toeZ: $, heelZ: Q } = Q8, Z = [ [0, $], [J * 0.62, $ + 0.012], [J * 0.92, $ + 0.045], [J, $ + 0.095], [J, Q - 0.05], [J * 0.88, Q - 0.012], [J * 0.52, Q], [0, Q], ], K = [ ...Z, ...Z.slice(1, -1) .reverse() .map(([F, N]) => [-F, N]), ], Y = [], U = Q8.soleH, X = K.length; for (let F = 0; F < X; F++) { let [N, O] = K[F], [M, V] = K[(F + 1) % X]; Y.push(N, 0, O, M, 0, V, M, U, V, N, 0, O, M, U, V, N, U, O); } let W = 0, H = ($ + Q) / 2; for (let F = 0; F < X; F++) { let [N, O] = K[F], [M, V] = K[(F + 1) % X]; (Y.push(W, U, H, N, U, O, M, U, V), Y.push(W, 0, H, M, 0, V, N, 0, O)); } let q = new b8(); return (q.setAttribute("position", new M8(Y, 3)), q.computeVertexNormals(), q); } function IG() { let J = Q8.soleH - 0.004, $ = Q8.upperHalfW, Q = Q8.height - Q8.soleH, Z = [ z9(Q8.toeZ + 0.008, $ * 0.55, Q * 0.34, 0.6, J), z9(Q8.toeZ + 0.052, $ * 0.94, Q * 0.56, 0.56, J), z9(-0.022, $, Q * 0.66, 0.5, J), z9(0.034, $ * 0.985, Q * 0.9, 0.46, J), z9(Q8.heelZ - 0.024, $ * 0.94, Q, 0.52, J), z9(Q8.heelZ - 0.006, $ * 0.84, Q * 0.96, 0.5, J), ]; return kG(Z, !0, !0); } var u$ = { upper: new n8({ color: 13771310, roughness: 0.58, flatShading: !0, side: e8 }), sole: new n8({ color: 15790057, roughness: 0.85, flatShading: !0 }), }; function dX(J) { let $ = J === "L" ? -1 : 1, Q = new u8(); Q.name = `shoe:foot${J}`; let Z = new H8(DG(), u$.sole); ((Z.name = `sole:${J}`), (Z.castShadow = !0), Q.add(Z)); let K = new H8(IG(), u$.upper); ((K.name = `upper:${J}`), (K.castShadow = !0), Q.add(K)); let Y = new L6(Q8.patch.w, Q8.patch.h, Q8.patch.d), U = Q8.height * Q8.patch.centerYFrac, X = new H8(Y, u$.sole); ((X.name = `patch:heel:${J}`), X.position.set(0, U, Q8.heelZ - 0.005), (X.castShadow = !0), Q.add(X)); let W = new H8(Y, u$.sole); ((W.name = `patch:side:${J}`), W.position.set($ * (Q8.upperHalfW * 0.985 - 0.0005), U, 0.052), (W.rotation.y = (Math.PI / 2) * $), (W.castShadow = !0), Q.add(W)); let H = (q, F, N, O) => { let M = new B8(); ((M.name = `mark:${q}:${J}`), M.position.set(F, N, O), Q.add(M)); }; return ( H("sole", $ * Q8.soleHalfW, Q8.soleH * 0.5, -0.012), H("soleback", 0, Q8.soleH * 0.5, Q8.heelZ - 0.004), H("solefront", 0, Q8.soleH * 0.5, Q8.toeZ + 0.004), H("upper", $ * Q8.upperHalfW * 0.93, Q8.soleH + (Q8.height - Q8.soleH) * 0.42, -0.035), H("upperfront", 0, Q8.soleH + 0.022, Q8.toeZ + 0.014), H("heelupper", 0, Q8.height * 0.74, Q8.heelZ - 0.004), H("heelpatch", 0, U, Q8.heelZ - 0.0025), H("sidepatch", $ * (Q8.upperHalfW * 0.985 + Q8.patch.d / 2), U, 0.052), { group: Q, side: J } ); } var T8 = { skin: new n8({ color: 14262396, roughness: 0.62 }), skinHand: new n8({ color: 14262396, roughness: 0.62, flatShading: !0, side: e8 }), shirt: new n8({ color: 16053489, roughness: 0.88 }), pants: new n8({ color: 2369326, roughness: 0.9 }), pantsFlat: new n8({ color: 2369326, roughness: 0.9, flatShading: !0 }), glove: new n8({ color: 1315860, roughness: 0.7 }), }, d$ = 0.76, l$ = 1; class EK { group = new u8(); hands = []; shoes = []; capsules; boxes; headMesh; up = new x(0, 1, 0); tmpDir = new x(); tmpOffset = new x(); tmpQuat = new w6(); constructor() { ((this.capsules = [ { from: "pelvis", to: "chest", r: 0.125, mat: T8.shirt, inset: 0.02 }, { from: "chest", to: "head", r: 0.042, mat: T8.skin, inset: 0.03 }, { from: "shoulderL", to: "elbowL", r: 0.055, mat: T8.shirt }, { from: "elbowL", to: "wristL", r: 0.052, mat: T8.shirt, t0: 0, t1: 0.78 }, { from: "elbowL", to: "wristL", r: 0.061, mat: T8.shirt, t0: 0.74, t1: 0.9, name: "cuff:L" }, { from: "elbowL", to: "wristL", r: 0.037, mat: T8.glove, t0: 0.88, t1: 1.08 }, { from: "shoulderR", to: "elbowR", r: 0.055, mat: T8.shirt }, { from: "elbowR", to: "wristR", r: 0.052, mat: T8.shirt, t0: 0, t1: 0.78 }, { from: "elbowR", to: "wristR", r: 0.061, mat: T8.shirt, t0: 0.74, t1: 0.9, name: "cuff:R" }, { from: "elbowR", to: "wristR", r: 0.037, mat: T8.glove, t0: 0.88, t1: 1.08 }, { from: "hipL", to: "kneeL", r: 0.078, rTip: 0.064, mat: T8.pantsFlat }, { from: "kneeL", to: "ankleL", r: 0.062, rTip: 0.05, mat: T8.pantsFlat, t0: 0, t1: d$, name: "hem:L" }, { from: "kneeL", to: "ankleL", r: 0.031, mat: T8.skin, t0: d$ - 0.04, t1: 1.06, name: "ankleskin:L" }, { from: "hipR", to: "kneeR", r: 0.078, rTip: 0.064, mat: T8.pantsFlat }, { from: "kneeR", to: "ankleR", r: 0.062, rTip: 0.05, mat: T8.pantsFlat, t0: 0, t1: d$, name: "hem:R" }, { from: "kneeR", to: "ankleR", r: 0.031, mat: T8.skin, t0: d$ - 0.04, t1: 1.06, name: "ankleskin:R" }, ]), (this.boxes = [ { joint: "pelvis", size: [0.3, 0.16, 0.18], offset: [0, 0.02, 0], mat: T8.pants }, { joint: "chest", size: [0.25, 0.15, 0.11], offset: [0, -0.11, 0.05], mat: T8.shirt }, ])); for (let J of this.capsules) { let $ = J.rTip ? new K7(J.rTip, J.r, 1, 6, 1) : new Z7(J.r, 1, 4, 12), Q = new H8($, J.mat); if (((Q.castShadow = !0), J.name)) Q.name = J.name; if (J.from === "chest" && J.to === "head") Q.layers.set(l$); ((J.mesh = Q), this.group.add(Q)); } for (let J of this.boxes) { let $ = new H8(new L6(...J.size), J.mat); (($.castShadow = !0), (J.mesh = $), this.group.add($)); } for (let J of ["elbowL", "elbowR", "kneeL", "kneeR", "shoulderL", "shoulderR"]) { let $ = J.startsWith("knee"), Q = $ ? 0.062 : J.startsWith("shoulder") ? 0.065 : 0.054, Z = $ ? T8.pantsFlat : T8.shirt, K = new H8(new e6(Q, $ ? 7 : 10, $ ? 5 : 8), Z); ((K.castShadow = !0), (K.name = `ball:${J}`), this.group.add(K)); } for (let J of ["L", "R"]) { let $ = dX(J); (this.shoes.push($), this.group.add($.group)); for (let Q of ["ankleskin", "hemline"]) { let Z = new B8(); ((Z.name = `mark:${Q}:${J}`), this.group.add(Z)); } } for (let J of ["L", "R"]) { let $ = mX(J, T8.skinHand); (this.hands.push($), this.group.add($.group)); let Q = new H8(new e6(0.037, 10, 8), T8.glove); ((Q.castShadow = !0), (Q.name = `ball:wrist${J}`), this.group.add(Q)); } ((this.headMesh = new H8(new e6(D8.headR, 14, 12), new n8({ colorWrite: !1, depthWrite: !1 }))), (this.headMesh.castShadow = !0), this.group.add(this.headMesh)); } apply(J) { let $ = C$(J); for (let K of this.capsules) { let Y = $[K.from].pos, U = $[K.to].pos, X = K.t0 ?? 0, W = K.t1 ?? 1, H = Y.x + (U.x - Y.x) * X, q = Y.y + (U.y - Y.y) * X, F = Y.z + (U.z - Y.z) * X, N = Y.x + (U.x - Y.x) * W, O = Y.y + (U.y - Y.y) * W, M = Y.z + (U.z - Y.z) * W, V = K.mesh; this.tmpDir.set(N - H, O - q, M - F); let G = Math.max(0.02, this.tmpDir.length() - (K.inset ?? 0) * 2); (this.tmpDir.normalize(), this.tmpQuat.setFromUnitVectors(this.up, this.tmpDir), V.quaternion.copy(this.tmpQuat), V.position.set((H + N) / 2, (q + O) / 2, (F + M) / 2), V.scale.set(1, G, 1)); } for (let K of this.boxes) { let Y = $[K.joint], U = K.mesh; if ( (U.quaternion.set(Y.quat.x, Y.quat.y, Y.quat.z, Y.quat.w), U.position.set(Y.pos.x, Y.pos.y, Y.pos.z), K.offset[0] || K.offset[1] || K.offset[2]) ) (this.tmpOffset.set(K.offset[0], K.offset[1], K.offset[2]).applyQuaternion(U.quaternion), U.position.add(this.tmpOffset)); } for (let K of this.group.children) if (K.name.startsWith("ball:")) { let Y = $[K.name.slice(5)]; K.position.set(Y.pos.x, Y.pos.y, Y.pos.z); } else if (K.name.startsWith("fist:")) { let Y = $[K.name.slice(5)]; (K.position.set(Y.pos.x, Y.pos.y, Y.pos.z), K.quaternion.set(Y.quat.x, Y.quat.y, Y.quat.z, Y.quat.w)); } else if (K.name.startsWith("shoe:")) { let Y = $[K.name.slice(5)]; (K.quaternion.set(Y.quat.x, Y.quat.y, Y.quat.z, Y.quat.w), this.tmpOffset.copy(uX).applyQuaternion(K.quaternion), K.position.set(Y.pos.x + this.tmpOffset.x, Y.pos.y + this.tmpOffset.y, Y.pos.z + this.tmpOffset.z)); } else if (K.name.startsWith("mark:ankleskin:") || K.name.startsWith("mark:hemline:")) { let Y = K.name.endsWith(":L") ? "L" : "R", U = $[`knee${Y}`].pos, X = $[`ankle${Y}`].pos, W = K.name.startsWith("mark:ankleskin:") ? 0.84 : 0.62, H = K.name.startsWith("mark:ankleskin:") ? 0.031 : 0.055, q = Y === "L" ? -1 : 1; K.position.set(U.x + (X.x - U.x) * W + q * H, U.y + (X.y - U.y) * W, U.z + (X.z - U.z) * W); } let Q = KX(J); for (let K of this.hands) { let Y = $[`wrist${K.side}`].pos, U = $[`hand${K.side}`]; this.tmpDir.set(Y.x - U.pos.x, Y.y - U.pos.y, Y.z - U.pos.z); let X = this.tmpDir.length(); if ( (this.tmpQuat.set(U.quat.x, U.quat.y, U.quat.z, U.quat.w).invert(), K.aimPalm(this.tmpDir.applyQuaternion(this.tmpQuat), X), K.side === "L") ) K.setPose(Q.curlL, Q.spreadL); else K.setPose(Q.curlR, Q.spreadR); } let Z = $.head; return (this.headMesh.position.set(Z.pos.x, Z.pos.y, Z.pos.z), $); } } var lX = { white: 16185075, red: 14232352, orange: 16743711 }; function cX(J) { let $ = new K$(), Q = new e6(360, 24, 12), Z = new X6({ side: t8, depthWrite: !1, uniforms: { top: { value: new e0(3108816) }, horizon: { value: new e0(14478583) } }, vertexShader: "varying vec3 vPos; void main(){ vPos = position; gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0); }", fragmentShader: `varying vec3 vPos; uniform vec3 top; uniform vec3 horizon; void main(){ float h = clamp(normalize(vPos).y, 0.0, 1.0); gl_FragColor = vec4(mix(horizon, top, pow(h, 0.65)), 1.0); }`, }); ($.add(new H8(Q, Z)), ($.fog = new J7(14478583, 90, 320))); let K = new R$(16774374, 2.7); (K.position.set(38, 62, 26), (K.castShadow = !0), K.shadow.mapSize.set(4096, 4096), (K.shadow.camera.left = -70), (K.shadow.camera.right = 70), (K.shadow.camera.top = 70), (K.shadow.camera.bottom = -70), (K.shadow.camera.near = 10), (K.shadow.camera.far = 160), (K.shadow.bias = -0.0004), (K.shadow.normalBias = 0.025), $.add(K), $.add(new O$(12507378, 16777215, 0.85))); let Y = document.createElement("canvas"); Y.width = Y.height = 256; let U = Y.getContext("2d"); ((U.fillStyle = "#f2f2ef"), U.fillRect(0, 0, 256, 256), (U.strokeStyle = "#dadad6"), (U.lineWidth = 3), U.strokeRect(0, 0, 256, 256), (U.strokeStyle = "#e8e8e4"), (U.lineWidth = 1), U.beginPath(), U.moveTo(128, 0), U.lineTo(128, 256), U.moveTo(0, 128), U.lineTo(256, 128), U.stroke()); let X = new N$(Y); ((X.wrapS = X.wrapT = n7), X.repeat.set(110, 110), (X.anisotropy = 8), (X.colorSpace = D9)); let W = new H8(new xJ(440, 440), new n8({ map: X, roughness: 0.93, metalness: 0 })); ((W.rotation.x = -Math.PI / 2), (W.receiveShadow = !0), $.add(W)); for (let H of J.boxes) { if (H.color === "floor") continue; let q = new x(H.max.x - H.min.x, H.max.y - H.min.y, H.max.z - H.min.z), F = new H8(new L6(q.x, q.y, q.z), new n8({ color: lX[H.color] ?? 16185075, roughness: 0.85, metalness: 0 })); (F.position.set((H.min.x + H.max.x) / 2, (H.min.y + H.max.y) / 2, (H.min.z + H.max.z) / 2), (F.castShadow = !0), (F.receiveShadow = !0), $.add(F)); } for (let H of J.ramps ?? []) { let q = new H8(LG(H), new n8({ color: lX[H.color] ?? 16185075, roughness: 0.85, metalness: 0, side: e8 })); ((q.castShadow = !0), (q.receiveShadow = !0), $.add(q)); } return $; } function LG(J) { let $ = J.min.y, Q = J.max.y, Z, K, Y, U; switch (J.dir) { case "+x": ((Z = [J.min.x, $, J.min.z]), (K = [J.min.x, $, J.max.z]), (Y = [J.max.x, $, J.min.z]), (U = [J.max.x, $, J.max.z])); break; case "-x": ((Z = [J.max.x, $, J.min.z]), (K = [J.max.x, $, J.max.z]), (Y = [J.min.x, $, J.min.z]), (U = [J.min.x, $, J.max.z])); break; case "+z": ((Z = [J.min.x, $, J.min.z]), (K = [J.max.x, $, J.min.z]), (Y = [J.min.x, $, J.max.z]), (U = [J.max.x, $, J.max.z])); break; case "-z": ((Z = [J.min.x, $, J.max.z]), (K = [J.max.x, $, J.max.z]), (Y = [J.min.x, $, J.min.z]), (U = [J.max.x, $, J.min.z])); break; } let X = [Y[0], Q, Y[2]], W = [U[0], Q, U[2]], H = [ [Z, K, W], [Z, W, X], [Y, W, U], [Y, X, W], [Z, U, K], [Z, Y, U], [Z, X, Y], [K, U, W], ].flat(), q = new b8(); return (q.setAttribute("position", new M8(H.flat(), 3)), q.computeVertexNormals(), q); } var nX = { body: 0, hands: -2, slide: -6, footstep: -7, breath: -8, cloth: -16 }, kK = { stepWalk: -6, stepRun: -2, stepSprint: 0, stepWall: -1, landSoft: -8, landHard: -2, landCatchBody: 0, headBump: -6, slideEntry: -6, vaultPlant: -3, ledgeGrab: -3, handRegrip: -14, wallPush: -5, exhaleJump: -8, exhaleBoost: -7, gruntEffort: -6, gruntImpact: -2, breathIdle: -21, breathRun: -13, breathSprint: -8, breathRecover: -5, slideLoop: -4, clothMove: -4, }, DK = -4, iX = 0.07, oX = 1.2, sX = 0.045, w9 = (J) => Math.pow(10, J / 20); class aX { voices; loop; catGain; order = []; cursor = 0; lastPlay = -1e9; constructor(J, $, Q) { this.voices = J; this.loop = $; this.catGain = Q; } next() { if (this.cursor >= this.order.length) { let J = this.order.length ? this.order[this.order.length - 1] : -1, $ = this.voices.map((Q, Z) => Z); for (let Q = $.length - 1; Q > 0; Q--) { let Z = Math.floor(Math.random() * (Q + 1)); [$[Q], $[Z]] = [$[Z], $[Q]]; } if ($.length > 1 && $[0] === J) [$[0], $[1]] = [$[1], $[0]]; ((this.order = $), (this.cursor = 0)); } return this.voices[this.order[this.cursor++]]; } } class rX { ctx; voice; baseGain; src = null; gain; level = 0; constructor(J, $, Q, Z) { this.ctx = J; this.voice = $; this.baseGain = Q; ((this.gain = J.createGain()), (this.gain.gain.value = 0), this.gain.connect(Z)); } set(J, $) { if (J > 0.0005 && !this.src) { let Z = this.ctx.createBufferSource(); ((Z.buffer = this.voice.buffer), (Z.loop = !0), (Z.loopStart = this.voice.file.loopStart ?? 0), (Z.loopEnd = this.voice.file.loopEnd ?? this.voice.buffer.duration), Z.connect(this.gain), Z.start(0, Z.loopStart + Math.random() * Math.max(0, Z.loopEnd - Z.loopStart - 0.05)), (this.src = Z)); } this.level = J; let Q = this.gain.gain; if ( (Q.cancelScheduledValues(this.ctx.currentTime), Q.setValueAtTime(Q.value, this.ctx.currentTime), Q.linearRampToValueAtTime(J * this.baseGain, this.ctx.currentTime + $), J <= 0.0005 && this.src) ) { let Z = this.src; ((this.src = null), Z.stop(this.ctx.currentTime + $ + 0.05)); } } duck(J, $) { if (!this.src) return; let Q = this.gain.gain, Z = this.ctx.currentTime, K = this.level * this.baseGain; (Q.cancelScheduledValues(Z), Q.setValueAtTime(Q.value, Z), Q.linearRampToValueAtTime(K * (1 - J), Z + 0.04), Q.linearRampToValueAtTime(K, Z + 0.04 + $)); } } class tX { exertion = 0; recovering = !1; step(J, $) { let Q = Math.min(1, J.speedSmooth / k.sprintMaxSpeed) * (J.grounded || J.wallState > 0 ? 1 : 0.85) + (J.boostTime > 0 ? 0.25 : 0); if (Q > this.exertion) this.exertion = Math.min(Q, this.exertion + $ / 6); else { let Z = 3 + 5 * Math.min(1, Q / 0.6); this.exertion = Math.max(Q * 0.35, this.exertion - $ / Z); } if (this.recovering && this.exertion < 0.55) this.recovering = !1; } spike(J, $ = !1) { if (((this.exertion = Math.min($ ? 1.2 : 1, this.exertion + J)), $)) this.recovering = !0; } levels() { if (this.recovering) return [0, 0, 0, 1]; let J = this.exertion, $ = Math.min(1, Math.max(0, (J - 0.2) / 0.2)), Q = Math.min(1, Math.max(0, (J - 0.8) / 0.15)); return [1 - $, $ * (1 - Q), Q, 0]; } } class IK { ctx = null; master = null; cats = new Map(); pools = new Map(); beds = new Map(); breather = new tX(); ready = !1; failed = !1; muted = !1; prevVaultT = 0; prevShimmy = 0; prevTuck = 0; prevPress = 0; wasHanging = !1; unlock() { if (this.failed || this.ctx) { this.ctx?.resume(); return; } try { ((this.ctx = new AudioContext()), this.ctx.resume(), this.load()); } catch { this.failed = !0; } } toggleMute() { if (((this.muted = !this.muted), this.master && this.ctx)) this.master.gain.linearRampToValueAtTime(this.muted ? 0 : w9(DK), this.ctx.currentTime + 0.05); return this.muted; } async load() { let J = this.ctx; try { let $ = await (await fetch("/sfx/manifest.json")).json(), Q = J.createDynamicsCompressor(); ((Q.threshold.value = -6), (Q.knee.value = 8), (Q.ratio.value = 12), (Q.attack.value = 0.002), (Q.release.value = 0.12), Q.connect(J.destination), (this.master = J.createGain()), (this.master.gain.value = this.muted ? 0 : w9(DK)), this.master.connect(Q)); for (let [Y, U] of Object.entries(nX)) { let X = J.createGain(); ((X.gain.value = w9(U)), X.connect(this.master), this.cats.set(Y, X)); } let Z = Object.entries($).map(async ([Y, U]) => { let X = []; for (let W of U.files) { let H = await (await fetch(`/sfx/${W.file}`)).arrayBuffer(); X.push({ file: W, buffer: await J.decodeAudioData(H) }); } this.pools.set(Y, new aX(X, U.loop, this.cats.get(U.category))); }); await Promise.all(Z); let K = (Y, U) => { let X = this.pools.get(Y); if (!X?.voices.length) return; let W = X.voices[0]; this.beds.set(Y, new rX(this.ctx, W, w9(W.file.gainDb + kK[U]), X.catGain)); }; (K("breath-idle", "breathIdle"), K("breath-run", "breathRun"), K("breath-sprint", "breathSprint"), K("breath-recover", "breathRecover"), K("slide-loop", "slideLoop"), (this.ready = !0)); } catch { this.failed = !0; } } play(J, $, Q = {}) { if (!this.ready || !this.ctx) return; let Z = this.pools.get(J); if (!Z || Z.voices.length === 0) return; let K = this.ctx.currentTime; if (K - Z.lastPlay < iX) return; Z.lastPlay = K; let Y = Z.next(), U = this.ctx.createBufferSource(); ((U.buffer = Y.buffer), (U.playbackRate.value = (Q.rate ?? 1) * (1 + (Math.random() * 2 - 1) * sX))); let X = (Math.random() * 2 - 1) * oX, W = this.ctx.createGain(); ((W.gain.value = w9(Y.file.gainDb + $ + X)), U.connect(W)); let H = W; if (Q.pan) { let F = this.ctx.createStereoPanner(); ((F.pan.value = Q.pan), W.connect(F), (H = F)); } H.connect(Z.catGain); let q = K + (Q.delayS ?? 0); U.start(q, Y.file.trimStart, Math.max(0.03, Y.file.trimEnd - Y.file.trimStart)); } duckBreath(J = 0.75, $ = 0.3) { for (let Q of ["breath-idle", "breath-run", "breath-sprint", "breath-recover"]) this.beds.get(Q)?.duck(J, $); } onTick(J, $) { if (!this.ready || !this.ctx || this.ctx.state !== "running") return; let Q = 0.008333333333333333, Z = kK; this.breather.step($, Q); let [K, Y, U, X] = this.breather.levels(), W = (q, F, N) => { let O = this.beds.get(q); if (O && (Math.abs(F - O.level) > 0.02 || (F === 0 && O.level > 0))) O.set(F, N); }; if ( (W("breath-idle", K, 0.4), W("breath-run", Y, 0.4), W("breath-sprint", U, 0.4), W("breath-recover", X, 0.25), J.footstep) ) { let q = (J.footstep === "L" ? -1 : 1) * ($.wallState > 0 ? 0.3 * $.wallSide : 0.12); if ($.wallState > 0) this.play("step-wall", Z.stepWall, { pan: q }); else { let F = $.speedSmooth, N = F < 3.2 ? "step-walk" : F < 6.3 ? "step-run" : "step-sprint", O = F < 3.2 ? Z.stepWalk : F < 6.3 ? Z.stepRun : Z.stepSprint, M = (Math.min(1, F / k.sprintMaxSpeed) - 0.7) * 6; this.play(N, O + Math.max(-3, Math.min(2, M)), { pan: q }); } } if (J.jumped) (this.play("jump-takeoff", Z.stepSprint - 1), this.play("exhale-jump", Z.exhaleJump), this.play("cloth-move", Z.clothMove), this.duckBreath(), this.breather.spike(0.03)); if (J.hardLanded) (this.play("land-hard", Z.landCatchBody), this.play("palm-slap", Z.landCatchBody - 1, { delayS: 0.055 }), this.play("grunt-impact", Z.gruntImpact, { delayS: 0.09 }), this.play("cloth-move", Z.clothMove, { delayS: 0.03 }), this.breather.spike(0.6, !0), this.duckBreath(0.9, 0.8)); else if (J.landed !== void 0 && J.landed > 1.2) { let q = Math.max(-6, Math.min(6, (J.landed - 6) * 0.9)); if (J.landed < 5.5) this.play("land-soft", Z.landSoft + q); else (this.play("land-hard", Z.landHard + q), this.play("exhale-jump", Z.exhaleJump - 2, { delayS: 0.06 })); if (J.landed > 3) this.play("cloth-move", Z.clothMove); this.breather.spike(Math.min(0.12, J.landed * 0.015)); } if (J.headBump) this.play("head-bump", Z.headBump); if (J.grabbed !== void 0) { let q = Math.max(-4, Math.min(4, (J.grabbed - 5) * 0.7)); if ( (this.play("ledge-grab", Z.ledgeGrab + q), this.play("cloth-move", Z.clothMove, { delayS: 0.04 }), J.grabbed > 4) ) this.play("grunt-effort", Z.gruntEffort, { delayS: 0.12 }); (this.duckBreath(), this.breather.spike(0.08)); } if (J.climbStarted) (this.play("grunt-effort", Z.gruntEffort), this.play("cloth-move", Z.clothMove, { delayS: 0.1 }), this.duckBreath(), this.breather.spike(0.1)); if (J.climbEnded) this.play("land-soft", Z.landSoft - 6, { delayS: 0.02 }); if (J.dropped) this.play("cloth-move", Z.clothMove); if ($.ledgePhase === 1 && Math.floor($.shimmyPhase) > Math.floor(this.prevShimmy)) this.play("hand-regrip", Z.handRegrip, { pan: $.shimmyVel > 0 ? 0.2 : -0.2 }); if ( ((this.prevShimmy = $.ledgePhase === 1 ? $.shimmyPhase : 0), (this.wasHanging = $.ledgePhase === 1), J.vaulted !== void 0) ) (this.play("exhale-jump", Z.exhaleJump - 1), this.play("cloth-move", Z.clothMove), this.duckBreath(), this.breather.spike(0.06)); if ($.vaultState > 0 && this.prevVaultT < $.vaultT1 && $.vaultT >= $.vaultT1) this.play("vault-plant", Z.vaultPlant, { pan: $.vaultHands === 1 ? 0.15 : 0 }); if (((this.prevVaultT = $.vaultState > 0 ? $.vaultT : 0), J.wallStarted !== void 0)) (this.play("step-wall", Z.stepWall + 1, { pan: 0.3 * $.wallSide }), this.play("cloth-move", Z.clothMove), this.breather.spike(0.06)); if (J.wallJumped !== void 0) (this.play("wall-push", Z.wallPush, { pan: 0.25 * $.wallSide }), this.play("exhale-jump", Z.exhaleJump, { delayS: 0.03 }), this.duckBreath(), this.breather.spike(0.06)); if (J.slideStarted !== void 0) (this.play("slide-entry", Z.slideEntry + Math.max(-3, Math.min(3, (J.slideStarted - 6) * 0.6))), this.play("cloth-move", Z.clothMove)); let H = this.beds.get("slide-loop"); if (H) { let q = Math.min(1, Math.hypot($.vel.x, $.vel.z) / k.slideMinSpeed), F = $.slideState > 0 ? Math.min(1, $.slideFade) * Math.max(0.25, q) : 0; if (Math.abs(F - H.level) > 0.03 || (F === 0 && H.level > 0)) H.set(F, F > 0 ? 0.08 : 0.15); } if (J.boosted !== void 0) (this.play("exhale-boost", Z.exhaleBoost), this.duckBreath(), this.breather.spike(0.12)); if ($.tuckState > 0 && this.prevTuck === 0) this.play("cloth-move", Z.clothMove + 2); if (((this.prevTuck = $.tuckState), $.pressHit === 1 && this.prevPress === 0)) this.play("hand-regrip", Z.handRegrip + 2); this.prevPress = $.pressHit; } } export { EK as BodyView, IK as AudioEngine, cX as buildScene, LG as rampGeometry, lX as PALETTE, l$ as HEAD_LAYER };
// First-person body rig, base scene builder and the SFX engine.
// Extracted verbatim from the published EDGERUNNERS build (index-1sq5vsxc.js).
// Generated by tools/extract-core.mjs — do not edit by hand.
import {
Object3D as B8,
SRGBColorSpace as D9,
Mesh as H8,
ShapeUtils as I9,
Fog as J7,
Scene as K$,
CylinderGeometry as K7,
BoxGeometry as L6,
Float32BufferAttribute as M8,
CanvasTexture as N$,
HemisphereLight as O$,
DirectionalLight as R$,
ShaderMaterial as X6,
CapsuleGeometry as Z7,
BufferGeometry as b8,
Color as e0,
SphereGeometry as e6,
DoubleSide as e8,
RepeatWrapping as n7,
MeshStandardMaterial as n8,
Vector2 as r0,
BackSide as t8,
Group as u8,
Quaternion as w6,
Vector3 as x,
PlaneGeometry as xJ,
} from "../vendor/three.module.min.js";
import { bodyPose as C$, BODY as D8, handPose as KX, CFG as k } from "./sim.js";
var W6 = new x();
class M7 extends b8 {
type = "LoftGeometry";
parameters;
constructor(J = [], $ = {}) {
super();
let { closed: Q = !0, capStart: Z = !1, capEnd: K = !1 } = $;
this.parameters = { sections: J, closed: Q, capStart: Z, capEnd: K };
let Y = J.length;
if (Y < 2) {
console.error("THREE.LoftGeometry: At least two sections are required.");
return;
}
let U = J[0].length;
for (let N = 1; N < Y; N++)
if (J[N].length !== U) {
console.error("THREE.LoftGeometry: All sections must have the same number of points.");
return;
}
let X = Q ? U + 1 : U,
W = [],
H = [],
q = [];
for (let N = 0; N < Y; N++) {
let O = J[N];
for (let M = 0; M < X; M++) {
let V = O[M % U];
(H.push(V.x, V.y, V.z), q.push(N / (Y - 1), M / (X - 1)));
}
}
for (let N = 0; N < Y - 1; N++)
for (let O = 0; O < X - 1; O++) {
let M = N * X + O,
V = N * X + O + 1,
G = (N + 1) * X + O + 1,
R = (N + 1) * X + O;
(W.push(M, V, R), W.push(V, G, R));
}
if (Z === !0) F(0);
if (K === !0) F(Y - 1);
if (
(this.setIndex(W),
this.setAttribute("position", new M8(H, 3)),
this.setAttribute("uv", new M8(q, 2)),
this.computeVertexNormals(),
Q === !0)
) {
let N = this.getAttribute("normal");
for (let O = 0; O < Y; O++) {
let M = O * X,
V = O * X + (X - 1);
(W6.set(N.getX(M) + N.getX(V), N.getY(M) + N.getY(V), N.getZ(M) + N.getZ(V)).normalize(),
N.setXYZ(M, W6.x, W6.y, W6.z),
N.setXYZ(V, W6.x, W6.y, W6.z));
}
}
function F(N) {
let O = J[N],
M = new x(),
V = new x();
for (let A = 0; A < U; A++) {
let v = O[A],
u = O[(A + 1) % U];
(M.add(v),
(V.x += (v.y - u.y) * (v.z + u.z)),
(V.y += (v.z - u.z) * (v.x + u.x)),
(V.z += (v.x - u.x) * (v.y + u.y)));
}