pyrender_visualizer_3.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. def render_ground(self, size=[20.0, 20.0],
  2. dsize=[1.0, 1.0],
  3. color=[0.0, 0.0, 0.0, 1.0],
  4. line_width=1.0,
  5. axis="y",
  6. origin=True,
  7. use_arrow=False,
  8. lighting=False):
  9. if self.ground_node is None:
  10. lx = size[0]
  11. lz = size[1]
  12. dx = dsize[0]
  13. dz = dsize[1]
  14. nx = int(lx / dx) + 1
  15. nz = int(lz / dz) + 1
  16. grid_pts = np.zeros((2 * nx + 2 * nz, 3))
  17. colors = np.zeros((2 * nx + 2 * nz, 4))
  18. colors[:] = np.array(color)
  19. if axis is "x":
  20. linei = 0
  21. for i in np.linspace(-0.5 * lx, 0.5 * lx, nx):
  22. grid_pts[2 * linei] = [0, i, -0.5 * lz]
  23. grid_pts[2 * linei + 1] = [0, i, 0.5 * lz]
  24. linei += 1
  25. for i in np.linspace(-0.5 * lz, 0.5 * lz, nz):
  26. grid_pts[2 * linei] = [0, -0.5 * lx, i]
  27. grid_pts[2 * linei + 1] = [0, 0.5 * lx, i]
  28. linei += 1
  29. elif axis is "y":
  30. linei = 0
  31. for i in np.linspace(-0.5 * lx, 0.5 * lx, nx):
  32. grid_pts[2 * linei] = [i, 0, -0.5 * lz]
  33. grid_pts[2 * linei + 1] = [i, 0, 0.5 * lz]
  34. linei += 1
  35. for i in np.linspace(-0.5 * lz, 0.5 * lz, nz):
  36. grid_pts[2 * linei] = [-0.5 * lx, 0, i]
  37. grid_pts[2 * linei + 1] = [0.5 * lx, 0, i]
  38. linei += 1
  39. elif axis is "z":
  40. linei = 0
  41. for i in np.linspace(-0.5 * lx, 0.5 * lx, nx):
  42. grid_pts[2 * linei] = [i, -0.5 * lz, 0.]
  43. grid_pts[2 * linei + 1] = [i, 0.5 * lz, 0.]
  44. linei += 1
  45. for j, i in enumerate(np.linspace(-0.5 * lz, 0.5 * lz, nz)):
  46. grid_pts[2 * linei] = [-0.5 * lx, i, 0.]
  47. grid_pts[2 * linei + 1] = [0.5 * lx, i, 0.]
  48. linei += 1
  49. grid = pyrender.Primitive(grid_pts, color_0=colors, mode=1) # 1->LINES
  50. grid = pyrender.Mesh([grid])
  51. self.ground_node = Node(mesh=grid, name="ground_plane")
  52. self.scene.add_node(self.ground_node)