def __init__(self): rootdir = ExecutionEnvironment.getEnvironmentVariable("MAIN_DIR") self.classConfigurationCSV = os.path.join(rootdir, "config", "playerClasses.csv") self.classDefinitions = [] with open(self.classConfigurationCSV, newline='') as csvfile: for row in csv.DictReader(csvfile): self.classDefinitions.append(row)
def __init__(self, enemyFieldName, difficultyNameID): rootdir = ExecutionEnvironment.getEnvironmentVariable("MAIN_DIR") self.enemyConfigurationCSV = os.path.join(rootdir, "config", "enemies.csv") self.enemyDefinitions = [] # create the enemies dice self.dice = SixSidedDice() self.enemyFieldName = enemyFieldName self.difficultyName = RoomGlobals.DIFFICULTIES_AS_NAMES[ difficultyNameID] # load the csv file data with open(self.enemyConfigurationCSV, newline='') as csvfile: for row in csv.DictReader(csvfile): self.enemyDefinitions.append(row) self.numEnemies = self.getNumEnemies()
def init_action(self): main_dir = ExecutionEnvironment.getEnvironmentVariable("MAIN_DIR") filename = os.path.join(main_dir, "ralph_actions.json") self.load_action_manifest(filename, "/actions/ralph") self.action_haptic_left = self.vr_input.getActionHandle( '/actions/ralph/out/Haptic_Left') self.source_left = self.vr_input.getInputSourceHandle( '/user/hand/left') self.action_pose_left = self.vr_input.getActionHandle( '/actions/ralph/in/Hand_Left') self.action_haptic_right = self.vr_input.getActionHandle( '/actions/ralph/out/Haptic_Right') self.source_right = self.vr_input.getInputSourceHandle( '/user/hand/right') self.action_pose_right = self.vr_input.getActionHandle( '/actions/ralph/in/Hand_Right') self.action_trackpad_click = self.vr_input.getActionHandle( '/actions/ralph/in/trackpadclick') self.action_trackpad_pos = self.vr_input.getActionHandle( '/actions/ralph/in/trackpadpos')
def init_action(self): main_dir = ExecutionEnvironment.getEnvironmentVariable("MAIN_DIR") filename = os.path.join(main_dir, "demo_actions.json") self.load_action_manifest(filename, "/actions/demo") self.action_haptic_left = self.vr_input.getActionHandle( '/actions/demo/out/Haptic_Left') self.source_left = self.vr_input.getInputSourceHandle( '/user/hand/left') self.action_pose_left = self.vr_input.getActionHandle( '/actions/demo/in/Hand_Left') self.action_haptic_right = self.vr_input.getActionHandle( '/actions/demo/out/Haptic_Right') self.source_right = self.vr_input.getInputSourceHandle( '/user/hand/right') self.action_pose_right = self.vr_input.getActionHandle( '/actions/demo/in/Hand_Right') self.action_left_trigger = self.vr_input.getActionHandle( '/actions/demo/in/left_trigger') self.action_right_trigger = self.vr_input.getActionHandle( '/actions/demo/in/right_trigger')
def __init__(self, ovr): self.ovr = ovr # Setup the application manifest, it will identify and configure the app # We force it in case it has changed. main_dir = ExecutionEnvironment.getEnvironmentVariable("MAIN_DIR") ovr.identify_application(os.path.join(main_dir, "skeleton.vrmanifest"), "p3dopenvr.demo.skeleton", force=True) # Load the actions manifest, it must be the same as the manifest referenced in the application manifest ovr.load_action_manifest( os.path.join(main_dir, "../manifest/actions.json")) # Use the '/actions/default' action set. This action set will be updated each frame ovr.add_action_set("/actions/default") # Get the handle of the action '/actions/default/in/Pose'. This hande will be used to update the position of the hands. hands_pose = ovr.vr_input.getActionHandle('/actions/default/in/Pose') # Get the handle of the skeleton actions. These handle will be used to update the # animation of the hands left_hand_skeleton_input = ovr.vr_input.getActionHandle( '/actions/default/in/SkeletonLeftHand') right_hand_skeleton_input = ovr.vr_input.getActionHandle( '/actions/default/in/SkeletonRightHand') # Create the representation of the left hand and attach a skinned hand model to it self.left_hand = LeftHand(ovr, "models/vr_glove_left_model.glb", hands_pose) self.left_hand.set_skeleton( DefaultLeftHandSkeleton(ovr, left_hand_skeleton_input)) # Create the representation of the left hand and attach a skinned hand model to it self.right_hand = RightHand(ovr, "models/vr_glove_right_model.glb", hands_pose) self.right_hand.set_skeleton( DefaultRightHandSkeleton(ovr, right_hand_skeleton_input)) # Register the update task with the correct sort number taskMgr.add(self.update, sort=ovr.get_update_task_sort())
def __init__(self, ovr): self.ovr = ovr # Setup the application manifest, it will identify and configure the app # We force it in case it has changed. main_dir = ExecutionEnvironment.getEnvironmentVariable("MAIN_DIR") ovr.identify_application(os.path.join(main_dir, "actions.vrmanifest"), "p3dopenvr.demo.actions", force=True) # Load the actions manifest, it must be the same as the manifest referenced in the application manifest ovr.load_action_manifest( os.path.join(main_dir, "../manifest/actions.json")) # Use the '/actions/default' action set. This action set will be updated each frame ovr.add_action_set("/actions/default") # Get the handle of the action '/actions/default/out/Haptic'. This hande will be used to trigger the haptic vibration. self.action_haptic = ovr.vr_input.getActionHandle( '/actions/default/out/Haptic') # Get the handle of the action '/actions/default/in/Pose'. This hande will be used to update the position of the hands. hands_pose = ovr.vr_input.getActionHandle('/actions/default/in/Pose') # Get the handle of the action '/actions/default/in/GrabGrip'. This hande will be used to retrieve the data of the action. self.action_grip = ovr.vr_input.getActionHandle( '/actions/default/in/GrabGrip') # Create the representation of the left hand and attach a simple box on it self.left_hand = LeftHand(ovr, "box", hands_pose) self.left_hand.model.set_scale(0.1) # Create the representation of the right hand and attach a simple box on it self.right_hand = RightHand(ovr, "box", hands_pose) self.right_hand.model.set_scale(0.1) # Register the update task with the correct sort number taskMgr.add(self.update, sort=ovr.get_update_task_sort())
if len(files) > 0: return files[0] return None def find_texture(self, pattern): return self.find_file('textures', pattern) def find_model(self, pattern): return self.find_file('models', pattern) def find_data(self, pattern): return self.find_file('data', pattern) def find_script(self, pattern): return self.find_file('scripts', pattern) def find_font(self, pattern): return self.find_file('fonts', pattern) def find_shader(self, pattern): return self.find_file('shaders', pattern) def find_doc(self, pattern): return self.find_file('doc', pattern) defaultDirContext = DirContext() main_dir = ExecutionEnvironment.getEnvironmentVariable("MAIN_DIR") defaultDirContext.add_all_path_auto(main_dir) defaultDirContext.add_all_path(main_dir)
def __init__(self): # Set up the window, camera, etc. ShowBase.__init__(self) # Create and configure the VR environment self.ovr = P3DOpenVR() self.ovr.init(msaa=4) main_dir = ExecutionEnvironment.getEnvironmentVariable("MAIN_DIR") # Setup the application manifest, it will identify and configure the app # We force it in case it has changed. self.ovr.identify_application(os.path.join(main_dir, "ralph.vrmanifest"), "p3dopenvr.demo.ralph", force=True) # Load the actions manifest, it must be the same as the manifest referenced in the application manifest self.ovr.load_action_manifest( os.path.join(main_dir, "manifest/actions.json")) # Use the '/actions/platformer' action set. This action set will be updated each frame self.ovr.add_action_set("/actions/platformer") # Get the handle of the action '/actions/platformer/in/Move'. This hande will be used to retrieve the data of the action. self.action_move = self.ovr.vr_input.getActionHandle( '/actions/platformer/in/Move') # Set the background color to black self.win.setClearColor((0, 0, 0, 1)) # Post the instructions self.title = addTitle( "Panda3D Tutorial: Roaming Ralph (Walking on Uneven Terrain)") self.inst1 = addInstructions(0.06, "[ESC]: Quit") self.inst2 = addInstructions(0.12, "[Left trackpad]: Rotate Left") self.inst3 = addInstructions(0.18, "[Right trackpad]: Rotate Right") self.inst4 = addInstructions(0.24, "[Up trackpad]: Walk Forward") self.inst4 = addInstructions(0.30, "[Down trackpad]: Walk Backward") # Set up the environment # # This environment model contains collision meshes. If you look # in the egg file, you will see the following: # # <Collide> { Polyset keep descend } # # This tag causes the following mesh to be converted to a collision # mesh -- a mesh which is optimized for collision, not rendering. # It also keeps the original mesh, so there are now two copies --- # one optimized for rendering, one for collisions. self.environ = loader.loadModel("models/world") self.environ.reparentTo(render) # Create the main character, Ralph self.ralph = render.attachNewNode('ralph') self.ralphStartPos = self.environ.find("**/start_point").getPos() self.ovr.tracking_space.setPos(self.ralphStartPos) self.ralph.setPos(self.ovr.hmd_anchor.getPos(render)) self.accept("escape", sys.exit) taskMgr.add(self.move, "moveTask") taskMgr.add(self.collision, "collisionTask") # Set up the camera self.disableMouse() # We will detect the height of the terrain by creating a collision # ray and casting it downward toward the terrain. One ray will # start above ralph's head, and the other will start above the camera. # A ray may hit the terrain, or it may hit a rock or a tree. If it # hits the terrain, we can detect the height. If it hits anything # else, we rule that the move is illegal. self.cTrav = CollisionTraverser() self.ralphGroundRay = CollisionRay() self.ralphGroundRay.setOrigin(0, 0, 9) self.ralphGroundRay.setDirection(0, 0, -1) self.ralphGroundCol = CollisionNode('ralphRay') self.ralphGroundCol.addSolid(self.ralphGroundRay) self.ralphGroundCol.setFromCollideMask(CollideMask.bit(0)) self.ralphGroundCol.setIntoCollideMask(CollideMask.allOff()) self.ralphGroundColNp = self.ralph.attachNewNode(self.ralphGroundCol) self.ralphGroundHandler = CollisionHandlerQueue() self.cTrav.addCollider(self.ralphGroundColNp, self.ralphGroundHandler) # Uncomment this line to see the collision rays #self.ralphGroundColNp.show() # Uncomment this line to show a visual representation of the # collisions occuring #self.cTrav.showCollisions(render) # Create some lighting ambientLight = AmbientLight("ambientLight") ambientLight.setColor((.3, .3, .3, 1)) directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection((-5, -5, -5)) directionalLight.setColor((1, 1, 1, 1)) directionalLight.setSpecularColor((1, 1, 1, 1)) render.setLight(render.attachNewNode(ambientLight)) render.setLight(render.attachNewNode(directionalLight))
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()
import os import yaml import random import imageio import argparse import numpy as np import time import cv2 from direct.showbase.ShowBase import ShowBase from panda3d.core import loadPrcFileData, Vec3, \ ConfigVariableFilename, ExecutionEnvironment from pynput import keyboard from direct.gui.OnscreenImage import OnscreenImage print('XDG_CACHE_HOME={xch}'.format( xch=ExecutionEnvironment.getEnvironmentVariable('XDG_CACHE_HOME'))) print('WARNING: models will be cached to {mcd}'.format( mcd=ConfigVariableFilename('model-cache-dir'))) loadPrcFileData('', 'window-type offscreen') loadPrcFileData('', 'sync-video 0') loadPrcFileData('', 'load-file-type p3assimp') loadPrcFileData('', 'win-size {w} {h}'.format(w=600, h=450)) KEY_W = keyboard.KeyCode.from_char('w') KEY_A = keyboard.KeyCode.from_char('a') KEY_S = keyboard.KeyCode.from_char('s') KEY_D = keyboard.KeyCode.from_char('d') KEY_F = keyboard.KeyCode.from_char('f') KEY_U = keyboard.KeyCode.from_char('u')