From 953ec56630770dd5f940bfc89cfd9e60957bf931 Mon Sep 17 00:00:00 2001 From: Michi Date: Sun, 8 Nov 2026 01:50:09 +0100 Subject: [PATCH] paint_mesh: Taubin smoothing before decimation Co-Authored-By: Claude Opus 5.5 --- paint_mesh.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/paint_mesh.py b/paint_mesh.py index c6637b2..443a5be 100644 --- a/paint_mesh.py +++ b/paint_mesh.py @@ -1,7 +1,7 @@ """Gives a Hunyuan3D shape its colours back, from the pictures it was made from. gen paint_mesh [--back=] [--back-mirrored] - [--name=hero] [--faces=30000] [--height=180] + [--name=hero] [--faces=30000] [--height=180] [--smooth=12] Hunyuan3D (generate_mesh) returns shape only. This tool: @@ -41,13 +41,16 @@ import config # ── shape ──────────────────────────────────────────────────────────────── -def clean(path, faces): +def clean(path, faces, smooth=12): mesh = trimesh.load(path, force="mesh") parts = mesh.split(only_watertight=False) big = max(len(p.faces) for p in parts) keep = [p for p in parts if len(p.faces) >= big * 0.02] mesh = trimesh.util.concatenate(keep) print(f"shape: {len(parts)} parts, kept {len(keep)} -> {len(mesh.faces)} faces") + if smooth: + # surface net leaves a grainy, stair-stepped skin; Taubin smooths it without shrinking + trimesh.smoothing.filter_taubin(mesh, iterations=smooth) if len(mesh.faces) > faces: mesh = mesh.simplify_quadric_decimation(face_count=faces) mesh.merge_vertices() @@ -222,7 +225,7 @@ def main(): out = config.OUTPUT_DIR os.makedirs(out, exist_ok=True) - mesh = clean(args[0], int(flags.get("--faces", 30000))) + mesh = clean(args[0], int(flags.get("--faces", 30000)), int(flags.get("--smooth", 12))) verts = np.asarray(mesh.vertices) normals = np.asarray(mesh.vertex_normals) samples, _ = trimesh.sample.sample_surface(mesh, 600_000)