Пример #1
0
 def startSky(self):
     self.sky.reparentTo(camera)
     self.sky.setZ(0.0)
     self.sky.setHpr(0.0, 0.0, 0.0)
     ce = CompassEffect.make(NodePath(),
                             CompassEffect.PRot | CompassEffect.PZ)
     self.sky.node().setEffect(ce)
Пример #2
0
 def load(self):
     spawn = random.choice(DGG.SpawnPoints)
     base.localAvatar.setPos(spawn)
     base.localAvatar.setHpr(0, 0, 0)
     self.soundPickUpBarrel = base.loadSfx("phase_6/audio/sfx/SZ_MM_gliss.mp3")
     self.soundDropOff = base.loadSfx("phase_4/audio/sfx/MG_sfx_travel_game_bell_for_trolley.mp3")
     self.setMinigameMusic("phase_4/audio/bgm/MG_Delivery.mp3")
     self.setDescription(
         "A new supply of Gags were just shipped to Toontown! "
         + "Run over to a truck with Gag barrels to take a barrel out. Then, carry it over to the Gag Shop. "
         + "Try to unload and deliver as many barrels as you can to the Gag Shop. "
         + "Watch out for the Cogs - they might try to snatch a barrel!"
     )
     self.setWinnerPrize(100)
     self.setLoserPrize(0)
     self.gagShop = loader.loadModel("phase_4/models/modules/gagShop_TT.bam")
     self.gagShop.reparentTo(base.render)
     self.gagShop.setY(-70)
     sphere = CollisionSphere(0, 0, 0, 3)
     sphere.setTangible(0)
     node = CollisionNode("MGDeliveryGagShop")
     node.addSolid(sphere)
     self.gagShopCollNP = self.gagShop.attachNewNode(node)
     self.world = loader.loadModel("phase_4/models/minigames/delivery_area.egg")
     self.world.setY(-5)
     self.world.reparentTo(base.render)
     self.sky = loader.loadModel("phase_3.5/models/props/TT_sky.bam")
     self.sky.reparentTo(base.camera)
     ce = CompassEffect.make(NodePath(), CompassEffect.PRot | CompassEffect.PZ)
     self.sky.node().setEffect(ce)
     self.sky.setZ(-20)
     self.skyUtil.startSky(self.sky)
     base.camera.setPos(20, 50, 30)
     base.camera.lookAt(20, 0, 7.5)
     DistributedMinigame.load(self)
Пример #3
0
def setupCamera(app):
    app.disableMouse()  # disable default mouse controls

    # dummy node for camera, we will rotate the dummy node for camera rotation
    parentNode = app.render.attachNewNode('camparent')
    parentNode.reparentTo(app.model)  # inherit transforms
    parentNode.setEffect(CompassEffect.make(
        app.render))  # NOT inherit rotation

    # # the camera
    app.cam.reparentTo(parentNode)
    app.cam.lookAt(parentNode)
    app.cam.setY(-10)  # camera distance from model

    # camera zooming
    app.accept(
        'wheel_up',
        lambda: app.cam.setY(app.cam.getY() + 200 * globalClock.getDt()))
    app.accept(
        'wheel_down',
        lambda: app.cam.setY(app.cam.getY() - 200 * globalClock.getDt()))
    app.accept('mouse1', app.click)
    app.accept('mouse1-up', app.clickOut)
    app.clickOut()

    # global vars for camera rotation
    app.heading = 0
    app.pitch = 0
    return parentNode
Пример #4
0
 def announceGenerate(self):
     DistributedObject.announceGenerate(self)
     base.transitions.fadeScreen(0.0)
     self.guide = Toon(base.cr)
     self.guide.autoClearChat = False
     self.guide.parseDNAStrand(NPCGlobals.NPC_DNA[self.GUIDE_NAME])
     self.guide.setName(self.GUIDE_NAME)
     self.guide.generateToon()
     self.guide.startBlink()
     self.guide.reparentTo(render)
     base.localAvatar.reparentTo(render)
     loader.loadDNAFile(self.dnaStore, 'phase_3.5/dna/storage_tutorial.dna')
     node = loader.loadDNAFile(self.dnaStore, 'phase_3.5/dna/tutorial_street.dna')
     if node.getNumParents() == 1:
         self.streetGeom = NodePath(node.getParent(0))
         self.streetGeom.reparentTo(hidden)
     else:
         self.streetGeom = hidden.attachNewNode(node)
     self.streetGeom.flattenMedium()
     gsg = base.win.getGsg()
     if gsg:
         self.streetGeom.prepareScene(gsg)
     self.streetGeom.reparentTo(render)
     self.streetGeom.setPos(20.5, -20, 0)
     self.streetGeom.setH(90)
     self.sky = loader.loadModel('phase_3.5/models/props/TT_sky.bam')
     self.skyUtil.startSky(self.sky)
     self.sky.reparentTo(camera)
     ce = CompassEffect.make(NodePath(), CompassEffect.PRot | CompassEffect.PZ)
     self.sky.node().setEffect(ce)
     self.music = base.loadMusic('phase_3.5/audio/bgm/TC_SZ.mid')
     base.playMusic(self.music, volume=0.8, looping=1)
     self.battleMusic = base.loadMusic('phase_3.5/audio/bgm/encntr_general_bg.mid')
     self.fsm.request('newPlayerEmerge')
     base.localAvatar.inTutorial = True
 def load(self):
     spawn = random.choice(DGG.SpawnPoints)
     base.localAvatar.setPos(spawn)
     base.localAvatar.setHpr(0, 0, 0)
     self.soundPickUpBarrel = base.loadSfx('phase_6/audio/sfx/SZ_MM_gliss.ogg')
     self.soundDropOff = base.loadSfx('phase_4/audio/sfx/MG_sfx_travel_game_bell_for_trolley.ogg')
     self.setMinigameMusic('phase_4/audio/bgm/MG_Delivery.ogg')
     self.setDescription('A new supply of Gags were just shipped to Toontown! ' + 'Run over to a truck with Gag barrels to take a barrel out. Then, carry it over to the Gag Shop. ' + 'Try to unload and deliver as many barrels as you can to the Gag Shop. ' + 'Watch out for the Cogs - they might try to snatch a barrel!')
     self.setWinnerPrize(100)
     self.setLoserPrize(0)
     self.gagShop = loader.loadModel('phase_4/models/modules/gagShop_TT.bam')
     self.gagShop.reparentTo(base.render)
     self.gagShop.setY(-70)
     sphere = CollisionSphere(0, 0, 0, 3)
     sphere.setTangible(0)
     node = CollisionNode('MGDeliveryGagShop')
     node.addSolid(sphere)
     self.gagShopCollNP = self.gagShop.attachNewNode(node)
     self.world = loader.loadModel('phase_4/models/minigames/delivery_area.egg')
     self.world.setY(-5)
     self.world.reparentTo(base.render)
     self.world.find('**/ground').setBin('ground', 18)
     self.sky = loader.loadModel('phase_3.5/models/props/TT_sky.bam')
     self.sky.reparentTo(base.camera)
     ce = CompassEffect.make(NodePath(), CompassEffect.PRot | CompassEffect.PZ)
     self.sky.node().setEffect(ce)
     self.sky.setZ(-20)
     self.skyUtil.startSky(self.sky)
     base.camera.setPos(40, 50, 30)
     base.camera.lookAt(20, 0, 7.5)
     DistributedMinigame.load(self)
Пример #6
0
 def loadSkyBox(self):
   self.skybox = game.loader.loadModel("Models/skybox.egg")
   self.skybox.setScale(100.0,100.0,100.0)
   self.skybox.setPos(0,0,0)
   self.skybox.reparentTo(self.ship.getModel())
   # Roots the skybox with relation to the render node, making it stationary
   # even though its parented to the ship
   self.skybox.setEffect(CompassEffect.make(render, CompassEffect.PRot))
Пример #7
0
 def loadSkyBox(self):
     self.skybox = game.loader.loadModel("Models/skybox.egg")
     self.skybox.setScale(100.0, 100.0, 100.0)
     self.skybox.setPos(0, 0, 0)
     self.skybox.reparentTo(self.ship.getModel())
     # Roots the skybox with relation to the render node, making it stationary
     # even though its parented to the ship
     self.skybox.setEffect(CompassEffect.make(render, CompassEffect.PRot))
Пример #8
0
  def loadSkyBox(self):
    """Loads and centers the skybox."""
    self.skybox = self.loader.loadModel("Models/skybox.egg")
    self.skybox.setScale(1000.0,1000.0,1000.0)
    self.skybox.setPos(0,0,0)
    self.skybox.reparentTo(self.player.modelNP)

    self.skybox.setEffect(CompassEffect.make(self.render, CompassEffect.PRot))
Пример #9
0
 def create_celestial_node(self):
     bounds = self.camera.node().get_lens().make_bounds()
     self.celestials = self.celestials.create_node()
     self.celestials.set_transparency(TransparencyAttrib.MAlpha)
     self.celestials.set_light_off()
     self.celestials.set_effect(CompassEffect.make(self.camera, CompassEffect.PPos))
     self.celestials.node().set_bounds(bounds)
     self.celestials.node().set_final(True)
     self.celestials.reparent_to(self.scene)
Пример #10
0
 def create_celestial_node(self):
     bounds = self.camera.node().get_lens().make_bounds()
     self.celestials = self.celestials.create_node()
     self.celestials.set_transparency(TransparencyAttrib.MAlpha)
     self.celestials.set_light_off()
     self.celestials.set_effect(
         CompassEffect.make(self.camera, CompassEffect.PPos))
     self.celestials.node().set_bounds(bounds)
     self.celestials.node().set_final(True)
     self.celestials.reparent_to(self.scene)
Пример #11
0
    def load(self):
        self.unload()
        if self.loadingText:
            self.loadingText.destroy()
            self.loadingText = None
        self.loadingText = OnscreenText(text='Loading ' + self.getNameOfCurrentLevel() + '...', font=CIGlobals.getMinnieFont(), fg=(1, 1, 1, 1))
        self.loadingText.setBin('gui-popup', 0)
        base.graphicsEngine.renderFrame()
        base.graphicsEngine.renderFrame()
        if self.levelName == 'momada':
            self.__momadaLoad()
        elif self.levelName in ('cbhq',):
            modelPath = self.LevelData[self.levelName]['model']
            self.levelGeom = loader.loadModel(modelPath)
            self.levelGeom.flattenMedium()
            self.levelGeom.reparentTo(render)
            if self.LevelData[self.levelName]['sky'] != None:
                self.skyModel = loader.loadModel(self.SkyData['cog'] + '/cog_sky.bam')
                self.skyUtil = SkyUtil()
                self.skyUtil.startSky(self.skyModel)
                self.skyModel.reparentTo(render)
        else:
            dnaFiles = self.LevelData[self.levelName]['dna']
            skyType = self.LevelData[self.levelName]['sky']
            skyPhase = self.SkyData[skyType]
            loader.loadDNAFile(self.dnaStore, 'phase_4/dna/storage.dna')
            for index in range(len(dnaFiles)):
                if index == len(dnaFiles) - 1:
                    node = loader.loadDNAFile(self.dnaStore, dnaFiles[index])
                    if node.getNumParents() == 1:
                        self.levelGeom = NodePath(node.getParent(0))
                        self.levelGeom.reparentTo(hidden)
                    else:
                        self.levelGeom = hidden.attachNewNode(node)
                    self.levelGeom.flattenMedium()
                    gsg = base.win.getGsg()
                    if gsg:
                        self.levelGeom.prepareScene(gsg)
                    self.levelGeom.reparentTo(render)
                else:
                    loader.loadDNAFile(self.dnaStore, dnaFiles[index])

            self.skyModel = loader.loadModel(skyPhase + '/' + skyType + '_sky.bam')
            self.skyUtil = SkyUtil()
            self.skyUtil.startSky(self.skyModel)
            self.skyModel.reparentTo(camera)
            ce = CompassEffect.make(NodePath(), CompassEffect.PRot | CompassEffect.PZ)
            self.skyModel.node().setEffect(ce)
        if self.loadingText:
            self.loadingText.destroy()
            self.loadingText = None
        return
Пример #12
0
 def loadSky(sky):
     data = self.skyData[sky]
     if data:
         model = data['model']
         moving = 0
         if data.get('moving'):
             moving = data['moving']
         self.skyModel = loader.loadModel(model)
         self.skyModel.reparentTo(camera)
         self.skyUtil = SkyUtil()
         self.skyUtil.startSky(self.skyModel)
         if moving:
             compass = CompassEffect.make(NodePath(), CompassEffect.PRot | CompassEffect.PZ)
             self.skyModel.node().setEffect(compass)
Пример #13
0
    def createEnviroment(self):
        # Fog to hide performance tweak:
        colour = (0.5, 0.5, 0.5)
        expfog = Fog("scene-wide-fog")
        expfog.setColor(*colour)
        expfog.setExpDensity(0.002)
        self.render.setFog(expfog)
        base.setBackgroundColor(*colour)

        # Our sky
        skydome = self.loader.loadModel('blue-sky-sphere')
        skydome.setEffect(CompassEffect.make(self.render))
        skydome.setScale(0.08)  # bit less than "far"

        # NOT render - you`ll fly through the sky!:
        skydome.reparentTo(self.camera)

        # Our lighting
        ambientLight = AmbientLight("ambientLight")
        ambientLight.setColor(Vec4(.6, .6, .6, 1))
        render.setLight(render.attachNewNode(ambientLight))

        directionalLight = DirectionalLight("directionalLight")
        directionalLight.setColor(Vec4(0.8, 0.8, 0.5, 1))
        dlnp = self.render.attachNewNode(directionalLight)
        dlnp.setPos(0, 0, 260)
        dlnp.lookAt(self.player)
        self.render.setLight(dlnp)

        self.render2d = render2d

        # image scale of 1 fills screen, position defaults to central
        Scale = 1.0 / 2.5  # decimal point is VITAL
        self.radar = OnscreenImage(image='radar.png', scale=Scale, \
                                parent=self.render2d, pos=(-0.95,0,-0.95))
        self.radar.setTransparency(TransparencyAttrib.MAlpha)
        # note the image itself and how it is centered

        hud = OnscreenImage(image='hud1.png', scale=1, \
                                parent=self.render2d, pos=(0,0,0))
        hud.setTransparency(TransparencyAttrib.MAlpha)
        self.dots = list()
        self.playerobj = OnscreenImage(image='playerdot.png', \
                                       scale=1.0/20.0,parent=self.radar)
        self.playerobj.setTransparency(TransparencyAttrib.MAlpha)
 def announceGenerate(self):
     DistributedObject.announceGenerate(self)
     base.transitions.fadeScreen(0.0)
     self.guide = Toon(base.cr)
     self.guide.autoClearChat = False
     self.guide.parseDNAStrand(NPCGlobals.NPC_DNA[self.GUIDE_NAME])
     self.guide.setName(self.GUIDE_NAME)
     self.guide.generateToon()
     self.guide.nametag.setNametagColor(
         NametagGlobals.NametagColors[NametagGlobals.CCNPC])
     self.guide.nametag.setActive(0)
     self.guide.nametag.updateAll()
     self.guide.startBlink()
     self.guide.reparentTo(render)
     base.localAvatar.reparentTo(render)
     loader.loadDNAFile(self.dnaStore,
                        'phase_3.5/dna/storage_tutorial.pdna')
     node = loader.loadDNAFile(self.dnaStore,
                               'phase_3.5/dna/tutorial_street.pdna')
     if node.getNumParents() == 1:
         self.streetGeom = NodePath(node.getParent(0))
         self.streetGeom.reparentTo(hidden)
     else:
         self.streetGeom = hidden.attachNewNode(node)
     self.streetGeom.flattenMedium()
     gsg = base.win.getGsg()
     if gsg:
         self.streetGeom.prepareScene(gsg)
     self.streetGeom.reparentTo(render)
     self.streetGeom.setPos(20.5, -20, 0)
     self.streetGeom.setH(90)
     self.sky = loader.loadModel('phase_3.5/models/props/TT_sky.bam')
     self.skyUtil.startSky(self.sky)
     self.sky.reparentTo(camera)
     ce = CompassEffect.make(NodePath(),
                             CompassEffect.PRot | CompassEffect.PZ)
     self.sky.node().setEffect(ce)
     self.music = base.loadMusic('phase_3.5/audio/bgm/TC_SZ.mid')
     base.playMusic(self.music, volume=0.8, looping=1)
     self.battleMusic = base.loadMusic(
         'phase_3.5/audio/bgm/encntr_general_bg.mid')
     self.fsm.request('newPlayerEmerge')
     base.localAvatar.inTutorial = True
Пример #15
0
def startCloudSky(hood, parent=camera, effects=CompassEffect.PRot | CompassEffect.PZ):
    hood.sky.reparentTo(parent)
    hood.sky.setDepthTest(0)
    hood.sky.setDepthWrite(0)
    hood.sky.setBin('background', 100)
    hood.sky.find('**/Sky').reparentTo(hood.sky, -1)
    hood.sky.reparentTo(parent)
    hood.sky.setZ(0.0)
    hood.sky.setHpr(0.0, 0.0, 0.0)
    ce = CompassEffect.make(NodePath(), effects)
    hood.sky.node().setEffect(ce)
    skyTrackTask = Task(hood.skyTrack)
    skyTrackTask.h = 0
    skyTrackTask.cloud1 = hood.sky.find('**/cloud1')
    skyTrackTask.cloud2 = hood.sky.find('**/cloud2')
    if not skyTrackTask.cloud1.isEmpty() and not skyTrackTask.cloud2.isEmpty():
        taskMgr.add(skyTrackTask, 'skyTrack')
    else:
        notify.warning("Couln't find clouds!")
Пример #16
0
def startCloudSky(hood,
                  parent=camera,
                  effects=CompassEffect.PRot | CompassEffect.PZ):
    hood.sky.reparentTo(parent)
    hood.sky.setDepthTest(0)
    hood.sky.setDepthWrite(0)
    hood.sky.setBin('background', 100)
    hood.sky.find('**/Sky').reparentTo(hood.sky, -1)
    hood.sky.reparentTo(parent)
    hood.sky.setZ(0.0)
    hood.sky.setHpr(0.0, 0.0, 0.0)
    ce = CompassEffect.make(NodePath(), effects)
    hood.sky.node().setEffect(ce)
    skyTrackTask = Task(hood.skyTrack)
    skyTrackTask.h = 0
    skyTrackTask.cloud1 = hood.sky.find('**/cloud1')
    skyTrackTask.cloud2 = hood.sky.find('**/cloud2')
    if not skyTrackTask.cloud1.isEmpty() and not skyTrackTask.cloud2.isEmpty():
        taskMgr.add(skyTrackTask, 'skyTrack')
    else:
        notify.warning("Couln't find clouds!")
Пример #17
0
def startClouds(sky,
                skyTrack,
                parent=camera,
                effects=CompassEffect.PRot | CompassEffect.PZ):
    sky.setDepthTest(0)
    sky.setDepthWrite(0)
    sky.setBin('background', 100)
    if sky.find('**/Sky').isEmpty():
        sky.reparentTo(render)
        return
    sky.reparentTo(parent)
    sky.find('**/Sky').reparentTo(sky, -1)
    if effects:
        ce = CompassEffect.make(NodePath(), effects)
        sky.node().setEffect(ce)
    skyTrackTask = Task(skyTrack)
    skyTrackTask.h = 0
    skyTrackTask.cloud1 = sky.find('**/cloud1')
    skyTrackTask.cloud2 = sky.find('**/cloud2')
    if not skyTrackTask.cloud1.isEmpty() and not skyTrackTask.cloud2.isEmpty():
        taskMgr.add(skyTrackTask, 'skyTrack')
Пример #18
0
    def __init__(self, game, parent):
        self.game = game

        # class properties for camera rotation
        self.heading = 0
        self.pitch = 0

        # class properties for camera zoom
        self.targetY = -6
        self.interval = None

        # find screen center
        props = base.win.getProperties()
        self.centerX = props.getXSize() / 2
        self.centerY = props.getYSize() / 2

        # constrain mouse
        base.disableMouse()  # disable default mouse camera control
        self.hideMouse()

        # set up floater
        self.floater = render.attachNewNode("floater")
        self.floater.reparentTo(parent)  # inherit position from parent, but rotation and scale from render
        self.floater.setEffect(CompassEffect.make(render, CompassEffect.P_rot | CompassEffect.P_scale))
        self.floater.setZ(1)  # distance above model

        # set up camera
        base.camera.reparentTo(self.floater)
        base.camera.setY(self.targetY)  # original distance from model
        base.camera.lookAt(self.floater)

        # camera zooming
        # TODO move into method, clamp Y value?
        base.accept("wheel_up", lambda: self.zoom(2))
        base.accept("shift-wheel_up", lambda: self.zoom(2))
        base.accept("wheel_down", lambda: self.zoom(-2))
        base.accept("shift-wheel_down", lambda: self.zoom(-2))

        # start task
        taskMgr.add(self.mouseControl, "Camera.mouseControl")
Пример #19
0
    def createWorld(self):
        self.deleteWorld()
        self.maze = loader.loadModel('phase_4/models/minigames/maze_1player.bam')
        self.maze.find('**/maze_walls').setSz(1.5)
        self.maze.reparentTo(base.render)
        self.mazeCollModel = loader.loadModel('phase_4/models/minigames/maze_1player_collisions.egg')
        self.mazeCollModel.reparentTo(base.render)
        self.mazeCollModel.hide()
        self.mazeCollModel.setTransparency(1)
        self.mazeCollModel.setColorScale(1, 1, 1, 0)
        for node in self.mazeCollModel.findAllMatches('**'):
            node.setSz(1.5)

        self.sky = loader.loadModel('phase_3.5/models/props/TT_sky.bam')
        self.skyUtil = SkyUtil()
        self.skyUtil.startSky(self.sky)
        self.sky.reparentTo(base.camera)
        ce = CompassEffect.make(NodePath(), CompassEffect.PRot | CompassEffect.PZ)
        self.sky.node().setEffect(ce)
        self.spawnPoints.append((Point3(0, 0, 0), Vec3(0, 0, 0)))
        self.spawnPoints.append((Point3(-23.89, 18.58, 0.0), Vec3(90.0, 0.0, 0.0)))
        self.spawnPoints.append((Point3(-23.89, 6.3, 0.0), Vec3(0.0, 0.0, 0.0)))
        self.spawnPoints.append((Point3(23.78, 6.3, 0.0), Vec3(0.0, 0.0, 0.0)))
        self.spawnPoints.append((Point3(8.12, -17.79, 0.0), Vec3(270.0, 0.0, 0.0)))
Пример #20
0
 def __init__(self):
     base.disable_mouse()
     self.camera_dest = NodePath("camera dest")
     base.camera.node().set_effect(CompassEffect.make(render, 112))
Пример #21
0
    def load(self):
        self.unload()
        if self.loadingText:
            self.loadingText.destroy()
            self.loadingText = None
        self.loadingText = OnscreenText(text='', font=CIGlobals.getMinnieFont(), fg=(1,
                                                                                     1,
                                                                                     1,
                                                                                     1))
        self.loadingText.setBin('gui-popup', 0)
        base.graphicsEngine.renderFrame()
        base.graphicsEngine.renderFrame()
        if self.levelName == 'momada':
            self.__momadaLoad()
        else:
            if self.levelName in ('cbhq', 'sbf'):
                modelPath = self.LevelData[self.levelName]['model']
                self.levelGeom = loader.loadModel(modelPath)
                self.levelGeom.flattenMedium()
                self.levelGeom.reparentTo(render)
                if self.LevelData[self.levelName]['sky'] != None:
                    self.skyModel = loader.loadModel(self.SkyData['cog'] + '/cog_sky.bam')
                    self.skyUtil = SkyUtil()
                    self.skyUtil.startSky(self.skyModel)
                    self.skyModel.reparentTo(render)
                    self.skyModel.setScale(self.LevelData[self.levelName].get('sky_scale', 1.0))
                if self.LevelData[self.levelName].get('occluders'):
                    self.occluders = loader.loadModel(self.LevelData[self.levelName]['occluders'])
                    for occluderNode in self.occluders.findAllMatches('**/+OccluderNode'):
                        base.render.setOccluder(occluderNode)
                        occluderNode.node().setDoubleSided(True)

                if self.levelName == 'sbf':
                    base.camLens.setFar(250)
            else:
                dnaFiles = self.LevelData[self.levelName]['dna']
                skyType = self.LevelData[self.levelName]['sky']
                skyPhase = self.SkyData[skyType]
                loadDNAFile(self.dnaStore, 'phase_4/dna/storage.pdna')
                for index in range(len(dnaFiles)):
                    if index == len(dnaFiles) - 1:
                        node = loadDNAFile(self.dnaStore, dnaFiles[index])
                        if node.getNumParents() == 1:
                            self.levelGeom = NodePath(node.getParent(0))
                            self.levelGeom.reparentTo(hidden)
                        else:
                            self.levelGeom = hidden.attachNewNode(node)
                        if self.levelName == 'ttc' and dnaFiles[index] == 'phase_4/dna/new_ttc_sz.pdna':
                            self.levelGeom.find('**/prop_gazebo_DNARoot').removeNode()
                        else:
                            self.levelGeom.flattenMedium()
                        gsg = base.win.getGsg()
                        if gsg:
                            self.levelGeom.prepareScene(gsg)
                        self.levelGeom.reparentTo(render)
                    else:
                        loadDNAFile(self.dnaStore, dnaFiles[index])

                children = self.levelGeom.findAllMatches('**/*doorFrameHole*')
                for child in children:
                    child.hide()

                self.skyModel = loader.loadModel(skyPhase + '/' + skyType + '_sky.bam')
                self.skyUtil = SkyUtil()
                self.skyUtil.startSky(self.skyModel)
                self.skyModel.reparentTo(camera)
                ce = CompassEffect.make(NodePath(), CompassEffect.PRot | CompassEffect.PZ)
                self.skyModel.node().setEffect(ce)
        if self.loadingText:
            self.loadingText.destroy()
            self.loadingText = None
        return
Пример #22
0
    def __init__(self):
        ShowBase.__init__(self)

        self.scene = self.loader.loadModel("models/test.egg")
        self.scene.reparentTo(self.render)
        self.scene.setScale(1, 3, 1)
        # self.scene.setPos(0, 1000, 0)
        sphere = CollisionSphere(0, 0, 0, 50)
        cnode = self.scene.attachNewNode(CollisionNode('cnode_scene'))
        cnode.node().addSolid(sphere)
        # cnode.show()

        base.setBackgroundColor(0, 0.0, 0)

        base.disableMouse()
        props = WindowProperties()
        props.setCursorHidden(True)
        base.win.requestProperties(props)
        OnscreenText(text='.', pos=(0, 0, 0))

        plight = PointLight('plight')
        plight.setColor(VBase4(2, 2, 2, 1))
        plnp = self.render.attachNewNode(plight)
        plnp.setPos(0, 0, 100)
        self.render.setLight(plnp)

        # dummy node for camera, attach player to it
        self.camparent = self.render.attachNewNode('camparent')
        self.camparent.reparentTo(self.render)  # inherit transforms
        self.camparent.setEffect(CompassEffect.make(
            self.render))  # NOT inherit rotation
        self.camparent.setY(-1000)
        self.camparent.setZ(200)

        # the camera
        base.camera.reparentTo(self.camparent)
        base.camera.lookAt(self.camparent)
        base.camera.setY(0)  # camera distance from model

        self.heading = 0
        self.pitch = 0

        self.taskMgr.add(self.cameraTask, 'cameraTask')

        self.keyMap = {"left": 0, "right": 0, "forward": 0, "reverse": 0}

        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, ["reverse", True])
        self.accept("w", self.setKey, ["forward", True])
        self.accept("a", self.setKey, ["left", True])
        self.accept("s", self.setKey, ["reverse", True])
        self.accept("d", self.setKey, ["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, ["reverse", False])
        self.accept("w-up", self.setKey, ["forward", False])
        self.accept("a-up", self.setKey, ["left", False])
        self.accept("s-up", self.setKey, ["reverse", False])
        self.accept("d-up", self.setKey, ["right", False])
        self.accept('mouse1', self.myFunction)

        self.textObject = None

        db = TinyDB('paintings/db.json')
        self.descriptions = dict()

        base.cTrav = CollisionTraverser()

        pickerNode = CollisionNode('mouseRay')
        pickerNP = self.camera.attachNewNode(pickerNode)
        pickerNode.setFromCollideMask(GeomNode.getDefaultCollideMask())
        self.pickerRay = CollisionRay()
        pickerNode.addSolid(self.pickerRay)
        self.queue = CollisionHandlerQueue()
        base.cTrav.addCollider(pickerNP, self.queue)

        id = 0
        for item in db.all():
            self.addImage('paintings/' + item['img'], id=id)
            self.descriptions[id] = item['name']
            id += 1
Пример #23
0
 def load(self):
     self.unload()
     if self.loadingText:
         self.loadingText.destroy()
         self.loadingText = None
     self.loadingText = OnscreenText(text = "",
         font = CIGlobals.getMinnieFont(), fg = (1, 1, 1, 1))
     self.loadingText.setBin('gui-popup', 0)
     base.graphicsEngine.renderFrame()
     base.graphicsEngine.renderFrame()
     if self.levelName == "momada":
         # momada is completely different from the other levels,
         # so it has it's own separate method for loading.
         self.__momadaLoad()
     elif self.levelName in ['cbhq', 'sbf']:
         # Cog hqs are just one model with everything in it. no dna loading needed.
         modelPath = self.LevelData[self.levelName]['model']
         self.levelGeom = loader.loadModel(modelPath)
         self.levelGeom.flattenMedium()
         self.levelGeom.reparentTo(render)
         if self.LevelData[self.levelName]['sky'] != None:
             self.skyModel = loader.loadModel(self.SkyData['cog'] + '/cog_sky.bam')
             self.skyUtil = SkyUtil()
             self.skyUtil.startSky(self.skyModel)
             self.skyModel.reparentTo(render)
             self.skyModel.setScale(self.LevelData[self.levelName].get('sky_scale', 1.0))
         if self.LevelData[self.levelName].get('occluders'):
             self.occluders = loader.loadModel(self.LevelData[self.levelName]['occluders'])
             for occluderNode in self.occluders.findAllMatches('**/+OccluderNode'):
                 base.render.setOccluder(occluderNode)
                 occluderNode.node().setDoubleSided(True)
         if self.levelName == 'sbf':
             base.camLens.setFar(250)
     else:
         # It's a playground with dna and stuff. Just do the
         # normal loading procedure.
         dnaFiles = self.LevelData[self.levelName]['dna']
         skyType = self.LevelData[self.levelName]['sky']
         skyPhase = self.SkyData[skyType]
         loadDNAFile(self.dnaStore, 'phase_4/dna/storage.pdna')
         for index in range(len(dnaFiles)):
             if index == len(dnaFiles) - 1:
                 node = loadDNAFile(self.dnaStore, dnaFiles[index])
                 if node.getNumParents() == 1:
                     self.levelGeom = NodePath(node.getParent(0))
                     self.levelGeom.reparentTo(hidden)
                 else:
                     self.levelGeom = hidden.attachNewNode(node)
                 if self.levelName == 'ttc' and dnaFiles[index] == 'phase_4/dna/new_ttc_sz.pdna':
                     self.levelGeom.find('**/prop_gazebo_DNARoot').removeNode()
                 else:
                     self.levelGeom.flattenMedium()
                 gsg = base.win.getGsg()
                 if gsg:
                     self.levelGeom.prepareScene(gsg)
                 self.levelGeom.reparentTo(render)
             else:
                 loadDNAFile(self.dnaStore, dnaFiles[index])
         children = self.levelGeom.findAllMatches('**/*doorFrameHole*')
         
         for child in children:
             child.hide()
         self.skyModel = loader.loadModel(skyPhase + "/" + skyType + "_sky.bam")
         self.skyUtil = SkyUtil()
         self.skyUtil.startSky(self.skyModel)
         self.skyModel.reparentTo(camera)
         ce = CompassEffect.make(NodePath(), CompassEffect.PRot | CompassEffect.PZ)
         self.skyModel.node().setEffect(ce)
     if self.loadingText:
         self.loadingText.destroy()
         self.loadingText = None
Пример #24
0
    def __init__(self):
        ShowBase.__init__(self)
        self.xray_mode = False
        self.show_model_bounds = False

        self.lastHighlight = None

        # Display instructions
        add_title("TrenchAssessment")
        add_instructions(0.06, "[Esc]: Quit")
        #add_instructions(0.12, "[W]: Move Forward")
        #add_instructions(0.18, "[A]: Move Left")
        #add_instructions(0.24, "[S]: Move Right")
        #add_instructions(0.30, "[D]: Move Back")
        #add_instructions(0.36, "Arrow Keys: Look Around")
        add_instructions(0.12, "[F]: Toggle Wireframe")
        add_instructions(0.18, "[X]: Toggle X-Ray Mode")
        add_instructions(0.24, "[B]: Toggle Bounding Volumes")

        self.keys = {}
        self.accept('f', self.toggleWireframe)
        self.accept('x', self.toggle_xray_mode)
        self.accept('b', self.toggle_model_bounds)
        self.accept('escape', __import__('sys').exit, [0])
        self.disableMouse()

        # Setup camera
        self.cameraarm = render.attachNewNode('arm')
        self.cameraarm.setEffect(
            CompassEffect.make(render))  # NOT inherit rotation
        self.lens = PerspectiveLens()
        self.lens.setFov(60)
        self.lens.setNear(0.01)
        self.lens.setFar(10000000.0)
        self.cam.node().setLens(self.lens)
        self.heading = 0
        self.pitch = 0.0
        self.camera.reparentTo(self.cameraarm)
        self.camera.setY(-10)  # camera distance from model
        self.accept(
            'wheel_up', lambda: base.camera.setY(self.camera.getY() + 400 *
                                                 globalClock.getDt()))
        self.accept(
            'wheel_down', lambda: base.camera.setY(self.camera.getY() - 400 *
                                                   globalClock.getDt()))
        self.accept(
            'shift-wheel_up', lambda: base.camera.setY(self.camera.getY(
            ) + 2000 * globalClock.getDt()))
        self.accept(
            'shift-wheel_down', lambda: base.camera.setY(self.camera.getY(
            ) - 2000 * globalClock.getDt()))
        self.isMouse3Down = False
        self.accept('mouse3', self.setMouse3Down)
        self.accept('mouse3-up', self.setMouse3Up)
        self.taskMgr.add(self.thirdPersonCameraTask, 'thirdPersonCameraTask')
        # Add Camera picking
        #self.rollover = Picker(render)
        #taskMgr.add(self.rolloverTask, 'rollover')
        self.picker = Picker(render)
        self.accept('mouse1', self.tryPick)
        self.accept('mouse1-up', self.stopRotation)

        # Setup Lights
        dlight = DirectionalLight('dlight')
        dlight2 = DirectionalLight('dlight2')
        alight = AmbientLight('alight')
        alight.setColor(VBase4(0.2, 0.2, 0.2, 1))
        self.lightnode = render.attachNewNode(dlight)
        self.lightnode2 = render.attachNewNode(dlight2)
        self.lightnode2.setHpr(0, -90, 0)
        self.alightnode = render.attachNewNode(alight)
        render.setLight(self.lightnode)
        render.setLight(self.lightnode2)
        render.setLight(self.alightnode)

        # load models
        m = loader.loadModel("models/grube_simplified_rotated.egg")
        self.trench = render.attachNewNode("trench")
        m.reparentTo(self.trench)
        tbounds = self.trench.getTightBounds()
        p1 = tbounds[0]
        p2 = tbounds[1]
        po = p2 - (p2 - p1) / 2
        m.setPos(-po)
        self.trench.setColor(WHITE)
        self.trench.setCollideMask(BitMask32.allOff())

        self.attachGizmos(self.trench)
        self.rotEnabled = False

        # load grid
        grid = ThreeAxisGrid()
        gridnodepath = grid.create()
        gridnodepath.setTransparency(TransparencyAttrib.MAlpha)
        gridnodepath.setAlphaScale(0.25)
        gridnodepath.reparentTo(render)

        # buttons
        a = DirectButton(text=("X-Sections", "X-Sections", "X-Sections",
                               "disabled"),
                         scale=.05,
                         pos=(-1.2, 0, -0.95),
                         command=self.calculateXSessions)
        a = DirectButton(text=("RotGimbal", "RotGimbal", "RotGimbal",
                               "disabled"),
                         scale=.05,
                         pos=(-0.9, 0, -0.95),
                         command=self.toggleRotGimbal)