Skip to content

Instantly share code, notes, and snippets.

@mikedh
Created June 14, 2018 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikedh/3a462587c1519e3cefdfd6f6c7c1b2ab to your computer and use it in GitHub Desktop.
Save mikedh/3a462587c1519e3cefdfd6f6c7c1b2ab to your computer and use it in GitHub Desktop.
import trimesh
import numpy as np
from scipy.spatial import Voronoi
if __name__ == '__main__':
points = np.random.random((20,3))
v = Voronoi(points)
meshes = []
for idx in v.regions:
# only mesh finite regions
if -1 in idx: continue
if len(idx) < 4: continue
m = trimesh.convex.convex_hull(v.vertices[idx])
# color BS
color = trimesh.visual.random_color()
color[3] = 50
m.visual.face_colors = color
meshes.append(m)
# show with points
trimesh.Scene(np.append(meshes, trimesh.points.PointCloud(points))).show(smooth=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment