def _createMaskTextureCard(self): """ This will return a NodePath with a card textured with the map mask. It also creates several other members that re needed to change the mask. """ # create and fill empty mask image self._maskImage = PNMImage(self._maskResolution, self._maskResolution, 4) for x in range(self._maskResolution): for y in range(self._maskResolution): #maskImage.setXel(x,y,mapImage.getRed(x/13,y/10),mapImage.getGreen(x/13,y/10),mapImage.getBlue(x/13,y/10)) self._maskImage.setXelA(x,y,0,0,0,1) # create the texture for the mask 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() # put the mask texture on a card and return it cm = CardMaker("mask_cardMaker") cm.setFrame(-1.0,1.0,-1.0,1.0) mask = self.attachNewNode(cm.generate()) mask.setTexture(self.maskTexture, 1) mask.setTransparency(1) return mask
def __init__( self, *args, **kwargs ): colour = kwargs.pop( 'colour', (1, 1, 1, .2) ) p3d.SingleTask.__init__( self, *args, **kwargs ) # Create a card maker cm = CardMaker( self.name ) cm.setFrame( 0, 1, 0, 1 ) # Init the node path, wrapping the card maker to make a rectangle NodePath.__init__( self, cm.generate() ) self.setColor( colour ) self.setTransparency( 1 ) self.reparentTo( self.root2d ) self.hide() # Create the rectangle border ls = LineSegs() ls.moveTo( 0, 0, 0 ) ls.drawTo( 1, 0, 0 ) ls.drawTo( 1, 0, 1 ) ls.drawTo( 0, 0, 1 ) ls.drawTo( 0, 0, 0 ) # Attach border to rectangle self.attachNewNode( ls.create() )
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)
def __init__(self, name, inclination, baseDimension): #public props self.baseDimension = baseDimension tex = loader.loadTexture(resourceManager.getResource(name) + '.png') xscaled = tex.getOrigFileXSize() / self.baseDimension yscaled = tex.getOrigFileYSize() / self.baseDimension cm = CardMaker("unscrollobject") cm.setFrame(0, xscaled, 0, yscaled) ts = TextureStage('ts') ts.setMode(TextureStage.MDecal) uvscroll = UvScrollNode("uvscrollnode", 1, 0.0, 0.0, 0.0) uvscroll.addChild(cm.generate()) self.node = NodePath(uvscroll) self.node.setTwoSided(True) self.node.setX((-xscaled / 2) + 0.5) self.node.setP(-(360 - int(inclination))) self.node.setTexture(tex) self.node.setTransparency(TransparencyAttrib.MAlpha) self.node.reparentTo(render)
def announceGenerate(self): #TODO - for some reason this is getting called hundreds of times when there are multiple districts DistributedObject.DistributedObject.announceGenerate(self) self.sendUpdate('enteredParty', []) 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 range(len(self.grid)): for j in range(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 _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()
def __init__(self, character): self.character = character # Setup mouse base.disableMouse() hideMouse(True) self.mouseSensitivity = 0.1 base.taskMgr.doMethodLater(0.1, self.prepareCameraTask, "prepare-camera") # Setup camera base.camera.reparentTo(self.character.node) base.camera.setPos(0, 0, 0) base.camera.lookAt(0, 1, 0) # Create target self.target = OnscreenImage(image="media/target.png", pos=(0, 0, 0)) self.target.setTransparency(TransparencyAttrib.MAlpha) self.target.setScale(0.1) self.target.setSa(0.5) # Create overlay self.overlayCard = CardMaker("overlayCard") self.overlayCard.setFrameFullscreenQuad() self.overlay = base.render2d.attachNewNode(self.overlayCard.generate()) self.overlay.setTransparency(TransparencyAttrib.MAlpha) self.overlay.setColor(0, 0, 0, 0) # Setup interval sequences self.shakeSequence = None self.flashSequence = None
def createCARD(self, tex, sizeCELLS, sizeRAWS): card = CardMaker("tilesheet") tile = NodePath(card.generate()) tile.reparentTo(render2d) tile.setTexScale(self.ts,sizeCELLS,sizeRAWS) tile.setTexture(self.ts, tex) return tile
def __init__(self, **kwargs): """ See the Element class to find out what attributes are available from scratch """ super(VideoPlayer, self).__init__(**kwargs) self.videofile = getattr(self.config, 'file_video', None) self.loopCount = getattr(self.config, 'loop', 1) self.hoffset = getattr(self.config, 'hoffset', 0) self.voffset = getattr(self.config, 'voffset', 0) #self.videoScale = getattr(self.config, 'scale', (1,1)) #self.playrate = getattr(self.config, 'speed', 1.0) if self.videofile: movieTexture = loader.loadTexture(self.videofile) cm = CardMaker("video_card") # cm.setFrameFullscreenQuad() cm.setUvRange(movieTexture) card = NodePath(cm.generate()) card.reparentTo(self.hudNP) card.setTexture(movieTexture) card.setTexScale(TextureStage.getDefault(), movieTexture.getTexScale()) card.setPos(-0.5 + self.hoffset, 0.0, -0.5 + self.voffset) self.movie = movieTexture print card.getScale() self.time = 0 self.movie.stop() self.hideElement()
def __init__(self): self.ticks=0 base.setBackgroundColor(224.0/255.0, 188.0/255.0, 112.0/255.0) base.camera.setPos(100,100,100) self.correctAspectRatio() self.titleScreenTrack=loader.loadModel("models/titlescreentrack") self.titleScreenTrack.setScale(1.0) self.titleScreenTrack.reparentTo(render) self.titleScreenTrack.setPos(0.0,-10,-2.5) self.trackRotation=0 self.titleScreenTitle=loader.loadModel("models/gridleader") self.titleScreenTitle.setScale(1.0) self.titleScreenTitle.setH(180.0) self.titleScreenTitle.reparentTo(render) self.titleScreenTitle.setPos(0.0,-10,0.3) self.titleScreenText=TitleScreenText() startLineCm=CardMaker('card') # left, right, top, bottom startLineCm.setFrame(0,2.25,0,0.6) startLineNode=self.titleScreenTrack.attachNewNode(startLineCm.generate()) startLineNode.setTwoSided(True) startLineNode.setBillboardAxis() startLineNode.setTransparency(TransparencyAttrib.MAlpha) tex=loader.loadTexture('textures/titlestartline.png') tex.setWrapU(Texture.WMClamp) tex.setWrapV(Texture.WMClamp) startLineNode.setTexture(tex) startLineNode.setPos(-0.202,1.521,0) self.startLineNode=startLineNode base.accept('aspectRatioChanged',self.correctAspectRatio)
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
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 _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
def __init__(self, sx, sy, z, length): maker = CardMaker('land') NodePath.__init__(self, maker.generate()) #self.landNP = render.attachNewNode(maker.generate()) self.setHpr(0, -90, 0) self.setPos(sx, sy, z) self.setScale(length, 0, length)
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)
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
def announceGenerate(self): assert(self.notify.debug("announceGenerate()")) DistributedObject.DistributedObject.announceGenerate(self) self.sendUpdate("avIdEnteredParty", [base.localAvatar.doId]) # we probably just spent a lot of time loading, so # tell globalClock to update the frame timestamp globalClock.syncFrameTime() self.startPartyClock() base.localAvatar.chatMgr.chatInputSpeedChat.addInsidePartiesMenu() self.spawnTitleText() if config.GetBool('show-debug-party-grid', 0): # Debug grid self.testGrid = NodePath("test_grid") self.testGrid.reparentTo(base.cr.playGame.hood.loader.geom) for i in range(len(self.grid)): for j in range(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 announceGenerate(self): # TODO - for some reason this is getting called hundreds of times when there are multiple districts DistributedObject.DistributedObject.announceGenerate(self) self.sendUpdate("enteredParty", []) 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 playFullScreen(self, video, audio=None): self._releaseResources() # self.videoTex = loader.loadTexture(self.resources.getResourceFullPath(PanoConstants.RES_TYPE_VIDEOS, video)) self.videoTex = MovieTexture('name') self.videoTex.read( self.resources.getResourceFullPath(PanoConstants.RES_TYPE_VIDEOS, video)) self.texCard = CardMaker("Full screen Video Card for " + video) self.texCard.setFrameFullscreenQuad() self.texCard.setUvRange(self.videoTex) self.texCardNode = NodePath(self.texCard.generate()) self.texCardNode.reparentTo(render2d) self.texCardNode.setTexture(self.videoTex) if audio is not None: self.vidSound = loader.loadSfx( self.resources.getResourceFullPath( PanoConstants.RES_TYPE_MUSIC, audio)) self.videoTex.synchronizeTo(self.vidSound) self.animInterface = self.videoTex if self.vidSound is not None: self.animInterface = self.vidSound self.totalTime = self.videoTex.getTime() self.animInterface.setLoop(False) self.animInterface.play()
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.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
def createCARD(self, tex, sizeCELLS, sizeRAWS): card = CardMaker("tilesheet") tile = NodePath(card.generate()) tile.reparentTo(render2d) tile.setTexScale(self.ts, sizeCELLS, sizeRAWS) tile.setTexture(self.ts, tex) return tile
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 None cm = CardMaker('filter-stage-quad') cm.setFrameFullscreenQuad() quad = NodePath(cm.generate()) quad.setDepthTest(0) quad.setDepthWrite(0) quad.setColor(Vec4(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) buffer.getDisplayRegion(0).setCamera(quadcam) buffer.getDisplayRegion(0).setActive(1) self.buffers.append(buffer) self.sizes.append((mul, div, align)) return quad
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 = base.config.GetBool('want-toggle-quest-map', 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 __init__(self, player): self.player = player self.root = NodePath("CogdoFlyingGui") self.root.reparentTo(aspect2d) self.fuelMeter = NodePath("scrubMeter") self.fuelMeter.reparentTo(self.root) self.fuelMeter.setPos(1.1, 0.0, -0.7) self.fuelMeter.setSz(2.0) cm = CardMaker('card') cm.setFrame(-0.07, 0.07, 0.0, 0.75) self.fuelMeterBar = self.fuelMeter.attachNewNode(cm.generate()) self.fuelMeterBar.setColor(0.95, 0.95, 0.0, 1.0) self.fuelLabel = DirectLabel( parent=self.root, relief=None, pos=(1.1, 0, -0.8), scale=0.075, text="Fuel", text_fg=(0.95, 0.95, 0, 1), text_shadow=(0, 0, 0, 1), text_font=ToontownGlobals.getInterfaceFont(), ) self.messageLabel = DirectLabel( parent=self.root, relief=None, pos=(0.0, 0.0, -0.9), scale=0.1, text=" ", text_align=TextNode.ACenter, text_fg=(0.95, 0.95, 0, 1), text_shadow=(0, 0, 0, 1), text_font=ToontownGlobals.getInterfaceFont(), textMayChange=1, ) self.messageLabel.stash() self.winLabel = DirectLabel( parent=self.root, relief=None, pos=(0.0, 0.0, 0.0), scale=0.25, text="You win!", text_align=TextNode.ACenter, text_fg=(0.95, 0.95, 0, 1), text_shadow=(0, 0, 0, 1), text_font=ToontownGlobals.getInterfaceFont(), ) self.winLabel.stash() self.refuelLerp = LerpFunctionInterval(self.fuelMeterBar.setSz, fromData=0.0, toData=1.0, duration=2.0)
def renderSceneInto(self, depthtex=None, colortex=None, auxtex=None, auxbits=0, textures=None): if textures: colortex = textures.get('color', None) depthtex = textures.get('depth', None) auxtex = textures.get('aux', None) if colortex == None: colortex = Texture('filter-base-color') colortex.setWrapU(Texture.WMClamp) colortex.setWrapV(Texture.WMClamp) texgroup = (depthtex, colortex, auxtex, None) (winx, winy) = self.getScaledSize(1, 1, 1) buffer = self.createBuffer('filter-base', winx, winy, texgroup) if buffer == None: return None cm = CardMaker('filter-base-quad') cm.setFrameFullscreenQuad() quad = NodePath(cm.generate()) quad.setDepthTest(0) quad.setDepthWrite(0) quad.setTexture(colortex) quad.setColor(Vec4(1, 0.5, 0.5, 1)) cs = NodePath('dummy') cs.setState(self.camstate) if auxbits: cs.setAttrib(AuxBitplaneAttrib.make(auxbits)) self.camera.node().setInitialState(cs.getState()) 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) self.region.setCamera(quadcam) dr = buffer.getDisplayRegion(0) self.setStackedClears(dr, self.rclears, self.wclears) if auxtex: dr.setClearActive(GraphicsOutput.RTPAuxRgba0, 1) dr.setClearValue(GraphicsOutput.RTPAuxRgba0, Vec4(0.5, 0.5, 1.0, 0.0)) self.region.disableClears() if self.isFullscreen(): self.win.disableClears() dr.setCamera(self.camera) dr.setActive(1) self.buffers.append(buffer) self.sizes.append((1, 1, 1)) return quad
def __init__(self, manager, xml): self.texture = loader.loadTexture('data/textures/bullet-hole.png') self.texture.setMinfilter(Texture.FTLinearMipmapLinear) self.container = render.attachNewNode(ModelRoot('bullet-holes')) self.card = CardMaker('bullet-hole') s = BULLETHOLE_SIZE * 0.5 self.card.setFrame(-s, s, -s, s) self.card.setUvRange(Point2(0, 0), Point2(1, 1))
def load(self): self.world = NodePath('ToonBlitzWorld') self.background = loader.loadModel('phase_4/models/minigames/toonblitz_game') self.background.reparentTo(self.world) self.startingWall = loader.loadModel('phase_4/models/minigames/toonblitz_game_wall') self.startingPipe = loader.loadModel('phase_4/models/minigames/toonblitz_game_start') self.exitElevator = loader.loadModel('phase_4/models/minigames/toonblitz_game_elevator') self.arrow = loader.loadModel('phase_4/models/minigames/toonblitz_game_arrow') self.sprayProp = loader.loadModel('phase_4/models/minigames/prop_waterspray') self.treasureModelList = [] salesIcon = loader.loadModel('phase_4/models/minigames/salesIcon') self.treasureModelList.append(salesIcon) moneyIcon = loader.loadModel('phase_4/models/minigames/moneyIcon') self.treasureModelList.append(moneyIcon) legalIcon = loader.loadModel('phase_4/models/minigames/legalIcon') self.treasureModelList.append(legalIcon) corpIcon = loader.loadModel('phase_4/models/minigames/corpIcon') self.treasureModelList.append(corpIcon) self.particleGlow = loader.loadModel('phase_4/models/minigames/particleGlow') self.blockTypes = [] for i in xrange(4): blockType = loader.loadModel('phase_4/models/minigames/toonblitz_game_block0' + str(i)) self.blockTypes.append(blockType) self.stomper = loader.loadModel('phase_4/models/minigames/toonblitz_game_stomper') plane = CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0, 0, -50))) dropPlane = CollisionNode('dropPlane') dropPlane.addSolid(plane) dropPlane.setCollideMask(ToontownGlobals.FloorBitmask) self.world.attachNewNode(dropPlane) self.gameMusic = base.loadMusic('phase_4/audio/bgm/MG_TwoDGame.ogg') self.treasureGrabSound = loader.loadSfx('phase_4/audio/sfx/SZ_DD_treasure.ogg') self.sndOof = base.loadSfx('phase_4/audio/sfx/MG_cannon_hit_dirt.ogg') self.soundJump = base.loadSfx('phase_4/audio/sfx/MG_sfx_vine_game_jump.ogg') self.fallSound = base.loadSfx('phase_4/audio/sfx/MG_sfx_vine_game_fall.ogg') self.watergunSound = base.loadSfx('phase_4/audio/sfx/AA_squirt_seltzer_miss.ogg') self.splashSound = base.loadSfx('phase_4/audio/sfx/Seltzer_squirt_2dgame_hit.ogg') self.threeSparkles = loader.loadSfx('phase_4/audio/sfx/threeSparkles.ogg') self.sparkleSound = loader.loadSfx('phase_4/audio/sfx/sparkly.ogg') self.headCollideSound = loader.loadSfx('phase_3.5/audio/sfx/AV_collision.ogg') self.faceStartPos = Vec3(-0.8, 0, -0.87) self.faceEndPos = Vec3(0.8, 0, -0.87) self.aspect2dRoot = aspect2d.attachNewNode('TwoDGuiAspect2dRoot') self.aspect2dRoot.setDepthWrite(1) self.cardMaker = CardMaker('card') self.cardMaker.reset() self.cardMaker.setName('ProgressLine') self.cardMaker.setFrame(-0.5, 0.5, -0.5, 0.5) self.progressLine = self.aspect2dRoot.attachNewNode(self.cardMaker.generate()) self.progressLine.setScale(self.faceEndPos[0] - self.faceStartPos[0], 1, 0.01) self.progressLine.setPos(0, 0, self.faceStartPos[2]) self.cardMaker.setName('RaceProgressLineHash') for n in xrange(ToonBlitzGlobals.NumSections[self.game.getSafezoneId()] + 1): hash = self.aspect2dRoot.attachNewNode(self.cardMaker.generate()) hash.setScale(self.progressLine.getScale()[2], 1, self.progressLine.getScale()[2] * 5) t = float(n) / ToonBlitzGlobals.NumSections[self.game.getSafezoneId()] hash.setPos(self.faceStartPos[0] * (1 - t) + self.faceEndPos[0] * t, self.faceStartPos[1], self.faceStartPos[2])
def renderQuadInto(self, mul=1, div=1, align=1, depthtex=None, colortex=None, auxtex0=None, auxtex1=None): """ Creates an offscreen buffer for an intermediate computation. Installs a quad into the buffer. Returns the fullscreen quad. The size of the buffer is initially equal to the size of the main window. The parameters 'mul', 'div', and 'align' can be used to adjust that size. """ 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 None cm = CardMaker("filter-stage-quad") cm.setFrameFullscreenQuad() quad = NodePath(cm.generate()) quad.setDepthTest(0) quad.setDepthWrite(0) quad.setColor(Vec4(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) # This clear stage is important if the buffer is padded, so that # any pixels accidentally sampled in the padded region won't # be reading from unititialised memory. buffer.setClearColor((0, 0, 0, 1)) buffer.setClearColorActive(True) self.buffers.append(buffer) self.sizes.append((mul, div, align)) return quad
def __init__(self, table=None, mask=None): """ @keyword table: filename of a table texture. See table_template.psd. Either paint anywhere inside the mask for a complete background or turn off the pads and spinner and paint in the table circle for just a table texture that will have spinners and pads put on top of it. @type mask: str @keyword mask: filename of a mask texture of the non-Jam-o-Drum area. probably jod_mask.png that comes with the Jam-o-Drum library. @type mask: str """ NodePath.__init__(self, "JamoDrum") totalHeight = max(1.0, math.sqrt(2) / 4.0 + SPINNER_RADIUS) * 2 cm = CardMaker("card") cm.setFrame(-1, 1, -1, 1) self.tableCard = self.attachNewNode(cm.generate()) self.tableCard.setP(-90) self.tableCard.setScale(4.0 / 3.0) self.tableCard.setLightOff() self.tableCard.setBin("background", 0) self.tableCard.setDepthTest(0) self.tableCard.setDepthWrite(0) self.tableCard.hide() if (table): self.setTableTexture(loader.loadTexture(table)) if (mask): cm = CardMaker("JOD Mask") cm.setFrame(-4.0 / 3.0, 4.0 / 3.0, -4.0 / 3.0, 4.0 / 3.0) self.mask = aspect2d.attachNewNode(cm.generate()) #self.mask.setP(-90) self.mask.setTexture(loader.loadTexture(mask), 1) self.mask.setTransparency(1) self.mask.setDepthTest(0) else: self.mask = None self.stations = [] for i in range(4): station = Station(self, i) station.reparentTo(self) self.stations.append(station) self.reparentTo(render) base.disableMouse() self.lens = OrthographicLens() self.lens.setFilmSize(totalHeight * base.getAspectRatio(), totalHeight) base.cam.node().setLens(self.lens) camera.setPosHpr(0, 0, 10.0, 0, -90, 0) base.setBackgroundColor(0, 0, 0) self.audio3d = Audio3DManager(base.sfxManagerList[0], self) self.audio3d.setDropOffFactor(0)
def __init__(self, distRace): self.race = distRace self.timerEnabled = False self.maxLapHit = 0 self.photoFinish = False toonInteriorTextures = loader.loadModel( 'phase_3.5/models/modules/toon_interior_textures') invTextures = loader.loadModel('phase_3.5/models/gui/inventory_icons') racingTextures = loader.loadModel( 'phase_6/models/karting/racing_textures') self.gagTextures = [ toonInteriorTextures.find('**/couch'), invTextures.find('**/inventory_bannana_peel'), racingTextures.find('**/boost_arrow'), invTextures.find('**/inventory_anvil'), invTextures.find('**/inventory_creampie') ] self.gagTextures[1].setScale(7.5) self.gagTextures[3].setScale(7.5) self.gagTextures[4].setScale(7.5) self.cardMaker = CardMaker('card') self.racerDict = {} self.render2dRoot = render2d.attachNewNode('RaceGuiRender2dRoot') self.render2dRoot.setDepthWrite(1) self.directObjList = [] self.aspect2dRoot = aspect2d.attachNewNode('RaceGuiAspect2dRoot') self.aspect2dRoot.setDepthWrite(1) self.raceModeRoot = self.aspect2dRoot.attachNewNode('RaceModeRoot') gui = loader.loadModel('phase_3.5/models/gui/avatar_panel_gui') self.closeButton = DirectButton(image=(gui.find('**/CloseBtn_UP'), gui.find('**/CloseBtn_DN'), gui.find('**/CloseBtn_Rllvr'), gui.find('**/CloseBtn_UP')), relief=None, scale=1.05, text=TTLocalizer.KartRace_Leave, text_scale=0.040000000000000001, text_pos=(0, -0.070000000000000007), text_fg=VBase4(1, 1, 1, 1), pos=(-0.98999999999999999, 0, 0.92500000000000004), command=self.race.leaveRace) self.closeButton.reparentTo(self.aspect2dRoot) self.directObjList.append(self.closeButton) self.raceTimeDelta = 0 self.raceModeReady = False self.resultModeReady = False self.gagCycleSound = base.loadSfx( 'phase_3.5/audio/sfx/tick_counter.mp3') if hasattr(self.gagCycleSound, 'setPlayRate'): self.gagCycleSound.setPlayRate(0.20000000000000001) self.gagCycleSound.setLoop(1) self.gagAcquireSound = base.loadSfx( 'phase_6/audio/sfx/SZ_MM_gliss.mp3') self.disable()
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
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 create_click_card(self): # Creade card behind the label. Used for enable mouse click on the label. if self.hierarchy: cm = CardMaker('card-' + self.title) card = self.card_np.attachNewNode(cm.generate()) tex = loader.loadTexture('static/images/menu_left3.tif') card.setTexture(tex) card.setTransparency(TransparencyAttrib.MAlpha) card.setScale(0.5 * self.axisLabelTextLength, 1, 1) card.setPos((-0.25 * self.axisLabelTextLength), 0.01, -0.3) card.setTwoSided(True)
def make_vertical_wall(self, pos): x, y = pos cm = CardMaker("wall") cm.setFrame(0, 1, 0, 2) front_card = cm.generate() front = self.render.attachNewNode(front_card) front.setH(0) front.setPos(x,y,0) back_card = cm.generate() back = self.render.attachNewNode(back_card) back.setH(180) back.setPos(x+1,y,0)
def __init__(self, x1, y1, x2, y2, z): Att_base.__init__(self, False, "Water1") # Water surface maker = CardMaker( 'water' ) maker.setFrame( x1, x2, y1, y2 ) self.waterNP = render.attachNewNode(maker.generate()) self.waterNP.setHpr(0,-90,0) self.waterNP.setPos(0,0,z) self.waterNP.setTransparency(TransparencyAttrib.MAlpha ) self.waterNP.setShader(loader.loadShader( 'Shaders/water1.sha' )) # Reflection plane self.waterPlane = Plane( Vec3( 0, 0, z+1 ), Point3( 0, 0, z ) ) planeNode = PlaneNode( 'waterPlane' ) planeNode.setPlane( self.waterPlane ) # Buffer and reflection camera self.buffer = base.win.makeTextureBuffer( 'waterBuffer', 512, 512 ) self.buffer.setClearColor( Vec4( 0, 0, 0, 1 ) ) cfa = CullFaceAttrib.makeReverse( ) rs = RenderState.make(cfa) self.watercamNP = base.makeCamera( self.buffer ) self.watercamNP.reparentTo(render) sa = ShaderAttrib.make() sa = sa.setShader(loader.loadShader('Shaders/splut3Clipped.sha') ) self.cam = self.watercamNP.node() self.cam.getLens( ).setFov( base.camLens.getFov( ) ) self.cam.getLens().setNear(1) self.cam.getLens().setFar(5000) self.cam.setInitialState( rs ) self.cam.setTagStateKey('Clipped') self.cam.setTagState('True', RenderState.make(sa)) # ---- water textures --------------------------------------------- # 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)
def _initVisuals(self): RepairMincroGame._initVisuals(self) self.model = loader.loadModel('models/gui/pir_m_gui_srp_pumping_main') self.visual = self.attachNewNode('visual') self.visual.setPos(-0.25, 0.0, 0.074999999999999997) goalTopLoc = self.model.find('**/locator_top') goalTopLoc.reparentTo(self.visual) goalBottomLoc = self.model.find('**/locator_bottom') goalBottomLoc.reparentTo(self.visual) self.goalPositions = (goalBottomLoc.getPos(self), goalTopLoc.getPos(self)) self.greatLabel = DirectLabel(text = PLocalizer.Minigame_Repair_Pumping_Great, text_fg = (0.20000000000000001, 0.80000000000000004, 0.29999999999999999, 1.0), text_pos = (0.0, 0.59999999999999998), text_align = TextNode.ACenter, text_font = PiratesGlobals.getPirateFont(), relief = None, text_shadow = (0.0, 0.0, 0.0, 1.0), scale = (0.080000000000000002, 0.080000000000000002, 0.080000000000000002), pos = (-0.46500000000000002, 0.0, 0.0), parent = self) self.failLabel = DirectLabel(text = PLocalizer.Minigame_Repair_Pumping_Fail, text_fg = (0.80000000000000004, 0.20000000000000001, 0.29999999999999999, 1.0), text_pos = (0.0, 0.59999999999999998), text_align = TextNode.ARight, text_font = PiratesGlobals.getPirateFont(), text_shadow = (0.0, 0.0, 0.0, 1.0), relief = None, scale = (0.080000000000000002, 0.080000000000000002, 0.080000000000000002), pos = (-0.625, 0.0, 0.0), parent = self) self.shipBackground = self.model.find('**/static_ship_background') self.shipBackground.reparentTo(self.visual) self.waterMeter = self.model.find('**/sprite_waterBottom') self.waterMeter.reparentTo(self.visual) self.waterTop = self.model.find('**/sprite_waterTop') self.waterTop.reparentTo(self.visual) self.waterMeterTopLoc = self.waterMeter.find('**/locator_topOfShipWater') self.pumpBackground = self.model.find('**/pumpBackground') self.pumpBackground.reparentTo(self.visual) self.pumpWaterTop = self.model.find('**/sprite_pumpWaterTop') self.pumpWaterTop.reparentTo(self.visual) self.pumpWaterBottom = self.model.find('**/sprite_pumpWaterBottom') self.pumpWaterBottom.reparentTo(self.visual) self.pumpWaterTopLoc = self.pumpWaterBottom.find('**/locator_topOfPumpWater') self.pumpHandle = self.model.find('**/sprite_handle') self.pumpHandle.reparentTo(self.visual) self.pumpBar = self.model.find('**/static_pump') self.pumpBar.reparentTo(self.visual) self.goalBox = self.model.find('**/sprite_clickField') self.goalBox.reparentTo(self.visual) self.goalBox.setTransparency(1) self.enableGoalBox() self.pumpLine = self.model.find('**/sprite_bar') self.pumpLine.reparentTo(self.visual) self.ghostLine = self.visual.attachNewNode('ghostLine') self.pumpLine.getChild(0).copyTo(self.ghostLine) self.ghostLine.setScale(self.pumpLine.getScale()) self.ghostLine.setColor(1.0, 0.20000000000000001, 0.20000000000000001, 1.0) self.shipForground = self.model.find('**/static_ship_foreground') self.shipForground.reparentTo(self.visual) cm = CardMaker('cardMaker') cm.setFrame(-0.33000000000000002, 0.33000000000000002, 0.0, 1.0) self.goalBox.setZ(self.goalPositions[TOP].getZ()) self.goalBoxStartScale = self.goalBox.getSz() self.enableGoalBox() self.pumpWaterUpLerp = LerpFunc(self.setPumpWater, fromData = -0.10000000000000001, toData = 1.0, duration = 0.5) self.pumpWaterDownLerp = LerpFunc(self.setPumpWater, fromData = 1.0, toData = -0.10000000000000001, duration = 0.5) self.model.removeNode() del self.model
def loadFlatQuad(self, fullFilename): """Load the flat jpg into a quad.""" assert self.notify.debugStateCall(self) #Texture.setTexturesPower2(AutoTextureScale.ATSUp) #Texture.setTexturesPower2(2) 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) # the html area will be center aligned and vertically top aligned #cm.setFrame(-htmlWidth/2.0, htmlWidth/2.0, 1.0 - htmlHeight, 1.0) 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,0), Point2(bottomRightX, bottomRightY)) cm.setUvRange(Point2(0,1-bottomRightY), Point2(bottomRightX,1)) card = cm.generate() quad = NodePath(card) #quad.reparentTo(self.parent) 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.setKeepRamImage(True) #guiTex.makeRamImage() guiTex.setWrapU(Texture.WMClamp) guiTex.setWrapV(Texture.WMClamp) ts = TextureStage('webTS') quad.setTexture(ts, guiTex) #quad.setTexScale(ts, 1.0, -1.0) quad.setTransparency(0) quad.setTwoSided(True) quad.setColor(1.0, 1.0, 1.0, 1.0) result= quad else: # if we have an error loading the file, return None to signify an error result = None #Texture.setTexturesPower2(AutoTextureScale.ATSDown) Texture.setTexturesPower2(1) return result
def __init__(self, listConsideration=[]): z = -0.05 self.plane = Plane(Vec3(0, 0, 1), Point3(0, 0, z)) cm = CardMaker("blah") cm.setFrame(-100, 100, -100, 100) render.attachNewNode(cm.generate()).lookAt(0, 0, -1) #Create a selection window using cardmaker #We will use the setScale function to dynamically scale the quad to the appropriate size in UpdateSelRect temp = CardMaker('') temp.setFrame(0, 1, 0, 1) #self.npSelRect is the actual selection rectangle that we dynamically hide/unhide and change size self.npSelRect = render2d.attachNewNode(temp.generate()) self.npSelRect.setColor(0.5,1,0,.3) self.npSelRect.setTransparency(1) self.npSelRect.hide() LS = LineSegs() LS.setColor(0.5,1,0,1) LS.moveTo(0,0,0) LS.drawTo(1,0,0) LS.drawTo(1,0,1) LS.drawTo(0,0,1) LS.drawTo(0,0,0) self.npSelRect.attachNewNode(LS.create()) self.listConsideration = listConsideration self.listSelected = [] self.listLastSelected = [] self.pt2InitialMousePos = (-12, -12) self.pt2LastMousePos = (-12, -12) ####----Used to differentiate between group selections and point selections #self.booMouseMoved = False self.fFovh, self.fFovv = base.camLens.getFov() ####--Used to control how frequently update_rect is updated; self.fTimeLastUpdateSelRect = 0 self.fTimeLastUpdateSelected = 0 self.UpdateTimeSelRect = 0.015 self.UpdateTimeSelected = 0.015 ####------Register the left-mouse-button to start selecting self.accept("mouse1", self.OnStartSelect) self.accept("control-mouse1", self.OnStartSelect) self.accept("mouse1-up", self.OnStopSelect) self.taskUpdateSelRect = 0 ####------otherThings self.booSelecting = False
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
def __init__(self, name, nrplates, width, height, shaderfile, texturefile, uvlist, jitter=-1): self.name = name self.texturefile = texturefile self.shaderfile = shaderfile self.np = NodePath('leaf') self.tex = loader.loadTexture('textures/' + texturefile) self.tex.setMinfilter(Texture.FTLinearMipmapLinear) self.tex.setMagfilter(Texture.FTLinearMipmapLinear) self.tex.setAnisotropDegree(2) self.np.setTexture(self.tex) self.np.setTwoSided(True) self.np.setTransparency(TransparencyAttrib.MAlpha) self.np.setDepthWrite(False) maker = CardMaker('leaf') maker.setFrame(-width/2.0, width/2.0, 0, height) #maker.setFrame(0,1,0,1) for i in range(nrplates): if uvlist != None: maker.setUvRange(uvlist[i][0], uvlist[i][1]) else: maker.setUvRange(Point2(0,0), Point2(1,0.98)) node = self.np.attachNewNode(maker.generate()) #node.setTwoSided(True) node.setHpr(i * 180.0 / nrplates,0,0) self.np.flattenStrong() #np.flattenLight() #np.setTwoSided(True) if jitter == -1: self.jitter = height/width/2 else: self.jitter = jitter
def __init__(self,width,height,texture,scale): self.width = width*scale self.height = height*scale print texture self.texture = loader.loadTexture(texture) cm = CardMaker("CardMaker") cm.setFrame((self.width/2,self.height/2,0),(-self.width/2,self.height/2,0),(-self.width/2,-self.height/2,0),(self.width/2,-self.height/2,0)) card = render.attachNewNode(cm.generate()) card.clearColor() card.setBin("background", 10) card.setHpr(180,0,0) card.setTransparency(TransparencyAttrib.MAlpha) card.setTexture(self.texture)
def __init__(self,table=None,mask=None): """ @keyword table: filename of a table texture. See table_template.psd. Either paint anywhere inside the mask for a complete background or turn off the pads and spinner and paint in the table circle for just a table texture that will have spinners and pads put on top of it. @type mask: str @keyword mask: filename of a mask texture of the non-Jam-o-Drum area. probably jod_mask.png that comes with the Jam-o-Drum library. @type mask: str """ NodePath.__init__(self,"JamoDrum") totalHeight = max(1.0,math.sqrt(2)/4.0+SPINNER_RADIUS)*2 cm = CardMaker("card") cm.setFrame(-1,1,-1,1) self.tableCard = self.attachNewNode(cm.generate()) self.tableCard.setP(-90) self.tableCard.setScale(4.0/3.0) self.tableCard.setLightOff() self.tableCard.setBin("background",0) self.tableCard.setDepthTest(0) self.tableCard.setDepthWrite(0) self.tableCard.hide() if (table): self.setTableTexture(loader.loadTexture(table)) if (mask): cm = CardMaker("JOD Mask") cm.setFrame(-4.0/3.0,4.0/3.0,-4.0/3.0,4.0/3.0) self.mask = aspect2d.attachNewNode(cm.generate()) #self.mask.setP(-90) self.mask.setTexture(loader.loadTexture(mask),1) self.mask.setTransparency(1) self.mask.setDepthTest(0) else: self.mask = None self.stations = [] for i in range(4): station = Station(self,i) station.reparentTo(self) self.stations.append(station) self.reparentTo(render) base.disableMouse() self.lens = OrthographicLens() self.lens.setFilmSize(totalHeight*base.getAspectRatio(),totalHeight) base.cam.node().setLens(self.lens) camera.setPosHpr(0,0,10.0, 0,-90,0) base.setBackgroundColor(0,0,0) self.audio3d = Audio3DManager(base.sfxManagerList[0],self) self.audio3d.setDropOffFactor(0)
def setSky(directory, ext=".jpg"): """Sets up a skybox. 'directory' is the directory whitch contains 6 pictures with the names right.ext, left.ext and so on (see template). ext is the extension the pictures have (with dot). """ #TODO: accept all supported image file extensions without the need for an # extra argument # remove the old sky first when loading a new one # TODO: get this working... #oldsky = render.find("*sky*") #print oldsky #for child in render.getChildren(): # child.remove() sky = NodePath().attachNewNode("sky") sides = { "right": ( 1, 0, 0, -90, 0, 0), "left": (-1, 0, 0, 90, 0, 0), "top": ( 0, 0, 1, 0, 90, 0), "bottom": ( 0, 0, -1, 180, -90, 0), "front": ( 0, 1, 0, 0, 0, 0), "back": ( 0, -1, 0, 180, 0, 0) } for name, poshpr in sides.iteritems(): c = CardMaker(name) c.setFrame(-1, 1, -1, 1) card = c.generate() cardnode = sky.attachNewNode(card) cardnode.setPosHpr(*poshpr) tex = loader.loadTexture("skyboxes/" + directory + "/" + name + ext) tex.setWrapV(tex.WMClamp) tex.setMagfilter(tex.FTNearestMipmapNearest) tex.setMinfilter(tex.FTNearestMipmapNearest) cardnode.setTexture(tex) sky.flattenStrong() sky.setScale(10, 10, 10) sky.setCompass() sky.setBin('background', 0) sky.setDepthTest(False) sky.setDepthWrite(False) sky.setLightOff() sky.reparentTo(camera) geom = sky.getChild(0).node() geom.setName("cube")
def __init__(self, potionGame): self.numColumns = 8 self.numRows = 10 DirectFrame.__init__(self, parent = potionGame.background, relief = None) cm = CardMaker('card') cm.setFrame(0, 0, 1.0, 1.0) self.background = self.attachNewNode(cm.generate()) self.background.setColor(0.20000000000000001, 0.20000000000000001, 0.20000000000000001, 1) self.potionGame = potionGame self.pieceDropped = False self.pieceFlipped = False self.pieceNotDropped = False self.delayDropped = False self.experementMatched = False self.experementFailed = False self.initBoard()
def createSprite(self,filename, x, z, sx, sz, transparent = 1): cm = CardMaker('spritesMaker') cm.setFrame(-0.5, 0.5, -0.5, 0.5) sprite = cm.generate() tex = loader.loadTexture(filename) spriteNP = NodePath(sprite) spriteNP.setTexture(tex) spriteNP.setPos(x, 0, z) spriteNP.setScale(sx, 1.0, sz) spriteNP.setTransparency(transparent) return spriteNP
def __init__(self, character): self.character = character # Setup mouse base.disableMouse() hideMouse(True) self.mouseSensitivity = 0.1 base.taskMgr.doMethodLater(0.1, self.prepareCameraTask, "prepare-camera") # Setup camera base.camera.reparentTo(self.character.node) base.camera.setPos(0, 0, 0) base.camera.lookAt(0, 1, 0) # Create target self.target = OnscreenImage(image = "media/target.png", pos = (0, 0, 0)) self.target.setTransparency(TransparencyAttrib.MAlpha) self.target.setScale(0.1) self.target.setSa(0.5) # Create overlay self.overlayCard = CardMaker("overlayCard") self.overlayCard.setFrameFullscreenQuad() self.overlay = base.render2d.attachNewNode(self.overlayCard.generate()) self.overlay.setTransparency(TransparencyAttrib.MAlpha) self.overlay.setColor(0,0,0,0) # Setup interval sequences self.shakeSequence = None self.flashSequence = None
def load(self): self.world = NodePath("ToonBlitzWorld") self.background = loader.loadModel("phase_4/models/minigames/toonblitz_game") self.background.reparentTo(self.world) self.startingWall = loader.loadModel("phase_4/models/minigames/toonblitz_game_wall") self.startingPipe = loader.loadModel("phase_4/models/minigames/toonblitz_game_start") self.exitElevator = loader.loadModel("phase_4/models/minigames/toonblitz_game_elevator") self.arrow = loader.loadModel("phase_4/models/minigames/toonblitz_game_arrow") self.sprayProp = loader.loadModel("phase_4/models/minigames/prop_waterspray") self.treasureModelList = [] salesIcon = loader.loadModel("phase_4/models/minigames/salesIcon") self.treasureModelList.append(salesIcon) moneyIcon = loader.loadModel("phase_4/models/minigames/moneyIcon") self.treasureModelList.append(moneyIcon) legalIcon = loader.loadModel("phase_4/models/minigames/legalIcon") self.treasureModelList.append(legalIcon) corpIcon = loader.loadModel("phase_4/models/minigames/corpIcon") self.treasureModelList.append(corpIcon) self.particleGlow = loader.loadModel("phase_4/models/minigames/particleGlow") self.blockTypes = [] for i in xrange(4): blockType = loader.loadModel("phase_4/models/minigames/toonblitz_game_block0" + str(i)) self.blockTypes.append(blockType) self.stomper = loader.loadModel("phase_4/models/minigames/toonblitz_game_stomper") plane = CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0, 0, -50))) dropPlane = CollisionNode("dropPlane") dropPlane.addSolid(plane) dropPlane.setCollideMask(ToontownGlobals.FloorBitmask) self.world.attachNewNode(dropPlane) self.gameMusic = base.loadMusic("phase_4/audio/bgm/MG_TwoDGame.ogg") self.treasureGrabSound = loader.loadSfx("phase_4/audio/sfx/SZ_DD_treasure.ogg") self.sndOof = base.loadSfx("phase_4/audio/sfx/MG_cannon_hit_dirt.ogg") self.soundJump = base.loadSfx("phase_4/audio/sfx/MG_sfx_vine_game_jump.ogg") self.fallSound = base.loadSfx("phase_4/audio/sfx/MG_sfx_vine_game_fall.ogg") self.watergunSound = base.loadSfx("phase_4/audio/sfx/AA_squirt_seltzer_miss.ogg") self.splashSound = base.loadSfx("phase_4/audio/sfx/Seltzer_squirt_2dgame_hit.ogg") self.threeSparkles = loader.loadSfx("phase_4/audio/sfx/threeSparkles.ogg") self.sparkleSound = loader.loadSfx("phase_4/audio/sfx/sparkly.ogg") self.headCollideSound = loader.loadSfx("phase_3.5/audio/sfx/AV_collision.ogg") self.faceStartPos = Vec3(-0.8, 0, -0.87) self.faceEndPos = Vec3(0.8, 0, -0.87) self.aspect2dRoot = aspect2d.attachNewNode("TwoDGuiAspect2dRoot") self.aspect2dRoot.setDepthWrite(1) self.cardMaker = CardMaker("card") self.cardMaker.reset() self.cardMaker.setName("ProgressLine") self.cardMaker.setFrame(-0.5, 0.5, -0.5, 0.5) self.progressLine = self.aspect2dRoot.attachNewNode(self.cardMaker.generate()) self.progressLine.setScale(self.faceEndPos[0] - self.faceStartPos[0], 1, 0.01) self.progressLine.setPos(0, 0, self.faceStartPos[2]) self.cardMaker.setName("RaceProgressLineHash") for n in xrange(ToonBlitzGlobals.NumSections[self.game.getSafezoneId()] + 1): hash = self.aspect2dRoot.attachNewNode(self.cardMaker.generate()) hash.setScale(self.progressLine.getScale()[2], 1, self.progressLine.getScale()[2] * 5) t = float(n) / ToonBlitzGlobals.NumSections[self.game.getSafezoneId()] hash.setPos( self.faceStartPos[0] * (1 - t) + self.faceEndPos[0] * t, self.faceStartPos[1], self.faceStartPos[2] )
def create_floor(self, size_x_axis, size_y_axis, texture): card_maker = CardMaker('') card_maker.setFrame(0,size_x_axis,0,size_y_axis) ''' for y in range(size_y_axis): for x in range(size_x_axis): new_node = self.floorNode.attachNewNode(card_maker.generate()) new_node.setP(-90) new_node.setPos(x, y, 0) ''' new_node = self.floor_node.attachNewNode(card_maker.generate()) new_node.setP(-90) new_node.setPos(0, 0, 0) new_node.setTexture(textures[texture]) self.floor_node.flattenStrong()
def __init__(self,manager,xml): self.texture = loader.loadTexture('data/textures/bullet-hole.png') self.texture.setMinfilter(Texture.FTLinearMipmapLinear) self.container = render.attachNewNode(ModelRoot('bullet-holes')) self.card = CardMaker('bullet-hole') s = BULLETHOLE_SIZE * 0.5 self.card.setFrame(-s, s, -s, s) self.card.setUvRange(Point2(0, 0), Point2(1, 1))
def load_floor(self): cm = CardMaker("floor") cm.setFrame(0, 1, 0, 1) card = cm.generate() grass_texture = self.loader.loadTexture(os.path.join("data", "images", "grass.png")) wood_texture = self.loader.loadTexture(os.path.join("data", "images", "floor_wood_0.png")) for x, row in enumerate(self.floor_data.layout): for y, tile in enumerate(row): floor = self.render.attachNewNode(cm.generate()) floor.setP(270) floor.setPos(x,y,0) if tile == floor_layout.GRASS: floor.setTexture(grass_texture) elif tile == floor_layout.WOOD: floor.setTexture(wood_texture)
class BulletHoles: """The name says it all.""" def __init__(self,manager,xml): self.texture = loader.loadTexture('data/textures/bullet-hole.png') self.texture.setMinfilter(Texture.FTLinearMipmapLinear) self.container = render.attachNewNode(ModelRoot('bullet-holes')) self.card = CardMaker('bullet-hole') s = BULLETHOLE_SIZE * 0.5 self.card.setFrame(-s, s, -s, s) self.card.setUvRange(Point2(0, 0), Point2(1, 1)) def makeNew(self, pos, nor, parent = None): """Makes a new bullet hole.""" if parent == None: parent = self.container else: # Add a subnode to the parent, if it's not already there child = parent.find('bullet-holes') if child.isEmpty(): parent = parent.attachNewNode('bullet-holes') else: parent = child newhole = NodePath(self.card.generate()) newhole.reparentTo(parent) newhole.lookAt(render, Point3(newhole.getPos(render) - nor)) newhole.setR(newhole, random() * 360.0) newhole.setPos(render, pos) # Offset it a little to avoid z-fighting # Increase this value if you still see it. newhole.setY(newhole, -.001 - random() * 0.01) del newhole # We don't want one batch per bullet hole, so flatten it. # This could be made smarter to preserve culling, but # I have yet to see a performance loss. # The clearTexture() is a necessary hack. parent.clearTexture() parent.flattenStrong() parent.setTexture(self.texture) parent.setTransparency(TransparencyAttrib.MDual) parent.setShaderOff(1) parent.hide(BitMask32.bit(2)) # Invisible to volumetric lighting camera (speedup) parent.hide(BitMask32.bit(3)) # Invisible to shadow cameras (speedup) def destroy(self): self.container.removeNode()
def __setupEnvironment(self): cm = CardMaker("ground") size = 200 cm.setFrame(-size, size, -size, size) environment = render.attachNewNode(cm.generate()) environment.lookAt(0, 0, -1) environment.setPos(100, -100, 0) environment.setCollideMask(BitMask32.allOn()) environment.reparentTo(render) texture = loader.loadTexture("textures/ground.png") # This is so the textures can look better from a distance texture.setMinfilter(Texture.FTLinearMipmapLinear) environment.setTexGen(TextureStage.getDefault(), TexGenAttrib.MWorldPosition) environment.setTexScale(TextureStage.getDefault(), 0.02, 0.02) environment.setTexture(texture, 1)
def __init__(self): self.music = loader.loadMusic('phase_4/audio/bgm/science_fair_credits.ogg') cm = CardMaker('screen-cover') cm.setFrameFullscreenQuad() self.screenCover = render2d.attachNewNode(cm.generate()) self.screenCover.hide() self.screenCover.setScale(100) self.screenCover.setColor((0, 0, 0, 1)) self.logo = OnscreenImage(image='phase_3/maps/toontown-logo.png', scale=(1.0 * (4.0/3.0), 1, 1.0 / (4.0/3.0)), pos=(-0.05, 1, -0.85)) self.logo.setTransparency(TransparencyAttrib.MAlpha) self.logo.reparentTo(base.a2dTopCenter) self.logo.hide() self.creditsSeq = None
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 __init__(self, distRace): self.race = distRace self.timerEnabled = False self.maxLapHit = 0 self.photoFinish = False toonInteriorTextures = loader.loadModel("phase_3.5/models/modules/toon_interior_textures") invTextures = loader.loadModel("phase_3.5/models/gui/inventory_icons") racingTextures = loader.loadModel("phase_6/models/karting/racing_textures") self.gagTextures = [ toonInteriorTextures.find("**/couch"), invTextures.find("**/inventory_bannana_peel"), racingTextures.find("**/boost_arrow"), invTextures.find("**/inventory_anvil"), invTextures.find("**/inventory_creampie"), ] self.gagTextures[1].setScale(7.5) self.gagTextures[3].setScale(7.5) self.gagTextures[4].setScale(7.5) self.cardMaker = CardMaker("card") self.racerDict = {} self.render2dRoot = render2d.attachNewNode("RaceGuiRender2dRoot") self.render2dRoot.setDepthWrite(1) self.directObjList = [] self.aspect2dRoot = aspect2d.attachNewNode("RaceGuiAspect2dRoot") self.aspect2dRoot.setDepthWrite(1) self.raceModeRoot = self.aspect2dRoot.attachNewNode("RaceModeRoot") gui = loader.loadModel("phase_3.5/models/gui/avatar_panel_gui") self.closeButton = DirectButton( image=( gui.find("**/CloseBtn_UP"), gui.find("**/CloseBtn_DN"), gui.find("**/CloseBtn_Rllvr"), gui.find("**/CloseBtn_UP"), ), relief=None, scale=1.05, text=TTLocalizer.KartRace_Leave, text_scale=0.04, text_pos=(0, -0.07), text_fg=VBase4(1, 1, 1, 1), pos=(-0.99, 0, 0.925), command=self.race.leaveRace, ) self.closeButton.reparentTo(self.aspect2dRoot) self.directObjList.append(self.closeButton) self.raceTimeDelta = 0 self.raceModeReady = False self.resultModeReady = False self.gagCycleSound = base.loadSfx("phase_3.5/audio/sfx/tick_counter.ogg") if hasattr(self.gagCycleSound, "setPlayRate"): self.gagCycleSound.setPlayRate(0.2) self.gagCycleSound.setLoop(1) self.gagAcquireSound = base.loadSfx("phase_6/audio/sfx/SZ_MM_gliss.ogg") self.disable() return