def _add_raymond_light(self): from pyrender.light import DirectionalLight from pyrender.node import Node thetas = np.pi * np.array([1.0 / 6.0, 1.0 / 6.0, 1.0 / 6.0]) phis = np.pi * np.array([0.0, 2.0 / 3.0, 4.0 / 3.0]) nodes = [] for phi, theta in zip(phis, thetas): xp = np.sin(theta) * np.cos(phi) yp = np.sin(theta) * np.sin(phi) zp = np.cos(theta) z = np.array([xp, yp, zp]) z = z / np.linalg.norm(z) x = np.array([-z[1], z[0], 0.0]) if np.linalg.norm(x) == 0: x = np.array([1.0, 0.0, 0.0]) x = x / np.linalg.norm(x) y = np.cross(z, x) matrix = np.eye(4) matrix[:3, :3] = np.c_[x, y, z] nodes.append( Node(light=DirectionalLight(color=np.ones(3), intensity=1.0), matrix=matrix)) return nodes
def add_raymond_light(self, s=1, d=0.25, T=np.eye(4)): thetas = np.pi * np.array([1.0 / 6.0, 1.0 / 6.0, 1.0 / 6.0]) phis = np.pi * np.array([0.0, 2.0 / 3.0, 4.0 / 3.0]) nodes = [] for phi, theta in zip(phis, thetas): xp = s * np.sin(theta) * np.cos(phi) yp = s * np.sin(theta) * np.sin(phi) zp = s * np.cos(theta) z = np.array([xp, yp, zp]) z = z / np.linalg.norm(z) x = np.array([-z[1], z[0], 0.0]) if np.linalg.norm(x) == 0: x = np.array([1.0, 0.0, 0.0]) x = x / np.linalg.norm(x) y = np.cross(z, x) matrix = np.eye(4) matrix[:3, :3] = np.c_[x, y, z] Tl = np.copy(T) matrix = matrix @ Tl nodes.append( Node(light=DirectionalLight(color=np.ones(3), intensity=1.0 / d), matrix=matrix)) return nodes
def __init__(self, width=1200, height=800, bg_color=[0.0, 0.0, 0.0, 1.0], offscreen=False, center_cam=False, registered_keys=None): super(MeshViewer, self).__init__() if registered_keys is None: registered_keys = dict() self.bg_color = bg_color self.offscreen = offscreen self.center_cam = center_cam self.scene = pyrender.Scene(bg_color=bg_color, ambient_light=(0.4, 0.4, 0.4), name='scene') self.aspect_ratio = float(width) / height pc = pyrender.PerspectiveCamera(yfov=np.pi / 3.0, aspectRatio=self.aspect_ratio) camera_pose = np.eye(4) camera_pose[:3, 3] = np.array([0, 0, .6]) self.cam = pyrender.Node(name='camera', camera=pc, matrix=camera_pose) self.scene.add_node(self.cam) if self.offscreen: light = Node(light=DirectionalLight(color=np.ones(3), intensity=3.0), matrix=camera_pose) self.scene.add_node(light) self.viewer = pyrender.OffscreenRenderer(width, height) else: self.viewer = pyrender.Viewer(self.scene, use_raymond_lighting=True, viewport_size=(width, height), cull_faces=False, run_in_thread=True, registered_keys=registered_keys) for i, node in enumerate(self.scene.get_nodes()): if node.name is None: node.name = 'Req%d' % i