Skip to content

Latest commit

 

History

History
80 lines (58 loc) · 3.45 KB

README.md

File metadata and controls

80 lines (58 loc) · 3.45 KB

Streamlit STL Display Component

A Streamlit component to display STL files.

Installation

This component requires access to write files to the temporary directory.

pip install streamlit_stl

Example

Alt Text

Look at the example for a streamlit Web App:

Streamlit App

The original STL file is from Printables.

Usage

Display from file paths

import streamlit as st
from streamlit_stl import stl_from_file

success = stl_from_file(
    file_path=path_to_conf,          # Path to the STL file
    color='#FF9900',                 # Color of the STL file (hexadecimal value)
    material='material',             # Material of the STL file ('material', 'flat', or 'wireframe')
    auto_rotate=True,                # Enable auto-rotation of the STL model
    opacity=1,                       # Opacity of the STL model (0 to 1)
    shininess=100,                   # How shiny the specular highlight is, when using the 'material' style.
    cam_v_angle=60,                  # Vertical angle (in degrees) of the camera
    cam_h_angle=-90,                 # Horizontal angle (in degrees) of the camera
    cam_distance=None,               # Distance of the camera from the object (defaults to 3x bounding box size)
    height=500,                      # Height of the viewer frame
    max_view_distance=1000,          # Maximum viewing distance for the camera
    key=None                         # Streamlit component key
)

Display from file text

import streamlit as st
from streamlit_stl import stl_from_text

file_input = st.file_uploader("Or upload an STL file", type=["stl"])

if file_input is not None:
    success = stl_from_text(
        text=file_input.getvalue(),  # Content of the STL file as text
        color='#FF9900',             # Color of the STL file (hexadecimal value)
        material='material',         # Material of the STL file ('material', 'flat', or 'wireframe')
        auto_rotate=True,            # Enable auto-rotation of the STL model
        opacity=1,                   # Opacity of the STL model (0 to 1)
        shininess=100,               # How shiny the specular highlight is, when using the 'material' style.
        cam_v_angle=60,              # Vertical angle (in degrees) of the camera
        cam_h_angle=-90,             # Horizontal angle (in degrees) of the camera
        cam_distance=None,           # Distance of the camera from the object (defaults to 3x bounding box size)
        height=500,                  # Height of the viewer frame
        max_view_distance=1000,      # Maximum viewing distance for the camera
        key=None                     # Streamlit component key
    )

The functions return a boolean value indicating if the program was able to write and read the files.

The 'material' style is the default style, it uses the Phong shading model from Three.js.

License

Code is licensed under the GNU General Public License v3.0 (GPL-3.0)

License: GPL-3.0