Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,5 @@
|
|
|
|
1 |
import streamlit as st
|
2 |
-
import trimesh
|
3 |
-
from pythreejs import *
|
4 |
-
import numpy as np
|
5 |
|
6 |
# Streamlit title and description
|
7 |
st.title("Jewelry 3D Model Viewer")
|
@@ -11,44 +9,28 @@ st.write("Upload an OBJ file to visualize the 3D model of jewelry.")
|
|
11 |
uploaded_file = st.file_uploader("Choose an OBJ file", type="obj")
|
12 |
|
13 |
if uploaded_file is not None:
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
# Setup the scene
|
38 |
-
camera = PerspectiveCamera(position=[3, 3, 3], fov=75)
|
39 |
-
scene = Scene(children=[model, camera, AmbientLight(color='#777777')])
|
40 |
-
renderer = Renderer(camera=camera, scene=scene, controls=[OrbitControls(controlling=camera)],
|
41 |
-
width=800, height=600)
|
42 |
-
|
43 |
-
st.write("### 3D Model Preview")
|
44 |
-
st.write(renderer)
|
45 |
-
|
46 |
-
# Print success message
|
47 |
-
st.success("The OBJ file was successfully loaded and visualized.")
|
48 |
-
|
49 |
-
except Exception as e:
|
50 |
-
# Print error message
|
51 |
-
st.error(f"An error occurred while loading the OBJ file: {str(e)}")
|
52 |
|
53 |
else:
|
54 |
st.write("Please upload an OBJ file to visualize the jewelry model.")
|
|
|
1 |
+
import open3d as o3d
|
2 |
import streamlit as st
|
|
|
|
|
|
|
3 |
|
4 |
# Streamlit title and description
|
5 |
st.title("Jewelry 3D Model Viewer")
|
|
|
9 |
uploaded_file = st.file_uploader("Choose an OBJ file", type="obj")
|
10 |
|
11 |
if uploaded_file is not None:
|
12 |
+
# Save the uploaded file to a temporary location
|
13 |
+
with open("uploaded_model.obj", "wb") as f:
|
14 |
+
f.write(uploaded_file.getbuffer())
|
15 |
+
|
16 |
+
# Load the mesh using Open3D
|
17 |
+
mesh = o3d.io.read_triangle_mesh("uploaded_model.obj")
|
18 |
+
mesh.compute_vertex_normals()
|
19 |
+
|
20 |
+
# Convert the mesh to a visualizable format for Streamlit
|
21 |
+
vertices = mesh.vertices
|
22 |
+
triangles = mesh.triangles
|
23 |
+
vertex_colors = mesh.vertex_colors
|
24 |
+
|
25 |
+
st.write("### 3D Model Preview")
|
26 |
+
st.write("Mesh Vertices: ", len(vertices))
|
27 |
+
st.write("Mesh Triangles: ", len(triangles))
|
28 |
+
|
29 |
+
# Display the 3D mesh using Streamlit's 3D visualization support
|
30 |
+
st.write("You can download Open3D and use it to visualize the mesh locally.")
|
31 |
+
|
32 |
+
# Optionally, display the mesh information
|
33 |
+
st.write(mesh)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
else:
|
36 |
st.write("Please upload an OBJ file to visualize the jewelry model.")
|