Update RigNet/quick_start.py
Browse files- RigNet/quick_start.py +26 -10
RigNet/quick_start.py
CHANGED
|
@@ -63,7 +63,6 @@ def create_single_data(mesh_filename):
|
|
| 63 |
mesh_v = np.asarray(mesh.vertices)
|
| 64 |
mesh_vn = np.asarray(mesh.vertex_normals)
|
| 65 |
mesh_f = np.asarray(mesh.triangles)
|
| 66 |
-
|
| 67 |
mesh_v, translation_normalize, scale_normalize = normalize_obj(mesh_v)
|
| 68 |
mesh_normalized = o3d.geometry.TriangleMesh(vertices=o3d.utility.Vector3dVector(mesh_v), triangles=o3d.utility.Vector3iVector(mesh_f))
|
| 69 |
o3d.io.write_triangle_mesh(mesh_filename.replace("_remesh.obj", "_normalized.obj"), mesh_normalized)
|
|
@@ -73,17 +72,17 @@ def create_single_data(mesh_filename):
|
|
| 73 |
v = torch.from_numpy(v).float()
|
| 74 |
|
| 75 |
# topology edges
|
| 76 |
-
print("
|
| 77 |
tpl_e = get_tpl_edges(mesh_v, mesh_f).T
|
| 78 |
tpl_e = torch.from_numpy(tpl_e).long()
|
| 79 |
tpl_e, _ = add_self_loops(tpl_e, num_nodes=v.size(0))
|
| 80 |
|
| 81 |
# surface geodesic distance matrix
|
| 82 |
-
print("
|
| 83 |
surface_geodesic = calc_surface_geodesic(mesh)
|
| 84 |
|
| 85 |
# geodesic edges
|
| 86 |
-
print("
|
| 87 |
geo_e = get_geo_edges(surface_geodesic, mesh_v).T
|
| 88 |
geo_e = torch.from_numpy(geo_e).long()
|
| 89 |
geo_e, _ = add_self_loops(geo_e, num_nodes=v.size(0))
|
|
@@ -91,16 +90,33 @@ def create_single_data(mesh_filename):
|
|
| 91 |
# batch
|
| 92 |
batch = torch.zeros(len(v), dtype=torch.long)
|
| 93 |
|
| 94 |
-
# voxel
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
if platform == "linux" or platform == "linux2":
|
| 97 |
-
|
| 98 |
elif platform == "win32":
|
| 99 |
-
|
| 100 |
else:
|
| 101 |
raise Exception('Sorry, we currently only support windows and linux.')
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
vox = binvox_rw.read_as_3d_array(fvox)
|
| 105 |
|
| 106 |
data = Data(x=v[:, 3:6], pos=v[:, 0:3], tpl_edge_index=tpl_e, geo_edge_index=geo_e, batch=batch)
|
|
|
|
| 63 |
mesh_v = np.asarray(mesh.vertices)
|
| 64 |
mesh_vn = np.asarray(mesh.vertex_normals)
|
| 65 |
mesh_f = np.asarray(mesh.triangles)
|
|
|
|
| 66 |
mesh_v, translation_normalize, scale_normalize = normalize_obj(mesh_v)
|
| 67 |
mesh_normalized = o3d.geometry.TriangleMesh(vertices=o3d.utility.Vector3dVector(mesh_v), triangles=o3d.utility.Vector3iVector(mesh_f))
|
| 68 |
o3d.io.write_triangle_mesh(mesh_filename.replace("_remesh.obj", "_normalized.obj"), mesh_normalized)
|
|
|
|
| 72 |
v = torch.from_numpy(v).float()
|
| 73 |
|
| 74 |
# topology edges
|
| 75 |
+
print(" gathering topological edges.")
|
| 76 |
tpl_e = get_tpl_edges(mesh_v, mesh_f).T
|
| 77 |
tpl_e = torch.from_numpy(tpl_e).long()
|
| 78 |
tpl_e, _ = add_self_loops(tpl_e, num_nodes=v.size(0))
|
| 79 |
|
| 80 |
# surface geodesic distance matrix
|
| 81 |
+
print(" calculating surface geodesic matrix.")
|
| 82 |
surface_geodesic = calc_surface_geodesic(mesh)
|
| 83 |
|
| 84 |
# geodesic edges
|
| 85 |
+
print(" gathering geodesic edges.")
|
| 86 |
geo_e = get_geo_edges(surface_geodesic, mesh_v).T
|
| 87 |
geo_e = torch.from_numpy(geo_e).long()
|
| 88 |
geo_e, _ = add_self_loops(geo_e, num_nodes=v.size(0))
|
|
|
|
| 90 |
# batch
|
| 91 |
batch = torch.zeros(len(v), dtype=torch.long)
|
| 92 |
|
| 93 |
+
# voxel - FIXED: Use absolute path and better error handling
|
| 94 |
+
binvox_file = mesh_filename.replace('_remesh.obj', '_normalized.binvox')
|
| 95 |
+
normalized_obj = mesh_filename.replace("_remesh.obj", "_normalized.obj")
|
| 96 |
+
|
| 97 |
+
if not os.path.exists(binvox_file):
|
| 98 |
+
print(f" voxelizing mesh with binvox...")
|
| 99 |
+
|
| 100 |
+
# Use absolute path to binvox (installed in Dockerfile)
|
| 101 |
if platform == "linux" or platform == "linux2":
|
| 102 |
+
cmd = f"binvox -d 88 -pb {normalized_obj}"
|
| 103 |
elif platform == "win32":
|
| 104 |
+
cmd = f"binvox.exe -d 88 {normalized_obj}"
|
| 105 |
else:
|
| 106 |
raise Exception('Sorry, we currently only support windows and linux.')
|
| 107 |
+
|
| 108 |
+
print(f" Running: {cmd}")
|
| 109 |
+
exit_code = os.system(cmd)
|
| 110 |
+
|
| 111 |
+
if exit_code != 0:
|
| 112 |
+
raise Exception(f"binvox command failed with exit code {exit_code}. Command: {cmd}")
|
| 113 |
+
|
| 114 |
+
if not os.path.exists(binvox_file):
|
| 115 |
+
raise Exception(f"binvox did not create output file: {binvox_file}")
|
| 116 |
+
|
| 117 |
+
print(f" ✓ Voxelization complete: {binvox_file}")
|
| 118 |
+
|
| 119 |
+
with open(binvox_file, 'rb') as fvox:
|
| 120 |
vox = binvox_rw.read_as_3d_array(fvox)
|
| 121 |
|
| 122 |
data = Data(x=v[:, 3:6], pos=v[:, 0:3], tpl_edge_index=tpl_e, geo_edge_index=geo_e, batch=batch)
|