diff --git a/nodes.py b/nodes.py index a1bd193..ad63f40 100644 --- a/nodes.py +++ b/nodes.py @@ -16,6 +16,9 @@ import gc import cumesh as CuMesh +import meshlib.mrmeshnumpy as mrmeshnumpy +import meshlib.mrmeshpy as mrmeshpy + import nvdiffrast.torch as dr from flex_gemm.ops.grid_sample import grid_sample_3d @@ -41,6 +44,32 @@ def convert_tensor_images_to_pil(images): pil_array.append(tensor2pil(image)) return pil_array + +def simplify_with_meshlib(vertices, faces, target=1000000): + current_faces_num = len(faces) + print(f'Current Faces Number: {current_faces_num}') + + if current_faces_num CPU -> Meshlib -> CPU -> GPU + v, f = cumesh.read() + new_vertices, new_faces = simplify_with_meshlib(v.cpu().numpy(), f.cpu().numpy(), target_face_num) + cumesh.init(torch.from_numpy(new_vertices).float().cuda(), torch.from_numpy(new_faces).int().cuda()) + print(f"After simplifying: {cumesh.num_vertices} vertices, {cumesh.num_faces} faces") print('Unwrapping ...')