Official Codebase of 3DCodeVerse
Python
joint_sweep: render only the joints the agent asked about
gaoypeng1701a204741d
diff --git a/harness/codeverse/spatial/joints_export.py b/harness/codeverse/spatial/joints_export.pyindex 42c81319..8f14a70a 100644--- a/harness/codeverse/spatial/joints_export.py+++ b/harness/codeverse/spatial/joints_export.py@@ -171,11 +171,33 @@ def render_poses(return results+def _poses_for(robot, joints: list[str] | None) -> list[tuple[str, dict[str, float]]] | None:+ """``limit_poses`` narrowed to ``joints`` (rest kept); ``None`` = the full sheet.++ An unknown joint name narrows to nothing but rest, which is a wrong-but-visible sheet+ rather than a silent fallback to everything — the agent sees one tile and its typo.+ """+ if not joints:+ return None+ want = set(joints)+ return [(label, q) for label, q in limit_poses(robot) if label == "rest" or label.split("@")[0] in want]++# ------------------------------------------------------------------ tool-shaped entry pointdef joint_sweep_observation(ws, *, n_random: int = 8, seed: int = 0, render: bool = True, out_dir: Path | None = None,- joint: str | None = None, expected_direction: str | None = None):+ joint: str | None = None, expected_direction: str | None = None,+ joints: list[str] | None = None):"""Run the pose sweep on ``ws.artifacts/robot.urdf`` (+ ``meshes/``) and return an- ``Observation`` (package F wraps this as the ``joint_sweep`` tool)."""+ ``Observation`` (package F wraps this as the ``joint_sweep`` tool).++ ``joints`` narrows the RENDER to those joints' limit poses (plus rest). The collision+ sweep still covers every joint — a change to one joint can collide with another, and+ that check is cheap. Rendering is not: every pose is a GLB export plus three views, so+ a 10-joint object renders ~63 images per call, and agents call this 3-8 times a round.+ Measured 2026-08-25: articulated rounds ran a median 1007 s against 497 s for static+ objects, with the agent session — mostly waiting on sweeps — as the whole difference.+ The tool has accepted ``joints`` since it was written; nothing consumed it.+ """from codeverse.spatial.joints_model import load_urdffrom codeverse.spatial.joints_poses import pose_samplesfrom codeverse.spatial.joints_sweep import (@@ -203,7 +225,7 @@ def joint_sweep_observation(ws, *, n_random: int = 8, seed: int = 0, render: booimages: list[str] = []if render:d = Path(out_dir) if out_dir else Path(ws.artifacts) / "tool_scratch" / "joint_sweep"- render_poses(robot, d)+ render_poses(robot, d, poses=_poses_for(robot, joints))images.append(str(d / ARTICULATION_SHEET_NAME))ok = report.summary.max_penetration_m <= report.tol_m and not report.summary.floating_linksreturn Observation(ok=ok, text=text, numbers=numbers, images=images)diff --git a/harness/codeverse/spatial/tools_scene.py b/harness/codeverse/spatial/tools_scene.pyindex 902f7117..c391f2c3 100644--- a/harness/codeverse/spatial/tools_scene.py+++ b/harness/codeverse/spatial/tools_scene.py@@ -44,7 +44,9 @@ class JointSweepArgs(BaseModel):n_samples: int = Field(default=8, ge=2, le=32, description="poses per joint across its range")-@tool("joint_sweep", JointSweepArgs, "Sweep URDF joints through their ranges: pose renders + self-collision / limit findings.",+@tool("joint_sweep", JointSweepArgs, "Sweep URDF joints through their ranges: self-collision / limit findings for ALL joints, "+ "plus pose renders. Pass joints=[...] for the joints you changed — rendering every joint's poses is the slow part "+ "(three views per pose); the collision check always covers the whole robot.",tracks=(Track.ARTICULATED_OBJECT.value,), cost_hint="slow")def joint_sweep(ctx: ToolContext, args: JointSweepArgs) -> Observation:fn = lazy("codeverse.spatial.joints", "joint_sweep_observation")diff --git a/harness/tests/urdf_joints/test_sweep.py b/harness/tests/urdf_joints/test_sweep.pyindex 23617e37..b2ec4839 100644--- a/harness/tests/urdf_joints/test_sweep.py+++ b/harness/tests/urdf_joints/test_sweep.py@@ -147,3 +147,31 @@ def test_welded_child_overlap_is_structural_not_motion(tmp_path):rep2 = sweep_collisions(r, [{"hinge": 1.0}, {"hinge": 1.5}])assert [len(pr.overlaps) for pr in rep2.per_pose] == [1, 0] and rep2.summary.rest_max_penetration_m > 0.0025assert sweep_findings(rep2)[0].severity == Severity.WARN and "rigidly joined" in sweep_findings(rep2)[0].fix_hint+++# ------------------------------------------------- joints= narrows the RENDER, not the sweep+def test_joints_argument_narrows_the_render_to_those_joints(monkeypatch, tmp_path):+ """The tool accepted joints=[...] from the start and nothing consumed it: every call+ rendered every joint's limit poses (three views each). Measured 2026-08-25: articulated+ rounds ran a median 1007 s vs 497 s for static objects, agents calling the sweep 3-8+ times a round on 10-joint objects (~63 renders a call)."""+ from codeverse.spatial import joints_export as je++ class _J:+ def __init__(self, name, lo, hi, type="revolute"): self.name, self.lower, self.upper, self.type = name, lo, hi, type+ class _Robot:+ joints = {n: _J(n, -1.0, 1.0) for n in ("hinge", "slide", "knob")}+ def movable_joints(self): return list(self.joints.values())++ seen = {}+ monkeypatch.setattr(je, "render_poses", lambda robot, d, poses=None: seen.setdefault("poses", poses))+ monkeypatch.setattr(je, "load_urdf", lambda *a, **k: _Robot(), raising=False)++ full = je._poses_for(_Robot(), None)+ assert full is None, "no filter = the full articulation sheet, unchanged"+ narrowed = je._poses_for(_Robot(), ["hinge"])+ labels = [lbl for lbl, _ in narrowed]+ assert labels[0] == "rest" and all(x == "rest" or x.startswith("hinge@") for x in labels)+ assert len(narrowed) == 3, "rest + hinge@lower + hinge@upper, nothing from slide or knob"+ typo = je._poses_for(_Robot(), ["hinge_typo"])+ assert [lbl for lbl, _ in typo] == ["rest"], "an unknown joint yields a visibly wrong sheet, not the full one"