Beispiel #1
0
    def __init__(self,
                 parent,
                 offset=(0, 0, 0),
                 value=1,
                 fgColor=(1, 1, 1, 1),
                 bgColor=(0, 0, 0, 1)):
        self.scale = UI_BAR_SCALE
        NodePath.__init__(self, 'bar')
        # Create the foreground rect:
        cmfg = CardMaker('fg')
        cmfg.setFrame(-self.scale, self.scale, -0.1 * self.scale,
                      0.1 * self.scale)
        self.fg = self.attachNewNode(cmfg.generate())
        # Create the background rect:
        cmbg = CardMaker('bg')
        cmbg.setFrame(-self.scale, self.scale, -0.1 * self.scale,
                      0.1 * self.scale)
        self.bg = self.attachNewNode(cmbg.generate())
        """# Create the preview rect:
            cmpv = CardMaker('pv')
            cmpv.setFrame(-self.scale, self.scale,
                          -0.1 * self.scale, 0.1 * self.scale)
            self.pv = self.attachNewNode(cmpv.generate())"""

        # Set colors and values:
        self.fg.setColor(*fgColor)
        self.bg.setColor(*bgColor)
        """self.pv.setColor(*pvColor)"""
        self.setValue(value)
        # Set this bar to follow the transform of the parent.
        self.reparentTo(parent)
        # Offset this bar (most likely to above the parent)
        self.setPos(parent, offset)
        # Make this bar face the camera at all times (bill-boarding):
        self.setBillboardPointEye()
Beispiel #2
0
    def __init__(self, world, app):
        self.world = world

        self.image = PNMImage(self.world.width, 256)

        for z in self.world.zlevels():
            for x in range(self.world.height):
                mix = sum([ZMap.COLORS[self.world.get_block(x, y, z).substance]
                          for y in range(self.world.height)], VBase3F(0.0))
                self.image.setXel(x, z, mix / float(self.world.height))

        self.texture = Texture()
        self.texture.load(self.image)
        self.texture.setMagfilter(Texture.FTNearest)
        self.texture.setMinfilter(Texture.FTNearest)

        cm = CardMaker('zmap')
        cm.setFrame(0.95, 1, -1, 1)
        cm.setUvRange(Point2(1.0, 1.0), Point2(0.0, 1.0 - self.world.depth / 256.0))
        self.zcard = app.render2d.attachNewNode(cm.generate())
        self.zcard.setTexture(self.texture)

        cm = CardMaker('zpointer')
        cm.setFrame(0, 0.05, 0, 1.0 / self.world.depth)
        self.zpointer = app.render2d.attachNewNode(cm.generate())
        self.zpointer.setColorScale(1.0, 0.0, 0.0, 0.4)

        self.accept('slice-changed', self.slice_changed)
Beispiel #3
0
    def __init__(self, scale=1, value=0, r=10, g=0, b=0):
        NodePath.__init__(self, 'healthbar')
        self.value = value
        self.scale = scale
        self.range = 1.0
        self.buff = 0

        cmbg = CardMaker('bg')
        cmbg.setFrame(-scale, scale, -0.1 * scale, 0.1 * scale)
        self.bg = self.attachNewNode(cmbg.generate())

        self.bg.setColor(0.2, 0.2, 0.2, 1)
        self.bg.setPos(0, 0, 5.8)

        cmfg = CardMaker('fg')
        cmfg.setFrame(-scale, scale, -0.1 * scale, 0.1 * scale)
        self.fg = self.bg.attachNewNode(cmfg.generate())

        self.fg.setColor(r, g, b, 1)
        self.fg.setPos(0, -0.1, 0)
        self.fg.setBillboardPointWorld()
        self.bg.setBillboardPointWorld()

        self.fg.clearShader()
        self.bg.clearShader()

        self.setValue(0)
Beispiel #4
0
    def __init__(self, pg_world: PGWorld):
        if pg_world.win is None:
            return
        self.aspect2d_np = NodePath(PGTop("aspect2d"))
        self.aspect2d_np.show(self.CAM_MASK)
        self.para_vis_np = {}
        # make_buffer_func, make_camera_func = pg_world.win.makeTextureBuffer, pg_world.makeCamera

        # don't delete the space in word, it is used to set a proper position
        for i, np_name in enumerate(
            ["Steering", " Throttle", "     Brake", "    Speed"]):
            text = TextNode(np_name)
            text.setText(np_name)
            text.setSlant(0.1)
            textNodePath = self.aspect2d_np.attachNewNode(text)
            textNodePath.setScale(0.052)
            text.setFrameColor(0, 0, 0, 1)
            text.setTextColor(0, 0, 0, 1)
            text.setFrameAsMargin(-self.GAP, self.PARA_VIS_LENGTH, 0, 0)
            text.setAlign(TextNode.ARight)
            textNodePath.setPos(-1.125111, 0, 0.9 - i * 0.08)
            if i != 0:
                cm = CardMaker(np_name)
                cm.setFrame(0, self.PARA_VIS_LENGTH - 0.21,
                            -self.PARA_VIS_HEIGHT / 2 + 0.1,
                            self.PARA_VIS_HEIGHT / 2)
                cm.setHasNormals(True)
                card = textNodePath.attachNewNode(cm.generate())
                card.setPos(0.21, 0, 0.22)
                self.para_vis_np[np_name.lstrip()] = card
            else:
                # left
                name = "Left"
                cm = CardMaker(name)
                cm.setFrame(0, (self.PARA_VIS_LENGTH - 0.4) / 2,
                            -self.PARA_VIS_HEIGHT / 2 + 0.1,
                            self.PARA_VIS_HEIGHT / 2)
                cm.setHasNormals(True)
                card = textNodePath.attachNewNode(cm.generate())
                card.setPos(0.2 + self.PARA_VIS_LENGTH / 2, 0, 0.22)
                self.para_vis_np[name] = card
                # right
                name = "Right"
                cm = CardMaker(np_name)
                cm.setFrame(-(self.PARA_VIS_LENGTH - 0.1) / 2, 0,
                            -self.PARA_VIS_HEIGHT / 2 + 0.1,
                            self.PARA_VIS_HEIGHT / 2)
                cm.setHasNormals(True)
                card = textNodePath.attachNewNode(cm.generate())
                card.setPos(0.2 + self.PARA_VIS_LENGTH / 2, 0, 0.22)
                self.para_vis_np[name] = card
        super(VehiclePanel, self).__init__(self.BUFFER_W,
                                           self.BUFFER_H,
                                           Vec3(-0.9, -1.01, 0.78),
                                           self.BKG_COLOR,
                                           pg_world=pg_world,
                                           parent_node=self.aspect2d_np)
        self.add_to_display(pg_world,
                            [2 / 3, 1, self.display_bottom, self.display_top])
Beispiel #5
0
 def setup_skybox(self,
                  terrctr=645.0,
                  boxsz=1000.0,
                  aspect=1.0,
                  uplift=0.0):
     vsz = boxsz / aspect
     self.bckgtx = []
     self.bckgtx.append(self.loader.loadTexture('sky/Back2.png'))
     self.bckgtx.append(self.loader.loadTexture('sky/Right2.png'))
     self.bckgtx.append(self.loader.loadTexture('sky/Front2.png'))
     self.bckgtx.append(self.loader.loadTexture('sky/Left2.png'))
     self.bckgtx.append(self.loader.loadTexture('sky/Up.png'))
     for a in range(4):
         self.bckg = CardMaker('bkcard')
         lr = Point3(0.5 * boxsz, 0.5 * boxsz, -0.5 * vsz)
         ur = Point3(0.5 * boxsz, 0.5 * boxsz, 0.5 * vsz)
         ul = Point3(-0.5 * boxsz, 0.5 * boxsz, 0.5 * vsz)
         ll = Point3(-0.5 * boxsz, 0.5 * boxsz, -0.5 * vsz)
         self.bckg.setFrame(ll, lr, ur, ul)
         self.bckg.setHasNormals(0)
         self.bckg.setHasUvs(1)
         #self.bckg.setUvRange(self.bckgtx[a])
         bkcrd = self.render.attachNewNode(self.bckg.generate())
         bkcrd.setTexture(self.bckgtx[a])
         self.bckgtx[a].setWrapU(Texture.WMClamp)
         self.bckgtx[a].setWrapV(Texture.WMClamp)
         bkcrd.setLightOff()
         bkcrd.setFogOff()
         bkcrd.setHpr(90.0 * a, 0, 0)
         cz = 0.5 * boxsz * uplift
         #print 'set card at:', terrctr,terrctr,cz, ' with points: ', lr,ur,ul,ll
         bkcrd.setPos(terrctr, terrctr, cz)
         self.top = CardMaker('bkcard')
         lr = Point3(0.5 * boxsz, -0.5 * boxsz, 0)
         ur = Point3(0.5 * boxsz, 0.5 * boxsz, 0)
         ul = Point3(-0.5 * boxsz, 0.5 * boxsz, 0)
         ll = Point3(-0.5 * boxsz, -0.5 * boxsz, 0)
         self.top.setFrame(ll, lr, ur, ul)
         self.top.setHasNormals(0)
         self.top.setHasUvs(1)
         #self.top.setUvRange(self.bckgtx[4])
         bkcrd = self.render.attachNewNode(self.bckg.generate())
         bkcrd.setTexture(self.bckgtx[4])
         self.bckgtx[4].setWrapU(Texture.WMClamp)
         self.bckgtx[4].setWrapV(Texture.WMClamp)
         bkcrd.setLightOff()
         bkcrd.setFogOff()
         bkcrd.setHpr(0, 90, 90)
         bkcrd.setPos(terrctr, terrctr, 0.5 * vsz + 0.5 * boxsz * uplift)
Beispiel #6
0
 def _initModel(self):
     baseName = '**/tt_t_gui_cmg_miniMap_'
     cardModel = CogdoUtil.loadMazeModel('miniMap_cards', group='gui')
     cm = CardMaker('bg')
     cm.setFrame(-1.1, 1.1, -1.1, 1.1)
     bg = self.attachNewNode(cm.generate())
     bg.setColor(*self._bgColor)
     bg.setBin('fixed', 0)
     frame = cardModel.find(baseName + 'frame')
     frame.reparentTo(self)
     frame.setScale(2.5)
     frame.setPos(0.01, 0, -0.01)
     self._entrance = cardModel.find(baseName + 'entrance')
     self._entrance.reparentTo(self)
     self._entrance.setScale(0.35)
     self._entrance.hide()
     self._exit = NodePath('exit')
     self._exit.setScale(0.35)
     self._exit.reparentTo(self)
     self._exitOpen = cardModel.find(baseName + 'exitOpen')
     self._exitOpen.reparentTo(self._exit)
     self._exitClosed = cardModel.find(baseName + 'exitClosed')
     self._exitClosed.reparentTo(self._exit)
     self._suitMarkerTemplate = cardModel.find(baseName + 'cogIcon')
     self._suitMarkerTemplate.detachNode()
     self._suitMarkerTemplate.setScale(0.225)
     self._waterCoolerTemplate = cardModel.find(baseName + 'waterDrop')
     self._waterCoolerTemplate.detachNode()
     self._waterCoolerTemplate.setScale(0.225)
     self._exit.hide()
     cardModel.removeNode()
Beispiel #7
0
 def announceGenerate(self):
     DistributedObject.DistributedObject.announceGenerate(self)
     self.sendUpdate('avIdEnteredParty', [base.localAvatar.doId])
     globalClock.syncFrameTime()
     self.startPartyClock()
     base.localAvatar.chatMgr.chatInputSpeedChat.addInsidePartiesMenu()
     self.spawnTitleText()
     messenger.send(self.generatedEvent)
     if config.GetBool('show-debug-party-grid', 0):
         self.testGrid = NodePath('test_grid')
         self.testGrid.reparentTo(base.cr.playGame.hood.loader.geom)
         for i in xrange(len(self.grid)):
             for j in xrange(len(self.grid[i])):
                 cm = CardMaker('gridsquare')
                 np = NodePath(cm.generate())
                 np.setScale(12)
                 np.setP(-90.0)
                 np.setPos(
                     PartyUtils.convertDistanceFromPartyGrid(j, 0) - 6.0,
                     PartyUtils.convertDistanceFromPartyGrid(i, 1) - 6.0,
                     0.1)
                 np.reparentTo(self.testGrid)
                 if self.grid[i][j]:
                     np.setColorScale(0.0, 1.0, 0.0, 1.0)
                 else:
                     np.setColorScale(1.0, 0.0, 0.0, 1.0)
    def __init__(self, texture_cube, window_size=512, texture_size=512):
        super().__init__()
        self.cube_ind = 0
        self.num_slices = texture_cube.shape[0]
        self.cube = texture_cube

        # SET Frame rate
        ShowBaseGlobal.globalClock.setMode(ClockObject.MLimited)
        ShowBaseGlobal.globalClock.setFrameRate(40)  #can lock this at

        #Create texture stage
        self.texture = Texture("Stimulus")
        #        self.texture.setMagfilter(SamplerState.FT_nearest)
        #        self.texture.setMinfilter(SamplerState.FT_nearest)
        self.texture.setup2dTexture(texture_size, texture_size,
                                    Texture.T_unsigned_byte,
                                    Texture.F_luminance)
        self.texture.setRamImageAs(self.cube[0, :, :], "L")
        self.textureStage = TextureStage("Stimulus")

        #Create scenegraph
        cm = CardMaker('card1')
        cm.setFrameFullscreenQuad()
        self.card1 = self.aspect2d.attachNewNode(cm.generate())
        self.card1.setTexture(self.textureStage, self.texture)  #ts, tx
        ShowBaseGlobal.base.setFrameRateMeter(True)

        self.taskMgr.add(self.setTextureTask, "setTextureTask")
Beispiel #9
0
def loadVideo(videoFileName, loop=False):
    videoPathStr = 'Video/{}'
    videoPathStr = videoPathStr.format(videoFileName)

    try:
        tex = MovieTexture(videoFileName)
        success = tex.read(videoPathStr)
        assert success, "Failed to load video!"

        # Set up a fullscreen card to set the video texture on.
        cm = CardMaker("My Fullscreen Card")
        cm.setFrameFullscreenQuad()
        # Tell the CardMaker to create texture coordinates that take into
        # account the padding region of the texture.
        cm.setUvRange(tex)
        # Now place the card in the scene graph and apply the texture to it.
        card = render2d.attachNewNode(cm.generate())
        card.setTexture(tex)
        card.hide()
        sound = loader.loadMusic(videoPathStr)
        # set loop false
        sound.setLoop(loop)
        # Synchronize the video to the sound.
        tex.synchronizeTo(sound)

        return sound, card
    except Exception as e:
        #logging.debug("loadvideo: {}".format(traceback.format_exc()))
        pass
    return sound, card
    def _createMapTextureCard(self):
        mapImage = PNMImage(MAP_RESOLUTION, MAP_RESOLUTION)
        mapImage.fill(*self._bgColor)
        fgColor = VBase4D(*self._fgColor)
        for x in range(self._mazeHeight):
            for y in range(self._mazeWidth):
                if self._mazeCollTable[y][x] == 1:
                    ax = float(x) / self._mazeWidth * MAP_RESOLUTION
                    invertedY = self._mazeHeight - 1 - y
                    ay = float(invertedY) / self._mazeHeight * MAP_RESOLUTION
                    self._drawSquare(mapImage, int(ax), int(ay), 10, fgColor)

        mapTexture = Texture('mapTexture')
        mapTexture.setupTexture(Texture.TT2dTexture, self._maskResolution,
                                self._maskResolution, 1, Texture.TUnsignedByte,
                                Texture.FRgba)
        mapTexture.setMinfilter(Texture.FTLinear)
        mapTexture.load(mapImage)
        mapTexture.setWrapU(Texture.WMClamp)
        mapTexture.setWrapV(Texture.WMClamp)
        mapImage.clear()
        del mapImage
        cm = CardMaker('map_cardMaker')
        cm.setFrame(-1.0, 1.0, -1.0, 1.0)
        map = self.attachNewNode(cm.generate())
        map.setTexture(mapTexture, 1)
        return map
 def cardmaker_debug(self):
     for node in render2d.find_all_matches("pfm"):
         node.remove_node()
     for text in base.a2dBottomLeft.find_all_matches("*"):
         text.remove_node()
     width = 0.2  # render2d coordinates range: [-1..1]
     # Pseudo-normalize our PfmFile for better contrast.
     normalized_pfm = PfmFile(self.RotorPFM)
     max_p = LVector3()
     normalized_pfm.calc_min_max(LVector3(), max_p)
     normalized_pfm *= 1.0 / max_p.x
     # Put it in a texture
     tex = Texture()
     tex.load(normalized_pfm)
     # Apply the texture to a quad and put it in the lower left corner.
     cm = CardMaker("pfm")
     cm.set_frame(0, width, 0,
         width / normalized_pfm.get_x_size() * normalized_pfm.get_y_size())
     card = base.render2d.attach_new_node(cm.generate())
     card.set_pos(-1, 0, -1)        
     card.set_texture(tex)
     # Display max value text
     self.genLabelText(-3,
                       "Max value: {:.3f} == {:.2f}m".format(max_p.x,
                         max_p.x * self.terrain_scale.z),
                       parent="a2dBottomLeft")
Beispiel #12
0
    def create_geom(self, loader):
        """Creates self.geom_node from self.terrain_map."""
        # geom_builder = GeomBuilder('floor')
        map_size = len(self.terrain_map)
        unit_size = map_params.unit_size
        start_pos = -map_size*unit_size/2
        # colors = map_params.colors

        # geom_builder.add_rect(
        #     colors.floor,
        #     start_pos, start_pos, 0,
        #     -start_pos, -start_pos, 0
        # )
        card_maker = CardMaker("cm")
        card_maker.setFrame(
            Point3(-start_pos, -start_pos, 0),
            Point3(+start_pos, -start_pos, 0),
            Point3(+start_pos, +start_pos, 0),
            Point3(-start_pos, +start_pos, 0)
        )
        card_maker.setColor(map_params.colors.floor)

        floor_node = NodePath(card_maker.generate())
        floor_node.reparentTo(self.geom_node)
        # floor_node.setHpr(0, 90, 0)
        # floor_node.setPos(0, 0, 0)
        tex = loader.loadTexture('models/floor.png')
        floor_node.setTexture(tex, 1)
        floor_node.setTexScale(TextureStage.getDefault(), map_size, map_size)

        def get(i, j):
            return isinstance(self.get_tile(i, j), Wall)

        wall_count = 0
        for i in range(map_size-1):
            for j in range(map_size-1):
                if any([get(i, j), get(i+1, j), get(i+1, j+1), get(i, j+1)]):
                    wall_count += 1

        def callback():
            self.geom_node.clearModelNodes()
            self.geom_node.flattenStrong()

        threads = Threads(wall_count, callback)

        for i in range(map_size-1):
            for j in range(map_size-1):
                current_position = (
                    start_pos+i*unit_size,
                    start_pos+j*unit_size, 0
                )
                render_wall(
                    current_position,
                    [get(i, j), get(i+1, j),
                        get(i+1, j+1), get(i, j+1)],
                    ((i+j) & 1)+1,
                    self.geom_node,
                    loader,
                    threads
                )
Beispiel #13
0
    def scene_init(self, render, loader):
        # self.scene = self.loader.loadModel("models/environment")
        # self.scene.reparentTo(self.render)

        # region texture
        floor_texture = loader.loadTexture("models/maps/envir-ground.jpg")
        floor_texture.setMinfilter(SamplerState.FT_linear_mipmap_linear)

        wall_texture = loader.loadTexture("models/maps/envir-reeds.png")
        # endregion

        # region floor
        floor_card_maker = CardMaker("floor")
        floor_card_maker.setUvRange((0, 0), (self.size / 10, self.size / 10))
        floor_gfx = render.attachNewNode(CardMaker.generate(floor_card_maker))
        floor_gfx.setP(-90)  # This rotates the card to face upwards
        floor_gfx.setPos(-self.size / 2, -self.size / 2, 0)
        floor_gfx.setScale(self.size)

        floor_gfx.setTexture(floor_texture)
        # endregion

        # region walls

        self.create_wall(render, wall_texture, -90, 0, 0)
        self.create_wall_collider(render, 0, 1, -180)

        self.create_wall(render, wall_texture, 0, 90, -90)
        self.create_wall_collider(render, 0, -1, 0)

        self.create_wall(render, wall_texture, 90, -90, -180)
        self.create_wall_collider(render, 1, 0, 90)

        self.create_wall(render, wall_texture, -90, -90, -270)
        self.create_wall_collider(render, -1, 0, -90)
Beispiel #14
0
 def renderQuadInto(self, mul=1, div=1, align=1, depthtex=None, colortex=None, auxtex0=None, auxtex1=None):
     texgroup = (
      depthtex, colortex, auxtex0, auxtex1)
     winx, winy = self.getScaledSize(mul, div, align)
     depthbits = bool(depthtex != None)
     buffer = self.createBuffer('filter-stage', winx, winy, texgroup, depthbits)
     if buffer == None:
         return
     cm = CardMaker('filter-stage-quad')
     cm.setFrameFullscreenQuad()
     quad = NodePath(cm.generate())
     quad.setDepthTest(0)
     quad.setDepthWrite(0)
     quad.setColor(1, 0.5, 0.5, 1)
     quadcamnode = Camera('filter-quad-cam')
     lens = OrthographicLens()
     lens.setFilmSize(2, 2)
     lens.setFilmOffset(0, 0)
     lens.setNearFar(-1000, 1000)
     quadcamnode.setLens(lens)
     quadcam = quad.attachNewNode(quadcamnode)
     dr = buffer.makeDisplayRegion((0, 1, 0, 1))
     dr.disableClears()
     dr.setCamera(quadcam)
     dr.setActive(True)
     dr.setScissorEnabled(False)
     buffer.setClearColor((0, 0, 0, 1))
     buffer.setClearColorActive(True)
     self.buffers.append(buffer)
     self.sizes.append((mul, div, align))
     return quad
Beispiel #15
0
    def buildShadow(self):
        self.cleanupShadow()
        if not self.dropShadowPath or not self.avatar: return

        self.dropShadow = NodePath('locationIndicatorRoot')

        cm = CardMaker('locationIndicator')
        cm.setFrame(-1, 1, -1, 1)
        indicatorNP = self.dropShadow.attachNewNode(cm.generate())
        indicatorNP.setBSPMaterial(self.crosshairMaterial, 1)
        indicatorNP.setScale(self.shadowScale * 2.5)
        indicatorNP.setDepthOffset(16)
        indicatorNP.setTransparency(1)
        indicatorNP.setP(-90)
        indicatorNP.flattenStrong()

        self.confirmIndTrack = Sequence(
            Parallel(
                LerpHprInterval(self.dropShadow,
                                duration=0.2,
                                hpr=(360, 0, 0),
                                startHpr=(0, 0, 0)),
                LerpScaleInterval(self.dropShadow,
                                  duration=0.2,
                                  scale=0.01,
                                  startScale=1)),
            Func(self.gag.cleanupLocationSeeker))
Beispiel #16
0
    def __init__(self, experiment_structure, profile_on=False):
        super().__init__()
        self.current_stim_num = 0
        self.stim_classes = experiment_structure['stim_classes']
        self.stim_values = experiment_structure['stim_values']
        self.stim_durations = experiment_structure['stim_durations']
        self.stim_change_times = np.cumsum(
            self.stim_durations)  #times to switch
        self.bgcolor = (1, 1, 1, 1)

        #Set up profiling if desired
        if profile_on:
            PStatClient.connect()

        #Window properties
        self.windowProps = WindowProperties()
        self.windowProps.setSize(512, 512)

        #Create scenegraph
        cm = CardMaker('card')
        cm.setFrameFullscreenQuad()
        self.card = self.aspect2d.attachNewNode(cm.generate())
        self.card.setScale(np.sqrt(8))
        self.card.setColor(self.bgcolor)  #make this an add mode

        #Set initial texture
        self.taskMgr.add(self.set_stim_task, "set_stimulus_class")
Beispiel #17
0
 def __init__(self, startSize, endSize, roll, color, duration):
     NodePath.__init__(self, 'muzzleParticle')
     
     cm = CardMaker("muzzleSpriteCard")
     cm.setFrame(-1, 1, -1, 1)
     cm.setHasUvs(True)
     cm.setUvRange((0, 0), (1, 1))
     cmnp = self.attachNewNode(cm.generate())
     cmnp.setBillboardAxis()
     
     self.setTexture(loader.loadTexture(self.muzzleroot.format(random.randint(*self.muzzles))), 1)
     #self.setShaderOff(1)
     self.setLightOff(1)
     self.setMaterialOff(1)
     self.setAttrib(ColorBlendAttrib.make(ColorBlendAttrib.MAdd, ColorBlendAttrib.OOne, ColorBlendAttrib.OOne), 1)
     self.setDepthWrite(False, 1)
     #self.setTransparency(1)
     
     self.startAlpha = 0.5
     self.endAlpha = 0.0
     self.duration = duration
     self.startSize = startSize
     self.endSize = endSize
     self.color = color
     self.startTime = globalClock.getFrameTime()
     self.roll = roll
     taskMgr.add(self.particleUpdate, "muzzleParticleUpdate-" + str(id(self)))
Beispiel #18
0
    def draw_floor(self):
        # Load the scene.
        # if self.box.dimensions < 3:
        #     return
        floorTex = self.loader.loadTexture('maps/grid.jpg')

        cm = CardMaker('')
        # cm.setFrame(-2, 2, -2, 2)
        X = self.box.box_sizes[0]
        if self.box.dimensions > 1:
            Y = self.box.box_sizes[1]
        else:
            Y = X
        cm.setFrame(0, X, 0, Y)
        # cm.setFrame(0, 0, self.box.box_sizes[0], self.box.box_sizes[1])
        floor = self.render.attachNewNode(PandaNode("floor"))
        floor.reparentTo(self.boxnode)
        for y in range(1):
            for x in range(1):
                nn = floor.attachNewNode(cm.generate())
                nn.setP(-90)
                # nn.setPos((x - 6) * 4, (y - 6) * 4, 0)
                nn.setPos((x - 0) * 4, (y - 0) * 4, 0)
        floor.setTexture(floorTex)
        floor.flattenStrong()
        floor.setTwoSided(True)
Beispiel #19
0
 def setupTexture(self):
     cm = CardMaker('quadMaker')
     cm.setColor(1.0, 1.0, 1.0, 1.0)
     aspect = base.camLens.getAspectRatio()
     htmlWidth = 2.0 * aspect * WEB_WIDTH_PIXELS / float(WIN_WIDTH)
     htmlHeight = 2.0 * float(WEB_HEIGHT_PIXELS) / float(WIN_HEIGHT)
     cm.setFrame(-htmlWidth / 2.0, htmlWidth / 2.0, -htmlHeight / 2.0, htmlHeight / 2.0)
     bottomRightX = WEB_WIDTH_PIXELS / float(WEB_WIDTH + 1)
     bottomRightY = WEB_HEIGHT_PIXELS / float(WEB_HEIGHT + 1)
     cm.setUvRange(Point2(0, 1 - bottomRightY), Point2(bottomRightX, 1))
     card = cm.generate()
     self.quad = NodePath(card)
     self.quad.reparentTo(self.parent_)
     self.guiTex = Texture('guiTex')
     self.guiTex.setupTexture(Texture.TT2dTexture, WEB_WIDTH, WEB_HEIGHT, 1, Texture.TUnsignedByte, Texture.FRgba)
     self.guiTex.setMinfilter(Texture.FTLinear)
     self.guiTex.setKeepRamImage(True)
     self.guiTex.makeRamImage()
     self.guiTex.setWrapU(Texture.WMRepeat)
     self.guiTex.setWrapV(Texture.WMRepeat)
     ts = TextureStage('webTS')
     self.quad.setTexture(ts, self.guiTex)
     self.quad.setTexScale(ts, 1.0, -1.0)
     self.quad.setTransparency(0)
     self.quad.setTwoSided(True)
     self.quad.setColor(1.0, 1.0, 1.0, 1.0)
     self.calcMouseLimits()
    def enterShow(self, ts=0):
        self.darkenInterior()
        self.cr.playGame.hood.loader.interiorMusic.stop()

        videoFile = CinemaGlobals.Cinemas[self.cinemaIndex][0]
        audioFile = CinemaGlobals.Cinemas[self.cinemaIndex][1]

        self.movieTex = MovieTexture(self.uniqueName("movieTex"))
        self.movieTex.read(videoFile)
        card = CardMaker(self.uniqueName('movieCard'))
        card.setFrame(-1.5, 1.5, -1, 1)
        self.movieCard = NodePath(card.generate())
        self.movieCard.reparentTo(render)
        self.movieCard.setPos(
            self.interior.find('**/sign_origin;+s').getPos(render))
        #self.movieCard.setX(self.movieCard, -0.05)
        self.movieCard.setHpr(
            self.interior.find('**/sign_origin;+s').getHpr(render))
        self.movieCard.setDepthWrite(1, 1)
        self.movieCard.setTwoSided(True)
        self.movieCard.setTexture(self.movieTex)
        self.movieCard.setTexScale(TextureStage.getDefault(),
                                   self.movieTex.getTexScale())
        self.movieCard.setScale(2.5)
        self.movieSound = base.loadSfx(audioFile)
        self.movieTex.synchronizeTo(self.movieSound)
        self.movieTrack = SoundInterval(self.movieSound,
                                        name=self.uniqueName('movieTrack'))
        self.movieTrack.setDoneEvent(self.movieTrack.getName())
        self.acceptOnce(self.movieTrack.getDoneEvent(), self.fsm.request,
                        ['off'])
        self.movieTrack.start(ts)
Beispiel #21
0
    def load(self):
        Entity.load(self)

        scale = self.getEntityValueFloat("spriteScale")
        color = self.getEntityValueColor("spriteColor")

        sunVec = base.shaderGenerator.getSunVector()
        self.pivotNode = camera.attachNewNode('env_sun-pivot')
        self.pivotNode.lookAt(sunVec)
        self.pivotNode.setCompass()

        cm = CardMaker('sun_sprite')
        cm.setFrame(-0.5, 0.5, -0.5, 0.5)
        self.sunSprite = self.pivotNode.attachNewNode(
            GlowNode(cm.generate(), 32.0 * scale))
        self.sunSprite.setAttrib(
            ColorBlendAttrib.make(ColorBlendAttrib.MAdd, ColorBlendAttrib.OOne,
                                  ColorBlendAttrib.OOne), 1)
        self.sunSprite.setBSPMaterial("phase_14/materials/sun/sunsprite.mat",
                                      1)
        self.sunSprite.setFogOff(10)
        self.sunSprite.setBillboardPointEye()
        self.sunSprite.setDepthTest(False)
        self.sunSprite.setDepthWrite(False)
        self.sunSprite.setScale(scale * 100)
        self.sunSprite.setColorScale(color, 1)
        self.sunSprite.setY(1000)
        self.sunSprite.node().setBounds(OmniBoundingVolume())
        self.sunSprite.node().setFinal(True)
 def __init__(self, startSize, endSize, roll, color, duration):
     NodePath.__init__(self, 'muzzleParticle')
     
     muzzles = [1, 4]
     muzzleroot = "phase_14/hl2/muzzleflash{0}.png"
     
     cm = CardMaker("muzzleSpriteCard")
     cm.setFrame(-1, 1, -1, 1)
     cm.setHasUvs(True)
     cm.setUvRange((0, 0), (1, 1))
     cmnp = self.attachNewNode(cm.generate())
     cmnp.setBillboardAxis()
     
     self.setTexture(loader.loadTexture(muzzleroot.format(random.randint(*muzzles))), 1)
     #self.setShaderOff(1)
     self.setLightOff(1)
     self.setMaterialOff(1)
     self.setTransparency(1)
     
     self.startAlpha = 0.5
     self.endAlpha = 0.0
     self.duration = duration
     self.startSize = startSize
     self.endSize = endSize
     self.color = color
     self.startTime = globalClock.getFrameTime()
     self.roll = roll
     taskMgr.add(self.particleUpdate, "muzzleParticleUpdate-" + str(id(self)))
 def _createSimpleMarker(self, size, color=(1, 1, 1)):
     halfSize = size * 0.5
     cm = CardMaker('mazemap_simple_marker')
     cm.setFrame(-halfSize, halfSize, -halfSize, halfSize)
     markerNP = self.maskedLayer.attachNewNode(cm.generate())
     markerNP.setColor(*color)
     return markerNP
Beispiel #24
0
 def genArrow(self, pos, hpr, id):
     factory = CardMaker('factory')
     factory.setFrame(-0.5, 0.5, -0.5, 0.5)
     arrowNode = factory.generate()
     arrowRoot = NodePath('root')
     baseArrow = NodePath(arrowNode)
     baseArrow.setTransparency(1)
     baseArrow.setTexture(self.boostArrowTexture)
     baseArrow.reparentTo(arrowRoot)
     arrow2 = baseArrow.copyTo(baseArrow)
     arrow2.setPos(0, 0, 1)
     arrow3 = arrow2.copyTo(arrow2)
     arrowRoot.setPos(*pos)
     arrowRoot.setHpr(*hpr)
     baseArrow.setHpr(0, -90, 0)
     baseArrow.setScale(24)
     arrowRoot.reparentTo(self.geom)
     trigger = 'boostArrow' + str(id)
     cs = CollisionTube(Point3(0.6, -6, 0), Point3(0.6, 54, 0), 4.8)
     cs.setTangible(0)
     triggerEvent = 'imIn-' + trigger
     cn = CollisionNode(trigger)
     cn.addSolid(cs)
     cn.setIntoCollideMask(BitMask32(32768))
     cn.setFromCollideMask(BitMask32(32768))
     cnp = NodePath(cn)
     cnp.reparentTo(arrowRoot)
     self.accept(triggerEvent, self.hitBoostArrow)
     arrowVec = arrow2.getPos(self.geom) - baseArrow.getPos(self.geom)
     arrowVec.normalize()
     idStr = str(id)
     cnp.setTag('boostId', idStr)
     self.boostDir[idStr] = arrowVec
     base.arrows.append(arrowRoot)
Beispiel #25
0
    def generate(self, helperInfo):
        MapHelper.generate(self)

        # Check for a color255 to tint the sprite
        color255Props = self.mapObject.getPropsWithValueType(
            ['color255', 'color1'])
        # If we have a color255 property, select the first one.
        color255Prop = color255Props[0] if len(color255Props) > 0 else None
        if color255Prop:
            color = self.mapObject.getPropertyValue(color255Prop)
            color = LEGlobals.colorFromRGBScalar255(color)
        else:
            color = Vec4(1)

        spritePath = helperInfo['args'][0].replace("\"", "")

        cm = CardMaker("sprite")
        cm.setFrame(-0.75, 0.75, -0.75, 0.75)
        np = NodePath(cm.generate())
        #np.setBSPMaterial(spritePath)
        np.setTexture(base.loader.loadTexture(spritePath))
        np.setColorScale(color)
        np.setLightOff(1)
        np.setFogOff(1)
        np.setBillboardPointEye()
        np.setTransparency(True)
        np.hide(~VIEWPORT_3D_MASK)
        np.reparentTo(self.mapObject.helperRoot)
        self.sprite = np
Beispiel #26
0
    def rebuild(self, view_size):
        self.view_size = view_size
        props = base.win.getProperties()
        y = props.getYSize()
        pxm = float(y) / self.view_size
        hsize = 12 / pxm
        vsize = 40 / pxm
        #print(hsize, vsize)
        cm = CardMaker('card')
        cm.setFrame(LPoint3(-hsize, 0, 0), LPoint3(hsize, 0, 0),
                    LPoint3(hsize, vsize, 0), LPoint3(-hsize, vsize, 0))

        for n in self.nodes:
            n.removeNode()

        self.nodes = []
        for m in self.markers:
            node = NodePath(cm.generate())
            node.setTexture(self.icon, 1)
            node.setTransparency(TransparencyAttrib.MAlpha)
            node.setDepthTest(False)
            node.setDepthWrite(False)
            node.setBin("unsorted", 1)
            ned = m['ned']
            node.setPos(ned[1], ned[0], 0)
            node.reparentTo(self.render)
            self.nodes.append(node)
 def loadFlatQuad(self, fullFilename):
     cm = CardMaker('cm-%s' % fullFilename)
     cm.setColor(1.0, 1.0, 1.0, 1.0)
     aspect = base.camLens.getAspectRatio()
     htmlWidth = 2.0 * aspect * WEB_WIDTH_PIXELS / float(WIN_WIDTH)
     htmlHeight = 2.0 * float(WEB_HEIGHT_PIXELS) / float(WIN_HEIGHT)
     cm.setFrame(-htmlWidth / 2.0, htmlWidth / 2.0, -htmlHeight / 2.0,
                 htmlHeight / 2.0)
     bottomRightX = WEB_WIDTH_PIXELS / float(WEB_WIDTH + 1)
     bottomRightY = WEB_HEIGHT_PIXELS / float(WEB_HEIGHT + 1)
     cm.setUvRange(Point2(0, 1 - bottomRightY), Point2(bottomRightX, 1))
     card = cm.generate()
     quad = NodePath(card)
     jpgFile = PNMImage(WEB_WIDTH, WEB_HEIGHT)
     smallerJpgFile = PNMImage()
     readFile = smallerJpgFile.read(Filename(fullFilename))
     if readFile:
         jpgFile.copySubImage(smallerJpgFile, 0, 0)
         guiTex = Texture('guiTex')
         guiTex.setupTexture(Texture.TT2dTexture, WEB_WIDTH, WEB_HEIGHT, 1,
                             Texture.TUnsignedByte, Texture.FRgba)
         guiTex.setMinfilter(Texture.FTLinear)
         guiTex.load(jpgFile)
         guiTex.setWrapU(Texture.WMClamp)
         guiTex.setWrapV(Texture.WMClamp)
         ts = TextureStage('webTS')
         quad.setTexture(ts, guiTex)
         quad.setTransparency(0)
         quad.setTwoSided(True)
         quad.setColor(1.0, 1.0, 1.0, 1.0)
         result = quad
     else:
         result = None
     Texture.setTexturesPower2(1)
     return result
Beispiel #28
0
 def generateAnalysis(self):
     if self.analyzeMode:
         self.cleanupAnalysis()
     
     self.analyzeMode = True
     cm = CardMaker('cm')
     self.analysisBar.show()
     loadingTime = self.loadingEnd - self.loadingStart
     for stepName in self.stepInfo:
         (startTime, duration, color, ticks, startPercent, percent, expectedTicks) = self.stepInfo[stepName]
         cm.setName(stepName)
         cm.setColor(color)
         cm.setFrame((startTime / loadingTime) * 1.8 - 0.90000000000000002, ((startTime + duration) / loadingTime) * 1.8 - 0.90000000000000002, -0.5, -0.10000000000000001)
         self.analysisBarRoot.attachNewNode(cm.generate())
         button = DirectFrame(parent = self.analysisBarRoot, geom = NodePath('empty'), image = NodePath('empty'), state = DGG.NORMAL, relief = None, frameSize = ((startTime / loadingTime) * 1.8 - 0.90000000000000002, ((startTime + duration) / loadingTime) * 1.8 - 0.90000000000000002, -0.5, -0.10000000000000001))
         button.bind(DGG.ENTER, self.showInfo, extraArgs = [
             stepName])
         self.analysisButtons.append(button)
         button = DirectFrame(parent = self.analysisBarRoot, geom = NodePath('empty'), image = NodePath('empty'), state = DGG.NORMAL, relief = None, frameSize = ((startPercent / self.loadScale / 100.0) * 1.8 - 0.90000000000000002, ((startPercent + percent) / self.loadScale / 100.0) * 1.8 - 0.90000000000000002, 0.10000000000000001, 0.5))
         button.bind(DGG.ENTER, self.showInfo, extraArgs = [
             stepName])
         self.analysisButtons.append(button)
         for tick in ticks:
             self.line.moveTo(VBase3((tick / loadingTime) * 1.8 - 0.90000000000000002, 0, -0.5))
             self.line.drawTo(VBase3((tick / loadingTime) * 1.8 - 0.90000000000000002, 0, -0.55000000000000004))
         
     
     for tick in self.unmappedTicks:
         self.line.moveTo(VBase3((tick / loadingTime) * 1.8 - 0.90000000000000002, 0, -0.5))
         self.line.drawTo(VBase3((tick / loadingTime) * 1.8 - 0.90000000000000002, 0, -0.55000000000000004))
     
     self.analysisSegs = self.analysisBarRoot.attachNewNode(self.line.create())
Beispiel #29
0
    def create_cards(self):
        """ 
        Create cards: these are panda3d objects that are required for displaying textures.
        You can't just have a disembodied texture. In pandastim (at least for now) we are
        only showing 2d projections of textures, so we use cards.       
        """
        cardmaker = CardMaker("stimcard")
        cardmaker.setFrameFullscreenQuad()
        #Binocular cards
        if self.current_stim_params['stim_type'] == 'b':
            self.setBackgroundColor(
                (0, 0, 0, 1))  # without this the cards will appear washed out
            self.left_card = self.aspect2d.attachNewNode(cardmaker.generate())
            self.left_card.setAttrib(
                ColorBlendAttrib.make(
                    ColorBlendAttrib.M_add))  # otherwise only right card shows

            self.right_card = self.aspect2d.attachNewNode(cardmaker.generate())
            self.right_card.setAttrib(
                ColorBlendAttrib.make(ColorBlendAttrib.M_add))
            if self.profile_on:
                self.center_indicator = OnscreenText(
                    "x",
                    style=1,
                    fg=(1, 1, 1, 1),
                    bg=(0, 0, 0, .8),
                    pos=self.current_stim_params['position'],
                    scale=0.05)
        # Tex card
        elif self.current_stim_params['stim_type'] == 's':
            self.card = self.aspect2d.attachNewNode(cardmaker.generate())
            self.card.setColor((1, 1, 1, 1))  #?
            self.card.setScale(self.scale)
        return
Beispiel #30
0
    def create_instance(self):
        self.create_buffer()
        # Water surface
        maker = CardMaker('water')
        maker.setFrame(self.x1, self.x2, self.y1, self.y2)

        self.waterNP = self.parent.instance.attachNewNode(maker.generate())
        self.waterNP.setHpr(0, -90, 0)
        self.waterNP.setPos(0, 0, self.z)
        self.waterNP.setTransparency(TransparencyAttrib.MAlpha)
        self.waterNP.setShader(Shader.load(Shader.SL_GLSL,
                                           vertex=defaultDirContext.find_shader('water-vertex.glsl'),
                                           fragment=defaultDirContext.find_shader('water-fragment.glsl')))
        self.waterNP.setShaderInput('wateranim', Vec4(0.03, -0.015, self.scale, 0)) # vx, vy, scale, skip
        # offset, strength, refraction factor (0=perfect mirror, 1=total refraction), refractivity
        self.waterNP.setShaderInput('waterdistort', Vec4(0.4, 4.0, 0.25, 0.45))
        self.waterNP.setShaderInput('time', 0)

        # Reflection plane
        self.waterPlane = Plane(Vec3(0, 0, self.z + 1), Point3(0, 0, self.z))
        planeNode = PlaneNode('waterPlane')
        planeNode.setPlane(self.waterPlane)

        # reflection texture, created in realtime by the 'water camera'
        tex0 = self.buffer.getTexture()
        tex0.setWrapU(Texture.WMClamp)
        tex0.setWrapV(Texture.WMClamp)
        ts0 = TextureStage('reflection')
        self.waterNP.setTexture(ts0, tex0)

        # distortion texture
        tex1 = loader.loadTexture('textures/water.png')
        ts1 = TextureStage('distortion')
        self.waterNP.setTexture(ts1, tex1)
        self.task = taskMgr.add(self.update, "waterTask")