def make_light(self): d_light = DirectionalLight('dlight') d_light.setColor((0.3, 0.3, 0.3, 1)) d_light_np = self.app.render.attachNewNode(d_light) self.app.render.setLight(d_light_np) cam_cube_node = GeomNode('cam_cube') cam_cube_node.add_geom(make_cube_geom(geom_color=(1, 1, 0, 1))) cam_cube_path = self.app.render.attachNewNode(cam_cube_node) cam_cube_path.reparentTo(d_light_np) d_light_np.setPos(self.ref_node.getPos()) d_light_np.setHpr(self.ref_node.getHpr())
def setupLight(self): self.sunLight = DirectionalLight("sun") # sunLight.setColor(get_vbase4_from_hex('fbfcde')) self.sunLight.setColor(VBase4(.99, .99, .99, 1)) self.light = self.render.attach_new_node(self.sunLight) self.light.setHpr(45, -45, 0) self.light.setPos(0, 0, 300) self.render.setLight(self.light) ambientLight = AmbientLight("ambient") ambientLight.setColor(VBase4(0.2, 0.2, 0.2, 1)) self.ambientLight = self.render.attach_new_node(ambientLight) self.render.setLight(self.ambientLight) return
def __init__(self): ShowBase.__init__(self) self.camera.setPos(0, 0, 3) self.fm = FlyMove(self) self.scene = self.loader.loadModel('models/environment') self.disable_mouse() self.scene.reparentTo(self.render) self.scene.setScale(0.25, 0.25, 0.25) self.scene.setPos(-8, 42, 0) pandaMat = Material() pandaMat.setEmission((1, 0.4, 0, 1)) colour = (0.5, 0.8, 0.8) expfog = Fog("Scene-wide exponential Fog object") expfog.setColor(*colour) expfog.setExpDensity(0.005) self.render.setFog(expfog) self.pandaActor = Actor('models/panda-model', {'walk': 'models/panda-walk4'}) self.pandaActor.set_material(pandaMat) self.pandaActor.setScale(0.005, 0.005, 0.005) self.pandaActor.loop('walk') line = NodePath('pandaline') for i in range(50): placeholder = line.attachNewNode('line-panda') placeholder.setPos(i * 2, 0, 0) self.pandaActor.instanceTo(placeholder) line.reparentTo(self.render) pandaPosIntervalInterval1 = self.pandaActor.posInterval( 13, Point3(0, -10, 0), startPos=Point3(0, 10, 0)) pandaPosIntervalInterval2 = self.pandaActor.posInterval( 13, Point3(0, 10, 0), startPos=Point3(0, -10, 0)) pandaHprIntervalInterval1 = self.pandaActor.hprInterval( 2, Point3(180, 0, 0), startHpr=Point3(0, 0, 0)) pandaHprIntervalInterval2 = self.pandaActor.hprInterval( 2, Point3(0, 0, 0), startHpr=Point3(180, 0, 0)) self.pandaPace = Sequence(pandaPosIntervalInterval1, pandaHprIntervalInterval1, pandaPosIntervalInterval2, pandaHprIntervalInterval2) self.pandaPace.loop() light = DirectionalLight('pl') light.set_color_temperature(2000) np = self.render.attachNewNode(light) np.set_pos(0, 0, 5) light.set_shadow_caster(True, 512, 512) self.render.setLight(np) # np.place() alight = AmbientLight('alight') alight.setColor(VBase4(0.3, 0.1, 0.1, 1)) alnp = self.render.attachNewNode(alight) self.render.setLight(alnp)
def setupLight(self, color, hpr): sunlight = DirectionalLight("sun") sunlight.setColor(color) sunlight.setShadowCaster(True, 512, 512) self.sunlight = self.render.attachNewNode(sunlight) self.sunlight.setHpr(hpr[0], hpr[1], hpr[2]) self.render.setLight(self.sunlight) self.scene.setLight(self.sunlight)
class MyApp(ShowBase): # our 'class' def __init__(self): ShowBase.__init__(self) # initialise self.terrain = GeoMipTerrain("worldTerrain") # create a terrain self.terrain.setHeightfield( "heightmapper-1567436259173.png") # set the height map self.terrain.setColorMap( "TexturesCom_Moss0138_2_L.jpg") # set the colour map self.terrain.setBruteforce(True) # level of detail root = self.terrain.getRoot() # capture root root.reparentTo(self.render) # render from root root.setSz(80) # maximum height self.terrain.generate() # generate self.sphere = self.loader.loadModel("skysphere-1.egg") self.sphere.setScale(700) self.sphere.setPos(500, 500, 0) self.tex = self.loader.loadTexture("TexturesCom_Skies0282_L.jpg") self.sphere.setTexture(self.tex) self.sphere.reparentTo(self.render) self.setupLight() def setupLight(self): self.sunLight = DirectionalLight("sun") # sunLight.setColor(get_vbase4_from_hex('fbfcde')) self.sunLight.setColor(VBase4(.99, .99, .99, 1)) self.light = self.render.attach_new_node(self.sunLight) self.light.setHpr(45, -45, 0) self.light.setPos(0, 0, 300) self.render.setLight(self.light) ambientLight = AmbientLight("ambient") ambientLight.setColor(VBase4(0.2, 0.2, 0.2, 1)) self.ambientLight = self.render.attach_new_node(ambientLight) self.render.setLight(self.ambientLight) return
def setupLight(self, red, green, blue, alpha): sunlight = DirectionalLight("sun") sunlight.setColor(VBase4(red, green, blue, alpha)) self.sunlight = self.render.attachNewNode(sunlight) self.sunlight.setHpr(45, -60, 0) self.render.setLight(self.sunlight)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.set_background_color(0.2, 0.2, 0.2, 0.6) # self.render.setAntialias(AntialiasAttrib.MMultisample) self.controller = Controller(self.accept) self.cam.set_pos(0, -200, 10) self.player = self.loader.loadModel(str(settings.egg / "a2.egg")) self.player.set_pos(0, 0, 0) self.player.set_scale(3.0) self.player.set_color((0, 0, 0, 1)) self.player.reparent_to(self.render) self.plane = self.loader.loadModel(str(settings.egg / "plane.egg")) self.plane.reparent_to(self.render) self.plane.set_name("plane") self.cube_01 = self.loader.loadModel(str(settings.egg / "bd-cube.egg")) self.cube_01.reparent_to(self.render) self.cube_01.set_name("cube") self.cube_01.set_scale(20) self.cube_01.set_pos(-100, 30, 20) self.cube_02 = self.loader.loadModel(str(settings.egg / "bd-cube.egg")) self.cube_02.reparent_to(self.render) self.cube_02.set_name("cube") self.cube_02.set_scale(10) self.cube_02.set_pos(-30, 100, 10) # ############################################################################################################## # player self.light_model = self.loader.loadModel("models/misc/sphere") self.light_model.set_pos(0, 0, 20) self.light_model.set_scale(3.0) self.light_model.set_color((1, 1, 1, 1)) self.light_model.reparent_to(self.render) # lights if True: day_light = DirectionalLight("sun") day_light.set_color((1, 1, 1, 1)) self.sun = self.render.attach_new_node(day_light) self.sun.set_p(-20) self.sun.set_h(10) self.cube_01.set_light(self.sun) self.cube_02.set_light(self.sun) self.player.set_light(self.sun) self.plane.set_light(self.sun) sun_spotlight = PointLight("sun_spotlight") sun_spotlight.set_color((1, 1, 1, 1)) self.sun_spotlight_nodepath = self.render.attach_new_node(sun_spotlight) self.sun_spotlight_nodepath.reparent_to(self.light_model) self.cube_01.set_light(self.sun_spotlight_nodepath) self.cube_02.set_light(self.sun_spotlight_nodepath) self.player.set_light(self.sun_spotlight_nodepath) self.plane.set_light(self.sun_spotlight_nodepath) amblight = AmbientLight("ambient_light") amblight.set_color((0.01, 0.01, 0.01, 1)) self.ambnp = self.render.attach_new_node(amblight) self.cube_01.set_light(self.ambnp) self.cube_02.set_light(self.ambnp) self.player.set_light(self.ambnp) self.plane.set_light(self.ambnp) sun_spotlight.set_shadow_caster(True, 2048, 2048) self.render.set_shader_auto() # shadows # self.day_light.set_shadow_caster(True, 2048, 2048) # self.render.set_shader_auto() # uppdate self.task_mgr.add(self.update)
def __init__(self, framework, *args, **kwargs): self.bullets = [] self.environment = {} self.colliders = {} self.task_manager = [] self.bullet_colliders = [] self.remove_bullet_indices = [] super().__init__(*args, **kwargs) self.f = framework self.controller = Controller(self.f.accept, self) self.f.set_background_color(0.2, 0.2, 0.2, 0.6) if settings.ALLOW_FILTERS: self.filter = CommonFilters(self.f.win, self.f.cam) self.filter.set_bloom(mintrigger=0.99, size="small") # self.filter.set_blur_sharpen(amount=0.99) self.base_node = NodePath("base") self.base_node.reparent_to(self.f.render) # floor self.plane = self.create_model(settings.egg / "plane", self.base_node, "ground-zero", color=(1, 1, 1, 1)) self.create_model(settings.egg / "house_01", self.base_node, "house-01", position=(20, 50, 0), scale=1.5) self.create_model(settings.egg / "house_02", self.base_node, "house-02", position=(-50, 10, 0), scale=1.5) self.sun_light_model = self.create_model("models/misc/sphere", self.base_node, "sun", position=(0, -150, 250), scale=5.0, color=(1, 1, 1, 1), _store=False) tank = self.create_model(settings.egg / "tank", self.base_node, "player", scale=3.0, position=(0.0, 0.0, 1e-3)) gun = self.create_model("models/misc/sphere", tank, "player-gun", position=(0.0, 4.5, 1.755), scale=0.1, _store=False) self.tank = Tank(tank, gun, framework=self.f) self._tank = self.tank.tank enemy = self.create_model(settings.egg / "enemy", self.base_node, "enemy", scale=0.8, position=(-80.0, 80.0, 1e-3)) self.enemy = EnemyTank(enemy, None, framework=self.f) # point light for shadows sun_light = PointLight("sun-light") sun_light.set_color((0.4, 0.4, 0.4, 1)) self.sun_light_node = self.base_node.attach_new_node(sun_light) self.sun_light_node.reparent_to(self.sun_light_model) self.redistribute_light(self.sun_light_node) self.plane.set_light(self.sun_light_node) # daylight if settings.ALLOW_DAYLIGHT: day_light = DirectionalLight("day-light") day_light.set_color((1, 1, 1, 1)) self.daylight_node = self.f.render.attach_new_node(day_light) self.daylight_node.set_p(-20) self.daylight_node.set_h(10) self.daylight_node.reparent_to(self.sun_light_model) self.redistribute_light(self.daylight_node) # shadows if settings.ALLOW_SHADOWS: sun_light.set_shadow_caster(True, 2048, 2048) self.f.render.set_shader_auto() # 3rd person camera lock if settings.TRD_PERSON_CAM: self.f.camera.reparent_to(self.tank.tank) self.f.cam.set_pos(0, -25, 10) self.f.cam.lookAt(self.tank.tank) self.f.cam.setP(self.f.camera.getP() - 20) if settings.ALLOW_AMBIENT: amblight = AmbientLight("ambient-light") amblight.set_color((0.2, 0.2, 0.2, 1)) self.amblight_node = self.f.render.attach_new_node(amblight) self.redistribute_light(self.amblight_node) # colliders tank_collider = self.environment["player"].attachNewNode( CollisionNode('player-collider')) tank_collider.node().addSolid( CollisionBox(Point3(-1.5, -3, 0), Point3(1.5, 3, 2.25))) self.colliders['player-collider'] = tank_collider enemy_collider = self.environment["enemy"].attachNewNode( CollisionNode('enemy-collider')) enemy_collider.node().addSolid( CollisionBox(Point3(-6.5, -13.5, 0), Point3(6.5, 13, 10))) self.colliders['enemy-collider'] = enemy_collider house_01_collider = self.environment["house-01"].attachNewNode( CollisionNode('house-01-collider')) house_01_collider.node().addSolid( CollisionBox(Point3(0, 2, 0), Point3(14.5, 16, 17))) self.colliders['house-01'] = house_01_collider house_02_collider = self.environment["house-02"].attachNewNode( CollisionNode('house-02-collider')) house_02_collider.node().addSolid( CollisionBox(Point3(0, 0, 0), Point3(21, 27, 37))) self.colliders['house-02'] = house_02_collider floor_collider = self.environment["ground-zero"].attachNewNode( CollisionNode('ground-zero-collider')) floor_collider.node().addSolid( CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0, 0, 0)))) self.colliders['ground-zero-collider'] = floor_collider self.f.pusher.addCollider(tank_collider, self.environment["player"]) self.f.cTrav.addCollider(tank_collider, self.f.pusher) # show.hide all colliders if settings.SHOW_COLLIDERS: for key, value in self.colliders.items(): logger.info(f"collider for {key} is visible") value.show() self.f.cTrav.showCollisions(self.f.render) # uppdate self.f.cHandler.addInPattern('%fn') self.f.accept('bullet-collider', self.handle_collision) self.task_manager.append(self.f.task_mgr.add(self.update)) self.task_manager.append(self.f.task_mgr.add(self.update_bullets))