title: Rendering 2D images from STL file in Python
body: <p>I would like to load an STL file and produce a set of 2D images in different rotations. </p>
  
  <p>I got the basics working with numpy-stl based on <a href="https://w.wol.ph/2015/07/10/rendering-stl-files-matplotlib-numpy-stl/" rel="nofollow noreferrer">this</a> example, ended up with this code - </p>
  
  <pre><code>from stl import mesh
  from mpl_toolkits import mplot3d
  from matplotlib import pyplot
  
  filename = '3001.stl'
  
  # Create a new plot
  figure = pyplot.figure()
  axes = figure.gca(projection='3d')
  
  # Load the STL files and add the vectors to the plot
  mesh = mesh.Mesh.from_file(filename)
  
  axes.add_collection3d(mplot3d.art3d.Poly3DCollection(mesh.vectors, color='lightgrey'))
  #axes.plot_surface(mesh.x,mesh.y,mesh.z)
  # Auto scale to the mesh size
  scale = mesh.points.flatten()
  axes.auto_scale_xyz(scale, scale, scale)
  
  #turn off grid and axis from display      
  pyplot.axis('off')
  
  #set viewing angle
  axes.view_init(azim=120)
  
  # Show the plot to the screen
  pyplot.show()
  </code></pre>
  
  <p>This works well only that I end up with a silhouette of the component, lacking a lot of the detail. the picture below is a lego brick...  <a href="https://i.stack.imgur.com/zorrN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zorrN.png" alt="Lego brick"></a></p>
  
  <p>I tried to highlight the edges. but that is sensitive to how the model was created, which is not great for me. </p>
  
  <p><a href="https://i.stack.imgur.com/yQGet.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yQGet.png" alt="Lego brick with edges"></a></p>
  
  <p>I was hoping that by adding lighting, the shadows could help add the missing detail but I can't find a way to do that.</p>
  
  <p>Any idea how to add lightsource to the code below to create shadows ?</p>