diff --git a/comfy_extras/nodes_hunyuan3d.py b/comfy_extras/nodes_hunyuan3d.py index 09c213cf4..29bdab1dc 100644 --- a/comfy_extras/nodes_hunyuan3d.py +++ b/comfy_extras/nodes_hunyuan3d.py @@ -444,9 +444,7 @@ class VoxelToMeshBasic(IO.ComfyNode): vertices.append(v) faces.append(f) - if vertices and all(v.shape == vertices[0].shape for v in vertices) and all(f.shape == faces[0].shape for f in faces): - return IO.NodeOutput(Types.MESH(torch.stack(vertices), torch.stack(faces))) - return IO.NodeOutput(pack_variable_mesh_batch(vertices, faces)) + return IO.NodeOutput(Types.MESH(torch.stack(vertices), torch.stack(faces))) decode = execute # TODO: remove @@ -483,9 +481,7 @@ class VoxelToMesh(IO.ComfyNode): vertices.append(v) faces.append(f) - if vertices and all(v.shape == vertices[0].shape for v in vertices) and all(f.shape == faces[0].shape for f in faces): - return IO.NodeOutput(Types.MESH(torch.stack(vertices), torch.stack(faces))) - return IO.NodeOutput(pack_variable_mesh_batch(vertices, faces)) + return IO.NodeOutput(Types.MESH(torch.stack(vertices), torch.stack(faces))) decode = execute # TODO: remove @@ -633,57 +629,6 @@ def save_glb(vertices, faces, filepath, metadata=None, colors=None): return filepath - -def pack_variable_mesh_batch(vertices, faces, colors=None): - batch_size = len(vertices) - max_vertices = max(v.shape[0] for v in vertices) - max_faces = max(f.shape[0] for f in faces) - - packed_vertices = vertices[0].new_zeros((batch_size, max_vertices, vertices[0].shape[1])) - packed_faces = faces[0].new_zeros((batch_size, max_faces, faces[0].shape[1])) - vertex_counts = torch.tensor([v.shape[0] for v in vertices], device=vertices[0].device, dtype=torch.int64) - face_counts = torch.tensor([f.shape[0] for f in faces], device=faces[0].device, dtype=torch.int64) - - for i, (v, f) in enumerate(zip(vertices, faces)): - packed_vertices[i, :v.shape[0]] = v - packed_faces[i, :f.shape[0]] = f - - mesh = Types.MESH(packed_vertices, packed_faces) - mesh.vertex_counts = vertex_counts - mesh.face_counts = face_counts - - if colors is not None: - max_colors = max(c.shape[0] for c in colors) - packed_colors = colors[0].new_zeros((batch_size, max_colors, colors[0].shape[1])) - color_counts = torch.tensor([c.shape[0] for c in colors], device=colors[0].device, dtype=torch.int64) - for i, c in enumerate(colors): - packed_colors[i, :c.shape[0]] = c - mesh.colors = packed_colors - mesh.color_counts = color_counts - - return mesh - - -def get_mesh_batch_item(mesh, index): - if hasattr(mesh, "vertex_counts"): - vertex_count = int(mesh.vertex_counts[index].item()) - face_count = int(mesh.face_counts[index].item()) - vertices = mesh.vertices[index, :vertex_count] - faces = mesh.faces[index, :face_count] - colors = None - if hasattr(mesh, "colors") and mesh.colors is not None: - if hasattr(mesh, "color_counts"): - color_count = int(mesh.color_counts[index].item()) - colors = mesh.colors[index, :color_count] - else: - colors = mesh.colors[index, :vertex_count] - return vertices, faces, colors - - colors = None - if hasattr(mesh, "colors") and mesh.colors is not None: - colors = mesh.colors[index] - return mesh.vertices[index], mesh.faces[index], colors - class SaveGLB(IO.ComfyNode): @classmethod def define_schema(cls): @@ -741,8 +686,8 @@ class SaveGLB(IO.ComfyNode): bsz = mesh.vertices.shape[0] for i in range(bsz): f = f"{filename}_{counter:05}_.glb" - vertices, faces, v_colors = get_mesh_batch_item(mesh, i) - save_glb(vertices, faces, os.path.join(full_output_folder, f), metadata, v_colors) + v_colors = mesh.colors[i] if hasattr(mesh, "colors") and mesh.colors is not None else None + save_glb(mesh.vertices[i], mesh.faces[i], os.path.join(full_output_folder, f), metadata, v_colors) results.append({ "filename": f, "subfolder": subfolder,