def change_lookatpos(self, lookatpos): """ This function is questionable as lookat changes the rotation of the camera :param lookatpos: :return: author: weiwei date: 20180606 """ self.cam.lookAt(lookatpos[0], lookatpos[1], lookatpos[2]) self.lookatpos = lookatpos self.inputmgr = im.InputManager(self, self.lookatpos)
def __init__(self, base: wd.World, window_title: str = "WRS Robot Planning and Control System", cam_pos: np.ndarray = np.array([2.0, 0, 2.0]), lookat_pos: np.ndarray = np.array([0, 0, 0.25]), up: np.ndarray = np.array([0, 0, 1]), fov: int = 40, w: int = 1920, h: int = 1080, lens_type: str = "perspective"): self._base = base # setup render scene self.render = NodePath("extra_win_render") # setup render 2d self.render2d = NodePath("extra_win_render2d") self.render2d.setDepthTest(0) self.render2d.setDepthWrite(0) self.win = base.openWindow( props=WindowProperties(base.win.getProperties()), makeCamera=False, scene=self.render, requireWindow=True, ) # set window background to white base.setBackgroundColor(r=1, g=1, b=1, win=self.win) # set window title and window's dimension self.set_win_props( title=window_title, size=(w, h), ) # set len for the camera and set the camera for the new window lens = PerspectiveLens() lens.setFov(fov) lens.setNearFar(0.001, 5000.0) if lens_type == "orthographic": lens = OrthographicLens() lens.setFilmSize(1, 1) # make aspect ratio looks same as base window aspect_ratio = base.getAspectRatio() lens.setAspectRatio(aspect_ratio) self.cam = base.makeCamera( self.win, scene=self.render, ) # can also be found in base.camList self.cam.reparentTo(self.render) self.cam.setPos(Point3(cam_pos[0], cam_pos[1], cam_pos[2])) self.cam.lookAt(Point3(lookat_pos[0], lookat_pos[1], lookat_pos[2]), Vec3(up[0], up[1], up[2])) self.cam.node().setLens(lens) # use same len as sys # set up cartoon effect self._separation = 1 self.filter = flt.Filter(self.win, self.cam) self.filter.setCartoonInk(separation=self._separation) # camera in camera 2d self.cam2d = base.makeCamera2d(self.win, ) self.cam2d.reparentTo(self.render2d) # attach GPTop to the render2d to make sure the DirectGui can be used self.aspect2d = self.render2d.attachNewNode(PGTop("aspect2d")) # self.aspect2d.setScale(1.0 / aspect_ratio, 1.0, 1.0) # setup mouse for the new window # name of mouse watcher is to adapt to the name in the input manager self.mouse_thrower = base.setupMouse(self.win, fMultiWin=True) self.mouseWatcher = self.mouse_thrower.getParent() self.mouseWatcherNode = self.mouseWatcher.node() self.aspect2d.node().setMouseWatcher(self.mouseWatcherNode) # self.mouseWatcherNode.addRegion(PGMouseWatcherBackground()) # setup input manager self.inputmgr = im.InputManager(self, lookatpos=lookat_pos) # copy attributes and functions from base ## change the bound function to a function, and bind to `self` to become a unbound function self._interaction_update = functools.partial( base._interaction_update.__func__, self) self.p3dh = base.p3dh base.taskMgr.add(self._interaction_update, "interaction_extra_window", appendTask=True)
def change_campos_and_lookatpos(self, campos, lookatpos): self.cam.setPos(campos[0], campos[1], campos[2]) self.cam.lookAt(lookatpos[0], lookatpos[1], lookatpos[2]) self.lookatpos = lookatpos self.inputmgr = im.InputManager(self, self.lookatpos)
def change_campos(self, campos): self.cam.setPos(campos[0], campos[1], campos[2]) self.inputmgr = im.InputManager(self, self.lookatpos)
def __init__(self, cam_pos=np.array([2.0, 0.5, 2.0]), lookat_pos=np.array([0, 0, 0.25]), up=np.array([0, 0, 1]), fov=40, w=1920, h=1080, lens_type="perspective", toggle_debug=False, auto_cam_rotate=False): """ :param cam_pos: :param lookat_pos: :param fov: :param w: width of window :param h: height of window author: weiwei date: 2015?, 20201115 """ # the taskMgr, loader, render2d, etc. are added to builtin after initializing the showbase parental class super().__init__() # set up window winprops = WindowProperties(base.win.getProperties()) winprops.setTitle("WRS Robot Planning and Control System") base.win.requestProperties(winprops) self.disableAllAudio() self.setBackgroundColor(1, 1, 1) # set up lens lens = PerspectiveLens() lens.setFov(fov) lens.setNearFar(0.001, 5000.0) if lens_type == "orthographic": lens = OrthographicLens() lens.setFilmSize(640, 480) # disable the default mouse control self.disableMouse() self.cam.setPos(cam_pos[0], cam_pos[1], cam_pos[2]) self.cam.lookAt(Point3(lookat_pos[0], lookat_pos[1], lookat_pos[2]), Vec3(up[0], up[1], up[2])) self.cam.node().setLens(lens) # set up slight ## ambient light ablight = AmbientLight("ambientlight") ablight.setColor(Vec4(0.2, 0.2, 0.2, 1)) self.ablightnode = self.cam.attachNewNode(ablight) self.render.setLight(self.ablightnode) ## point light 1 ptlight0 = PointLight("pointlight0") ptlight0.setColor(Vec4(1, 1, 1, 1)) self._ptlightnode0 = self.cam.attachNewNode(ptlight0) self._ptlightnode0.setPos(0, 0, 0) self.render.setLight(self._ptlightnode0) ## point light 2 ptlight1 = PointLight("pointlight1") ptlight1.setColor(Vec4(.4, .4, .4, 1)) self._ptlightnode1 = self.cam.attachNewNode(ptlight1) self._ptlightnode1.setPos(self.cam.getPos().length(), 0, self.cam.getPos().length()) self.render.setLight(self._ptlightnode1) ## point light 3 ptlight2 = PointLight("pointlight2") ptlight2.setColor(Vec4(.3, .3, .3, 1)) self._ptlightnode2 = self.cam.attachNewNode(ptlight2) self._ptlightnode2.setPos(-self.cam.getPos().length(), 0, self.cam.getPos().length()) self.render.setLight(self._ptlightnode2) # helpers self.p3dh = p3dh # self.o3dh = o3dh self.rbtmath = rm # set up inputmanager self.lookatpos = lookat_pos self.inputmgr = im.InputManager(self, self.lookatpos) taskMgr.add(self._interaction_update, "interaction", appendTask=True) # set up rotational cam if auto_cam_rotate: taskMgr.doMethodLater(.1, self._rotatecam_update, "rotate cam") # set window size props = WindowProperties() props.setSize(w, h) self.win.requestProperties(props) # outline edge shader # self.set_outlineshader() # set up cartoon effect self._separation = 1 self.filter = flt.Filter(self.win, self.cam) self.filter.setCartoonInk(separation=self._separation) # self.filter.setViewGlow() # set up physics world self.physics_scale = 1e3 self.physicsworld = BulletWorld() self.physicsworld.setGravity(Vec3(0, 0, -9.81 * self.physics_scale)) taskMgr.add(self._physics_update, "physics", appendTask=True) globalbprrender = base.render.attachNewNode("globalbpcollider") debugNode = BulletDebugNode('Debug') debugNode.showWireframe(True) debugNode.showConstraints(True) debugNode.showBoundingBoxes(False) debugNode.showNormals(True) self._debugNP = globalbprrender.attachNewNode(debugNode) self._debugNP.show() self.toggledebug = toggle_debug if toggle_debug: self.physicsworld.setDebugNode(self._debugNP.node()) self.physicsbodylist = [] # set up render update (TODO, only for dynamics?) self._internal_update_obj_list = [ ] # the nodepath, collision model, or bullet dynamics model to be drawn self._internal_update_robot_list = [] taskMgr.add(self._internal_update, "internal_update", appendTask=True) # for remote visualization self._external_update_objinfo_list = [] # see anime_info.py self._external_update_robotinfo_list = [] taskMgr.add(self._external_update, "external_update", appendTask=True) # for stationary models self._noupdate_model_list = []