# ---
# 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
# ---

# +
"""
trimesh and vtkplotter interoperability
"""

# Install trimesh with:
# sudo apt install python3-rtree
# pip install rtree shapely
# conda install trimesh

import trimesh
from vtkplotter import download, trimesh2vtk, show, embedWindow, closePlotter

# uncomment this to pop a vtk rendering window instead of the K3D notebook backend
embedWindow(False)

url = 'https://raw.githubusercontent.com/mikedh/trimesh/master/models/'
filename = download(url + 'machinist.XAML')
mesh = trimesh.load(filename)

# +
actor = trimesh2vtk(mesh) # returns a Actor(vtkActor) object from Trimesh

# Any of these will work:
show(mesh) # conversion is on the fly (don't need 'actor')

# or
#actor.show()

# or
#show(actor)

# or
#mesh.show() # this is the trimesh built-in visualizer

# This closes the vtk rendering window. Use only if embedWindow(False)
closePlotter()
# -



StarcoderdataJupyterScriptsDedupFiltered