Official Codebase of 3DCodeVerse
Python
texturing: drop the knobs nothing passes; record_texturing reads through proc.read_json_or_none
gaoypengda5ef8f6ea9a
diff --git a/harness/codeverse3d/texturing/apply.py b/harness/codeverse3d/texturing/apply.pyindex 0e1e6887..5aa07e6b 100644--- a/harness/codeverse3d/texturing/apply.py+++ b/harness/codeverse3d/texturing/apply.py@@ -349,22 +349,19 @@ def node_part_lookup(node_names: list[str], plan_parts: dict[str, TexturePart])return out-def _material(- part: TexturePart, image: Image.Image, *, derived_maps: bool = True-) -> trimesh.visual.material.PBRMaterial:+def _material(part: TexturePart, image: Image.Image) -> trimesh.visual.material.PBRMaterial:"""PBR material for one texture id.- Beyond the albedo the material carries two maps DERIVED from that albedo- (``derived_maps`` below): a metallic/roughness texture so the grain also modulates- the specular lobe, and a normal map so it catches light in relief. They cost- no extra image call and cannot disagree with the colour. ``derived_maps=False``- reproduces the albedo-only material the pass shipped before.+ Beyond the albedo the material carries two maps DERIVED from that albedo (a flat+ image gets none): a metallic/roughness texture so the grain also modulates the+ specular lobe, and a normal map so it catches light in relief. They cost no extra+ image call and cannot disagree with the colour."""tint = part.tint_rgb or (1.0, 1.0, 1.0)factor = [int(round(255 * float(c))) for c in tint] + [255]fine = COARSE_TO_FINE.get(part.material_family, part.material_family)extra: dict[str, Any] = {}- if derived_maps and not is_flat(image):+ if not is_flat(image):extra["metallicRoughnessTexture"] = metallic_roughness_image(image, float(part.roughness), float(part.metallic), fine)extra["normalTexture"] = normal_image(image, fine)@@ -389,9 +386,6 @@ def apply_textures(texture_plan: TexturePlan,textures: dict[str, Path | str],glb_out: Path | str,- *,- verify: bool = True,- derived_maps: bool = True,) -> ApplyReport:"""Write ``glb_out`` = ``glb_in`` with textured PBR materials on the planned parts.``textures`` maps texture_id → PNG path (missing ids leave those parts untextured)."""@@ -445,7 +439,7 @@ def apply_textures(mkey = (part.texture_id, float(part.roughness), float(part.metallic), part.tint_rgb)mat = materials.get(mkey)if mat is None:- mat = materials[mkey] = _material(part, img, derived_maps=derived_maps)+ mat = materials[mkey] = _material(part, img)mesh = trimesh.Trimesh(vertices=uw.vertices, faces=uw.faces, vertex_normals=uw.normals, process=False)mesh.visual = trimesh.visual.TextureVisuals(uv=uw.uv, material=mat)mesh.metadata = dict(geom.metadata or {})@@ -458,8 +452,7 @@ def apply_textures(rep.n_derived_maps = sum(1 for m in materials.values() if getattr(m, "normalTexture", None) is not None)glb_out.parent.mkdir(parents=True, exist_ok=True)scene.export(glb_out)- if verify:- rep.warnings.extend(verify_textured_glb(glb_in, glb_out, expected_textured=len(rep.parts_textured)))+ rep.warnings.extend(verify_textured_glb(glb_in, glb_out, expected_textured=len(rep.parts_textured)))rep.duration_ms = int((time.time() - t0) * 1000)return rep@@ -612,7 +605,7 @@ def classify(def normalise_materials(- glb_in: Path | str, glb_out: Path | str, *, plan: StaticPlan | None = None, write: bool = True+ glb_in: Path | str, glb_out: Path | str, *, plan: StaticPlan | None = None) -> NormaliseReport:"""Rewrite the flat-default / impossible materials of ``glb_in`` into ``glb_out``.@@ -658,7 +651,7 @@ def normalise_materials(keyword=verdict.keyword, reason=verdict.reason,metallic=(round(before[0], 3), verdict.metallic), roughness=(round(before[1], 3), verdict.roughness),))- if rep.changes and write:+ if rep.changes:glb_out.parent.mkdir(parents=True, exist_ok=True)scene.export(glb_out)rep.glb_out = str(glb_out)diff --git a/harness/codeverse3d/texturing/generate.py b/harness/codeverse3d/texturing/generate.pyindex 2ec560a7..7a22c43c 100644--- a/harness/codeverse3d/texturing/generate.py+++ b/harness/codeverse3d/texturing/generate.py@@ -166,7 +166,7 @@ def _cache_dir(cache_dir: Path | None) -> Path:def generate_one(texture_id: str, prompt: str, out_dir: Path, image_model: Any, *, size: int = 1024, cache_dir: Path | None = None,- tileable: bool = True, border_frac: float = 0.12, use_cache: bool = True, seed: int | None = 0,+ use_cache: bool = True, seed: int | None = 0,) -> TextureAsset:"""Generate (or fetch from cache) one texture and deliver ``out_dir/<texture_id>.png``."""model_id = getattr(image_model, "id", getattr(image_model, "model", "image"))@@ -195,9 +195,7 @@ def generate_one(finally:tmp.unlink(missing_ok=True)asset.seam_score_raw = seam_score(raw)- img = fit_size(raw, size)- if tileable:- img = make_tileable(img, border_frac)+ img = make_tileable(fit_size(raw, size))asset.seam_score = seam_score(img)save_texture(img, Path(asset.path))asset.usage.latency_ms = asset.usage.latency_ms or int((time.time() - t0) * 1000)@@ -212,8 +210,6 @@ def generate_textures(size: int = 1024,cache_dir: Path | None = None,max_workers: int = 6,- tileable: bool = True,- border_frac: float = 0.12,use_cache: bool = True,seed: int = 0,) -> TextureSet:@@ -242,7 +238,7 @@ def generate_textures(def _job(tid: str) -> TextureAsset:try:return generate_one(tid, prompts[tid], out_dir, image_model, size=size, cache_dir=cache_dir,- tileable=tileable, border_frac=border_frac, use_cache=use_cache, seed=seed)+ use_cache=use_cache, seed=seed)except Exception as e: # noqa: BLE001 — per-texture failure is data, not a crashlog.warning("texture %s failed: %s: %s", tid, type(e).__name__, e)return TextureAsset(texture_id=tid, path=str(out_dir / f"{tid}.png"), prompt=prompts[tid],diff --git a/harness/codeverse3d/texturing/run.py b/harness/codeverse3d/texturing/run.pyindex c98b8453..8e5b9d39 100644--- a/harness/codeverse3d/texturing/run.py+++ b/harness/codeverse3d/texturing/run.py@@ -16,7 +16,6 @@ rejected pass leaves no canonical file for the deliverable/gallery to pick up.from __future__ import annotations-import jsonimport loggingimport timefrom collections.abc import Sequence@@ -31,7 +30,7 @@ from codeverse3d.contracts.common import TRACK_INFO, Track, Usagefrom codeverse3d.contracts.plan import StaticPlanfrom codeverse3d.contracts.spec import Specfrom codeverse3d.conventions import OBJECT_VIEWS_QUICK, ViewPreset-from codeverse3d.proc import EventLog+from codeverse3d.proc import EventLog, read_json_or_nonefrom codeverse3d.texturing.apply import (ApplyReport,NormaliseReport,@@ -316,11 +315,8 @@ def report_path(ws: Workspace) -> Path:def record_texturing(ws: Workspace, report: TextureReport) -> bool:"""``record.json`` extra["texturing"] = summary (+ asset paths) when a record exists."""- if not ws.record_path.is_file():- return False- try:- data = json.loads(ws.record_path.read_text())- except json.JSONDecodeError:+ data = read_json_or_none(ws.record_path)+ if data is None:return Falseextra = data.setdefault("extra", {})extra["texturing"] = texturing_extra(ws, report)