Created
January 25, 2023 12:27
-
-
Save Merwanski/ebb4145f8d51d6b2e16c8a8de9ff20d9 to your computer and use it in GitHub Desktop.
cad viewer in streamlit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import streamlit as st | |
import io | |
import pyvista as pv | |
from pyvista.jupyter.pv_pythreejs import convert_plotter | |
from ipywidgets import embed | |
import streamlit.components.v1 as components | |
def show_CAD_window(): | |
mesh = pv.read('model.obj') | |
p = pv.Plotter() | |
p.add_mesh(mesh, cmap="terrain", smooth_shading=True) | |
widget = convert_plotter(p) | |
state = embed.dependency_state(widget) | |
fp = io.StringIO() | |
embed.embed_minimal_html(fp, None, title="", state=state) | |
fp.seek(0) | |
snippet = fp.read() | |
components.html(snippet, width=900, height=900) | |
def side_bar_selection(): | |
panel = st.sidebar.radio('Menu', ('Image', 'CAD', 'Settings')) | |
print(panel) | |
if panel == 'Image': | |
pass | |
elif panel == 'CAD': | |
show_CAD_window() | |
elif panel == 'Settings': | |
pass | |
else: | |
st.write('Invalid option') | |
side_bar_selection() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment