Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,13 @@ from datasets import load_dataset
|
|
| 3 |
from pymesh import Mesh # For 3D mesh generation
|
| 4 |
import pyvista as pv # For 3D mesh visualization
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
# Page Title
|
| 7 |
st.title("Quick CAD Model Generator")
|
| 8 |
|
|
@@ -59,22 +66,20 @@ elif input_option == "Select Predefined Template":
|
|
| 59 |
# Example using PyMesh for generating a simple cube
|
| 60 |
if selected_template == "Cube": # Replace with your template logic
|
| 61 |
if "width" in user_inputs and "height" in user_inputs and "depth" in user_inputs:
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
plotter = pv.Plotter()
|
| 79 |
-
plotter.add_mesh(py_mesh)
|
| 80 |
-
plotter.show(jupyter_backend='static')
|
|
|
|
| 3 |
from pymesh import Mesh # For 3D mesh generation
|
| 4 |
import pyvista as pv # For 3D mesh visualization
|
| 5 |
|
| 6 |
+
# Error handling for pymesh
|
| 7 |
+
try:
|
| 8 |
+
from pymesh import Mesh
|
| 9 |
+
except ImportError:
|
| 10 |
+
print("Error: pymesh.Mesh not found. Please install pymesh using 'pip install pymesh'.")
|
| 11 |
+
st.error("**Mesh generation functionality requires pymesh library. Please install it.**")
|
| 12 |
+
|
| 13 |
# Page Title
|
| 14 |
st.title("Quick CAD Model Generator")
|
| 15 |
|
|
|
|
| 66 |
# Example using PyMesh for generating a simple cube
|
| 67 |
if selected_template == "Cube": # Replace with your template logic
|
| 68 |
if "width" in user_inputs and "height" in user_inputs and "depth" in user_inputs:
|
| 69 |
+
try:
|
| 70 |
+
width = float(user_inputs["width"])
|
| 71 |
+
height = float(user_inputs["height"])
|
| 72 |
+
depth = float(user_inputs["depth"])
|
| 73 |
+
cube_vertices = [
|
| 74 |
+
[0, 0, 0], [width, 0, 0], [width, height, 0], [0, height, 0],
|
| 75 |
+
[0, 0, depth], [width, 0, depth], [width, height, depth], [0, height, depth]
|
| 76 |
+
]
|
| 77 |
+
cube_faces = [
|
| 78 |
+
[0, 1, 2, 3], [4, 5, 6, 7],
|
| 79 |
+
[0, 4, 5, 1], [1, 5, 6, 2],
|
| 80 |
+
[2, 6, 7, 3], [0, 3, 7, 4]
|
| 81 |
+
]
|
| 82 |
+
cube_mesh = Mesh(vertices=cube_vertices, faces=cube_faces)
|
| 83 |
|
| 84 |
+
# **Visualization using PyVista**
|
| 85 |
+
py_mesh = pv.wrap(cube_mesh) # Convert PyMesh to PyVista
|
|
|
|
|
|
|
|
|