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 title(self): #Removes title and loads current room def destroyTitle(task): card.removeNode() startGame() def startGame(): if os.path.isfile('saves/location.json'): self.directToRoom() else: self.homeFirst() #Loads title animation titleText = self.loader.loadTexture('resources/titleText.avi') titleText.setLoopCount(1) titleText.play() #Displays title cm = CardMaker('titleText') cm.setFrameFullscreenQuad() cm.setUvRange(titleText) # noinspection PyArgumentList card = NodePath(cm.generate()) card.reparentTo(self.render2d) card.setTexture(titleText) self.taskMgr.doMethodLater(5.6, destroyTitle, 'endTitle')
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 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 _initGUI(self): base.loadingScreen.beginStep('init Gui', 4, 55) cm = CardMaker('PotionBackground') cm.setFrame(-10, 10, -10, 10) cm.setColor(0, 0, 0, 1) self.background = NodePath(cm.generate()) self.background.reparentTo(aspect2d) self.background.setBin('background', -100) self.xpBackground = NodePath('PotionXPBackground') self.xpBackground.reparentTo(aspect2d) self.xpBackground.setBin('background', -95) base.loadingScreen.tick() self.dialogs = NodePath('DialogBackground') self.dialogs.reparentTo(aspect2d) self.dialogs.setBin('background', -70) self.buttonsBackground = NodePath('PotionButtonBackground') self.buttonsBackground.reparentTo(base.a2dBottomRight) self.buttonsBackground.setBin('background', -90) textureCard = loader.loadModel('models/minigames/pir_m_gui_pot_textureCard') self.stretchedBackgroundTextureCard = textureCard.find('**/pir_t_gui_pot_background') self.stretchedBackgroundTextureCard.reparentTo(self.background) self.stretchedBackgroundTextureCard.setScale(3.3999999999999999, 1.0, 3.3999999999999999) self.stretchedBackgroundTextureCard.setPos(0.0, 20.0, 0.0) fadecm = CardMaker('card') fadecm.setFrameFullscreenQuad() self.fadeIn = render2d.attachNewNode(fadecm.generate()) self.fadeIn.setBin('background', -50) self.fadeIn.setPos(0.0, -30.0, 0.0) self.fadeIn.setColor(0, 0, 0, 1.0) self.fadeIn.setTransparency(True) base.loadingScreen.tick() cm = CardMaker('card') cm.setFrame(0, 1, 0.01, 0.01) self.foregroundLayer = aspect2d.attachNewNode(cm.generate()) self.foregroundTextureCard = textureCard.find('**/pir_t_gui_pot_foreground') self.foregroundTextureCard.setScale(0.80000000000000004, 1.0, 0.40000000000000002) self.foregroundTextureCard.setPos(-0.69999999999999996, -20.0, 0.80000000000000004) self.foregroundTextureCard.setBin('background', -80) self.foregroundTextureCard.copyTo(self.foregroundLayer) self.repMeter = ReputationMeter.ReputationMeter(InventoryType.PotionsRep, width = 0.56000000000000005) inv = localAvatar.getInventory() self.repMeter.reparentTo(self.xpBackground) self.repMeter.setPos(0, 0, -0.94999999999999996) self.repMeter.update(inv.getAccumulator(InventoryType.PotionsRep)) localAvatar.guiMgr.registerReputationHandler(self.updateRepMeter) base.loadingScreen.tick() self.closeButton = GuiButton.GuiButton(image = (textureCard.find('**/pir_t_gui_pot_escape'), textureCard.find('**/pir_t_gui_pot_escapeOn'), textureCard.find('**/pir_t_gui_pot_escapeOn'), textureCard.find('**/pir_t_gui_pot_escape')), image_scale = (0.10000000000000001, 0.10000000000000001, 0.10000000000000001), image_pos = (0.074999999999999997, 0, 0.080000000000000002), hotkeys = [ 'Escape'], hotkeyLabel = PLocalizer.PotionGui['ExitButton'], pos = (-0.40000000000000002, 0.0, 0.01), text0_fg = PotionGlobals.TextColor, text1_fg = PiratesGuiGlobals.TextFG0, text2_fg = PiratesGuiGlobals.TextFG15, text3_fg = PotionGlobals.TextColorDisabled, parent = self.buttonsBackground, command = self.confirmQuit) self.returnButton = GuiButton.GuiButton(text = (PLocalizer.PotionGui['SwitchRecipe'], PLocalizer.PotionGui['SwitchRecipe'], PLocalizer.PotionGui['SwitchRecipe'], PLocalizer.PotionGui['SwitchRecipe']), pos = (-0.57999999999999996, 0.0, -0.62), text_scale = PiratesGuiGlobals.TextScaleExtraLarge, text_shadow = None, image = (None, None, None, None), text0_fg = PotionGlobals.TextColor, text1_fg = PiratesGuiGlobals.TextFG0, text2_fg = PiratesGuiGlobals.TextFG15, text3_fg = PotionGlobals.TextColorDisabled, parent = self.background, command = self.confirmReturn) self.returnButton.stash() self.hintsButton = GuiButton.GuiButton(text = (PLocalizer.PotionGui['ShowTutorial'], PLocalizer.PotionGui['ShowTutorial'], PLocalizer.PotionGui['ShowTutorial'], PLocalizer.PotionGui['ShowTutorial']), text_scale = PiratesGuiGlobals.TextScaleSmall, image_scale = (0.25, 0.10000000000000001, 0.17999999999999999), image_pos = (0, 0, 0), pos = (-0.53000000000000003, 0.0, 0.074999999999999997), parent = self.buttonsBackground, command = self.showLastHint) self.InfoButton = GuiButton.GuiButton(text = (PLocalizer.PotionGui['IngredientList'], PLocalizer.PotionGui['IngredientList'], PLocalizer.PotionGui['IngredientList'], PLocalizer.PotionGui['IngredientList']), text_scale = PiratesGuiGlobals.TextScaleSmall, image_scale = (0.29999999999999999, 0.10000000000000001, 0.17999999999999999), image_pos = (0, 0, 0), pos = (-0.83999999999999997, 0.0, 0.074999999999999997), parent = self.buttonsBackground, command = self.showInfo) textureCard.removeNode() base.loadingScreen.endStep('init Gui')
def _initGUI(self): base.loadingScreen.beginStep('init Gui', 4, 55) cm = CardMaker('PotionBackground') cm.setFrame(-10, 10, -10, 10) cm.setColor(0, 0, 0, 1) self.background = NodePath(cm.generate()) self.background.reparentTo(aspect2d) self.background.setBin('background', -100) self.xpBackground = NodePath('PotionXPBackground') self.xpBackground.reparentTo(aspect2d) self.xpBackground.setBin('background', -95) base.loadingScreen.tick() self.dialogs = NodePath('DialogBackground') self.dialogs.reparentTo(aspect2d) self.dialogs.setBin('background', -70) self.buttonsBackground = NodePath('PotionButtonBackground') self.buttonsBackground.reparentTo(base.a2dBottomRight) self.buttonsBackground.setBin('background', -90) textureCard = loader.loadModel('models/minigames/pir_m_gui_pot_textureCard') self.stretchedBackgroundTextureCard = textureCard.find('**/pir_t_gui_pot_background') self.stretchedBackgroundTextureCard.reparentTo(self.background) self.stretchedBackgroundTextureCard.setScale(3.3999999999999999, 1.0, 3.3999999999999999) self.stretchedBackgroundTextureCard.setPos(0.0, 20.0, 0.0) fadecm = CardMaker('card') fadecm.setFrameFullscreenQuad() self.fadeIn = render2d.attachNewNode(fadecm.generate()) self.fadeIn.setBin('background', -50) self.fadeIn.setPos(0.0, -30.0, 0.0) self.fadeIn.setColor(0, 0, 0, 1.0) self.fadeIn.setTransparency(True) base.loadingScreen.tick() cm = CardMaker('card') cm.setFrame(0, 1, 0.01, 0.01) self.foregroundLayer = aspect2d.attachNewNode(cm.generate()) self.foregroundTextureCard = textureCard.find('**/pir_t_gui_pot_foreground') self.foregroundTextureCard.setScale(0.80000000000000004, 1.0, 0.40000000000000002) self.foregroundTextureCard.setPos(-0.69999999999999996, -20.0, 0.80000000000000004) self.foregroundTextureCard.setBin('background', -80) self.foregroundTextureCard.copyTo(self.foregroundLayer) self.repMeter = ReputationMeter.ReputationMeter(InventoryType.PotionsRep, width = 0.56000000000000005) inv = localAvatar.getInventory() self.repMeter.reparentTo(self.xpBackground) self.repMeter.setPos(0, 0, -0.94999999999999996) self.repMeter.update(inv.getAccumulator(InventoryType.PotionsRep)) localAvatar.guiMgr.registerReputationHandler(self.updateRepMeter) base.loadingScreen.tick() self.closeButton = GuiButton.GuiButton(image = (textureCard.find('**/pir_t_gui_pot_escape'), textureCard.find('**/pir_t_gui_pot_escapeOn'), textureCard.find('**/pir_t_gui_pot_escapeOn'), textureCard.find('**/pir_t_gui_pot_escape')), image_scale = (0.10000000000000001, 0.10000000000000001, 0.10000000000000001), image_pos = (0.074999999999999997, 0, 0.080000000000000002), hotkeys = [ 'Escape'], hotkeyLabel = PLocalizer.PotionGui['ExitButton'], pos = (-0.40000000000000002, 0.0, 0.01), text0_fg = PotionGlobals.TextColor, text1_fg = PiratesGuiGlobals.TextFG0, text2_fg = PiratesGuiGlobals.TextFG15, text3_fg = PotionGlobals.TextColorDisabled, parent = self.buttonsBackground, command = self.confirmQuit) self.returnButton = GuiButton.GuiButton(text = (PLocalizer.PotionGui['SwitchRecipe'], PLocalizer.PotionGui['SwitchRecipe'], PLocalizer.PotionGui['SwitchRecipe'], PLocalizer.PotionGui['SwitchRecipe']), pos = (-0.57999999999999996, 0.0, -0.62), text_scale = PiratesGuiGlobals.TextScaleExtraLarge, text_shadow = None, image = (None, None, None, None), text0_fg = PotionGlobals.TextColor, text1_fg = PiratesGuiGlobals.TextFG0, text2_fg = PiratesGuiGlobals.TextFG15, text3_fg = PotionGlobals.TextColorDisabled, parent = self.background, command = self.confirmReturn) self.returnButton.stash() self.hintsButton = GuiButton.GuiButton(text = (PLocalizer.PotionGui['ShowTutorial'], PLocalizer.PotionGui['ShowTutorial'], PLocalizer.PotionGui['ShowTutorial'], PLocalizer.PotionGui['ShowTutorial']), text_scale = PiratesGuiGlobals.TextScaleSmall, image_scale = (0.25, 0.10000000000000001, 0.17999999999999999), image_pos = (0, 0, 0), pos = (-0.53000000000000003, 0.0, 0.074999999999999997), parent = self.buttonsBackground, command = self.showLastHint) self.InfoButton = GuiButton.GuiButton(text = (PLocalizer.PotionGui['IngredientList'], PLocalizer.PotionGui['IngredientList'], PLocalizer.PotionGui['IngredientList'], PLocalizer.PotionGui['IngredientList']), text_scale = PiratesGuiGlobals.TextScaleSmall, image_scale = (0.29999999999999999, 0.10000000000000001, 0.17999999999999999), image_pos = (0, 0, 0), pos = (-0.83999999999999997, 0.0, 0.074999999999999997), parent = self.buttonsBackground, command = self.showInfo) textureCard.removeNode() base.loadingScreen.endStep('init Gui')
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) 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): 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 __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 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) 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,parent,segments,timeOfDay): super(VisualTrackSession, self).__init__() self.parent=parent self.ticks=0 self.cars=[] self.events=[] self.timerDependentObjects=[] self.segments=segments self.createdNodes=[] self.stencilReaders={} self.stencilWriters={} self.carShadowRefreshIndex=0 self.speed=-1 self.lapTimeSeconds=-1 self.lapTimeMilliseconds=-1 self.secondsRemaining=-1 self.topScore=-1 self.correctAspectRatio() base.setBackgroundColor(0.262,0.615,0.054) base.accept('aspectRatioChanged',self.correctAspectRatio ) self.carsAndSceneryNode=render.attachNewNode("CarsAndSceneryNode") self.carsAndSceneryNode.setColorScale(1.0,1.0,1.0,1.0) self.sunEffectsEnabled=False if timeOfDay==TimeOfDay.dusk: self.setBackgroundTexture('textures/mountains4x2blurredblended.png') self.setLightSourcePosition([12000,-800,1200]) self.addSunEffects() else: self.setBackgroundTexture('textures/mountainsx2blurredblended.png') self.setLightSourcePosition([-4000,-1800,2400]) m = loader.loadModel("models/newstartline") m.reparentTo(self.carsAndSceneryNode) m.setPos(self.segments[0].getMidPoint().getX(),self.segments[0].getMidPoint().getY(),0) m.setH(270) self.lights=m self.lightsIlluminated=False for i in range(1,5): self.setStartingLight(i,False) self.createdNodes.append(m) trackGeomNodes=TrackVisualGeometry.makeTrack(self.segments) track=render.attachNewNode(trackGeomNodes['tarmac']) texture=loader.loadTexture("textures/track256.png") texture.setAnisotropicDegree(4) texture.setMagfilter(Texture.FTNearest) texture.setMinfilter(Texture.FTLinearMipmapLinear) texture.setWrapU(Texture.WMRepeat) texture.setWrapV(Texture.WMRepeat) track.setTexture(texture) track.setTwoSided(False) track.setDepthWrite(False) track.setDepthTest(False) track.setBin("background",10) self.createdNodes.append(track) constantTwoStencil = StencilAttrib.make(1,StencilAttrib.SCFEqual,StencilAttrib.SOZero,StencilAttrib.SOKeep,StencilAttrib.SOReplace,2,0,2) track.node().setAttrib(constantTwoStencil) startLine=render.attachNewNode(trackGeomNodes['startline']) texture=loader.loadTexture("textures/startline.png") texture.setAnisotropicDegree(4) texture.setMagfilter(Texture.FTNearest) texture.setMinfilter(Texture.FTLinearMipmapLinear) texture.setWrapU(Texture.WMRepeat) texture.setWrapV(Texture.WMRepeat) startLine.setTexture(texture) startLine.setTwoSided(False) startLine.setDepthWrite(False) startLine.setDepthTest(False) startLine.setBin("background",11); self.createdNodes.append(startLine) backgroundGeomNodes=MountainsGeometry.makeMountains() mountainsGeomNode=backgroundGeomNodes['mountains'] mountains=render.attachNewNode(mountainsGeomNode) texture=loader.loadTexture(self.getBackgroundTexture()) texture.setAnisotropicDegree(4) texture.setWrapU(Texture.WMRepeat) texture.setWrapV(Texture.WMClamp) mountains.setTexture(texture) mountains.setTwoSided(False) mountains.setDepthWrite(False) mountains.setDepthTest(False) mountains.setBin("background",10); self.createdNodes.append(mountains) skyGeomNode=backgroundGeomNodes['sky'] sky=render.attachNewNode(skyGeomNode) sky.setDepthWrite(False) sky.setDepthTest(False) sky.setBin("background",11) self.createdNodes.append(sky) constantOneStencil = StencilAttrib.make(1,StencilAttrib.SCFEqual,StencilAttrib.SOZero,StencilAttrib.SOKeep,StencilAttrib.SOReplace,1,0,1) shadowX=self.segments[0].getMidPoint().getX() shadowY=self.segments[0].getMidPoint().getY() lightSourceX,lightSourceY,lightSourceZ=self.getLightSourcePosition() shadowGeomNode=ShadowGeometry.makeModelShadow("models/newstartlineshadow",shadowX,shadowY,0,lightSourceX,lightSourceY,lightSourceZ,270) shadow=render.attachNewNode(shadowGeomNode) shadow.setTwoSided(True) self.createdNodes.append(shadow) shadow.setPos(shadowX,shadowY,0) shadow.node().setAttrib(constantOneStencil) shadow.node().setAttrib(ColorWriteAttrib.make(0)) shadow.setBin('fixed',40) shadow.setDepthWrite(0) self.createdNodes.append(shadow) stencilReader = StencilAttrib.make(1,StencilAttrib.SCFEqual,StencilAttrib.SOKeep, StencilAttrib.SOKeep,StencilAttrib.SOKeep,1,1,0) cm2d = CardMaker('card') cm2d.setFrameFullscreenQuad() card = render2d.attachNewNode(cm2d.generate()) card.node().setAttrib(stencilReader) card.setDepthTest(False) card.setTransparency(TransparencyAttrib.MAlpha) card.setColor(0,0,0,0.40) self.createdNodes.append(card) trafficLightCm=CardMaker('card') trafficLightCm.setFrame(-0.20,0.20,0.20,-0.20) trafficLight = render.attachNewNode(trafficLightCm.generate()) trafficLight.reparentTo(self.lights) trafficLight.setDepthTest(True) trafficLight.setDepthWrite(False) trafficLight.setColor(1.0,0.0,0.0,1.0) trafficLight.setBin("unsorted",50) trafficLight.setBillboardAxis() trafficLight.setTwoSided(True) tex = loader.loadTexture('textures/roadhighlight.png') trafficLight.setTexture(tex) trafficLight.setTransparency(TransparencyAttrib.MAlpha) trafficLight.hide() self.trafficLight=trafficLight self.createdNodes.append(trafficLight) colour = (45.0/255.0,81.0/255.0,98.0/255.0) expfog = Fog("Scene-wide exponential Fog object") expfog.setColor(*colour) expfog.setExpDensity(0.002) self.carsAndSceneryNode.setFog(expfog) self.qualifyingEndBlimpFlightComplete=False self.qualifyingResultsDisplayComplete=False self.gearIndicator=GearIndicator() self.gearIndicator.setGear(Gearbox.low)
def addSunEffects(self): self.sunEffectsEnabled=True dazzlerCm = CardMaker('card') dazzlerCm.setFrameFullscreenQuad() self.dazzler = render2d.attachNewNode(dazzlerCm.generate()) self.dazzler.setDepthTest(False) self.dazzler.setTransparency(TransparencyAttrib.MAlpha) self.dazzler.setColor(1.0,1.0,1.0,0.0) self.dazzler.setBin("fixed",40) self.createdNodes.append(self.dazzler) sunCm=CardMaker('card') sunCm.setFrame(-500,500,500,-500) sun = render.attachNewNode(sunCm.generate()) sun.setDepthTest(True) sun.setDepthWrite(False) sun.setColor(1.0,0.8,0.4,1.0) sun.setBin("unsorted",50) sunX,sunY,sunZ=self.getLightSourcePosition() sun.setPos(sunX,sunY,sunZ) sun.setBillboardAxis() sun.setTwoSided(True) tex = loader.loadTexture('textures/sun.png') sun.setTexture(tex) sun.setTransparency(TransparencyAttrib.MAlpha) self.createdNodes.append(sun) sunSurroundCm=CardMaker('card') sunSurroundCm.setFrame(-1500,1500,1500,-1500) sunSurround = render.attachNewNode(sunSurroundCm.generate()) sunSurround.setDepthTest(True) sunSurround.setDepthWrite(False) sunSurround.setColor(1.0,1.0,1.0,1.0) sunSurround.setBin("unsorted",50) sunX,sunY,sunZ=self.getLightSourcePosition() sunSurround.setPos(sunX,sunY,sunZ) sunSurround.setBillboardAxis() sunSurround.setTwoSided(True) tex = loader.loadTexture('textures/roadhighlight.png') sunSurround.setTexture(tex) sunSurround.setTransparency(TransparencyAttrib.MAlpha) self.sunSurround=sunSurround self.createdNodes.append(sunSurround) stencilReader2 = StencilAttrib.make(1,StencilAttrib.SCFEqual,StencilAttrib.SOKeep, StencilAttrib.SOKeep,StencilAttrib.SOKeep,2,2,0) roadHighlightCm=CardMaker('card') roadHighlightCm.setFrame(-3000,3000,3000,-3000) roadHighlight = render.attachNewNode(roadHighlightCm.generate()) roadHighlight.setDepthTest(True) roadHighlight.setDepthWrite(False) roadHighlight.setColor(1.0,1.0,1.0,0.4) roadHighlight.setBin("unsorted",50) sunX,sunY,sunZ=self.getLightSourcePosition() roadHighlight.setPos(sunX,sunY,sunZ) roadHighlight.setBillboardAxis() roadHighlight.setTwoSided(True) tex = loader.loadTexture('textures/roadhighlight.png') roadHighlight.setTexture(tex) roadHighlight.setTransparency(TransparencyAttrib.MAlpha) self.createdNodes.append(roadHighlight) roadHighlight.node().setAttrib(stencilReader2)
def __init__(self, manager, xml): self.updateTask = None self.sun = base.cam.attachNewNode('sun') loader.loadModel( manager.get('paths').getConfig().find('misc').get('path') + '/sphere').reparentTo(self.sun) self.sun.setScale(0.1) self.sun.setTwoSided(True) self.sun.setColorScale(10.0, 10.0, 10.0, 1.0, 10001) self.sun.setLightOff(1) self.sun.setShaderOff(1) self.sun.setFogOff(1) self.sun.setCompass() self.sun.setBin('background', 10) self.sun.setDepthWrite(False) self.sun.setDepthTest(False) # Workaround an annoyance in Panda. No idea why it's needed. self.sun.node().setBounds(OmniBoundingVolume()) isa = xml.find('isa') inst = xml.find('instance') if isa != None or inst != None: if inst != None: orig = Vec3(float(inst.get('x', '0')), float(inst.get('y', '0')), float(inst.get('z', '0'))) else: level = manager.get(isa.get('source')) orig = Vec3(level.getByIsA(isa.get('name'))[0].getPos(render)) orig.normalize() self.sun.setPos(orig) godrays = xml.find('godrays') if godrays != None: self.vlbuffer = base.win.makeTextureBuffer('volumetric-lighting', base.win.getXSize() / 2, base.win.getYSize() / 2) self.vlbuffer.setClearColor(Vec4(0, 0, 0, 1)) cam = base.makeCamera(self.vlbuffer) cam.node().setLens(base.camLens) cam.reparentTo(base.cam) initstatenode = NodePath('InitialState') initstatenode.setColorScale(0, 0, 0, 1, 10000) initstatenode.setShaderOff(10000) initstatenode.setLightOff(10000) initstatenode.setMaterialOff(10000) initstatenode.setTransparency(TransparencyAttrib.MBinary, 10000) cam.node().setCameraMask(BitMask32.bit(2)) cam.node().setInitialState(initstatenode.getState()) self.vltexture = self.vlbuffer.getTexture() self.vltexture.setWrapU(Texture.WMClamp) self.vltexture.setWrapV(Texture.WMClamp) card = CardMaker('VolumetricLightingCard') card.setFrameFullscreenQuad() self.finalQuad = render2d.attachNewNode(card.generate()) self.finalQuad.setAttrib( ColorBlendAttrib.make(ColorBlendAttrib.MAdd, ColorBlendAttrib.OIncomingColor, ColorBlendAttrib.OFbufferColor)) self.finalQuad.setShader( Shader.load( posixpath.join( manager.get('paths').getConfig().find('shaders').get( 'path'), 'filter-vlight.cg'))) self.finalQuad.setShaderInput('src', self.vltexture) self.finalQuad.setShaderInput( 'vlparams', 32, 0.9 / 32.0, 0.97, 0.5 ) # Note - first 32 is now hardcoded into shader for cards that don't support variable sized loops. self.finalQuad.setShaderInput('casterpos', 0.5, 0.5, 0, 0) # Last parameter to vlcolor is the exposure vlcolor = Vec4(float(godrays.get('r', '1')), float(godrays.get('g', '1')), float(godrays.get('b', '1')), 0.04) self.finalQuad.setShaderInput('vlcolor', vlcolor) else: self.finalQuad = None
class CameraHandler(): 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 shake(self, amplitude=(1, 0, 0), duration=1.0, swings=1): if self.shakeSequence != None: self.shakeSequence.finish() self.shakeSequence = Sequence() swings = int(swings) duration = float(duration) dt = duration / (swings * 4) ds = Point3(amplitude) for i in range(swings): self.shakeSequence.append(LerpPosInterval(base.camera, dt, ds * -1)) self.shakeSequence.append(LerpPosInterval(base.camera, dt * 2, ds)) self.shakeSequence.append( LerpPosInterval(base.camera, dt, Point3(0, 0, 0))) self.shakeSequence.start() def flash(self, color=(1, 1, 1, 1), duration=1.0, fadeIn=0.2): if self.flashSequence != None: self.flashSequence.finish() self.flashSequence = Sequence() dtIn = float(duration) * fadeIn dtOut = duration - dtIn if dtIn > 0: self.flashSequence.append( LerpColorInterval(self.overlay, dtIn, color)) if dtOut > 0: self.flashSequence.append( LerpColorInterval(self.overlay, dtOut, (0, 0, 0, 0), color)) self.flashSequence.start() def prepareCameraTask(self, task): base.win.movePointer(0, base.win.getXSize() / 2, base.win.getYSize() / 2) base.taskMgr.add(self.controlCameraTask, "camera-control") return task.done def controlCameraTask(self, task): char = self.character.node # Get current mouse location. md = base.win.getPointer(0) x = md.getX() y = md.getY() # Rotate character based on mouse coordinates. if base.win.movePointer(0, base.win.getXSize() / 2, base.win.getYSize() / 2): char.setP( (char.getP() - (y - base.win.getYSize() / 2) * self.mouseSensitivity) % 360) char.setH( (char.getH() - (x - base.win.getXSize() / 2) * self.mouseSensitivity) % 360) # Don't let the camera loop over. Allowed range is 0-90 (up) and 360-270 (down). if char.getP() > 90 and char.getP() < 180: char.setP(90) elif char.getP() < 270 and char.getP() >= 180: char.setP(270) return task.cont
def __init__(self, filters): self.filters = filters self.updateTask = None self.finalQuad = None self.sun = base.cam.attachNewNode('sun') loader.loadModel("models/sphere").reparentTo(self.sun) self.sun.setScale(0.08) self.sun.setTwoSided(True) self.sun.setColorScale(1.0, 1.0, 1.0, 1.0, 10001) self.sun.setLightOff(1) self.sun.setShaderOff(1) self.sun.setFogOff(1) self.sun.setCompass() self.sun.setBin('background', 2) self.sun.setDepthWrite(False) self.sun.setDepthTest(False) # Workaround an annoyance in Panda. No idea why it's needed. self.sun.node().setBounds(OmniBoundingVolume()) direct = Vec4(2.0, 1.9, 1.8, 1) #bright for hdr #direct = Vec4(0.7, 0.65, 0.6, 1) self.dlight = DirectionalLight('dlight') self.dlight.setColor(direct) dlnp = self.sun.attachNewNode(self.dlight) render.setLight(dlnp) render.setShaderInput('dlight0', dlnp) self.setTime(700.0) pandaVolumetricLighting = False if pandaVolumetricLighting: self.filters.setVolumetricLighting( dlnp ) else: self.vlbuffer = base.win.makeTextureBuffer('volumetric-lighting', base.win.getXSize() / 2, base.win.getYSize() / 2) self.vlbuffer.setClearColor(Vec4(0, 0, 0, 1)) cam = base.makeCamera(self.vlbuffer) cam.node().setLens(base.camLens) cam.reparentTo(base.cam) initstatenode = NodePath('InitialState') initstatenode.setColorScale(0, 0, 0, 1, 10000) initstatenode.setShaderOff(10000) initstatenode.setFogOff(1) initstatenode.setLightOff(10000) initstatenode.setMaterialOff(10000) initstatenode.setTransparency(TransparencyAttrib.MBinary, 10000) cam.node().setCameraMask(BitMask32.bit(2)) cam.node().setInitialState(initstatenode.getState()) self.vltexture = self.vlbuffer.getTexture() self.vltexture.setWrapU(Texture.WMClamp) self.vltexture.setWrapV(Texture.WMClamp) card = CardMaker('VolumetricLightingCard') card.setFrameFullscreenQuad() self.finalQuad = render2d.attachNewNode(card.generate()) self.finalQuad.setAttrib(ColorBlendAttrib.make(ColorBlendAttrib.MAdd, ColorBlendAttrib.OIncomingColor, ColorBlendAttrib.OFbufferColor)) self.finalQuad.setShader(Shader.load("shaders/filter-vlight.cg")) self.finalQuad.setShaderInput('src', self.vltexture) self.finalQuad.setShaderInput('vlparams', 32, 0.95 / 32.0, 0.985, 0.5) # Note - first 32 is now hardcoded into shader for cards that don't support variable sized loops. self.finalQuad.setShaderInput('casterpos', 0.5, 0.5, 0, 0) # Last parameter to vlcolor is the exposure vlcolor = Vec4(1, 0.99, 0.80, 0.03) self.finalQuad.setShaderInput('vlcolor', vlcolor) self.start()
def renderSceneInto(self, depthtex=None, colortex=None, auxtex=None, auxbits=0, textures=None): """ Causes the scene to be rendered into the supplied textures instead of into the original window. Puts a fullscreen quad into the original window to show the render-to-texture results. Returns the quad. Normally, the caller would then apply a shader to the quad. To elaborate on how this all works: * An offscreen buffer is created. It is set up to mimic the original display region - it is the same size, uses the same clear colors, and contains a DisplayRegion that uses the original camera. * A fullscreen quad and an orthographic camera to render that quad are both created. The original camera is removed from the original window, and in its place, the orthographic quad-camera is installed. * The fullscreen quad is textured with the data from the offscreen buffer. A shader is applied that tints the results pink. * Automatic shader generation NOT enabled. If you have a filter that depends on a render target from the auto-shader, you either need to set an auto-shader attrib on the main camera or scene, or, you need to provide these outputs in your own shader. * All clears are disabled on the original display region. If the display region fills the whole window, then clears are disabled on the original window as well. It is assumed that rendering the full-screen quad eliminates the need to do clears. Hence, the original window which used to contain the actual scene, now contains a pink-tinted quad with a texture of the scene. It is assumed that the user will replace the shader on the quad with a more interesting filter. """ 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) # Choose the size of the offscreen buffer. (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) # Do we really need to turn on the Shader Generator? #cs.setShaderAuto() 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 renderSceneInto(self, depthtex=None, colortex=None, auxtex=None, auxbits=0, textures=None): """ Causes the scene to be rendered into the supplied textures instead of into the original window. Puts a fullscreen quad into the original window to show the render-to-texture results. Returns the quad. Normally, the caller would then apply a shader to the quad. To elaborate on how this all works: * An offscreen buffer is created. It is set up to mimic the original display region - it is the same size, uses the same clear colors, and contains a DisplayRegion that uses the original camera. * A fullscreen quad and an orthographic camera to render that quad are both created. The original camera is removed from the original window, and in its place, the orthographic quad-camera is installed. * The fullscreen quad is textured with the data from the offscreen buffer. A shader is applied that tints the results pink. * Automatic shader generation NOT enabled. If you have a filter that depends on a render target from the auto-shader, you either need to set an auto-shader attrib on the main camera or scene, or, you need to provide these outputs in your own shader. * All clears are disabled on the original display region. If the display region fills the whole window, then clears are disabled on the original window as well. It is assumed that rendering the full-screen quad eliminates the need to do clears. Hence, the original window which used to contain the actual scene, now contains a pink-tinted quad with a texture of the scene. It is assumed that the user will replace the shader on the quad with a more interesting filter. """ if (textures): colortex = textures.get("color", None) depthtex = textures.get("depth", None) auxtex = textures.get("aux", None) auxtex0 = textures.get("aux0", auxtex) auxtex1 = textures.get("aux1", None) else: auxtex0 = auxtex auxtex1 = None if (colortex == None): colortex = Texture("filter-base-color") colortex.setWrapU(Texture.WMClamp) colortex.setWrapV(Texture.WMClamp) texgroup = (depthtex, colortex, auxtex0, auxtex1) # Choose the size of the offscreen buffer. (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) # Do we really need to turn on the Shader Generator? #cs.setShaderAuto() 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) self.setStackedClears(buffer, self.rclears, self.wclears) if (auxtex0): buffer.setClearActive(GraphicsOutput.RTPAuxRgba0, 1) buffer.setClearValue(GraphicsOutput.RTPAuxRgba0, Vec4(0.5, 0.5, 1.0, 0.0)) if (auxtex1): buffer.setClearActive(GraphicsOutput.RTPAuxRgba1, 1) self.region.disableClears() if (self.isFullscreen()): self.win.disableClears() dr = buffer.makeDisplayRegion() dr.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.updateTask = None self.sun = base.cam.attachNewNode("sun") loader.loadModel(manager.get("paths").getConfig().find("misc").get("path") + "/sphere").reparentTo(self.sun) self.sun.setScale(0.1) self.sun.setTwoSided(True) self.sun.setColorScale(10.0, 10.0, 10.0, 1.0, 10001) self.sun.setLightOff(1) self.sun.setShaderOff(1) self.sun.setFogOff(1) self.sun.setCompass() self.sun.setBin("background", 10) self.sun.setDepthWrite(False) self.sun.setDepthTest(False) # Workaround an annoyance in Panda. No idea why it's needed. self.sun.node().setBounds(OmniBoundingVolume()) isa = xml.find("isa") inst = xml.find("instance") if isa != None or inst != None: if inst != None: orig = Vec3(float(inst.get("x", "0")), float(inst.get("y", "0")), float(inst.get("z", "0"))) else: level = manager.get(isa.get("source")) orig = Vec3(level.getByIsA(isa.get("name"))[0].getPos(render)) orig.normalize() self.sun.setPos(orig) godrays = xml.find("godrays") if godrays != None: self.vlbuffer = base.win.makeTextureBuffer( "volumetric-lighting", base.win.getXSize() / 2, base.win.getYSize() / 2 ) self.vlbuffer.setClearColor(Vec4(0, 0, 0, 1)) cam = base.makeCamera(self.vlbuffer) cam.node().setLens(base.camLens) cam.reparentTo(base.cam) initstatenode = NodePath("InitialState") initstatenode.setColorScale(0, 0, 0, 1, 10000) initstatenode.setShaderOff(10000) initstatenode.setLightOff(10000) initstatenode.setMaterialOff(10000) initstatenode.setTransparency(TransparencyAttrib.MBinary, 10000) cam.node().setCameraMask(BitMask32.bit(2)) cam.node().setInitialState(initstatenode.getState()) self.vltexture = self.vlbuffer.getTexture() self.vltexture.setWrapU(Texture.WMClamp) self.vltexture.setWrapV(Texture.WMClamp) card = CardMaker("VolumetricLightingCard") card.setFrameFullscreenQuad() self.finalQuad = render2d.attachNewNode(card.generate()) self.finalQuad.setAttrib( ColorBlendAttrib.make( ColorBlendAttrib.MAdd, ColorBlendAttrib.OIncomingColor, ColorBlendAttrib.OFbufferColor ) ) self.finalQuad.setShader( Shader.load( posixpath.join(manager.get("paths").getConfig().find("shaders").get("path"), "filter-vlight.cg") ) ) self.finalQuad.setShaderInput("src", self.vltexture) self.finalQuad.setShaderInput( "vlparams", 32, 0.9 / 32.0, 0.97, 0.5 ) # Note - first 32 is now hardcoded into shader for cards that don't support variable sized loops. self.finalQuad.setShaderInput("casterpos", 0.5, 0.5, 0, 0) # Last parameter to vlcolor is the exposure vlcolor = Vec4( float(godrays.get("r", "1")), float(godrays.get("g", "1")), float(godrays.get("b", "1")), 0.04 ) self.finalQuad.setShaderInput("vlcolor", vlcolor) else: self.finalQuad = None
class VideoPlayer: def __init__(self, name, resources): self.log = logging.getLogger('pano.videoPlayer' + name) self.resources = resources self.texCard = None self.texCardNode = None self.videoTex = None self.vidSound = None self.animInterface = None # has the length of a movie in seconds self.totalTime = 0.0 def dispose(self): self._releaseResources() 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 stop(self): if self.animInterface is not None: self.animInterface.stop() def pause(self): if self.animInterface is not None: t = self.animInterface.getTime() self.animInterface.stop() self.animInterface.setTime(t) def hasFinished(self): if self.animInterface is not None: if type(self.animInterface) == AudioSound: return self.animInterface.getTime( ) >= self.animInterface.length() else: return self.totalTime <= self.animInterface.getTime() else: return True def getAnimInterface(self): return self.animInterface def _releaseResources(self): if self.texCardNode is not None: self.texCardNode.removeNode() self.texCard = None self.texCardNode = None self.videoTex = None self.vidSound = None self.animInterface = None self.totalTime = 0.0 def renderToGeom(resources, geom, video, audio): videoTex = loader.loadTexture( resources.getResourceFullPath(PanoConstants.RES_TYPE_VIDEOS, video)) if videoTex is None: print "Couldn't load video %s" % video return None # if (base.sfxManagerList[0].getType().getName() != "OpenALAudioManager"): # self.log.error("OpenAL support is not enabled, cannot proceed.") # return None if (videoTex.getType().getName() != "MovieTexture"): print "MovieTexture support is not enabled, cannot proceed." return None geom.setTexture(videoTex) videoTex.setWrapU(Texture.WMClamp) videoTex.setWrapV(Texture.WMClamp) if videoTex.getTexturesPower2(): geom.setTexScale(TextureStage.getDefault(), videoTex.getTexScale()) if audio is not None: vidSound = loader.loadSfx( resources.getResourceFullPath(PanoConstants.RES_TYPE_MUSIC, audio)) videoTex.synchronizeTo(vidSound) return vidSound else: return videoTex def renderToTexture(resources, video, audio): videoTex = loader.loadTexture( resources.getResourceFullPath(PanoConstants.RES_TYPE_VIDEOS, video)) if videoTex is None: print "Couldn't load video %s" % video return None if (videoTex.getType().getName() != "MovieTexture"): print "MovieTexture support is not enabled, cannot proceed." return None videoTex.setWrapU(Texture.WMClamp) videoTex.setWrapV(Texture.WMClamp) #TODO: Check how I can set the texture scale # if videoTex.getTexturesPower2(): # geom.setTexScale(TextureStage.getDefault(), videoTex.getTexScale()) if audio is not None: vidSound = loader.loadSfx( resources.getResourceFullPath(PanoConstants.RES_TYPE_MUSIC, audio)) videoTex.synchronizeTo(vidSound) return vidSound else: return videoTex renderToGeom = staticmethod(renderToGeom) renderToTexture = staticmethod(renderToTexture)
class CameraHandler(): 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 shake(self, amplitude = (1,0,0), duration = 1.0, swings = 1): if self.shakeSequence != None: self.shakeSequence.finish() self.shakeSequence = Sequence() swings = int(swings) duration = float(duration) dt = duration / (swings * 4) ds = Point3(amplitude) for i in range(swings): self.shakeSequence.append(LerpPosInterval(base.camera, dt, ds*-1)) self.shakeSequence.append(LerpPosInterval(base.camera, dt*2, ds)) self.shakeSequence.append(LerpPosInterval(base.camera, dt, Point3(0, 0, 0))) self.shakeSequence.start() def flash(self, color = (1,1,1,1), duration = 1.0, fadeIn = 0.2): if self.flashSequence != None: self.flashSequence.finish() self.flashSequence = Sequence() dtIn = float(duration) * fadeIn dtOut = duration - dtIn if dtIn > 0: self.flashSequence.append(LerpColorInterval(self.overlay, dtIn, color)) if dtOut > 0: self.flashSequence.append(LerpColorInterval(self.overlay, dtOut, (0,0,0,0), color)) self.flashSequence.start() def prepareCameraTask(self, task): base.win.movePointer(0, base.win.getXSize()/2, base.win.getYSize()/2) base.taskMgr.add(self.controlCameraTask, "camera-control") return task.done def controlCameraTask(self, task): char = self.character.node # Get current mouse location. md = base.win.getPointer(0) x = md.getX() y = md.getY() # Rotate character based on mouse coordinates. if base.win.movePointer(0, base.win.getXSize()/2, base.win.getYSize()/2): char.setP((char.getP() - (y - base.win.getYSize()/2)*self.mouseSensitivity) % 360) char.setH((char.getH() - (x - base.win.getXSize()/2)*self.mouseSensitivity) % 360) # Don't let the camera loop over. Allowed range is 0-90 (up) and 360-270 (down). if char.getP() > 90 and char.getP() < 180: char.setP(90) elif char.getP() < 270 and char.getP() >= 180: char.setP(270) return task.cont