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 __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): 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): 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()