From 029b782936afbad9400c567cda84388b6aee41e5 Mon Sep 17 00:00:00 2001 From: Jedrzej Kosinski Date: Sun, 14 Jun 2026 23:48:03 -0700 Subject: [PATCH] Cube3D: fix mesh winding for vendored marching cubes The vendored Lorensen table emits the opposite base winding from skimage, so the upstream-style faces[:, [2,1,0]] flip produced inward-facing normals (negative mesh volume). Drop the flip so normals point outward (positive volume), matching the upstream output orientation. Amp-Thread-ID: https://ampcode.com/threads/T-019ec361-addb-70d8-a74b-438ce8a1e096 Co-authored-by: Amp --- comfy/ldm/cube/vae.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/comfy/ldm/cube/vae.py b/comfy/ldm/cube/vae.py index a83d6eb2b..b4c9a7ee7 100644 --- a/comfy/ldm/cube/vae.py +++ b/comfy/ldm/cube/vae.py @@ -354,10 +354,11 @@ class CubeShapeVAE(nn.Module): def grid_logits_to_mesh(grid_logit, grid_size, bbox_size, bbox_min, level=0.0): """Occupancy-logit grid -> mesh, using the vendored dependency-free marching cubes - (classic Lorensen, same family as upstream cube's default warp backend). The vertex - transform mirrors upstream: index coords -> bbox, with the same face winding flip.""" + (classic Lorensen, same family as upstream cube's default warp backend). Vertices are + rescaled from grid-index space into the bbox, matching upstream's transform.""" from comfy.ldm.cube.marching_cubes import marching_cubes vertices, faces = marching_cubes(grid_logit, level) vertices = vertices / np.array(grid_size) * bbox_size + bbox_min - faces = faces[:, [2, 1, 0]] + # The vendored Lorensen table already emits outward-facing winding for this + # occupancy convention, so (unlike the upstream skimage path) no face flip is needed. return vertices.astype(np.float32), np.ascontiguousarray(faces)