class DistanceFog(ColoredByTime): def __init__(self): self.exponential() render.attachNewNode(self.fog) render.setFog(self.fog) #self.dayColor = Vec4(0.73, 0.82, 0.90, 1.0) #self.dayColor = Vec4(0.57, 0.75, 0.94, 1.0) self.dayColor = Vec4(0.58, 0.66, 0.82, 1) self.nightColor = Vec4(-0.5, -0.3, .0, 1.0) self.sunsetColor = Vec4(0.75, .60, .65, 1.0) ColoredByTime.__init__(self) self.setColor = self.fog.setColor self.getColor = self.fog.getColor def setTime(self, time): self.colorize(time) def linear(self): self.fog = Fog("A linear-mode Fog node") self.fog.setLinearRange(0, 320) self.fog.setLinearFallback(5, 20, 50) def exponential(self): self.fog = Fog("Scene-wide exponential Fog object") density = 1.38629436 / (MAX_VIEW_RANGE + 30) self.fog.setExpDensity(density)
def __init__(self): # Make some nice fog colour = (0.3, 0.3, 0.3) linfog = Fog("A linear-mode Fog node") linfog.setColor(*colour) linfog.setLinearRange(0, 320) linfog.setLinearFallback(45, 160, 320) # Catchables positions catchables = [] for i in xrange(100): pos = (i * 10 + 10, 0, 2) catchables.append(pos) # Rocks positions and such rocks = [] rock1 = (0, 50, 0, 10) rocks.append(rock1) self.fog = linfog self.bgcolor = colour self.scale = (1, 1, 1) self.map = "worlds/maps/normalmap" self.catchables = catchables self.rocks = rocks
class environmentClass: def __init__( self, cameraPos, heightfield ): self.cameraPos = cameraPos self.heightfield = heightfield if USELIGHT: self.setupLight() if USESKY: self.setupSky() if USEFOG: self.setupFog() if USESOUND: self.setupSound() if USERAIN: self.setupRain() #taskMgr.doMethodLater(DAYNIGHTCYCLETIME/60.0, self.dayNightCycle, 'UpdateDayNight') taskMgr.doMethodLater(0.1, self.dayNightCycle, 'UpdateDayNight') taskMgr.doMethodLater(0.1, self.updateScene, 'updateScene' ) def setupSound( self ): self.mySound1 = loader.loadSfx("data/sounds/rainshower.wav") self.mySound1.setLoop(True) self.mySound1.play() def setupSky( self ): self.skyNP = loader.loadModel( 'data/models/sky.bam.pz' ) self.skyNP.reparentTo( render ) self.skyNP.setScale( 4000, 4000, 1000 ) self.skyNP.setPos( 0, 0, 0 ) self.skyNP.setTexture( loader.loadTexture( 'data/textures/clouds.png' ) ) self.skyNP.setShader( loader.loadShader( 'data/sky.sha' ) ) '''self.skyFogNP = loader.loadModel( 'data/models/sphere.egg' ) self.skyFogNP.reparentTo( base.camera ) self.skyFogNP.setTwoSided( True ) self.skyFogNP.setScale( 10 ) self.skyFogNP.setPos( Vec3(0,0,4) ) self.skyFogNP.setTransparent( True )''' sky = Vec4( 0.25, 0.5, 1.0, 0.0 ) # r, g, b, skip sky2 = Vec4( 1.0, 1.0, 1.0, 0.0 ) clouds = Vec4( 0.004, 0.002, 0.008, 0.010 ) # vx, vy, vx, vy self.skyNP.setShaderInput( 'sky', sky ) self.skyNP.setShaderInput( 'sky2', sky2 ) self.skyNP.setShaderInput( 'clouds', clouds ) render.setShaderInput( 'time', 0 ) def setupLight( self ): #Default lightAttrib with no lights #self.lightAttrib = LightAttrib.makeAllOff() # First we create an ambient light. All objects are affected by ambient # light equally #Create and name the ambient light self.ambientLight = AmbientLight( "ambientLight" ) #Set the color of the ambient light self.ambientLight.setColor( Vec4( .1, .1, .1, 1 ) ) self.alnp = render.attachNewNode(self.ambientLight) render.setLight(self.alnp) self.heightfield.mHeightFieldNode.setLightOff() self.ambientLight2 = AmbientLight( "ambientLight2" ) #Set the color of the ambient light self.ambientLight2.setColor( Vec4( .1, .1, .1, 1 ) ) self.al2np = render.attachNewNode(self.ambientLight2) self.heightfield.mHeightFieldNode.setLight(self.al2np) self.dlight = DirectionalLight('dlight') self.dlight.setColor(VBase4(1.0, 1.0, 0.6, 1)) self.dlnp = render.attachNewNode(self.dlight.upcastToPandaNode()) self.dlnp.setHpr(-90, -30, 0) self.heightfield.mHeightFieldNode.setLight(self.dlnp) # Now we create a spotlight. Spotlights light objects in a given cone # They are good for simulating things like flashlights self.spotlight = Spotlight( "spotlight" ) self.spotlight.setColor( Vec4( .9, .9, .9, 1 ) ) #The cone of a spotlight is controlled by it's lens. This creates the lens self.spotlight.setLens( PerspectiveLens() ) #This sets the Field of View (fov) of the lens, in degrees for width and #height. The lower the numbers, the tighter the spotlight. self.spotlight.getLens().setFov( 30, 30 ) # Attenuation controls how the light fades with distance. The numbers are # The three values represent the three constants (constant, linear, and # quadratic) in the internal lighting equation. The higher the numbers the # shorter the light goes. self.spotlight.setAttenuation( Vec3( 0.0, 0.0075, 0.0 ) ) # This exponent value sets how soft the edge of the spotlight is. 0 means a # hard edge. 128 means a very soft edge. self.spotlight.setExponent( 60.0 ) # Unlike our previous lights, the spotlight needs a position in the world # We are attaching it to the camera so that it will appear is if we are # holding a flashlight, but it can be attached to any NodePath # # When attaching a spotlight to a NodePath, you must use the # upcastToLensNode function or Panda will crash #camera.attachNewNode( self.spotlight.upcastToLensNode() ) self.spnp = camera.attachNewNode( self.spotlight.upcastToLensNode() ) render.setLight(self.spnp) self.heightfield.mHeightFieldNode.setLight(self.spnp) #self.lightAttrib = self.lightAttrib.addLight( self.spotlight ) #Finally we set the light attrib to a node. In this case we are using render #so that the lights will effect everything, but you could put it on any #part of the scene #render.node().setAttrib( self.lightAttrib ) # Create and start interval to spin the lights, and a variable to # manage them. #self.pointLightsSpin = self.pointLightHelper.hprInterval(6, Vec3(360, 0, 0)) #self.pointLightsSpin.loop() def setupFog( self ): '''defaultExpFogColor = (0.33, 0.5, 1.0) self.expFog = Fog("exponentialFog") self.expFog.setColor(*defaultExpFogColor) self.expFog.setExpDensity(DEFAULTFOG) render.setFog(self.expFog)''' defaultLinFogColor = (0.33, 0.5, 1.0) self.linFog = Fog("linearFog") self.linFog.setColor(*defaultLinFogColor) self.linFog.setLinearRange(0, linFogMinRange + linFogVarianceRange) self.linFog.setLinearFallback(30, 60, 240) base.camera.attachNewNode(self.linFog) render.setFog(self.linFog) base.setBackgroundColor( defaultLinFogColor ) def setupRain( self ): base.enableParticles() self.rain = rainClass() self.rain.reparentTo( base.camera ) #self.rain.setPos( 0, 0, 5 ) self.rain.setScale( 200 ) #self.rain.particle.setPoolSize( 8192 ) #self.rain.particle.setBirthRate( 2.000 ) #self.rain.particle.renderer.setHeadColor(Vec4(1.00, 1.00, 1.00, 0.8)) #self.rain.particle.renderer.setTailColor(Vec4(1.00, 1.00, 1.00, 0.2)) self.rain.start( render ) def dayNightCycle( self, task ): #print "dayNight", rainStrenght if USERAIN: rainStrenght = (RAINCYCLEFUNC**((math.sin(time.time()/(DAYNIGHTCYCLETIME/24.))+1.0)/2.0)-1.0)/(RAINCYCLEFUNC-1.0) self.rain.particle.setBirthRate( max( rainStrenght, 0.01 ) ) sunPos = time.time()/(DAYNIGHTCYCLETIME/(math.pi*2))%(math.pi*2) dayNight = (math.sin(sunPos)+1.0)/2.0 dayNight = (DAYNIGHTCYCLEFUNC**dayNight-1.0)/(DAYNIGHTCYCLEFUNC-1.0) if USELIGHT: #print dayNight c = (dayNight)/1.2 + 0.01 #print dayNight, c [commented by Finn] aLightCol = Vec4( c, c, c, 1 ) self.ambientLight.setColor( aLightCol ) if abs(sunPos/math.pi-1) < 0.5: self.dlnp.setHpr(-90, 180 + (dayNight-0.3) * 108, 0) else: self.dlnp.setHpr(-90, 0 - (dayNight-0.3) * 108, 0) # Time for clouds shader if USESKY: render.setShaderInput( 'time', task.time/4.0 ) #dayNight = 1.0 # color for clouds & fog #dayNight = ( math.sin(time.time()/DAYNIGHTCYCLETIME) + 1.0 ) / 2.0 # 0.0 for night, 1.0 for day sky = Vec4( dayNight/4.0, dayNight/2.0, dayNight, 0.0 ) # r, g, b, skip sky2 = Vec4( dayNight, dayNight, dayNight, 0.0 ) # set colors self.skyNP.setShaderInput( 'sky', sky ) self.skyNP.setShaderInput( 'sky2', sky2 ) if USEFOG: #expFogColor = dayNight/3.0,dayNight/2.0,dayNight #self.expFog.setColor( *expFogColor ) #self.expFog.setExpDensity(DEFAULTFOG*(NIGHTFOGMULTIPLIER-dayNight*(NIGHTFOGMULTIPLIER-1.0))) linFogColor = dayNight/3.0,dayNight/2.0,dayNight self.linFog.setColor( *linFogColor ) fogRange = linFogMinRange + linFogVarianceRange*dayNight self.linFog.setLinearRange( fogRange/4., fogRange ) self.linFog.setLinearFallback(fogRange/8., fogRange/4., fogRange) base.setBackgroundColor( linFogColor ) return Task.again def updateScene( self, task ): # set position of the particle system if USERAIN: self.rain.setPos( base.camera.getPos() + Vec3( 0,0,200) ) return Task.cont
class Environment: def __init__(self): self.cameraPos = base.camera.getPos() # create a heightfield self.heightfield = heightfield.Heightfield(base.camera) if USELIGHT: self.setupLight() if USESKY: self.setupSky() if USEFOG: self.setupFog() if USESOUND: self.setupSound() if USERAIN: from src.rain import rainClass self.setupRain() if USENIGHT: self.setupNight() def setupLight(self): self.ambientLight = AmbientLight("ambientLight") self.ambientLight.setColor(Vec4(0.1, 0.1, 0.1, 1)) self.ambientLightNP = render.attachNewNode(self.ambientLight.upcastToPandaNode()) render.setLight(self.ambientLightNP) self.dlight = DirectionalLight("dlight") self.dlight.setColor(VBase4(0.8, 0.8, 0.5, 1)) self.dlnp = render.attachNewNode(self.dlight.upcastToPandaNode()) self.dlnp.setHpr(0, -30, 0) render.setLight(self.dlnp) """ # First we create an ambient light. All objects are affected by ambient # light equally #Create and name the ambient light self.ambientLight = AmbientLight( "ambientLight" ) #Set the color of the ambient light self.ambientLight.setColor( VBase4( 0.1, 0.1, 0.1, 1 ) ) #Make the light affect render (ie everything) render.setLight(render.attachNewNode(self.ambientLight.upcastToPandaNode())) """ def setupSky(self): self.skyNP = loader.loadModel("data/models/sky.bam.pz") self.skyNP.reparentTo(render) self.skyNP.setScale(4000, 4000, 1000) self.skyNP.setPos(0, 0, 0) self.skyNP.setTexture(loader.loadTexture("data/textures/clouds.png")) self.skyNP.setShader(loader.loadShader("data/sky.sha")) """self.skyFogNP = loader.loadModel( 'data/models/sphere.egg' ) self.skyFogNP.reparentTo( base.camera ) self.skyFogNP.setTwoSided( True ) self.skyFogNP.setScale( 10 ) self.skyFogNP.setPos( Vec3(0,0,4) ) self.skyFogNP.setTransparent( True )""" sky = Vec4(0.25, 0.5, 1.0, 0.0) # r, g, b, skip sky2 = Vec4(1.0, 1.0, 1.0, 0.0) clouds = Vec4(0.004, 0.002, 0.008, 0.010) # vx, vy, vx, vy self.skyNP.setShaderInput("sky", sky) self.skyNP.setShaderInput("sky2", sky2) self.skyNP.setShaderInput("clouds", clouds) render.setShaderInput("time", 0) def setupFog(self): """defaultExpFogColor = (0.33, 0.5, 1.0) self.expFog = Fog("exponentialFog") self.expFog.setColor(*defaultExpFogColor) self.expFog.setExpDensity(DEFAULTFOG) render.setFog(self.expFog)""" defaultLinFogColor = (0.165, 0.25, 0.5) self.linFog = Fog("linearFog") self.linFog.setColor(*defaultLinFogColor) self.linFog.setLinearRange(0, linFogMinRange + linFogVarianceRange) self.linFog.setLinearFallback(30, 60, 240) base.camera.attachNewNode(self.linFog) render.setFog(self.linFog) base.setBackgroundColor(defaultLinFogColor) def setupSound(self): self.mySound1 = loader.loadSfx("data/sounds/rainshower.wav") self.mySound1.setLoop(True) self.mySound1.play() def setupRain(self): base.enableParticles() self.rain = rainClass() self.rain.reparentTo(base.camera) self.rain.setScale(200) self.rain.start(render) def setupNight(self): taskMgr.doMethodLater(0.05, self.dayNightCycle, "UpdateDayNight") taskMgr.doMethodLater(0.05, self.updateScene, "updateScene") def dayNightCycle(self, task): # print "dayNight", rainStrenght if USERAIN: rainStrenght = ( RAINCYCLEFUNC ** ((math.sin(time.time() / (DAYNIGHTCYCLETIME / 24.0)) + 1.0) / 2.0) - 1.0 ) / (RAINCYCLEFUNC - 1.0) self.rain.particle.setBirthRate(max(rainStrenght, 0.01)) sunPos = time.time() / (DAYNIGHTCYCLETIME / (math.pi * 2)) % (math.pi * 2) dayNight = (math.sin(sunPos) + 1.0) / 2.0 # dayNight = (DAYNIGHTCYCLEFUNC**dayNight-1.0)/(DAYNIGHTCYCLEFUNC-1.0) if USELIGHT: # print dayNight c = (dayNight) / 1.5 + 0.1 # print dayNight, c [commented by Finn] aLightCol = Vec4(c, c, c, 1) # self.ambientLight.setColor( aLightCol ) self.dlnp.setHpr(0, (sunPos / (2 * math.pi) - 0.5) * 360, 0) # Time for clouds shader if USESKY: render.setShaderInput("time", task.time / 4.0) # dayNight = 1.0 # color for clouds & fog # dayNight = ( math.sin(time.time()/DAYNIGHTCYCLETIME) + 1.0 ) / 2.0 # 0.0 for night, 1.0 for day sky = Vec4(dayNight / 4.0, dayNight / 2.0, dayNight, 0.0) # r, g, b, skip sky2 = Vec4(dayNight, dayNight, dayNight, 0.0) # set colors self.skyNP.setShaderInput("sky", sky) self.skyNP.setShaderInput("sky2", sky2) if USEFOG: # expFogColor = dayNight/3.0,dayNight/2.0,dayNight # self.expFog.setColor( *expFogColor ) # self.expFog.setExpDensity(DEFAULTFOG*(NIGHTFOGMULTIPLIER-dayNight*(NIGHTFOGMULTIPLIER-1.0))) linFogColor = dayNight / 3.0, dayNight / 2.0, dayNight self.linFog.setColor(*linFogColor) fogRange = linFogMinRange + linFogVarianceRange * dayNight self.linFog.setLinearRange(fogRange / 4.0, fogRange) self.linFog.setLinearFallback(fogRange / 8.0, fogRange / 4.0, fogRange) base.setBackgroundColor(linFogColor) return Task.again def updateScene(self, task): # set position of the particle system if USERAIN: self.rain.setPos(base.camera.getPos() + Vec3(0, 0, 200)) return Task.cont
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(0.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()
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()
class environmentClass: def __init__( self, cameraPos, heightfield ): self.cameraPos = cameraPos self.heightfield = heightfield if USELIGHT: self.setupLight() if USESKY: self.setupSky() if USEFOG: self.setupFog() if USESOUND: self.setupSound() if USERAIN: self.setupRain() #taskMgr.doMethodLater(DAYNIGHTCYCLETIME/60.0, self.dayNightCycle, 'UpdateDayNight') taskMgr.doMethodLater(0.25, self.dayNightCycle, 'UpdateDayNight') taskMgr.doMethodLater(0.25, self.updateScene, 'updateScene' ) def setupSound( self ): self.mySound1 = loader.loadSfx("data/sounds/rainshower.wav") self.mySound1.setLoop(True) self.mySound1.play() #self.walkSound = loader.loadSfx("sounds/walking/542581_SOUNDDOGS_Ho.mp3") #self.walkSound.setLoop(True) def setupSky( self ): self.skyNP = loader.loadModel( 'data/models/sky.bam.pz' ) self.skyNP.reparentTo( render ) self.skyNP.setScale( 4000, 4000, 1000 ) self.skyNP.setPos( 0, 0, 0 ) self.skyNP.setTexture( loader.loadTexture( 'data/textures/clouds.png' ) ) self.skyNP.setShader( loader.loadShader( 'data/sky.sha' ) ) '''self.skyFogNP = loader.loadModel( 'data/models/sphere.egg' ) self.skyFogNP.reparentTo( base.camera ) self.skyFogNP.setTwoSided( True ) self.skyFogNP.setScale( 10 ) self.skyFogNP.setPos( Vec3(0,0,4) ) self.skyFogNP.setTransparent( True )''' sky = Vec4( 0.25, 0.5, 1.0, 0.0 ) # r, g, b, skip sky2 = Vec4( 1.0, 1.0, 1.0, 0.0 ) clouds = Vec4( 0.004, 0.002, 0.008, 0.010 ) # vx, vy, vx, vy self.skyNP.setShaderInput( 'sky', sky ) self.skyNP.setShaderInput( 'sky2', sky2 ) self.skyNP.setShaderInput( 'clouds', clouds ) render.setShaderInput( 'time', 0 ) def setupLight( self ): ''' #Default lightAttrib with no lights self.lightAttrib = LightAttrib.makeAllOff() # Add a light to the scene. self.lightpivot = self.cameraPos.attachNewNode("lightpivot") #self.lightpivot.setPos(0,0,500) #self.lightpivot.hprInterval(MAPSIZE/4,Point3(360,0,0)).loop() self.plight = PointLight('plight') self.plight.setColor(Vec4(0.5, 0.5, 0.5, 1)) self.plight.setAttenuation(Vec3(0.1,0.0001,0)) self.plnp = self.lightpivot.attachNewNode(self.plight.upcastToPandaNode()) #self.plnp.setPos(45, 0, 0) render.setLight(self.plnp) self.lightAttrib = self.lightAttrib.addLight( self.plight ) # create a sphere to denote the light #sphere = loader.loadModel("data/models/sphere") #sphere.reparentTo(self.plnp) # Add an ambient light alight = AmbientLight('alight') alight.setColor(Vec4(0.2, 0.2, 0.2, 1.0)) alnp = render.attachNewNode(alight.upcastToPandaNode()) render.setLight(alnp) self.lightAttrib = self.lightAttrib.addLight( alight ) # Now we create a spotlight. Spotlights light objects in a given cone # They are good for simulating things like flashlights self.spotlight = Spotlight( "spotlight" ) self.spotlight.setColor( Vec4( .9, .9, .9, 1 ) ) #The cone of a spotlight is controlled by it's lens. This creates the lens self.spotlight.setLens( PerspectiveLens() ) #This sets the Field of View (fov) of the lens, in degrees for width and #height. The lower the numbers, the tighter the spotlight. self.spotlight.getLens().setFov( 16, 16 ) # Attenuation controls how the light fades with distance. The numbers are # The three values represent the three constants (constant, linear, and # quadratic) in the internal lighting equation. The higher the numbers the # shorter the light goes. self.spotlight.setAttenuation( Vec3( 1, 0.0, 0.0 ) ) # This exponent value sets how soft the edge of the spotlight is. 0 means a # hard edge. 128 means a very soft edge. self.spotlight.setExponent( 60.0 ) #self.spotlight.lookAt( Vec3( 0,1,0) ) # Unlike our previous lights, the spotlight needs a position in the world # We are attaching it to the camera so that it will appear is if we are # holding a flashlight, but it can be attached to any NodePath # # When attaching a spotlight to a NodePath, you must use the # upcastToLensNode function or Panda will crash self.spotLightNp = base.camera.attachNewNode( self.spotlight.upcastToLensNode() ) self.spotLightNp.lookAt( Point3(0,1,0) ) self.lightAttrib = self.lightAttrib.addLight( self.spotlight ) #self.spotlight.reparentTo( base.camera ) ''' #Default lightAttrib with no lights #self.lightAttrib = LightAttrib.makeAllOff() # First we create an ambient light. All objects are affected by ambient # light equally #Create and name the ambient light self.ambientLight = AmbientLight( "ambientLight" ) #Set the color of the ambient light self.ambientLight.setColor( Vec4( .1, .1, .1, 1 ) ) #add the newly created light to the lightAttrib render.setLight(render.attachNewNode(self.ambientLight)) #self.lightAttrib = self.lightAttrib.addLight( self.ambientLight ) ''' # Now we create a directional light. Directional lights add shading from a # given angle. This is good for far away sources like the sun self.directionalLight = DirectionalLight( "directionalLight" ) self.directionalLight.setColor( Vec4( .7, .7, .7, 1 ) ) # The direction of a directional light is set as a 3D vector self.directionalLight.setDirection( Vec3( 1, 1, -2 ) ) self.lightAttrib = self.lightAttrib.addLight( self.directionalLight ) ''' # Now we create a spotlight. Spotlights light objects in a given cone # They are good for simulating things like flashlights self.spotlight = Spotlight( "spotlight" ) self.spotlight.setColor( Vec4( .9, .9, .9, 1 ) ) #The cone of a spotlight is controlled by it's lens. This creates the lens self.spotlight.setLens( PerspectiveLens() ) #This sets the Field of View (fov) of the lens, in degrees for width and #height. The lower the numbers, the tighter the spotlight. self.spotlight.getLens().setFov( 30, 30 ) # Attenuation controls how the light fades with distance. The numbers are # The three values represent the three constants (constant, linear, and # quadratic) in the internal lighting equation. The higher the numbers the # shorter the light goes. self.spotlight.setAttenuation( Vec3( 0.0, 0.0075, 0.0 ) ) # This exponent value sets how soft the edge of the spotlight is. 0 means a # hard edge. 128 means a very soft edge. self.spotlight.setExponent( 60.0 ) # Unlike our previous lights, the spotlight needs a position in the world # We are attaching it to the camera so that it will appear is if we are # holding a flashlight, but it can be attached to any NodePath # # When attaching a spotlight to a NodePath, you must use the # upcastToLensNode function or Panda will crash #camera.attachNewNode( self.spotlight.upcastToLensNode() ) render.setLight(camera.attachNewNode( self.spotlight.upcastToLensNode() )) #self.lightAttrib = self.lightAttrib.addLight( self.spotlight ) ''' PLIGHTATT = Vec3( 0.0, 0.0, 0.0 ) # Now we create three colored Point lights. Point lights are lights that # radiate from a single point, like a light bulb. Like spotlights, they # are given position by attaching them to NodePaths in the world self.redPointLight = PointLight( "redPointLight" ) self.redPointLight.setColor( Vec4( .7, 0, 0, 1 ) ) self.redPointLight.setAttenuation( PLIGHTATT ) self.redHelper = loader.loadModelCopy('models/sphere') self.redHelper.setColor( Vec4( 1, 0, 0, 1 ) ) # To attach a point light to the scene, you must use the upcastToPandaNode # Again, if you don't do this Panda will crash self.redHelper.attachNewNode( self.redPointLight.upcastToPandaNode() ) self.redHelper.setPos( -6.5, -3.75, 0 ) self.redHelper.setScale(.25) #The green point light and helper self.greenPointLight = PointLight( "greenPointLight" ) self.greenPointLight.setAttenuation( PLIGHTATT ) self.greenPointLight.setColor( Vec4( 0, .7, 0, 1 ) ) self.greenHelper = loader.loadModelCopy('models/sphere') self.greenHelper.setColor( Vec4( 0, 1, 0, 1 ) ) self.greenHelper.attachNewNode( self.greenPointLight.upcastToPandaNode() ) self.greenHelper.setPos( 0, 7.5, 0 ) self.greenHelper.setScale(.25) #The blue point light and helper self.bluePointLight = PointLight( "bluePointLight" ) self.bluePointLight.setAttenuation( PLIGHTATT ) self.bluePointLight.setColor( Vec4( 0, 0, .7, 1 ) ) self.bluePointLight.setSpecularColor( Vec4( 1 ) ) self.blueHelper = loader.loadModelCopy('models/sphere') self.blueHelper.setColor( Vec4( 0, 0, 1, 1 ) ) self.blueHelper.attachNewNode( self.bluePointLight.upcastToPandaNode() ) self.blueHelper.setPos( 6.5, -3.75, 0 ) self.blueHelper.setScale(.25) #Create a dummy node so the lights can be spun with one command self.pointLightHelper = render.attachNewNode( "pointLightHelper" ) self.pointLightHelper.setPos(0, 50, 11) self.redHelper.reparentTo( self.pointLightHelper ) self.greenHelper.reparentTo( self.pointLightHelper ) self.blueHelper.reparentTo( self.pointLightHelper ) #Add the point lights we just made to our lightAttrib self.lightAttrib = self.lightAttrib.addLight( self.redPointLight ) self.lightAttrib = self.lightAttrib.addLight( self.greenPointLight ) self.lightAttrib = self.lightAttrib.addLight( self.bluePointLight ) ''' #Finally we set the light attrib to a node. In this case we are using render #so that the lights will effect everything, but you could put it on any #part of the scene #render.node().setAttrib( self.lightAttrib ) # Create and start interval to spin the lights, and a variable to # manage them. #self.pointLightsSpin = self.pointLightHelper.hprInterval(6, Vec3(360, 0, 0)) #self.pointLightsSpin.loop() def setupFog( self ): '''defaultExpFogColor = (0.33, 0.5, 1.0) self.expFog = Fog("exponentialFog") self.expFog.setColor(*defaultExpFogColor) self.expFog.setExpDensity(DEFAULTFOG) render.setFog(self.expFog)''' defaultLinFogColor = (0.33, 0.5, 1.0) self.linFog = Fog("linearFog") self.linFog.setColor(*defaultLinFogColor) self.linFog.setLinearRange(0, linFogMinRange + linFogVarianceRange) self.linFog.setLinearFallback(30, 60, 240) base.camera.attachNewNode(self.linFog) render.setFog(self.linFog) base.setBackgroundColor( defaultLinFogColor ) def setupRain( self ): base.enableParticles() self.rain = rainClass() self.rain.reparentTo( base.camera ) #self.rain.setPos( 0, 0, 5 ) self.rain.setScale( 200 ) #self.rain.particle.setPoolSize( 8192 ) #self.rain.particle.setBirthRate( 2.000 ) #self.rain.particle.renderer.setHeadColor(Vec4(1.00, 1.00, 1.00, 0.8)) #self.rain.particle.renderer.setTailColor(Vec4(1.00, 1.00, 1.00, 0.2)) self.rain.start( render ) def dayNightCycle( self, task ): #print "dayNight", rainStrenght if USERAIN: rainStrenght = (RAINCYCLEFUNC**((math.sin(time.time()/(DAYNIGHTCYCLETIME/24.))+1.0)/2.0)-1.0)/(RAINCYCLEFUNC-1.0) self.rain.particle.setBirthRate( max( rainStrenght, 0.01 ) ) dayNight = (DAYNIGHTCYCLEFUNC**((math.sin(time.time()/(DAYNIGHTCYCLETIME/6.))+1.0)/2.0)-1.0)/(DAYNIGHTCYCLEFUNC-1.0) if USELIGHT: #print dayNight c = (dayNight)/1.5 + 0.1 #print dayNight, c [commented by Finn] aLightCol = Vec4( c, c, c, 1 ) self.ambientLight.setColor( aLightCol ) # Time for clouds shader if USESKY: render.setShaderInput( 'time', task.time/4.0 ) #dayNight = 1.0 # color for clouds & fog #dayNight = ( math.sin(time.time()/DAYNIGHTCYCLETIME) + 1.0 ) / 2.0 # 0.0 for night, 1.0 for day sky = Vec4( dayNight/4.0, dayNight/2.0, dayNight, 0.0 ) # r, g, b, skip sky2 = Vec4( dayNight, dayNight, dayNight, 0.0 ) # set colors self.skyNP.setShaderInput( 'sky', sky ) self.skyNP.setShaderInput( 'sky2', sky2 ) if USEFOG: #expFogColor = dayNight/3.0,dayNight/2.0,dayNight #self.expFog.setColor( *expFogColor ) #self.expFog.setExpDensity(DEFAULTFOG*(NIGHTFOGMULTIPLIER-dayNight*(NIGHTFOGMULTIPLIER-1.0))) linFogColor = dayNight/3.0,dayNight/2.0,dayNight self.linFog.setColor( *linFogColor ) fogRange = linFogMinRange + linFogVarianceRange*dayNight self.linFog.setLinearRange( fogRange/4., fogRange ) self.linFog.setLinearFallback(fogRange/8., fogRange/4., fogRange) base.setBackgroundColor( linFogColor ) return Task.again def updateScene( self, task ): # set position of the particle system if USERAIN: self.rain.setPos( base.camera.getPos() + Vec3( 0,0,200) ) return Task.cont