Official Codebase of 3DCodeVerse
Python
urdf: the link exporter skips hidden objects by the census predicate, so a hidden cutter is no longer link geometry
gaoypeng11843a025e37
diff --git a/harness/codeverse3d/languages/wrappers/run_bpy_links.py b/harness/codeverse3d/languages/wrappers/run_bpy_links.pyindex 28894581..ba756528 100644--- a/harness/codeverse3d/languages/wrappers/run_bpy_links.py+++ b/harness/codeverse3d/languages/wrappers/run_bpy_links.py@@ -29,7 +29,12 @@ import bpyfrom mathutils import Matrix, Vectorsys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))-from _census import collect_census, world_bbox # noqa: E402 (siblings, Blender-executed)+from _census import ( # noqa: E402 (siblings, Blender-executed)+ MEASURABLE_TYPES,+ collect_census,+ is_hidden,+ world_bbox,+)from _wrapper_common import ( # noqa: E402exit_after,map_exception,@@ -40,7 +45,6 @@ from _wrapper_common import ( # noqa: E402write_report,)-MESH_LIKE = {"MESH", "CURVE", "FONT", "SURFACE", "META"}TRI_LIMIT = 600_000 # a warning here (census), the blender language's build error@@ -148,20 +152,23 @@ def main() -> int:census.update(collect_census(bpy, TRI_LIMIT))depsgraph = bpy.context.evaluated_depsgraph_get()- by_name = {ob.name: ob for ob in bpy.data.objects if ob.type in MESH_LIKE or ob.type == "EMPTY"}+ by_name = {ob.name: ob for ob in bpy.data.objects if ob.type in MEASURABLE_TYPES or ob.type == "EMPTY"}+ # a hidden object (a boolean cutter, as the census tells agents to hide one) is not+ # geometry: the blender language's export skips it by the same predicate+ vl_names = set(bpy.context.view_layer.objects.keys())claimed: set[str] = set()for link in links:ob = by_name.get(link)if ob is None:census["missing_links"].append(link)- near = [o.name for o in bpy.data.objects if o.type in MESH_LIKE and _snake(o.name) == _snake(link)]+ near = [o.name for o in bpy.data.objects if o.type in MEASURABLE_TYPES and _snake(o.name) == _snake(link)]if near:census["hints"][link] = f"no object named exactly '{link}' — did you mean {near}? names are case-sensitive"continue- group = [o for o in (ob, *ob.children_recursive) if o.type in MESH_LIKE]+ group = [o for o in (ob, *ob.children_recursive) if o.type in MEASURABLE_TYPES and not is_hidden(o, vl_names)]if not group:census["missing_links"].append(link)- census["hints"][link] = f"object '{link}' has no mesh geometry (type {ob.type})"+ census["hints"][link] = f"object '{link}' has no visible mesh geometry (type {ob.type})"continueclaimed.update(o.name for o in group)try:@@ -169,7 +176,7 @@ def main() -> int:except Exception as e: # export failure is a build failurereturn fail("ExportError", f"link {link}: {e}")census["unmatched_objects"] = [o["name"] for o in census["objects"]- if o["type"] in MESH_LIKE and o["name"] not in claimed]+ if o["type"] in MEASURABLE_TYPES and not o["hidden"] and o["name"] not in claimed]if census["missing_links"]:return fail("MissingLinkObjects","URDF links without a mesh object in model.py: " + ", ".join(census["missing_links"]))diff --git a/harness/tests/urdf_joints/test_live_blender.py b/harness/tests/urdf_joints/test_live_blender.pyindex 16efd67c..d59236ef 100644--- a/harness/tests/urdf_joints/test_live_blender.py+++ b/harness/tests/urdf_joints/test_live_blender.py@@ -104,3 +104,34 @@ def test_links_script_that_calls_sys_exit_0_still_builds(tmp_path):assert census["links"]["base"]["bbox_max"][0] == pytest.approx((0.2 + random.random()) / 2, abs=1e-5)assert (out / "meshes" / "base.glb").is_file()assert any("has no material" in w for w in census["warnings"]) # the blender language's census+++@needs_blender[email protected]("parented", [True, False])+def test_a_hidden_boolean_cutter_is_not_link_geometry(tmp_path, parented):+ """Regression (audit 2026-09-24 N7): the link exporter skips hidden objects by the blender+ language's own predicate (``_census.is_hidden``). It used to export a parented hidden cutter+ as a solid rod inside the link (z 0..2) and fail an unparented one as UnmatchedObjects."""+ import json as _json+ import subprocess++ from codeverse3d.languages.urdf import WRAPPER++ (tmp_path / "robot.urdf").write_text('<robot name="r"><link name="base"/></robot>')+ (tmp_path / "model.py").write_text(+ "import bpy\n"+ "bpy.ops.mesh.primitive_cube_add(size=1, location=(0, 0, 0.5)); base = bpy.context.active_object; base.name = 'base'\n"+ "bpy.ops.mesh.primitive_cylinder_add(radius=0.2, depth=2, location=(0, 0, 0.5)); cut = bpy.context.active_object\n"+ "cut.name = 'HoleCutter'\n"+ "m = base.modifiers.new('hole', 'BOOLEAN'); m.object = cut; m.operation = 'DIFFERENCE'\n"+ + ("cut.parent = base\n" if parented else "")+ + "cut.hide_set(True); cut.hide_render = True\n")+ out = tmp_path / "art"+ subprocess.run(+ [get_settings().resolve_blender(), "-b", "--factory-startup", "--python", str(WRAPPER), "--",+ "--script", str(tmp_path / "model.py"), "--urdf", str(tmp_path / "robot.urdf"), "--out", str(out)],+ capture_output=True, text=True, timeout=180, check=False)+ build = _json.loads((out / "build.json").read_text())+ assert build["ok"], build+ link = _json.loads((out / "census.json").read_text())["links"]["base"]+ assert link["objects"] == ["base"] and link["bbox_max"][2] == pytest.approx(1.0, abs=1e-4)