Example #1
0
 def add_ground(self):
     cm = CardMaker("ground")
     cm.setFrame(-1, 1, -1, 1)
     ground = render.attachNewNode(cm.generate())
     ground.setColor(0.5, 0.7, 0.8)
     ground.lookAt(0, 0, -1)
     groundGeom = OdePlaneGeom(self.space, Vec4(0, 0, 1, 0))
Example #2
0
 def genArrow(self, pos, hpr, id):
     factory = CardMaker('factory')
     factory.setFrame(-.5, 0.5, -.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)
Example #3
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)
Example #4
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)
Example #5
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
                )
Example #6
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)))
Example #7
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))
Example #8
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")
    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
Example #10
0
    def __init__(self, battleGraphics, matrixContainer):
        self.battleGraphics = battleGraphics
        self.matrixContainer = matrixContainer

        self.curtex = loader.loadTexture(GAME+'/textures/cursor.png')
        self.curtex.setMagfilter(Texture.FTNearest)
        self.curtex.setMinfilter(Texture.FTNearest)

        self.x = False
        self.y = False
        self.z = False

        self.cursor = loader.loadModel(GAME+'/models/slopes/flat')
        self.cursor.reparentTo( self.matrixContainer )
        self.cursor.setScale(3.7)
        self.cursor.setTransparency(TransparencyAttrib.MAlpha)
        self.cursor.setColor( 1, 1, 1, 1 )
        self.cursor.setTexture(self.curtex)

        pointertex = loader.loadTexture(GAME+'/textures/pointer.png')
        pointertex.setMagfilter(Texture.FTNearest)
        pointertex.setMinfilter(Texture.FTNearest)
        cm = CardMaker('card')
        cm.setFrame(-2, 2, -2, 2) 
        self.pointer = render.attachNewNode(cm.generate())
        self.pointer.setTexture(pointertex)
        self.pointer.setTransparency(True)
        self.pointer.setBillboardPointEye()
        self.pointer.reparentTo(render)
        self.pointer.setScale(256.0/240.0)
Example #11
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 __createAnimationSequence__(self,name,sprite_images,sprites_time,is_left = False):
   """
     Creates the sequence node that plays these images
   """
   
   seq = SpriteSequencePlayer(name)
   
   for i in range(0,len(sprite_images)):
       
     txtr = sprite_images[i]
     
     w = txtr.getXSize() 
     h = txtr.getYSize()       
     
     # creating CardMaker to hold the texture
     cm = CardMaker(name +    str(i))
     cm.setFrame(0,w,-h,0 )  # This configuration places the image's topleft corner at the origin
     card = NodePath(cm.generate())            
     card.setTexture(txtr)
     seq.addChild(card.node(),i)
     seq.addFrame(card.node(),i,sprites_time[i])
     
     # offseting image
     xoffset = float(txtr.axisx + (-w if is_left else 0))
     yoffset = float(txtr.axisy)
     card.setPos(Vec3(xoffset,0,yoffset))
     
     AnimationActor.LOGGER.debug("Animation %s Sprite [%i] image size %s and offset %s."%( name,i, str((w,h)), str((txtr.axisx,txtr.axisy)) ) ) 
    
              
   return seq     
   
   
 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
Example #14
0
class FadeOut(DirectObject):
    def __init__(self):
        self.cm = CardMaker("fadeout")
        self.cm.setFrame(-2,2,-2,2)
        self.cmnode = NodePath(self.cm.generate())
        self.cmnode.setTransparency(TransparencyAttrib.MAlpha)
        self.cmnode.setY(-1)
        self.cmnode.setColorScale(LVecBase4f(0.0,0.0,0.0,0.0))
        self.cmnode.reparentTo(aspect2d)
        
    def fadeIn(self, t):
        return LerpColorScaleInterval(self.cmnode,
                            t,
                            LVecBase4f(0.0,0.0,0.0,1.0),
                            LVecBase4f(0.0,0.0,0.0,0.0))
    
    def fadeOut(self, t):
        return LerpColorScaleInterval(self.cmnode,
                            t,
                            LVecBase4f(0.0,0.0,0.0,0.0),
                            LVecBase4f(0.0,0.0,0.0,1.0))
    
    def remove(self):
        self.cmnode.remove_node()
        
Example #15
0
    def __init__(self):
        ShowBase.__init__(self)

        cm = CardMaker('grass')
        cm.setFrame(-1, 1, -1, 1)

        grass1 = render.attachNewNode(cm.generate())
        grass2 = render.attachNewNode(cm.generate())

        grass1.setTexture(loader.loadTexture("data/env/grass1.png"), 1)
        grass2.setTexture(loader.loadTexture("data/env/grass2.png"), 1)

        grass1.setTransparency(True)
        grass2.setTransparency(True)

        grass1.setBillboardPointEye()
        grass2.setBillboardPointEye()

        grass1.setHpr(0, -40, 0)
        grass2.setHpr(0, -40, 0)

        grass1.setPos(0, 1, -0.4)
        grass2.setPos(0, 1, -0.3)

        self.taskMgr.add(self.panCameraTask, "PanCameraTask")
Example #16
0
    def __init__(self):
        ShowBase.__init__(self)

        cm = CardMaker('grass')
        cm.setFrame(-1, 1, -1, 1)

        grass1 = render.attachNewNode(cm.generate())
        grass2 = render.attachNewNode(cm.generate())

        grass1.setTexture(loader.loadTexture("data/env/grass1.png"), 1)
        grass2.setTexture(loader.loadTexture("data/env/grass2.png"), 1)

        grass1.setTransparency(True)
        grass2.setTransparency(True)

        grass1.setBillboardPointEye()
        grass2.setBillboardPointEye()

        grass1.setHpr(0, -40, 0)
        grass2.setHpr(0, -40, 0)

        grass1.setPos(0, 1, -0.4)
        grass2.setPos(0, 1, -0.3)

        self.taskMgr.add(self.panCameraTask, "PanCameraTask")
Example #17
0
def makeCube(geom, x, y, z, scale=1.0, texpos=None, colors=False):
    """
    Function that adds six cards to a GeomNode to form a cube
    
    geom: GeomNode to add cards to
    x, y, z: Position offset
    scale: Optional, Scale factor, cube is 1x1x1 by default
    texpos: Optional, Dictionary of tuples with texture co-ordinates
            Tuple has Point2 for top-left and Point2 for bottom-right
            Faces are "front", "back", "left", "right", "top", "bottom"
    colors: Optional, if True set different color for each face for debugging
            (see cardcolors)
    """
    cardmaker = CardMaker("cardmaker")

    mycards = deepcopy(CARDS)
    for k, i in mycards.iteritems():
        points = i
        for j in points:
            j += Point3(x, y, z)
            j *= scale
        cardmaker.setFrame(*points)

        if texpos:
            cardmaker.setUvRange(*texpos[k])
        if colors:
            cardmaker.setColor(*CARDCOLORS[k])
        geom.addGeomsFrom(cardmaker.generate())
Example #18
0
    def addImage(self,
                 filename='../Artwork/022waVoF8tbU.jpg',
                 name='NAME',
                 id=0):
        cm = CardMaker('card_' + str(id))
        max_width = 120
        with Image.open(filename) as img:
            width, height = img.size
        cm.setFrame(0, max_width, 0, height * max_width * 1. / width)
        card = self.render.attachNewNode(cm.generate())
        card.setPos(-270, 100 - id * max_width * 1.5,
                    (300 - height * max_width * 1. / width) * 0.5)
        # card.setPos(-5, 100, 125)
        card.setHpr(90, 0, 0)

        box = CollisionBox(Point3(), max_width, 1,
                           height * max_width * 1. / width)
        cnodePath = card.attachNewNode(CollisionNode('cnode'))
        cnodePath.node().addSolid(box)
        # cnodePath.show()
        card.setTag('myObjectTag', str(id))

        tex = loader.loadTexture(filename)
        # tex = self.loader.loadTexture('maps/noise.rgb')
        card.setTexture(tex)
 def setupBackgroundImage(self):    
   
   image_file = Filename(TestGameBase.__BACKGROUND_IMAGE_PATH__)
   
   # check if image can be loaded
   img_head = PNMImageHeader()
   if not img_head.readHeader(image_file ):
       raise IOError("PNMImageHeader could not read file %s. Try using absolute filepaths"%(image_file.c_str()))
       sys.exit()
       
   # Load the image with a PNMImage
   w = img_head.getXSize()
   h = img_head.getYSize()
   img = PNMImage(w,h)
   #img.alphaFill(0)
   img.read(image_file) 
   
   texture = Texture()        
   texture.setXSize(w)
   texture.setYSize(h)
   texture.setZSize(1)    
   texture.load(img)
   texture.setWrapU(Texture.WM_border_color) # gets rid of odd black edges around image
   texture.setWrapV(Texture.WM_border_color)
   texture.setBorderColor(LColor(0,0,0,0))
   
   # creating CardMaker to hold the texture
   cm = CardMaker('background')
   cm.setFrame(-0.5*w,0.5*w,-0.5*h,0.5*h)  # This configuration places the image's topleft corner at the origin (left, right, bottom, top)
   background_np = NodePath(cm.generate())            
   background_np.setTexture(texture)
   
   background_np.reparentTo(self.render)
   background_np.setPos(TestGameBase.__BACKGROUND_POSITION__)
   background_np.setScale(TestGameBase.__BACKGROUND_SCALE__)
Example #20
0
 def __init__(self):
     ShowBase.__init__(self)
     cm = CardMaker("cm")
     cm.setFrame(Point3(-1, -1, -1), Point3(1, -1, -1), Point3(1, 1, -1),
                 Point3(-1, 1, -1))
     model = self.hidden.attachNewNode(cm.generate())
     model.setScale(0.1)
     #self.disableMouse()
     base.setFrameRateMeter(True)
     self.n = 100
     self.data = gen(self.n)
     self.zvezde = self.render.attachNewNode("zvezde")
     model.reparentTo(self.zvezde)
     model.setTexture(self.loader.loadTexture("explosion1.png"))
     self.zvezde.setPosHpr(0, 70, 0, 0, 90, 0)
     self.zvezde.setInstanceCount(self.n)
     myShader = Shader.load(Shader.SLGLSL, "vertex.glsl", "fragment.glsl")
     self.zvezde.setShader(myShader)  #Shader.load('instance.cg'))
     self.render.setShaderAuto()
     self.offsets = PTA_LVecBase4f.emptyArray(self.n)
     self.accept("r", self.reset)
     self.zvezde.setShaderInput('shader_data', self.offsets)
     self.zvezde.setShaderInput('shader_data[0]', self.offsets)
     #self.taskMgr.setupTaskChain('threaded chain', numThreads = 0, frameBudget = -1,frameSync = 1)
     self.taskMgr.add(self.update,
                      "update")  #,taskChain = 'threaded chain')
	def register(self, render, camera, keys):
		State.register(self, render, camera, keys)

		cm = CardMaker('CardMaker-Title')
		tex = loadTexture('titlescreen.png')

		cm.setFrame(-1, 1, -1, 1)

		self.bg = self.node.attachNewNode(cm.generate())
		self.bg.setPos(0, 0, 0)
		self.bg.setTexture(tex)

		menuActions = {'up': (Menu.previousOpt, self.menu),
						'down': (Menu.nextOpt, self.menu),
						'action': (self.selectOption, None)
						}

		self.menu.registerKeys(keys, menuActions)

		self.title = OnscreenText(text="", mayChange = True , style=2,
							 fg=(1,1,1,1), pos=(0, 0.75), scale = 0.2) # is this used??
		self.text = {}

		id=0
		for opt in self.menu.options:
			self.text[opt] = OnscreenText(text=opt, mayChange = True , style=2, fg=(1,1,1,1), pos=(0, -0.3 - 0.15*id), scale = .1)
			id+=1

		self.title.reparentTo(self.node)
		for opt in self.text.keys():
			self.text[opt].reparentTo(self.node)


		State.register(self, render, camera, keys)
Example #22
0
 def create_instance(self):
     #print("Create label for", self.get_name())
     self.label = TextNode(self.parent.get_ascii_name() + '-label')
     if not self.font_init:
         self.load_font()
     if self.font is not None:
         self.label.set_font(self.font)
     name = bayer.decode_name(self.parent.get_label_text())
     self.label.setText(name)
     self.label.setTextColor(*self.parent.get_label_color())
     #node=label.generate()
     #self.instance = self.context.annotation.attachNewNode(node)
     #self.instance.setBillboardPointEye()
     #node.setIntoCollideMask(GeomNode.getDefaultCollideMask())
     #node.setPythonTag('owner', self.parent)
     cardMaker = CardMaker(self.get_ascii_name() + '-labelcard')
     cardMaker.setFrame(self.label.getFrameActual())
     cardMaker.setColor(0, 0, 0, 0)
     card_node = cardMaker.generate()
     self.label_instance = NodePath(card_node)
     tnp = self.label_instance.attachNewNode(self.label)
     self.label_instance.setTransparency(TransparencyAttrib.MAlpha)
     #card.setEffect(DecalEffect.make())
     #Using look_at() instead of billboard effect to also rotate the collision solid
     #card.setBillboardPointEye()
     #Using a card holder as look_at() is changing the hpr parameters
     self.instance = NodePath('label-holder')
     self.label_instance.reparentTo(self.instance)
     self.instance.reparentTo(self.context.annotation_shader)
     self.instance.setCollideMask(GeomNode.getDefaultCollideMask())
     self.instance.set_depth_write(False)
     card_node.setPythonTag('owner', self.parent)
     self.look_at = self.instance.attachNewNode("dummy")
 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)))
Example #24
0
	def constructModel(self):
		self.obstacles = []
		self.blocks = []
		self.liftables = []

		if self.nodePath != None:
			self.nodePath.removeNode()
			self.cards = []

		self.nodePath = NodePath("Map")
		#the ground
		cm = CardMaker('CardMaker')
		cm.setFrame(-2,2,-2,2)
		card = self.nodePath.attachNewNode(cm.generate())
		card.setTexture(tex)

		for y in range(self.height):
			for x in range(self.width):
				# TO DO: MUDAR NOME
				a = {"block": self.blocks,
					 "obstacle": self.obstacles,
					 "tree": self.obstacles,
					 "bush" : self.obstacles,
					 "liftable": self.liftables}
				tType = self.tileType(Map.COLLISION, (x,y))

				if tType != 'free':
					a[tType].append(self.makeObject(tType, x,y))
Example #25
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()
Example #26
0
def makeCube(geom, x, y, z, scale=1.0, texpos=None, colors=False):
    """
    Function that adds six cards to a GeomNode to form a cube
    
    geom: GeomNode to add cards to
    x, y, z: Position offset
    scale: Optional, Scale factor, cube is 1x1x1 by default
    texpos: Optional, Dictionary of tuples with texture co-ordinates
            Tuple has Point2 for top-left and Point2 for bottom-right
            Faces are "front", "back", "left", "right", "top", "bottom"
    colors: Optional, if True set different color for each face for debugging
            (see cardcolors)
    """
    cardmaker = CardMaker("cardmaker")
    
    mycards = deepcopy(CARDS)
    for k, i in mycards.iteritems():
        points = i
        for j in points:
            j += Point3(x, y, z)
            j *= scale
        cardmaker.setFrame(*points)
        
        if texpos:
            cardmaker.setUvRange(*texpos[k])
        if colors:
            cardmaker.setColor(*CARDCOLORS[k])
        geom.addGeomsFrom(cardmaker.generate())
Example #27
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
Example #28
0
    def __init__(self):
        ShowBase.__init__(self)
        props = WindowProperties( )
        props.setTitle( 'Differentiable Physics Engine' )
        self.win.requestProperties( props )
        self.t = 0
        self.starttime = time.time()
        #self.setFrameRateMeter(True)
        cour = self.loader.loadFont('cmtt12.egg')
        self.textObject = OnscreenText(font= cour, text = 'abcdefghijklmnopqrstuvwxyz', pos=(0, -0.045), parent = self.a2dTopCenter, bg=(0,0,0,1), fg =(1,1,1,1), scale = 0.07, mayChange=True)
        cm = CardMaker("ground")
        cm.setFrame(-2000, 2000, -2000, 2000)
        cm.setUvRange(Point2(-2000/5,-2000/5),Point2(2000/5,2000/5))

        tmp = self.render.attachNewNode(cm.generate())
        tmp.reparentTo(self.render)

        tmp.setPos(0, 0, 0)
        tmp.lookAt((0, 0, -2))
        tmp.setColor(1.0,1.0,1.0,1)
        tmp.setTexScale(TextureStage.getDefault(), 1, 1)
        tex = self.loader.loadTexture('textures/grid2.png')

        tex.setWrapU(Texture.WMRepeat)
        tex.setWrapV(Texture.WMRepeat)
        tmp.setTexture(tex,1)
        self.setBackgroundColor(0.0, 191.0/255.0, 1.0, 1.0) #color of the sky

        ambientLight = AmbientLight('ambientLight')
        ambientLight.setColor(Vec4(0.2, 0.2, 0.2, 1))
        ambientLightNP = self.render.attachNewNode(ambientLight)
        self.render.setLight(ambientLightNP)

        # Directional light 01
        directionalLight = DirectionalLight('directionalLight')
        directionalLight.setColor(Vec4(0.8, 0.8, 0.8, 1))
        directionalLightNP = self.render.attachNewNode(directionalLight)
        # This light is facing backwards, towards the camera.
        directionalLightNP.setHpr(-60, -50, 0)
        directionalLightNP.node().setScene(self.render)
        directionalLightNP.node().setShadowCaster(True)
        directionalLightNP.node().getLens().setFov(40)
        directionalLightNP.node().getLens().setNearFar(10, 100)
        self.render.setLight(directionalLightNP)

        # Add the spinCameraTask procedure to the task manager.
        self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")


        # Load the environment model.
        self.objects = dict()
        self.names = []
        data = pickle.load(open("../PhysXVids/state-dump-exp15.pkl","rb"))

        self.json = json.loads(data["json"]) # json.loads(data["json"])
        self.states = data["states"]
        self.load_robot_model()
        self.dt = self.json["integration_parameters"]["time_step"]
        self.setupKeys()
        self.robot_id = 0
Example #29
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.hide(BaseObject.AllCamerasMask)
        self.waterNP.show(BaseObject.DefaultCameraMask)
        self.waterNP.setHpr(0, -90, 0)
        self.waterNP.setPos(0, 0, self.z)
        self.waterNP.setTransparency(TransparencyAttrib.MAlpha)
        vertex_shader = defaultDirContext.find_shader('water-vertex.glsl')
        fragment_shader = defaultDirContext.find_shader('water-fragment.glsl')
        self.waterNP.setShader(
            Shader.load(
                Shader.SL_GLSL,
                vertex=Filename.from_os_specific(vertex_shader).get_fullpath(),
                fragment=Filename.from_os_specific(
                    fragment_shader).get_fullpath()))
        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, 1.0, 0.25, 0.45))
        self.waterNP.setShaderInput('time', 0)

        self.waterNP.setShaderInput('reflection_tex', self.texture)

        # distortion texture
        tex1 = loader.loadTexture('textures/water.png')
        self.waterNP.setShaderInput('distortion_tex', tex1)
Example #30
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)
Example #31
0
    def __init__(self, battleGraphics, matrixContainer):
        self.battleGraphics = battleGraphics
        self.matrixContainer = matrixContainer

        self.curtex = loader.loadTexture(GAME + '/textures/cursor.png')
        self.curtex.setMagfilter(Texture.FTNearest)
        self.curtex.setMinfilter(Texture.FTNearest)

        self.x = False
        self.y = False
        self.z = False

        self.cursor = loader.loadModel(GAME + '/models/slopes/flat')
        self.cursor.reparentTo(self.matrixContainer)
        self.cursor.setScale(3.7)
        self.cursor.setTransparency(TransparencyAttrib.MAlpha)
        self.cursor.setColor(1, 1, 1, 1)
        self.cursor.setTexture(self.curtex)

        pointertex = loader.loadTexture(GAME + '/textures/pointer.png')
        pointertex.setMagfilter(Texture.FTNearest)
        pointertex.setMinfilter(Texture.FTNearest)
        cm = CardMaker('card')
        cm.setFrame(-2, 2, -2, 2)
        self.pointer = render.attachNewNode(cm.generate())
        self.pointer.setTexture(pointertex)
        self.pointer.setTransparency(True)
        self.pointer.setBillboardPointEye()
        self.pointer.reparentTo(render)
        self.pointer.setScale(256.0 / 240.0)
Example #32
0
	def __init__(self, world, attach, name = '', position = Vec3(0,0,0), orientation = Vec3(0,0,0), size = (32, 32)):
		cm=CardMaker('')
		cm.setFrame(0,1,0,1)
		floor = render.attachNewNode(PandaNode("floor"))
		tex = loader.loadTexture('media/'+'ground.png')
		tex.setMagfilter(Texture.FTNearest)
		tex.setMinfilter(Texture.FTNearest)
		for y in range(size[0]):
			for x in range(size[1]):
				nn = floor.attachNewNode(cm.generate())
				nn.setP(-90)
				nn.setPos((x), (y), 0)
		floor.setTexture(tex)
		floor.flattenStrong()



		myMaterial = Material()
		myMaterial.setShininess(0) #Make this material shiny
		myMaterial.setAmbient(VBase4(0.5,.5,.5,1)) #Make this material blue
		myMaterial.setDiffuse(VBase4(.5,.5,.5,1))
		nn.setMaterial(myMaterial)
		shape = BulletPlaneShape(Vec3(0, 0, 1), 0)

		StaticWorldObject.__init__(self, world, attach, name, position, shape, orientation) ##Mass must be zero.

		self._nodePath.node().setFriction(1)
 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
Example #34
0
 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
Example #35
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)
Example #36
0
    def _createMapTextureCard(self):
        mapImage = PNMImage(MAP_RESOLUTION, MAP_RESOLUTION)
        mapImage.fill(*self._bgColor)
        fgColor = VBase4D(*self._fgColor)
        for x in xrange(self._mazeHeight):
            for y in xrange(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
Example #37
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)
Example #38
0
 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
Example #39
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)
Example #40
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())
    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)
Example #42
0
	def register(self, render, camera, keys):
		State.register(self, render, camera, keys)
		
		cm = CardMaker('CardMaker-Pause')
		cm.setFrame(0.5, -0.5, 0.5, -0.5)
		cm.setColor(0,0,0, 0.1)
		
		self.bg = self.node.attachNewNode(cm.generate())
		self.bg.setPos(0, 0, 0)
		
		menuActions = {'up': (Menu.previousOpt, self.menu),
						'down': (Menu.nextOpt, self.menu), 
						'action': (self.selectOption, None),
						'cancel': (self.selectOption, 0) }
		self.menu.registerKeys(keys, menuActions)
	
		self.title = OnscreenText(text="Game Paused", mayChange = True , style=1, fg=(1,1,1,1), pos=(0,0.35), scale = .1)
		self.text = {}
		
		id=0
		for opt in self.menu.options:
			self.text[opt] = OnscreenText(text=opt, mayChange = True , style=1, fg=(1,1,1,1), pos=(0,0.1 - 0.1*id), scale = .06)
			id+=1
		
		self.title.reparentTo(self.node)
		for opt in self.text.keys():
			self.text[opt].reparentTo(self.node)
Example #43
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()
Example #44
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()
Example #45
0
 def add_ground(self):
     cm = CardMaker("ground")
     cm.setFrame(-1, 1, -1, 1)
     ground = render.attachNewNode(cm.generate())
     ground.setColor(0.5, 0.7, 0.8)
     ground.lookAt(0, 0, -1)
     groundGeom = OdePlaneGeom(self.space, Vec4(0, 0, 1, 0))
Example #46
0
class CardQuad(visual):
    def setup(self):
        self.path.removeNode()
        self.path = self.render.attachNewNode("Card Quad")

        self.plane = CardMaker("plane")

        self.plane.setFrame(-10,10,-10,10)
        self.left = self.path.attachNewNode(self.plane.generate())
        self.right = self.path.attachNewNode(self.plane.generate())
        self.up = self.path.attachNewNode(self.plane.generate())
        self.down = self.path.attachNewNode(self.plane.generate())
        self.front = self.path.attachNewNode(self.plane.generate())
        self.back = self.path.attachNewNode(self.plane.generate())
        self.left.setX(-10)
        self.right.setX(10)
        self.up.setZ(10)
        self.down.setZ(-10)
        self.left.setH(270)
        self.right.setH(90)
        self.up.setP(270)
        self.down.setP(90)
        self.front.setY(-10)
        self.back.setY(10)
        self.back.setH(180)

        self.tex = self.loader.loadTexture("indian_ornament_texture.png")

        self.path.setTexture(self.tex)
        self.path.setTransparency(TransparencyAttrib.MAlpha, 1)
        self.path.setTwoSided(1)
Example #47
0
 def _addCard(self,texture):
     tex = loader.loadTexture(MAIN_DIR+"/../assets/models/bamboo/"+texture)
     cm = CardMaker('card')
     ratio = float(tex.getXSize())/tex.getYSize()
     cm.setFrame(-0.5*ratio,0.5*ratio,-0.5,0.5)
     card = self.menuNP.attachNewNode(cm.generate())
     card.setTexture(tex)
     return card
Example #48
0
    def __init__(self, charid, sprite, camhandler, callback, cancelcallback):
    
        self.charid = charid
        self.sprite = sprite
        self.camhandler = camhandler
        self.callback = callback
        self.cancelcallback = cancelcallback
        self.initdir  = self.sprite.realdir
        self.hidir = None

        # Textures
        self.readytex = loader.loadTexture(GAME+'/textures/gui/direction.png')
        self.readytex.setMagfilter(Texture.FTNearest)
        self.readytex.setMinfilter(Texture.FTNearest)
        self.hovertex = loader.loadTexture(GAME+'/textures/gui/direction_hover.png')
        self.hovertex.setMagfilter(Texture.FTNearest)
        self.hovertex.setMinfilter(Texture.FTNearest)

        # Sounds
        self.hover_snd   = base.loader.loadSfx(GAME+'/sounds/hover.ogg')
        self.clicked_snd = base.loader.loadSfx(GAME+'/sounds/clicked.ogg')
        self.cancel_snd  = base.loader.loadSfx(GAME+'/sounds/cancel.ogg')

        # Buttons list
        self.directionbuttons = []

        # Buttons container
        self.directionRoot = sprite.node.attachNewNode( "directionRoot" )

        directionsdata = [
            { 'direction': '1', 'pos': ( 1.45, 0.0, 5) },
            { 'direction': '2', 'pos': ( 0.0, 1.45, 5) },
            { 'direction': '3', 'pos': (-1.45, 0.0, 5) },
            { 'direction': '4', 'pos': ( 0.0,-1.45, 5) }
        ]
        for directiondata in directionsdata:
            cm = CardMaker('card')
            cm.setFrame(-.5, .5, -.5, .5) 
            card = render.attachNewNode(cm.generate())
            card.setTexture(self.readytex)
            card.setTransparency(True)
            card.setBillboardPointEye()
            card.reparentTo(self.directionRoot)
            card.setPos(directiondata['pos'])
            card.setScale(256.0/240.0)

            self.directionbuttons.append(card)

            if int(directiondata['direction']) == int(self.initdir):
                self.hidir = directiondata['direction']
                card.setTexture(self.hovertex)

        self.accept("b", self.onCircleClicked)
        self.accept("space", self.onCrossClicked)
        self.accept("arrow_up", lambda: self.onArrowClicked('up'))
        self.accept("arrow_down", lambda: self.onArrowClicked('down'))
        self.accept("arrow_left", lambda: self.onArrowClicked('left'))
        self.accept("arrow_right", lambda: self.onArrowClicked('right'))
Example #49
0
 def _makeSquare(self):
     c = CardMaker("square")
     c.setFrame(-0.5, 0.5, -0.5, 0.5)
     self.square = NodePath(c.generate())
     self.square.setShaderInput("font", self.fontTex)
     self.square.setShader(self.fontShader)
     self.square.setAttrib(
         TransparencyAttrib.make(TransparencyAttrib.MAlpha), 100)
     self.square.reparentTo(Globals.base.aspect2d)
     return self.square
Example #50
0
 def loadImageAsPlane(self, filepath, yresolution = 600):
     tex = loader.loadTexture(filepath) # @UndefinedVariable
     tex.setBorderColor(Vec4(0,0,0,0))
     tex.setWrapU(Texture.WMBorderColor)
     tex.setWrapV(Texture.WMBorderColor)
     cm = CardMaker(filepath + ' card')
     cm.setFrame(-tex.getOrigFileXSize(), tex.getOrigFileXSize(), -tex.getOrigFileYSize(), tex.getOrigFileYSize())
     card = NodePath(cm.generate())
     card.setTexture(tex)
     card.setScale(card.getScale()/ yresolution)
     card.flattenLight() # apply scale
     return card
Example #51
0
	def iterate(self):
		cm = CardMaker('CardMaker-GameOver')
		tex = loadTexture('gameover.png')

		cm.setFrame(-1, 1, -1, 1)
		bg = self.node.attachNewNode(cm.generate())
		bg.setColor(0, 0, 0)
		bg.setPos(0, 0, 0)

		cm.setFrame(-0.4, 0.4, -0.2, 0.2)
		self.text = self.node.attachNewNode(cm.generate())
		self.text.setPos(0, 0, 0)
		self.text.setTexture(tex)
Example #52
0
 def initSwitchSigns(self):
     self.switchSigns = []
     for i in range(11):
         cm = CardMaker('card%d'%i)
         cm.setColor(0,0,0,0)
         cm.setFrame(-0.5, 0.5, -0.5, 0.5)
         card = self.level.attachNewNode(cm.generate())
         card.setAttrib(TransparencyAttrib.make(TransparencyAttrib.M_alpha))
         tex = loader.loadTexture('%d.png'%i)
         ts = TextureStage('ts')
         ts.setMode(TextureStage.MReplace)
         card.setTexture(ts, tex)
         card.setEffect(BillboardEffect.makePointEye())
         card.hide()
         self.switchSigns.append(card)
Example #53
0
 def createFadeableImage(img, tsName, big=False):
     cm = CardMaker("FadableCard")
     cm.setFrame(-1, 1, -1, 1)
     image = NodePath(cm.generate())
     image.setTransparency(TransparencyAttrib.MAlpha)
     imageTex = loader.loadTexture(img)
     imageTs = TextureStage(tsName)
     imageTs.setMode(TextureStage.MReplace)
     image.setTexture(imageTs, imageTex)
     image.reparentTo(render2d)
     if big:
         image.setScale(0.75)
     else:
         image.setScale(0.5)
     image.setPos(0, 0, 0.25)
     image.hide()
     return image
Example #54
0
    def _createMaskTextureCard(self):
        self._maskImage = PNMImage(self._maskResolution, self._maskResolution, 4)
        for x in xrange(self._maskResolution):
            for y in xrange(self._maskResolution):
                self._maskImage.setXelA(x, y, 0, 0, 0, 1)

        self.maskTexture = Texture('maskTexture')
        self.maskTexture.setupTexture(Texture.TT2dTexture, self._maskResolution, self._maskResolution, 1, Texture.TUnsignedByte, Texture.FRgba)
        self.maskTexture.setMinfilter(Texture.FTLinear)
        self.maskTexture.setWrapU(Texture.WMClamp)
        self.maskTexture.setWrapV(Texture.WMClamp)
        self.maskTexture.load(self._maskImage)
        base.graphicsEngine.renderFrame()
        cm = CardMaker('mask_cardMaker')
        cm.setFrame(-1.1, 1.1, -1.1, 1.1)
        mask = self.attachNewNode(cm.generate())
        mask.setTexture(self.maskTexture, 1)
        mask.setTransparency(1)
        return mask
    def getRenderMapCam(self, rawTile, inputMaps, shader, size):
        """
        Sets up scene and cam for rendering the map
        Returns the cam
        """
        margin=texMargin(size)
        
        altRender=NodePath("newRender")

        # setup square orthographic cam
        altCam=NodePath(Camera("renderMapCam"))
        altCam.reparentTo(altRender)   
        altCam.setPos(.5,-1,.5) 

        oLens = OrthographicLens()
        oLens.setFilmSize(1+margin*2, 1+margin*2)
        altCam.node().setLens(oLens)
        
         # Make a card on which the shader will render the map
        c=CardMaker("MapCardMaker")
        c.setUvRange(0-margin,1+margin,0-margin,1+margin)
        c.setFrame(0-margin,1+margin,0-margin,1+margin)
        mapCard=NodePath(c.generate())
        
        mapCard.setPos(0,0,0)   
        mapCard.setShader(shader.shader)
        mapCard.setShaderInput("offset",rawTile.x,rawTile.y,0,0)
        mapCard.setShaderInput("scale",rawTile.scale,0,0,0)

        for m in inputMaps:
            texStage=TextureStage(m.name+"stage")
            mapCard.setTexture(texStage,m.tex)
        
        for p in shader.shaderTex:
            mapCard.setTexture(*p)
        
        mapCard.reparentTo(altRender)
        
        # Comment out this line to cause the bug with multiple textures requireing an extra frame to work properly
        altRender.prepareScene(base.win.getGsg())
        
        return altCam
Example #56
0
    def __init__(self, charid, sprite, camhandler, callback, cancelcallback):
        print game
    
        self.charid = charid
        self.sprite = sprite
        self.camhandler = camhandler
        self.callback = callback
        self.cancelcallback = cancelcallback
        self.initdir  = self.sprite.realdir
        self.hidir = None

        # Textures
        self.tex = [ 0 for i in range(4) ]
        for i in range(4):
            self.tex[i] = loader.loadTexture(GAME+'/textures/gui/direction'+str(i)+'.png')
            self.tex[i].setMagfilter(Texture.FTNearest)
            self.tex[i].setMinfilter(Texture.FTNearest)

        # Sounds
        self.hover_snd   = base.loader.loadSfx(GAME+"/sounds/hover.ogg")
        self.clicked_snd = base.loader.loadSfx(GAME+"/sounds/clicked.ogg")
        self.cancel_snd  = base.loader.loadSfx(GAME+"/sounds/cancel.ogg")

        # Buttons container
        self.directionRoot = sprite.node.attachNewNode( "directionRoot" )

        cm = CardMaker('card')
        cm.setFrame(-2, 2, -2, 2) 
        self.card = render.attachNewNode(cm.generate())
        self.card.setTexture(self.tex[self.initdir-1])
        self.card.setTransparency(True)
        self.card.setBillboardPointEye()
        self.card.reparentTo(self.directionRoot)
        self.card.setPos(0,0,6)
        self.card.setScale(256.0/240.0)

        self.accept("b", self.onCircleClicked)
        self.accept("space", self.onCrossClicked)
        self.accept("arrow_up", lambda: self.onArrowClicked('up'))
        self.accept("arrow_down", lambda: self.onArrowClicked('down'))
        self.accept("arrow_left", lambda: self.onArrowClicked('left'))
        self.accept("arrow_right", lambda: self.onArrowClicked('right'))
Example #57
0
 def setupRightTexture(self):
     cm = CardMaker('quadMaker')
     cm.setColor(1.0, 1.0, 1.0, 1.0)
     aspect = base.camLens.getAspectRatio()
     htmlWidth = 2.0 * aspect * WEB_WIDTH / float(WIN_WIDTH)
     htmlHeight = 2.0 * float(WEB_HEIGHT) / float(WIN_HEIGHT)
     cm.setFrame(0, htmlWidth / 2.0, -htmlHeight / 2.0, htmlHeight / 2.0)
     card = cm.generate()
     self.rightQuad = NodePath(card)
     self.rightQuad.reparentTo(self.parent_)
     self.rightGuiTex = Texture('guiTex')
     self.rightGuiTex.setupTexture(Texture.TT2dTexture, WEB_HALF_WIDTH, WEB_HEIGHT, 1, Texture.TUnsignedByte, Texture.FRgba)
     self.rightGuiTex.setKeepRamImage(True)
     self.rightGuiTex.makeRamImage()
     self.rightGuiTex.setWrapU(Texture.WMClamp)
     self.rightGuiTex.setWrapV(Texture.WMClamp)
     ts = TextureStage('rightWebTS')
     self.rightQuad.setTexture(ts, self.rightGuiTex)
     self.rightQuad.setTexScale(ts, 1.0, -1.0)
     self.rightQuad.setTransparency(0)
     self.rightQuad.setTwoSided(True)
     self.rightQuad.setColor(1.0, 1.0, 1.0, 1.0)
Example #58
0
    def __init__(self, av, **kw):
        DirectFrame.__init__(self, relief=None, sortOrder=50)
        self.initialiseoptions(QuestMap)
        self.container = DirectFrame(parent=self, relief=None)
        self.marker = DirectFrame(parent=self.container, relief=None)
        self.cogInfoFrame = DirectFrame(parent=self.container, relief=None)
        cm = CardMaker('bg')
        cm.setFrame(-0.5, 0.5, -0.5, 0.5)
        bg = self.cogInfoFrame.attachNewNode(cm.generate())
        bg.setTransparency(1)
        bg.setColor(0.5, 0.5, 0.5, 0.5)
        bg.setBin('fixed', 0)
        self.cogInfoFrame['geom'] = bg
        self.cogInfoFrame['geom_pos'] = (0, 0, 0)
        self.cogInfoFrame['geom_scale'] = (6, 1, 2)
        self.cogInfoFrame.setScale(0.05)
        self.cogInfoFrame.setPos(0, 0, 0.6)
        self.buildingMarkers = []
        self.av = av
        self.wantToggle = False
        if base.config.GetBool('want-toggle-quest-map', True):
            self.wantToggle = True
        self.updateMarker = True
        self.cornerPosInfo = None
        self.hqPosInfo = None
        self.fishingSpotInfo = None
        self.load()
        self.setScale(1.5)
        bg.removeNode()
        self.hoodId = None
        self.zoneId = None
        self.suitPercentage = {}
        for currHoodInfo in SuitPlannerBase.SuitPlannerBase.SuitHoodInfo:
            tracks = currHoodInfo[SuitPlannerBase.SuitPlannerBase.SUIT_HOOD_INFO_TRACK]
            self.suitPercentage[currHoodInfo[SuitPlannerBase.SuitPlannerBase.SUIT_HOOD_INFO_ZONE]] = tracks

        return
  def createSequenceNode(self,name,img,cols,rows,scale_x,scale_y,frame_rate):
    
    seq = SequenceNode(name)
    w = int(img.getXSize()/cols)
    h = int(img.getYSize()/rows)

    counter = 0
    for i in range(0,cols):
      for j in range(0,rows):
        sub_img = PNMImage(w,h)
        sub_img.addAlpha()
        sub_img.alphaFill(0)
        sub_img.fill(1,1,1)
        sub_img.copySubImage(img ,0 ,0 ,i*w ,j*h ,w ,h)

        # Load the image onto the texture
        texture = Texture()        
        texture.setXSize(w)
        texture.setYSize(h)
        texture.setZSize(1)    
        texture.load(sub_img)
        texture.setWrapU(Texture.WM_border_color) # gets rid of odd black edges around image
        texture.setWrapV(Texture.WM_border_color)
        texture.setBorderColor(LColor(0,0,0,0))

        cm = CardMaker(name + '_' + str(counter))
        cm.setFrame(-0.5*scale_x,0.5*scale_x,-0.5*scale_y,0.5*scale_y)
        card = NodePath(cm.generate())
        seq.addChild(card.node(),counter)
        card.setTexture(texture)
        sub_img.clear()
        counter+=1
    
    seq.setFrameRate(frame_rate)
    print "Sequence Node %s contains %i frames of size %s"%(name,seq.getNumFrames(),str((w,h)))
    return seq