# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Displaying 3D Objects in Jupyter
#
# I was missing the possibility to display 3D objects directly in Jupyterlab. So I implemented a simpole Mime Renderer with the help of Three.js.
#
# You can direclty open any files like the [cube.stl](./cube.stl) or you can display them in Cell as demonstrated below. 
#
# The following mime types are supported:
# - model/stl
# - model/amf
# - model/obj
# - model/3mf
# - model/gcode
# - model/vnd.collada+xml
#
#
# ## Installation
# The extension can be installed with the folliwng 
# ```bash
# git clone 
# # cd jupyterlab-viewer-stl
# npm install
# npm run build
# jupyter labextension install
# ```
#
#
# ## Examples
# The following examples are written in Python. However I plan to use them in my JVM based kernels.... 
#

from IPython.display import publish_display_data


with open('cube.stl','rb') as f:
    publish_display_data({'model/stl': f.read()})


with open('cube.gcode','rb') as f:
    publish_display_data({'model/gcode': f.read()})

with open('cube.amf','rb') as f:
    publish_display_data({'model/amf': f.read()})





StarcoderdataJupyterScriptsDedupFiltered