def setupWorld(self): """ responsible for loading all models """ # load our ball self.mBall = self.loader.loadModel("data/cube") # add to scenegraph self.mBall.reparentTo(self.render) # set position self.mBall.setScale(1.0, 1.0, 1.0) # self.mBall.setPosHpr(0,0,0,0.,45.,0) self.mBall.setColor(0.0, 0.2, 0.8) # use object tag to find the object when picking self.mBall.setTag("MyObjectTag", "1") self.mBall.setRenderModeWireframe() # Panda's coordintes are Z is up, -Y is forward, and X is to the right # it also uses degrees as the orientation component # self.camera.setPos(0, -6.0, 0) angleDegrees = 0 angleRadians = angleDegrees * (math.pi / 180.0) self.camera.setPos(2 * math.sin(angleRadians), -5.0 * math.cos(angleRadians), 0) self.camera.setHpr(angleDegrees, 0, 0) # lets create a light plight = PointLight("plight") plight.setColor(Vec4(0.7, 0.7, 0.7, 1)) plnp = self.render.attachNewNode(plight) plnp.setPos(self.mBall, 0, 0, 40) self.render.setLight(plnp)
def __init__(self): super().__init__() self.set_background_color(0, 0, 0, 1) self.cam.setPos(0, -20, 5) self.plane = self.loader.loadModel('my-models/planeTB') self.plane.setPos(-5, 5, 0) self.plane.reparentTo(self.render) self.sphere = self.loader.loadModel("my-models/icosphere") self.sphere.reparentTo(self.render) alight = AmbientLight('alight') alight.setColor((0.2, 0.2, 0.2, 1)) alnp = self.render.attachNewNode(alight) self.plane.setLight(alnp) plight = PointLight('plight') plight.setColor((1, 1, 1, 1)) plnp = self.sphere.attachNewNode(plight) self.plane.setLight(plnp) self.render.setShaderAuto() self.taskMgr.add(self.move_light, "move-light")
def setUpLights(self): # ambient #alight=AmbientLight("alight") #alight.setColor(Vec4(Terrain.COLOR_AMB_50)) #alightP=self.base.render.attachNewNode(alight) # point plight = PointLight("plight") plight.setColor(Vec4(Terrain.COLOR_WHITE)) self.plightP = self.base.render.attachNewNode(plight) self.plightP.setPos(14, -30, 17) # directional # sun sun = DirectionalLight("sun") sun.setColor(Vec4(Terrain.COLOR_WHITE)) #sun.setShadowCaster(True, 1024, 1024) sun.getLens().setFilmSize(Vec2(100, 100)) sun.getLens().setNearFar(10, 200) sun.getLens().setFov(200) #sun.showFrustum() sunP = self.base.render.attachNewNode(sun) sunP.setPos(0, -2, 20) sunP.setHpr(-60, -90, -30) # sky sunSky = DirectionalLight("sunSky") sunSky.setColor(Vec4(Terrain.COLOR_WHITE)) sunSkyP = self.base.render.attachNewNode(sunSky) sunSkyP.setPos(-14, 30, -17) sunSkyP.setHpr(-10, 60, -10) # #self.base.render.setLight(alightP) self.base.render.setLight(sunP) self.base.render.setLight(self.plightP)
class Bullet(DirectObject): def __init__(self, ship, bulletPos, bulletVelocityVec, collisionHandler): self.model = game.loader.loadModel("Models/bullet.egg.pz") self.model.setPos(bulletPos) self.model.setScale(BULLET_SIZE) self.model.reparentTo(render) self.model.setPythonTag("owner", self) self.ship = ship finalPosition = bulletPos + (bulletVelocityVec * BULLET_TRAVEL_TIME) self.trajectory = self.model.posInterval(BULLET_TRAVEL_TIME, finalPosition).start() self.collisionNode = self.model.attachNewNode(CollisionNode("bullet")) self.collisionNode.node().addSolid(CollisionSphere(0, 0, 0, 1)) base.cTrav.addCollider(self.collisionNode, collisionHandler) # Add Point Light to the bullet self.plight = PointLight('plight' + str(random())) self.plight.setColor(Vec4(1, 1, 1, 1)) self.plight.setAttenuation(Vec3(0.7, 0.05, 0)) self.plnp = self.model.attachNewNode(self.plight) render.setLight(self.plnp) render.setShaderInput("light", self.plnp) ### # Bullet.remove # # Removes this asteroid from rendering and registering collisions. ## def remove(self): self.ignoreAll() self.model.remove() self.collisionNode.remove()
def addPointLight(self, color=(0.2, 0.2, 0.2, 1), pos=(0, 0, 100)): plight = PointLight('plight') plight.setColor(color) plnp = self.render.attachNewNode(plight) plnp.setPos(pos) self.render.setLight(plnp)
def __init__(self): super().__init__() self.set_background_color(0, 0, 0, 1) self.cam.setPos(0, -12, 0) self.tree = self.loader.loadModel('my-models/christmas_tree') self.tree.setPos(0, 0, -2.5) self.tree.reparentTo(self.render) self.light_model = self.loader.loadModel('models/misc/sphere') self.light_model.setScale(0.2, 0.2, 0.2) self.light_model.setPos(4, 0, 0) self.light_model.reparentTo(self.render) plight = PointLight("plight") plight.setColor((1,1,1,1)) self.plnp = self.light_model.attachNewNode(plight) # plight.setAttenuation((0, 0, 1)) self.tree.setLight(self.plnp) alight = AmbientLight("alight") alight.setColor((0.04, 0.04, 0.04, 1)) alnp = self.render.attachNewNode(alight) self.tree.setLight(alnp) self.taskMgr.add(self.move_light, "move-light")
class Camera: """Does camera set up - will probably end up with lots of options.""" def __init__(self, xml): base.camNode.setCameraMask(BitMask32.bit(0)) #only temporary while testing self.plight = PointLight('plight') bright = 2 self.plight.setColor(VBase4(bright, bright, bright, 1)) #self.plight.setAttenuation(Point3(0, 0, 0.5)) plnp = base.camera.attachNewNode(self.plight) #plnp.setPos(0, 0, 0) render.setLight(plnp) #base.disableMouse() self.reload(xml) def reload(self, xml): pass def start(self): pass def stop(self): pass def destroy(self): pass
def __init__(self): ShowBase.__init__(self) self.cap = cv2.VideoCapture(0) self.classifier = cv2.CascadeClassifier(self.haar) self.scene = self.loader.loadModel('models/abstractroom') self.scene.reparentTo(self.render) self.scene.setPos(-10, 100, 0) self.shaderenable = 1 self.scene.setShaderAuto() # Add ambient light alight = AmbientLight('alight') alight.setColor((0.1, 0.11, 0.11, 1)) alnp = self.render.attachNewNode(alight) self.scene.setLight(alnp) # Add point light. plight = PointLight('plight') plight.setColor((1, 1, 1, 1)) plight.setAttenuation(LVector3(0.1, 0.02, 0)) plnp = self.render.attachNewNode(plight) plnp.setPos(-27, 100, 0) self.scene.setLight(plnp) # Create a sphere to denote the light sphere = self.loader.loadModel("models/icosphere") sphere.reparentTo(plnp) self.taskMgr.add(self.display, 'Display') print("%.1f, %.1f, %.1f" % (self.x, self.y, self.z))
def generate(self, helperInfo): color = self.mapObject.getPropertyValue("_light", default=Vec4( 255, 255, 255, 255)) color = CIGlobals.colorFromRGBScalar255(color) color = CIGlobals.vec3GammaToLinear(color) constant = float( self.mapObject.getPropertyValue("_constant_attn", default="0.0")) linear = float( self.mapObject.getPropertyValue("_linear_attn", default="0.0")) quadratic = float( self.mapObject.getPropertyValue("_quadratic_attn", default="1.0")) # Scale intensity for unit 100 distance ratio = (constant + 100 * linear + 100 * 100 * quadratic) if ratio > 0: color *= ratio pl = PointLight("lightHelper-light") pl.setColor(Vec4(color[0], color[1], color[2], 1.0)) pl.setAttenuation(Vec3(constant, linear, quadratic)) self.light = self.mapObject.helperRoot.attachNewNode(pl) if self.mapObject.doc.numlights < 128: self.mapObject.doc.render.setLight(self.light) self.mapObject.doc.numlights += 1 self.hasLight = True
class Bullet(DirectObject): def __init__(self, ship, bulletPos, bulletVelocityVec, collisionHandler): self.model = game.loader.loadModel("Models/bullet.egg.pz") self.model.setPos(bulletPos) self.model.setScale(BULLET_SIZE) self.model.reparentTo(render) self.model.setPythonTag("owner", self) self.ship = ship finalPosition = bulletPos + (bulletVelocityVec * BULLET_TRAVEL_TIME) self.trajectory = self.model.posInterval(BULLET_TRAVEL_TIME, finalPosition).start() self.collisionNode = self.model.attachNewNode(CollisionNode("bullet")) self.collisionNode.node().addSolid(CollisionSphere(0,0,0,1)) base.cTrav.addCollider(self.collisionNode, collisionHandler) # Add Point Light to the bullet self.plight = PointLight('plight'+str(random())) self.plight.setColor(Vec4(1,1,1,1)) self.plight.setAttenuation(Vec3(0.7, 0.05, 0)) self.plnp = self.model.attachNewNode(self.plight) render.setLight(self.plnp) render.setShaderInput("light", self.plnp) ### # Bullet.remove # # Removes this asteroid from rendering and registering collisions. ## def remove(self): self.ignoreAll() self.model.remove() self.collisionNode.remove()
def setup_point_light(self, x, y, z): plight = PointLight('plight') plight.setColor(VBase4(0.9, 0.9, 0.9, 1)) light = self.base.render.attachNewNode(plight) light.setPos(x, y, z) self.point_light.append(light) self.base.render.setLight(light)
def __init__(self): # Basics ShowBase.__init__(self) base.disableMouse() base.setFrameRateMeter(True) self.accept("escape", sys.exit) self.camera.set_pos(-10, -10, 10) self.camera.look_at(0, 0, 0) # A light plight = PointLight('plight') plight.setColor(VBase4(0.5, 0.5, 0.5, 1)) plnp = render.attachNewNode(plight) plnp.setPos(10, 10, 10) render.setLight(plnp) # Create the geometry self.sidelength = 30 self.map_a = self.create_map(self.sidelength) self.map_b = self.map_a geom = self.create_geom(self.sidelength) np = NodePath(geom) np.reparent_to(self.render) # Start the task to interpolate the geometry each frame self.last_time = 0.0 self.need_to_swap_maps = True self.taskMgr.add(self.swap_maps, 'swap_geometry', sort = 5) self.taskMgr.add(self.interpolate_maps, 'interpolate_geometry', sort = 10)
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 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 load_scene(self): self.scene_model = self.loader.loadModel("models/scene.egg") self.scene_model.reparentTo(self.render) self.alight = AmbientLight('alight') self.alight.setColor(VBase4(0.1, 0.1, 0.1, 1)) self.alnp = self.render.attachNewNode(self.alight) self.render.setLight(self.alnp) self.dlight = DirectionalLight('dlight') self.dlight.setColor(VBase4(0.5, 0.5, 0.5, 0.5)) self.dlnp = self.render.attachNewNode(self.dlight) self.dlnp.setHpr(0, -60, 0) self.render.setLight(self.dlnp) self.plights = [] for position in [ [0, 0, 20], # [10, 10, 20], # [-10, 10, 20], # [-10, -10, 20], [10, -10, 20], ]: plight = PointLight('plight_{}'.format(position)) plight.setColor(VBase4(0.4, 0.4, 0.4, 1)) plnp = self.render.attachNewNode(plight) plnp.setPos(*position) self.render.setLight(plnp) self.plights.append(plight) # self.camera.setPos(0, -20, 3) self.trackball.node().setPos(0, 20, -3)
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 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 insertLight(self, name, x, y, z): lightball = self.loader.loadModel("lightball_1.obj", noCache=True) lightball.reparentTo(self.render) lightball.setPos(x, y, z) plight = PointLight(name) plight.setColor(VBase4(1.0, 1.0, 1.0, 1)) plnp = self.render.attachNewNode(plight) plnp.setPos(x, y, z) self.render.setLight(plnp)
def pointlight(self, x, y, z): """ Erzeugt einen Schatten, je nach Position der Sonne :return: die Schattierung des Planeten """ plight = PointLight('plight') plight.setColor(VBase4(0.8, 0.8, 0.8, 1)) plnp = render.attachNewNode(plight) plnp.setPos(x, y, z) return plnp
def __init__(self): # Basics ShowBase.__init__(self) #base.disableMouse() base.setFrameRateMeter(True) self.accept("escape", sys.exit) self.camera.set_pos(-10, -10, 10) self.camera.look_at(0, 0, 0) # A light plight = PointLight("plight") plight.setColor(VBase4(1, 1, 1, 1)) plnp = render.attachNewNode(plight) plnp.setPos(100, 100, 100) render.setLight(plnp) # Create the geometry vformat = GeomVertexFormat.getV3n3c4() vdata = GeomVertexData("Data", vformat, Geom.UHStatic) vdata.setNumRows(3) vertex = GeomVertexWriter(vdata, 'vertex') normal = GeomVertexWriter(vdata, 'normal') color = GeomVertexWriter(vdata, 'color') vertex.addData3f(100, 0, 0) normal.addData3f(0, 0, 1) color.addData4f(0, 1, 0, 1) vertex.addData3f(100, 100, 0) normal.addData3f(0, 0, 1) color.addData4f(0, 0, 1, 1) vertex.addData3f(0, 100, 0) normal.addData3f(0, 0, 1) color.addData4f(1, 0, 0, 1) prim = GeomTriangles(Geom.UHStatic) prim.addVertices(0, 1, 2) prim.closePrimitive() geom = Geom(vdata) geom.addPrimitive(prim) node = GeomNode("GNode") node.addGeom(geom) nodePath = self.render.attachNewNode(node)
def makePointLight(name, color, pos, falloff=1.0): point = PointLight(name + "-point") point.setColor(color) ATTN_FCTR = 0.0625 point.setAttenuation((0, 0, falloff * ATTN_FCTR)) pnp = render.attachNewNode(point) pnp.setPos(pos) if False: sm = loader.loadModel("models/smiley.egg.pz") sm.reparentTo(pnp) return pnp
def buildSubType(self): """Build the light with the given subType""" if self.subType == "pointType": # make a point light c = self.color pointLight = PointLight(self.name) pointLight.setColor(VBase4(c[0], c[1], c[2], c[3])) pointLight.setShadowCaster(True, 512, 512) plnp = self.renderObjectsLight.attachNewNode(pointLight) plnp.setPos(self.position) self.lightNP = plnp self.setLightSwitch(True) if self.subType == "directType": # make a directional light c = self.color directLight = DirectionalLight(self.name) directLight.setColor(VBase4(c[0], c[1], c[2], c[3])) directLight.setShadowCaster(True, 512, 512) dlnp = self.renderObjectsLight.attachNewNode(directLight) #dlnp.setHpr(0, -60, 0) # no idea why its like that.. but it works self.lightNP = dlnp self.setLightSwitch(True) if self.subType == "ambientType": # make a ambient light c = self.color ambientLight = AmbientLight(self.name) ambientLight.setColor(VBase4(c[0], c[1],c[2], c[3])) alnp = self.renderObjectsLight.attachNewNode(ambientLight) self.lightNP = alnp self.setLightSwitch(True) if self.subType == "spotType": # make a spot light # lookAtObj = _object.getTag("lookAt") get rid of this. c = self.color spotLight = Spotlight(self.name) spotLight.setColor(VBase4(c[0], c[1], c[2], c[3])) spotLight.setShadowCaster(True, 512, 512) lens = PerspectiveLens() spotLight.setLens(lens) slnp = self.renderObjectsLight.attachNewNode(spotLight) slnp.setPos(self.position) slnp.setHpr(self.hpr) # Find out if this is really the only option # because setHpr doesnt seem to have any effect. # lookAt would be okay but that means adding anothe type #slnp.lookAt(self.main.GameObjects["player"].collisionBody) self.lightNP = slnp self.setLightSwitch(True)
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()
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 setup_light(self): # light plight = PointLight('plight') plight.setColor(VBase4(1, 1, 1, 1)) self.plnp = self.base.render.attachNewNode(plight) self.plnp.setPos(0, 0, 0) alight = AmbientLight('alight') alight.setColor(VBase4(.1, .1, .1, 1)) self.alnp = self.planets['sun'].get_model().attachNewNode(alight) self.planets['sun'].get_model().setLightOff() self.toggle_light()
def __init__(self): camera_hpr = base.camera.getHpr() self.name = "missle" self.core = loader.loadModel("./Models/sphere.egg") self.ttl = 2 # Time to live in seconds self.core.setPos(base.camera, (0, 0, 0)) self.core.setHpr(camera_hpr) self.core.setScale(600, 600, 600) self.glow = loader.loadModel("./Models/sphere.egg") self.core.setTransparency(TransparencyAttrib.MAlpha) self.glow.setScale(2, 2, 2) self.glow.reparentTo(self.core) self.core.setColor(colors.get("white")) self.glow.setColor(colors.get("white-transparent")) self.glow.setPos(0, 0, 0) #relative to parent self.core.setLightOff( ) # remove all other lights from missle so it is a bright white missle_total.append(self) #Create the light so the missle glows plight = PointLight('plight') plight.setColor(colors.get("white")) plight.setAttenuation(LVector3(0, 0.00008, 0)) plight.setMaxDistance(1000) self.plnp = self.core.attachNewNode(plight) #point light node point render.setLight(self.plnp) # Create hitsphere cNode = CollisionNode(self.name) cNode.addSolid(CollisionSphere(0, 0, 0, 1)) self.c_np = self.core.attachNewNode(cNode) # Create and run the missle animation end_location = Location(self.core).obj.getPos() start_location = base.camera.getPos() dt = globalClock.getDt() start_location[0] += spaceship_speed_x * dt start_location[1] += spaceship_speed_y * dt start_location[2] += spaceship_speed_z * dt self.asteroid_lerp = LerpPosInterval( self.core, # Object being manipulated. The missle in this case. 500, # How long it will take the missle to go from point a to b in seconds end_location, # future location at end of lerp start_location, # The start position of the missle fluid=1) # Allow for colisions during the lerp self.asteroid_lerp.start() del end_location self.core.reparentTo(render)
def __init__(self, node): self.node = node plight = PointLight("plight") plight.setColor((5, 5, 5, 0)) plight_node_path = self.node.attachNewNode(plight) plight_node_path.setPos(20, 0, 0) core.instance.render.setLight(plight_node_path) alight = AmbientLight("alight") alight.setColor((1, 1, 1, 0)) alight_node_path = self.node.attachNewNode(alight) alight_node_path.setPos(20, 0, 0) core.instance.render.setLight(alight_node_path)
def __init__(self): #initialization self.title = OnscreenText( # display title text="""Mundus /u/adhoc92""", parent=base.a2dBottomRight, align=TextNode.A_right, style=1, fg=(1, 1, 1, 1), pos=(-0.1, 0.1), scale=.07) base.setBackgroundColor(0, 0, 0) # Set the background to black camera.setPos(0, 0, 45) # Set the camera position (X, Y, Z) camera.setHpr(0, -90, 0) # Set the camera orientation #(heading, pitch, roll) in degrees #sets up PointLighting to simulate Light coming from Magnus plight = PointLight('plight') plight.setColor((1, 1, 1, 1)) plnp = render.attachNewNode(plight) plnp.setPos(20, 0, 0) #position just in front of Magnus render.setLight( plnp ) #because if pos set behind Magnus than the side of Magnus within the star sphere will not be illuminated #sets up AmbientLighting so that the dark side of plane(t)s/moons aren't /too/ dark. alight = AmbientLight('alight') alight.setColor((0.2, 0.2, 0.2, 1)) alnp = render.attachNewNode(alight) render.setLight(alnp) # Here again is where we put our global variables. Added this time are # variables to control the relative speeds of spinning and orbits in the # simulation # Number of seconds a full rotation of Earth around the sun should take self.yearscale = 60 # Number of seconds a day rotation of Earth should take. # It is scaled from its correct value for easier visability self.dayscale = self.yearscale / 364.0 * 15 # 364 days in Nirn year self.orbitscale = 2 # Orbit scale self.sizescale = 0.6 # Planet size scale self.loadPlanets() # Load and position the models # rotatePlanets function that puts the plane(t)s and moons into motion self.rotatePlanets()
def buildSubType(self): """Build the light with the given subType""" if self.subType == "pointType": # make a point light c = self.color pointLight = PointLight(self.name) pointLight.setColor(VBase4(c[0], c[1], c[2], c[3])) plnp = self.renderObjectsLight.attachNewNode(pointLight) plnp.setPos(self.position) self.lightNP = plnp self.setLightSwitch(True) if self.subType == "directType": # make a directional light c = self.color directLight = DirectionalLight(self.name) directLight.setColor(VBase4(c[0], c[1], c[2], c[3])) dlnp = self.renderObjectsLight.attachNewNode(directLight) dlnp.setHpr(0, -60, 0) # no idea why its like that.. but it works self.lightNP = dlnp self.setLightSwitch(True) if self.subType == "ambientType": # make a ambient light c = self.color ambientLight = AmbientLight(self.name) ambientLight.setColor(VBase4(c[0], c[1], c[2], c[3])) alnp = self.renderObjectsLight.attachNewNode(ambientLight) self.lightNP = alnp self.setLightSwitch(True) if self.subType == "spotType": # make a spot light # lookAtObj = _object.getTag("lookAt") get rid of this. c = self.color spotLight = Spotlight(self.name) spotLight.setColor(VBase4(c[0], c[1], c[2], c[3])) lens = PerspectiveLens() spotLight.setLens(lens) slnp = self.renderObjectsLight.attachNewNode(spotLight) slnp.setPos(self.position) slnp.setHpr(self.hpr) # Find out if this is really the only option # because setHpr doesnt seem to have any effect. # lookAt would be okay but that means adding anothe type #slnp.lookAt(self.main.GameObjects["player"].collisionBody) self.lightNP = slnp self.setLightSwitch(True)
def __create_point_light(self, lightId, lightColor, lightPos, shadow = True): pointLight = PointLight(lightId) pointLight.setColor(lightColor) pointLight.setShadowCaster(shadow) pointLightNP = NodePath(pointLight) pointLightNP.setPos(lightPos) return pointLightNP
def __init__(self): ShowBase.__init__(self) base.disableMouse() # base.camera.setPos(0, 0, 0) dl = DirectionalLight('dLight') dl.setColor(Vec4(0.1, 0.1, 0.1, 1)) dlNP = render.attachNewNode(dl) dlNP.setPos(1000, 1000, 0) al = AmbientLight('alight') al.setColor(Vec4(0.3, 0.3, 0.3, 1)) alNP = render.attachNewNode(al) pl = PointLight('plight') pl.setColor(VBase4(0.2, 0.2, 0.2, 1)) plNP = render.attachNewNode(pl) plNP.setPos(100, 100, 100) render.setLight(plNP) self.shipList = [ # Awing('awing1'), # Bwing('bwing1'), # Ywing("ywing1"), Xwing('xwing1'), TieInterceptor("interceptor1") #, #Xwing('xwing1') ] # xwing = Xwing("xwing1") # tie = TieInterceptor("tie1") # self.shipList = [xwing, tie] # xwing.weaponSystem.fireWeapon() for i, ship in enumerate(self.shipList): ship.reparentTo(render) ship.setScale(2) ship.setPos(Point3(i * 0, i * 50, i * 0)) # ship.setLight(dlNP) ship.setLight(alNP) base.camera.setPos(0, 1000, 0) base.camera.lookAt(0, 0, 0) taskMgr.add(self.clearSpaceFlag, 'clearFlags')
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) # TODO(@hart): position of pt-light needs to be fixed plight = PointLight('plight') plight.setColor((1, 1, 1, 1)) self.plnp = self.render.attachNewNode(plight) self.plnp.setPos(0, 0, 10000) self.render.setLight(self.plnp)
def __init__(self, game, duration=None, storage_path="storage/3d/frame", fps=30, as_gif=False, gif_name=None, size=(480, 480)): self.game = game self.duration = duration self.storage_path = storage_path self.fps = fps self.as_gif = as_gif self.gif_name = gif_name self.base = ShowBase(windowType='none') self.base.openWindow(type=('offscreen' if as_gif else 'onscreen'), size=size) depth, height, width = game.shape self.rhomdos = [] for z in range(depth): self.rhomdos.append([]) for y in range(height): self.rhomdos[-1].append([]) for x in range(width): rr = RhomdoRender((z, y, x), game.shape) render.attachNewNode(rr.geomnode) self.rhomdos[-1][-1].append(rr) plight = PointLight('plight') plight.setColor(VBase4(1, 1, 1, 1)) plight.setAttenuation((0, 0, .0005)) self.plnp = render.attachNewNode(plight) self.plnp.setPos(0, 0, (game.shape[0] * SR2) + 40) render.setLight(self.plnp) if self.as_gif: self.base.movie(self.storage_path, duration=self.duration, fps=self.fps) self.base.taskMgr.add(self.spinCameraTask, "SpinCameraTask") self.base.taskMgr.add(self.updateClock, "UpdateClock") self.frame = 0 self.game_step = 0
def setup_lights(self): pl = PointLight('pl') pl.setColor((1, 1, 1, 1)) plNP = self.render.attachNewNode(pl) plNP.setPos(-10, -10, 10) self.render.setLight(plNP) pos = [[[0, 0, 50], [0, 0, -10]], [[0, -50, 0], [0, 10, 0]], [[-50, 0, 0], [10, 0, 0]]] for i in pos: dl = Spotlight('dl') dl.setColor((1, 1, 1, 1)) dlNP = self.render.attachNewNode(dl) dlNP.setPos(*i[0]) dlNP.lookAt(*i[1]) dlNP.node().setShadowCaster(False) self.render.setLight(dlNP)
def apply(self, render): plight = PointLight("plight") plight.setColor( VBase4(self.color[0], self.color[1], self.color[2], self.color[3])) self.plnp = render.attachNewNode(plight) self.plnp.setPos(self.position[0], self.position[1], self.position[2]) render.setLight(self.plnp) builder = ModelBuilder() builder.add_box( nar([0, 0, 0]) - self.size / 2, nar([self.size, 0, 0]), nar([0, self.size, 0]), nar([0, 0, self.size]), self.color) self.path = render.attachNewNode(builder.build("plight_box")) self.path.setPos(self.position[0], self.position[1], self.position[2])
def __init__(self): #initialization self.title = OnscreenText( # display title text="""Mundus /u/adhoc92""", parent=base.a2dBottomRight, align=TextNode.A_right, style=1, fg=(1, 1, 1, 1), pos=(-0.1, 0.1), scale=.07) base.setBackgroundColor(0, 0, 0) # Set the background to black camera.setPos(0, 0, 45) # Set the camera position (X, Y, Z) camera.setHpr(0, -90, 0) # Set the camera orientation #(heading, pitch, roll) in degrees #sets up PointLighting to simulate Light coming from Magnus plight = PointLight('plight') plight.setColor((1, 1, 1, 1)) plnp = render.attachNewNode(plight) plnp.setPos(20, 0, 0) #position just in front of Magnus render.setLight(plnp) #because if pos set behind Magnus than the side of Magnus within the star sphere will not be illuminated #sets up AmbientLighting so that the dark side of plane(t)s/moons aren't /too/ dark. alight = AmbientLight('alight') alight.setColor((0.2, 0.2, 0.2, 1)) alnp = render.attachNewNode(alight) render.setLight(alnp) # Here again is where we put our global variables. Added this time are # variables to control the relative speeds of spinning and orbits in the # simulation # Number of seconds a full rotation of Earth around the sun should take self.yearscale = 60 # Number of seconds a day rotation of Earth should take. # It is scaled from its correct value for easier visability self.dayscale = self.yearscale / 364.0 * 15 # 364 days in Nirn year self.orbitscale = 2 # Orbit scale self.sizescale = 0.6 # Planet size scale self.loadPlanets() # Load and position the models # rotatePlanets function that puts the plane(t)s and moons into motion self.rotatePlanets()
def __init__(self): ShowBase.__init__(self) self.gameTask = taskMgr.add(self.flyCircles, "circles") base.disableMouse() base.camera.setPos(50, 100, 800) base.camera.lookAt(0, 0, 0) dl = DirectionalLight('dLight') dl.setColor(Vec4(0.1,0.1,0.1,1)) dlNP = render.attachNewNode(dl) dlNP.setPos(1000,1000,0) al = AmbientLight('alight') al.setColor(Vec4(0.3, 0.3, 0.3, 1)) alNP = render.attachNewNode(al) pl = PointLight('plight') pl.setColor(VBase4(0.2,0.2,0.2,1)) plNP = render.attachNewNode(pl) plNP.setPos(100,100,100) render.setLight(plNP) self.shipList = [ Bwing("xwing1"), TieInterceptor("tie1") ] for i, ship in enumerate(self.shipList): ship.reparentTo(render) ship.setScale(2) ship.setPos(Point3(i*10,i*0,i*0)) # ship.setLight(dlNP) ship.setLight(alNP) self.count = 0 self.iter = 0
def _addDefaultLighting(self): alight = AmbientLight('alight') alight.setColor(VBase4(0.2, 0.2, 0.2, 1)) alnp = self.render.attachNewNode(alight) self.render.setLight(alnp) # NOTE: Point light following the camera plight = PointLight('plight') plight.setColor(VBase4(0.9, 0.9, 0.9, 1)) plnp = self.cam.attachNewNode(plight) self.render.setLight(plnp) if self.shadowing: # Use a 512x512 resolution shadow map plight.setShadowCaster(True, 512, 512) # Enable the shader generator for the receiving nodes self.render.setShaderAuto() self.render.setAntialias(AntialiasAttrib.MAuto)
def __init__(self): ShowBase.__init__(self) base.disableMouse() # base.camera.setPos(0, 0, 0) dl = DirectionalLight('dLight') dl.setColor(Vec4(0.1, 0.1, 0.1, 1)) dlNP = render.attachNewNode(dl) dlNP.setPos(1000, 1000, 0) al = AmbientLight('alight') al.setColor(Vec4(0.3, 0.3, 0.3, 1)) alNP = render.attachNewNode(al) pl = PointLight('plight') pl.setColor(VBase4(0.2, 0.2, 0.2, 1)) plNP = render.attachNewNode(pl) plNP.setPos(100, 100, 100) render.setLight(plNP) xwing = Xwing("xwing1") tie = TieFighter("tie1") awing = Awing('awing1') self.shipList = [xwing, tie, awing] # xwing.weaponSystem.fireWeapon() for i, ship in enumerate(self.shipList): ship.reparentTo(render) ship.setScale(2) ship.setPos(Point3(i * 0, i * 400, i * 0)) # ship.setLight(dlNP) ship.setLight(alNP) base.camera.setPos(tie.getPos() + Vec3(20, 400, 0)) base.camera.lookAt(xwing.getPos()) taskMgr.add(self.clearSpaceFlag, 'clearFlags') self.camFilter = LpfVec3(Vec3(0, 0, 0), 10)
def activateStar(self, player): ''' Activates a constructed dead star object, starting the lifetime counter with the assigned default value while the Game Engine calls the graphic engine to display the corresponding animation. @param player, the player who has activated the star ''' self.lifetime = LIFETIME self.stage = 1 self.activated = True self.radius = MAX_STAR_RADIUS self.player = player self.timer_task = taskMgr.doMethodLater(1, self.trackStarLife, 'starLifeTick') player.selected_star = self # point_light = PointLight("starLight") # point_light.setColor(Vec4(1.0, 1.0, 1.0, 1.0)) # pt_node = render.attachNewNode(point_light) ## pt_node.setHpr(60, 0, 90) # pt_node.setPos(Vec3(0, 0, -40.0)) # render.setLight(pt_node) point_light = PointLight("starLight") point_light.setColor(Vec4(1.0, 1.0, 1.0, 1.0)) point_light.setPoint(Point3(0, 0, 0)) pt_node = self.point_path.attachNewNode(point_light) # pt_node.setHpr(60, 0, 90) render.setLight(pt_node) '''TODO : display star birth animation ''' star_created_sound = base.loader.loadSfx("sound/effects/star/starCreation1.wav") star_created_sound.setVolume(0.6) star_created_sound.play() # base.sfxManagerList[0].update() # SphericalBody.star_created_sound1.play() #SphericalBody.star_created_sound2.play() self.radius = MAX_STAR_RADIUS self.model_path.setScale(self.radius) self.model_path.setTexture(self.flare_ts, SphericalBody.star_stage1_tex) self._activateSunflare()
def setupLightSources(self, base, scene): for np in self.model.findAllMatches('**/=Light'): if np.getTag('Light') == 'Point': light = PointLight('PointLight.%d' % (len(self.lights) + 1,)) elif np.getTag('Light') == 'Spot': light = Spotlight('Spotlight.%d' % (len(self.lights) + 1,)) fov = np.getTag('Fov') if fov: light.getLens().setFov(float(fov)) nf = np.getTag('NearFar').split(',') if len(nf) > 1: light.getLens().setNearFar(float(nf[0]), float(nf[1])) exp = np.getTag('Exponent') if exp: light.setExponent(float(exp)) elif np.getTag('Light') == 'Directional': light = DirectionalLight('DirectionalLight.%d' % (len(self.lights) + 1,)) materials = np.findAllMaterials() if len(materials) > 0: light.setColor(materials[0].getDiffuse()) attenuation = np.getTag('Attenuation').split(',') if len(attenuation) > 0 and not isinstance(light, DirectionalLight): light.setAttenuation(tuple([float(a) for a in attenuation])) # if np.getTag('Shadow'): # self.model.setShaderAuto() # light.setShadowCaster(True) self.lights.append(light) lightNP = self.model.attachNewNode(light) lightNP.setPos(np.getPos()) lightNP.setHpr(np.getHpr()) # lightNP.setCompass() self.model.setLight(lightNP)
def __init__(self): ShowBase.__init__(self) self.disableMouse() self.camera.setPos(10, -80, 70) self.camera.lookAt(10, 20, 0) self.camLens.setFov(90.0) self.win.setClearColor(Vec4(0,0,0,0)) make_level(self.render) self.accept("escape", exit) self.accept("arrow_up", self.forward) self.accept("arrow_down", self.reverse) self.accept("arrow_left", self.turn_left) self.accept("arrow_right", self.turn_right) self.accept("1", self.set_camera) self.accept("2", self.set_camera_out) self.accept("3", self.spin_camera_left) self.accept("4", self.spin_camera_right) slight = PointLight('slight') slight.setColor(Vec4(1, 1, 1, 1)) slnp = render.attachNewNode(slight) render.setLight(slnp) slnp.setPos(self.camera, 0, 0, 20) alight = AmbientLight('alight') alight.setColor((0.2, 0.2, 0.2, 1)) alnp = render.attachNewNode(alight) render.setLight(alnp) title = OnscreenText(text="Bard's Tale I", style=1, fg=(1,1,1,1), pos=(0.7,0.92), scale = .07) self.dir = Direction() self.pos = Vector([0, 0]) self.set_camera() self.map = make_map()
def initializeLight(self): """ In dieser Methode werden 3 Lichtarten initialisiert. Es wird ein AmbientLight auf die Sonne gesetzt und ebenfalls ein AmbientLight und ein PointLight auf das gesamte System. Mittels "Vase4" wird hier eingestellt, wie stark das Licht das jeweilige Objekt beleuchten soll (je hoeher die Zahl, desto staerker wird beleuchtet). """ self.sunLight = AmbientLight('slight') self.sunLight.setColor(VBase4(1, 1, 1, 1)) sun = self.middle slnp = sun.model.attachNewNode(self.sunLight) sun.model.setLight(slnp) alight = AmbientLight('alight') alight.setColor(VBase4(0.2, 0.2, 0.2, 1)) self.alnp = render.attachNewNode(alight) plight = PointLight('plight') plight.setColor(VBase4(1, 1, 1, 1)) self.plnp = render.attachNewNode(plight) self.plnp.setPos(0, 0, 0) render.setLight(self.plnp)
def readLights(self,light_data): self.lights = [] i = 0 for light in light_data: name = '%s light %d' % (light['type'], i ) pl = None if light['type'] == 'point': pl = PointLight( name ) pl.setPoint(Point3(*light['pos'])) pl.setColor(Vec4(*light['color']) ) elif light['type'] == 'directional': pl = DirectionalLight( name ) pl.setColor(Vec4(*light['color']) ) elif light['type'] == 'ambient': pl = AmbientLight( name ) pl.setColor(Vec4(*light['color']) ) #not implemented #elif light['type'] == 'spotlight': # pl = Spotlight( name ) #if it's allright if pl != None: self.lights.append(NodePath(pl)) i += 1
def __readLights(self, root): lightCounter = 0 for entry in list(root): # read in the type of the light lightType = entry.get("type", default="PointLight").lower() light = None if lightType == "pointlight": light = PointLight("Pnt_Light%03d" % lightCounter) elif lightType == "directionallight": light = DirectionalLight("Dir_Light%03d" % lightCounter) elif lightType == "ambientlight": light = AmbientLight("Amb_Light%03d" % lightCounter) elif lightType == "spotlight": light = Spotlight("Spt_Light%03d" % lightCounter) if light != None: color = entry.find("color") if color != None: # set the light"s color r = float(color.get("r", "1")) g = float(color.get("g", "1")) b = float(color.get("b", "1")) a = float(color.get("a", "1")) light.setColor(VBase4(r, g, b, a)) # now create a new nodepath with the light lightnp = NodePath(light) # set the light"s position pos = self.__readPos(entry) lightnp.setPos(pos) # and it"s orientation hpr = self.__readHpr(entry) lightnp.setHpr(hpr) # finaly append the light to the list of lights self.leveldata.lights.append(lightnp) lightCounter += 1
def __init__(self): ShowBase.__init__(self) base.disableMouse() dl = DirectionalLight('dLight') dl.setColor(Vec4(0.1,0.1,0.1,1)) dlNP = render.attachNewNode(dl) dlNP.setPos(1000,1000,0) al = AmbientLight('alight') al.setColor(Vec4(0.3, 0.3, 0.3, 1)) alNP = render.attachNewNode(al) pl = PointLight('plight') pl.setColor(VBase4(0.2,0.2,0.2,1)) plNP = render.attachNewNode(pl) plNP.setPos(100,100,100) render.setLight(plNP) self.shipList = [ Xwing('xwing1'), TieInterceptor("interceptor1") ] for i, ship in enumerate(self.shipList): ship.reparentTo(render) ship.setScale(2) ship.setPos(Point3(i*0,i*50,i*0)) # ship.setLight(dlNP) ship.setLight(alNP) base.camera.setPos(-200,300,0) base.camera.lookAt(0, 0, 0) taskMgr.add(self.clearSpaceFlag, 'clearFlags')
def __init__(self): ShowBase.__init__(self) base.disableMouse() dl = DirectionalLight('dLight') dl.setColor(Vec4(0.1,0.1,0.1,1)) dlNP = render.attachNewNode(dl) dlNP.setPos(1000,1000,0) al = AmbientLight('alight') al.setColor(Vec4(0.3, 0.3, 0.3, 1)) alNP = render.attachNewNode(al) pl = PointLight('plight') pl.setColor(VBase4(0.2,0.2,0.2,1)) plNP = render.attachNewNode(pl) plNP.setPos(100,100,100) render.setLight(plNP) xwing = Xwing("xwing1") tie = TieFighter("tie1") awing = Awing('awing1') self.shipList = [xwing, tie, awing] for i, ship in enumerate(self.shipList): ship.reparentTo(render) ship.setScale(2) ship.setPos(Point3(i*0,i*400,i*0)) ship.setLight(alNP) base.camera.setPos(tie.getPos()+Vec3(20,400,0)) base.camera.lookAt(xwing.getPos()) taskMgr.add(self.clearSpaceFlag, 'clearFlags') self.camFilter = LpfVec3(Vec3(0,0,0),10)
def __init__(self): # simple level #self.environ = loader.loadModel("world") #self.environ.reparentTo(render) #self.environ.hide() self.environ = loader.loadModel("IndoorLevel01") self.environ.reparentTo(render) self.environ.hide() for i in range(9): #print "load lamp: Lamp.%03d" % i lampPos = self.environ.find("**/Lamp.%03d" % i).getPos() plight = PointLight('plight') plight.setColor(VBase4(0.2, 0.2, 0.2, 1)) plnp = render.attachNewNode(plight) plnp.setPos(lampPos) render.setLight(plnp) self.ambientlight = AmbientLight('ambient light') self.ambientlight.setColor(VBase4(0.2, 0.2, 0.2, 1)) self.ambientlightnp = render.attachNewNode(self.ambientlight) render.setLight(self.ambientlightnp)
def __init__(self, img_size=512, screen_off=True, target_area_radius=5, initial_area_radius=10, keyboard_input=False, random_reset_around_target=False, test=False): logging.info('random_reset_around_target :%s', random_reset_around_target) self.random_reset_around_target = random_reset_around_target self.keyboard_input = keyboard_input # Configure the parallax mapping settings (these are just the defaults) self.img_size = img_size self.initial_area_radius = initial_area_radius self.target_area_radius = target_area_radius loadPrcFileData("", "side-by-side-stereo 1") if test: loadPrcFileData("", "load-display p3tinydisplay") loadPrcFileData("", "transform-cache false") loadPrcFileData("", "audio-library-name null") # Prevent ALSA errors loadPrcFileData("", "win-size %d %d" % (2 * img_size, img_size)) loadPrcFileData("", "parallax-mapping-samples 3\n" "parallax-mapping-scale 0.1") if screen_off: # Spawn an offscreen buffer loadPrcFileData("", "window-type offscreen") # Initialize the ShowBase class from which we inherit, which will # create a window and set up everything we need for rendering into it. ShowBase.__init__(self) self.keyMap = { "left": 0, "right": 0, "forward": 0, "cam-left": 0, "cam-right": 0} # Load the 'abstract room' model. This is a model of an # empty room containing a pillar, a pyramid, and a bunch # of exaggeratedly bumpy textures. self.room = loader.loadModel("models/abstractroom") self.room.reparentTo(render) # Create the main character, Ralph ghost = BulletGhostNode('Ghost') ghostNP = render.attachNewNode(ghost) # self.agent = Actor("models/agent", # {"run": "models/agent-run", # "walk": "models/agent-walk"}) self.agent = ghostNP self.agent.reparentTo(render) # self.agent.setScale(.2) target = BulletGhostNode('target') self.navigation_target = render.attachNewNode(target) self.navigation_target.reparentTo(render) # knghit=Knight((0,0,0),(0.3,.3,.3,1)) self.pieces = [Piece(self.room) for _ in range(200)] ################################################## cnodePath = self.room.attachNewNode(CollisionNode('room')) plane = CollisionPlane(Plane(Vec3(1, 0, 0), Point3(-60, 0, 0))) # left cnodePath.node().addSolid(plane) plane = CollisionPlane( Plane(Vec3(-1, 0, 0), Point3(60, 0, 0))) # right cnodePath.node().addSolid(plane) plane = CollisionPlane(Plane(Vec3(0, 1, 0), Point3(0, -60, 0))) # back cnodePath.node().addSolid(plane) plane = CollisionPlane( Plane(Vec3(0, -1, 0), Point3(0, 60, 0))) # front cnodePath.node().addSolid(plane) sphere = CollisionSphere(-25, -25, 0, 12.5) # tube = CollisionTube(-25, -25,0 , -25, -25, 1, 12.5) cnodePath.node().addSolid(sphere) box = CollisionBox(Point3(5, 5, 0), Point3(45, 45, 10)) cnodePath.node().addSolid(box) # cnodePath.show() # Make the mouse invisible, turn off normal mouse controls self.disableMouse() # props = WindowProperties() # props.setCursorHidden(True) # self.win.requestProperties(props) # self.camLens.setFov(60) self.camLens.setFov(80) # Set the current viewing target self.focus = LVector3(55, -55, 20) self.heading = 180 self.pitch = 0 self.mousex = 0 self.mousey = 0 self.last = 0 self.mousebtn = [0, 0, 0] # Start the camera control task: # taskMgr.add(self.controlCamera, "camera-task") # self.accept("escape", sys.exit, [0]) # self.accept("enter", self.toggleShader) # self.accept("j", self.rotateLight, [-1]) # self.accept("k", self.rotateLight, [1]) # self.accept("arrow_left", self.rotateCam, [-1]) # self.accept("arrow_right", self.rotateCam, [1]) # Accept the control keys for movement and rotation self.accept("escape", sys.exit) self.accept("arrow_left", self.setKey, ["left", True]) self.accept("arrow_right", self.setKey, ["right", True]) self.accept("arrow_up", self.setKey, ["forward", True]) self.accept("a", self.setKey, ["cam-left", True]) self.accept("s", self.setKey, ["cam-right", True]) self.accept("arrow_left-up", self.setKey, ["left", False]) self.accept("arrow_right-up", self.setKey, ["right", False]) self.accept("arrow_up-up", self.setKey, ["forward", False]) self.accept("a-up", self.setKey, ["cam-left", False]) self.accept("s-up", self.setKey, ["cam-right", False]) # Add a light to the scene. self.lightpivot = render.attachNewNode("lightpivot") self.lightpivot.setPos(0, 0, 25) self.lightpivot.hprInterval(10, LPoint3(360, 0, 0)).loop() plight = PointLight('plight') plight.setColor((5, 5, 5, 1)) plight.setAttenuation(LVector3(0.7, 0.05, 0)) plnp = self.lightpivot.attachNewNode(plight) plnp.setPos(45, 0, 0) self.room.setLight(plnp) # Add an ambient light alight = AmbientLight('alight') alight.setColor((0.2, 0.2, 0.2, 1)) alnp = render.attachNewNode(alight) self.room.setLight(alnp) # Create a sphere to denote the light sphere = loader.loadModel("models/icosphere") sphere.reparentTo(plnp) # self.cameraModel = self.agent # self.win2 = self.openWindow() # self.win2.removeAllDisplayRegions() # self.dr2 = self.win2.makeDisplayRegion() # camNode = Camera('cam') # camNP = NodePath(camNode) # camNP.reparentTo(self.cameraModel) # camNP.setZ(150) # camNP.lookAt(self.cameraModel) # self.dr2.setCamera(camNP) # self.cam2 = camNP # Camera('cam')p # We will detect the height of the terrain by creating a collision # ray and casting it downward toward the terrain. One ray will # start above agent's head, and the other will start above the camera. # A ray may hit the terrain, or it may hit a rock or a tree. If it # hits the terrain, we can detect the height. If it hits anything # else, we rule that the move is illegal. self.cTrav = CollisionTraverser() cs = CollisionSphere(0, 0, 0, 0.2) cnodePath = self.agent.attachNewNode(CollisionNode('agent')) cnodePath.node().addSolid(cs) # cnodePath.show() self.ralphGroundHandler = CollisionHandlerQueue() self.cTrav.addCollider(cnodePath, self.ralphGroundHandler) cnodePath = self.navigation_target.attachNewNode( CollisionNode('target')) cnodePath.node().addSolid(CollisionSphere(0, 0, 0, 2)) self.cTrav.addCollider(cnodePath, self.ralphGroundHandler) # Tell Panda that it should generate shaders performing per-pixel # lighting for the room. self.room.setShaderAuto() self.shaderenable = 1 # tex = self.win.getScreenshot() # tex.setFormat(Texture.FDepthComponent) tex = Texture() self.depthmap = tex tex.setFormat(Texture.FDepthComponent) altBuffer = self.win.makeTextureBuffer( "hello", img_size, img_size, tex, True) self.altBuffer = altBuffer altCam = self.makeCamera(altBuffer) altCam.reparentTo(self.agent) # altRender) altCam.setZ(0.4) l = altCam.node().getLens() l.setFov(80) l.setNear(.1) camera.reparentTo(self.agent) camera.setZ(0.4) l = self.camLens # l.setFov(80) l.setNear(.1)
class MusicBox(DirectObject): def __init__(self): # Our standard title and instructions text self.title = OnscreenText(text="Panda3D: Tutorial - Music Box", parent=base.a2dBottomCenter, pos=(0, 0.08), scale=0.08, fg=(1, 1, 1, 1), shadow=(0, 0, 0, .5)) self.escapeText = OnscreenText(text="ESC: Quit", parent=base.a2dTopLeft, fg=(1, 1, 1, 1), pos=(0.06, -0.1), align=TextNode.ALeft, scale=.05) # Set up the key input self.accept('escape', sys.exit) # Fix the camera position base.disableMouse() # Loading sounds is done in a similar way to loading other things # Loading the main music box song self.musicBoxSound = loader.loadMusic('music/musicbox.ogg') self.musicBoxSound.setVolume(.5) # Volume is a percentage from 0 to 1 # 0 means loop forever, 1 (default) means # play once. 2 or higher means play that many times self.musicBoxSound.setLoopCount(0) # Set up a simple light. self.plight = PointLight("light") self.plight.setColor((0.7, 0.7, 0.5, 1)) light_path = base.render.attachNewNode(self.plight) light_path.setPos(0, 0, 20) base.render.setLight(light_path) alight = AmbientLight("ambient") alight.setColor((0.3, 0.3, 0.4, 1)) base.render.setLight(base.render.attachNewNode(alight)) # Enable per-pixel lighting base.render.setShaderAuto() # Sound objects do not have a pause function, just play and stop. So we will # Use this variable to keep track of where the sound is at when it was stoped # to impliment pausing self.musicTime = 0 # Loading the open/close effect # loadSFX and loadMusic are identical. They are often used for organization #(loadMusic is used for background music, loadSfx is used for other effects) self.lidSfx = loader.loadSfx('music/openclose.ogg') # The open/close file has both effects in it. Fortunatly we can use intervals # to easily define parts of a sound file to play self.lidOpenSfx = SoundInterval(self.lidSfx, duration=2, startTime=0) self.lidCloseSfx = SoundInterval(self.lidSfx, startTime=5) # For this tutorial, it seemed appropriate to have on screen controls. # The following code creates them. # This is a label for a slider self.sliderText = OnscreenText("Volume", pos=(-0.1, 0.87), scale=.07, fg=(1, 1, 1, 1), shadow=(0, 0, 0, 1)) # The slider itself. It calls self.setMusicBoxVolume when changed self.slider = DirectSlider(pos=(-0.1, 0, .75), scale=0.8, value=.50, command=self.setMusicBoxVolume) # A button that calls self.toggleMusicBox when pressed self.button = DirectButton(pos=(.9, 0, .75), text="Open", scale=.1, pad=(.2, .2), rolloverSound=None, clickSound=None, command=self.toggleMusicBox) # A variable to represent the state of the simulation. It starts closed self.boxOpen = False # Here we load and set up the music box. It was modeled in a complex way, so # setting it up will be complicated self.musicBox = loader.loadModel('models/MusicBox') self.musicBox.setPos(0, 60, -9) self.musicBox.reparentTo(render) # Just like the scene graph contains hierarchies of nodes, so can # models. You can get the NodePath for the node using the find # function, and then you can animate the model by moving its parts # To see the hierarchy of a model, use, the ls function # self.musicBox.ls() prints out the entire hierarchy of the model # Finding pieces of the model self.Lid = self.musicBox.find('**/lid') self.Panda = self.musicBox.find('**/turningthing') # This model was made with the hinge in the wrong place # this is here so we have something to turn self.HingeNode = self.musicBox.find( '**/box').attachNewNode('nHingeNode') self.HingeNode.setPos(.8659, 6.5, 5.4) # WRT - ie with respect to. Reparents the object without changing # its position, size, or orientation self.Lid.wrtReparentTo(self.HingeNode) self.HingeNode.setHpr(0, 90, 0) # This sets up an interval to play the close sound and actually close the box # at the same time. self.lidClose = Parallel( self.lidCloseSfx, LerpHprInterval(self.HingeNode, 2.0, (0, 90, 0), blendType='easeInOut')) # Same thing for opening the box self.lidOpen = Parallel( self.lidOpenSfx, LerpHprInterval(self.HingeNode, 2.0, (0, 0, 0), blendType='easeInOut')) # The interval for turning the panda self.PandaTurn = self.Panda.hprInterval(7, (360, 0, 0)) # Do a quick loop and pause to set it as a looping interval so it can be # started with resume and loop properly self.PandaTurn.loop() self.PandaTurn.pause() def setMusicBoxVolume(self): # Simply reads the current value from the slider and sets it in the # sound newVol = self.slider.guiItem.getValue() self.musicBoxSound.setVolume(newVol) def toggleMusicBox(self): #if self.lidOpen.isPlaying() or self.lidClose.isPlaying(): # # It's currently already opening or closing # return if self.boxOpen: self.lidOpen.pause() self.lidClose.start() # Start the close box interval self.PandaTurn.pause() # Pause the figurine turning # Save the current time of the music self.musicTime = self.musicBoxSound.getTime() self.musicBoxSound.stop() # Stop the music self.button['text'] = "Open" # Prepare to change button label else: self.lidClose.pause() self.lidOpen.start() # Start the open box interval self.PandaTurn.resume() # Resume the figuring turning # Reset the time of the music so it starts where it left off self.musicBoxSound.setTime(self.musicTime) self.musicBoxSound.play() # Play the music self.button['text'] = "Close" # Prepare to change button label self.button.setText() # Actually change the button label # Set our state to opposite what it was self.boxOpen = not self.boxOpen
def __init__(self): # Set up the window, camera, etc. ShowBase.__init__(self) #self.setupCD() # Set the background color to black # self.win.setClearColor((0.6, 0.6, 1.0, 1.0)) # self.fog = Fog('myFog') # self.fog.setColor(0, 0, 0) # self.fog.setExpDensity(.05) # render.setFog(self.fog) # This is used to store which keys are currently pressed. self.keyMap = { "left": 0, "right": 0, "forward": 0, "cam-left": 0, "cam-right": 0, "c":0, "back":0, "space":0} # Post the instructions #self.title = addTitle( # "Panda3D Tutorial: Roaming Ralph (Walking on Uneven Terrain)") self.inst1 = addInstructions(0.06, "[ESC]: Quit") self.inst2 = addInstructions(0.12, "[Left Arrow]: Rotate Ralph Left") self.inst3 = addInstructions(0.18, "[Right Arrow]: Rotate Ralph Right") self.inst4 = addInstructions(0.24, "[Up Arrow]: Run Ralph Forward") #self.inst6 = addInstructions(0.30, "[A]: Rotate Camera Left") #self.inst7 = addInstructions(0.36, "[S]: Rotate Camera Right") # Set up the environment # # This environment model contains collision meshes. If you look # in the egg file, you will see the following: # # <Collide> { Polyset keep descend } # # This tag causes the following mesh to be converted to a collision # mesh -- a mesh which is optimized for collision, not rendering. # It also keeps the original mesh, so there are now two copies --- # one optimized for rendering, one for collisions. self.environ = loader.loadModel("models/world") #self.environ.reparentTo(render) self.room = loader.loadModel("models/room2.egg") self.room.reparentTo(render) #self.room.setScale(.1) self.room.setPos(0,0,-5) self.room.setShaderAuto() #self.room.writeBamFile("myRoom1.bam") #self.room.setColor(1,.3,.3,1) self.room2 = loader.loadModel("models/abstractroom2") self.room2.reparentTo(render) self.room2.setScale(.1) self.room2.setPos(-12,0,0) # Create the main character, Ralph #ralphStartPos = LVecBase3F(0,0,0) #self.room.find("**/start_point").getPos() self.ralph = Actor("models/ralph", {"run": "models/ralph-run", "walk": "models/ralph-walk"}) self.ralph.reparentTo(render) self.ralph.setScale(.2) self.ralph.setPos(0,0,0) #cs = CollisionSphere(0, 0, 0, 1) #cnodePath = self.ralph.attachNewNode(CollisionNode('cnode')) #cnodePath.node().addSolid(cs) #cnodePath.node().setPos(0,0,0) #cnodePath.show() self.gianteye = loader.loadModel("models/gianteye") self.gianteye.reparentTo(render) self.gianteye.setScale(.1) self.gianteye.setPos(10,10,0) #self.bluefinal = loader.loadModel("models/chrysalis") #self.bluefinal.reparentTo(render) #self.bluefinal.setScale(.1) #self.bluefinal.setPos(7,7,0) #self.blue = loader.loadModel("models/blue1") #self.blue.reparentTo(render) #self.blue.setScale(.1) #self.blue.setPos(10,5,0) self.chik = loader.loadModel("models/chik") self.chik.reparentTo(render) self.chik.setScale(.1) self.chik.setPos(3,13,0) self.pawn = loader.loadModel("pawn") self.pawn.reparentTo(render) self.pawn.setPos(0,0,0) self.shot = loader.loadModel("models/icosphere.egg") self.shot.reparentTo(render) self.shot.setScale(.5) self.shot.setPos(0,0,1) self.shot.setColor(1,.3,.3,1) self.myShot = loader.loadModel("models/icosphere.egg") #self.myShot.reparentTo(render) self.myShot.setScale(.1) self.myShot.setPos(0,0,1) self.myShotVec = LVector3(0,0,0) self.lightpivot3 = render.attachNewNode("lightpivot3") self.lightpivot3.setPos(0, 0, 0) self.lightpivot3.hprInterval(10, LPoint3(0, 0, 0)).loop() plight3 = PointLight('plight2') plight3.setColor((0, .3,0, 1)) plight3.setAttenuation(LVector3(0.7, 0.05, 0)) plnp3 = self.lightpivot3.attachNewNode(plight3) plnp3.setPos(0, 0, 0) self.room2.setLight(plnp3) self.room.setLight(plnp3) sphere3 = loader.loadModel("models/icosphere") sphere3.reparentTo(plnp3) sphere3.setScale(0.1) sphere3.setColor((0,1,0,1)) # Create a floater object, which floats 2 units above ralph. We # use this as a target for the camera to look at. self.floater = NodePath(PandaNode("floater")) self.floater.reparentTo(self.ralph) self.floater.setZ(8.0) # Accept the control keys for movement and rotation self.accept("escape", sys.exit) self.accept("arrow_left", self.setKey, ["left", True]) self.accept("arrow_right", self.setKey, ["right", True]) self.accept("arrow_up", self.setKey, ["forward", True]) self.accept("arrow_down", self.setKey, ["back", True]) self.accept("a", self.setKey, ["cam-left", True]) self.accept("s", self.setKey, ["cam-right", True]) self.accept("arrow_left-up", self.setKey, ["left", False]) self.accept("arrow_right-up", self.setKey, ["right", False]) self.accept("arrow_up-up", self.setKey, ["forward", False]) self.accept("arrow_down-up", self.setKey, ["back", False]) self.accept("a-up", self.setKey, ["cam-left", False]) self.accept("s-up", self.setKey, ["cam-right", False]) self.accept("space", self.setKey, ["space", True]) self.accept("space-up", self.setKey, ["space", False]) self.accept("c",self.setKey,["c",True]) self.accept("c-up",self.setKey,["c",False]) taskMgr.add(self.move, "moveTask") # Game state variables self.isMoving = False self.jumping = False self.vz = 0 # Set up the camera self.disableMouse() self.camera.setPos(self.ralph.getX(), self.ralph.getY() + 7, 3) self.camLens.setFov(60) # We will detect the height of the terrain by creating a collision # ray and casting it downward toward the terrain. One ray will # start above ralph's head, and the other will start above the camera. # A ray may hit the terrain, or it may hit a rock or a tree. If it # hits the terrain, we can detect the height. If it hits anything # else, we rule that the move is illegal. def setupCollision(self): cs = CollisionSphere(0,0,2,1) cnodePath = self.ralph.attachNewNode(CollisionNode('cnode')) cnodePath.node().addSolid(cs) cnodePath.show() #for o in self.OBS: #ct = CollisionTube(0,0,0, 0,0,1, 0.5) #cn = o.attachNewNode(CollisionNode('ocnode')) #cn.node().addSolid(ct) #cn.show() eyecs = CollisionSphere(0,0,4,5) cnodePath = self.gianteye.attachNewNode(CollisionNode('cnode')) cnodePath.node().addSolid(eyecs) cnodePath.show() eyecs = CollisionSphere(0,0,4,2) cnodePath = self.chik.attachNewNode(CollisionNode('cnode')) cnodePath.node().addSolid(eyecs) cnodePath.show() pusher = CollisionHandlerPusher() pusher.addCollider(cnodePath, self.player) self.cTrav = CollisionTraverser() self.cTrav.add_collider(cnodePath,pusher) self.cTrav.showCollisions(render) self.walls = self.room2.find("**/wall_collide") #self.walls.node().setIntoCollideMask(BitMask32.bit(0)) self.cTrav = CollisionTraverser() self.ralphGroundRay = CollisionRay() self.ralphGroundRay.setOrigin(0, 0, 9) self.ralphGroundRay.setDirection(0, 0, -1) self.ralphGroundCol = CollisionNode('ralphRay') self.ralphGroundCol.addSolid(self.ralphGroundRay) self.ralphGroundCol.setFromCollideMask(CollideMask.bit(0)) self.ralphGroundCol.setIntoCollideMask(CollideMask.allOff()) self.ralphGroundColNp = self.ralph.attachNewNode(self.ralphGroundCol) self.ralphGroundHandler = CollisionHandlerQueue() self.cTrav.addCollider(self.ralphGroundColNp, self.ralphGroundHandler) self.camGroundRay = CollisionRay() self.camGroundRay.setOrigin(0, 0, 9) self.camGroundRay.setDirection(0, 0, -1) self.camGroundCol = CollisionNode('camRay') self.camGroundCol.addSolid(self.camGroundRay) self.camGroundCol.setFromCollideMask(CollideMask.bit(0)) self.camGroundCol.setIntoCollideMask(CollideMask.allOff()) self.camGroundColNp = self.camera.attachNewNode(self.camGroundCol) self.camGroundHandler = CollisionHandlerQueue() self.cTrav.addCollider(self.camGroundColNp, self.camGroundHandler) self.sphere = CollisionSphere(0,0,4,2) self.sphere2 = CollisionSphere(0,0,2,2) self.cnodePath = self.ralph.attachNewNode((CollisionNode('cnode'))) self.cnodePath.node().addSolid(self.sphere) self.cnodePath.node().addSolid(self.sphere2) self.cnodePath.show() self.pusher = CollisionHandlerPusher() self.pusher.addCollider(self.cnodePath, self.ralph) self.cTrav.add_collider(self.cnodePath, self.pusher) self.eyecs = CollisionSphere(0,0,22,25) self.cnodePath1 = self.gianteye.attachNewNode(CollisionNode('cnode')) self.cnodePath1.node().addSolid(self.eyecs) self.cnodePath1.show() self.pusher1 = CollisionHandlerPusher() self.pusher1.addCollider(self.cnodePath1, self.gianteye) self.cTrav.add_collider(self.cnodePath1, self.pusher1) self.cTrav.showCollisions(render) self.eyeGroundRay = CollisionRay() self.eyeGroundRay.setOrigin(0, 0, 9) self.eyeGroundRay.setDirection(0, 0, -1) self.eyeGroundCol = CollisionNode('eyeRay') self.eyeGroundCol.addSolid(self.eyeGroundRay) self.eyeGroundCol.setFromCollideMask(CollideMask.bit(0)) self.eyeGroundCol.setIntoCollideMask(CollideMask.allOff()) self.eyeGroundColNp = self.gianteye.attachNewNode(self.eyeGroundCol) self.eyeGroundHandler = CollisionHandlerQueue() self.cTrav.addCollider(self.eyeGroundColNp, self.eyeGroundHandler) self.chikcs = CollisionSphere(0,0,11,20) self.cnodePath2 = self.chik.attachNewNode(CollisionNode('cnode')) self.cnodePath2.node().addSolid(self.chikcs) self.cnodePath2.show() self.pusher2 = CollisionHandlerPusher() self.pusher2.addCollider(self.cnodePath, self.chik) self.cTrav.add_collider(self.cnodePath, self.pusher2) self.cTrav.showCollisions(render) self.chikGroundRay = CollisionRay() self.chikGroundRay.setOrigin(0, 0, 9) self.chikGroundRay.setDirection(0, 0, -1) self.chikGroundCol = CollisionNode('chikRay') self.chikGroundCol.addSolid(self.chikGroundRay) self.chikGroundCol.setFromCollideMask(CollideMask.bit(0)) self.chikGroundCol.setIntoCollideMask(CollideMask.allOff()) self.chikGroundColNp = self.chik.attachNewNode(self.chikGroundCol) self.chikGroundHandler = CollisionHandlerQueue() self.cTrav.addCollider(self.chikGroundColNp, self.chikGroundHandler) # Uncomment this line to see the collision rays self.ralphGroundColNp.show() self.camGroundColNp.show() #self.ralphroom1ColNp.show() # Uncomment this line to show a visual representation of the # collisions occuring #self.cTrav.showCollisions(render) # Create some lighting ambientLight = AmbientLight("ambientLight") ambientLight.setColor((.3, .3, .3, .4)) ambientLight2 = AmbientLight("ambientLight2") ambientLight2.setColor((1, 1, 1, 10)) directionalLight = DirectionalLight("directionalLight") directionalLight.setDirection((0, 0, -2)) directionalLight.setColor((1, 1, 1, 1)) directionalLight.setSpecularColor((1, 1, 1, 1)) render.setLight(render.attachNewNode(ambientLight)) #self.environ.setLight(self.environ.attachNewNode(ambientLight2)) render.setLight(render.attachNewNode(directionalLight)) # Add a light to the scene. self.lightpivot = render.attachNewNode("lightpivot") self.lightpivot.setPos(0, 0, 1.6) self.lightpivot.hprInterval(20, LPoint3(360, 0, 0)).loop() plight = PointLight('plight') plight.setColor((.7, .3, 0, 1)) plight.setAttenuation(LVector3(0.7, 0.05, 0)) plnp = self.lightpivot.attachNewNode(plight) plnp.setPos(5, 0, 0) self.room.setLight(plnp) sphere = loader.loadModel("models/icosphere") sphere.reparentTo(plnp) sphere.setScale(0.1) sphere.setColor((1,1,0,1)) self.lightpivot2 = render.attachNewNode("lightpivot") self.lightpivot2.setPos(-16, 0, 1.6) self.lightpivot2.hprInterval(20, LPoint3(360, 0, 0)).loop() plight2 = PointLight('plight2') plight2.setColor((0, .4,.8, 1)) plight2.setAttenuation(LVector3(0.7, 0.05, 0)) plnp2 = self.lightpivot2.attachNewNode(plight2) plnp2.setPos(5, 0, 0) self.room2.setLight(plnp2) sphere2 = loader.loadModel("models/icosphere") sphere2.reparentTo(plnp2) sphere2.setScale(0.2) sphere2.setColor((0,0,1,1)) self.vec = LVector3(0,1,0)
def __init__(self, img_size=512, screen_off=True): self.img_size = img_size loadPrcFileData("", "transform-cache false") loadPrcFileData("", "audio-library-name null") # Prevent ALSA errors loadPrcFileData("", "win-size %d %d" % (img_size, img_size)) loadPrcFileData("", "parallax-mapping-samples 3\n" "parallax-mapping-scale 0.1") if screen_off: # Spawn an offscreen buffer loadPrcFileData("", "window-type offscreen") # Initialize the ShowBase class from which we inherit, which will # create a window and set up everything we need for rendering into it. ShowBase.__init__(self) # Load the 'abstract room' model. This is a model of an # empty room containing a pillar, a pyramid, and a bunch # of exaggeratedly bumpy textures. self.room = loader.loadModel("models/abstractroom") self.room.reparentTo(render) # Create the main character, Ralph self.ralph = Actor("models/ralph", {"run": "models/ralph-run", "walk": "models/ralph-walk"}) self.ralph.reparentTo(render) self.ralph.setScale(.2) self.reset() self.pieces = [Piece(self.room) for _ in range(200)] ################################################## cnodePath = self.room.attachNewNode(CollisionNode('cnode')) plane = CollisionPlane(Plane(Vec3(1, 0, 0), Point3(-60, 0, 0))) # left cnodePath.node().addSolid(plane) plane = CollisionPlane( Plane(Vec3(-1, 0, 0), Point3(60, 0, 0))) # right cnodePath.node().addSolid(plane) plane = CollisionPlane(Plane(Vec3(0, 1, 0), Point3(0, -60, 0))) # back cnodePath.node().addSolid(plane) plane = CollisionPlane( Plane(Vec3(0, -1, 0), Point3(0, 60, 0))) # front cnodePath.node().addSolid(plane) sphere = CollisionSphere(-25, -25, 0, 12.5) cnodePath.node().addSolid(sphere) box = CollisionBox(Point3(5, 5, 0), Point3(45, 45, 10)) cnodePath.node().addSolid(box) # Make the mouse invisible, turn off normal mouse controls self.disableMouse() self.camLens.setFov(80) # Set the current viewing target self.focus = LVector3(55, -55, 20) self.heading = 180 self.pitch = 0 self.mousex = 0 self.mousey = 0 self.last = 0 self.mousebtn = [0, 0, 0] # Add a light to the scene. self.lightpivot = render.attachNewNode("lightpivot") self.lightpivot.setPos(0, 0, 25) self.lightpivot.hprInterval(10, LPoint3(360, 0, 0)).loop() plight = PointLight('plight') plight.setColor((5, 5, 5, 1)) plight.setAttenuation(LVector3(0.7, 0.05, 0)) plnp = self.lightpivot.attachNewNode(plight) plnp.setPos(45, 0, 0) self.room.setLight(plnp) # Add an ambient light alight = AmbientLight('alight') alight.setColor((0.2, 0.2, 0.2, 1)) alnp = render.attachNewNode(alight) self.room.setLight(alnp) # Create a sphere to denote the light sphere = loader.loadModel("models/icosphere") sphere.reparentTo(plnp) self.cameraModel = self.ralph camera.reparentTo(self.cameraModel) camera.setZ(2) self.cTrav = CollisionTraverser() cs = CollisionSphere(0, 0, 0, 1) cnodePath = self.ralph.attachNewNode(CollisionNode('cnode')) cnodePath.node().addSolid(cs) cnodePath.show() self.ralphGroundHandler = CollisionHandlerQueue() self.cTrav.addCollider(cnodePath, self.ralphGroundHandler) self.cnodePath = cnodePath # Tell Panda that it should generate shaders performing per-pixel # lighting for the room. self.room.setShaderAuto() self.shaderenable = 1 tex = Texture() self.depthmap = tex tex.setFormat(Texture.FDepthComponent) altBuffer = self.win.makeTextureBuffer( "hello", img_size, img_size, tex, True) self.altBuffer = altBuffer altCam = self.makeCamera(altBuffer) altCam.reparentTo(self.ralph) # altRender) altCam.setZ(2) l = altCam.node().getLens() l.setFov(80)
def drawGame(self, game): if not self.gameReady: self.game = game # menu = OnscreenImage(image = 'textures/menu.png', pos = (1.53, 0, 0), scale=(0.35, 1, 1)) # menu.setTransparency(TransparencyAttrib.MAlpha) # setup the background of the board self.environ = self.loader.loadModel('models/plane') sea = self.loader.loadTexture('textures/sea.png') self.environ.setTexture(sea) self.environ.setPos(0, 1, 0) self.environ.setScale(1.1) sea.setWrapU(Texture.WM_repeat) sea.setWrapV(Texture.WM_repeat) self.environ.reparentTo(self.render) # setup camera self.camera.setPos(0, 0, 10) self.camera.setHpr(0, -70, 0) self.camLens.setNear(0.85) # setup lighting plight = PointLight('plight') plight.setColor(VBase4(1, 1, 1, 3)) plnp = self.render.attachNewNode(plight) plnp.setPos(10, 0, 10) self.render.setLight(plnp) ambientLight = AmbientLight('ambientLight') ambientLight.setColor(Vec4(0.25, 0.25, 0.25, .3)) ambientLightNP = self.render.attachNewNode(ambientLight) self.render.setLight(ambientLightNP) # place islands first = True for island in game.board.islands: island.drawable = True island.model = self.loader.loadModel('models/island2_104') self.drawIsland(island, first) first = False self.drawFigures() self.drawSeaways() self.turn = OnscreenText(text='Black\'s turn.', pos=(0.06, -0.1), align=TextNode.ALeft, parent=base.a2dTopLeft, scale=0.06) self.resources = OnscreenText(text='Resources: ', pos=(0.08, -0.2), align=TextNode.ALeft, parent=base.a2dTopLeft, scale=0.06) self.gameReady = True player = 'Black' if game.turn == 1: player = 'White' self.turn.setText(player + '\'s turn.') resourcesText = 'Resources: ' + \ str(self.game.currentPlayer().resources) self.resources.setText(resourcesText) if self.game.loosers != None: message = OnscreenText(text='End of the game', align=TextNode.ACenter, pos=(0, 0), scale=0.1) if self.game.loosers == 'black': message.setText('White wins!') elif self.game.loosers == 'white': message.setText('Black wins!') else: message.setText('Nobody wins!')
def __init__(self): # Configure the parallax mapping settings (these are just the defaults) loadPrcFileData("", "parallax-mapping-samples 3\n" "parallax-mapping-scale 0.1") # Initialize the ShowBase class from which we inherit, which will # create a window and set up everything we need for rendering into it. ShowBase.__init__(self) # Check video card capabilities. if not self.win.getGsg().getSupportsBasicShaders(): addTitle("Bump Mapping: " "Video driver reports that Cg shaders are not supported.") return # Post the instructions self.title = addTitle("Panda3D: Tutorial - Bump Mapping") self.inst1 = addInstructions(0.06, "Press ESC to exit") self.inst2 = addInstructions(0.12, "Move mouse to rotate camera") self.inst3 = addInstructions(0.18, "Left mouse button: Move forwards") self.inst4 = addInstructions(0.24, "Right mouse button: Move backwards") self.inst5 = addInstructions(0.30, "Enter: Turn bump maps Off") # Load the 'abstract room' model. This is a model of an # empty room containing a pillar, a pyramid, and a bunch # of exaggeratedly bumpy textures. self.room = loader.loadModel("models/abstractroom") self.room.reparentTo(render) # Make the mouse invisible, turn off normal mouse controls self.disableMouse() props = WindowProperties() props.setCursorHidden(True) self.win.requestProperties(props) self.camLens.setFov(60) # Set the current viewing target self.focus = LVector3(55, -55, 20) self.heading = 180 self.pitch = 0 self.mousex = 0 self.mousey = 0 self.last = 0 self.mousebtn = [0, 0, 0] # Start the camera control task: taskMgr.add(self.controlCamera, "camera-task") self.accept("escape", sys.exit, [0]) self.accept("mouse1", self.setMouseBtn, [0, 1]) self.accept("mouse1-up", self.setMouseBtn, [0, 0]) self.accept("mouse2", self.setMouseBtn, [1, 1]) self.accept("mouse2-up", self.setMouseBtn, [1, 0]) self.accept("mouse3", self.setMouseBtn, [2, 1]) self.accept("mouse3-up", self.setMouseBtn, [2, 0]) self.accept("enter", self.toggleShader) self.accept("j", self.rotateLight, [-1]) self.accept("k", self.rotateLight, [1]) self.accept("arrow_left", self.rotateCam, [-1]) self.accept("arrow_right", self.rotateCam, [1]) # Add a light to the scene. self.lightpivot = render.attachNewNode("lightpivot") self.lightpivot.setPos(0, 0, 25) self.lightpivot.hprInterval(10, LPoint3(360, 0, 0)).loop() plight = PointLight('plight') plight.setColor((1, 1, 1, 1)) plight.setAttenuation(LVector3(0.7, 0.05, 0)) plnp = self.lightpivot.attachNewNode(plight) plnp.setPos(45, 0, 0) self.room.setLight(plnp) # Add an ambient light alight = AmbientLight('alight') alight.setColor((0.2, 0.2, 0.2, 1)) alnp = render.attachNewNode(alight) self.room.setLight(alnp) # Create a sphere to denote the light sphere = loader.loadModel("models/icosphere") sphere.reparentTo(plnp) # Tell Panda that it should generate shaders performing per-pixel # lighting for the room. self.room.setShaderAuto() self.shaderenable = 1
def __init__(self): # Check video card capabilities. if base.win.getGsg().getSupportsBasicShaders() == 0: addTitle("Bump Mapping: Video driver reports that shaders are not supported.") return # Post the instructions self.title = addTitle("Panda3D: Tutorial - Bump Mapping") self.inst1 = addInstructions(0.95, "Press ESC to exit") self.inst2 = addInstructions(0.90, "Move mouse to rotate camera") self.inst3 = addInstructions(0.85, "Left mouse button: Move forwards") self.inst4 = addInstructions(0.80, "Right mouse button: Move backwards") self.inst5 = addInstructions(0.75, "Enter: Turn bump maps Off") # Load the 'abstract room' model. This is a model of an # empty room containing a pillar, a pyramid, and a bunch # of exaggeratedly bumpy textures. self.room = loader.loadModel("models/abstractroom") self.room.reparentTo(render) # Make the mouse invisible, turn off normal mouse controls base.disableMouse() props = WindowProperties() props.setCursorHidden(True) base.win.requestProperties(props) # Set the current viewing target self.focus = Vec3(55, -55, 20) self.heading = 180 self.pitch = 0 self.mousex = 0 self.mousey = 0 self.last = 0 self.mousebtn = [0, 0, 0] # Start the camera control task: taskMgr.add(self.controlCamera, "camera-task") self.accept("escape", sys.exit, [0]) self.accept("mouse1", self.setMouseBtn, [0, 1]) self.accept("mouse1-up", self.setMouseBtn, [0, 0]) self.accept("mouse2", self.setMouseBtn, [1, 1]) self.accept("mouse2-up", self.setMouseBtn, [1, 0]) self.accept("mouse3", self.setMouseBtn, [2, 1]) self.accept("mouse3-up", self.setMouseBtn, [2, 0]) self.accept("enter", self.toggleShader) self.accept("j", self.rotateLight, [-1]) self.accept("k", self.rotateLight, [1]) self.accept("arrow_left", self.rotateCam, [-1]) self.accept("arrow_right", self.rotateCam, [1]) # Add a light to the scene. self.lightpivot = render.attachNewNode("lightpivot") self.lightpivot.setPos(0, 0, 25) self.lightpivot.hprInterval(10, Point3(360, 0, 0)).loop() plight = PointLight("plight") plight.setColor(Vec4(1, 1, 1, 1)) plight.setAttenuation(Vec3(0.7, 0.05, 0)) plnp = self.lightpivot.attachNewNode(plight) plnp.setPos(45, 0, 0) self.room.setLight(plnp) # Add an ambient light alight = AmbientLight("alight") alight.setColor(Vec4(0.2, 0.2, 0.2, 1)) alnp = render.attachNewNode(alight) self.room.setLight(alnp) # create a sphere to denote the light sphere = loader.loadModel("models/sphere") sphere.reparentTo(plnp) # load and apply the shader. This is using panda's # built-in shader generation capabilities to create the # shader for you. However, if desired, you can supply # the shader manually. Change this line of code to: # self.room.setShaderInput("light", plnp) # self.room.setShader(Shader.load("bumpMapper.sha")) self.room.setShaderAuto() self.shaderenable = 1