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)