Spaces:
Running
Running
feat: soccer-ball look for the kickable ball
Browse filesReplace the beach-ball CanvasTexture with an equirectangular soccer
pattern: off-white base, a black cap at each texture pole (full-width
strips, dodging the equirect pinch) and two staggered rings of five
pentagons with 1/cos(lat) horizontal stretch compensation. Sphere
segments bumped to 48x32 and max anisotropy enabled so the pole caps
stay round up close.
Also set condim=6 on the ball geom: with the default condim 3 the
rolling/torsional friction coefficients were silently ignored and a
rolling ball never decelerated (verified: now 0.27 -> 0.001 m/s in 6 s).
Cache-buster bumped to 27.
Co-authored-by: Cursor <cursoragent@cursor.com>
- index.html +1 -1
- rl.js +54 -14
index.html
CHANGED
|
@@ -476,7 +476,7 @@
|
|
| 476 |
appended: a plain src attribute can 401 when the browser blocks the
|
| 477 |
*.static.hf.space auth cookie inside the hub iframe. -->
|
| 478 |
<script type="module">
|
| 479 |
-
const V = "
|
| 480 |
const sign = new URLSearchParams(location.search).get("__sign");
|
| 481 |
const suffix = sign ? `&__sign=${encodeURIComponent(sign)}` : "";
|
| 482 |
import(`./rl.js?v=${V}${suffix}`);
|
|
|
|
| 476 |
appended: a plain src attribute can 401 when the browser blocks the
|
| 477 |
*.static.hf.space auth cookie inside the hub iframe. -->
|
| 478 |
<script type="module">
|
| 479 |
+
const V = "27"; // bump on rl.js changes to defeat heuristic caching
|
| 480 |
const sign = new URLSearchParams(location.search).get("__sign");
|
| 481 |
const suffix = sign ? `&__sign=${encodeURIComponent(sign)}` : "";
|
| 482 |
import(`./rl.js?v=${V}${suffix}`);
|
rl.js
CHANGED
|
@@ -154,9 +154,12 @@ async function buildPhysicsXml() {
|
|
| 154 |
// and the ghosts' getLocalState.
|
| 155 |
const ballBody = el("body", { name: "ball", pos: BALL_PARK_POS });
|
| 156 |
ballBody.appendChild(el("freejoint", { name: "ball_freejoint" }));
|
|
|
|
|
|
|
|
|
|
| 157 |
ballBody.appendChild(el("geom", {
|
| 158 |
name: "ball_geom", type: "sphere", size: String(BALL_RADIUS),
|
| 159 |
-
mass: "0.03", friction: "0.4 0.01 0.003", solref: "0.03 0.4",
|
| 160 |
}));
|
| 161 |
doc.querySelector("worldbody").appendChild(ballBody);
|
| 162 |
// STAND keyframe from mjlab's scene_walk.xml (STAND2 pose). The ball's
|
|
@@ -534,22 +537,57 @@ const rig = await rigPromise;
|
|
| 534 |
scene.add(rig.placer);
|
| 535 |
const trunkGroup = rig.bodies.get("trunk_base");
|
| 536 |
|
| 537 |
-
//
|
| 538 |
-
//
|
| 539 |
-
//
|
| 540 |
-
|
|
|
|
| 541 |
const c = document.createElement("canvas");
|
| 542 |
-
c.width =
|
| 543 |
-
c.height =
|
| 544 |
const ctx = c.getContext("2d");
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 550 |
}
|
| 551 |
const tex = new THREE.CanvasTexture(c);
|
| 552 |
tex.colorSpace = THREE.SRGBColorSpace;
|
|
|
|
|
|
|
|
|
|
| 553 |
return tex;
|
| 554 |
}
|
| 555 |
// Same Z-up -> Y-up trick as the duck rig: the group takes the axis fix,
|
|
@@ -557,8 +595,10 @@ function makeBeachBallTexture() {
|
|
| 557 |
const ballGroup = new THREE.Group();
|
| 558 |
ballGroup.rotation.x = -Math.PI / 2;
|
| 559 |
const ballMesh = new THREE.Mesh(
|
| 560 |
-
|
| 561 |
-
|
|
|
|
|
|
|
| 562 |
);
|
| 563 |
ballMesh.visible = false;
|
| 564 |
ballGroup.add(ballMesh);
|
|
|
|
| 154 |
// and the ghosts' getLocalState.
|
| 155 |
const ballBody = el("body", { name: "ball", pos: BALL_PARK_POS });
|
| 156 |
ballBody.appendChild(el("freejoint", { name: "ball_freejoint" }));
|
| 157 |
+
// condim 6 enables the torsional + rolling friction components of the
|
| 158 |
+
// friction vector; with the default condim 3 they are ignored and a
|
| 159 |
+
// rolling ball never decelerates.
|
| 160 |
ballBody.appendChild(el("geom", {
|
| 161 |
name: "ball_geom", type: "sphere", size: String(BALL_RADIUS),
|
| 162 |
+
mass: "0.03", friction: "0.4 0.01 0.003", solref: "0.03 0.4", condim: "6",
|
| 163 |
}));
|
| 164 |
doc.querySelector("worldbody").appendChild(ballBody);
|
| 165 |
// STAND keyframe from mjlab's scene_walk.xml (STAND2 pose). The ball's
|
|
|
|
| 537 |
scene.add(rig.placer);
|
| 538 |
const trunkGroup = rig.bodies.get("trunk_base");
|
| 539 |
|
| 540 |
+
// Soccer-ball look on an equirectangular CanvasTexture: off-white base
|
| 541 |
+
// (pure white would blow out under ACES tone mapping) with black
|
| 542 |
+
// pentagons - a cap at each pole plus two staggered rings - so the
|
| 543 |
+
// rolling actually reads visually.
|
| 544 |
+
function makeSoccerBallTexture() {
|
| 545 |
const c = document.createElement("canvas");
|
| 546 |
+
c.width = 1024;
|
| 547 |
+
c.height = 512;
|
| 548 |
const ctx = c.getContext("2d");
|
| 549 |
+
ctx.fillStyle = "#e9e7e0";
|
| 550 |
+
ctx.fillRect(0, 0, c.width, c.height);
|
| 551 |
+
ctx.fillStyle = "#17171d";
|
| 552 |
+
// Pole "pentagons": a full-width strip at each canvas edge maps to a
|
| 553 |
+
// clean round patch at the pole, sidestepping the equirect pinch that
|
| 554 |
+
// would smear an actual drawn polygon there.
|
| 555 |
+
const capH = c.height * 0.075;
|
| 556 |
+
ctx.fillRect(0, 0, c.width, capH);
|
| 557 |
+
ctx.fillRect(0, c.height - capH, c.width, capH);
|
| 558 |
+
// Pentagon at (lon, lat), angular radius r (all degrees). Horizontal
|
| 559 |
+
// extent is stretched by 1/cos(lat) to counter the equirect longitude
|
| 560 |
+
// compression away from the equator; drawn three times so panels
|
| 561 |
+
// crossing the +-180 deg seam wrap around cleanly.
|
| 562 |
+
const pent = (lonDeg, latDeg, rDeg, rot) => {
|
| 563 |
+
const x = ((lonDeg + 180) / 360) * c.width;
|
| 564 |
+
const y = ((90 - latDeg) / 180) * c.height;
|
| 565 |
+
const ry = (rDeg / 180) * c.height;
|
| 566 |
+
const rx = ry / Math.cos((latDeg * Math.PI) / 180);
|
| 567 |
+
for (const dx of [-c.width, 0, c.width]) {
|
| 568 |
+
ctx.beginPath();
|
| 569 |
+
for (let i = 0; i < 5; i++) {
|
| 570 |
+
const a = rot + (i * 2 * Math.PI) / 5;
|
| 571 |
+
const px = x + dx + Math.cos(a) * rx;
|
| 572 |
+
const py = y + Math.sin(a) * ry;
|
| 573 |
+
if (i === 0) ctx.moveTo(px, py); else ctx.lineTo(px, py);
|
| 574 |
+
}
|
| 575 |
+
ctx.closePath();
|
| 576 |
+
ctx.fill();
|
| 577 |
+
}
|
| 578 |
+
};
|
| 579 |
+
// Two staggered rings of five (12 pentagons total with the poles),
|
| 580 |
+
// roughly the truncated-icosahedron layout. Point-up above the
|
| 581 |
+
// equator, point-down below, like the real panel orientation.
|
| 582 |
+
for (let i = 0; i < 5; i++) {
|
| 583 |
+
pent(-180 + i * 72, 27, 15, -Math.PI / 2);
|
| 584 |
+
pent(-144 + i * 72, -27, 15, Math.PI / 2);
|
| 585 |
}
|
| 586 |
const tex = new THREE.CanvasTexture(c);
|
| 587 |
tex.colorSpace = THREE.SRGBColorSpace;
|
| 588 |
+
// Texel footprints get extremely anamorphic near the UV poles; without
|
| 589 |
+
// anisotropy the cap edge visibly scallops at close range.
|
| 590 |
+
tex.anisotropy = renderer.capabilities.getMaxAnisotropy();
|
| 591 |
return tex;
|
| 592 |
}
|
| 593 |
// Same Z-up -> Y-up trick as the duck rig: the group takes the axis fix,
|
|
|
|
| 595 |
const ballGroup = new THREE.Group();
|
| 596 |
ballGroup.rotation.x = -Math.PI / 2;
|
| 597 |
const ballMesh = new THREE.Mesh(
|
| 598 |
+
// 48x32 segments: the coarser default makes the UV interpolation near
|
| 599 |
+
// the poles visibly scallop the round cap edge of the texture.
|
| 600 |
+
new THREE.SphereGeometry(BALL_RADIUS, 48, 32),
|
| 601 |
+
new THREE.MeshStandardMaterial({ map: makeSoccerBallTexture(), roughness: 0.35, metalness: 0 }),
|
| 602 |
);
|
| 603 |
ballMesh.visible = false;
|
| 604 |
ballGroup.add(ballMesh);
|