def render(self): LOG.debug("[SkyBox] Rendering") # If we are an orphan use render if self.parent is None: self.parent = render #LOG.debug("[SkyBox] model=%s"%self.modelFile) self.node = loader.loadModel(self.modelFile) #print("tf1 = %s, tf2 = %s"%(self.texture1File,self.texture2File)) if self.texture1File != '' and self.texture2File == '': #LOG.debug("[SkyBox] single texture = %s"%self.texture1File) t = loader.loadTexture(self.texture1File) self.node.setTexture(t) elif self.texture1File != '' and self.texture2File != '': #LOG.debug("[SkyBox] texture staging 1 = %s, 2 = %s"%(self.texture1File,self.texture2File)) t1 = loader.loadTexture(self.texture1File) t1.setWrapU(Texture.WMClamp) t1.setWrapV(Texture.WMClamp) ts1 = TextureStage('Space') ts1.setSort(self.texture1Sort) t2 = loader.loadTexture(self.texture2File) t2.setWrapU(Texture.WMClamp) t2.setWrapV(Texture.WMClamp) ts2 = TextureStage('SpaceClouds') ts2.setSort(self.texture2Sort) self.node.setTexture(ts1, t1) self.node.setTexture(ts2, t2) if self.shaderFile: LOG.debug("[SkyBox] shader = %s"%self.shaderFile) #skyShader = Shader.load("./data/shaders/%s"%self.shaderFile) skyShader = Shader.load("%s"%self.shaderFile) self.node.setShader(skyShader) # Should this be scaled here or done to the model? # It doesn't look like scaling the objects looks any different. self.node.setScale(280) # make sure it's drawn first (this can be done with shaders?) self.node.setBin('background', 0) # dont set depth attribute when rendering the sky (this can be done with shaders?) self.node.setAttrib(DepthWriteAttrib.make(DepthWriteAttrib.MOff)) # We don't want shadows on the skybox self.node.setLightOff() # Render self.node.reparentTo(self.parent) taskMgr.add(self.moveSkyTask, "Move the sky box with the cam")
def render(self): LOG.debug("[SkyBox] Rendering") # If we are an orphan use render if self.parent is None: self.parent = render #LOG.debug("[SkyBox] model=%s"%self.modelFile) self.node = loader.loadModel(self.modelFile) #print("tf1 = %s, tf2 = %s"%(self.texture1File,self.texture2File)) if self.texture1File != '' and self.texture2File == '': #LOG.debug("[SkyBox] single texture = %s"%self.texture1File) t = loader.loadTexture(self.texture1File) self.node.setTexture(t) elif self.texture1File != '' and self.texture2File != '': #LOG.debug("[SkyBox] texture staging 1 = %s, 2 = %s"%(self.texture1File,self.texture2File)) t1 = loader.loadTexture(self.texture1File) t1.setWrapU(Texture.WMClamp) t1.setWrapV(Texture.WMClamp) ts1 = TextureStage('Space') ts1.setSort(self.texture1Sort) t2 = loader.loadTexture(self.texture2File) t2.setWrapU(Texture.WMClamp) t2.setWrapV(Texture.WMClamp) ts2 = TextureStage('SpaceClouds') ts2.setSort(self.texture2Sort) self.node.setTexture(ts1, t1) self.node.setTexture(ts2, t2) if self.shaderFile: LOG.debug("[SkyBox] shader = %s" % self.shaderFile) #skyShader = Shader.load("./data/shaders/%s"%self.shaderFile) skyShader = Shader.load("%s" % self.shaderFile) self.node.setShader(skyShader) # Should this be scaled here or done to the model? # It doesn't look like scaling the objects looks any different. self.node.setScale(280) # make sure it's drawn first (this can be done with shaders?) self.node.setBin('background', 0) # dont set depth attribute when rendering the sky (this can be done with shaders?) self.node.setAttrib(DepthWriteAttrib.make(DepthWriteAttrib.MOff)) # We don't want shadows on the skybox self.node.setLightOff() # Render self.node.reparentTo(self.parent) taskMgr.add(self.moveSkyTask, "Move the sky box with the cam")
def loadAndSetCubeTexture2( self, nodePath1, nodePath2, fileName, textureStageName, texCoordName, sort ): #load texture from file texture = loader.loadCubeMap(fileName) #set texture stage textureStage=TextureStage(textureStageName) textureStage.setTexcoordName(texCoordName) textureStage.setSort(sort) #set texture and texture stage nodePath1.setTexture(textureStage,texture) nodePath2.setTexture(textureStage,texture)
def loadAndSetCubeTexture2(self, nodePath1, nodePath2, fileName, textureStageName, texCoordName, sort): #load texture from file texture = loader.loadCubeMap(fileName) #set texture stage textureStage = TextureStage(textureStageName) textureStage.setTexcoordName(texCoordName) textureStage.setSort(sort) #set texture and texture stage nodePath1.setTexture(textureStage, texture) nodePath2.setTexture(textureStage, texture)
def loadAndSetTexture(self,nodePath,fileName,textureStageName,texCoordName,sort): #load texture from file texture=loader.loadTexture(fileName) texture.setWrapU(Texture.WMClamp) texture.setWrapV(Texture.WMClamp) #set texture stage textureStage=TextureStage(textureStageName) textureStage.setTexcoordName(texCoordName) textureStage.setSort(sort) #set texture and texture stage nodePath.setTexture(textureStage,texture)
def loadAndSetTexture(self, nodePath, fileName, textureStageName, texCoordName, sort): #load texture from file texture = loader.loadTexture(fileName) texture.setWrapU(Texture.WMClamp) texture.setWrapV(Texture.WMClamp) #set texture stage textureStage = TextureStage(textureStageName) textureStage.setTexcoordName(texCoordName) textureStage.setSort(sort) #set texture and texture stage nodePath.setTexture(textureStage, texture)
def makeFadeIn(self, nodePath): # make a fade in of the new objects # our alpha gradient texture transTex = loader.loadTexture("data/textures/transSlider.tif") transTex.setWrapU(Texture.WMClamp) # our texture stage. By default it's set to modulate. # we give it a high sort value since it needs to be # 'above' the rest. ts = TextureStage("alpha") ts.setSort(1000) # apply the texture nodePath.setTexture(ts, transTex) nodePath.setTexScale(ts, Vec2(0)) nodePath.setTransparency(1) self.fadingNodepaths[nodePath] = [time.time(), ts]
def AddNewTextureStage(self, type=Texture.TT2dTexture): """Adds a new texture input to Fragment and returns a two-tuple with the texnum and new TextureStage.""" ts = TextureStage("tex_%d" % self.__curTex) if type == Texture.TT1dTexture: type = "sampler1D" elif type == Texture.TT2dTexture: type = "sampler2D" elif type == Texture.TT3dTexture: type = "sampler2D" elif type == Texture.TTCubeMap: type = "samplerCUBE" if not (isinstance(type, str) and type.startswith("sampler")): raise TypeError, "Unknown texture type %s!" % str(type) self.AddInput("tex_%d" % self.__curTex, "uniform " + type, "TEXUNIT%d" % self.__curTex) self.__curTex += 1 ts.setSort(self.__curTex) return self.__curTex - 1, ts
def Texture(self): """Applies textures and if needed shaders to the terrain. Call this initially, and whenever you have changed the size of some important textures, or added/removed some textures or changed the lighting mode. This function is automatically called by Initialize().""" if self.TextureMap == "": self.TextureMap = None if self.LightMap == "": self.LightMap = None # Does it have a detail map? if len(self.AlphaMaps) > 0: self._textureDetailed() elif self.TextureMap != None: self.Root.setTexture(self.TextureMap, 1) if self.LightMap != None: ts = TextureStage("LightMap") ts.setMode(TextureStage.MModulate) ts.setSort(2) self.Root.setTexture(ts, self.LightMap, 2) elif self.LightMap != None: self.Root.setTexture(ts, self.LightMap, 1)
def Texture(self): """Applies textures and if needed shaders to the terrain. Call this initially, and whenever you have changed the size of some important textures, or added/removed some textures or changed the lighting mode. This function is automatically called by Initialize().""" if self.TextureMap == "": self.TextureMap = None if self.LightMap == "": self.LightMap = None # Does it have a detail map? if len(self.AlphaMaps) > 0: self._textureDetailed() elif self.TextureMap != None: self.Root.setTexture(self.TextureMap, 1) if self.LightMap != None: ts = TextureStage("LightMap") ts.setMode(TextureStage.MModulate) ts.setSort(2) self.Root.setTexture(ts, self.LightMap, 2) elif self.LightMap != None: self.Root.setTexture(ts, self.LightMap, 1)
def __init__(self, panda3d): # Inicialización de variables self.winsize = [0, 0] self.panda3d = panda3d sha_normal = "data/shaders/normalGen.sha" sha_depth = "data/shaders/depthGen.sha" sha_color = "data/shaders/colorGen.sha" sha_ink = "data/shaders/inkGen.sha" self.normal_buff, self.normal_cam = self.make_buffer( "normalsBuffer", sha_normal, 0.5) # self.depth_buff, self.depth_cam = self.make_buffer("depthBuffer", sha_depth, 0.5) self.color_buff, self.color_cam = self.make_buffer( "colorsBuffer", sha_color, 0.5) tex_normal = self.normal_buff.getTextureCard() # tex_depth = self.depth_buff.getTextureCard() tex_color = self.color_buff.getTextureCard() tex_normal.setTransparency(1) tex_normal.setColor(1, 1, 1, 1) tex_normal.reparentTo(self.panda3d.render2d) stage_border = TextureStage("border") stage_border.setSort(1) # tex_normal.setTexture(stage_border, tex_color.getTexture()) # stage_depth = TextureStage("depth") # stage_depth.setSort(2) # tex_normal.setTexture(stage_depth, tex_depth.getTexture()) shader_ink = self.panda3d.loader.loadShader(sha_ink) #tex_normal.setShader(shader_ink) width = self.panda3d.win.getXSize() height = self.panda3d.win.getYSize() tex_normal.setShaderInput("screen", width, height) self.tex_normal = tex_normal
class ShipFactory: notify = DirectNotifyGlobal.directNotify.newCategory("ShipFactory") def __init__(self, phasedLoading=False): self.wantProws = config.GetBool("want-sprits", 0) self.hulls = {} self.texInfo = ({}, {}, {}) self.models = {} self.mastSets = {} ShipBlueprints.setupWheel() ShipBlueprints.setupShipTextures() self.preprocessMast(ShipGlobals.Masts.Main_Tri) self.preprocessMast(ShipGlobals.Masts.Fore_Tri) self.preprocessHull(ShipGlobals.INTERCEPTORL1) self.preprocessMast(ShipGlobals.Masts.Skel_Main_A) self.preprocessMast(ShipGlobals.Masts.Skel_Main_B) self.preprocessMast(ShipGlobals.Masts.Skel_Tri) self.preprocessMast(ShipGlobals.Masts.Skel_Fore) self.preprocessMast(ShipGlobals.Masts.Skel_Aft) self.preprocessHull(ShipGlobals.SKEL_INTERCEPTORL3) self.preprocessHull(ShipGlobals.SKEL_WARSHIPL3) if not phasedLoading: self.handlePhase4() self.handlePhase5() self.baseLayer = TextureStage("base") self.colorLayer = TextureStage("color") self.logoLayer = TextureStage("logo") self.logoLayerNoColor = TextureStage("logoNoColor") self.vertLayer = TextureStage("vertex") self.colorLayer.setSort(1) self.colorLayer.setCombineRgb(TextureStage.CMReplace, TextureStage.CSTexture, TextureStage.COSrcColor) self.colorLayer.setCombineAlpha(TextureStage.CMReplace, TextureStage.CSTexture, TextureStage.COSrcAlpha) self.colorLayer.setTexcoordName("uvColor") self.logoLayer.setSort(2) self.logoLayer.setCombineRgb( TextureStage.CMInterpolate, TextureStage.CSTexture, TextureStage.COSrcColor, TextureStage.CSPrevious, TextureStage.COSrcColor, TextureStage.CSTexture, TextureStage.COSrcAlpha, ) self.logoLayer.setCombineAlpha(TextureStage.CMReplace, TextureStage.CSPrevious, TextureStage.COSrcAlpha) self.logoLayer.setTexcoordName("uvLogo") self.logoLayerNoColor.setSort(2) self.logoLayerNoColor.setCombineRgb( TextureStage.CMInterpolate, TextureStage.CSTexture, TextureStage.COSrcColor, TextureStage.CSConstant, TextureStage.COSrcColor, TextureStage.CSTexture, TextureStage.COSrcAlpha, ) self.logoLayerNoColor.setCombineAlpha(TextureStage.CMReplace, TextureStage.CSPrevious, TextureStage.COSrcAlpha) self.logoLayerNoColor.setTexcoordName("uvLogo") self.logoLayerNoColor.setColor((1, 1, 1, 1)) self.vertLayer.setSort(3) self.vertLayer.setCombineRgb( TextureStage.CMModulate, TextureStage.CSPrevious, TextureStage.COSrcColor, TextureStage.CSPrimaryColor, TextureStage.COSrcColor, ) self.vertLayer.setCombineAlpha(TextureStage.CMReplace, TextureStage.CSPrimaryColor, TextureStage.COSrcAlpha) self.baseLayer.setSort(4) self.baseLayer.setCombineRgb( TextureStage.CMModulate, TextureStage.CSTexture, TextureStage.COSrcColor, TextureStage.CSPrevious, TextureStage.COSrcColor, ) self.baseLayer.setCombineAlpha( TextureStage.CMModulate, TextureStage.CSTexture, TextureStage.COSrcAlpha, TextureStage.CSPrevious, TextureStage.COSrcAlpha, ) def handlePhase4(self): self.preprocessHull(ShipGlobals.INTERCEPTORL2) self.preprocessHull(ShipGlobals.INTERCEPTORL3) self.preprocessMast(ShipGlobals.Masts.Main_Square) self.preprocessMast(ShipGlobals.Masts.Aft_Tri) self.preprocessMast(ShipGlobals.Masts.Fore_Multi) self.preprocessHull(ShipGlobals.WARSHIPL1) self.preprocessHull(ShipGlobals.WARSHIPL2) self.preprocessHull(ShipGlobals.WARSHIPL3) self.preprocessHull(ShipGlobals.MERCHANTL1) self.preprocessHull(ShipGlobals.MERCHANTL2) self.preprocessHull(ShipGlobals.MERCHANTL3) self.preprocessHull(ShipGlobals.QUEEN_ANNES_REVENGE) self.sprits = ShipBlueprints.preprocessSprits() def handlePhase5(self): self.preprocessHull(ShipGlobals.BLACK_PEARL) self.preprocessHull(ShipGlobals.GOLIATH) self.preprocessHull(ShipGlobals.SHIP_OF_THE_LINE) def preprocessMast(self, mastClass): self.mastSets[mastClass] = ShipBlueprints.generateMastCache(mastClass) def preprocessHull(self, modelClass): self.hulls[modelClass] = ShipBlueprints.generateHullCache(modelClass) def getHull(self, modelClass, custom): return self.hulls[modelClass].getHullAsset(custom) def getShip( self, shipClass, style=ShipGlobals.Styles.Undefined, logo=ShipGlobals.Logos.Undefined, hullDesign=None, detailLevel=2, wantWheel=True, hullMaterial=None, sailMaterial=None, sailPattern=None, prowType=None, ): Ship = Ship import pirates.ship modelClass = ShipGlobals.getModelClass(shipClass) shipConfig = ShipGlobals.getShipConfig(shipClass) if style == ShipGlobals.Styles.Undefined: style = shipConfig["defaultStyle"] complexCustomization = 0 if sailPattern and sailMaterial and hullMaterial or SailReplace.has_key(shipClass): complexCustomization = 1 if not prowType: prowType = shipConfig["prow"] if not hullMaterial: hullMaterial = style if not sailMaterial: if SailReplace.has_key(shipClass): sailMaterial = SailReplace[shipClass] else: sailMaterial = style if not sailPattern: sailPattern = style shipHullTexture = ShipBlueprints.getShipTexture(hullMaterial) shipTextureSail = ShipBlueprints.getShipTexture(sailMaterial) logoTex = None if logo: logoTex = ShipBlueprints.getLogoTexture(logo) sailPatternTex = None if sailPattern: sailPatternTex = ShipBlueprints.getSailTexture(sailPattern) self.notify.debug("%s %s" % (sailPattern, logo)) if logo == ShipGlobals.Logos.Undefined: logo = shipConfig["sailLogo"] if logo in ShipGlobals.MAST_LOGO_PLACEMENT_LIST: placeLogos = 1 else: placeLogos = 0 if modelClass <= ShipGlobals.INTERCEPTORL3: mastHax = True else: mastHax = False customHull = hullDesign is not None if not logo != 0: pass customMasts = sailPattern != 0 hull = self.getHull(modelClass, customHull) breakAnims = {} metaAnims = {} hitAnims = {} root = NodePath("Ship") hull.locators.reparentTo(root) charRoot = root.attachNewNode(Character("ShipChar")) collisions = root.attachNewNode("collisions") lodNode = charRoot.attachNewNode(LODNode("lod")) if detailLevel == 0: lodNode.node().addSwitch(200, 0) lodNode.node().addSwitch(800, 200) lodNode.node().addSwitch(100000, 800) high = lodNode.attachNewNode("high") low = lodNode.attachNewNode("low") med = NodePath("med") superlow = lodNode.attachNewNode("superlow") elif detailLevel == 1: lodNode.node().addSwitch(300, 0) lodNode.node().addSwitch(1000, 300) lodNode.node().addSwitch(2000, 1000) lodNode.node().addSwitch(100000, 2000) high = lodNode.attachNewNode("high") med = lodNode.attachNewNode("med") low = lodNode.attachNewNode("low") superlow = lodNode.attachNewNode("superlow") else: lodNode.node().addSwitch(750, 0) lodNode.node().addSwitch(3000, 750) lodNode.node().addSwitch(8000, 3000) lodNode.node().addSwitch(100000, 8000) high = lodNode.attachNewNode("high") med = lodNode.attachNewNode("med") low = lodNode.attachNewNode("low") superlow = lodNode.attachNewNode("superlow") mastSetup = ShipGlobals.getMastSetup(shipClass) for data in [ (0, "location_mainmast_0"), (1, "location_mainmast_1"), (2, "location_mainmast_2"), (3, "location_aftmast*"), (4, "location_foremast*"), ]: mastData = mastSetup.get(data[0]) if mastData: mast = self.mastSets[mastData[0]].getMastSet(mastData[1] - 1, customMasts) mastRoot = hull.locators.find("**/%s" % data[1]).getTransform(hull.locators) model = NodePath(mast.charRoot) model.setTransform(mastRoot) if complexCustomization: model.setTexture(shipTextureSail) useLogoTex = logoTex if placeLogos: mastNum = data[0] if mastNum not in ShipGlobals.MAST_LOGO_PLACEMENT.get(modelClass): useLogoTex = None charBundle = mast.charRoot.getBundle(0) if data[0] < 3: for side in ["left", "right"]: ropeNode = hull.locators.find("**/location_ropeLadder_%s_%s" % (side, data[0])) if ropeNode: transform = ropeNode.getTransform(NodePath(mast.charRoot)) charBundle.findChild("def_ladder_0_%s" % side).applyFreeze(transform) continue if sailPatternTex and useLogoTex: for node in model.findAllMatches("**/sails"): node.setTextureOff(TextureStage.getDefault()) node.setTexture(self.colorLayer, sailPatternTex) node.setTexture(self.logoLayer, logoTex) node.setTexture(self.vertLayer, shipTextureSail) node.setTexture(self.baseLayer, shipTextureSail) elif sailPatternTex: for node in model.findAllMatches("**/sails"): node.setTextureOff(TextureStage.getDefault()) node.setTexture(self.colorLayer, sailPatternTex) node.setTexture(self.vertLayer, shipTextureSail) node.setTexture(self.baseLayer, shipTextureSail) elif useLogoTex: for node in model.findAllMatches("**/sails"): node.setTextureOff(TextureStage.getDefault()) node.setTexture(self.logoLayerNoColor, logoTex) node.setTexture(self.vertLayer, shipTextureSail) node.setTexture(self.baseLayer, shipTextureSail) model.flattenLight() if detailLevel == 0: model.find("**/low").copyTo(high) model.find("**/low").copyTo(low) model.find("**/superlow").copyTo(superlow) elif detailLevel == 1: model.find("**/med").copyTo(high) model.find("**/med").copyTo(med) low.node().stealChildren(model.find("**/low").node()) superlow.node().stealChildren(model.find("**/superlow").node()) elif detailLevel == 2: high.node().stealChildren(model.find("**/high").node()) med.node().stealChildren(model.find("**/med").node()) low.node().stealChildren(model.find("**/low").node()) superlow.node().stealChildren(model.find("**/superlow").node()) mastRoot = mast.collisions.find("**/collision_masts") if modelClass > ShipGlobals.INTERCEPTORL3 or data[0] != 3: mastCode = str(data[0]) mastRoot.setTag("Mast Code", mastCode) else: mastRoot.setName("colldision_sub_mast") mastRoot.reparentTo(collisions.find("**/collision_masts")) mastCode = "0" for coll in mast.collisions.findAllMatches("**/collision_sail_*"): coll.setName("Sail-%s" % data[0]) coll.setTag("Mast Code", mastCode) for coll in mast.collisions.findAllMatches("**/sail_*"): coll.setName("Sail-%s" % data[0]) coll.setTag("Mast Code", mastCode) collisions.node().stealChildren(mast.collisions.node()) charBundle = mast.charRoot.getBundle(0) if mastHax and data[0] == 3: breakAnims[0][0].storeAnim( charBundle.loadBindAnim(loader.loader, mast.breakAnim[0], -1, MastSubset, True), "1" ) breakAnims[0][1].storeAnim( charBundle.loadBindAnim(loader.loader, mast.breakAnim[1], -1, MastSubset, True), "1" ) tempHit = hitAnims[0] tempHit[0].storeAnim( charBundle.loadBindAnim(loader.loader, mast.hitAnim, -1, HitMastSubset, True), "1" ) tempHit[1].storeAnim( charBundle.loadBindAnim(loader.loader, mast.hitAnim, -1, PartSubset(), True), "1" ) else: breakAnims[data[0]] = (AnimControlCollection(), AnimControlCollection()) breakAnims[data[0]][0].storeAnim( charBundle.loadBindAnim(loader.loader, mast.breakAnim[0], -1, MastSubset, True), "0" ) breakAnims[data[0]][1].storeAnim( charBundle.loadBindAnim(loader.loader, mast.breakAnim[1], -1, MastSubset, True), "0" ) tempHit = [AnimControlCollection(), AnimControlCollection()] tempHit[0].storeAnim( charBundle.loadBindAnim(loader.loader, mast.hitAnim, -1, HitMastSubset, True), "0" ) tempHit[1].storeAnim( charBundle.loadBindAnim(loader.loader, mast.hitAnim, -1, PartSubset(), True), "0" ) hitAnims[data[0]] = tempHit for (anim, fileName) in mast.metaAnims.iteritems(): if anim not in metaAnims: metaAnims[anim] = AnimControlCollection() if anim not in MissingAnims.get(modelClass, []): ac = charBundle.loadBindAnim(loader.loader, fileName, -1, SailSubset, True) if ac: metaAnims[anim].storeAnim(ac, str(metaAnims[anim].getNumAnims())) charRoot.node().combineWith(mast.charRoot) continue if self.wantProws and prowType: (highSprit, medSprit, lowSprit) = self.sprits[prowType].getAsset() transform = hull.locators.find("**/location_bowsprit").getTransform(hull.locators) highSprit.setTransform(transform) medSprit.setTransform(transform) lowSprit.setTransform(transform) highSprit.reparentTo(hull.geoms[0]) medSprit.reparentTo(hull.geoms[1]) lowSprit.reparentTo(hull.geoms[2]) if wantWheel: shipWheel = ShipBlueprints.getWheel() wheelPoint = hull.locators.find("**/location_wheel;+s").getTransform(hull.locators) shipWheel.setTransform(wheelPoint) shipWheel.flattenLight() shipWheel.find("**/collisions").copyTo(collisions) hull.geoms[0].node().stealChildren(shipWheel.find("**/high").node()) hull.geoms[1].node().stealChildren(shipWheel.find("**/med").node()) hull.geoms[2].node().stealChildren(shipWheel.find("**/low").node()) if complexCustomization: hull.geoms[0].setTexture(shipHullTexture) hull.geoms[0].flattenLight() hull.geoms[1].setTexture(shipHullTexture) hull.geoms[1].flattenLight() hull.geoms[2].setTexture(shipHullTexture) hull.geoms[2].flattenLight() hull.geoms[3].setTexture(shipHullTexture) hull.geoms[3].flattenLight() high.attachNewNode(ModelNode("non-animated")).node().stealChildren(hull.geoms[0].node()) med.attachNewNode(ModelNode("non-animated")).node().stealChildren(hull.geoms[1].node()) low.attachNewNode(ModelNode("non-animated")).node().stealChildren(hull.geoms[2].node()) superlow.attachNewNode(ModelNode("non-animated")).node().stealChildren(hull.geoms[3].node()) collisions.node().stealChildren(hull.collisions.node()) hull.locators.stash() charRoot.flattenStrong() ship = Ship.Ship(shipClass, root, breakAnims, hitAnims, metaAnims, collisions, hull.locators) if not complexCustomization: ship.char.setTexture(shipHullTexture) return ship def getAIShip(self, shipClass): ShipAI = ShipAI import pirates.ship modelClass = ShipGlobals.getModelClass(shipClass) hull = self.getHull(modelClass, 0) root = NodePath("Ship") collisions = root.attachNewNode("collisions") mastSetup = ShipGlobals.getMastSetup(shipClass) for data in [ (0, "location_mainmast_0"), (1, "location_mainmast_1"), (2, "location_mainmast_2"), (3, "location_aftmast*"), (4, "location_foremast*"), ]: mastData = mastSetup.get(data[0]) if mastData: mast = self.mastSets[mastData[0]].getMastSet(mastData[1] - 1) model = NodePath(mast.charRoot) model.setPos(hull.locators.find("**/%s" % data[1]).getPos(hull.locators)) model.setHpr(hull.locators.find("**/%s" % data[1]).getHpr(hull.locators)) model.setScale(hull.locators.find("**/%s" % data[1]).getScale(hull.locators)) if modelClass > ShipGlobals.INTERCEPTORL3 or data[0] != 3: mastCode = str(data[0]) else: mastCode = "0" mast.collisions.find("**/collision_masts").setTag("Mast Code", mastCode) collisions.node().stealChildren(mast.collisions.node()) continue collisions.node().stealChildren(hull.collisions.node()) hull.locators.reparentTo(root) ship = ShipAI.ShipAI(root, collisions, hull.locators) ship.modelRoot.setTag("Mast Code", str(255)) ship.modelRoot.setTag("Hull Code", str(255)) return ship
class ShipFactory: notify = DirectNotifyGlobal.directNotify.newCategory('ShipFactory') def __init__(self, phasedLoading=False): self.wantProws = config.GetBool('want-sprits', 0) self.hulls = {} self.texInfo = ({}, {}, {}) self.models = {} self.mastSets = {} ShipBlueprints.setupWheel() ShipBlueprints.setupShipTextures() self.preprocessMast(ShipGlobals.Masts.Main_Tri) self.preprocessMast(ShipGlobals.Masts.Fore_Tri) self.preprocessHull(ShipGlobals.INTERCEPTORL1) self.preprocessMast(ShipGlobals.Masts.Skel_Main_A) self.preprocessMast(ShipGlobals.Masts.Skel_Main_B) self.preprocessMast(ShipGlobals.Masts.Skel_Tri) self.preprocessMast(ShipGlobals.Masts.Skel_Fore) self.preprocessMast(ShipGlobals.Masts.Skel_Aft) self.preprocessHull(ShipGlobals.SKEL_INTERCEPTORL3) self.preprocessHull(ShipGlobals.SKEL_WARSHIPL3) if not phasedLoading: self.handlePhase4() self.handlePhase5() self.baseLayer = TextureStage('base') self.colorLayer = TextureStage('color') self.logoLayer = TextureStage('logo') self.logoLayerNoColor = TextureStage('logoNoColor') self.logoLayerNoColorInv = TextureStage('logoNoColorInverse') self.logoLayerInv = TextureStage('logoInverse') self.vertLayer = TextureStage('vertex') self.colorLayer.setSort(1) self.colorLayer.setCombineRgb(TextureStage.CMReplace, TextureStage.CSTexture, TextureStage.COSrcColor) self.colorLayer.setCombineAlpha(TextureStage.CMReplace, TextureStage.CSTexture, TextureStage.COSrcAlpha) self.colorLayer.setTexcoordName('uvColor') self.logoLayer.setSort(2) self.logoLayer.setCombineRgb( TextureStage.CMInterpolate, TextureStage.CSTexture, TextureStage.COSrcColor, TextureStage.CSPrevious, TextureStage.COSrcColor, TextureStage.CSTexture, TextureStage.COSrcAlpha) self.logoLayer.setCombineAlpha(TextureStage.CMReplace, TextureStage.CSPrevious, TextureStage.COSrcAlpha) self.logoLayer.setTexcoordName('uvLogo') self.logoLayerInv.setSort(2) self.logoLayerInv.setCombineRgb( TextureStage.CMInterpolate, TextureStage.CSTexture, TextureStage.COOneMinusSrcColor, TextureStage.CSPrevious, TextureStage.COSrcColor, TextureStage.CSTexture, TextureStage.COSrcAlpha) self.logoLayerInv.setCombineAlpha(TextureStage.CMReplace, TextureStage.CSPrevious, TextureStage.COSrcAlpha) self.logoLayerInv.setTexcoordName('uvLogo') self.logoLayerNoColor.setSort(2) self.logoLayerNoColor.setCombineRgb( TextureStage.CMInterpolate, TextureStage.CSTexture, TextureStage.COSrcColor, TextureStage.CSConstant, TextureStage.COSrcColor, TextureStage.CSTexture, TextureStage.COSrcAlpha) self.logoLayerNoColor.setCombineAlpha(TextureStage.CMReplace, TextureStage.CSPrevious, TextureStage.COSrcAlpha) self.logoLayerNoColor.setTexcoordName('uvLogo') self.logoLayerNoColor.setColor((1, 1, 1, 1)) self.logoLayerNoColorInv.setSort(2) self.logoLayerNoColorInv.setCombineRgb( TextureStage.CMInterpolate, TextureStage.CSTexture, TextureStage.COOneMinusSrcColor, TextureStage.CSConstant, TextureStage.COSrcColor, TextureStage.CSTexture, TextureStage.COSrcAlpha) self.logoLayerNoColorInv.setCombineAlpha(TextureStage.CMReplace, TextureStage.CSPrevious, TextureStage.COSrcAlpha) self.logoLayerNoColorInv.setTexcoordName('uvLogo') self.logoLayerNoColorInv.setColor((1, 1, 1, 1)) self.vertLayer.setSort(3) self.vertLayer.setCombineRgb(TextureStage.CMModulate, TextureStage.CSPrevious, TextureStage.COSrcColor, TextureStage.CSPrimaryColor, TextureStage.COSrcColor) self.vertLayer.setCombineAlpha(TextureStage.CMReplace, TextureStage.CSPrimaryColor, TextureStage.COSrcAlpha) self.baseLayer.setSort(4) self.baseLayer.setCombineRgb(TextureStage.CMModulate, TextureStage.CSTexture, TextureStage.COSrcColor, TextureStage.CSPrevious, TextureStage.COSrcColor) self.baseLayer.setCombineAlpha(TextureStage.CMModulate, TextureStage.CSTexture, TextureStage.COSrcAlpha, TextureStage.CSPrevious, TextureStage.COSrcAlpha) def handlePhase4(self): self.preprocessHull(ShipGlobals.INTERCEPTORL2) self.preprocessHull(ShipGlobals.INTERCEPTORL3) self.preprocessMast(ShipGlobals.Masts.Main_Square) self.preprocessMast(ShipGlobals.Masts.Aft_Tri) self.preprocessMast(ShipGlobals.Masts.Fore_Multi) self.preprocessHull(ShipGlobals.WARSHIPL1) self.preprocessHull(ShipGlobals.WARSHIPL2) self.preprocessHull(ShipGlobals.WARSHIPL3) self.preprocessHull(ShipGlobals.MERCHANTL1) self.preprocessHull(ShipGlobals.MERCHANTL2) self.preprocessHull(ShipGlobals.MERCHANTL3) self.preprocessHull(ShipGlobals.BRIGL1) self.preprocessHull(ShipGlobals.BRIGL2) self.preprocessHull(ShipGlobals.BRIGL3) self.preprocessHull(ShipGlobals.QUEEN_ANNES_REVENGE) self.sprits = ShipBlueprints.preprocessSprits() def handlePhase5(self): self.preprocessHull(ShipGlobals.BLACK_PEARL) self.preprocessHull(ShipGlobals.GOLIATH) self.preprocessHull(ShipGlobals.SHIP_OF_THE_LINE) def preprocessMast(self, mastClass): self.mastSets[mastClass] = ShipBlueprints.generateMastCache(mastClass) def preprocessHull(self, modelClass): self.hulls[modelClass] = ShipBlueprints.generateHullCache(modelClass) def getHull(self, modelClass, custom): return self.hulls[modelClass].getHullAsset(custom) def getShip(self, shipClass, style=ShipGlobals.Styles.Undefined, logo=ShipGlobals.Logos.Undefined, hullDesign=None, detailLevel=2, wantWheel=True, hullMaterial=None, sailMaterial=None, sailPattern=None, prowType=None, invertLogo=False): Ship = Ship import pirates.ship modelClass = ShipGlobals.getModelClass(shipClass) shipConfig = ShipGlobals.getShipConfig(shipClass) if style == ShipGlobals.Styles.Undefined: style = shipConfig['defaultStyle'] complexCustomization = 0 if sailPattern and sailMaterial and hullMaterial or SailReplace.has_key( shipClass): complexCustomization = 1 if not prowType: prowType = shipConfig['prow'] if not hullMaterial: hullMaterial = style if not sailMaterial: if SailReplace.has_key(shipClass): sailMaterial = SailReplace[shipClass] else: sailMaterial = style if not sailPattern: sailPattern = style shipHullTexture = ShipBlueprints.getShipTexture(hullMaterial) shipTextureSail = ShipBlueprints.getShipTexture(sailMaterial) logoTex = None if logo: logoTex = ShipBlueprints.getLogoTexture(logo) sailPatternTex = None if sailPattern: sailPatternTex = ShipBlueprints.getSailTexture(sailPattern) self.notify.debug('%s %s' % (sailPattern, logo)) if logo == ShipGlobals.Logos.Undefined: logo = shipConfig['sailLogo'] if logo in ShipGlobals.MAST_LOGO_PLACEMENT_LIST: placeLogos = 1 else: placeLogos = 0 if modelClass <= ShipGlobals.INTERCEPTORL3: mastHax = True else: mastHax = False customHull = hullDesign is not None if not logo != 0: pass customMasts = sailPattern != 0 hull = self.getHull(modelClass, customHull) breakAnims = {} metaAnims = {} hitAnims = {} root = NodePath('Ship') hull.locators.reparentTo(root) charRoot = root.attachNewNode(Character('ShipChar')) collisions = root.attachNewNode('collisions') lodNode = charRoot.attachNewNode(LODNode('lod')) if detailLevel == 0: lodNode.node().addSwitch(200, 0) lodNode.node().addSwitch(800, 200) lodNode.node().addSwitch(100000, 800) high = lodNode.attachNewNode('high') low = lodNode.attachNewNode('low') med = NodePath('med') superlow = lodNode.attachNewNode('superlow') elif detailLevel == 1: lodNode.node().addSwitch(300, 0) lodNode.node().addSwitch(1000, 300) lodNode.node().addSwitch(2000, 1000) lodNode.node().addSwitch(100000, 2000) high = lodNode.attachNewNode('high') med = lodNode.attachNewNode('med') low = lodNode.attachNewNode('low') superlow = lodNode.attachNewNode('superlow') else: lodNode.node().addSwitch(750, 0) lodNode.node().addSwitch(3000, 750) lodNode.node().addSwitch(8000, 3000) lodNode.node().addSwitch(100000, 8000) high = lodNode.attachNewNode('high') med = lodNode.attachNewNode('med') low = lodNode.attachNewNode('low') superlow = lodNode.attachNewNode('superlow') mastSetup = ShipGlobals.getMastSetup(shipClass) for data in [(0, 'location_mainmast_0'), (1, 'location_mainmast_1'), (2, 'location_mainmast_2'), (3, 'location_aftmast*'), (4, 'location_foremast*')]: mastData = mastSetup.get(data[0]) if mastData: mast = self.mastSets[mastData[0]].getMastSet( mastData[1] - 1, customMasts) mastRoot = hull.locators.find('**/%s' % data[1]).getTransform( hull.locators) model = NodePath(mast.charRoot) model.setTransform(mastRoot) if complexCustomization: model.setTexture(shipTextureSail) useLogoTex = logoTex if placeLogos: mastNum = data[0] if mastNum not in ShipGlobals.MAST_LOGO_PLACEMENT.get( modelClass): useLogoTex = None charBundle = mast.charRoot.getBundle(0) if data[0] < 3: for side in ['left', 'right']: ropeNode = hull.locators.find( '**/location_ropeLadder_%s_%s' % (side, data[0])) if ropeNode: transform = ropeNode.getTransform( NodePath(mast.charRoot)) charBundle.findChild('def_ladder_0_%s' % side).applyFreeze(transform) continue if sailPatternTex and useLogoTex: for node in model.findAllMatches('**/sails'): node.setTextureOff(TextureStage.getDefault()) node.setTexture(self.colorLayer, sailPatternTex) if invertLogo: node.setTexture(self.logoLayerInv, logoTex) else: node.setTexture(self.logoLayer, logoTex) node.setTexture(self.vertLayer, shipTextureSail) node.setTexture(self.baseLayer, shipTextureSail) elif sailPatternTex: for node in model.findAllMatches('**/sails'): node.setTextureOff(TextureStage.getDefault()) node.setTexture(self.colorLayer, sailPatternTex) node.setTexture(self.vertLayer, shipTextureSail) node.setTexture(self.baseLayer, shipTextureSail) elif useLogoTex: for node in model.findAllMatches('**/sails'): node.setTextureOff(TextureStage.getDefault()) if invertLogo: node.setTexture(self.logoLayerNoColorInv, logoTex) else: node.setTexture(self.logoLayerNoColor, logoTex) node.setTexture(self.vertLayer, shipTextureSail) node.setTexture(self.baseLayer, shipTextureSail) model.flattenLight() if detailLevel == 0: model.find('**/low').copyTo(high) model.find('**/low').copyTo(low) model.find('**/superlow').copyTo(superlow) elif detailLevel == 1: model.find('**/med').copyTo(high) model.find('**/med').copyTo(med) low.node().stealChildren(model.find('**/low').node()) superlow.node().stealChildren( model.find('**/superlow').node()) elif detailLevel == 2: high.node().stealChildren(model.find('**/high').node()) med.node().stealChildren(model.find('**/med').node()) low.node().stealChildren(model.find('**/low').node()) superlow.node().stealChildren( model.find('**/superlow').node()) mastRoot = mast.collisions.find('**/collision_masts') if modelClass > ShipGlobals.INTERCEPTORL3 or data[0] != 3: mastCode = str(data[0]) mastRoot.setTag('Mast Code', mastCode) else: mastRoot.setName('colldision_sub_mast') mastRoot.reparentTo(collisions.find('**/collision_masts')) mastCode = '0' for coll in mast.collisions.findAllMatches( '**/collision_sail_*'): coll.setName('Sail-%s' % data[0]) coll.setTag('Mast Code', mastCode) for coll in mast.collisions.findAllMatches('**/sail_*'): coll.setName('Sail-%s' % data[0]) coll.setTag('Mast Code', mastCode) collisions.node().stealChildren(mast.collisions.node()) charBundle = mast.charRoot.getBundle(0) if mastHax and data[0] == 3: breakAnims[0][0].storeAnim( charBundle.loadBindAnim(loader.loader, mast.breakAnim[0], -1, MastSubset, True), '1') breakAnims[0][1].storeAnim( charBundle.loadBindAnim(loader.loader, mast.breakAnim[1], -1, MastSubset, True), '1') tempHit = hitAnims[0] tempHit[0].storeAnim( charBundle.loadBindAnim(loader.loader, mast.hitAnim, -1, HitMastSubset, True), '1') tempHit[1].storeAnim( charBundle.loadBindAnim(loader.loader, mast.hitAnim, -1, PartSubset(), True), '1') else: breakAnims[data[0]] = (AnimControlCollection(), AnimControlCollection()) breakAnims[data[0]][0].storeAnim( charBundle.loadBindAnim(loader.loader, mast.breakAnim[0], -1, MastSubset, True), '0') breakAnims[data[0]][1].storeAnim( charBundle.loadBindAnim(loader.loader, mast.breakAnim[1], -1, MastSubset, True), '0') tempHit = [ AnimControlCollection(), AnimControlCollection() ] tempHit[0].storeAnim( charBundle.loadBindAnim(loader.loader, mast.hitAnim, -1, HitMastSubset, True), '0') tempHit[1].storeAnim( charBundle.loadBindAnim(loader.loader, mast.hitAnim, -1, PartSubset(), True), '0') hitAnims[data[0]] = tempHit for (anim, fileName) in mast.metaAnims.iteritems(): if anim not in metaAnims: metaAnims[anim] = AnimControlCollection() if anim not in MissingAnims.get(modelClass, []): ac = charBundle.loadBindAnim(loader.loader, fileName, -1, SailSubset, True) if ac: metaAnims[anim].storeAnim( ac, str(metaAnims[anim].getNumAnims())) charRoot.node().combineWith(mast.charRoot) continue if self.wantProws and prowType: (highSprit, medSprit, lowSprit) = self.sprits[prowType].getAsset() transform = hull.locators.find( '**/location_bowsprit').getTransform(hull.locators) highSprit.setTransform(transform) medSprit.setTransform(transform) lowSprit.setTransform(transform) highSprit.reparentTo(hull.geoms[0]) medSprit.reparentTo(hull.geoms[1]) lowSprit.reparentTo(hull.geoms[2]) if wantWheel: shipWheel = ShipBlueprints.getWheel() wheelPoint = hull.locators.find( '**/location_wheel;+s').getTransform(hull.locators) shipWheel.setTransform(wheelPoint) shipWheel.flattenLight() shipWheel.find('**/collisions').copyTo(collisions) hull.geoms[0].node().stealChildren( shipWheel.find('**/high').node()) hull.geoms[1].node().stealChildren(shipWheel.find('**/med').node()) hull.geoms[2].node().stealChildren(shipWheel.find('**/low').node()) if complexCustomization: hull.geoms[0].setTexture(shipHullTexture) hull.geoms[0].flattenLight() hull.geoms[1].setTexture(shipHullTexture) hull.geoms[1].flattenLight() hull.geoms[2].setTexture(shipHullTexture) hull.geoms[2].flattenLight() hull.geoms[3].setTexture(shipHullTexture) hull.geoms[3].flattenLight() high.attachNewNode(ModelNode('non-animated')).node().stealChildren( hull.geoms[0].node()) med.attachNewNode(ModelNode('non-animated')).node().stealChildren( hull.geoms[1].node()) low.attachNewNode(ModelNode('non-animated')).node().stealChildren( hull.geoms[2].node()) superlow.attachNewNode(ModelNode('non-animated')).node().stealChildren( hull.geoms[3].node()) collisions.node().stealChildren(hull.collisions.node()) hull.locators.stash() charRoot.flattenStrong() ship = Ship.Ship(shipClass, root, breakAnims, hitAnims, metaAnims, collisions, hull.locators) if not complexCustomization: ship.char.setTexture(shipHullTexture) return ship def getAIShip(self, shipClass): ShipAI = ShipAI import pirates.ship modelClass = ShipGlobals.getModelClass(shipClass) hull = self.getHull(modelClass, 0) root = NodePath('Ship') collisions = root.attachNewNode('collisions') mastSetup = ShipGlobals.getMastSetup(shipClass) for data in [(0, 'location_mainmast_0'), (1, 'location_mainmast_1'), (2, 'location_mainmast_2'), (3, 'location_aftmast*'), (4, 'location_foremast*')]: mastData = mastSetup.get(data[0]) if mastData: mast = self.mastSets[mastData[0]].getMastSet(mastData[1] - 1) model = NodePath(mast.charRoot) model.setPos( hull.locators.find('**/%s' % data[1]).getPos( hull.locators)) model.setHpr( hull.locators.find('**/%s' % data[1]).getHpr( hull.locators)) model.setScale( hull.locators.find('**/%s' % data[1]).getScale( hull.locators)) if modelClass > ShipGlobals.INTERCEPTORL3 or data[0] != 3: mastCode = str(data[0]) else: mastCode = '0' mast.collisions.find('**/collision_masts').setTag( 'Mast Code', mastCode) collisions.node().stealChildren(mast.collisions.node()) continue collisions.node().stealChildren(hull.collisions.node()) hull.locators.reparentTo(root) ship = ShipAI.ShipAI(root, collisions, hull.locators) ship.modelRoot.setTag('Mast Code', str(255)) ship.modelRoot.setTag('Hull Code', str(255)) return ship
class RepairLeak(DirectButton, FSM.FSM): def __init__(self, name, parent, leakscale, **kw): self.name = name pitchingGui = loader.loadModel('models/gui/pir_m_gui_srp_pitching_main') self.hole = pitchingGui.find('**/hole') if random.random() > 0.5: self.holeFilled = pitchingGui.find('**/pitch1') else: self.holeFilled = pitchingGui.find('**/pitch2') optiondefs = (('relief', None, None), ('geom', (self.hole, self.hole, self.hole, self.holeFilled), None), ('rolloverSound', None, None), ('clickSound', None, None)) self.defineoptions(kw, optiondefs) DirectButton.__init__(self, parent = parent) self.initialiseoptions(RepairLeak) FSM.FSM.__init__(self, 'leak_%sFSM' % self.name) self.onCleanup = None self.leakScale = leakscale self.pitchingGame = parent self._initVars() self._initVisuals() self._initIntervals() self.fadeSequence = None self.request('Idle') def _initVars(self): self.timeActive = 0.0 self.pulseScale = 0.59999999999999998 def _initVisuals(self): textureCard = loader.loadModel('models/minigames/pir_m_gam_srp_water') self.waterStream = textureCard.find('**/waterPlane') tex = textureCard.findTexture('pir_t_gui_srp_waterDrops') textureCard2 = loader.loadModel('models/minigames/pir_m_gam_srp_water') self.waterStream2 = textureCard2.find('**/waterPlane') tex2 = textureCard2.findTexture('pir_t_gui_srp_waterDrops') alphaCard = loader.loadModel('models/minigames/pir_m_gui_srp_waterDropsAlpha') self.alphaWaterStream = textureCard.find('**/pir_t_gui_srp_waterDropsAlpha') alphatex = alphaCard.find('**/pir_t_gui_srp_waterDropsAlpha').findTexture('*') self.alphaWaterStream2 = textureCard.find('**/pir_t_gui_srp_waterDropsAlpha2') alphatex2 = alphaCard.find('**/pir_t_gui_srp_waterDropsAlpha2').findTexture('*') alphaCard2 = loader.loadModel('models/minigames/pir_m_gui_srp_waterDropsAlpha') self.alphaWaterStream3 = textureCard.find('**/pir_t_gui_srp_waterDropsAlpha') alphatex3 = alphaCard2.findTexture('*') self.alphaWaterStream4 = textureCard.find('**/pir_t_gui_srp_waterDropsAlpha2') alphatex4 = alphaCard2.findTexture('*') tex.setWrapU(Texture.WMRepeat) tex.setWrapV(Texture.WMRepeat) alphatex.setWrapU(Texture.WMRepeat) alphatex.setWrapV(Texture.WMRepeat) tex2.setWrapU(Texture.WMRepeat) tex2.setWrapV(Texture.WMRepeat) alphatex3.setWrapU(Texture.WMRepeat) alphatex3.setWrapV(Texture.WMRepeat) self.setScale(2.5 * self.leakScale) self.waterStream.setScale(self.leakScale) self.waterStream.setPos(self.getX(), 0.0, -0.5 * self.leakScale + self.getZ()) self.waterStream2.setScale(self.leakScale * 0.80000000000000004, self.leakScale, self.leakScale * 1.2) self.waterStream2.setPos(self.getX(), 0.0, -0.59999999999999998 * self.leakScale + self.getZ()) self.waterStream.setColor(0.69999999999999996, 0.84999999999999998, 1.0, 1.0) self.waterStream2.setColor(0.5, 0.59999999999999998, 0.90000000000000002, 1.0) self.waterStream2.reparentTo(self.pitchingGame) self.waterStream.reparentTo(self.pitchingGame) self.waterStream2.setBin('fixed', 42) self.waterStream.setBin('fixed', 40) self.textureYOffset = random.random() self.textureYDelta = 0.25 + 0.025000000000000001 / self.leakScale self.textureYOffset2 = random.random() self.textureYDelta2 = 0.25412353999999998 + 0.058754645634 / self.leakScale self.textureYOffsetAlpha = 0.0 self.textureYDeltaAlpha = 0.25 + 0.025000000000000001 / self.leakScale self.textureYOffsetAlpha2 = 0.0 self.textureYDeltaAlpha2 = 0.25412353999999998 + 0.058754645634 / self.leakScale self.textureStage = self.waterStream.findTextureStage('*') self.textureStage2 = self.waterStream2.findTextureStage('*') self.textureStage3 = TextureStage('alphaLayer') self.textureStage3.setMode(TextureStage.MModulate) self.textureStage3.setSort(1) self.waterStream.setTexture(self.textureStage3, alphatex) self.textureStage4 = TextureStage('alphaLayer2') self.textureStage4.setMode(TextureStage.MModulate) self.textureStage4.setSort(2) self.waterStream.setTexture(self.textureStage4, alphatex2) trans = TransformState.makePos((0, 0.47999999999999998, 0)) self.waterStream.setTexTransform(self.textureStage4, trans) self.textureStage5 = TextureStage('alphaLayer3') self.textureStage5.setMode(TextureStage.MModulate) self.textureStage5.setSort(1) self.waterStream2.setTexture(self.textureStage5, alphatex3) self.textureStage6 = TextureStage('alphaLayer4') self.textureStage6.setMode(TextureStage.MModulate) self.textureStage6.setSort(2) self.waterStream2.setTexture(self.textureStage6, alphatex4) trans = TransformState.makePos((0, 0.47999999999999998, 0)) self.waterStream2.setTexTransform(self.textureStage6, trans) def repositionTo(self, newX, newZ): self.setPos(newX, 0.0, newZ) self.waterStream.setPos(self.getX(), 0.0, -0.5 * self.leakScale + self.getZ()) self.waterStream2.setPos(self.getX(), 0.0, -0.59999999999999998 * self.leakScale + self.getZ()) def _initIntervals(self): pass def destroy(self): if self.fadeSequence is not None: self.fadeSequence.clearToInitial() self['extraArgs'] = None taskMgr.remove('RepairLeak_%s.update' % self.name) if self.onCleanup is not None: self.onCleanup(self) self.cleanup() self.waterStream.removeNode() self.waterStream2.removeNode() DirectButton.destroy(self) def update(self, task): dt = globalClock.getDt() self.timeActive += dt self.textureYOffset += self.textureYDelta * dt trans = TransformState.makePos((0, self.textureYOffset, 0)) self.waterStream.setTexTransform(self.textureStage, trans) done = False if self.getCurrentOrNextState() == 'Active' and self.textureYOffsetAlpha < _activePosition: self.textureYOffsetAlpha += self.textureYDeltaAlpha * dt if self.textureYOffsetAlpha > _activePosition: self.textureYOffsetAlpha = _activePosition trans2 = TransformState.makePos((0, self.textureYOffsetAlpha, 0)) self.waterStream.setTexTransform(self.textureStage3, trans2) if self.getCurrentOrNextState() == 'Patched': if self.textureYOffsetAlpha < _activePosition: self.textureYOffsetAlpha = 0.75 - self.textureYOffsetAlpha / 2.0 trans2 = TransformState.makePos((0, self.textureYOffsetAlpha, 0)) self.waterStream.setTexTransform(self.textureStage3, trans2) elif self.textureYOffsetAlpha < 1.0: self.textureYOffsetAlpha += self.textureYDeltaAlpha * dt trans2 = TransformState.makePos((0, self.textureYOffsetAlpha, 0)) self.waterStream.setTexTransform(self.textureStage3, trans2) self.textureYOffset2 += self.textureYDelta2 * dt trans = TransformState.makePos((0, self.textureYOffset2, 0)) self.waterStream2.setTexTransform(self.textureStage2, trans) if self.getCurrentOrNextState() == 'Active' and self.textureYOffsetAlpha2 < _activePosition: self.textureYOffsetAlpha2 += self.textureYDeltaAlpha2 * dt if self.textureYOffsetAlpha2 > _activePosition: self.textureYOffsetAlpha2 = _activePosition trans2 = TransformState.makePos((0, self.textureYOffsetAlpha2, 0)) self.waterStream2.setTexTransform(self.textureStage5, trans2) if self.getCurrentOrNextState() == 'Patched': if self.textureYOffsetAlpha2 < _activePosition: self.textureYOffsetAlpha2 = 0.75 - self.textureYOffsetAlpha2 / 2.0 trans2 = TransformState.makePos((0, self.textureYOffsetAlpha2, 0)) self.waterStream2.setTexTransform(self.textureStage5, trans2) if self.textureYOffsetAlpha2 < 1.0: self.textureYOffsetAlpha2 += self.textureYDeltaAlpha2 * dt trans2 = TransformState.makePos((0, self.textureYOffsetAlpha2, 0)) self.waterStream2.setTexTransform(self.textureStage5, trans2) else: done = True if done: self.waterStream.stash() self.waterStream2.stash() self.fadeSequence = Sequence(LerpColorScaleInterval(self, duration = 2.0, colorScale = (1.0, 1.0, 1.0, 0.0)), Func(self.destroy)) self.fadeSequence.start() return Task.done else: return Task.cont def setCommandButtons(self): self.guiItem.addClickButton(MouseButton.one()) self.bind(DGG.B1PRESS, self.commandFunc) def enterIdle(self): self.stash() self.waterStream.stash() self.waterStream2.stash() self['state'] = DGG.DISABLED def exitIdle(self): pass def enterPatched(self): self['state'] = DGG.DISABLED self.setScale(0.84999999999999998) def exitPatched(self): self.stash() self.waterStream.stash() self.waterStream2.stash() def enterActive(self): taskMgr.add(self.update, 'RepairLeak_%s.update' % self.name) self.unstash() self.waterStream.unstash() self.waterStream2.unstash() self['state'] = DGG.NORMAL def exitActive(self): self['state'] = DGG.DISABLED
class RepairLeak(DirectButton, FSM.FSM): __module__ = __name__ def __init__(self, name, parent, leakscale, **kw): self.name = name pitchingGui = loader.loadModel( 'models/gui/pir_m_gui_srp_pitching_main') self.hole = pitchingGui.find('**/hole') if random.random() > 0.5: self.holeFilled = pitchingGui.find('**/pitch1') else: self.holeFilled = pitchingGui.find('**/pitch2') optiondefs = (('relief', None, None), ('geom', (self.hole, self.hole, self.hole, self.holeFilled), None), ('rolloverSound', None, None), ('clickSound', None, None)) self.defineoptions(kw, optiondefs) DirectButton.__init__(self, parent=parent, **kw) self.initialiseoptions(RepairLeak) FSM.FSM.__init__(self, 'leak_%sFSM' % self.name) self.onCleanup = None self.leakScale = leakscale self.pitchingGame = parent self._initVars() self._initVisuals() self._initIntervals() self.fadeSequence = None self.request('Idle') return def _initVars(self): self.timeActive = 0.0 self.pulseScale = 0.6 def _initVisuals(self): textureCard = loader.loadModel('models/minigames/pir_m_gam_srp_water') self.waterStream = textureCard.find('**/waterPlane') tex = textureCard.findTexture('pir_t_gui_srp_waterDrops') textureCard2 = loader.loadModel('models/minigames/pir_m_gam_srp_water') self.waterStream2 = textureCard2.find('**/waterPlane') tex2 = textureCard2.findTexture('pir_t_gui_srp_waterDrops') alphaCard = loader.loadModel( 'models/minigames/pir_m_gui_srp_waterDropsAlpha') self.alphaWaterStream = textureCard.find( '**/pir_t_gui_srp_waterDropsAlpha') alphatex = alphaCard.find( '**/pir_t_gui_srp_waterDropsAlpha').findTexture('*') self.alphaWaterStream2 = textureCard.find( '**/pir_t_gui_srp_waterDropsAlpha2') alphatex2 = alphaCard.find( '**/pir_t_gui_srp_waterDropsAlpha2').findTexture('*') alphaCard2 = loader.loadModel( 'models/minigames/pir_m_gui_srp_waterDropsAlpha') self.alphaWaterStream3 = textureCard.find( '**/pir_t_gui_srp_waterDropsAlpha') alphatex3 = alphaCard2.findTexture('*') self.alphaWaterStream4 = textureCard.find( '**/pir_t_gui_srp_waterDropsAlpha2') alphatex4 = alphaCard2.findTexture('*') tex.setWrapU(Texture.WMRepeat) tex.setWrapV(Texture.WMRepeat) alphatex.setWrapU(Texture.WMRepeat) alphatex.setWrapV(Texture.WMRepeat) tex2.setWrapU(Texture.WMRepeat) tex2.setWrapV(Texture.WMRepeat) alphatex3.setWrapU(Texture.WMRepeat) alphatex3.setWrapV(Texture.WMRepeat) self.setScale(2.5 * self.leakScale) self.waterStream.setScale(self.leakScale) self.waterStream.setPos(self.getX(), 0.0, -0.5 * self.leakScale + self.getZ()) self.waterStream2.setScale(self.leakScale * 0.8, self.leakScale, self.leakScale * 1.2) self.waterStream2.setPos(self.getX(), 0.0, -0.6 * self.leakScale + self.getZ()) self.waterStream.setColor(0.7, 0.85, 1.0, 1.0) self.waterStream2.setColor(0.5, 0.6, 0.9, 1.0) self.waterStream2.reparentTo(self.pitchingGame) self.waterStream.reparentTo(self.pitchingGame) self.waterStream2.setBin('fixed', 42) self.waterStream.setBin('fixed', 40) self.textureYOffset = random.random() self.textureYDelta = 0.25 + 0.025 / self.leakScale self.textureYOffset2 = random.random() self.textureYDelta2 = 0.25412354 + 0.058754645634 / self.leakScale self.textureYOffsetAlpha = 0.0 self.textureYDeltaAlpha = 0.25 + 0.025 / self.leakScale self.textureYOffsetAlpha2 = 0.0 self.textureYDeltaAlpha2 = 0.25412354 + 0.058754645634 / self.leakScale self.textureStage = self.waterStream.findTextureStage('*') self.textureStage2 = self.waterStream2.findTextureStage('*') self.textureStage3 = TextureStage('alphaLayer') self.textureStage3.setMode(TextureStage.MModulate) self.textureStage3.setSort(1) self.waterStream.setTexture(self.textureStage3, alphatex) self.textureStage4 = TextureStage('alphaLayer2') self.textureStage4.setMode(TextureStage.MModulate) self.textureStage4.setSort(2) self.waterStream.setTexture(self.textureStage4, alphatex2) trans = TransformState.makePos((0, 0.48, 0)) self.waterStream.setTexTransform(self.textureStage4, trans) self.textureStage5 = TextureStage('alphaLayer3') self.textureStage5.setMode(TextureStage.MModulate) self.textureStage5.setSort(1) self.waterStream2.setTexture(self.textureStage5, alphatex3) self.textureStage6 = TextureStage('alphaLayer4') self.textureStage6.setMode(TextureStage.MModulate) self.textureStage6.setSort(2) self.waterStream2.setTexture(self.textureStage6, alphatex4) trans = TransformState.makePos((0, 0.48, 0)) self.waterStream2.setTexTransform(self.textureStage6, trans) def repositionTo(self, newX, newZ): self.setPos(newX, 0.0, newZ) self.waterStream.setPos(self.getX(), 0.0, -0.5 * self.leakScale + self.getZ()) self.waterStream2.setPos(self.getX(), 0.0, -0.6 * self.leakScale + self.getZ()) def _initIntervals(self): pass def destroy(self): if self.fadeSequence is not None: self.fadeSequence.clearToInitial() self['extraArgs'] = None taskMgr.remove('RepairLeak_%s.update' % self.name) if self.onCleanup is not None: self.onCleanup(self) self.cleanup() self.waterStream.removeNode() self.waterStream2.removeNode() DirectButton.destroy(self) return def update(self, task): dt = globalClock.getDt() self.timeActive += dt self.textureYOffset += self.textureYDelta * dt trans = TransformState.makePos((0, self.textureYOffset, 0)) self.waterStream.setTexTransform(self.textureStage, trans) done = False if self.getCurrentOrNextState() == 'Active': if self.textureYOffsetAlpha < _activePosition: self.textureYOffsetAlpha += self.textureYDeltaAlpha * dt if self.textureYOffsetAlpha > _activePosition: self.textureYOffsetAlpha = _activePosition trans2 = TransformState.makePos( (0, self.textureYOffsetAlpha, 0)) self.waterStream.setTexTransform(self.textureStage3, trans2) if self.getCurrentOrNextState() == 'Patched': if self.textureYOffsetAlpha < _activePosition: self.textureYOffsetAlpha = 0.75 - self.textureYOffsetAlpha / 2.0 trans2 = TransformState.makePos( (0, self.textureYOffsetAlpha, 0)) self.waterStream.setTexTransform(self.textureStage3, trans2) elif self.textureYOffsetAlpha < 1.0: self.textureYOffsetAlpha += self.textureYDeltaAlpha * dt trans2 = TransformState.makePos( (0, self.textureYOffsetAlpha, 0)) self.waterStream.setTexTransform(self.textureStage3, trans2) self.textureYOffset2 += self.textureYDelta2 * dt trans = TransformState.makePos((0, self.textureYOffset2, 0)) self.waterStream2.setTexTransform(self.textureStage2, trans) if self.getCurrentOrNextState( ) == 'Active' and self.textureYOffsetAlpha2 < _activePosition: self.textureYOffsetAlpha2 += self.textureYDeltaAlpha2 * dt if self.textureYOffsetAlpha2 > _activePosition: self.textureYOffsetAlpha2 = _activePosition trans2 = TransformState.makePos( (0, self.textureYOffsetAlpha2, 0)) self.waterStream2.setTexTransform(self.textureStage5, trans2) if self.getCurrentOrNextState() == 'Patched': if self.textureYOffsetAlpha2 < _activePosition: self.textureYOffsetAlpha2 = 0.75 - self.textureYOffsetAlpha2 / 2.0 trans2 = TransformState.makePos( (0, self.textureYOffsetAlpha2, 0)) self.waterStream2.setTexTransform(self.textureStage5, trans2) if self.textureYOffsetAlpha2 < 1.0: self.textureYOffsetAlpha2 += self.textureYDeltaAlpha2 * dt trans2 = TransformState.makePos( (0, self.textureYOffsetAlpha2, 0)) self.waterStream2.setTexTransform(self.textureStage5, trans2) else: done = True done and self.waterStream.stash() self.waterStream2.stash() self.fadeSequence = Sequence( LerpColorScaleInterval(self, duration=2.0, colorScale=(1.0, 1.0, 1.0, 0.0)), Func(self.destroy)) self.fadeSequence.start() return Task.done else: return Task.cont def setCommandButtons(self): self.guiItem.addClickButton(MouseButton.one()) self.bind(DGG.B1PRESS, self.commandFunc) def enterIdle(self): self.stash() self.waterStream.stash() self.waterStream2.stash() self['state'] = DGG.DISABLED def exitIdle(self): pass def enterPatched(self): self['state'] = DGG.DISABLED self.setScale(0.85) def exitPatched(self): self.stash() self.waterStream.stash() self.waterStream2.stash() def enterActive(self): taskMgr.add(self.update, 'RepairLeak_%s.update' % self.name) self.unstash() self.waterStream.unstash() self.waterStream2.unstash() self['state'] = DGG.NORMAL def exitActive(self): self['state'] = DGG.DISABLED
def add_shadders(self: ShowBase): normalsBuffer = self.win.makeTextureBuffer("normalsBuffer", 0, 0) normalsBuffer.setClearColor(LVecBase4(0.5, 0.5, 0.5, 0.5)) self.normalsBuffer = normalsBuffer normalsCamera = self.makeCamera(normalsBuffer, lens=self.cam.node().getLens()) normalsCamera.node().setScene(self.render) tempnode = NodePath(PandaNode("temp node")) normalGen = self.loader.loadShader("app/view/shaders/normalGen.sha") tempnode.setShader(normalGen) tempnode.setShaderInput("showborders", LVecBase4(1)) normalsCamera.node().setInitialState(tempnode.getState()) depth_buffer = self.win.makeTextureBuffer("depthBuffer", 0, 0) depth_buffer.setClearColor(LVecBase4(0, 0, 0, 0)) self.depth_buffer = depth_buffer depth_camera = self.makeCamera(depth_buffer, lens=self.cam.node().getLens()) depth_camera.node().setScene(self.render) tempnode = NodePath(PandaNode("temp node depth")) depth_gen = self.loader.loadShader("app/view/shaders/depthGen.sha") tempnode.setShader(depth_gen) depth_camera.node().setInitialState(tempnode.getState()) colors_buffer = self.win.makeTextureBuffer("colorsBuffer", 0, 0) colors_buffer.setClearColor(LVecBase4(0, 0, 0, 0)) self.colors_buffer = colors_buffer colorsCamera = self.makeCamera(colors_buffer, lens=self.cam.node().getLens()) colorsCamera.node().setScene(self.render) tempnode = NodePath(PandaNode("temp node colors")) colorGen = self.loader.loadShader("app/view/shaders/colorGen.sha") tempnode.setShader(colorGen) tempnode.setShaderInput("showborders", LVecBase4(1)) tempnode.setShaderInput("colorborders", LVecBase4(0, 0, 0, 1)) colorsCamera.node().setInitialState(tempnode.getState()) # what we actually do to put edges on screen is apply them as a texture to # a transparent screen-fitted card drawnScene = normalsBuffer.getTextureCard() colorBorderTex = colors_buffer.getTextureCard() depthTex = depth_buffer.getTextureCard() drawnScene.setTransparency(1) drawnScene.setColor(1, 1, 1, 1) drawnScene.reparentTo(render2d) self.drawnScene = drawnScene # this shader accepts, as input, the picture from the normals buffer. # it compares each adjacent pixel, looking for discontinuities. # wherever a discontinuity exists, it emits black ink. self.separation = 0.0005 self.separation = 1 self.cutoff = 0.3 inkGen = loader.loadShader("app/view/shaders/inkGen.sha") stage_border = TextureStage("border") stage_border.setSort(1) drawnScene.setTexture(stage_border, colorBorderTex.getTexture()) stage_depth = TextureStage("depth") stage_depth.setSort(2) drawnScene.setTexture(stage_depth, depthTex.getTexture()) drawnScene.setShader(inkGen) drawnScene.setShaderInput( "separation", LVecBase4(self.separation, 0, self.separation, 0)) drawnScene.setShaderInput("screen", 1280, 720) drawnScene.setShaderInput("cutoff", LVecBase4(self.cutoff)) print("SHADER DEBUG") print(drawnScene.findAllTextureStages())
base.camLens.setNearFar(1.0, 50.0) base.camLens.setFov(45.0) camera.setPos(0.0, -20.0, 10.0) camera.lookAt(0.0, 0.0, 0.0) root = render.attachNewNode("Root") root.setPos(0.0, 0.0, 0.0) textureArrow = loader.loadTexture("arrow.png") textureArrow.setWrapU(Texture.WMClamp) textureArrow.setWrapV(Texture.WMClamp) stageArrow = TextureStage("Arrow") stageArrow.setSort(1) textureCircle = loader.loadTexture("circle.png") textureCircle.setWrapU(Texture.WMClamp) textureCircle.setWrapV(Texture.WMClamp) stageCircle = TextureStage("Circle") stageCircle.setSort(2) """ Please open the file cube.egg with a text editor. Egg files are human readable. We will need this information later on to understand how the vertex shader and the fragment shader works. You can also see how the model looks like in panda by using the pview model viewer. The cube has six faces. Each face has four different vertices. Therefore this cube has 24 vertices. Theoretically a cube only needs eight
camera.lookAt(0.0, 0.0, 0.0) root = render.attachNewNode("Root") textureArrow = loader.loadTexture("arrow.png") textureArrow.setWrapU(Texture.WMClamp) textureArrow.setWrapV(Texture.WMClamp) """ DIRTY Like in the previous example, increase the setSort parameter and see what happens, the influence of the order depends on the applied shader. Sometimes you can see a difference, sometimes not. """ stageArrow = TextureStage("Arrow") stageArrow.setSort(1) textureCircle = loader.loadTexture("circle.png") textureCircle.setWrapU(Texture.WMClamp) textureCircle.setWrapV(Texture.WMClamp) stageCircle = TextureStage("Circle") stageCircle.setSort(2) modelCube = loader.loadModel("cube.egg") cubes = [] for x in [-3.0, 0.0, 3.0]: cube = modelCube.copyTo(root) cube.setPos(x, 0.0, 0.0) cubes += [ cube ]