Upload visualize_mesh.py with huggingface_hub
Browse files- visualize_mesh.py +36 -0
visualize_mesh.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import trimesh
|
| 2 |
+
import sys
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
def visualize(mesh_path):
|
| 6 |
+
if not os.path.exists(mesh_path):
|
| 7 |
+
print(f"Error: File {mesh_path} not found.")
|
| 8 |
+
return
|
| 9 |
+
|
| 10 |
+
try:
|
| 11 |
+
# Load the mesh
|
| 12 |
+
# force='mesh' ensures we get a Trimesh object if possible,
|
| 13 |
+
# though .obj usually loads as such or a Scene.
|
| 14 |
+
mesh = trimesh.load(mesh_path, force='mesh')
|
| 15 |
+
|
| 16 |
+
print(f"Loaded mesh from {mesh_path}")
|
| 17 |
+
print(f"Vertices: {len(mesh.vertices)}")
|
| 18 |
+
print(f"Faces: {len(mesh.faces)}")
|
| 19 |
+
|
| 20 |
+
# Create a scene to add lights and camera if needed,
|
| 21 |
+
# but mesh.show() handles basic setup.
|
| 22 |
+
print("Opening visualization window...")
|
| 23 |
+
mesh.show()
|
| 24 |
+
|
| 25 |
+
except Exception as e:
|
| 26 |
+
print(f"Failed to visualize mesh: {e}")
|
| 27 |
+
print("\nNote: Visualization requires a display environment (GUI).")
|
| 28 |
+
print("If you are running on a headless server, you cannot open a window.")
|
| 29 |
+
|
| 30 |
+
if __name__ == "__main__":
|
| 31 |
+
# Default to output_mesh.obj if no argument provided
|
| 32 |
+
mesh_path = "output_mesh.obj"
|
| 33 |
+
if len(sys.argv) > 1:
|
| 34 |
+
mesh_path = sys.argv[1]
|
| 35 |
+
|
| 36 |
+
visualize(mesh_path)
|