class ServerBase: def __init__(self): self.config = DConfig self.graphicsEngine = GraphicsEngine() globalClock = ClockObject.getGlobalClock() self.trueClock = TrueClock.getGlobalPtr() globalClock.setRealTime(self.trueClock.getShortTime()) globalClock.setAverageFrameRateInterval(30.0) globalClock.tick() __builtins__['globalClock'] = globalClock taskMgr.globalClock = globalClock self.vfs = VirtualFileSystem.getGlobalPtr() __builtins__['vfs'] = self.vfs def __ivalLoop(self, state): ivalMgr.step() return Task.cont def __igLoop(self, state): self.graphicsEngine.renderFrame() return Task.cont def run(self): taskMgr.add(self.__ivalLoop, 'ivalLoop', priority=20) taskMgr.add(self.__igLoop, 'igLoop', priority=50) taskMgr.run()
def __init__(self, base, color=True, depth=False, size=None, near_far=None, hfov=None, title=None): if size is None: size = (640, 480) if near_far is None: near_far = (0.01, 10000.0) if hfov is None: hfov = 60 winprops = WindowProperties.size(*size) winprops.setTitle(title or 'Camera Sensor') fbprops = FrameBufferProperties() # Request 8 RGB bits, 8 alpha bits, and a depth buffer. fbprops.setRgbColor(True) fbprops.setRgbaBits(8, 8, 8, 8) fbprops.setDepthBits(24) self.graphics_engine = GraphicsEngine(base.pipe) window_type = base.config.GetString('window-type', 'onscreen') flags = GraphicsPipe.BFFbPropsOptional if window_type == 'onscreen': flags = flags | GraphicsPipe.BFRequireWindow elif window_type == 'offscreen': flags = flags | GraphicsPipe.BFRefuseWindow self.buffer = self.graphics_engine.makeOutput(base.pipe, "camera sensor buffer", -100, fbprops, winprops, flags) if not color and not depth: raise ValueError("At least one of color or depth should be True") if color: self.color_tex = Texture("color_texture") self.buffer.addRenderTexture(self.color_tex, GraphicsOutput.RTMCopyRam, GraphicsOutput.RTPColor) else: self.color_tex = None if depth: self.depth_tex = Texture("depth_texture") self.buffer.addRenderTexture(self.depth_tex, GraphicsOutput.RTMCopyRam, GraphicsOutput.RTPDepth) else: self.depth_tex = None self.cam = base.makeCamera(self.buffer, scene=base.render, camName='camera_sensor') self.lens = self.cam.node().getLens() self.lens.setFov(hfov) self.lens.setFilmSize( *size) # this also defines the units of the focal length self.lens.setNearFar(*near_far)
def __init__(self): self.config = DConfig self.graphicsEngine = GraphicsEngine() globalClock = ClockObject.getGlobalClock() self.trueClock = TrueClock.getGlobalPtr() globalClock.setRealTime(self.trueClock.getShortTime()) globalClock.setAverageFrameRateInterval(30.0) globalClock.tick() __builtins__['globalClock'] = globalClock taskMgr.globalClock = globalClock self.vfs = VirtualFileSystem.getGlobalPtr() __builtins__['vfs'] = self.vfs
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, name, lens): panda3d.core.Camera.__init__(self, name, lens) self.name = name self.path = NodePath(self) self.height, self.width = 512, 512 self.dataSize = self.height * self.width * NUM_CHANNELS self.buffer = base.win.makeTextureBuffer(name + 'Buffer', self.height, self.width) # Set the sort order to a negative number so this buffer will be rendered before the # main window. self.buffer.setSort(-100) self.tex = self.buffer.getTexture() self.tex.setRenderToTexture(True) self.tex.makeRamImage() # Attach this camera to the buffer. base.makeCamera(self.buffer, useCamera=self.path) self.setCameraMask(BitMask32(2)) # Make a PNMImage into which we'll copy screenshots from the buffer. self.image = PNMImage() self.stringStream = StringStream() self.gfxEngine = GraphicsEngine.getGlobalPtr() self.gsg = base.win.getGsg() self.currentFrame = 0 # Only initialize IPC and the copy out task if the posix_ipc module # was loaded successfully. if POSIX_IPC_LOADED: self.initializeIpc()
def __init__(self): self.config = getConfigShowbase() vfs = VirtualFileSystem.getGlobalPtr() self.eventMgr = eventMgr self.messenger = messenger self.bboard = bulletinBoard self.taskMgr = taskMgr self.AISleep = self.config.GetFloat('ai-sleep', 0.04) Task.TaskManager.taskTimerVerbose = self.config.GetBool( 'task-timer-verbose', 0) Task.TaskManager.extendedExceptions = self.config.GetBool( 'extended-exceptions', 0) self.sfxManagerList = None self.musicManager = None self.jobMgr = jobMgr self.hidden = NodePath('hidden') self.graphicsEngine = GraphicsEngine.getGlobalPtr() globalClock = ClockObject.getGlobalClock() self.trueClock = TrueClock.getGlobalPtr() globalClock.setRealTime(self.trueClock.getShortTime()) globalClock.setAverageFrameRateInterval(30.0) globalClock.tick() taskMgr.globalClock = globalClock __builtins__['ostream'] = Notify.out() __builtins__['globalClock'] = globalClock __builtins__['vfs'] = vfs __builtins__['hidden'] = self.hidden self.restart()
def graphics_engine(): from panda3d.core import GraphicsEngine engine = GraphicsEngine.get_global_ptr() yield engine # This causes GraphicsEngine to also terminate the render threads. engine.remove_all_windows()
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 setupSensorCam(self): #use the same size as the main window xsize, ysize = self.getSize() #TESTING purposes #self.accept("space", self.takeAndStorePic, ["test.png"]) #Create the camera's buffer : GraphicsOutput self.camBuffer = GraphicsEngine.makeParasite(self.graphicsEngine, host=self.win, name="camera", sort=0, x_size = xsize, y_size = ysize) self.sensorCam = self.makeCamera(self.camBuffer, camName="sensorCam") self.sensorCam.reparentTo(render) self.sensorCam.setPos(0, 5.56, 4.17) self.sensorCam.setHpr(180, -14.74, 0) self.camBuffer.setClearColorActive(True) self.camBuffer.setClearColor((.8, .8, .8, 1))
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()
from panda3d.core import GraphicsEngine from panda3d.core import KeyboardButton from panda3d.core import ModifierButtons from panda3d.core import MouseButton from panda3d.core import NodePath from panda3d.core import PandaNode from panda3d.core import PerspectiveLens from panda3d.core import Vec2 from panda3d.core import Vec4 from mouseevent import MouseEvent from cameracontroller import CameraController, EVT_CAMERA_MODE, TRACKBALL tmpColor = Vec4() gfxEngine = GraphicsEngine.getGlobalPtr() class ButtonWatcher(DirectObject): def __init__(self, keys): self.modKeys = ModifierButtons() for key in keys: self.modKeys.addButton(key) self.accept(key.getName(), self.modKeys.buttonDown, [key]) self.accept(key.getName() + '-up', self.modKeys.buttonUp, [key]) def getKeys(self): return self.modKeys def destroy(self):
def graphics_engine(): from panda3d.core import GraphicsEngine engine = GraphicsEngine.get_global_ptr() yield engine
def destroy_windows(): """Destroy all graphics windows globally.""" GraphicsEngine.getGlobalPtr().removeAllWindows()
from panda3d.core import GraphicsEngine from panda3d.core import KeyboardButton from panda3d.core import ModifierButtons from panda3d.core import MouseButton from panda3d.core import NodePath from panda3d.core import PandaNode from panda3d.core import PerspectiveLens from panda3d.core import Vec2 from panda3d.core import Vec4 from mouseevent import MouseEvent from cameracontroller import CameraController, EVT_CAMERA_MODE, TRACKBALL tmpColor = Vec4() gfxEngine = GraphicsEngine.getGlobalPtr() class ButtonWatcher(DirectObject): def __init__(self, keys): self.modKeys = ModifierButtons() for key in keys: self.modKeys.addButton(key) self.accept(key.getName(), self.modKeys.buttonDown, [key]) self.accept(key.getName()+'-up', self.modKeys.buttonUp, [key]) def getKeys(self): return self.modKeys def destroy(self): self.ignoreAll()
def graphics_engine(scope='session'): from panda3d.core import GraphicsEngine engine = GraphicsEngine.get_global_ptr() yield engine
class Panda3dCameraSensor(object): def __init__(self, base, color=True, depth=False, size=None, near_far=None, hfov=None, title=None): if size is None: size = (640, 480) if near_far is None: near_far = (0.01, 10000.0) if hfov is None: hfov = 60 winprops = WindowProperties.size(*size) winprops.setTitle(title or 'Camera Sensor') fbprops = FrameBufferProperties() # Request 8 RGB bits, 8 alpha bits, and a depth buffer. fbprops.setRgbColor(True) fbprops.setRgbaBits(8, 8, 8, 8) fbprops.setDepthBits(24) self.graphics_engine = GraphicsEngine(base.pipe) window_type = base.config.GetString('window-type', 'onscreen') flags = GraphicsPipe.BFFbPropsOptional if window_type == 'onscreen': flags = flags | GraphicsPipe.BFRequireWindow elif window_type == 'offscreen': flags = flags | GraphicsPipe.BFRefuseWindow self.buffer = self.graphics_engine.makeOutput(base.pipe, "camera sensor buffer", -100, fbprops, winprops, flags) if not color and not depth: raise ValueError("At least one of color or depth should be True") if color: self.color_tex = Texture("color_texture") self.buffer.addRenderTexture(self.color_tex, GraphicsOutput.RTMCopyRam, GraphicsOutput.RTPColor) else: self.color_tex = None if depth: self.depth_tex = Texture("depth_texture") self.buffer.addRenderTexture(self.depth_tex, GraphicsOutput.RTMCopyRam, GraphicsOutput.RTPDepth) else: self.depth_tex = None self.cam = base.makeCamera(self.buffer, scene=base.render, camName='camera_sensor') self.lens = self.cam.node().getLens() self.lens.setFov(hfov) self.lens.setFilmSize( *size) # this also defines the units of the focal length self.lens.setNearFar(*near_far) def observe(self): for _ in range(self.graphics_engine.getNumWindows()): self.graphics_engine.renderFrame() self.graphics_engine.syncFrame() images = [] if self.color_tex: data = self.color_tex.getRamImageAs('RGBA') if sys.version_info < (3, 0): data = data.get_data() image = np.frombuffer(data, np.uint8) image.shape = (self.color_tex.getYSize(), self.color_tex.getXSize(), self.color_tex.getNumComponents()) image = np.flipud(image) image = image[ ..., : -1] # remove alpha channel; if alpha values are needed, set alpha bits to 8 images.append(image) if self.depth_tex: depth_data = self.depth_tex.getRamImage() if sys.version_info < (3, 0): depth_data = depth_data.get_data() depth_image_size = self.depth_tex.getYSize( ) * self.depth_tex.getXSize() * self.depth_tex.getNumComponents() if len(depth_data) == 2 * depth_image_size: dtype = np.float16 elif len(depth_data) == 3 * depth_image_size: dtype = np.float24 elif len(depth_data) == 4 * depth_image_size: dtype = np.float32 else: raise ValueError( "Depth data has %d bytes but the size of the depth image is %d" % (len(depth_data), depth_image_size)) depth_image = np.frombuffer(depth_data, dtype) depth_image.shape = (self.depth_tex.getYSize(), self.depth_tex.getXSize(), self.depth_tex.getNumComponents()) depth_image = np.flipud(depth_image) depth_image = depth_image.astype( np.float32, copy=False) # copy only if necessary images.append(depth_image) return tuple(images)
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()