12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- def render_ground(self, size=[20.0, 20.0],
- dsize=[1.0, 1.0],
- color=[0.0, 0.0, 0.0, 1.0],
- line_width=1.0,
- axis="y",
- origin=True,
- use_arrow=False,
- lighting=False):
- if self.ground_node is None:
- lx = size[0]
- lz = size[1]
- dx = dsize[0]
- dz = dsize[1]
- nx = int(lx / dx) + 1
- nz = int(lz / dz) + 1
- grid_pts = np.zeros((2 * nx + 2 * nz, 3))
- colors = np.zeros((2 * nx + 2 * nz, 4))
- colors[:] = np.array(color)
- if axis is "x":
- linei = 0
- for i in np.linspace(-0.5 * lx, 0.5 * lx, nx):
- grid_pts[2 * linei] = [0, i, -0.5 * lz]
- grid_pts[2 * linei + 1] = [0, i, 0.5 * lz]
- linei += 1
- for i in np.linspace(-0.5 * lz, 0.5 * lz, nz):
- grid_pts[2 * linei] = [0, -0.5 * lx, i]
- grid_pts[2 * linei + 1] = [0, 0.5 * lx, i]
- linei += 1
- elif axis is "y":
- linei = 0
- for i in np.linspace(-0.5 * lx, 0.5 * lx, nx):
- grid_pts[2 * linei] = [i, 0, -0.5 * lz]
- grid_pts[2 * linei + 1] = [i, 0, 0.5 * lz]
- linei += 1
- for i in np.linspace(-0.5 * lz, 0.5 * lz, nz):
- grid_pts[2 * linei] = [-0.5 * lx, 0, i]
- grid_pts[2 * linei + 1] = [0.5 * lx, 0, i]
- linei += 1
- elif axis is "z":
- linei = 0
- for i in np.linspace(-0.5 * lx, 0.5 * lx, nx):
- grid_pts[2 * linei] = [i, -0.5 * lz, 0.]
- grid_pts[2 * linei + 1] = [i, 0.5 * lz, 0.]
- linei += 1
- for j, i in enumerate(np.linspace(-0.5 * lz, 0.5 * lz, nz)):
- grid_pts[2 * linei] = [-0.5 * lx, i, 0.]
- grid_pts[2 * linei + 1] = [0.5 * lx, i, 0.]
- linei += 1
- grid = pyrender.Primitive(grid_pts, color_0=colors, mode=1) # 1->LINES
- grid = pyrender.Mesh([grid])
- self.ground_node = Node(mesh=grid, name="ground_plane")
- self.scene.add_node(self.ground_node)
|