Spaces:
Running
Running
feat: trigger-only jaw, tactile leather ball material
Browse files- The jaw no longer flaps on mode changes, rolls, kicks or colour
swaps: it is driven only by the analog gamepad triggers and the
RT-edge quack (which keeps its flap). Ghost jaw sync is untouched
since it broadcasts the same jawOpenNow value.
- The soccer ball gains a bump map derived from the same Voronoi panel
construction (seams as soft recessed grooves plus a fine leather
grain) and moves to MeshPhysicalMaterial with a touch of clearcoat
for a waxed vintage look.
Co-authored-by: Cursor <cursoragent@cursor.com>
- index.html +1 -1
- rl.js +48 -18
index.html
CHANGED
|
@@ -673,7 +673,7 @@
|
|
| 673 |
appended: a plain src attribute can 401 when the browser blocks the
|
| 674 |
*.static.hf.space auth cookie inside the hub iframe. -->
|
| 675 |
<script type="module">
|
| 676 |
-
const V = "
|
| 677 |
const sign = new URLSearchParams(location.search).get("__sign");
|
| 678 |
const suffix = sign ? `&__sign=${encodeURIComponent(sign)}` : "";
|
| 679 |
import(`./rl.js?v=${V}${suffix}`);
|
|
|
|
| 673 |
appended: a plain src attribute can 401 when the browser blocks the
|
| 674 |
*.static.hf.space auth cookie inside the hub iframe. -->
|
| 675 |
<script type="module">
|
| 676 |
+
const V = "31"; // bump on rl.js changes to defeat heuristic caching
|
| 677 |
const sign = new URLSearchParams(location.search).get("__sign");
|
| 678 |
const suffix = sign ? `&__sign=${encodeURIComponent(sign)}` : "";
|
| 679 |
import(`./rl.js?v=${V}${suffix}`);
|
rl.js
CHANGED
|
@@ -711,9 +711,20 @@ function makeSoccerBallTexture() {
|
|
| 711 |
// Seam half-width and anti-alias band, in radians of arc.
|
| 712 |
const SEAM = (1.6 * Math.PI) / 180;
|
| 713 |
const AA = (0.35 * Math.PI) / 180;
|
|
|
|
|
|
|
|
|
|
| 714 |
const BG = [233, 231, 224], INK = [23, 23, 29], STITCH = [200, 197, 188];
|
| 715 |
const img = ctx.createImageData(W, H);
|
| 716 |
const px = img.data;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 717 |
for (let row = 0; row < H; row++) {
|
| 718 |
const lat = Math.PI / 2 - ((row + 0.5) / H) * Math.PI;
|
| 719 |
const cl = Math.cos(lat), sl = Math.sin(lat);
|
|
@@ -739,25 +750,48 @@ function makeSoccerBallTexture() {
|
|
| 739 |
px[o + ch] = base + (INK[ch] - base) * black;
|
| 740 |
}
|
| 741 |
px[o + 3] = 255;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 742 |
}
|
| 743 |
}
|
| 744 |
ctx.putImageData(img, 0, 0);
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 751 |
}
|
| 752 |
// Same Z-up -> Y-up trick as the duck rig: the group takes the axis fix,
|
| 753 |
// the mesh inside takes the raw MJCF free-joint pose.
|
| 754 |
const ballGroup = new THREE.Group();
|
| 755 |
ballGroup.rotation.x = -Math.PI / 2;
|
|
|
|
| 756 |
const ballMesh = new THREE.Mesh(
|
| 757 |
// 48x32 segments: the coarser default makes the UV interpolation near
|
| 758 |
// the poles visibly scallop the round cap edge of the texture.
|
| 759 |
new THREE.SphereGeometry(BALL_RADIUS, 48, 32),
|
| 760 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 761 |
);
|
| 762 |
ballMesh.visible = false;
|
| 763 |
ballGroup.add(ballMesh);
|
|
@@ -869,7 +903,7 @@ function syncRig() {
|
|
| 869 |
for (const m of wallMats) m.uniforms.uFocus.value.copy(controls.target);
|
| 870 |
}
|
| 871 |
|
| 872 |
-
// Quack:
|
| 873 |
// MuJoCo joint (duck.js re-creates the hinge in JS), so this is purely
|
| 874 |
// cosmetic and can't upset the policy. A held gamepad trigger drives the
|
| 875 |
// jaw analogically on top (same as the robot's mouth trigger).
|
|
@@ -898,13 +932,12 @@ function playChirp() {
|
|
| 898 |
a.currentTime = 0;
|
| 899 |
a.play().catch(() => {});
|
| 900 |
}
|
| 901 |
-
//
|
| 902 |
-
//
|
| 903 |
-
|
| 904 |
-
|
| 905 |
-
};
|
| 906 |
const quackLoud = () => {
|
| 907 |
-
|
| 908 |
playChirp();
|
| 909 |
};
|
| 910 |
function jawOpenNow() {
|
|
@@ -1178,7 +1211,6 @@ function setMode(next) {
|
|
| 1178 |
// return to walk - switching now would floor the duck.
|
| 1179 |
if ((mode === "roll" && rollRun) || (isKick() && kickRun)) return;
|
| 1180 |
clearModeTimers();
|
| 1181 |
-
quack();
|
| 1182 |
rollRun = null;
|
| 1183 |
if (next !== "sit") {
|
| 1184 |
// Leaving a sit: let the sitstand policy stand the duck back up first.
|
|
@@ -1220,7 +1252,6 @@ function triggerRoll(source = "kb") {
|
|
| 1220 |
if (mode !== "walk" || standTimer) return;
|
| 1221 |
clearModeTimers();
|
| 1222 |
rollSource = source;
|
| 1223 |
-
quack();
|
| 1224 |
mode = "roll";
|
| 1225 |
sitFlag = 0;
|
| 1226 |
rollRun = { steps: 0, tipped: false };
|
|
@@ -1235,7 +1266,6 @@ function triggerKick(foot, source = "kb") {
|
|
| 1235 |
if (mode !== "walk" || standTimer) return false;
|
| 1236 |
clearModeTimers();
|
| 1237 |
kickSource = source;
|
| 1238 |
-
quack();
|
| 1239 |
mode = foot === "left" ? "kickL" : "kickR";
|
| 1240 |
sitFlag = 0;
|
| 1241 |
kickRun = { steps: 0 };
|
|
@@ -1280,7 +1310,6 @@ for (const name of VARIANT_NAMES) {
|
|
| 1280 |
if (name === currentVariant) return;
|
| 1281 |
currentVariant = name;
|
| 1282 |
applyVariant(rig, name);
|
| 1283 |
-
quack();
|
| 1284 |
syncSwatches();
|
| 1285 |
});
|
| 1286 |
swatchesEl.appendChild(b);
|
|
@@ -1309,6 +1338,7 @@ window.rl = {
|
|
| 1309 |
get chaseCam() { return chaseCam; },
|
| 1310 |
set chaseCam(v) { chaseCam = !!v; },
|
| 1311 |
padOrbitStep,
|
|
|
|
| 1312 |
step: async (n = 1) => { for (let i = 0; i < n; i++) await controlStep(); },
|
| 1313 |
render: () => { syncRig(); renderer.render(scene, camera); },
|
| 1314 |
// One full render-loop iteration, for tests driving frames manually.
|
|
|
|
| 711 |
// Seam half-width and anti-alias band, in radians of arc.
|
| 712 |
const SEAM = (1.6 * Math.PI) / 180;
|
| 713 |
const AA = (0.35 * Math.PI) / 180;
|
| 714 |
+
// Groove reach for the bump map: a touch wider than the painted seam so
|
| 715 |
+
// the recess shoulders catch light on both sides of the line.
|
| 716 |
+
const GROOVE = SEAM * 1.5;
|
| 717 |
const BG = [233, 231, 224], INK = [23, 23, 29], STITCH = [200, 197, 188];
|
| 718 |
const img = ctx.createImageData(W, H);
|
| 719 |
const px = img.data;
|
| 720 |
+
// Height map sharing the same panel construction: seams become recessed
|
| 721 |
+
// grooves, plus a very fine leather/PVC grain over the whole surface.
|
| 722 |
+
const bc = document.createElement("canvas");
|
| 723 |
+
bc.width = W;
|
| 724 |
+
bc.height = H;
|
| 725 |
+
const bctx = bc.getContext("2d");
|
| 726 |
+
const bimg = bctx.createImageData(W, H);
|
| 727 |
+
const bpx = bimg.data;
|
| 728 |
for (let row = 0; row < H; row++) {
|
| 729 |
const lat = Math.PI / 2 - ((row + 0.5) / H) * Math.PI;
|
| 730 |
const cl = Math.cos(lat), sl = Math.sin(lat);
|
|
|
|
| 750 |
px[o + ch] = base + (INK[ch] - base) * black;
|
| 751 |
}
|
| 752 |
px[o + 3] = 255;
|
| 753 |
+
// Bump: quadratic groove profile (soft shoulders, no golf-ball
|
| 754 |
+
// embossing) + grain noise.
|
| 755 |
+
const groove = Math.max(0, 1 - halfGap / GROOVE) ** 2;
|
| 756 |
+
const hgt = 205 - groove * 115 + (Math.random() - 0.5) * 14;
|
| 757 |
+
const h8 = Math.max(0, Math.min(255, hgt));
|
| 758 |
+
bpx[o] = h8; bpx[o + 1] = h8; bpx[o + 2] = h8;
|
| 759 |
+
bpx[o + 3] = 255;
|
| 760 |
}
|
| 761 |
}
|
| 762 |
ctx.putImageData(img, 0, 0);
|
| 763 |
+
bctx.putImageData(bimg, 0, 0);
|
| 764 |
+
const finish = (canvas, srgb) => {
|
| 765 |
+
const tex = new THREE.CanvasTexture(canvas);
|
| 766 |
+
// The bump map stays linear; only the color map is sRGB.
|
| 767 |
+
if (srgb) tex.colorSpace = THREE.SRGBColorSpace;
|
| 768 |
+
// Texel footprints get extremely anamorphic near the UV poles; without
|
| 769 |
+
// anisotropy the cap edge visibly scallops at close range.
|
| 770 |
+
tex.anisotropy = renderer.capabilities.getMaxAnisotropy();
|
| 771 |
+
return tex;
|
| 772 |
+
};
|
| 773 |
+
return { map: finish(c, true), bumpMap: finish(bc, false) };
|
| 774 |
}
|
| 775 |
// Same Z-up -> Y-up trick as the duck rig: the group takes the axis fix,
|
| 776 |
// the mesh inside takes the raw MJCF free-joint pose.
|
| 777 |
const ballGroup = new THREE.Group();
|
| 778 |
ballGroup.rotation.x = -Math.PI / 2;
|
| 779 |
+
const ballTex = makeSoccerBallTexture();
|
| 780 |
const ballMesh = new THREE.Mesh(
|
| 781 |
// 48x32 segments: the coarser default makes the UV interpolation near
|
| 782 |
// the poles visibly scallop the round cap edge of the texture.
|
| 783 |
new THREE.SphereGeometry(BALL_RADIUS, 48, 32),
|
| 784 |
+
// Physical material for the waxed vintage-leather look: matte-ish base
|
| 785 |
+
// with a whisper of clearcoat so highlights ride the seam grooves.
|
| 786 |
+
new THREE.MeshPhysicalMaterial({
|
| 787 |
+
map: ballTex.map,
|
| 788 |
+
bumpMap: ballTex.bumpMap,
|
| 789 |
+
bumpScale: 0.0012,
|
| 790 |
+
metalness: 0,
|
| 791 |
+
roughness: 0.55,
|
| 792 |
+
clearcoat: 0.2,
|
| 793 |
+
clearcoatRoughness: 0.35,
|
| 794 |
+
}),
|
| 795 |
);
|
| 796 |
ballMesh.visible = false;
|
| 797 |
ballGroup.add(ballMesh);
|
|
|
|
| 903 |
for (const m of wallMats) m.uniforms.uFocus.value.copy(controls.target);
|
| 904 |
}
|
| 905 |
|
| 906 |
+
// Quack: jaw + chirp on the gamepad right trigger only. The jaw isn't a
|
| 907 |
// MuJoCo joint (duck.js re-creates the hinge in JS), so this is purely
|
| 908 |
// cosmetic and can't upset the policy. A held gamepad trigger drives the
|
| 909 |
// jaw analogically on top (same as the robot's mouth trigger).
|
|
|
|
| 932 |
a.currentTime = 0;
|
| 933 |
a.play().catch(() => {});
|
| 934 |
}
|
| 935 |
+
// The jaw is driven ONLY by the dedicated gamepad triggers: the analog
|
| 936 |
+
// RT/LT value (padJaw) plus the flap that accompanies the RT-edge quack
|
| 937 |
+
// sound below. Mode changes, rolls, kicks and colour swaps no longer
|
| 938 |
+
// move the mouth (the old silent flap was removed by user request).
|
|
|
|
| 939 |
const quackLoud = () => {
|
| 940 |
+
quackAt = performance.now();
|
| 941 |
playChirp();
|
| 942 |
};
|
| 943 |
function jawOpenNow() {
|
|
|
|
| 1211 |
// return to walk - switching now would floor the duck.
|
| 1212 |
if ((mode === "roll" && rollRun) || (isKick() && kickRun)) return;
|
| 1213 |
clearModeTimers();
|
|
|
|
| 1214 |
rollRun = null;
|
| 1215 |
if (next !== "sit") {
|
| 1216 |
// Leaving a sit: let the sitstand policy stand the duck back up first.
|
|
|
|
| 1252 |
if (mode !== "walk" || standTimer) return;
|
| 1253 |
clearModeTimers();
|
| 1254 |
rollSource = source;
|
|
|
|
| 1255 |
mode = "roll";
|
| 1256 |
sitFlag = 0;
|
| 1257 |
rollRun = { steps: 0, tipped: false };
|
|
|
|
| 1266 |
if (mode !== "walk" || standTimer) return false;
|
| 1267 |
clearModeTimers();
|
| 1268 |
kickSource = source;
|
|
|
|
| 1269 |
mode = foot === "left" ? "kickL" : "kickR";
|
| 1270 |
sitFlag = 0;
|
| 1271 |
kickRun = { steps: 0 };
|
|
|
|
| 1310 |
if (name === currentVariant) return;
|
| 1311 |
currentVariant = name;
|
| 1312 |
applyVariant(rig, name);
|
|
|
|
| 1313 |
syncSwatches();
|
| 1314 |
});
|
| 1315 |
swatchesEl.appendChild(b);
|
|
|
|
| 1338 |
get chaseCam() { return chaseCam; },
|
| 1339 |
set chaseCam(v) { chaseCam = !!v; },
|
| 1340 |
padOrbitStep,
|
| 1341 |
+
jawOpenNow,
|
| 1342 |
step: async (n = 1) => { for (let i = 0; i < n; i++) await controlStep(); },
|
| 1343 |
render: () => { syncRig(); renderer.render(scene, camera); },
|
| 1344 |
// One full render-loop iteration, for tests driving frames manually.
|