code: def voxelize_ray(mesh,
                   pitch,
                   per_cell=[2, 2],
                   **kwargs):
      
      # how many rays per cell
      per_cell = np.array(per_cell).astype(np.int).reshape(2)
      # edge length of cube voxels
      pitch = float(pitch)
  
      # create the ray origins in a grid
      bounds = mesh.bounds[:, :2].copy()
      # offset start so we get the requested number per cell
      bounds[0] += pitch / (1.0 + per_cell)
      # offset end so arange doesn't short us
      bounds[1] += pitch
      # on X we are doing multiple rays per voxel step
      step = pitch / per_cell
      # 2D grid
      ray_ori = util.grid_arange(bounds, step=step)
      # a Z position below the mesh
      z = np.ones(len(ray_ori)) * (mesh.bounds[0][2] - pitch)
      ray_ori = np.column_stack((ray_ori, z))
      # all rays are along positive Z
      ray_dir = np.ones_like(ray_ori) * [0, 0, 1]
  
      # if you have pyembree this should be decently fast
      hits = mesh.ray.intersects_location(ray_ori, ray_dir)[0]
  
      # just convert hit locations to integer positions
      voxels = np.round(hits / pitch).astype(np.int64)
  
      # offset voxels by min, so matrix isn't huge
      origin = voxels.min(axis=0)
      voxels -= origin
  
      return voxels, origin
docs: Voxelize a mesh using ray queries.
  
      Parameters
      -------------
      mesh     : Trimesh object
                   Mesh to be voxelized
      pitch    : float
                   Length of voxel cube
      per_cell : (2,) int
                   How many ray queries to make per cell
  
      Returns
      -------------
      voxels : (n, 3) int
                   Voxel positions
      origin : (3, ) int
                   Origin of voxels