def setup_renderer(window_type, size=(256, 256), light_spec=None, cam_spec=None): """ Sets up the LightBase rendering stuff.""" # Initialize lbase = LightBase() rootnode = lbase.rootnode if window_type == "onscreen": output = lbase.make_window(size, "window") elif window_type == "offscreen": output = lbase.make_buffer(size, "buffer") elif window_type == "texture": output, tex = lbase.make_texture_buffer(size, "texturebuffer", mode='RTMCopyRam') else: raise ValueError("Unknown window type: %s" % window_type) # Clear out frame contents lbase.render_frame() lbase.render_frame() # Set up a camera if cam_spec is None: cam_spec = {} # print('cam_spec', cam_spec) cam_x, cam_z, cam_y = cam_spec.get('cam_pos', (0., -20., 0.)) scene_width = cam_spec.get('scene_width', 3.) nm = np.sqrt(cam_x**2 + cam_y**2 + cam_z**2) fov = 2. * np.degrees(np.arctan(scene_width / (2. * nm))) cam_lx, cam_lz, cam_ly = cam_spec.get('cam_lookat', (0., 0., 0.)) cam_rot = cam_spec.get('cam_rot', 0.) camera = lbase.make_camera(output) lens = camera.node().getLens() lens.setMinFov(fov) # Position the camera camera_rot = rootnode.attachNewNode('camera_rot') lbase.cameras.reparentTo(camera_rot) lbase.cameras.setPos(cam_x, cam_z, cam_y) lbase.cameras.lookAt(cam_lx, cam_lz, cam_ly) camera_rot.setH(cam_rot) # Lights lights = LightBase.make_lights(light_spec=light_spec) lights.reparentTo(rootnode) for light in lights.getChildren(): rootnode.setLight(light) # # Pause while setup finishes # time.sleep(0.02) return lbase, output