Official Codebase of 3DCodeVerse
Python
connectivity: a model authored below the floor disabled the floating check
gaoypeng9feb86339cdf
diff --git a/harness/codeverse/spatial/connectivity.py b/harness/codeverse/spatial/connectivity.pyindex 6e04966e..b9746efd 100644--- a/harness/codeverse/spatial/connectivity.py+++ b/harness/codeverse/spatial/connectivity.py@@ -283,7 +283,14 @@ def check_connectivity())# ---- components → floating partscomps = _components(big, edges)- grounded = {n for n in big if float(parts[n].bounds[0][1]) <= gap_m}+ # TOUCHING the ground, not merely at-or-below it: the old one-sided `<= gap_m`+ # counted a part buried 1 m under the floor as grounded, so a model authored around+ # the origin instead of on it (a routine agent mistake, which the contract gate+ # already reports separately as "object floats 1000 mm below the ground") put every+ # part in `grounded`, hence in `support`, and switched the floating check off for the+ # whole run. abs() makes the sunk model fall through to the "no part touches the+ # ground" WARN branch and report the same floating ERROR it does at y=0.+ grounded = {n for n in big if abs(float(parts[n].bounds[0][1])) <= gap_m}support_sets = [c for c in comps if c & grounded]if support_sets:# THE support component (see the module docstring): ONE component, not the union@@ -295,7 +302,13 @@ def check_connectivity(# mutated the winning set in place, corrupting `comps`; hence the copy.support = set(max(support_sets, key=lambda c: sum(len(parts[n].faces) for n in c)))else:- support = max(comps, key=lambda c: sum(len(parts[n].faces) for n in c)) if comps else set()+ # Nothing touches the ground, so there is no ground to reason from: take the+ # LOWEST component as the base (face count only breaks ties). Picking the+ # biggest instead made a model authored around the origin report its base as the+ # floating part and the thing sitting on top as the support — the same finding as+ # the correctly-placed model, but with the two parts swapped.+ support = min(comps, key=lambda c: (round(min(float(parts[n].bounds[0][1]) for n in c), 6),+ -sum(len(parts[n].faces) for n in c))) if comps else set()findings.append(GateFinding(gate=GATE, severity=Severity.WARN, message=f"no part touches the ground ({up}=0)",fix_hint=f"move the whole object down so its lowest point sits on the ground ({up}=0, {frame_label(language)})"))for n in big:diff --git a/harness/tests/spatial_tools/test_connectivity.py b/harness/tests/spatial_tools/test_connectivity.pyindex 8da811b9..1bc6f52a 100644--- a/harness/tests/spatial_tools/test_connectivity.py+++ b/harness/tests/spatial_tools/test_connectivity.py@@ -210,3 +210,44 @@ def test_two_grounded_islands_are_not_one_connected_assembly(tmp_path: Path) ->assert not r.passed and len(r.errors) == 1assert not [f for f in r.findings if "parts are connected" in f.message]++def _hat_and_body(path: Path, dy: float) -> Path:+ """'hat' floating 100 mm above 'body', the pair translated by ``dy``."""+ sc = trimesh.Scene()+ body = trimesh.creation.box(extents=(0.2, 0.2, 0.2))+ body.apply_translation((0, 0.1 + dy, 0))+ hat = trimesh.creation.box(extents=(0.1, 0.1, 0.1))+ hat.apply_translation((0, 0.2 + 0.1 + 0.05 + dy, 0)) # 100 mm above the body's top+ sc.add_geometry(body, node_name="body", geom_name="body")+ sc.add_geometry(hat, node_name="hat", geom_name="hat")+ path.write_bytes(sc.export(file_type="glb"))+ return path+++def test_a_model_authored_below_the_floor_still_reports_its_floating_part(tmp_path: Path) -> None:+ """CG-3: `grounded` was the one-sided `bounds[0][1] <= gap_m`, so a part buried 1 m+ UNDER the floor counted as touching the ground. Every part of a sunk model therefore+ landed in `grounded`, hence in `support`, and no floating finding could be emitted at+ all — one routine agent mistake (authoring around the origin instead of on the floor,+ which the contract gate already flags separately) silently switched the whole+ connectivity floating check off for the run."""+ on_ground = check_connectivity(_hat_and_body(tmp_path / "f2_on_ground.glb", 0.0))+ sunk = check_connectivity(_hat_and_body(tmp_path / "f2_sunk.glb", -1.0))++ assert not on_ground.passed+ assert [(e.target, e.data["nearest"]) for e in on_ground.errors] == [("hat", "body")]++ # the identical model, 1 m lower, must reach the identical verdict+ assert not sunk.passed, "a sunk model must not disable the floating check"+ assert [(e.target, e.data["nearest"]) for e in sunk.errors] == [("hat", "body")]+ # ... plus the ground warning, since nothing is on the floor any more+ assert any("touches the ground" in f.message for f in sunk.findings)+++def test_a_part_resting_exactly_on_the_floor_is_still_grounded(tmp_path: Path) -> None:+ """The abs() must not cost the ordinary case: y=0 and a hair above it are grounded."""+ from codeverse.spatial.connectivity import check_connectivity as cc++ for dy in (0.0, 0.001):+ r = cc(_hat_and_body(tmp_path / f"f2_{dy}.glb", dy))+ assert not any("touches the ground" in f.message for f in r.findings), dy