boolean.py 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. from vedo import settings, Sphere, Plotter
  2. # Enable depth peeling for rendering transparency
  3. settings.use_depth_peeling = True
  4. # Declare an instance of the Plotter class with 2 rows and 2 columns of renderers,
  5. # and disable interactive mode, so that the program can continue running
  6. plt = Plotter(shape=(2, 2), interactive=False, axes=3)
  7. # Create two sphere meshes
  8. s1 = Sphere(pos=[-0.7, 0, 0]).c("red5",0.5)
  9. s2 = Sphere(pos=[0.7, 0, 0]).c("green5",0.5)
  10. # Show the spheres on the first renderer, and display the docstring as the title
  11. plt.at(0).show(s1, s2, __doc__)
  12. # Perform a boolean intersection operation between the two spheres,
  13. # set the color to magenta, and show the result on the second renderer
  14. b1 = s1.boolean("intersect", s2).c('magenta')
  15. plt.at(1).show(b1, "intersect", resetcam=False)
  16. # Perform a boolean union operation between the two spheres,
  17. # set the color to blue, add a wireframe, and show the result on the third renderer
  18. b2 = s1.boolean("plus", s2).c("blue").wireframe(True)
  19. plt.at(2).show(b2, "plus", resetcam=False)
  20. # Perform a boolean difference operation between the two spheres,
  21. # compute the normals, add a scalarbar, and show the result on the fourth renderer
  22. b3 = s1.boolean("minus", s2).compute_normals().add_scalarbar(c='white')
  23. plt.at(3).show(b3, "minus", resetcam=False)
  24. # Enable interactive mode, and close the plot
  25. plt.interactive().close()