当前位置: 首页>>代码示例>>Python>>正文


Python TextureStage.setMode方法代码示例

本文整理汇总了Python中pandac.PandaModules.TextureStage.setMode方法的典型用法代码示例。如果您正苦于以下问题:Python TextureStage.setMode方法的具体用法?Python TextureStage.setMode怎么用?Python TextureStage.setMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandac.PandaModules.TextureStage的用法示例。


在下文中一共展示了TextureStage.setMode方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SkyDome1

# 需要导入模块: from pandac.PandaModules import TextureStage [as 别名]
# 或者: from pandac.PandaModules.TextureStage import setMode [as 别名]
class SkyDome1(Att_base):
    def __init__(self, scene, dynamic=True, rate=(0.005,0.05),
        texturescale=(1000,1000),
        scale=(40,40,10), texturefile=None):
        Att_base.__init__(self,False, "Sky Dome 1")
        self.skybox = loader.loadModel("../media/models/dome2")
        self.skybox.setCollideMask(BitMask32().allOff())
        self.skybox.setTwoSided(False)
        self.skybox.setScale(scale[0],scale[1],scale[2])
        self.skybox.setLightOff()
        if texturefile == None:
            texturefile = "../media/textures/concrete.jpg"
        texture = loader.loadTexture(texturefile)
        self.textureStage0 = TextureStage("stage0")
        self.textureStage0.setMode(TextureStage.MReplace)
        self.skybox.setTexture(self.textureStage0,texture,1)
        self.skybox.setTexScale(self.textureStage0, texturescale[0], texturescale[1])

        self.skybox.reparentTo(scene)

    def setTextureScale(self, texturescale):
        self.skybox.setTexScale(self.textureStage0, texturescale[0], texturescale[1])

    def Destroy(self):
        self.skybox.removeNode()

    def setPos(self, v):
        self.skybox.setPos(v)

    def show(self):
        self.skybox.show()

    def hide(self):
        self.skybox.hide()
开发者ID:Joelone,项目名称:IsisWorld,代码行数:36,代码来源:skydome2.py

示例2: DetailTexturer

# 需要导入模块: from pandac.PandaModules import TextureStage [as 别名]
# 或者: from pandac.PandaModules.TextureStage import setMode [as 别名]
class DetailTexturer(TerrainTexturer):
    """adds a texture + detail texture to TerrainTiles"""

    def load(self):
        self.ts1 = TextureStage('ts2')
        tex = self.loadTexture("snow.jpg")
        tex.setWrapU(Texture.WMMirror)
        tex.setWrapV(Texture.WMMirror)
        self.monoTexture = tex

        self.loadDetail()

    def loadDetail(self):
        self.detailTS = TextureStage('ts')
        tex = self.loadTexture("Detail_COLOR.jpg")
        tex.setWrapU(Texture.WMMirror)
        tex.setWrapV(Texture.WMMirror)
        self.detailTexture = tex
        self.textureBlendMode = self.detailTS.MHeight
        self.detailTS.setMode(self.textureBlendMode)

    def apply(self, input):
        """Apply textures and shaders to the input."""

        input.setTexture(self.ts1, self.monoTexture)
        input.setTexScale(self.ts1, 5, 5)

        input.setTexture(self.detailTS, self.detailTexture)
        input.setTexScale(self.detailTS, 120, 120)


    def setDetailBlendMode(self, num):
        """Set the blending mode of the detail texture."""

        if (not self.detailTexture):
            return
        self.textureBlendMode = num
        #for pos, tile in self.tiles.items():
        #    if tile.detailTS:
        #        tile.detailTS.setMode(self.textureBlendMode)

        self.detailTS.setMode(self.textureBlendMode)

    def incrementDetailBlendMode(self):
        """Set the blending mode of the detail texture."""

        if (not self.detailTexture):
            return
        self.textureBlendMode += 1
        self.setDetailBlendMode(self.textureBlendMode)

    def decrementDetailBlendMode(self):
        """Set the blending mode of the detail texture."""

        if (not self.detailTexture):
            return
        self.textureBlendMode -= 1
        self.setDetailBlendMode(self.textureBlendMode)
开发者ID:StephenLujan,项目名称:Panda-3d-Procedural-Terrain-Engine,代码行数:60,代码来源:terraintexturer.py

示例3: UpdateTexture

# 需要导入模块: from pandac.PandaModules import TextureStage [as 别名]
# 或者: from pandac.PandaModules.TextureStage import setMode [as 别名]
 def UpdateTexture(self):
     if(not self.model):
         self.LoadContent()
         
     (u, v) = BlockGeometryGenerator.BlockIdToUV(self.currentBlockIdToPlace + 1) # Add 1 to offset from Air Id = 0
     ts = TextureStage('ts')
     ts.setMode(TextureStage.MReplace)
     self.model.clearTexture()
     self.model.setTexture(ts, self.blockTexture)
     self.model.setTexOffset(ts, u[0], v[0])
     self.model.setTexScale(ts, 0.0625, 0.0625)
开发者ID:czorn,项目名称:Modifire,代码行数:13,代码来源:Builder.py

示例4: SetGeomTexture

# 需要导入模块: from pandac.PandaModules import TextureStage [as 别名]
# 或者: from pandac.PandaModules.TextureStage import setMode [as 别名]
    def SetGeomTexture(geom, geomId, node, blockTexture):
        """ Applies the texture to the visible geometry of the Chunk."""
        ts = TextureStage('ts')
        ts.setMode(TextureStage.MDecal)
        ts.setTexcoordName('light')

        # Setup the block texture
        attrib = TextureAttrib.make(blockTexture)
        
        # Add the light overlay
        #attrib = attrib.addOnStage(ts, geom['lighttexture'])
        
        # Apply the texture to the node
        node.setGeomState(geomId, 
                               node.getGeomState(geomId).addAttrib(attrib))
开发者ID:czorn,项目名称:Modifire,代码行数:17,代码来源:ChunkOfBlocksNew.py

示例5: Texture

# 需要导入模块: from pandac.PandaModules import TextureStage [as 别名]
# 或者: from pandac.PandaModules.TextureStage import setMode [as 别名]
 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)
开发者ID:KillerGoldFisch,项目名称:panda3d-editor,代码行数:22,代码来源:terrainShader.py

示例6: SkyDome2

# 需要导入模块: from pandac.PandaModules import TextureStage [as 别名]
# 或者: from pandac.PandaModules.TextureStage import setMode [as 别名]
class SkyDome2(Att_base):
    def __init__(self, scene, dynamic=True, rate=Vec4(0.004, 0.002, 0.008, 0.010),
        skycolor=Vec4(0.25, 0.5, 1, 0),
        texturescale=Vec4(1,1,1,1),
        scale=(4000,4000,1000),
        texturefile=None):
        Att_base.__init__(self,False, "Sky Dome 2")
        self.skybox = loader.loadModel("./media/models/dome2")
        self.skybox.reparentTo(scene)
        self.skybox.setScale(scale[0],scale[1],scale[2])
        self.skybox.setLightOff()

        if texturefile == None:
            texturefile = "./media/textures/clouds_bw.png"
        texture = loader.loadTexture(texturefile)
        self.textureStage0 = TextureStage("stage0")
        self.textureStage0.setMode(TextureStage.MReplace)
        self.skybox.setTexture(self.textureStage0,texture,1)
        #self.skybox.setTexScale(self.textureStage0, texturescale[0], texturescale[1])

        self.rate = rate
        self.textureScale = texturescale
        self.skycolor = skycolor
        self.dynamic = dynamic
        if self.dynamic:
            self.skybox.setShader( loader.loadShader( './media/shaders/skydome2.sha' ) )
            self.setShaderInput()

    def setRate(self, rate):
        self.rate = rate

    def setTextureScale(self, texturescale):
        self.skybox.setTexScale(self.textureStage0, texturescale[0], texturescale[1])

    def Destroy(self):
        self.skybox.clearShader()
        self.skybox.removeNode()

    def setPos(self, v):
        self.skybox.setPos(v)

    def show(self):
        self.skybox.show()

    def hide(self):
        self.skybox.hide()

    def setStandardControl(self):
        self.att_rate = Att_Vecs(False,"Cloud Speed",4,self.rate,-1,1,3)
        self.att_scale = Att_Vecs(False, "Tex-scale", 4, self.textureScale, 0.01, 100.0, 2)
        self.att_skycolor = Att_color(False, "Sky Color", self.skycolor)
        self.att_rate.setNotifier(self.changeParams)
        self.att_scale.setNotifier(self.changeParams)
        self.att_skycolor.setNotifier(self.changeParams)

    def changeParams(self, object):
        self.rate = self.att_rate.getValue()
        self.skycolor = self.att_skycolor.getColor()
        self.textureScale = self.att_scale.getValue()
        self.setShaderInput()

    #def skyboxscalechange(self,object):
    #    self.setTextureScale(self.att_scale.getValue())

    def setShaderInput(self):
        self.skybox.setShaderInput("sky", self.skycolor)
        self.skybox.setShaderInput("clouds", self.rate)
        self.skybox.setShaderInput("ts", self.textureScale)
开发者ID:Joelone,项目名称:IsisWorld,代码行数:70,代码来源:skydome2.py

示例7: construct_scene

# 需要导入模块: from pandac.PandaModules import TextureStage [as 别名]
# 或者: from pandac.PandaModules.TextureStage import setMode [as 别名]
def construct_scene(lbase, modelpath, bgpath, scale, pos, hpr, 
                    bgscale, bghp,
                    texture=None,
                    internal_canonical=False,
                    check_penetration=False, 
                    light_spec=None, 
                    use_envmap=False):
    """ Constructs the scene per the parameters. """

    # Default scene is lbase's rootnode
    if bgpath is not None:
        bgpath = mt.resolve_bg_path(bgpath)
    rootnode = lbase.rootnode
    # Modelpath points to the model .egg/.bam file

    if isinstance(modelpath, str):
        modelpaths = [modelpath]
        scales = [scale]
        poses = [pos]
        hprs = [hpr]
        textures = [texture]
    else:  
        modelpaths = modelpath
        scales = scale
        poses = pos
        hprs = hpr
        textures = texture

    texmodes = []
    for _i, _t in enumerate(textures):
        if isinstance(_t, tuple):
            texfile, texmode = _t
            texmodes.append(texmode)
            textures[_i] = texfile
        else:
            texmodes.append(TexGenAttrib.MWorldNormal)    

    assert hasattr(modelpaths, '__iter__')
    assert hasattr(scales, '__iter__')
    assert hasattr(poses, '__iter__')
    assert hasattr(hprs, '__iter__')
    assert hasattr(textures, '__iter__')
    assert len(modelpaths) == len(scales) == len(hprs) == len(poses) == len(textures), (len(modelpaths), len(scales), len(hprs), len(poses), len(textures))
        
    modelpaths = map(mt.resolve_model_path, modelpaths)
    modelpaths = map(cm.autogen_egg, modelpaths)
    textures = map(mt.resolve_texture_path, textures)
    objnodes = []
    for mpth, scale, hpr, pos, t, tm in zip(modelpaths, scales, hprs, poses, textures, texmodes):
        objnode = tools.read_file(lbase.loader.loadModel, mpth)
        if t is not None: 
            #ts = TextureStage('ts')
            ts = TextureStage.get_default()
            ts.setMode(TextureStage.MReplace) 
            tex = tools.read_file(lbase.loader.loadTexture, t) 
            objnode.setTexGen(ts, tm)
            objnode.setTexture(tex, 6)
        
        robjnode = rootnode.attachNewNode('root_' + objnode.get_name())
        objnode.reparentTo(robjnode)
        if internal_canonical:
            vertices = np.array(objnode.getTightBounds())
            initial_scale_factor = max(abs(vertices[0]-vertices[1]))
            cscale = 1.2/initial_scale_factor
            ppos = vertices.mean(0) * cscale
            objnode.setPos(-ppos[0], -ppos[1], -ppos[2])
            objnode.setScale(cscale, cscale, cscale)
            
        robjnode.setScale(scale[0], scale[0], scale[0])
        robjnode.setPos(pos[0], -pos[2], pos[1])
        robjnode.setHpr(hpr[2], hpr[1], hpr[0])
        robjnode.setTwoSided(1)

        objnodes.append(robjnode)

    if check_penetration:
        for (i, n1) in enumerate(objnodes):
            for j, n2 in enumerate(objnodes[i+1:]):
                p = is_penetrating(n1, n2)
                if p:
                    for onode in objnodes:
                        onode.removeNode()
                    raise PenetrationError(i, j, n1, n2)

    # Environment map
    if bgpath and use_envmap:
        envtex = tools.read_file(lbase.loader.loadTexture, bgpath)
        # Map onto object
        ts = TextureStage('env')
        ts.setMode(TextureStage.MBlendColorScale)
        if not isinstance(use_envmap, list):
            use_envmap = [use_envmap] * len(objnodes)
        for _objnode, ue in zip(objnodes, use_envmap):
            if ue:
                if isinstance(ue, str):
                    envtex0 = tools.read_file(lbase.loader.loadTexture, mt.resolve_texture_path(ue))
                else:
                    envtex0 = envtex
                _objnode.setTexGen(ts, TexGenAttrib.MEyeSphereMap)
                _objnode.setTexture(ts, envtex0)
#.........这里部分代码省略.........
开发者ID:jiaxx,项目名称:genthor,代码行数:103,代码来源:renderer.py

示例8: RepairLeak

# 需要导入模块: from pandac.PandaModules import TextureStage [as 别名]
# 或者: from pandac.PandaModules.TextureStage import setMode [as 别名]
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)
#.........这里部分代码省略.........
开发者ID:Puggyblue999,项目名称:PiratesOfTheCarribeanOnline,代码行数:103,代码来源:RepairLeak.py

示例9: Star

# 需要导入模块: from pandac.PandaModules import TextureStage [as 别名]
# 或者: from pandac.PandaModules.TextureStage import setMode [as 别名]
class Star(SphericalBody):
    '''
    Class star contain attributes of the star and
    a list of all the planets orbiting the star.
    '''

    def __init__(self, position, radius, player=None):
        '''
        Constructor for class star: creates a dead star object, initializing the star's attributes with 
        the given parameters. 
        @param position : Point3D, the position of the center of the star
        @param radius : float, star radius
        @param player: Player, the owner of the star
        @param activated: boolean, determine whether star is activated by the player or not
        @param stage: Integer, is the stage in which the star is in; consists of 6 stages
        @param counter: Timer, is the count-down timer for the star's life
        '''
        super(Star, self).__init__(position, radius, False, player)
        self.lifetime = 0
        self._planets = []
        self.stage = 0
        self.timer_task = None
        
        self.t = Timer(self) 
        self.__initSceneGraph()
    
    def __initSceneGraph(self):
        # Parent node for relative position (no scaling)
        self.point_path = render.attachNewNode("star_node")
        self.point_path.setPos(self.position)
        
        #For transforming the object with scaling, colors, shading, etc.
        # Hosting the actual 3d model object.
        #Models & textures
        self.flare_ts = TextureStage('flare')
        self.flare_ts.setMode(TextureStage.MModulateGlow)
        self.model_path = loader.loadModel("models/stars/planet_sphere")
        self.model_path.setTexture(SphericalBody.star_dead_tex, 1)
        self.model_path.reparentTo(self.point_path)
        self.model_path.setScale(self.radius)
        self.model_path.setPythonTag('pyStar', self);
        
        # Collision sphere for object picking
        #-----------------------------------------------------
        # As described in the Tut-Chessboard.py sample: "If this model was
        # any more complex than a single polygon, you should set up a collision
        # sphere around it instead."
        cnode = CollisionNode("coll_sphere_node")
        cnode.setTag('star', str(id(self)))
        #We use no displacement (0,0,0) and no scaling factor (1)
        cnode.addSolid(CollisionSphere(0,0,0,1))
        cnode.setIntoCollideMask(BitMask32.bit(1))
        self.cnode_path = self.model_path.attachNewNode(cnode)
        #For temporary testing, display collision sphere.
#        self.cnode_path.show()
        self.quad_path = None
 
    def activateHighlight(self, thin):
        if thin:
            tex = base.loader.loadTexture("models/billboards/thin_ring.png")
        else:
            tex = base.loader.loadTexture("models/billboards/ring.png")
        cm = CardMaker('highlight')
        cm.setFrameFullscreenQuad() # so that the center acts as the origin (from -1 to 1)
        self.quad_path = self.point_path.attachNewNode(cm.generate())        
        self.quad_path.setTransparency(TransparencyAttrib.MAlpha)
        self.highlight_ts = TextureStage('flare')
        self.quad_path.setTexture(self.highlight_ts, tex)
        if thin:
            self.quad_path.setColor(Vec4(1.0, 1.0, 1.0, 1))
        else:
            self.quad_path.setColor(Vec4(1.0, 0.3, 0.2, 1))
        self.quad_path.setScale(12)
        self.quad_path.setPos(Vec3(0,0,0))
        self.quad_path.setBillboardPointEye()
    
    def deactivateHighlight(self):
        if self.quad_path:
            self.quad_path.detachNode()
            self.quad_path = None

    def select(self, player):
        '''
        @param player, the player who has selected
        This method observes the events on the star and calls the related methods
        and notifies the corresponding objects based on the state of the star
        '''
        player.selected_planet = None
        
        if(player.ge_amount != 0 and self.activated == False and \
           player.selected_star == self):
            player.ge_amount = player.ge_amount - 1
            self.activateStar(player)
            self.notify("updateGE")
        else:
#            from gameEngine.gameEngine import all_stars 
#            for star in all_stars:
#                if(star != self):
#                    star.deactivateHighlight()
            from gameEngine.gameEngine import all_planets
#.........这里部分代码省略.........
开发者ID:muadibbm,项目名称:COMP361Project,代码行数:103,代码来源:solar.py

示例10: Planet

# 需要导入模块: from pandac.PandaModules import TextureStage [as 别名]
# 或者: from pandac.PandaModules.TextureStage import setMode [as 别名]
class Planet(SphericalBody): 
    '''
    Planet contains units and structures
    '''

    def __init__(self, orbital_radius, orbital_angle, radius, parent_star, prev_planet=None, player=None):
        '''
        Constructor for class planet.
        @param position: Point3D, position in space
        @param radius: float, body radius
        @param player: Player, the owner of the planet
        @param parent_star: Star, the specific star the planet is orbiting around
        @param prev_planet: previous planet in the star system, if None then the planet is the first
        '''
        position = Point3(orbital_radius * math.cos(orbital_angle),
                          orbital_radius * math.sin(orbital_angle), 0)
        super(Planet, self).__init__(position, radius, False, player)
        self.orbital_velocity = 0
        self.max_orbital_velocity = 0
        self.orbital_radius = orbital_radius
        self.orbital_angle = orbital_angle
        self.parent_star = parent_star
        self.prev_planet = prev_planet
        self.next_planet = None
        self._orbiting_units = []
        self._surface_structures = []
        self.__initSceneGraph()
               
        '''For the Player'''
        self.task_structure_timer = None
        self.task_unit_timer = None
        '''For the AI'''
        self.task_structure_timers = []
        self.task_unit_timers = []
        
    def __initSceneGraph(self):

        #load various texture stages of the planet
        self.forge_tex = TextureStage('forge')
        self.forge_tex.setMode(TextureStage.MDecal)
        self.nexus_tex = TextureStage('nexus')
        self.nexus_tex.setMode(TextureStage.MDecal)
        self.extractor_phylon_ge_tex = TextureStage('extractor_phylon_ge')
        self.extractor_phylon_ge_tex.setMode(TextureStage.MDecal)
        
        # Parent node for relative position (no scaling)
        self.point_path = self.parent_star.point_path.attachNewNode("planet_node")
        self.point_path.setPos(self.position)
        
        #Models & textures
        self.model_path = loader.loadModel("models/planets/planet_sphere")
        self.model_path.setTexture(SphericalBody.dead_planet_tex, 1)
        self.model_path.reparentTo(self.point_path)
        self.model_path.setScale(self.radius)
        self.model_path.setPythonTag('pyPlanet', self);
        
        cnode = CollisionNode("coll_sphere_node")
        cnode.setTag('planet', str(id(self)))
        #We use no displacement (0,0,0) and no scaling factor (1)
        cnode.addSolid(CollisionSphere(0,0,0,1))
        cnode.setIntoCollideMask(BitMask32.bit(1))
        # Reparenting the collision sphere so that it 
        # matches the planet perfectly.
        self.cnode_path = self.model_path.attachNewNode(cnode)
        
        self.lines = LineNodePath(parent = self.parent_star.point_path, thickness = 4.0, colorVec = Vec4(1.0, 1.0, 1.0, 0.2))
        self.quad_path = None
        
    def setTexture(self, structureType):
        '''
        Used whenever a structure is built on the planet
        @ StructureType is a string specifying the type of the structure
        '''
        if(structureType == "forge"):
            #SphericalBody.planet_forge_tex.setWrapU(Texture.WMInvalid)
            #SphericalBody.planet_forge_tex.setWrapV(Texture.WMInvalid)
            self.model_path.setTexture(self.forge_tex, SphericalBody.planet_forge_tex)
            #self.model_path.getTexture().setWrapU(Texture.WMClamp)
            #self.model_path.getTexture().setWrapV(Texture.WMClamp)
            self.model_path.setTexOffset(self.forge_tex, 0, 0)
            #self.model_path.setTexScale(self.forge_tex, -4, -2)
        elif(structureType == "nexus"):
            self.model_path.setTexture(self.nexus_tex, SphericalBody.planet_nexus_tex)
            self.model_path.setTexOffset(self.nexus_tex, 0, 10)
        elif(structureType == "extractor"):
            self.model_path.setTexture(self.extractor_phylon_ge_tex, SphericalBody.planet_extractor_tex)
            self.model_path.setTexOffset(self.extractor_phylon_ge_tex, 0, 20)
        elif(structureType == "phylon"):
            self.model_path.setTexture(self.extractor_phylon_ge_tex, SphericalBody.planet_phylon_tex)
            self.model_path.setTexOffset(self.extractor_phylon_ge_tex, 0, 20)
        elif(structureType == "generatorCore"):
            self.model_path.setTexture(self.extractor_phylon_ge_tex, SphericalBody.planet_generatorCore_tex)
            self.model_path.setTexOffset(self.extractor_phylon_ge_tex, 0, 20)
    
    def activateHighlight(self, thin):
        if thin:
            flare_tex = base.loader.loadTexture("models/billboards/thin_ring.png")
        else:
            flare_tex = base.loader.loadTexture("models/billboards/ring.png")
        cm = CardMaker('quad')
#.........这里部分代码省略.........
开发者ID:muadibbm,项目名称:COMP361Project,代码行数:103,代码来源:solar.py


注:本文中的pandac.PandaModules.TextureStage.setMode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。