paint_mesh: Taubin smoothing before decimation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
"""Gives a Hunyuan3D shape its colours back, from the pictures it was made from.
|
"""Gives a Hunyuan3D shape its colours back, from the pictures it was made from.
|
||||||
|
|
||||||
gen paint_mesh <shape.glb> <front.png> [--back=<back.png>] [--back-mirrored]
|
gen paint_mesh <shape.glb> <front.png> [--back=<back.png>] [--back-mirrored]
|
||||||
[--name=hero] [--faces=30000] [--height=180]
|
[--name=hero] [--faces=30000] [--height=180] [--smooth=12]
|
||||||
|
|
||||||
Hunyuan3D (generate_mesh) returns shape only. This tool:
|
Hunyuan3D (generate_mesh) returns shape only. This tool:
|
||||||
|
|
||||||
@@ -41,13 +41,16 @@ import config
|
|||||||
|
|
||||||
# ── shape ────────────────────────────────────────────────────────────────
|
# ── shape ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
def clean(path, faces):
|
def clean(path, faces, smooth=12):
|
||||||
mesh = trimesh.load(path, force="mesh")
|
mesh = trimesh.load(path, force="mesh")
|
||||||
parts = mesh.split(only_watertight=False)
|
parts = mesh.split(only_watertight=False)
|
||||||
big = max(len(p.faces) for p in parts)
|
big = max(len(p.faces) for p in parts)
|
||||||
keep = [p for p in parts if len(p.faces) >= big * 0.02]
|
keep = [p for p in parts if len(p.faces) >= big * 0.02]
|
||||||
mesh = trimesh.util.concatenate(keep)
|
mesh = trimesh.util.concatenate(keep)
|
||||||
print(f"shape: {len(parts)} parts, kept {len(keep)} -> {len(mesh.faces)} faces")
|
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:
|
if len(mesh.faces) > faces:
|
||||||
mesh = mesh.simplify_quadric_decimation(face_count=faces)
|
mesh = mesh.simplify_quadric_decimation(face_count=faces)
|
||||||
mesh.merge_vertices()
|
mesh.merge_vertices()
|
||||||
@@ -222,7 +225,7 @@ def main():
|
|||||||
out = config.OUTPUT_DIR
|
out = config.OUTPUT_DIR
|
||||||
os.makedirs(out, exist_ok=True)
|
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)
|
verts = np.asarray(mesh.vertices)
|
||||||
normals = np.asarray(mesh.vertex_normals)
|
normals = np.asarray(mesh.vertex_normals)
|
||||||
samples, _ = trimesh.sample.sample_surface(mesh, 600_000)
|
samples, _ = trimesh.sample.sample_surface(mesh, 600_000)
|
||||||
|
|||||||
Reference in New Issue
Block a user