pyrender_visualizer_2.py 1.1 KB

12345678910111213141516171819202122
  1. def render_capsule(self, at_index, p, Q, length, scale=1.0, color=[1.0, 0.0, 0.0]):
  2. if at_index >= len(self.cap_pool):
  3. # create enough to allow at_index to work
  4. for i in range(len(self.cap_pool), at_index + 1): # must include at_index too
  5. # get primitive first
  6. sphere_trimesh = trimesh.creation.capsule(height=1.0, radius=1.0, count=[8, 8])
  7. sphere_face_colors = np.zeros(sphere_trimesh.faces.shape)
  8. sphere_face_colors[:] = np.array(color)
  9. sphere_trimesh.visual.face_colors = sphere_face_colors
  10. sphere_mesh = Mesh.from_trimesh(sphere_trimesh, smooth=False)
  11. sphere_node = Node(mesh=sphere_mesh,
  12. name="capsule_" + str(i)) # , translation=np.array([-0.1, -0.10, 0.05]))
  13. self.scene.add_node(sphere_node)
  14. self.cap_pool.append(sphere_node)
  15. # okay now we know the node exists, just change it's position
  16. self.cap_pool[at_index].scale = [0.1, 0.1, length]
  17. self.cap_pool[at_index].translation = p
  18. self.cap_pool[at_index].rotation = Q
  19. # print("Q: " + str(Q))