Skip to content

Official Codebase of 3DCodeVerse

Python

skeleton finishes read the one PBR table: finish_for is texturing.materials' family, base hint and factors

gaoypeng445ea4628173
diff --git a/harness/codeverse3d/languages/blender/__init__.py b/harness/codeverse3d/languages/blender/__init__.py
index 220ee158..e90fc078 100644
--- a/harness/codeverse3d/languages/blender/__init__.py
+++ b/harness/codeverse3d/languages/blender/__init__.py
@@ -23,6 +23,7 @@ from codeverse3d.languages._ast_lint import (
from codeverse3d.languages._common import run_wrapper_build, strip_blender_noise, ws_rel
from codeverse3d.languages.base import RuntimeLayout
from codeverse3d.proc import scrub_secrets
+from codeverse3d.texturing.materials import family_for, pbr_for
from codeverse3d.workspace import Workspace
# ===================================================================== lint
@@ -403,30 +404,23 @@ def lint_workspace(ws: Workspace) -> GateReport:
# ===================================================================== skeleton
-# keyword → (rgb, roughness, metallic) placeholder finishes so the first render is not all-grey
-_FINISHES: tuple[tuple[tuple[str, ...], tuple[float, float, float], float, float], ...] = (
- (("wood", "oak", "walnut", "pine", "timber", "birch"), (0.55, 0.36, 0.20), 0.55, 0.0),
- (("steel", "chrome", "aluminium", "aluminum", "metal", "iron", "brass"), (0.75, 0.75, 0.78), 0.35, 1.0),
- (("fabric", "cloth", "cushion", "upholster", "velvet", "linen"), (0.45, 0.30, 0.30), 0.9, 0.0),
- (("leather",), (0.30, 0.16, 0.10), 0.6, 0.0),
- (("glass", "acrylic"), (0.85, 0.9, 0.95), 0.05, 0.0),
- (("rubber", "tire", "tyre"), (0.05, 0.05, 0.05), 0.9, 0.0),
- (("plastic", "abs", "nylon"), (0.9, 0.9, 0.9), 0.4, 0.0),
- (("black",), (0.05, 0.05, 0.05), 0.5, 0.0),
- (("white",), (0.9, 0.9, 0.9), 0.5, 0.0),
- (("red",), (0.7, 0.1, 0.1), 0.5, 0.0),
- (("blue",), (0.1, 0.2, 0.7), 0.5, 0.0),
- (("green",), (0.1, 0.5, 0.2), 0.5, 0.0),
+#: base colour for a part whose material names no family: a bare colour word
+_COLOUR_WORDS: tuple[tuple[str, tuple[float, float, float]], ...] = (
+ ("black", (0.05, 0.05, 0.05)), ("white", (0.9, 0.9, 0.9)), ("red", (0.7, 0.1, 0.1)),
+ ("blue", (0.1, 0.2, 0.7)), ("green", (0.1, 0.5, 0.2)),
)
def finish_for(text: str) -> tuple[tuple[float, float, float], float, float]:
- """Placeholder (rgb, roughness, metallic) from material words; neutral grey otherwise."""
+ """Placeholder (rgb, roughness, metallic) so the first render is not all-grey: the material
+ family's base hint and factors from ``texturing.materials`` (THE PBR table), else a bare
+ colour word at the Principled defaults, else neutral grey."""
+ hit = family_for(text)
+ pbr = pbr_for(hit.family) if hit else None
+ if pbr is not None:
+ return pbr.base_hint, pbr.roughness, pbr.metallic
low = text.lower()
- for words, rgb, rough, metal in _FINISHES:
- if any(w in low for w in words):
- return rgb, rough, metal
- return (0.6, 0.6, 0.6), 0.5, 0.0
+ return next((rgb for word, rgb in _COLOUR_WORDS if word in low), (0.6, 0.6, 0.6)), 0.5, 0.0
def instance_centers(bbox: BBox, n: int, symmetry: str) -> list[tuple[float, float, float]]:
diff --git a/harness/tests/blender_cadquery/test_blender_skeleton.py b/harness/tests/blender_cadquery/test_blender_skeleton.py
index d03107a6..99b555e8 100644
--- a/harness/tests/blender_cadquery/test_blender_skeleton.py
+++ b/harness/tests/blender_cadquery/test_blender_skeleton.py
@@ -4,8 +4,11 @@ from __future__ import annotations
import ast
+import pytest
+
from codeverse3d.contracts.plan import BBox
from codeverse3d.languages.blender import (
+ finish_for,
instance_centers,
lint_blender_source,
part_file_source,
@@ -19,7 +22,7 @@ def test_part_file_source_is_self_contained(table_plan) -> None:
assert "def build_leg():" in src and "def make_material(" in src and "def add_box(" in src
assert "LEG_CENTER = (0.210, 0.210, 0.280)" in src and "LEG_INSTANCES = 4" in src
assert "tapered square leg" in src and "support" in src and "Attaches to: TableTop" in src and "oak" in src
- assert "(0.550, 0.360, 0.200)" in src # oak colour hint
+ assert "(0.340, 0.200, 0.100)" in src # oak: the hardwood base hint (texturing.materials)
assert "add_empty" not in src and "obj.parent" not in src
assert 'add_box(f"Leg_{i}"' in src and "return objs" in src and "TOP-LEVEL" in src
# defines builders only — nothing is built at import time
@@ -36,3 +39,18 @@ def test_instance_centers_symmetry() -> None:
assert len(four) == 4 and {(round(x, 3), round(y, 3)) for x, y, _ in four} == {(0.2, -0.3), (-0.2, -0.3), (-0.2, 0.3), (0.2, 0.3)}
rad = instance_centers(BBox(center=(0.5, 0.0, 0.1), extents=(0.1, 0.1, 0.1)), 3, "radial")
assert len(rad) == 3 and all(abs((x * x + y * y) ** 0.5 - 0.5) < 1e-9 for x, y, _ in rad)
+
+
[email protected]("text, family", [("solid oak", "hardwood"), ("brushed steel", "brushed_metal"),
+ ("ABS plastic", "rough_plastic"), ("black", None)])
+def test_placeholder_finish_is_the_pbr_table(text, family) -> None:
+ """Audit 2026-09-24 N54: the skeleton's finishes had their own numbers (wood 0.55 vs the
+ table's 0.45, steel 0.35 vs 0.22, plastic 0.40 vs 0.62)."""
+ from codeverse3d.texturing.materials import MATERIALS
+
+ rgb, rough, metal = finish_for(text)
+ if family is None:
+ assert (rough, metal) == (0.5, 0.0) and rgb == (0.05, 0.05, 0.05)
+ else:
+ pbr = MATERIALS[family]
+ assert (rgb, rough, metal) == (pbr.base_hint, pbr.roughness, pbr.metallic)