def __init__(self, scene, suncgDatasetRoot, size=(512, 512), mode='offscreen', zNear=0.1, zFar=1000.0, fov=40.0, cameraTransform=None): # Off-screen buffers are not supported in OSX if sys.platform == 'darwin': mode = 'onscreen' super(Panda3dSemanticsRenderer, self).__init__() self.__dict__.update(scene=scene, suncgDatasetRoot=suncgDatasetRoot, size=size, mode=mode, zNear=zNear, zFar=zFar, fov=fov, cameraTransform=cameraTransform) self.categoryMapping = ModelCategoryMapping( os.path.join(self.suncgDatasetRoot, 'metadata', 'ModelCategoryMapping.csv')) self.cameraMask = BitMask32.bit(1) self.graphicsEngine = GraphicsEngine.getGlobalPtr() self.loader = Loader.getGlobalPtr() self.graphicsEngine.setDefaultLoader(self.loader) self._initModels() selection = GraphicsPipeSelection.getGlobalPtr() self.pipe = selection.makeDefaultPipe() logger.debug('Using %s' % (self.pipe.getInterfaceName())) # Attach a camera to every agent in the scene self.cameras = [] for agentNp in self.scene.scene.findAllMatches('**/agents/agent*'): camera = agentNp.attachNewNode(ModelNode('camera-semantics')) if self.cameraTransform is not None: camera.setTransform(cameraTransform) camera.node().setPreserveTransform(ModelNode.PTLocal) self.cameras.append(camera) # Reparent node below the existing physic node (if any) physicsNp = agentNp.find('**/physics') if not physicsNp.isEmpty(): camera.reparentTo(physicsNp) self.rgbBuffers = dict() self.rgbTextures = dict() self._initRgbCapture() self.scene.worlds['render-semantics'] = self
def graphics_pipe(): from panda3d.core import GraphicsPipeSelection pipe = GraphicsPipeSelection.get_global_ptr().make_default_pipe() if pipe is None or not pipe.is_valid(): pytest.skip("GraphicsPipe is invalid") yield pipe
def graphics_pipe(scope='session'): from panda3d.core import GraphicsPipeSelection pipe = GraphicsPipeSelection.get_global_ptr().make_default_pipe() if not pipe.is_valid(): pytest.xfail("GraphicsPipe is invalid") yield pipe
def __init__(self, frame_size: tuple, fb_props: FrameBufferProperties): self._window = None # make default graphics pipe pipe = GraphicsPipeSelection.get_global_ptr().make_default_pipe() if pipe is None or not pipe.is_valid(): raise RuntimeError("GraphicsPipe is invalid") self._pipe = pipe self._engine = GraphicsEngine.get_global_ptr() self._fb_props = fb_props if frame_size is not None: self._configure_window(frame_size)
def __init__(self, scene, size=(512, 512), shadowing=False, mode='offscreen', zNear=0.1, zFar=1000.0, fov=40.0, depth=True, modelLightsInfo=None, cameraTransform=None): # Off-screen buffers are not supported in OSX if sys.platform == 'darwin': mode = 'onscreen' super(Panda3dRenderer, self).__init__() self.__dict__.update(scene=scene, size=size, mode=mode, zNear=zNear, zFar=zFar, fov=fov, depth=depth, shadowing=shadowing, modelLightsInfo=modelLightsInfo, cameraTransform=cameraTransform) self.cameraMask = BitMask32.bit(0) self.graphicsEngine = GraphicsEngine.getGlobalPtr() self.loader = Loader.getGlobalPtr() self.graphicsEngine.setDefaultLoader(self.loader) # Change some scene attributes for rendering self.scene.scene.setAttrib(RescaleNormalAttrib.makeDefault()) self.scene.scene.setTwoSided(0) self._initModels() selection = GraphicsPipeSelection.getGlobalPtr() self.pipe = selection.makeDefaultPipe() logger.debug('Using %s' % (self.pipe.getInterfaceName())) # Attach a camera to every agent in the scene self.cameras = [] for agentNp in self.scene.scene.findAllMatches('**/agents/agent*'): camera = agentNp.attachNewNode(ModelNode('camera-rgbd')) if self.cameraTransform is not None: camera.setTransform(cameraTransform) camera.node().setPreserveTransform(ModelNode.PTLocal) self.cameras.append(camera) self.rgbBuffers = dict() self.rgbTextures = dict() self.depthBuffers = dict() self.depthTextures = dict() self._initRgbCapture() if self.depth: self._initDepthCapture() self._addDefaultLighting() self.scene.worlds['render'] = self
def __init__(self): self.gotLocalConfig = False HostBase.__init__(self) self.docTitle = "" self.viewportName = "" self.renderRequested = False ################################################################### # Minimal emulation of ShowBase glue code. Note we're not using # ShowBase because there's too much going on in there that assumes # too much (one camera, one lens, one aspect2d, lots of bloat). self.graphicsEngine = GraphicsEngine.getGlobalPtr() self.pipe = GraphicsPipeSelection.getGlobalPtr().makeDefaultPipe() if not self.pipe: self.notify.error("No graphics pipe is available!") return self.dgTrav = DataGraphTraverser() self.dataRoot = NodePath("data") self.hidden = NodePath("hidden") self.aspect2d = NodePath("aspect2d") builtins.aspect2d = self.aspect2d builtins.hidden = self.hidden ################################################################### self.clickTrav = CollisionTraverser() # All open documents. self.documents = [] # The focused document. self.document = None TextNode.setDefaultFont( loader.loadFont("resources/models/fonts/consolas.ttf"))
def init_graphics(self): """Creates GraphicsEngine, GraphicsPipe, and loader.""" # Get a handle to the graphics pipe selector selection = GraphicsPipeSelection.getGlobalPtr() # Check for DISPLAY if "DISPLAY" in os.environ: # Use the first option (should be glx) pipe_type = selection.getPipeTypes()[0] else: # Use the last option (should be some fallback module) pipe_type = selection.getPipeTypes()[-1] # Create the graphics pipe self.pipe = selection.makePipe(pipe_type) # Get the graphics engine self.engine = GraphicsEngine.getGlobalPtr() # Get the model loader object and assign it to the engine # self.loader = Loader.Loader(self) # self.engine.setDefaultLoader(self.loader.loader) self.loader = Loader() self.engine.setDefaultLoader(self.loader.panda_loader)
def __init__(self, screen_size=84): ShowBase.__init__(self) self.render.setShaderAuto() # Offscreen Buffer winprops = WindowProperties.size(screen_size, screen_size) fbprops = FrameBufferProperties() self.pipe = GraphicsPipeSelection.get_global_ptr().make_module_pipe( 'pandagl') self.imageBuffer = self.graphicsEngine.makeOutput( self.pipe, "image buffer", 1, fbprops, winprops, GraphicsPipe.BFRefuseWindow) # Camera self.camera = Camera('cam') self.cam = NodePath(self.camera) self.cam.reparentTo(self.render) self.cam.setPos(0, 0, 7) self.cam.lookAt(0, 0, 0) #Display Region self.dr = self.imageBuffer.makeDisplayRegion() self.dr.setCamera(self.cam) # Spotlight with shadows self.light = Spotlight('light') self.lightNP = self.render.attachNewNode(self.light) self.lightNP.setPos(0, 10, 10) self.lightNP.lookAt(0, 0, 0) self.lightNP.node().setShadowCaster(True, 1024, 1024) self.render.setLight(self.lightNP) # Block node = PandaNode('Block') block_np = self.render.attachNewNode(node) model = loader.loadModel('box.egg') model.reparentTo(block_np) self.start_time = time.time()
def __init__(self): HostBase.__init__(self) # Initialize rendering things self.graphicsEngine = GraphicsEngine.getGlobalPtr() self.pipeSelection = GraphicsPipeSelection.getGlobalPtr() self.pipe = self.pipeSelection.makeDefaultPipe() self.win = None # Camera things self.camera = None self.cam = None self.camLens = None self.camNode = None # Scene things self.render = None self.render2d = None self.aspect2d = None self.hidden = None self.cl = self.createClientRepository()
def __init__(self, screen_size=84, DEBUGGING=False, human_playable=False): ShowBase.__init__(self) self.forward_button = KeyboardButton.ascii_key(b'w') self.backward_button = KeyboardButton.ascii_key(b's') self.fps = 20 self.human_playable = human_playable self.actions = 3 self.last_frame_start_time = time.time() self.action_buffer = [1, 1, 1] self.last_teleport_time = 0.0 self.time_to_teleport = False if self.human_playable is False: winprops = WindowProperties.size(screen_size, screen_size) fbprops = FrameBufferProperties() fbprops.set_rgba_bits(8, 8, 8, 0) fbprops.set_depth_bits(24) self.pipe = GraphicsPipeSelection.get_global_ptr().make_module_pipe('pandagl') self.imageBuffer = self.graphicsEngine.makeOutput( self.pipe, "image buffer", 1, fbprops, winprops, GraphicsPipe.BFRefuseWindow) self.camera = Camera('cam') self.cam = NodePath(self.camera) self.cam.reparentTo(self.render) self.dr = self.imageBuffer.makeDisplayRegion() self.dr.setCamera(self.cam) self.render.setShaderAuto() self.cam.setPos(0.5, 0, 6) self.cam.lookAt(0.5, 0, 0) # Create Ambient Light self.ambientLight = AmbientLight('ambientLight') self.ambientLight.setColor((0.2, 0.2, 0.2, 1)) self.ambientLightNP = self.render.attachNewNode(self.ambientLight) self.render.setLight(self.ambientLightNP) # Spotlight self.light = Spotlight('light') self.light.setColor((0.9, 0.9, 0.9, 1)) self.lightNP = self.render.attachNewNode(self.light) self.lightNP.setPos(0, 10, 10) self.lightNP.lookAt(0, 0, 0) self.lightNP.node().getLens().setFov(40) self.lightNP.node().getLens().setNearFar(10, 100) self.lightNP.node().setShadowCaster(True, 1024, 1024) self.render.setLight(self.lightNP) self.world = BulletWorld() self.world.setGravity(Vec3(0, 0, -9.81)) if DEBUGGING is True: debugNode = BulletDebugNode('Debug') debugNode.showWireframe(True) debugNode.showConstraints(True) debugNode.showBoundingBoxes(False) debugNode.showNormals(False) debugNP = render.attachNewNode(debugNode) debugNP.show() self.world.setDebugNode(debugNP.node()) self.finger_speed_mps = 0.0 self.penalty_applied = False self.teleport_cooled_down = True self.fps = 20 self.framecount = 0 self.reset()
def __init__(self): DirectObject.__init__(self) if ConfigVariableBool("want-pstats", False): PStatClient.connect() self.docTitle = "" self.viewportName = "" self.renderRequested = False ################################################################### # Minimal emulation of ShowBase glue code. Note we're not using # ShowBase because there's too much going on in there that assumes # too much (one camera, one lens, one aspect2d, lots of bloat). self.graphicsEngine = GraphicsEngine.getGlobalPtr() self.pipe = GraphicsPipeSelection.getGlobalPtr().makeDefaultPipe() if not self.pipe: self.notify.error("No graphics pipe is available!") return self.globalClock = ClockObject.getGlobalClock() # Since we have already started up a TaskManager, and probably # a number of tasks; and since the TaskManager had to use the # TrueClock to tell time until this moment, make sure the # globalClock object is exactly in sync with the TrueClock. trueClock = TrueClock.getGlobalPtr() self.globalClock.setRealTime(trueClock.getShortTime()) self.globalClock.tick() builtins.globalClock = self.globalClock self.loader = CogInvasionLoader(self) self.graphicsEngine.setDefaultLoader(self.loader.loader) builtins.loader = self.loader self.taskMgr = taskMgr builtins.taskMgr = self.taskMgr self.dgTrav = DataGraphTraverser() self.dataRoot = NodePath("data") self.hidden = NodePath("hidden") self.aspect2d = NodePath("aspect2d") builtins.aspect2d = self.aspect2d # Messages that are sent regardless of the active document. self.messenger = messenger builtins.messenger = self.messenger builtins.base = self builtins.hidden = self.hidden ################################################################### self.clickTrav = CollisionTraverser() # All open documents. self.documents = [] # The focused document. self.document = None TextNode.setDefaultFont( loader.loadFont("resources/models/fonts/consolas.ttf")) self.initialize()