Skip to content

Official Codebase of 3DCodeVerse

Python

material normaliser: the harness's own writer defaults count as never authored — CadQuery steel is steel

gaoypeng5e8f73980e95
diff --git a/harness/codeverse3d/texturing/materials.py b/harness/codeverse3d/texturing/materials.py
index 2de23895..873d3187 100644
--- a/harness/codeverse3d/texturing/materials.py
+++ b/harness/codeverse3d/texturing/materials.py
@@ -35,12 +35,16 @@ from pydantic import BaseModel, Field
from codeverse3d.conventions import to_snake
-#: glTF/Blender/three framework defaults. A material sitting exactly on one of
-#: these pairs was never authored — see ``is_framework_default``.
+#: glTF/Blender/three framework defaults, and the factors the harness's own writers put
+#: on a material nobody authored. A material sitting exactly on one of these pairs was
+#: never authored — see ``is_framework_default``. The two harness rows are pinned to their
+#: writers by ``tests/texturing/test_normalise.py``.
FRAMEWORK_DEFAULTS: tuple[tuple[float, float], ...] = (
(1.0, 1.0), # glTF 2.0 material default (metallic 1, roughness 1) — renders as dark mud
(0.0, 1.0), # three.js MeshStandardMaterial default
(0.0, 0.5), # Blender Principled BSDF default
+ (0.0, 0.6), # languages/wrappers/run_cq.py: every CadQuery part's exported material
+ (0.05, 0.6), # languages/threejs PART_TEMPLATE: the part stub's placeholder material
)
diff --git a/harness/tests/texturing/test_normalise.py b/harness/tests/texturing/test_normalise.py
index d6187112..4fc53a0a 100644
--- a/harness/tests/texturing/test_normalise.py
+++ b/harness/tests/texturing/test_normalise.py
@@ -98,3 +98,33 @@ def test_an_instanced_part_reads_its_plan_material(tmp_path: Path):
plan = NS(parts=[NS(name="Leg", material="solid oak", description="leg")])
rep = normalise_materials(glb, tmp_path / "out.glb", plan=plan)
assert [(c.node, c.family) for c in rep.changes] == [("Leg_0", "hardwood")]
+
+
+def _cq_export_factors() -> tuple[float, float]:
+ """The (metallic, roughness) run_cq.py writes on every material (a stdlib-only wrapper: read, not imported)."""
+ import ast
+
+ from codeverse3d import languages
+
+ tree = ast.parse((Path(languages.__file__).parent / "wrappers" / "run_cq.py").read_text())
+ call = next(n for n in ast.walk(tree) if isinstance(n, ast.Call) and getattr(n.func, "attr", "") == "PBRMaterial")
+ kw = {k.arg: ast.literal_eval(k.value) for k in call.keywords if k.arg in ("metallicFactor", "roughnessFactor")}
+ return kw["metallicFactor"], kw["roughnessFactor"]
+
+
+def test_the_harness_writers_own_defaults_count_as_never_authored():
+ """N54: CadQuery's (0, 0.6) and the three.js stub's (0.05, 0.6) read as authored, so CadQuery
+ steel was clamped to half-metallic and CadQuery wood was never normalised."""
+ import re
+
+ from codeverse3d.languages.threejs import PART_TEMPLATE
+ from codeverse3d.texturing.materials import is_framework_default
+
+ stub = re.search(r"roughness: ([\d.]+), metalness: ([\d.]+)", PART_TEMPLATE)
+ assert stub and is_framework_default(float(stub[2]), float(stub[1]))
+ cq = _cq_export_factors()
+ assert is_framework_default(*cq)
+ steel = classify("SteelFrame", "SteelFrameMat", "", *cq)
+ assert steel is not None and steel.reason == "untouched" and steel.metallic == 1.0
+ oak = classify("Leg", "LegMat", "solid oak", *cq)
+ assert oak is not None and oak.family == "hardwood"