def __init__(self, *args, **kwargs): ViewTowers.__init__(self, *args, **kwargs) # ignore keys set by viewer for key in self.getAllAccepting(): if key in ("s", "escape"): continue self.ignore(key) self.permanent_events = self.getAllAccepting() # global variables self.text_bg = (1, 1, 1, 0.7) self.font = self.loader.loadFont('cmr12.egg') self.question = ( "Use the mouse to indicate the direction that " "the tower will fall.") self.feedback_time = 3.0 self.buffer_time = 0.75 # create text self.create_all_text() # create direction line self.line = LineSegs() self.line_node = None self.angle = None alight = AmbientLight('alight3') alight.setColor((0.8, 0.8, 0.8, 1)) self.line_light = self.lights.attachNewNode(alight)
def buildAmbientLight(self, color): """ Builds a Panda3D Ambient Light with the specified color. """ alight = render.attachNewNode(AmbientLight("Ambient")) alight.node().setColor(Vec4(*color)) render.setLight(alight) return alight
def init_node_path(self): if self.node_path: self.parent.node_path_mesh.clearLight(self.node_path) self.node_path.remove() from pandac.PandaModules import AmbientLight alight = AmbientLight('alight') alight.setColor(VBase4(*[x / 127.0 for x in self.color] + [1.0])) self.node_path = self.parent.node_path_mesh.attachNewNode(alight) self.parent.node_path_mesh.setLight(self.node_path)
def loadStars(self): ambientlight = AmbientLight('alight') ambientlight.setColor(Vec4(1, 1, 1, 0)) lightnode = render.attachNewNode(ambientlight) self.stars = loader.loadModel("stars.bam") self.stars.setLight(lightnode) self.stars.setScale(1000) self.stars.setPos(0, 0, 0) self.stars.reparentTo(render) self.starsRotation = self.stars.getQuat()
def set_lighting(self): dlight = DirectionalLight('dlight') dlnp = self.render.attachNewNode(dlight) dlnp.setHpr(45,-45,0) self.render.setLight(dlnp) ambientLight = AmbientLight('ambientLight') ambientLight.setColor(VBase4(0.5, 0.5, 0.5, 1)) ambientLightNP = render.attachNewNode(ambientLight) self.render.setLight(ambientLightNP)
def setupLights(self): lAttrib = LightAttrib.makeAllOff() ambientLight = AmbientLight( "ambientLight" ) ambientLight.setColor( Vec4(.4, .4, .35, 1) ) lAttrib = lAttrib.addLight( ambientLight ) directionalLight = DirectionalLight( "directionalLight" ) directionalLight.setDirection( Vec3( 0, 8, -2.5 ) ) directionalLight.setColor( Vec4( 0.9, 0.8, 0.9, 1 ) ) lAttrib = lAttrib.addLight( directionalLight ) render.attachNewNode( directionalLight.upcastToPandaNode() ) render.attachNewNode( ambientLight.upcastToPandaNode() ) render.node().setAttrib( lAttrib )
def addLight(self, type, tag, pos, color, hpr): ''' Create a light of the given type and assign the given properties. Dynamic class instantantiation is difficult due to the Panda module layout so we use conditionals TODO - support for attenuation. ''' LOG.debug("[GXMgr] Adding light of type %s"%type) if hasattr(pandac.PandaModules, type): LOG.debug("[GXMgr] Found light class - %s"%type) if (type.lower() == 'ambientlight'): from pandac.PandaModules import AmbientLight l = AmbientLight(tag) if color: l.setColor(color) lnp = render.attachNewNode(l) elif (type.lower() == 'directionallight'): from pandac.PandaModules import DirectionalLight l = DirectionalLight(tag) if color: l.setColor(color) lnp = render.attachNewNode(l) if hpr: lnp.setHpr(hpr) elif (type.lower() == 'pointlight'): from pandac.PandaModules import PointLight l = PointLight(tag) if color: l.setColor(color) lnp = render.attachNewNode(l) if pos: lnp.setPos(pos) elif (type.lower() == 'spotlight'): from pandac.PandaModules import Spotlight l = Spotlight(tag) if lens: lightLens = PerspectiveLens() l.setLens(lightLens) if color: l.setColor(color) lnp = render.attachNewNode(l) if hpr: lnp.setHpr(hpr) if pos: lnp.setPos(pos) self.lightList.append(lnp) render.setLight(lnp) else: LOG.error("[GXMgr] Unknown light class - %s"%type)
def setupLights(self): lAttrib = LightAttrib.makeAllOff() ambientLight = AmbientLight( "ambientLight" ) ambientLight.setColor( Vec4(.6, .6, .55, 1) ) lAttrib = lAttrib.addLight( ambientLight ) directionalLight = DirectionalLight( "directionalLight" ) directionalLight.setDirection( Vec3( 0, 8, -2.5 ) ) directionalLight.setColor( Vec4( 0.9, 0.8, 0.9, 1 ) ) lAttrib = lAttrib.addLight( directionalLight ) #set lighting on teapot so steam doesn't get affected #self.t.attachNewNode( directionalLight.upcastToPandaNode() ) self.t.attachNewNode( directionalLight ) #self.t.attachNewNode( ambientLight.upcastToPandaNode() ) self.t.attachNewNode( ambientLight) self.t.node().setAttrib( lAttrib )
def _set_light_sources(self): light_positions = [(1, -1, 1), (-1, -5, 1)] intensity = 0.8 for l_pos in light_positions: plight = PointLight('plight') plight.setColor(VBase4(intensity, intensity, intensity, 1)) plnp = render.attachNewNode(plight) plnp.setPos(l_pos[0], l_pos[1], l_pos[2]) render.setLight(plnp) light = AmbientLight('') light.setColor(VBase4(0.4, 0.4, 0.4, 1)) light_np = render.attachNewNode(light) light_np.setPos(0, 0, 0) render.setLight(light_np) pass
def __init__(self): ShowBase.__init__(self) base.setFrameRateMeter(True) # base.disableMouse() # initialise the lights alight = AmbientLight('alight') alight.setColor(VBase4(0.2, 0.2, 0.2, 1)) alnp = render.attachNewNode(alight) render.setLight(alnp) # Initialise the Ode world self.world = OdeWorld() self.world.setGravity(0, 0, -9.81) # load the models # environment self.environ = self.loader.loadModel("data/models/Plane") # Reparent the model to render. self.environ.reparentTo(self.render) # Apply scale and position transforms on the model. self.environ.setScale(10, 10, 10) self.environ.setPos(0, 0, 0) # racer self.glider = self.loader.loadModel("data/models/vehicle01") # Reparent the model to render. self.glider.reparentTo(self.render) # Apply scale and position transforms on the model. self.glider.setScale(1, 1, 1) self.glider.setPos(0, 0, 50) self.myBody = OdeBody(self.world) self.myBody.setPosition(self.glider.getPos(render)) self.myBody.setQuaternion(self.glider.getQuat(render)) self.myMass = OdeMass() self.myMass.setBox(11340, 1, 1, 1) self.myBody.setMass(self.myMass) # set up the camera base.camera.reparentTo(self.glider) base.camera.setPos(0, -30, 10) base.camera.lookAt(self.glider) # add physics to taskmgr taskMgr.add(self.physicsTask, 'physics')
def __init__(self): super(SimViewer, self).__init__() # Make a window. size = (700, 520) self.create_output(size, "SimViewer") self.output.setClearColor((0.0, 0.0, 0.0, 1.0)) # Lights node self.lights = NodePath('lights') # Create a spotlight slight = Spotlight('slight') slight.setScene(self.root) slight.setShadowCaster(True, 2**11, 2**11) # Set shadow mask, so we can exclude objects from casting shadows self.shadow_mask = BitMask32.bit(2) slight.setCameraMask(self.shadow_mask) c = 1.4 slight.setColor((c, c, c, 1.0)) slight.getLens().setNearFar(4, 100) slight.getLens().setFov(45) slnp = self.lights.attachNewNode(slight) slnp.setPos((7, 10, 40)) slnp.lookAt(2, 0, 1.5) self.root.setLight(slnp) # Create an ambient light. alight = AmbientLight('alight') c = 0.6 alight.setColor((c, c, c, 1.0)) alnp = self.lights.attachNewNode(alight) self.root.setLight(alnp) self.lights.reparentTo(self.root) # Set auto shading for shadows. self.root.setShaderAuto() # Set antialiasing on. self.root.setAntialias(AntialiasAttrib.MAuto) # Camera. lens = PerspectiveLens() self.lens = lens self.lens.setNearFar(0.1, 1000.) self.lens.setFov((40, 30)) self.cameras = self.root.attachNewNode('cameras') self.camera = self.make_camera(self.output, lens=self.lens) self.camera.setPos(15, 44, 3.) self.camera.setPos(15, 35, 15.) self.camera.lookAt(0, 0, 1.)
def __init__(self): ShowBase.__init__(self) # ambient light, so we can see colors on models alight = AmbientLight('alight') alight.setColor(VBase4(1, 1, 1, 1)) alnp = render.attachNewNode(alight) render.setLight(alnp) # this piece of code loads a model, and places it at (1,3,0) # it will be visible as soon as the program is started self.cityModel = self.loader.loadModel('models/City.egg') self.cityModel.setPos(1, 3, 0) # reparenting to "render" causes it to be displayed (render is the # root of the object tree self.cityModel.reparentTo(self.render) self.taskMgr.add(self.move_city, "move_city")
def __init__(self, filters): self.skybox = SkyBox() self.sun = Sun(filters) self.clouds = CloudLayer() self.fog = DistanceFog() #self.addDirectLight() self.dayLength = 120 #in seconds self.setTime(800.0) self.previousTime = 0 self.nightSkip = True self.paused = False ambient = Vec4(0.55, 0.65, 1.0, 1) #bright for hdr alight = AmbientLight('alight') alight.setColor(ambient) alnp = render.attachNewNode(alight) render.setLight(alnp) render.setShaderInput('alight0', alnp)
def create(self): lightAttrib = LightAttrib.makeAllOff() #create ambient light ambientLight = AmbientLight("ambientLight") ambientLight.setColor(self.ambientColor) lightAttrib = lightAttrib.addLight(ambientLight) render.attachNewNode(ambientLight.upcastToPandaNode()) self.ambientLight = ambientLight #default light settings """colors = [ Vec4(1,0,0,0), Vec4(0,1,0,0), Vec4(0,0,1,0), Vec4(1,1,0,0) ] directions = [ Vec3(1,0,0), Vec3(0,1,0), Vec3(-1,0,0), Vec3(0,-1,0) ] intensities = [ 3.0, 0.1, 3.0, 0.1 ]""" colors = [ Vec4(1, 1, 1, 0), Vec4(0, 1, 0, 0), Vec4(0, 0, 1, 0), Vec4(1, 1, 0, 0) ] # basic 3+1 point lighting directions = [ Vec3(0, 1, -0.2), Vec3(0, 1, 0), Vec3(-1, 0.3, 0), Vec3(0, -1, 0) ] intensities = [1.0, 0.0, 0.5, 0.0] #add directional lights self.directionalLights = [] for i in range(4): self.directionalLights.append( ShaderDirectionalLight(colors[i], directions[i], intensities[i], i)) lightAttrib = self.directionalLights[i].create(lightAttrib) #set light attributes render.node().setAttrib(lightAttrib)
def startGame(self): ''' Start the game ''' base.enableParticles() # self.p = ParticleEffect() # self.loadParticleConfig('./data.parcticles/blowout_fire.ptf') # Start of the code from steam.ptf # self.p.cleanup() self.p = ParticleEffect() self.p.loadConfig('./data/particles/blowout_test.ptf') # Sets particles to birth relative to the teapot, but to render at toplevel self.p.start(render) self.p.setPos(0.000, 0.000, 0) # Load the Lights ambilight = AmbientLight('ambilight') ambilight.setColor(VBase4(0.2, 0.2, 0.2, 1)) render.setLight(render.attachNewNode(ambilight))
def __init__( self, name=NAME_DEFAULT, pos=POS_DEFAULT, heading=HEADING_DEFAULT, vel=VEL_DEFAULT, acc=ACC_DEFAULT # player controlled acceleration. Can be 0.0 - 1.0 ): """@param name string""" self.name = name self.pos = pos self.vel = vel self.acc = acc self.heading = heading self.rotateLeft = False self.rotateRight = False self.visualNode = self.createVisualNode(self.pos) self.bullets = [] self.collisionHandler = colHandler self.collisions = [] self.collisionSphere = OdeSphereGeom(4) self.collisionSphere.setCategoryBits(BitMask32(0xffffffff)) self.collisionSphere.setCollideBits(BitMask32(0xffffffff)) self.collisionSphere.setPosition(pos[0], pos[1], 0) self.forces = [] self.mass = 1.0 self.health = Ship.HEALTH self.isAlive = True self.shootingSound = loader.loadSfx('anti_tank_gun_single_shot.mp3') self.destroySound = loader.loadSfx('large_explosion.mp3') self.bulletHitSound = loader.loadSfx( 'explosion_loud_internal_explosion_very_reverberant.mp3') self.collisionSound = loader.loadSfx('car_door_close.mp3') self.bulletParent = NodePath("Bullet Parent") self.bulletParent.reparentTo(render) self.bulletAmbientLight = AmbientLight('Bullet Light') self.bulletAmbientLight.setColor(Vec4(.0, .1, .2, .0)) lightnode = render.attachNewNode(self.bulletAmbientLight) self.bulletParent.setLight(lightnode)
def init_lights(self): from pandac.PandaModules import AmbientLight, DirectionalLight from pandac.PandaModules import ShadeModelAttrib # Set flat shading flatShade = ShadeModelAttrib.make(ShadeModelAttrib.MFlat) self.nodePath.setAttrib(flatShade) # Create directional light dlight1 = DirectionalLight('dlight1') dlight1.setColor(VBase4(1.0, 1.0, 1.0, 1.0)) dlnp1 = self.nodePath.attachNewNode(dlight1) dlnp1.setHpr(-10, -30, 0) self.nodePath.setLight(dlnp1) # Create second directional light dlight2 = DirectionalLight('dlight2') dlight2.setColor(VBase4(0.0, 0.1, 0.2, 1.0)) dlnp2 = self.nodePath.attachNewNode(dlight2) dlnp2.setHpr(170, 0, 0) self.nodePath.setLight(dlnp2) # Create ambient light alight = AmbientLight('alight') alight.setColor(VBase4(0.3, 0.3, 0.3, 1.0)) alnp = self.nodePath.attachNewNode(alight) self.nodePath.setLight(alnp)
def setLights(self): # Ambient Light ambientLight = AmbientLight('ambientLight') ambientLight.setColor(Vec4(0.1, 0.1, 0.1, 1)) ambientLightNP = render.attachNewNode(ambientLight.upcastToPandaNode()) render.setLight(ambientLightNP) # Directional light 01 directionalLight = DirectionalLight("directionalLight") directionalLight.setColor(Vec4(1, 1, 1, 1)) directionalLightNP = render.attachNewNode( directionalLight.upcastToPandaNode()) directionalLightNP.setPos(10, -20, 20) directionalLightNP.lookAt(0, 0, 0) render.setLight(directionalLightNP) # Directional light 02 directionalLight = DirectionalLight("directionalLight") directionalLight.setColor(Vec4(1, 1, 1, 1)) directionalLightNP = render.attachNewNode( directionalLight.upcastToPandaNode()) directionalLightNP.lookAt(0, 0, 0) directionalLightNP.setPos(10, 20, 20) render.setLight(directionalLightNP)
def collectPlayer(self, task): ''' Wait until all players are ready ''' if len(self._players) > 0 and self.player_buttonpressed[0] < task.time: if self._players[0].device.boost and self.countdown <= 0: loading = False for player in self._players: if player.vehicle.model_loading: loading = True break self._notify.debug("Loading vehicle: %s" % (loading)) if not loading: taskMgr.remove("selectVehicle") self.track = trackgen3d.Track3d(1000, 1800, 1600, 1200, 5) # len(self._players)) self.streetPath = render.attachNewNode( self.track.createRoadMesh()) # self.borderleftPath = render.attachNewNode(self.track.createBorderLeftMesh()) self.borderleftPath = render.attachNewNode( self.track.createBorderLeftMesh()) self.borderrightPath = render.attachNewNode( self.track.createBorderRightMesh()) self.borderleftcollisionPath = NodePath( self.track.createBorderLeftCollisionMesh()) self.borderrightcollisionPath = NodePath( self.track.createBorderRightCollisionMesh()) # #self.borderPath = render.attachNewNode(self.track.createBorderMesh()) textures = ["tube", "tube2", "street"] tex = textures[random.randint(0, len(textures) - 1)] roadtex = loader.loadTexture('data/textures/' + tex + '.png') bordertex = loader.loadTexture('data/textures/border.png') self.streetPath.setTexture(roadtex) self.borderleftPath.setTexture(bordertex) self.borderrightPath.setTexture(bordertex) # self.streetPath = loader.loadModel('data/models/Street.egg') # self.streetPath = loader.loadModel('data/models/Street.egg') # tex = loader.loadTexture('data/models/StreetTex.png') # self.nodePath.setTexture(tex) self._parent.startGame(self.streetPath, self.borderleftPath, self.borderrightPath, self.track.trackpoints, self.borderleftcollisionPath, self.borderrightcollisionPath) return task.done for device in self.unusedDevices: if device.boost: self.countdown = COUNTDOWN_START self.player_buttonpressed.append(0) self._parent.addPlayer(device) # Set the PlayerCam to the Vehicle select menu Node vehicleSelectNode = NodePath("VehicleSelectNode") self._players[-1].camera.camera.reparentTo(vehicleSelectNode) # Light, that casts shadows plight = Spotlight('plight') plight.setColor(VBase4(10.0, 10.0, 10.0, 1)) if (base.win.getGsg().getSupportsBasicShaders() != 0): pass # plight.setShadowCaster(True, 2048, 2048)#enable shadows for this light ##TODO wegen Linux # Light plight.getLens().setFov(80) plnp = vehicleSelectNode.attachNewNode(plight) plnp.setPos(2, -10, 10) plnp.lookAt(0, 0, 0) vehicleSelectNode.setLight(plnp) # vehicleSelectNode.setShaderAuto()#enable autoshader so we can use shadows # Light ambilight = AmbientLight('ambilight') ambilight.setColor(VBase4(0.2, 0.2, 0.2, 1)) vehicleSelectNode.setLight( vehicleSelectNode.attachNewNode(ambilight)) self.platform.instanceTo( vehicleSelectNode) # Load the platform # instance shown text self.countdown_node.instanceTo( vehicleSelectNode) # Instance the Countdown self.loading.instanceTo( vehicleSelectNode) # Show the Loading-Text self.attributes.copyTo(vehicleSelectNode).hide() self._players[-1].vehicle.model_loading = True # start loading the model loader.loadModel(self.vehicle_list[0], callback=self._players[-1].setVehicle) self._notify.debug("Loading initial vehicle: %s" % (self.vehicle_list[0])) self.unusedDevices.remove(device) self.player_buttonpressed[-1] = task.time + self.KEY_DELAY # Add the Skybox skybox = loader.loadModel("data/models/skybox.egg") t = Texture() t.load(PNMImage("data/textures/skybox_hangar.png")) skybox.setTexture(t) skybox.setBin("background", 1) skybox.setDepthWrite(0) skybox.setDepthTest(0) skybox.setLightOff() skybox.setScale(10000) skybox.reparentTo(vehicleSelectNode) for player in self._players: if self.player_buttonpressed[self._players.index( player)] < task.time: if player.device.use_item: self.countdown = COUNTDOWN_START self._notify.debug("Removing player: %s" % (player)) self.unusedDevices.append(player.device) self.player_buttonpressed.pop(self._players.index(player)) self._parent.removePlayer(player) return task.cont
def __init__(self): ShowBase.__init__(self) resize_window = ConfigVariableBool('viewer-resize-window', '#t') if resize_window.getValue(): self.win_size = (800, 800) # Black background self.win.setClearColor((0.0, 0.0, 0.0, 1.0)) # Set up lights. self.lights = NodePath("lights") # Spotlight. Casts shadows. slight = Spotlight("slight") slight.setScene(self.render) slight.setShadowCaster(True, 2**11, 2**11) # Set shadow mask, so we can exclude objects from casting shadows self.shadow_mask = BitMask32.bit(2) slight.setCameraMask(self.shadow_mask) slight.setColor((1.2, 1.2, 1.2, 1.)) slight.getLens().setFov(45) slight.getLens().setNearFar(1, 100) slnp = self.lights.attachNewNode(slight) slnp.setPos((6, 8, 20)) slnp.lookAt(0, 0, 0) self.render.setLight(slnp) # Ambient light. alight = AmbientLight("alight") a = 0.75 alight.setColor((a, a, a, 1.0)) #alight.setColor((0.8, 0.8, 0.8, 1.0)) alnp = self.lights.attachNewNode(alight) self.render.setLight(alnp) self.lights.reparentTo(self.render) # Set auto shading for shadows use_shaders = ConfigVariableBool('viewer-use-shaders', '#t') if use_shaders.getValue(): self.render.setShaderAuto() # Set antialiasing on self.render.setAntialias(AntialiasAttrib.MAuto) # Camera self.camera_rot = self.render.attachNewNode("camera_rot") self.cameras = self.camera_rot.attachNewNode("cameras") self.cameras.setPos(14, 32, 9.) self.look_at = self.render.attachNewNode("look_at") self.look_at.setPos(Point3(2, 0, 1)) self.cameras.lookAt(self.look_at) self.camera.reparentTo(self.cameras) # Adjust the camera's lens lens = PerspectiveLens() self.camLens = lens self.camLens.setNearFar(0.01, 1000.0) setlens = ConfigVariableBool('viewer-set-cam-lens', '#t') if setlens: self.cam.node().setLens(self.camLens) # # Initialize / set variables self.sso = None self.ssos = [] self.cache = None self.scene = SSO("scene") self.scene.reparentTo(self.render) # Key callbacks. self.accept("shift-control-escape", self.exit) self.accept("escape", self.exit) self.accept("0", self.reset_sso) self.accept("arrow_left", self.prev) self.accept("arrow_right", self.next) self.accept("page_down", self.prev, [100]) self.accept("page_up", self.next, [100]) self.accept("f1", self.toggle_debug) self.accept("o", self.physics_once, extraArgs=[1. / 10]) self.accept("i", self.physics_once, extraArgs=[1. / 10000]) # Remove existing keyboard tasks. self.mandatory_events = ("window-event", "async_loader_0", "render-texture-targets-changed", "shift-control-escape") # Task list: name: (key, args) events = { "physics": ("p", ), "repel": ("t", ), "bump": ("f", ), "rotate": ("r", 20), "rotate90": ("h", ), "ss_task": ("s", ), "ssa_task": ("w", ), "bp": ("b", ) } # Add events for key, val in events.iteritems(): call = [key] + list(val[1:]) self.accept(val[0], self.toggle_task, call) # These are the key events that we will never ignore self.permanent_events = self.getAllAccepting() # These are the key events that we will never ignore self.permanent_tasks = [ task.getName() for task in self.taskMgr.getAllTasks() ] self.start_time = -1 self.old_elapsed = 0
def loadLight(self): #Sets the lights plight = AmbientLight('my plight') light = self.parserClass.userConfig.getfloat('display', 'light') plight.setColor(VBase4(light, light, light, 0.5)) plnp = render.attachNewNode(plight) render.setLight(plnp)
def start(self): self.textures.load_all() self.char = Actor("res/models/ralph", {"run":"res/models/ralph-run", "walk":"res/models/ralph-walk"}) self.char.pose('walk', 5) self.char.setScale(.2) self.char.setH(180) self.gui.buttons.add_button(name = 'Exit', text = ("Exit", "Exit", "Exit", "disabled"), pos = (1.23, 0, -0.95), scale = 0.07, command=self.stop) self.gui.screen_texts.add_text(name = 'status', text = 'Hello! Suber was started!', pos = (-1.3, -0.95), scale = 0.07) #self.gui.entries.add_entry(name = 'console',text = "" , #pos = (-1.29, 0, -0.85), #scale=0.07,command=self.cmd_handler.cmd_handle, #initialText="", width = 37, numLines = 1,focus=0) self.gui.screen_texts.add_text(name = 'help', text = 'F5 - create world\nm - toggle map\nF1 - toggle'+\ ' help\nEsc - exit\nF10 - render info\n'+\ 'F2/F3 - 1st/3d person camera\n'+\ 'F4 - toggle fly/terrain\n'+\ 'F9 - Cam disable\n'+\ 'F8 - Toggle Collisions\n'+\ 'F11/F12 - toggle polygons / disable textures', pos = (-1, 0.8), scale = 0.07) self.gui.hotkeys.accept('f1', self.toggle_help) self.gui.screen_images.add_image('sight', self.textures['sight'], scale = 0.05, pos = (0, 0, 0)) self.gui.screen_images['sight'].setTransparency(TransparencyAttrib.MAlpha) plight = PointLight('plight') sun = self.gui.render.attachNewNode(plight) sun.setPos(-32768, 32768, 20000) self.gui.render.setLight(sun) alight = AmbientLight('alight') alight.setColor(VBase4(0.5, 0.5, 0.5, 1)) alnp = self.gui.render.attachNewNode(alight) self.gui.render.setLight(alnp) color = (0.28125, 0.53125, 0.80859375) fog = Fog("A linear-mode Fog node") fog.setColor(*color) fog.setLinearFallback(0,500,550) self.gui.camera.attachNewNode(fog) color = (0.28125, 0.53125, 0.80859375) self.gui.render.setFog(fog) self.gui.setBackgroundColor(*color) self.cam_manager = CamManager(self) self.move_avatar = MoveAvatar(self) self.vox_config = VoxConfig() self.coord_block = CoordBlock(self, self.vox_config) self.vox_params = VoxParams() self.vox_params.gui = self.gui self.vox_params.avatar = self.cam_manager.node self.vox_params.status = self.write self.vox_params.root_node = self.gui.render self.vox_params.chunks_tex = self.textures['world_blocks'] self.vox_params.get_coord_block = self.coord_block self.vox_params.tree_tex = self.textures['tree'] self.vox_params.water_tex = self.textures['water'] self.vox_params.leafModel = self.gui.loader.loadModel("res/models/shrubbery") self.vox_params.leafTex = self.textures['leaf'] self.vox_params.fog = fog self.world = World(self.vox_config, self.vox_params) self.collision_avatar = CollisionAvatar(self) #self.vox_params.sun = sun self.gui.taskMgr.setupTaskChain('Ticker', tickClock = True) self.gui.taskMgr.doMethodLater(0.05, self.ticker, 'taskTicker', taskChain = 'Ticker') self.gui.start()
task.last = task.time self.keybControl(dt) base.cam.setY(self.avatar.getY() - self.camdistY) if self.steer2d: base.cam.setX(self.avatar.getX()) base.cam.setZ(self.avatar.getZ() + self.camdistZ) base.cam.lookAt(self.avatar) return Task.cont #========================================================================= # Main #========================================================================= alight = AmbientLight('alight') alight.setColor((.3, .3, .3, 1)) alnp = render.attachNewNode(alight) render.setLight(alnp) dlight = DirectionalLight('dlight') lv = .6 dlight.setColor((lv, lv, lv, 1)) dlnp = render.attachNewNode(dlight) render.setLight(dlnp) dlnp.setPos(0, -20, 35) dlnp.lookAt(0, 0, 0) DO = DirectObject() DO.accept('c', toggle_collisions) DO.accept('h', toggle_info)
def __init__(self): """Initialise the scene.""" # Show the framerate base.setFrameRateMeter(True) # Initialise terrain: # Make 4 terrain nodepath objects with different hilliness values # and arrange them side-by-side in a 2x2 grid, giving a big terrain # with variable hilly and flat areas. color = (0.6, 0.8, 0.5, 1) # Bright green-ish scale = 12 height = 18 # FIXME: For now we are raising the terrain so it # floats above the sea to prevent lakes from # appearing (but you still get them sometimes) t1 = Terrain(color=color, scale=scale, trees=0.7, pos=P.Point3(0, 0, height)) t1.prime.reparentTo(render) t2 = Terrain(color=color, scale=scale, h=24, pos=P.Point3(32 * scale, 0, height), trees=0.5) t2.prime.reparentTo(render) t3 = Terrain(color=color, scale=scale, h=16, pos=P.Point3(32 * scale, 32 * scale, height), trees=0.3) t3.prime.reparentTo(render) t4 = Terrain(color=color, scale=scale, h=2, pos=P.Point3(0, 32 * scale, height), trees=0.9) t4.prime.reparentTo(render) #tnp1.setPos(tnp1,-32,-32,terrainHeight) # Initialise sea sea = Sea() # Initialise skybox. self.box = loader.loadModel("models/skybox/space_sky_box.x") self.box.setScale(6) self.box.reparentTo(render) # Initialise characters self.characters = [] self.player = C.Character(model='models/eve', run='models/eve-run', walk='models/eve-walk') self.player.prime.setZ(100) self.player._pos = SteerVec(32 * 12 + random.random() * 100, 32 * 12 + random.random() * 100) self.player.maxforce = 0.4 self.player.maxspeed = 0.55 EdgeScreenTracker(self.player.prime, dist=200) # Setup camera for i in range(0, 11): self.characters.append(C.Character()) self.characters[i].prime.setZ(100) self.characters[i].wander() self.characters[i].maxforce = 0.3 self.characters[i].maxspeed = 0.2 self.characters[i]._pos = SteerVec(32 * 12 + random.random() * 100, 32 * 12 + random.random() * 100) C.setContainer( ContainerSquare(pos=SteerVec(32 * 12, 32 * 12), radius=31 * 12)) #C.toggleAnnotation() # Initialise keyboard controls. self.accept("c", C.toggleAnnotation) self.accept("escape", sys.exit) # Setup CollisionRay and CollisionHandlerQueue for mouse picking. self.pickerQ = P.CollisionHandlerQueue() self.picker = camera.attachNewNode( P.CollisionNode('Picker CollisionNode')) self.picker.node().addSolid(P.CollisionRay()) # We want the picker ray to collide with the floor and nothing else. self.picker.node().setFromCollideMask(C.floorMASK) self.picker.setCollideMask(P.BitMask32.allOff()) base.cTrav.addCollider(self.picker, self.pickerQ) try: handler.addCollider(self.picker, camera) except: pass self.accept('mouse1', self.onClick) # Set the far clipping plane to be far enough away that we can see the # skybox. base.camLens.setFar(10000) # Initialise lighting self.alight = AmbientLight('alight') self.alight.setColor(VBase4(0.35, 0.35, 0.35, 1)) self.alnp = render.attachNewNode(self.alight) render.setLight(self.alnp) self.dlight = DirectionalLight('dlight') self.dlight.setColor(VBase4(0.4, 0.4, 0.4, 1)) self.dlnp = render.attachNewNode(self.dlight) self.dlnp.setHpr(45, -45, 0) render.setLight(self.dlnp) self.plight = PointLight('plight') self.plight.setColor(VBase4(0.8, 0.8, 0.5, 1)) self.plnp = render.attachNewNode(self.plight) self.plnp.setPos(160, 160, 50) self.slight = Spotlight('slight') self.slight.setColor(VBase4(1, 1, 1, 1)) lens = PerspectiveLens() self.slight.setLens(lens) self.slnp = render.attachNewNode(self.slight) self.slnp.setPos(-20, -20, 20) self.slnp.lookAt(50, 50, 0) # Initialise some scene-wide exponential fog colour = (0.5, 0.8, 0.8) self.expfog = Fog("Scene-wide exponential Fog object") self.expfog.setColor(*colour) self.expfog.setExpDensity(0.0005) render.setFog(self.expfog) base.setBackgroundColor(*colour) # Add a task for this Plant to the global task manager. self.stepcount = 0 taskMgr.add(self.step, "Plant step task")
def startGame(self): ''' Start the game ''' # Create the Track self.track = trackgen3d.Track3d(1000, 800, 600, 200, 5) self.trackmesh = NodePath(self.track.createRoadMesh()) tex = loader.loadTexture('data/textures/street.png') self.trackmesh.setTexture(tex) self.trackmesh2 = NodePath(self.track.createUninterpolatedRoadMesh()) self.trackmesh2.setTexture(tex) # nodePath.setTwoSided(True) self.trackmesh.reparentTo(render) # LICHT self.plight = PointLight('kkkplight') self.plight.setColor(VBase4(21, 0, 0, 1)) self.plnp = NodePath(self.plight) self.plnp.reparentTo(render) self.plnp.setPos(0, 0, 2000) self.plnp.node().setAttenuation(Point3(0, 0, 1)) self.plnp.setScale(.5, .5, .5) # self.plnp.setHpr(0,-90,0) # print plight.getAttenuation() # plnp.setPos(-10, -800, 20) render.setLight(self.plnp) self.accept("w", self.setA, [100]) self.accept("s", self.setA, [-10]) self.accept("e", self.setB, [10]) self.accept("d", self.setB, [-10]) self.accept("r", self.setC, [100]) self.accept("f", self.setC, [-100]) self.accept("z", self.setRotation, [0, 10]) self.accept("h", self.setRotation, [0, -10]) self.accept("u", self.setRotation, [1, 10]) self.accept("j", self.setRotation, [1, -10]) self.accept("i", self.setRotation, [2, 10]) self.accept("k", self.setRotation, [2, -10]) self.accept("n", self.setExponent, [-50]) self.accept("m", self.setExponent, [50]) # load our model tron = loader.loadModel("data/models/vehicles/vehicle02") self.tron = tron # self.tron.loadAnims({"running":"models/tron_anim"}) tron.reparentTo(render) tron.setPos(0, 0, 15) tron.setHpr(0, -90, 0) # nodePath2 = self.render.attachNewNode(self.track.createBorderLeftMesh()) # tex2 = loader.loadTexture('data/textures/border.png') # nodePath2.setTexture(tex2) # # nodePath3 = self.render.attachNewNode(self.track.createBorderRightMesh()) # tex2 = loader.loadTexture('data/textures/border.png') # nodePath3.setTexture(tex2) ring = loader.loadModel("data/models/ring.egg") ring.setScale(24) ring.setZ(-25) ring.setY(100) ring.setTransparency(TransparencyAttrib.MAlpha) ring.reparentTo(render) # Load the Lights ambilight = AmbientLight('ambilight') ambilight.setColor(VBase4(0.8, 0.8, 0.8, 1)) render.setLight(render.attachNewNode(ambilight))
def __init__(self): from pandac.PandaModules import CollisionHandlerFloor, CollisionHandlerPusher, CollisionHandlerEvent, CollisionTraverser from pandac.PandaModules import DirectionalLight, AmbientLight, VBase4 ShowBase.__init__(self) self.sky = self.loader.loadModel('models/sky-sphere') self.sky.reparentTo(self.render) self.stage = self.loader.loadModel('models/test-collide') self.stage.reparentTo(self.render) self.floor = self.stage.findAllMatches('**/=CollideType=floor') self.floor.setCollideMask(FLOOR_MASK) self.obstacles = self.stage.findAllMatches('**/=CollideType=obstacle') if self.obstacles: self.obstacles.setCollideMask(OBSTACLE_MASK) self.zones = self.stage.findAllMatches('**/=CollideType=zone') if self.zones: self.zones.setCollideMask(ZONE_MASK) self.create_stanchions() # Character rig, which allows camera to follow character self.char_rig = self.stage.attachNewNode('char_rig') self.active_char = Character('mainchar', self.char_rig) self.cam.reparentTo(self.char_rig) self.cam.setPos(0.5, -3, 1.5) self.cam.lookAt(0.5, 0, 1.5) self.light = DirectionalLight('dlight') self.light.setColor(VBase4(0.3, 0.28, 0.26, 1.0)) self.lightNP = self.stage.attachNewNode(self.light) self.lightNP.setHpr(-75, -45, 0) self.stage.setLight(self.lightNP) self.amblight = AmbientLight('amblight') self.amblight.setColor(VBase4(0.7, 0.68, 0.66, 1.0)) self.amblightNP = self.stage.attachNewNode(self.amblight) self.stage.setLight(self.amblightNP) self.accept('w', self.active_char.begin_forward) self.accept('a', self.active_char.begin_left) self.accept('s', self.active_char.begin_backward) self.accept('d', self.active_char.begin_right) self.accept('w-up', self.active_char.end_forward) self.accept('a-up', self.active_char.end_left) self.accept('s-up', self.active_char.end_backward) self.accept('d-up', self.active_char.end_right) self.taskMgr.add(self.active_char.MoveTask, 'MoveTask') self.look = False self.prev_pos = None self.accept('mouse2', self.begin_look) self.accept('mouse2-up', self.end_look) self.accept('mouse3', self.active_char.begin_spin) self.accept('mouse3-up', self.active_char.end_spin) self.taskMgr.add(self.MouseTask, 'MouseTask') self.floor_handler = CollisionHandlerFloor() self.floor_handler.addCollider(self.active_char.actor_from_floor, self.char_rig) self.wall_handler = CollisionHandlerPusher() self.wall_handler.addCollider(self.active_char.actor_from_obstacle, self.char_rig) self.zone_handler = CollisionHandlerEvent() self.zone_handler.addInPattern('%fn-into') self.zone_handler.addOutPattern('%fn-out') def foo(entry): print 'You are in the zone' def bar(entry): print 'You are not in the zone' self.accept('blockchar_zone-into', foo) self.accept('blockchar_zone-out', bar) self.cTrav = CollisionTraverser('main traverser') self.cTrav.setRespectPrevTransform(True) self.cTrav.addCollider(self.active_char.actor_from_floor, self.floor_handler) self.cTrav.addCollider(self.active_char.actor_from_obstacle, self.wall_handler) self.cTrav.addCollider(self.active_char.actor_from_zone, self.zone_handler)