Пример #1
0
    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)
Пример #2
0
 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)
Пример #3
0
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 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()
Пример #5
0
    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)
Пример #6
0
 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)
Пример #7
0
 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)
Пример #8
0
    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")
Пример #9
0
    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()
Пример #10
0
    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)
Пример #11
0
    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))
Пример #12
0
    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)
Пример #13
0
    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")
Пример #14
0
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()
Пример #15
0
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
Пример #16
0
 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 __init__(self):
        base.disableMouse()
        base.cam.node().getLens().setNear(10.0)
        base.cam.node().getLens().setFar(9999999)
        camera.setPos(0, -50, 0)
        
        # Check video card capabilities.
        
        if (base.win.getGsg().getSupportsBasicShaders() == 0):
            addTitle("Toon Shader: Video driver reports that shaders are not supported.")
            return
        
        # Enable a 'light ramp' - this discretizes the lighting,
        # which is half of what makes a model look like a cartoon.
        # Light ramps only work if shader generation is enabled,
        # so we call 'setShaderAuto'.

        tempnode = NodePath(PandaNode("temp node"))
        tempnode.setAttrib(LightRampAttrib.makeSingleThreshold(0.5, 0.4))
        tempnode.setShaderAuto()
        base.cam.node().setInitialState(tempnode.getState())
        
        # Use class 'CommonFilters' to enable a cartoon inking filter.
        # This can fail if the video card is not powerful enough, if so,
        # display an error and exit.
        
        self.separation = 1 # Pixels
        self.filters = CommonFilters(base.win, base.cam)
        filterok = self.filters.setCartoonInk(separation=self.separation)
        if (filterok == False):
            addTitle("Toon Shader: Video card not powerful enough to do image postprocessing")
            return
        
        # Create a non-attenuating point light and an ambient light.
        
        plightnode = PointLight("point light")
        plightnode.setAttenuation(Vec3(1,0,0))
        plight = render.attachNewNode(plightnode)
        plight.setPos(30,-50,0)
        alightnode = AmbientLight("ambient light")
        alightnode.setColor(Vec4(0.8,0.8,0.8,1))
        alight = render.attachNewNode(alightnode)
        render.setLight(alight)
        render.setLight(plight)
        
        # Panda contains a built-in viewer that lets you view the 
        # results of all render-to-texture operations.  This lets you
        # see what class CommonFilters is doing behind the scenes.
        
        self.accept("v", base.bufferViewer.toggleEnable)
        self.accept("V", base.bufferViewer.toggleEnable)
        base.bufferViewer.setPosition("llcorner")
        self.accept("s", self.filters.manager.resizeBuffers)
        
        # These allow you to change cartooning parameters in realtime
        
        self.accept("escape", sys.exit, [0])
Пример #18
0
	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))

		"""
Пример #19
0
    def __init__(self):
        ShowBase.__init__(self)
        dir(self)
        self.disableMouse()

        # Load the environment model.
        self.environ = self.loader.loadModel("../levels/level01.egg")
        # Reparent the model to render.
        self.environ.reparentTo(self.render)
        '''add a light'''
        self.light = PointLight("dLight")
        self.light.setAttenuation((.01, .01, .01))
        self.light.setSpecularColor(VBase4(1, 1, 0, 1))
        self.lightNode = render.attachNewNode(self.light)
        self.lightNode.setZ(10)
        render.setLight(self.lightNode)
        '''move light constants'''
        self.moveLightDirection = -1000

        self.taskMgr.add(self.moveLight, "lightMove")
        self.taskMgr.add(self.fpsInput, "fpsInput")
        '''fps cam controls'''
        self.keymap = {
            "w": 0,
            "a": 0,
            "s": 0,
            "d": 0,
            "e": 0,
            "q": 0,
            "j": 0,
            "k": 0,
            "l": 0,
            "i": 0
        }

        self.fps = FpsCam(self.camera)
        self.accept("a", self.setKey, ["a", 1])
        self.accept("a-up", self.setKey, ['a', 0])
        self.accept("w", self.setKey, ["w", 1])
        self.accept("w-up", self.setKey, ["w", 0])
        self.accept("s", self.setKey, ["s", 1])
        self.accept("s-up", self.setKey, ["s", 0])
        self.accept("d", self.setKey, ["d", 1])
        self.accept("d-up", self.setKey, ["d", 0])
        self.accept("e", self.setKey, ["e", 1])
        self.accept("e-up", self.setKey, ["e", 0])
        self.accept("q", self.setKey, ["q", 1])
        self.accept("q-up", self.setKey, ["q", 0])
        self.accept("j", self.setKey, ["j", 1])
        self.accept("j-up", self.setKey, ["j", 0])
        self.accept("k", self.setKey, ["k", 1])
        self.accept("k-up", self.setKey, ["k", 0])
        self.accept("l", self.setKey, ["l", 1])
        self.accept("l-up", self.setKey, ["l", 0])
        self.accept("i", self.setKey, ["i", 1])
        self.accept("i-up", self.setKey, ["i", 0])
        self.accept("escape", sys.exit)
Пример #20
0
 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
Пример #21
0
    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)
Пример #22
0
    def __init__(self):
        super().__init__(self)
        self.var1 = 0
        self.scene = loader.loadModel("models/world")
        playerTexture = loader.loadTexture("models/starfoxShip.jpg")
        self.player = self.scene.find("player")
        self.player.setTexture(playerTexture)

        base.setBackgroundColor(0.1, 0.1, 0.1, 1)
        enemyTexture = loader.loadTexture("models/enemyShip.jpg")
        self.enemy = self.scene.find("enemy1")
        self.enemy.setTexture(enemyTexture)

        self.basePlane = self.scene.find("basePlane")

        self.scene.reparentTo(self.render)
        self.player.setPos(50, 50, 3)
        self.enemy.setPos(50, 55, 0)

        self.ambient = AmbientLight("ambient")
        self.ambient.color = (0.1, 0.1, 0.1, 1)
        self.ambientPath = self.render.attachNewNode(self.ambient)
        render.setLight(self.ambientPath)

        self.dirLight = DirectionalLight("dir light")
        self.dirLight.color = (1, 1, 1, 1)
        self.dirLightPath = self.render.attachNewNode(self.dirLight)
        self.dirLightPath.setHpr(0, -90, 0)
        self.dirLight.setShadowCaster(True, 512, 512)
        render.setLight(self.dirLightPath)

        self.pointLight = PointLight("point light")
        self.pointLight.color = (1, 1, 1, 1)
        self.pointLightPath = self.render.attachNewNode(self.pointLight)
        self.pointLightPath.setPos(50, 52.5, 4)
        self.pointLight.attenuation = (.5, 0, 0)
        self.pointLight.setShadowCaster(True, 1024, 1024)
        self.render.setLight(self.pointLightPath)

        self.fog = Fog("fog")
        self.fog.setColor(0.1, 0.1, 0.1)
        self.fog.setExpDensity(.3)
        self.fog.setLinearRange(150, 300)
        self.fog.setLinearFallback(45, 160, 320)
        self.render.setFog(self.fog)

        self.render.setShaderAuto()
        self.render.setAntialias(AntialiasAttrib.MAuto)

        filters = CommonFilters(base.win, base.cam)
        filters.setBloom(size="large")
        filters.setAmbientOcclusion(strength=0.6, falloff=0.0005, radius=0.1)
        filters.setCartoonInk(separation=2, color=(0, 0, 0, 1))
        self.taskMgr.add(self.update, "update")
Пример #23
0
 def innitialize_fov(self):
     render.set_shader_auto()
     self.fov_point = PointLight("caster")
     self.fov_point.set_shadow_caster(True, 256*2, 256*2, -1000)
     self.fov_point.set_camera_mask(0b001)
     self.fov_point.set_lens_active(4, False)
     self.fov_point.set_lens_active(5, False)
     for i in range(6):
         self.fov_point.get_lens(i).set_near_far(0.5, 10)
     self.fov_point_np = render.attach_new_node(self.fov_point)
     self.fov_point_np.set_z(0.5)
     self.fov_point.set_color(VBase4(1,1,1,1))
Пример #24
0
    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)
Пример #25
0
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()
Пример #26
0
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()
Пример #27
0
    def makeLights(self, lights):
        def makeSpot(parent, color=VBase4(1, 1, 1, 1), fov=8, atten=.003):
            x = parent.attachNewNode(Spotlight("spot"))
            x.node().setColor(color)
            lens = PerspectiveLens()
            lens.setFov(fov)
            x.node().setLens(lens)
            x.node().setAttenuation(VBase3(0, 0, atten))
            return x

        self.trainLights = lights.attachNewNode("trainLights")
        if 1:
            pl = self.trainLights.attachNewNode(PointLight("point"))
            pl.setPos(2, 10, 10)
            #pl.node().setColor(VBase4(.7, .7, .7, 1))
            pl.node().setAttenuation(Vec3(0, 0, 0.005))
            #pl.node().setShadowCaster(True, 512, 512)
            self.base.render.setLight(pl)
            pl.node().setShadowCaster(True)

            spot = makeSpot(self.trainLights, VBase4(1, 1, 1, 1), 8)
            spot.setPos(2, 0, 18)
            spot.lookAt(self.cubes, Point3(0, .6, 0))
            self.base.render.setLight(spot)

        self.gameLights = lights.attachNewNode("gameLights")
        if 1:
            bg = self.gameLights.attachNewNode(PointLight("point"))
            bg.node().setColor(VBase4(.1, .2, .6, 1))
            bg.setPos(-6, 15, 2)
            self.base.render.setLight(bg)
            bg.node().setShadowCaster(True)

            up = makeSpot(self.gameLights,
                          color=VBase4(.6, .6, .6, 1),
                          fov=25,
                          atten=.009)
            up.setPos(self.cubes.getPos().x, 10, .4)
            up.lookAt(self.cubes, Point3(0, 0, 1.3))
            self.base.render.setLight(up)

            self.rotLights = []
            for color, pos in [
                (VBase4(1, 1, 0, 1), Point3(4, 10, 10)),
                (VBase4(0, .7, 0, 1), Point3(-4, 10, 10)),
                (VBase4(0, .6, 1, 1), Point3(0, 20, 10)),
            ]:
                s1 = makeSpot(self.gameLights, color=color, fov=8)
                s1.setPos(pos)
                s1.lookAt(self.cubes)
                self.base.render.setLight(s1)
                self.rotLights.append(s1)
Пример #28
0
    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)
Пример #29
0
    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()
Пример #30
0
    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)
Пример #31
0
    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)
Пример #32
0
    def __init__(self):
        super().__init__()
        self.set_background_color(0, 0, 0, 1)
        self.cam.setPos(0, -12, 0)

        self.trees = NodePath("trees")

        self.tree1 = self.loader.loadModel('my-models/christmas_tree')
        self.tree1.setPos(0, 0, -2.5)
        self.tree1.reparentTo(self.trees)

        self.tree2 = self.loader.loadModel('my-models/christmas_tree')
        self.tree2.setPos(4, 5, -2.5)
        self.tree2.reparentTo(self.trees)

        self.tree3 = self.loader.loadModel('my-models/christmas_tree')
        self.tree3.setPos(-4, 7, -2.5)
        self.tree3.reparentTo(self.trees)

        self.trees.reparentTo(self.render)

        self.floor = self.loader.loadModel('my-models/floor')
        self.floor.setPos(0, 0, -2.5)
        self.floor.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, -4, 0)
        self.light_model.reparentTo(self.render)

        plight = PointLight("plight")
        plight.setShadowCaster(True, 1024, 1024)
        self.render.setShaderAuto()
        plnp = self.light_model.attachNewNode(plight)
        # plight.setAttenuation((1, 0, 0)) # constant, linear, and quadratic.
        self.trees.setLight(plnp)

        alight = AmbientLight("alight")
        alight.setColor((0.04, 0.04, 0.04, 1))
        alnp = self.render.attachNewNode(alight)
        self.trees.setLight(alnp)

        self.floor.setLight(plnp)
        self.floor.setLight(alnp)

        filters = CommonFilters(self.win, self.cam)
        filters.setBloom(size="large")

        self.taskMgr.add(self.move_light, "move-light")
Пример #33
0
    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()
Пример #34
0
    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
Пример #35
0
    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')
Пример #36
0
	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()
Пример #37
0
    def __init__(self, base, USE_RP):
        self.base = base
        """ direct.showbase.ShowBase """

        if not USE_RP:
            alight = AmbientLight('alight')
            alnp = self.base.render.attachNewNode(alight)
            alight.setColor((0.2, 0.2, 0.2, 1))
            self.base.render.setLight(alnp)

            # Put lighting on the main scene

            dlight = DirectionalLight('dlight')
            dlnp = self.base.render.attachNewNode(dlight)
            dlnp.setPos(0, 5, 5)
            dlight.setColor((0.8, 0.8, 0.5, 1))
            dlnp.setHpr(0, 60, 0)
            self.base.render.setLight(dlnp)

            plight = PointLight('plight')
            plnp = self.base.render.attachNewNode(plight)
            plnp.setPos(0, -50, 50)
            plnp.setHpr(0, 60, 0)
            self.base.render.setLight(plnp)

        self.sounds = {}
Пример #38
0
def launch_panda_window(panda_widget, size):
    """
    Configure and create Panda window
    Connect to the gtk widget resize event
    Load a panda
    """
    props = WindowProperties().getDefault()
    props.setOrigin(0, 0)
    props.setSize(*size)
    props.setParentWindow(panda_widget.window.xid)
    base.openDefaultWindow(props=props)
    # ==
    panda_widget.connect("size_allocate", resize_panda_window)
    # ==
    panda = loader.loadModel("panda")
    panda.reparentTo(render)
    panda.setPos(0, 40, -5)

    pl = render.attachNewNode(PointLight("redPointLight"))
    pl.node().setColor(Vec4(.9, .8, .8, 1))
    render.setLight(pl)
    pl.node().setAttenuation(Vec3(0, 0, 0.05))

    slight = Spotlight('slight')
    slight.setColor(VBase4(1, 1, 1, 1))
    lens = PerspectiveLens()
    slight.setLens(lens)
    slnp = render.attachNewNode(slight)
    slnp.setPos(2, 20, 0)
    mid = PandaNode('mid')
    panda.attachNewNode(mid)
    #    slnp.lookAt(mid)
    render.setLight(slnp)
Пример #39
0
    def _load_quad(self):
        self.quad_node = self.app.loader.loadModel('iris')
        self.quad_node.reparentTo(self.app.render)

        ambient_color = (.1, .1, .1, 1)
        sun_light_color = (.5, .5, .5, 1)
        self.quad_node.setLightOff()
        ambient_light = self.app.render.attachNewNode(
            AmbientLight('quad_ambient_light'))
        ambient_light.node().setColor(ambient_color)
        self.quad_node.setLight(ambient_light)
        sun_light = self.app.render.attachNewNode(PointLight('quad_sun_light'))
        sun_light.node().setColor(sun_light_color)
        sun_light.setPos((-2506., -634., 2596.))
        self.quad_node.setLight(sun_light)
        self.quad_node.flattenStrong()

        quad_prop_positions = [
            np.array([0.20610, 0.13830, 0.025]),  # blue, right
            np.array([0.22254, -0.12507, 0.025]),  # black, right
            np.array([-0.20266, 0.13830, 0.025]),  # blue, left
            np.array([-0.21911, -0.12507, 0.025])
        ]  # black, left
        self.quad_prop_local_nodes = []
        for quad_prop_id, quad_prop_pos in enumerate(quad_prop_positions):
            is_ccw = quad_prop_id in (1, 2)
            quad_prop_node = self.quad_node.attachNewNode('quad_prop_%d' %
                                                          quad_prop_id)
            quad_prop_local_node = self.app.loader.loadModel(
                'iris_prop_%s' % ('ccw' if is_ccw else 'cw'))
            quad_prop_local_node.reparentTo(quad_prop_node)
            quad_prop_node.setPos(tuple(quad_prop_pos))
            quad_prop_node.flattenStrong()
            self.quad_prop_local_nodes.append(quad_prop_local_node)
Пример #40
0
    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)
Пример #41
0
    def setupLights(self):
        panda = self.app.panda

        panda.setBackgroundColor(.9, .9, .9, 1)
        panda.render.clearLight()

        keylight = Spotlight('keylight')
        keylight.setLens(PerspectiveLens())
        np = self._insertLight(
            keylight,
            colour=(1, 1, 1, 1),
            pos=(0, -5, 2),
        )
        np.lookAt((0, 0, 0.9))
        # Turn off shadows until we have fix for
        # https://bugs.launchpad.net/panda3d/+bug/1212752
        # keylight.setShadowCaster(True, 512, 512)

        sunlight = PointLight('sunlight')
        self._insertLight(
            sunlight,
            colour=(1, 1, 1, 1),
            pos=(1, -2, 20),
        )

        self._insertLight(
            AmbientLight('ambientLight'),
            colour=(.25, .25, .25, 1),
        )
Пример #42
0
    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
Пример #44
0
Файл: bt2.py Проект: btdevel/bt
    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()
Пример #45
0
    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()
Пример #46
0
    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 __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)
Пример #49
0
	def __init__(self):
		ShowBase.__init__(self)
		dir(self)
		self.disableMouse()
 
		# Load the environment model.
		self.environ = self.loader.loadModel("../levels/level01.egg")
		# Reparent the model to render.
		self.environ.reparentTo(self.render)
		'''add a light'''
		self.light = PointLight("dLight")
		self.light.setAttenuation( (.01,.01,.01 ) )
		self.light.setSpecularColor ( VBase4(1,1,0,1 ) )
		self.lightNode = render.attachNewNode(self.light)
		self.lightNode.setZ(10)
		render.setLight(self.lightNode)

		'''move light constants'''
		self.moveLightDirection = -1000

		self.taskMgr.add(self.moveLight,"lightMove")
		self.taskMgr.add(self.fpsInput,"fpsInput")

		'''fps cam controls'''
		self.keymap={"w":0,"a":0,"s":0,"d":0,"e":0,"q":0,
				"j":0,"k":0,"l":0,"i":0}
		
		self.fps = FpsCam(self.camera)
		self.accept("a", self.setKey,     ["a",1] )
		self.accept("a-up", self.setKey,  ['a',0] )
		self.accept("w", self.setKey,     ["w",1] )
		self.accept("w-up", self.setKey,  ["w",0] )
		self.accept("s", self.setKey,     ["s",1] )
		self.accept("s-up", self.setKey,  ["s",0] )
		self.accept("d", self.setKey,     ["d",1] )
		self.accept("d-up", self.setKey,  ["d",0] )
		self.accept("e", self.setKey,     ["e",1] )
		self.accept("e-up", self.setKey,  ["e",0] )
		self.accept("q", self.setKey,     ["q",1] )
		self.accept("q-up", self.setKey,  ["q",0] )
		self.accept("j", self.setKey,     ["j",1] )
		self.accept("j-up", self.setKey,  ["j",0] )
		self.accept("k", self.setKey,     ["k",1] )
		self.accept("k-up", self.setKey,  ["k",0] )
		self.accept("l", self.setKey,     ["l",1] )
		self.accept("l-up", self.setKey,  ["l",0] )
		self.accept("i", self.setKey,     ["i",1] )
		self.accept("i-up", self.setKey,  ["i",0] )
		self.accept("escape",sys.exit )
Пример #50
0
    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)
Пример #51
0
    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
Пример #52
0
    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
Пример #53
0
    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!')
Пример #54
0
    def __init__(self):
        # 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.disableMouse()
        self.cam.node().getLens().setNear(10.0)
        self.cam.node().getLens().setFar(200.0)
        camera.setPos(0, -50, 0)

        # Check video card capabilities.
        if not self.win.getGsg().getSupportsBasicShaders():
            addTitle("Toon Shader: Video driver reports that Cg shaders are not supported.")
            return

        # Enable a 'light ramp' - this discretizes the lighting,
        # which is half of what makes a model look like a cartoon.
        # Light ramps only work if shader generation is enabled,
        # so we call 'setShaderAuto'.

        tempnode = NodePath(PandaNode("temp node"))
        tempnode.setAttrib(LightRampAttrib.makeSingleThreshold(0.5, 0.4))
        tempnode.setShaderAuto()
        self.cam.node().setInitialState(tempnode.getState())

        # Use class 'CommonFilters' to enable a cartoon inking filter.
        # This can fail if the video card is not powerful enough, if so,
        # display an error and exit.

        self.separation = 1  # Pixels
        self.filters = CommonFilters(self.win, self.cam)
        filterok = self.filters.setCartoonInk(separation=self.separation)
        if (filterok == False):
            addTitle(
                "Toon Shader: Video card not powerful enough to do image postprocessing")
            return

        # Show instructions in the corner of the window.
        self.title = addTitle(
            "Panda3D: Tutorial - Toon Shading with Normals-Based Inking")
        self.inst1 = addInstructions(0.06, "ESC: Quit")
        self.inst2 = addInstructions(0.12, "Up/Down: Increase/Decrease Line Thickness")
        self.inst3 = addInstructions(0.18, "V: View the render-to-texture results")

        # Load a dragon model and animate it.
        self.character = Actor()
        self.character.loadModel('models/nik-dragon')
        self.character.reparentTo(render)
        self.character.loadAnims({'win': 'models/nik-dragon'})
        self.character.loop('win')
        self.character.hprInterval(15, (360, 0, 0)).loop()

        # Create a non-attenuating point light and an ambient light.
        plightnode = PointLight("point light")
        plightnode.setAttenuation((1, 0, 0))
        plight = render.attachNewNode(plightnode)
        plight.setPos(30, -50, 0)
        alightnode = AmbientLight("ambient light")
        alightnode.setColor((0.8, 0.8, 0.8, 1))
        alight = render.attachNewNode(alightnode)
        render.setLight(alight)
        render.setLight(plight)

        # Panda contains a built-in viewer that lets you view the
        # results of all render-to-texture operations.  This lets you
        # see what class CommonFilters is doing behind the scenes.
        self.accept("v", self.bufferViewer.toggleEnable)
        self.accept("V", self.bufferViewer.toggleEnable)
        self.bufferViewer.setPosition("llcorner")
        self.accept("s", self.filters.manager.resizeBuffers)

        # These allow you to change cartooning parameters in realtime
        self.accept("escape", sys.exit, [0])
        self.accept("arrow_up", self.increaseSeparation)
        self.accept("arrow_down", self.decreaseSeparation)
Пример #55
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)
Пример #56
0
	def __setPointLight(self,props):		
		light = PointLight(props['name'])
		light.setAttenuation(props['attenuation'])
		return self.__createLight(light,props)