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 <amp@ampcode.com>
This commit is contained in:
Jedrzej Kosinski 2026-06-14 23:48:03 -07:00
parent 81f5f84ad6
commit 029b782936

View File

@ -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)