Section ============= A demonstration of mesh-plane cross-sections, commonly referred to as "slicing" in the context of 3D printing. .. code:: ipython3 import numpy as np from shapely.geometry import LineString import trimesh %pylab inline %config InlineBackend.figure_format = 'svg' .. parsed-literal:: %pylab is deprecated, use %matplotlib inline and import the required libraries. Populating the interactive namespace from numpy and matplotlib .. code:: ipython3 # load the mesh from filename # file objects are also supported mesh = trimesh.load_mesh("../models/featuretype.STL") .. code:: ipython3 # get a single cross section of the mesh slice = mesh.section(plane_origin=mesh.centroid, plane_normal=[0, 0, 1]) .. code:: ipython3 # the section will be in the original mesh frame slice.show() .. raw:: html
.. code:: ipython3 # we can move the 3D curve to a Path2D object easily slice_2D, to_3D = slice.to_planar() slice_2D.show() .. image:: section_files/section_5_0.svg .. code:: ipython3 # if we wanted to take a bunch of parallel slices, like for a 3D printer # we can do that easily with the section_multiplane method # we're going to slice the mesh into evenly spaced chunks along z # this takes the (2,3) bounding box and slices it into [minz, maxz] z_extents = mesh.bounds[:, 2] # slice every .125 model units (eg, inches) z_levels = np.arange(*z_extents, step=0.125) .. code:: ipython3 # find a bunch of parallel cross sections sections = mesh.section_multiplane( plane_origin=mesh.bounds[0], plane_normal=[0, 0, 1], heights=z_levels ) sections .. parsed-literal:: [