File size: 1,194 Bytes
fbccb98
afe1c50
 
 
 
 
 
 
 
 
 
fbccb98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
afe1c50
 
170c731
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import open3d as o3d
import streamlit as st

# Streamlit title and description
st.title("Jewelry 3D Model Viewer")
st.write("Upload an OBJ file to visualize the 3D model of jewelry.")

# File uploader for the OBJ file
uploaded_file = st.file_uploader("Choose an OBJ file", type="obj")

if uploaded_file is not None:
    # Save the uploaded file to a temporary location
    with open("uploaded_model.obj", "wb") as f:
        f.write(uploaded_file.getbuffer())

    # Load the mesh using Open3D
    mesh = o3d.io.read_triangle_mesh("uploaded_model.obj")
    mesh.compute_vertex_normals()
    
    # Convert the mesh to a visualizable format for Streamlit
    vertices = mesh.vertices
    triangles = mesh.triangles
    vertex_colors = mesh.vertex_colors

    st.write("### 3D Model Preview")
    st.write("Mesh Vertices: ", len(vertices))
    st.write("Mesh Triangles: ", len(triangles))
    
    # Display the 3D mesh using Streamlit's 3D visualization support
    st.write("You can download Open3D and use it to visualize the mesh locally.")
    
    # Optionally, display the mesh information
    st.write(mesh)

else:
    st.write("Please upload an OBJ file to visualize the jewelry model.")