Create streamlit application which take a OBJ file in input, and display the 3d mesh in a 3D plotly chart
To upload files, please first save the app
import streamlit as st
import plotly.graph_objects as go
import trimesh
st.title('3D OBJ Viewer')
# Upload the OBJ file
uploaded_file = st.file_uploader('Choose an OBJ file', type='obj')
if uploaded_file is not None:
# Load the mesh using trimesh
mesh = trimesh.load(uploaded_file)
# Create a Plotly figure
fig = go.Figure(data=[go.Mesh3d(
x=mesh.vertices[:, 0],
y=mesh.vertices[:, 1],
z=mesh.vertices[:, 2],
i=mesh.faces[:, 0],
j=mesh.faces[:, 1],
k=mesh.faces[:, 2],
opacity=0.5,
color='lightblue'
)])
# Update layout
fig.update_layout(scene=dict(
xaxis=dict(title='X'),
yaxis=dict(title='Y'),
zaxis=dict(title='Z'),
))
# Show the figure
st.plotly_chart(fig, use_container_width=True)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?