def __init__(self): self.cvMgr = ConfigVariableManager.getGlobalPtr() load_prc_file_data('', 'textures-power-2 none') super().__init__() blenderpanda.init(self) self.accept('escape', sys.exit) if logger.isEnabledFor(logging.DEBUG): self.accept('d', self.toggle_debug_tools) for scene in scenes.available_scenes: self.addScene(scene()) # - surfdog - self.addScene(Scene('surfdog', filename='surfdog', # - surfdog - scale=[5.0, 0.1, 5.0], # - surfdog - position=[-8, 22, -2] # - surfdog - )) # -cannon- self.addScene(Scene('cannon', filename='cannon', # -cannon- position=[0,22,0], # -cannon- hpr=[-45,0,0] # -cannon- )) self.load_registered_scenes() # setup Horizons self.horizon = 'skysphere' self.addHorizon(Background('skysphere', filename='skysphere_mk2.egg')) self.addHorizon(Background('skybox', filename='skybox_1024')) self.load_horizon(self.horizon) self.console = ConsoleWindow(self) # explicit first hide self.console.toggleConsole(hide=True) self.setControls() self.render.set_shader_auto() atexit.register(self.killRestServer)
# ConfigVariableManager.getGlobalPtr().listVariables() import sys from panda3d.core import ConfigVariableString, ConfigVariableManager my_game_server = ConfigVariableString('my-game-server', '127.0.0.1') print('Server specified in config file: ', my_game_server.getValue()) # Allow the user to change servers on the command-line if sys.argv[1] == '--server': my_game_server.setValue(sys.argv[2]) # end if print('Server that we will user: ', my_game_server.getValue()) print(ConfigVariableString("my-game-server")) cvMgr = ConfigVariableManager.get_global_ptr() cvMgr.list_variables()
__all__ = [] from .ShowBase import ShowBase, WindowControls from direct.directnotify.DirectNotifyGlobal import directNotify, giveNotify from panda3d.core import VirtualFileSystem, Notify, ClockObject, PandaSystem from panda3d.core import ConfigPageManager, ConfigVariableManager from panda3d.core import NodePath, PGTop from . import DConfig as config __dev__ = config.GetBool('want-dev', __debug__) vfs = VirtualFileSystem.getGlobalPtr() ostream = Notify.out() globalClock = ClockObject.getGlobalClock() cpMgr = ConfigPageManager.getGlobalPtr() cvMgr = ConfigVariableManager.getGlobalPtr() pandaSystem = PandaSystem.getGlobalPtr() # This is defined here so GUI elements can be instantiated before ShowBase. aspect2d = NodePath(PGTop("aspect2d")) # Set direct notify categories now that we have config directNotify.setDconfigLevels() def run(): assert ShowBase.notify.warning( "run() is deprecated, use base.run() instead") base.run()
from .ShowBase import ShowBase, WindowControls from direct.directnotify.DirectNotifyGlobal import directNotify, giveNotify from panda3d.core import VirtualFileSystem, Notify, ClockObject, PandaSystem from panda3d.core import ConfigPageManager, ConfigVariableManager from panda3d.core import NodePath, PGTop from panda3d.direct import get_config_showbase config = get_config_showbase() __dev__ = config.GetBool('want-dev', __debug__) vfs = VirtualFileSystem.getGlobalPtr() ostream = Notify.out() globalClock = ClockObject.getGlobalClock() cpMgr = ConfigPageManager.getGlobalPtr() cvMgr = ConfigVariableManager.getGlobalPtr() pandaSystem = PandaSystem.getGlobalPtr() # This is defined here so GUI elements can be instantiated before ShowBase. aspect2d = NodePath(PGTop("aspect2d")) # Set direct notify categories now that we have config directNotify.setDconfigLevels() def run(): assert ShowBase.notify.warning("run() is deprecated, use base.run() instead") base.run() def inspect(anObject): # Don't use a regular import, to prevent ModuleFinder from picking # it up as a dependency when building a .p3d package.
from direct.showbase.ShowBase import ShowBase # from panda3d.core import loadPrcFile # loadPrcFile("config/conf.prc") from panda3d.core import loadPrcFileData confVars = """ win-size 1280 720 window-title My Game """ loadPrcFileData("", confVars) #all config variables from panda3d.core import ConfigVariableManager ConfigVariableManager.getGlobalPtr().listVariables() # ConfigVariableManager.getGlobalPtr().list class MyGame(ShowBase): def __init__(self): super().__init__() box = self.loader.loadModel('models/box') box.setPos(0, 10, 0) box.reparentTo(self.render) panda = self.loader.loadModel('models/panda') panda.setPos(-2, 10, 0) panda.setScale(0.2, 0.2, 0.2) panda.reparentTo(self.render)
def __init__(self, pipeline): DebugObject.__init__(self, "BugReporter") self.debug("Creating bug report") reportDir = "BugReports/" + str(int(time.time())) + "/" reportFname = "BugReports/" + str(int(time.time())) + "" if not isdir(reportDir): os.makedirs(reportDir) # Generate general log DebugLog = "Pipeline Bug-Report\n" DebugLog += "Created: " + datetime.datetime.now().isoformat() + "\n" DebugLog += "System: " + sys.platform + " / " + os.name + " (" + str( 8 * struct.calcsize("P")) + " Bit)\n" with open(join(reportDir, "general.log"), "w") as handle: handle.write(DebugLog) # Write stdout and stderr with open(join(reportDir, "stdout.log"), "w") as handle: handle.write(sys.stdout.getLog()) with open(join(reportDir, "stderr.log"), "w") as handle: handle.write(sys.stderr.getLog()) # Write the scene graph handle = OFileStream(join(reportDir, "scene_graph.log")) Globals.render.ls(handle) handle.close() # Write the pipeline settings SettingLog = "# Pipeline Settings Diff File:\n\n" for key, val in pipeline.settings.settings.iteritems(): if val.value != val.default: SettingLog += key + " = " + str( val.value) + " (Default " + str(val.default) + ")\n" with open(join(reportDir, "pipeline.ini"), "w") as handle: handle.write(SettingLog) # Write the panda settings handle = OFileStream(join(reportDir, "pandacfg.log")) ConfigVariableManager.getGlobalPtr().writePrcVariables(handle) handle.close() # Write lights and shadow sources with open(join(reportDir, "lights.log"), "w") as handle: pp = pprint.PrettyPrinter(indent=4, stream=handle) handle.write("\nLights:\n") pp.pprint(pipeline.lightManager.lightSlots) handle.write("\n\nShadowSources:\n") pp.pprint(pipeline.lightManager.shadowSourceSlots) # Extract buffers bufferDir = join(reportDir, "buffers") if not isdir(bufferDir): os.makedirs(bufferDir) for name, (size, entry) in MemoryMonitor.memoryEntries.iteritems(): if type(entry) == Texture: w, h = entry.getXSize(), entry.getYSize() # Ignore buffers if h < 2: continue pipeline.showbase.graphicsEngine.extractTextureData( entry, pipeline.showbase.win.getGsg()) if not entry.hasRamImage(): print "Ignoring", name continue pnmSrc = PNMImage(w, h, 4, 2**16 - 1) entry.store(pnmSrc) pnmColor = PNMImage(w, h, 3, 2**16 - 1) pnmColor.copySubImage(pnmSrc, 0, 0, 0, 0, w, h) pnmColor.write(join(bufferDir, name + "-color.png")) pnmAlpha = PNMImage(w, h, 3, 2**16 - 1) pnmAlpha.copyChannel(pnmSrc, 3, 0) pnmAlpha.write(join(bufferDir, name + "-alpha.png")) shutil.make_archive(reportFname, 'zip', reportDir) shutil.rmtree(reportDir) self.debug("Bug report saved: ", reportFname + ".zip")
def __init__(self, pipeline): DebugObject.__init__(self, "BugReporter") self.debug("Creating bug report") reportDir = "BugReports/" + str(int(time.time())) + "/" reportFname = "BugReports/" + str(int(time.time())) + "" if not isdir(reportDir): os.makedirs(reportDir) # Generate general log DebugLog = "Pipeline Bug-Report\n" DebugLog += "Created: " + datetime.datetime.now().isoformat() + "\n" DebugLog += "System: " + sys.platform + " / " + os.name + " (" + str(8 * struct.calcsize("P")) + " Bit)\n" with open(join(reportDir, "general.log"), "w") as handle: handle.write(DebugLog) # Write stdout and stderr with open(join(reportDir, "stdout.log"), "w") as handle: handle.write(sys.stdout.getLog()) with open(join(reportDir, "stderr.log"), "w") as handle: handle.write(sys.stderr.getLog()) # Write the scene graph handle = OFileStream(join(reportDir, "scene_graph.log")) Globals.render.ls(handle) handle.close() # Write the pipeline settings SettingLog = "# Pipeline Settings Diff File:\n\n" for key, val in pipeline.settings.settings.iteritems(): if val.value != val.default: SettingLog += key + " = " + str(val.value) + " (Default " + str(val.default) + ")\n" with open(join(reportDir, "pipeline.ini"), "w") as handle: handle.write(SettingLog) # Write the panda settings handle = OFileStream(join(reportDir, "pandacfg.log")) ConfigVariableManager.getGlobalPtr().writePrcVariables(handle) handle.close() # Write lights and shadow sources with open(join(reportDir, "lights.log"), "w") as handle: pp = pprint.PrettyPrinter(indent=4, stream=handle) handle.write("\nLights:\n") pp.pprint(pipeline.lightManager.lightSlots) handle.write("\n\nShadowSources:\n") pp.pprint(pipeline.lightManager.shadowSourceSlots) # Extract buffers bufferDir = join(reportDir, "buffers") if not isdir(bufferDir): os.makedirs(bufferDir) for name, (size, entry) in MemoryMonitor.memoryEntries.iteritems(): if type(entry) == Texture: w, h = entry.getXSize(), entry.getYSize() # Ignore buffers if h < 2: continue pipeline.showbase.graphicsEngine.extractTextureData(entry, pipeline.showbase.win.getGsg()) if not entry.hasRamImage(): print "Ignoring", name continue pnmSrc = PNMImage(w, h, 4, 2 ** 16 - 1) entry.store(pnmSrc) pnmColor = PNMImage(w, h, 3, 2 ** 16 - 1) pnmColor.copySubImage(pnmSrc, 0, 0, 0, 0, w, h) pnmColor.write(join(bufferDir, name + "-color.png")) pnmAlpha = PNMImage(w, h, 3, 2 ** 16 - 1) pnmAlpha.copyChannel(pnmSrc, 3, 0) pnmAlpha.write(join(bufferDir, name + "-alpha.png")) shutil.make_archive(reportFname, "zip", reportDir) shutil.rmtree(reportDir) self.debug("Bug report saved: ", reportFname + ".zip")
def __init__(self): #: The directory containing the main Python file of this application. self.mainDir = ExecutionEnvironment.getEnvironmentVariable("MAIN_DIR") self.main_dir = self.mainDir self.wantStats = self.config.GetBool('want-pstats', 0) # Do you want to enable a fixed simulation timestep? Setting this true # only means that the builtin resetPrevTransform and collisionLoop # tasks are added onto the simTaskMgr instead of taskMgr, which runs at # a fixed time step. You can still add your own fixed timestep tasks # when this is false, it only has to do with builtin simulation tasks. self.fixedSimulationStep = self.config.GetBool( 'want-fixed-simulation-step', 0) #: The global event manager, as imported from `.EventManagerGlobal`. self.eventMgr = eventMgr #: The global messenger, as imported from `.MessengerGlobal`. self.messenger = messenger #: The global bulletin board, as imported from `.BulletinBoardGlobal`. self.bboard = bulletinBoard #: The global task manager, as imported from `.TaskManagerGlobal`. self.taskMgr = taskMgr self.task_mgr = taskMgr #: The global simulation task manager, as imported from `.TaskManagerGlobal` self.simTaskMgr = simTaskMgr self.sim_task_mgr = simTaskMgr #: The global job manager, as imported from `.JobManagerGlobal`. self.jobMgr = jobMgr #: `.Loader.Loader` object. self.loader = Loader(self) # Get a pointer to Panda's global ClockObject, used for # synchronizing events between Python and C. globalClock = ClockObject.getGlobalClock() # We will manually manage the clock globalClock.setMode(ClockObject.MSlave) self.globalClock = globalClock # 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.trueClock = trueClock globalClock.setRealTime(trueClock.getShortTime()) globalClock.tick() # Now we can make the TaskManager start using the new globalClock. taskMgr.globalClock = globalClock simTaskMgr.globalClock = globalClock vfs = VirtualFileSystem.getGlobalPtr() self.vfs = vfs # Make sure we're not making more than one HostBase. if hasattr(builtins, 'base'): raise Exception("Attempt to spawn multiple HostBase instances!") # DO NOT ADD TO THIS LIST. We're trying to phase out the use of # built-in variables by ShowBase. Use a Global module if necessary. builtins.base = self builtins.taskMgr = self.taskMgr builtins.simTaskMgr = self.simTaskMgr builtins.jobMgr = self.jobMgr builtins.eventMgr = self.eventMgr builtins.messenger = self.messenger builtins.bboard = self.bboard builtins.loader = self.loader # Config needs to be defined before ShowBase is constructed #builtins.config = self.config builtins.ostream = Notify.out() builtins.directNotify = directNotify builtins.giveNotify = giveNotify builtins.globalClock = globalClock builtins.vfs = vfs builtins.cpMgr = ConfigPageManager.getGlobalPtr() builtins.cvMgr = ConfigVariableManager.getGlobalPtr() builtins.pandaSystem = PandaSystem.getGlobalPtr() # Now add this instance to the ShowBaseGlobal module scope. from . import ShowBaseGlobal builtins.run = ShowBaseGlobal.run ShowBaseGlobal.base = self # What is the current frame number? self.frameCount = 0 # Time at beginning of current frame self.frameTime = self.globalClock.getRealTime() # How long did the last frame take. self.deltaTime = 0 # # Variables pertaining to simulation ticks. # self.prevRemainder = 0 self.remainder = 0 # What is the current overall simulation tick? self.tickCount = 0 # How many ticks are we going to run this frame? self.totalTicksThisFrame = 0 # How many ticks have we run so far this frame? self.currentTicksThisFrame = 0 # What tick are we currently on this frame? self.currentFrameTick = 0 # How many simulations ticks are we running per-second? self.ticksPerSec = 60 self.intervalPerTick = 1.0 / self.ticksPerSec self.taskMgr.finalInit()