def __init__(self, base, USE_RP): self.base = base """ direct.showbase.ShowBase """ if not USE_RP: alight = AmbientLight('alight') alnp = self.base.render.attachNewNode(alight) alight.setColor((0.2, 0.2, 0.2, 1)) self.base.render.setLight(alnp) # Put lighting on the main scene dlight = DirectionalLight('dlight') dlnp = self.base.render.attachNewNode(dlight) dlnp.setPos(0, 5, 5) dlight.setColor((0.8, 0.8, 0.5, 1)) dlnp.setHpr(0, 60, 0) self.base.render.setLight(dlnp) plight = PointLight('plight') plnp = self.base.render.attachNewNode(plight) plnp.setPos(0, -50, 50) plnp.setHpr(0, 60, 0) self.base.render.setLight(plnp) self.sounds = {}
def begin(self): base.setBackgroundColor( self.environment['colourBackground'] ) alight = AmbientLight('AmbientLight') alight.setColor(self.environment['colourAmbient'] ) alnp = self.sceneNode.attachNewNode(alight) self.sceneNode.setLight(alnp) if self.environment['fog']: fog = Fog( 'sceneName' ) fog.setColor( self.environment['fog']['color'] ) if self.environment['fog']['mode'] == "linear": fog.setLinearRange(self.environment['fog']['linearStart']*1000,self.environment['fog']['linearEnd']*1000) else: fog.setExpDensity( self.environment['fog']['expDensity'] ) self.sceneNode.setFog(fog) [self.createNode(props) for props in self.nodes] [self.createLight(props) for props in self.lights] [self.createCamera(props) for props in self.cameras] [self.createEntity(props) for props in self.entities] # [self.createStaticGeoms(props) for props in self.staticGeoms] self.sceneNode.clearModelNodes() self.sceneNode.flattenStrong() self.sceneNode.setShaderAuto()
def initLights(self): torches = self.level.findAllMatches("**/TorchTop*") self.lights = [] for torch in torches: tLight = PointLight(torch.getName()) tLight.setColor((.4, .2, .0, 1)) tlnp = render.attachNewNode(tLight) tlnp.setPos(torch.getPos(render)) render.setLight(tlnp) self.lights.append(tlnp) windows = self.level.findAllMatches("**/Window*") plates = self.level.findAllMatches("**/Plate*") spikes = self.level.findAllMatches("**/Spikes*") for window in windows: wLight = Spotlight(window.getName()) lens = PerspectiveLens() wLight.setLens(lens) wLight.setColor((0.5, 0.4, 0.5, 1)) wlnp = render.attachNewNode(wLight) wlnp.setPos(window.getPos(render)) wlnp.lookAt((0, window.getY(), 0)) for plate in plates: plate.setLight(wlnp) self.lights.append(wlnp) ambientLight = AmbientLight("ambientLight") ambientLight.setColor((.1, .1, .025, 1)) render.setLight(render.attachNewNode(ambientLight))
def __init__(self): self.hotelModel = loader.loadModel("menuBG/menuback") self.hotelModel.reparentTo(render) self.hotelModel.stash() # setup some lights plight = PointLight("mapgen_plight") plight.setColor(VBase4(0.45, 0.35, 0.35, 1)) self.plnp = self.hotelModel.attachNewNode(plight) self.plnp.setPos(-3, 3, 5) base.render.setLight(self.plnp) # setup a default ambient light alight = AmbientLight("mapgen_alight") alight.setColor(VBase4(0.20, 0.20, 0.28, 1)) self.alnp = self.hotelModel.attachNewNode(alight) base.render.setLight(self.alnp) sun = DirectionalLight('sun') sun.setColor(VBase4(0.8, 0.8, 0.8, 1)) lens = PerspectiveLens() lens.setFar(50) lens.setFov(80, 80) sun.setLens(lens) ms = 1024 #graphicMgr.shadowMapSize sun.setShadowCaster(True, ms, ms) self.sunnp = self.hotelModel.attachNewNode(sun) self.sunnp.setHpr(85, -50, 0) self.sunnp.setPos(12, 0, 10) base.render.setLight(self.sunnp)
def __init__(self): ShowBase.__init__(self) ambLight = AmbientLight("ambient") ambLight.setColor(Vec4(0.1,0.11,0.12,1.0)) ambNode = render.attachNewNode(ambLight) render.setLight(ambNode) dirLight = DirectionalLight("directional") dirLight.setColor(Vec4(0.7,0.7,0.68,1.0)) dirNode = render.attachNewNode(dirLight) dirNode.setHpr(60,-40,90) render.setLight(dirNode) sptLight = Spotlight("spot") sptLens = PerspectiveLens() sptLight.setLens(sptLens) sptLight.setColor(Vec4(0.6,0.6,0.6,1.0)) sptLight.setShadowCaster(True) sptNode = render.attachNewNode(sptLight) sptNode.setPos(0,0,20) sptNode.lookAt(0,0,0) render.setLight(sptNode) render.setShaderAuto() base.camLens.setFov(70) base.camLens.setNear(0.1) base.camLens.setFar(50) self.cam.setPos(-1,-4,4) self.cam.lookAt(0,-1,1)
def attachLights(render): dl = DirectionalLight('dirLight') dl.setColor(ColorToVec4('666060')) dlNP = render.attachNewNode(dl) dlNP.setHpr(0, -45, 0) render.setLight(dlNP) dl = DirectionalLight('dirLight') dl.setColor(ColorToVec4('606666')) dlNP = render.attachNewNode(dl) dlNP.setHpr(180, 45, 0) render.setLight(dlNP) dl = DirectionalLight('dirLight') dl.setColor(ColorToVec4('606060')) dlNP = render.attachNewNode(dl) dlNP.setHpr(90, -45, 0) render.setLight(dlNP) dl = DirectionalLight('dirLight') dl.setColor(ColorToVec4('626262')) dlNP = render.attachNewNode(dl) dlNP.setHpr(-90, 45, 0) render.setLight(dlNP) ambientLight = AmbientLight('ambientLight') ambientLight.setColor(Vec4(0.2, 0.2, 0.2, 1)) ambientLightNP = render.attachNewNode(ambientLight) render.setLight(ambientLightNP)
def setupLights(self): # Create some lighting ambientLight = AmbientLight("ambientLight") ambientLight.setColor(Vec4(.3, .3, .3, 1)) directionalLight1 = DirectionalLight("directionalLight") directionalLight1.setDirection(Vec3(5, 5, -5)) directionalLight1.setColor(Vec4(1, 1, 1, 1)) directionalLight1.setSpecularColor(Vec4(1, 1, 1, 1)) directionalLight2 = DirectionalLight("directionalLight") directionalLight2.setDirection(Vec3(5, -5, -5)) directionalLight2.setColor(Vec4(1, 1, 1, 1)) directionalLight2.setSpecularColor(Vec4(1, 1, 1, 1)) directionalLight3 = DirectionalLight("directionalLight") directionalLight3.setDirection(Vec3(-5, -5, -5)) directionalLight3.setColor(Vec4(1, 1, 1, 1)) directionalLight3.setSpecularColor(Vec4(1, 1, 1, 1)) directionalLight4 = DirectionalLight("directionalLight") directionalLight4.setDirection(Vec3(-5, 5, -5)) directionalLight4.setColor(Vec4(1, 1, 1, 1)) directionalLight4.setSpecularColor(Vec4(1, 1, 1, 1)) render.setLight(render.attachNewNode(ambientLight)) render.setLight(render.attachNewNode(directionalLight1)) render.setLight(render.attachNewNode(directionalLight2)) render.setLight(render.attachNewNode(directionalLight3)) render.setLight(render.attachNewNode(directionalLight4))
def __init__(self): # call superclass init (no implicit chaining) ShowBase.__init__(self) self.pnode = loader.loadModel("models/queen") self.pnode.reparentTo(render) self.pnode.setPos(0, 5, -1) self.pnode.setH(-60) self.pnode2 = loader.loadModel("models/pawn") self.pnode2.reparentTo(self.pnode) self.pnode2.setScale(0.5) self.ground = 1.2 self.pnode2.setPos(1, 0, self.ground) self.vz = 0 self.vx = 0 self.vy = 0 ############ lighting ############# alight = AmbientLight('alight') alight.setColor((.7, .3, .3, 1)) self.alnp = render.attachNewNode(alight) render.setLight(self.alnp) slight = DirectionalLight('slight') slight.setColor((1, .5, .5, 1)) slight.setDirection(LVector3(-0.8, 0, 0)) self.slnp = render.attachNewNode(slight) render.setLight(self.slnp) taskMgr.add(self.update, "update")
def __init__(self): base.setBackgroundColor(0.1, 0.1, 0.8, 1) base.setFrameRateMeter(True) base.cam.setPos(0, -60, 20) base.cam.lookAt(0, 0, 0) # Light alight = AmbientLight('ambientLight') alight.setColor(Vec4(0.5, 0.5, 0.5, 1)) alightNP = render.attachNewNode(alight) dlight = DirectionalLight('directionalLight') dlight.setDirection(Vec3(1, 1, -1)) dlight.setColor(Vec4(0.7, 0.7, 0.7, 1)) dlightNP = render.attachNewNode(dlight) render.clearLight() render.setLight(alightNP) render.setLight(dlightNP) # Input self.accept('escape', self.doExit) self.accept('r', self.doReset) self.accept('f1', self.toggleWireframe) self.accept('f2', self.toggleTexture) self.accept('f3', self.toggleDebug) self.accept('f5', self.doScreenshot) # Task taskMgr.add(self.update, 'updateWorld') # Physics self.setup()
def initialize_lighting(self): ambientLight_color = Vec4(0.5,0.5,0.5,1) sunLight_color = Vec4(0.5,0.5,0.5,1) backLight_color = Vec4(0.22,0.44,0.44,1) if self.timeOfDay == "morning": ambientLight_color = Vec4(0.56,0.52,0.62,1) sunLight_color = Vec4(0.86,0.75,0.63,1) # Create Ambient Light ambientLight = AmbientLight('ambientLight') ambientLight.setColor(ambientLight_color) ambientLightNP = render.attachNewNode(ambientLight) render.setLight(ambientLightNP) #Create Directional Light sunLight = DirectionalLight('sunLight') sunLight.setColor(sunLight_color) sunLightNP = render.attachNewNode(sunLight) sunLightNP.setHpr(180,-20,0) render.setLight(sunLightNP) #Create Directional Light backLight = DirectionalLight('backLight') backLight.setColor(backLight_color) backLightNP = render.attachNewNode(backLight) backLightNP.setHpr(-180,160,0) render.setLight(backLightNP)
def __init__(self): self.setAI() self.keyMap = {"left": 0, "right": 0, "forward": 0, "backward": 0, "cam-left": 0, "cam-right": 0} base.win.setClearColor(Vec4(0, 0, 0, 1)) # the menu self.loadAudio() self.showMenu() # keyboard and mouse events self.accept("escape", sys.exit) self.accept("w", self.setKey, ["forward", 1]) self.accept("a", self.setKey, ["left", 1]) self.accept("s", self.setKey, ["backward", 1]) self.accept("d", self.setKey, ["right", 1]) self.accept("w-up", self.setKey, ["forward", 0]) self.accept("a-up", self.setKey, ["left", 0]) self.accept("s-up", self.setKey, ["backward", 0]) self.accept("d-up", self.setKey, ["right", 0]) self.accept("arrow_left", self.setKey, ["cam-left", 1]) self.accept("arrow_left-up", self.setKey, ["cam-left", 0]) self.accept("arrow_right", self.setKey, ["cam-right", 1]) self.accept("arrow_right-up", self.setKey, ["cam-right", 0]) # create some lighting ambientLight = AmbientLight("ambientLight") ambientLight.setColor(Vec4(0.3, 0.3, 0.3, 1)) directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection(Vec3(-5, -5, -5)) directionalLight.setColor(Vec4(1, 1, 1, 1)) directionalLight.setSpecularColor(Vec4(1, 1, 1, 1)) render.setLight(render.attachNewNode(ambientLight)) render.setLight(render.attachNewNode(directionalLight))
def setupLights(self): base.setBackgroundColor(0.0, 0.0, 0.0, 1) base.setFrameRateMeter(True) # Add a light to the scene. self.lightpivot = render.attachNewNode("lightpivot") self.lightpivot.setPos(0, 0, 5) self.lightpivot.hprInterval(10, Point3(360, 0, 0)).loop() plight = PointLight('plight') plight.setColor(Vec4(1, 0, 0, 1)) plight.setAttenuation(Vec3(0.37, 0.025, 0)) plnp = self.lightpivot.attachNewNode(plight) plnp.setPos(45, 0, 0) plnp.lookAt(*Vec3(0, 0, 0, )) # Light alight = AmbientLight('ambientLight') alight.setColor(Vec4(0.2, 0.2, 0.2, 1)) alightNP = render.attachNewNode(alight) # dlight = DirectionalLight('directionalLight') # dlight.setDirection(Vec3(1, 1, -1)) # dlight.setColor(Vec4(0.7, 0.7, 0.7, 1)) # dlightNP = render.attachNewNode(dlight) render.clearLight() render.setLight(alightNP) # render.setLight(dlightNP) render.setLight(plnp) # create a sphere to denote the light sphere = loader.loadModel("models/sphere") sphere.reparentTo(plnp) render.setShaderAuto()
def setupLights(self): ambientLight = AmbientLight("ambientLight") ambientLight.setColor((.8, .8, .75, 1)) directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection(LVector3(0, 0, -2.5)) directionalLight.setColor((0.9, 0.8, 0.9, 1)) render.setLight(render.attachNewNode(ambientLight)) render.setLight(render.attachNewNode(directionalLight))
def setupLights(self): #This function sets up some default lighting ambientLight = AmbientLight("ambientLight") ambientLight.setColor(Vec4(.8, .8, .8, 1)) directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection(Vec3(0, 45, -45)) directionalLight.setColor(Vec4(0.2, 0.2, 0.2, 1)) render.setLight(render.attachNewNode(directionalLight)) render.setLight(render.attachNewNode(ambientLight))
def setupLight(self): ambientLight = AmbientLight("ambientLight") ambientLight.setColor((.8, .8, .8, 1)) directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection(LVector3(0, 45, -45)) directionalLight.setColor((0.2, 0.2, 0.2, 1)) render.setLight(render.attachNewNode(directionalLight)) render.setLight(render.attachNewNode(ambientLight))
def setupLights(self): # Sets up some default lighting ambientLight = AmbientLight("ambientLight") ambientLight.setColor((.4, .4, .35, 1)) directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection(LVector3(0, 8, -2.5)) directionalLight.setColor((0.9, 0.8, 0.9, 1)) render.setLight(render.attachNewNode(directionalLight)) render.setLight(render.attachNewNode(ambientLight))
def loadSimpleLighting(self): ambientLight = AmbientLight( "ambientLight" ) ambientLight.setColor( Vec4(.8, .8, .8, 1) ) directionalLight = DirectionalLight( "directionalLight" ) directionalLight.setDirection( Vec3( 0, 45, -45 ) ) directionalLight.setColor( Vec4( 0.2, 0.2, 0.2, 0.6 ) ) render.setLight(render.attachNewNode( directionalLight ) ) render.setLight(render.attachNewNode( ambientLight ) )
def __init__(self): base.win.setClearColor(Vec4(0, 0, 0, 1)) # Network Setup print "before" self.cManager = ConnectionManager(self) self.startConnection() print "after" # Set up the environment # self.environ = loader.loadModel("models/square") self.environ.reparentTo(render) self.environ.setPos(0, 0, 0) self.environ.setScale(100, 100, 1) self.moon_tex = loader.loadTexture("models/moon_1k_tex.jpg") self.environ.setTexture(self.moon_tex, 1) self.floater = NodePath(PandaNode("floater")) self.floater.reparentTo(render) # add spheres earth = Earth(self) sun = Sun(self) venus = Venus(self) controls = Control() chat = Chat(self) player = Ralph(self) # player = Panda(self) # player = Car(self) taskMgr.add(player.move, "moveTask") taskMgr.add(sun.rotatePlanets, "rotateSun", extraArgs=[self.player], appendTask=True) taskMgr.add(earth.rotatePlanets, "rotateEarth", extraArgs=[self.player], appendTask=True) taskMgr.add(venus.rotatePlanets, "rotateVenus", extraArgs=[self.player], appendTask=True) # Create some lighting ambientLight = AmbientLight("ambientLight") ambientLight.setColor(Vec4(.3, .3, .3, 1)) directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection(Vec3(-5, -5, -5)) directionalLight.setColor(Vec4(1, 1, 1, 1)) directionalLight.setSpecularColor(Vec4(1, 1, 1, 1)) render.setLight(render.attachNewNode(ambientLight)) render.setLight(render.attachNewNode(directionalLight))
def __init__(self): ShowBase.__init__(self) # Override defaults self.disableMouse() self.setBackgroundColor(VBase3(160, 200, 150) / 255.0) self.setFrameRateMeter(True) # Lights dlight = DirectionalLight("dlight") dlnp = self.render.attachNewNode(dlight) dlnp.setHpr(180.0, -70.0, 0) self.render.setLight(dlnp) alight = AmbientLight("alight") alnp = self.render.attachNewNode(alight) alight.setColor(VBase4(0.4, 0.4, 0.4, 1)) self.render.setLight(alnp) # Collision traverser self.cTrav = CollisionTraverser("collisionTraverser") #self.cTrav.showCollisions(self.render) # Collision handlers self.carCollisionHandler = CollisionHandlerEvent() self.carCollisionHandler.addInPattern("%fn-into-%in") # Camera controls self.cameraController = CameraController(self, 400, math.pi / 4.0, math.pi / 4.0) #self.cameraController = CameraController(self, 300, -math.pi, math.pi / 4.0) # Load the track #self.track = self.loader.loadModel("models/trackMotegi") self.track = self.loader.loadModel("models/trackValencia") checkpointsCollision = self.track.find("checkpoints").node() checkpointsCollision.setIntoCollideMask(BitMask32(0xF0)) self.numCheckpoints = checkpointsCollision.getNumSolids() self.track.reparentTo(self.render) # Load the car #self.car = KeyboardCar(self) self.car = NeuralNetworkCar(self) self.cameraController.follow(self.car.getNodePath()) #self.cameraController.setTarget(self.car.getNodePath()) # Reposition the car #self.car.getNodePath().setH(180.0) # Register car collisions with track self.cTrav.addCollider(self.car.carCollider, self.carCollisionHandler) self.accept("carCollider-into-trackCollision", self.car.onCrash) self.accept("carCollider-into-checkpoints", self.car.onCheckpoint) # State logger self.loggingActive = False self.log = [] self.accept("l", self.toggleStateLogger)
def setup_lights(self): ambientLight = AmbientLight('ambient') ambientLight.setColor(Vec4(.5, .5, .5, 1)) render.setLight(render.attachNewNode(ambientLight)) directionalLight = DirectionalLight('directional') directionalLight.setDirection(Vec3(-10, 10, -25)) directionalLight.setColor(Vec4(.1, .1, .1, 1)) render.setLight(render.attachNewNode(directionalLight))
def setupLights(self, direc=(0, 45, -45), point=(0,0,0), color=(0.2, 0.2, 0.2, 1)): # This function sets up some default lighting ambientLight = AmbientLight("ambientLight") ambientLight.setColor((.8, .8, .8, 1)) directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection(LVector3(direc)) directionalLight.setPoint(LVector3(point)) directionalLight.setColor(color) render.setLight(render.attachNewNode(directionalLight)) render.setLight(render.attachNewNode(ambientLight))
def __init__(self): base.disableMouse() base.cam.node().getLens().setNear(10.0) base.cam.node().getLens().setFar(9999999) camera.setPos(0, -50, 0) # Check video card capabilities. if (base.win.getGsg().getSupportsBasicShaders() == 0): addTitle("Toon Shader: Video driver reports that shaders are not supported.") return # Enable a 'light ramp' - this discretizes the lighting, # which is half of what makes a model look like a cartoon. # Light ramps only work if shader generation is enabled, # so we call 'setShaderAuto'. tempnode = NodePath(PandaNode("temp node")) tempnode.setAttrib(LightRampAttrib.makeSingleThreshold(0.5, 0.4)) tempnode.setShaderAuto() base.cam.node().setInitialState(tempnode.getState()) # Use class 'CommonFilters' to enable a cartoon inking filter. # This can fail if the video card is not powerful enough, if so, # display an error and exit. self.separation = 1 # Pixels self.filters = CommonFilters(base.win, base.cam) filterok = self.filters.setCartoonInk(separation=self.separation) if (filterok == False): addTitle("Toon Shader: Video card not powerful enough to do image postprocessing") return # Create a non-attenuating point light and an ambient light. plightnode = PointLight("point light") plightnode.setAttenuation(Vec3(1,0,0)) plight = render.attachNewNode(plightnode) plight.setPos(30,-50,0) alightnode = AmbientLight("ambient light") alightnode.setColor(Vec4(0.8,0.8,0.8,1)) alight = render.attachNewNode(alightnode) render.setLight(alight) render.setLight(plight) # Panda contains a built-in viewer that lets you view the # results of all render-to-texture operations. This lets you # see what class CommonFilters is doing behind the scenes. self.accept("v", base.bufferViewer.toggleEnable) self.accept("V", base.bufferViewer.toggleEnable) base.bufferViewer.setPosition("llcorner") self.accept("s", self.filters.manager.resizeBuffers) # These allow you to change cartooning parameters in realtime self.accept("escape", sys.exit, [0])
def setupLighting(self): alight = AmbientLight("AmbientLight") alight.setColor(AMBIENT_LIGHT) self.amblight = self.render.attachNewNode(alight) self.render.setLight(self.amblight) alight = AmbientLight("ShadelessLight") alight.setColor((1.0, 1.0, 1.0, 1.0)) self.shadeless = self.render.attachNewNode(alight)
def initLights(self): # Create some lighting #self.environ.ls() #print(self.environ.findAllMatches("**/Spot")) ambientLight = AmbientLight("ambientLight") ambientLight.setColor(Vec4(0.8, 0.8, 0.8, 0.65)) """ directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection(Vec3(-10, -10, 5)) directionalLight.showFrustum() directionalLight.setColor(Vec4(1, 1, 1, 1)) directionalLight.setSpecularColor(Vec4(1, 1, 1, 1)) dirnp = render.attachNewNode(directionalLight) dirnp.setPos(10, 0, 6) """ plight1 = PointLight('plight1') plight1.setColor(VBase4(1, 1, 1, 1)) plight1.showFrustum() #plight1.setShadowCaster(True) plnp1 = render.attachNewNode(plight1) plnp1.setPos(26.71, -33.2, 26) plight2 = PointLight('plight2') plight2.setColor(VBase4(1, 1, 1, 1)) plight2.showFrustum() plnp2 = render.attachNewNode(plight2) plnp2.setPos(-25, 25, 25) slight = Spotlight('slight') slight.setColor(VBase4(1, 1, 1, 1)) lens = PerspectiveLens() lens.setFilmSize(1, 1) # Or whatever is appropriate for your scene slight.setLens(lens) slight.setShadowCaster(True, 512, 512) slight.showFrustum() slnp = render.attachNewNode(slight) slnp.setPos(0, 0, 100) slnp.lookAt(Vec3(0,0,0)) render.setLight(slnp) render.setLight(plnp1) render.setLight(plnp2) #render.setLight(render.attachNewNode(ambientLight)) #render.setLight(dirnp) render.setShaderAuto() #render.setLight(render.attachNewNode(directionalLight)) """
def __init__(self, **kwargs): self.type = 'ambient' # ambient or directional for now self.color = color.rgb(0.3, 0.3, 0.3, 1) # a modest amount of full-spectrum light self.direction = Vec3( -1, -1, -1) # shining down from top-right corner, behind camera self.position = None self.attenuation = None self.node = None for key, value in kwargs.items(): if key == 'type': if value in ('ambient', 'directional', 'point'): self.type = value else: print("ERR Light type is not 'ambient' or 'directional'") elif key == 'color': self.color = value elif key == 'direction': self.direction = value elif key == 'attenuation': self.attenuation = value elif key == 'position': self.position = value else: print("Err ", key, " is not a valid keyword") scene.lights.append(self) # light added for all subsequent entities if self.type == 'ambient': ambientLight = AmbientLight('ambientLight') ambientLight.setColor(self.color) self.node = scene.attachNewNode(ambientLight) elif self.type == 'directional': directionalLight = DirectionalLight('directionalLight') directionalLight.setColor(self.color) self.node = scene.attachNewNode(directionalLight) # This light should be facing straight down, but clearly it isn't. self.node.setHpr( self.direction) # convert vector to Hpr (in degrees!?) first elif self.type == 'point': pointLight = PointLight('pointLight') pointLight.setColor(self.color) if self.attenuation is None: self.attenuation = Vec3(1, 0, 0) pointLight.setAttenuation(self.attenuation) if self.position is None: self.position = Vec3(0, 0, 0) self.node = scene.attachNewNode(pointLight) self.node.setPos(self.position)
def __init__(self): __builtin__.main = self self.taskMgr = taskMgr self.base = base # Connect to the server self.cManager = ConnectionManager() self.startConnection() self.characters = dict() self.cpList = dict() base.win.setClearColor(Vec4(0,0,0,1)) self.environ = loader.loadModel("models/world") self.environ.reparentTo(render) self.environ.setPos(0,0,0) self.ralphStartPos = self.environ.find("**/start_point").getPos() # Create a floater object. We use the "floater" as a temporary # variable in a variety of calculations. self.floater = NodePath(PandaNode("floater")) self.floater.reparentTo(render) self.accept("escape", sys.exit) # Login as 'CPHandler' # Temporary workaround, can add a seperate request/response for client/NPC client logins later self.name = "CPHandler" factionId = 0 self.cManager.sendRequest(Constants.CMSG_AUTH, [self.name, factionId]) # Create two control points cp1 = ControlPoint(1, -107.575, 0.6066, 0.490075, 10, RED) cp2 = ControlPoint(2, -100.575, -35.6066, 0.090075, 10, BLUE) self.cpList[1] = cp1 self.cpList[2] = cp2 taskMgr.doMethodLater(0.1, self.refresh, "heartbeat") taskMgr.doMethodLater(1, self.CPHandler, 'CPHandler') # Set up the camera base.disableMouse() #base.camera.setPos(self.character.actor.getX(),self.character.actor.getY()+10,2) # Create some lighting ambientLight = AmbientLight("ambientLight") ambientLight.setColor(Vec4(.3, .3, .3, 1)) directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection(Vec3(-5, -5, -5)) directionalLight.setColor(Vec4(1, 1, 1, 1)) directionalLight.setSpecularColor(Vec4(1, 1, 1, 1)) render.setLight(render.attachNewNode(ambientLight)) render.setLight(render.attachNewNode(directionalLight))
def create_ambient_light(self): """Creates an ambient light with a preset color :return: the node created for the light """ ambient_light = AmbientLight("ambient light") ambient_light.setColor(Vec4(0.2, 0.2, 0.2, 1)) node = self.render.attachNewNode(ambient_light) return node
def setup_lights(self): ambientLight = AmbientLight('ambient') ambientLight.setColor( Vec4( .5, .5, .5, 1 ) ) render.setLight(render.attachNewNode(ambientLight)) directionalLight = DirectionalLight('directional') directionalLight.setDirection( Vec3( -10, 10, -25 ) ) directionalLight.setColor( Vec4( .1, .1, .1, 1 ) ) render.setLight(render.attachNewNode(directionalLight))
def setupLights(self): ambientLight = AmbientLight("ambientLight") ambientLight.setColor(Vec4(.4, .4, .35, 1)) directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection(Vec3( 0, 8, -2.5 ) ) directionalLight.setColor(Vec4( 0.9, 0.8, 0.9, 1 ) ) #Set lighting on teapot so steam doesn't get affected self.t.setLight(self.t.attachNewNode(directionalLight)) self.t.setLight(self.t.attachNewNode(ambientLight))
def __init__(self): ShowBase.__init__(self) properties = WindowProperties() properties.setSize(1000, 750) self.win.requestProperties(properties) self.disableMouse() self.useTrackball() self.environment = loader.loadModel("models/island.bam") self.environment.reparentTo(render) self.camera.getChild(0).setPos(100, 100, 15) # Tilt the camera down by setting its pitch. self.camera.getChild(0).setHpr(135, 5, 0) #self.camera.getChild(0).lookAt(self.environment) print(self.camera.getChild(0).getHpr()) self.camera.reparentTo(render) ambientLight = AmbientLight("ambient light") ambientLight.setColor((.2, .2, .2, 1)) self.ambientLightNodePath = render.attachNewNode(ambientLight) render.setLight(self.ambientLightNodePath) # plight = PointLight('plight') # plight.setColor((0.5, 0.5, 0.5, 1)) # self.plnp = render.attachNewNode(plight) # self.plnp.setPos(0,0,3) # render.setLight(self.plnp) dlight = DirectionalLight('my dlight') self.dlnp = render.attachNewNode(dlight) self.dlnp.setHpr(45, -30, 0) self.dlnp.setColor((0.1, 0.1, 0.1, .1)) render.setLight(self.dlnp) # mainLight = DirectionalLight("main light") # self.mainLightNodePath = render.attachNewNode(mainLight) # # Turn it around by 45 degrees, and tilt it down by 45 degrees # self.mainLightNodePath.setHpr(45, -45, 0) # render.setLight(self.mainLightNodePath) """ this block finds all materials from blender andclear Base Color which is white, otherwise while rendering everything is black or white (with directional light) other type of lights seems OK though """ mats = self.environment.findAllMaterials() mats[0].clearBaseColor() mats[1].clearBaseColor() # mats[0].setDiffuse((0,1,0,1)) # mats[0].setAmbient((0,1,0,1)) #mats[0].setShininess(100) # mats[1].setDiffuse((0,0,1,.5)) # mats[1].setAmbient((0,0,1,.5)) mats[1].setShininess(10) render.setShaderAuto() print(mats[0])
def light(self): ambientLight = AmbientLight("ambientLight") ambientLight.setColor(Vec4(.3, .3, .3, 1)) directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection(Vec3(-5, -5, -5)) directionalLight.setColor(Vec4(1, 1, 1, 1)) directionalLight.setSpecularColor(Vec4(1, 1, 1, 1)) render.setLight(render.attachNewNode(ambientLight)) render.setLight(render.attachNewNode(directionalLight))
def setupLights(self): ambientLight = AmbientLight("ambientLight") ambientLight.setColor(Vec4(.4, .4, .35, 1)) directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection(Vec3( 0, 8, -2.5 ) ) directionalLight.setColor(Vec4( 0.9, 0.8, 0.9, 1 ) ) #Set lighting on teapot so spark doesn't get affected self.t.setLight(self.t.attachNewNode(directionalLight)) self.t.setLight(self.t.attachNewNode(ambientLight))
def __init__(self): ShowBase.__init__(self) properties = WindowProperties() properties.setSize(1000, 750) self.win.requestProperties(properties) self.textObject = OnscreenText(text='shape-boi', pos=(0.925, 0.925), scale=0.075) #self.thread = threading.Thread(target=self.udpConnect) #self.thread2 = threading.Thread(target=self.runColorTrack) #self.connectButton = DirectButton(text=('Open Connection'),pos=(-0.3,0,-0.98), scale=0.090, command=self.openConnection, frameColor=(255,255,255,0.15)) #self.trackButton = DirectButton(text=('Color Track'),pos=(-1,0,-0.98), scale=0.090, command=self.thread2.start,frameColor=(255,255,255,0.15),state=0) #loader.loadModel("Models/Misc/environment") self.environment = loader.loadModel("MorgansModels/mirroredwalltest.x") self.environment.reparentTo(render) self.environment.getChild(0).setPos(0, 50, -4) self.environment.getChild(0).setH(90) self.environment.getChild(0).setP(0) self.tempActor = Actor( "MorgansModels/shape-boi-grab-test-point_level2", { "walk": "MorgansModels/shape-boi-grab-test-point_level2-ArmatureAction", "lift": "MorgansModels/shape-boi-grab-test-point_level2-IcosphereAction" }) self.tempActor.reparentTo(render) self.tempActor.getChild(0).setH(180) self.tempActor.getChild(0).setPos(0, 54, -3) self.tempActor.getChild(0).setScale(0.5, 0.5, 0.5) self.tempActor.loop("walk") self.tempActor2 = Actor( "MorgansModels/shape-boi-grab-test", {"walk": "MorgansModels/shape-boi-grab-test-ArmatureAction"}) self.tempActor2.reparentTo(render) self.tempActor2.getChild(0).setH(180) self.tempActor2.getChild(0).setPos(1, 54, -3) self.tempActor2.getChild(0).setScale(0.5, 0.5, 0.5) self.tempActor2.loop("walk") ambientLight = AmbientLight("ambient light") ambientLight.setColor(Vec4(0.2, 0.2, 0.2, 1)) self.ambientLightNodePath = render.attachNewNode(ambientLight) render.setLight(self.ambientLightNodePath) # In the body of your code mainLight = DirectionalLight("main light") self.mainLightNodePath = render.attachNewNode(mainLight) # Turn it around by 45 degrees, and tilt it down by 45 degrees self.mainLightNodePath.setHpr(45, -45, 0) render.setLight(self.mainLightNodePath) render.setShaderAuto()
def __init__(self): ShowBase.__init__(self) properties = WindowProperties() properties.setSize(1000, 750) self.win.requestProperties(properties) self.disableMouse() self.environment = loader.loadModel( "models/misc/Environment/environment") self.environment.reparentTo(render) self.tempActor = Actor("models/panda", {"walk": "models/panda-walk"}) self.tempActor.reparentTo(render) self.tempActor.setPos(0, 7, 0) self.tempActor.setScale(0.05, 0.05, 0.05) self.tempActor.loop("walk") #camera control self.camera.setPos(0, 0, 32) self.camera.setP(-90) ambientLight = AmbientLight("ambient light") ambientLight.setColor(Vec4(0.2, 0.2, 0.2, 1)) self.ambientLightNodePath = render.attachNewNode(ambientLight) render.setLight(self.ambientLightNodePath) mainLight = DirectionalLight("main light") self.mainLightNodePath = render.attachNewNode(mainLight) # turn it 45 degrees, tilt down 45 degrees self.mainLightNodePath.setHpr(45, -45, 0) render.setLight(self.mainLightNodePath) render.setShaderAuto() self.keyMap = { "up": False, "down": False, "left": False, "right": False, "shoot": False } def updateKeyMap(self, controlName, controlState): self.keyMap[controlName] = controlState print(controlName, "set to", controlState) self.accept("w", self.updateKeyMap, ["up", True]) self.accept("w-up", self.updateKeyMap, ["up", False]) self.accept("s", self.updateKeyMap, ["down", True]) self.accept("s-up", self.updateKeyMap, ["down", False]) self.accept("a", self.updateKeyMap, ["left", True]) self.accept("a-up", self.updateKeyMap, ["left", False]) self.accept("d", self.updateKeyMap, ["right", True]) self.accept("d-up", self.updateKeyMap, ["right", False]) self.accept("mouse1", self.updateKeyMap, ["shoot", True]) self.accept("mouse1-up", self.updateKeyMap, ["shoot", False])
def __init__(self): __builtin__.main = self self.taskMgr = taskMgr self.base = base # Connect to the server self.cManager = ConnectionManager() self.startConnection() self.characters = dict() self.cpList = dict() base.win.setClearColor(Vec4(0, 0, 0, 1)) self.environ = loader.loadModel("models/world") self.environ.reparentTo(render) self.environ.setPos(0, 0, 0) self.ralphStartPos = self.environ.find("**/start_point").getPos() # Create a floater object. We use the "floater" as a temporary # variable in a variety of calculations. self.floater = NodePath(PandaNode("floater")) self.floater.reparentTo(render) self.accept("escape", sys.exit) # Login as 'CPHandler' # Temporary workaround, can add a seperate request/response for client/NPC client logins later self.name = "CPHandler" factionId = 0 self.cManager.sendRequest(Constants.CMSG_AUTH, [self.name, factionId]) # Create two control points cp1 = ControlPoint(1, -107.575, 0.6066, 0.490075, 10, RED) cp2 = ControlPoint(2, -100.575, -35.6066, 0.090075, 10, BLUE) self.cpList[1] = cp1 self.cpList[2] = cp2 taskMgr.doMethodLater(0.1, self.refresh, "heartbeat") taskMgr.doMethodLater(1, self.CPHandler, 'CPHandler') # Set up the camera base.disableMouse() #base.camera.setPos(self.character.actor.getX(),self.character.actor.getY()+10,2) # Create some lighting ambientLight = AmbientLight("ambientLight") ambientLight.setColor(Vec4(.3, .3, .3, 1)) directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection(Vec3(-5, -5, -5)) directionalLight.setColor(Vec4(1, 1, 1, 1)) directionalLight.setSpecularColor(Vec4(1, 1, 1, 1)) render.setLight(render.attachNewNode(ambientLight)) render.setLight(render.attachNewNode(directionalLight))
def setupLights(self): ambientLight = AmbientLight("ambientLight") ambientLight.setColor(Vec4(.4, .4, .35, 1)) directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection(Vec3(0, 8, -2.5)) directionalLight.setColor(Vec4(0.9, 0.8, 0.9, 1)) render.setLight(render.attachNewNode(directionalLight)) render.setLight(render.attachNewNode(directionalLight)) self.env.setLightOff()
def setupLights(self): #This is one area I know hardly anything about. I really don't know how to get this to behave nicely. #The black pieces are hardly distinguishable. ambientLight = AmbientLight( "ambientLight" ) ambientLight.setColor( Vec4(.8, .8, .8, 1) ) directionalLight = DirectionalLight( "directionalLight" ) directionalLight.setDirection( Vec3( 0, 45, -45 ) ) directionalLight.setColor( Vec4( 0.2, 0.2, 0.2, 1 ) ) render.setLight(render.attachNewNode( directionalLight ) ) render.setLight(render.attachNewNode( ambientLight ) )
def __init__(self, base): self.base = base alight = AmbientLight("ambient-light") alight.setColor(VBase4(0.2, 0.2, 0.2, 1)) alnp = base.render.attachNewNode(alight) base.render.setLight(alnp) dlight = DirectionalLight("direction-light") dlight.setColor(VBase4(0.8, 0.8, 0.5, 1)) dlnp = base.render.attachNewNode(dlight) base.render.setLight(dlnp)
def setupLights(self): ambiet = AmbientLight('ambient') ambiet.setColor((0.1, 0.1, 0.1, 1)) alight = render.attachNewNode(ambiet) render.setLight(alight) dlight = DirectionalLight('dlight') dlight.setColor((0.8, 0.8, 0.8, 1)) dlnp = render.attachNewNode(dlight) dlnp.setHpr(0, -45, 0) render.setLight(dlnp)
def __init__(self, aCol, dDir, dCol): render.setAttrib(LightRampAttrib.makeHdr1()) ambientLight = AmbientLight("ambientLight") ambientLight.setColor(aCol) directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection(dDir) directionalLight.setColor(dCol) directionalLight.setSpecularColor(Vec4(2.0, 2.0, 2.0, 0)) render.setLight(render.attachNewNode(ambientLight)) render.setLight(render.attachNewNode(directionalLight))
def makeLights(self): alight = AmbientLight('alight') alight.setColor(VBase4(0.2,0.2,0.2,1)) alnp = render.attachNewNode(alight) render.setLight(alnp) for pl in self.settings.pointlights: lamp = PointLight('player_light') lampnp = render.attachNewNode(lamp) lampnp.setPos(*pl) render.setLight(lampnp)
def __create_ambient_light(self, lightId, lightColor): ambientLight = AmbientLight(lightId) ambientLight.setColor(lightColor) ambientLightNP = NodePath(ambientLight) return ambientLightNP
def setLight(self, color=VBase4(1, 1, 1, 1)): """Sets an ambient and omnidirectional light for rendering Keyword Arguments: color {VBase4} -- color of the ambient light (default: {VBase4(1, 1, 1, 1)}) """ alight = AmbientLight('alight') alight.setColor(color) alnp = self.render.attachNewNode(alight) self.render.setLight(alnp)
def setupLights(self): ambientLight = AmbientLight("ambientLight") ambientLight.setColor(Vec4(0.4, 0.4, 0.35, 1)) directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection(Vec3(0, 8, -2.5)) directionalLight.setColor(Vec4(0.9, 0.8, 0.9, 1)) render.setLight(render.attachNewNode(directionalLight)) render.setLight(render.attachNewNode(directionalLight)) self.env.setLightOff()
def __init__(self, game): self.game = game background_music = loader.loadMusic( "resources/music/background_theme.ogg") background_music.setLoop(True) # I find this piece to be pretty loud, so I've turned the volume down a lot. background_music.setVolume(0.5) background_music.play() main_light = DirectionalLight("main light") self.main_light_node_path = render.attachNewNode(main_light) self.main_light_node_path.setHpr(45, -45, 0) render.setLight(self.main_light_node_path) ambient_light = AmbientLight("ambient light") ambient_light.setColor(Vec4(0.2, 0.2, 0.2, 1)) self.ambient_light_node_path = render.attachNewNode(ambient_light) render.setLight(self.ambient_light_node_path) render.setShaderAuto() # Load the environment model. self.scene = loader.loadModel("models/environment") # Reparent the model to render. self.scene.reparentTo(render) # Apply scale and position transforms on the model. self.scene.setScale(0.15, 0.15, 0.15) self.scene.setPos(10, 60, 0) # self.environment = loader.loadModel("Misc/environment") # self.environment.reparentTo(render) self.walking_enemies = [] self.deadEnemies = [] self.foods = [] # Set up some monster spawn points self.spawn_time = 1 self.spawn_timer = 1 self.maximum_walking_enemies = 2 self.spawn_points = [] number_points_per_wall = 5 for i in range(number_points_per_wall): coord = 7.0 / number_points_per_wall + 0.5 self.spawn_points.append(Vec3(-7.0, coord, 0)) self.spawn_points.append(Vec3(7.0, coord, 0)) self.spawn_points.append(Vec3(coord, -7.0, 0)) self.spawn_points.append(Vec3(coord, 7.0, 0)) self.generate_walls() self.spawn_food(Vec3(2.0, -7.0, 2.0)) self.spawn_food(Vec3(3.0, -3.0, 3.0)) self.spawn_food(Vec3(-5.0, -4.0, 7.0))
def __init__(self): base.setBackgroundColor(0.1, 0.1, 0.8, 1) base.setFrameRateMeter(True) # Light alight = AmbientLight('ambientLight') alight.setColor(Vec4(0.5, 0.5, 0.5, 1)) alightNP = render.attachNewNode(alight) dlight = DirectionalLight('directionalLight') dlight.setDirection(Vec3(1, 1, -1)) dlight.setColor(Vec4(0.7, 0.7, 0.7, 1)) dlightNP = render.attachNewNode(dlight) render.clearLight() render.setLight(alightNP) render.setLight(dlightNP) # Input self.accept('escape', self.doExit) self.accept('r', self.doReset) self.accept('f1', self.toggleWireframe) self.accept('f2', self.toggleTexture) self.accept('f3', self.toggleDebug) self.accept('f5', self.doScreenshot) # ROS self.crash_pub = rospy.Publisher('crash', std_msgs.msg.Empty, queue_size=100) ### subscribers (info sent to Arduino) self.cmd_steer_sub = rospy.Subscriber( 'cmd/steer', std_msgs.msg.Float32, callback=self._cmd_steer_callback) self.cmd_motor_sub = rospy.Subscriber( 'cmd/motor', std_msgs.msg.Float32, callback=self._cmd_motor_callback) self.cmd_vel_sub = rospy.Subscriber('cmd/vel', std_msgs.msg.Float32, callback=self._cmd_vel_callback) self.reset_sub = rospy.Subscriber('reset', std_msgs.msg.Empty, callback=self._reset_callback) self.cmd_steer_queue = Queue.Queue(maxsize=1) self.cmd_motor_queue = Queue.Queue(maxsize=1) # Task taskMgr.add(self.update, 'updateWorld') # Physics self.setup() print('Starting ROS thread') threading.Thread(target=self._ros_servos_thread).start() threading.Thread(target=self._ros_crash_thread).start() threading.Thread(target=self._ros_image_thread).start()
def createEnvironment(self): # Fog to hide a performance tweak exp_fog = Fog("scene-wide-fog") exp_fog.setColor(1, 0.8, 0.8) exp_fog.setExpDensity(0.002) render.setFog(exp_fog) # base.setBackgroundColor(*colour) # Sky Dome ''' sky_dome = loader.loadModel("models/sky") # sky_sphere.egg by default sky_dome.setEffect(CompassEffect.make(self.render)) sky_dome.setScale(self.max_distance / 2) sky_dome.setZ(-65) # sink it # NOT render - you'll fly through the sky! sky_dome.reparentTo(self.camera) ''' # Sky Sphere sky_sphere = self.loader.loadModel("models/sky_sphere") sky_sphere.setEffect(CompassEffect.make(self.render)) sky_sphere.setScale(0.08) sky_sphere.reparentTo(self.camera) # Lighting ambient_light = AmbientLight("ambientLight") ambient_colour = Vec4(0.6, 0.6, 0.6, 1) ambient_light.setColor(ambient_colour) self.render.setLight(self.render.attachNewNode(ambient_light)) directional_light = DirectionalLight("directionalLight") # direction = Vec3(0, -10, -10) # directional_light.setDirection(direction) directional_colour = Vec4(0.8, 0.8, 0.5, 1) directional_light.setColor(directional_colour) # directional_specular = Vec4(1, 1, 1, 1) # directional_light.setSpecularColor(directional_specular) dir_light_np = self.render.attachNewNode(directional_light) dir_light_np.setPos(0, 0, 260) dir_light_np.lookAt(self.player) self.render.setLight(dir_light_np) # Water self.water = self.loader.loadModel("models/square") self.water.setSx(self.world_size*2) self.water.setSy(self.world_size*2) self.water.setPos(self.world_size/2, self.world_size/2, 25) # z is sea level self.water.setTransparency(TransparencyAttrib.MAlpha) newTS = TextureStage("1") self.water.setTexture(newTS, self.loader.loadTexture("models/water.png")) self.water.setTexScale(newTS, 4) self.water.reparentTo(self.render) LerpTexOffsetInterval(self.water, 200, (1,0), (0,0), textureStage=newTS).loop()
def init(self): # window setup base.win.setClearColor(Vec4(0, 0, 0, 1)) # display instructions addTitle("CS454 HW2") addInstructions(0.95, "[ESC]: Quit") addInstructions(0.90, "[Mouse Move]: Move camera") addInstructions(0.85, "[Mouse Wheel]: Zoom camera") addInstructions(0.80, "[W,A,S,D]: Move character") addInstructions(0.75, "[T]: Open chat box") addInstructions(0.70, "[Y]: Open whisper box") addInstructions(0.65, "[Up,Down]: Select whisper target") addInstructions(0.60, "[Tab]: Show players") # create environment environ = loader.loadModel("models/square") environ.reparentTo(render) environ.setPos(0, 0, 0) environ.setScale(100, 100, 1) environ.setTexture(loader.loadTexture("models/moon_1k_tex.jpg"), 1) # create lighting ambientLight = AmbientLight("ambientLight") ambientLight.setColor(Vec4(0.3, 0.3, 0.3, 1)) render.setLight(render.attachNewNode(ambientLight)) directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection(Vec3(-5, -5, -5)) directionalLight.setColor(Vec4(1, 1, 1, 1)) directionalLight.setSpecularColor(Vec4(1, 1, 1, 1)) render.setLight(render.attachNewNode(directionalLight)) # accept special keys base.accept("escape", self.exit) base.accept("shift-escape", self.exit) # create spheres sun = Sphere(self, "sun") sun.model.setPos(-15, -15, 8) earth = Sphere(self, "earth") earth.model.setPos(-12, 12, 5) venus = Sphere(self, "venus") venus.model.setPos(10, 10, 3.5) # track game entities self.character = None self.player = None self.camera = None self.characters = {} self.chat = Chat(self) self.playerList = PlayerList(self)
def lights(self): ambientLight = AmbientLight("ambient light") ambientLight.setColor(Vec4(0.2, 0.2, 0.2, 1)) self.ambientLightNodePath = render.attachNewNode(ambientLight) render.setLight(self.ambientLightNodePath) mainLight = DirectionalLight("main light") self.mainLightNodePath = render.attachNewNode(mainLight) # Turn it around by 45 degrees, and tilt it down by 45 degrees self.mainLightNodePath.setHpr(45, -45, 0) render.setLight(self.mainLightNodePath)
class HAmbientLight(NodePath): def __init__(self, name, level, color=(1, 1, 1, 1), affectAll=True): self.name = name self.level = level self.lamp = AmbientLight(name) NodePath.__init__(self, self.lamp) #self.attachNewNode(self.lamp) self.lamp.setColor(VBase4(color[0], color[1], color[2], color[3])) if affectAll: self.level.Base.render.setLight(self) self.reparentTo(self.level.Base.render)
def __init__(self, player): super().__init__() self.player = player # Set up the game UI if isinstance(self.player, templars.Templar): base.guiScene = templarHud.TemplarHud(base.gameState) elif isinstance(self.player, mariners.Mariner): base.guiScene = marinerHud.MarinerHud(base.gameState) elif isinstance(self.player, thieves.Thief): base.guiScene = thiefHud.ThiefHud(base.gameState) elif isinstance(self.player, fae.Faerie): base.guiScene = faerieHud.FaerieHud(base.gameState) else: base.guiScene = hud.game.GameHud(self.gameState) self.base_model = base.loader.loadModel('env.bam', noCache=True) self.base_model.reparentTo(base.render) # So it looks like there's an object called <BlenderRoot> # that gets loaded when you pull in a .blend file. # We need to search for the actual nodes we want in <BlenderRoot> self.model = self.base_model.find('<BlenderRoot>') base.camera.setPosHpr(self.model.find('Camera'), 0, 0, 0, 0, -90, 0) base.disableMouse() # Fixes all your camera woes self.hept = self.model.find('Plane') self.hept.setTransparency(True) base.taskMgr.add(self.rotateTask, 'RotateHeptTask') # Convert the blender point light to a panda one #blenderLight = self.model.find('Point Light') #pandaLight = PointLight('Point Light') #pandaLight.setColor(VBase4(1, 1, 1, 1)) #lightNode = blenderLight.attachNewNode(pandaLight) #base.render.setLight(lightNode) # Ambient lighting so we can easily see cards alight = AmbientLight('alight') alight.setColor(VBase4(0.5, 0.5, 0.5, 1)) alnp = base.render.attachNewNode(alight) base.render.setLight(alnp) spawn = self.model.find('Spawn') self.zoneMaker = ZoneMaker( self.player, self.model, playerHand=spawn.find('Player Hand'), enemyHand=spawn.find('Enemy Hand'), playerBoard=spawn.find('Player Board'), enemyBoard=spawn.find('Enemy Board'), playerFace=spawn.find('Player Face'), enemyFace=spawn.find('Enemy Face'), playerGraveyard=spawn.find('Player Graveyard'), enemyGraveyard=spawn.find('Enemy Graveyard'))
def startSuitEffect(self): self.stopSuitEffect() light = AmbientLight("suitLight") light.setColor(Vec4(*self.suitLightColor)) self.suitLight = render.attachNewNode(light) render.setLight(self.suitLight) self.suitFog = Fog("suitFog") self.suitFog.setColor(*self.suitFogData[0]) self.suitFog.setExpDensity(self.suitFogData[1]) render.setFog(self.suitFog) self.createSpookySky() Hood.startSky(self)
def setupLight(self): primeL = DirectionalLight("prime") primeL.setColor(VBase4(.9, .9, .9, 1)) self.light = render.attachNewNode(primeL) self.light.setHpr(45, -60, 0) render.setLight(self.light) ambL = AmbientLight("amb") ambL.setColor(VBase4(.2, .2, .2, 1)) self.ambLight = render.attachNewNode(ambL) render.setLight(self.ambLight) return
def __init__(self): ShowBase.__init__(self) self.disableMouse() properties = WindowProperties() properties.setSize(1000, 750) self.win.requestProperties(properties) mainLight = DirectionalLight("main light") self.mainLightNodePath = render.attachNewNode(mainLight) self.mainLightNodePath.setHpr(45, -45, 0) render.setLight(self.mainLightNodePath) ambientLight = AmbientLight("ambient light") ambientLight.setColor(Vec4(0.2, 0.2, 0.2, 1)) self.ambientLightNodePath = render.attachNewNode(ambientLight) render.setLight(self.ambientLightNodePath) render.setShaderAuto() self.environment = loader.loadModel("Models/Misc/environment") self.environment.reparentTo(render) self.tempActor = Actor("Models/PandaChan/act_p3d_chan", {"walk": "Models/PandaChan/a_p3d_chan_run"}) self.tempActor.getChild(0).setH(180) self.tempActor.reparentTo(render) self.tempActor.loop("walk") self.camera.setPos(0, 0, 32) self.camera.setP(-90) self.keyMap = { "up": False, "down": False, "left": False, "right": False, "shoot": False } self.accept("w", self.updateKeyMap, ["up", True]) self.accept("w-up", self.updateKeyMap, ["up", False]) self.accept("s", self.updateKeyMap, ["down", True]) self.accept("s-up", self.updateKeyMap, ["down", False]) self.accept("a", self.updateKeyMap, ["left", True]) self.accept("a-up", self.updateKeyMap, ["left", False]) self.accept("d", self.updateKeyMap, ["right", True]) self.accept("d-up", self.updateKeyMap, ["right", False]) self.accept("mouse1", self.updateKeyMap, ["shoot", True]) self.accept("mouse1-up", self.updateKeyMap, ["shoot", False]) self.updateTask = taskMgr.add(self.update, "update")
class Game(ShowBase): def __init__(self): ShowBase.__init__(self) self.setBackgroundColor(0.2, 0.2, 0.2) self.accept("escape", self.taskMgr.stop) #self.accept("mouse1", self.onClick) #self.accept("mouse2", self.onClick2) self.globalClock = ClockObject() self.addLight() self.liner = LineDrawer(self) self.taskMgr.add(self.update, "update") def update(self, task): self.globalClock.tick() t = self.globalClock.getFrameTime() #print t dt = self.globalClock.getDt() return task.cont def addLight(self): self.render.clearLight() self.lightCenter = self.render.attachNewNode(PandaNode("center")) #self.lightCenter.setCompass() # ambient light self.ambientLight = AmbientLight('ambientLight') self.ambientLight.setColor(Vec4(0.5, 0.5, 0.5, 1)) self.alight = self.lightCenter.attachNewNode(self.ambientLight) self.render.setLight(self.alight) # point light self.pointlight = PointLight("pLight") self.light = self.lightCenter.attachNewNode(self.pointlight) self.pointlight.setColor(Vec4(0.8, 0.8, 0.8, 1)) self.light.setPos(0, 0, 2) self.render.setLight(self.light) # directional light self.dirlight = DirectionalLight("dLight") self.dlight = self.lightCenter.attachNewNode(self.dirlight) self.dirlight.setColor(Vec4(0.8, 0.8, 0.8, 1)) self.dirlight.setShadowCaster(True) self.dlight.setPos(0, 0, 5) self.dlight.lookAt(5, 10, 0) self.render.setLight(self.dlight) self.render.setShaderAuto()
def __init__(self): self.root = render.attachNewNode("Root") base.setBackgroundColor(0, 0, 0) # This code puts the standard title and instruction text on screen self.title = OnscreenText(text="Ball In Maze", style=1, fg=(1, 1, 0, 1), pos=(0.7, -0.95), scale=.07) self.instructions = OnscreenText(text="Press Esc to exit", pos=(-1.3, .95), fg=(1, 1, 0, 1), align=TextNode.ALeft, scale=.05) self.central_msg = OnscreenText(text="", pos=(0, 0), fg=(1, 1, 0, 1), scale=.1) self.central_msg.hide() self.accept("escape", sys.exit) # Escape quits base.disableMouse() # Disable mouse-based camera control camera.setPosHpr(0, 0, 25, 0, -90, 0) # Place the camera # Load the maze and place it in the scene self.maze = loader.loadModel("models/maze") self.maze.reparentTo(render) # Load the ball and attach it to the scene # It is on a root dummy node so that we can rotate the ball itself without # rotating the ray that will be attached to it self.ballRoot = render.attachNewNode("ballRoot") self.ball = loader.loadModel("models/ball") self.ball.reparentTo(self.ballRoot) # This section deals with lighting for the ball. Only the ball was lit # because the maze has static lighting pregenerated by the modeler ambientLight = AmbientLight("ambientLight") ambientLight.setColor(Vec4(.55, .55, .55, 1)) directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection(Vec3(0, 0, -1)) directionalLight.setColor(Vec4(0.375, 0.375, 0.375, 1)) directionalLight.setSpecularColor(Vec4(1, 1, 1, 1)) self.ballRoot.setLight(render.attachNewNode(ambientLight)) self.ballRoot.setLight(render.attachNewNode(directionalLight)) # This section deals with adding a specular highlight to the ball to make # it look shiny m = Material() m.setSpecular(Vec4(1, 1, 1, 1)) m.setShininess(96) self.ball.setMaterial(m, 1)