本文整理汇总了Python中panda3d.core.TextureStage.setMode方法的典型用法代码示例。如果您正苦于以下问题:Python TextureStage.setMode方法的具体用法?Python TextureStage.setMode怎么用?Python TextureStage.setMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.TextureStage
的用法示例。
在下文中一共展示了TextureStage.setMode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fillTextureStages
# 需要导入模块: from panda3d.core import TextureStage [as 别名]
# 或者: from panda3d.core.TextureStage import setMode [as 别名]
def fillTextureStages(self, nodePath):
""" Prepares all materials of a given nodepath to have at least the 4
default textures in the correct order: [diffuse, normal, specular, roughness] """
emptyDiffuseTex = loader.loadTexture("Data/Textures/EmptyDiffuseTexture.png")
emptyNormalTex = loader.loadTexture("Data/Textures/EmptyNormalTexture.png")
emptySpecularTex = loader.loadTexture("Data/Textures/EmptySpecularTexture.png")
emptyRoughnessTex = loader.loadTexture("Data/Textures/EmptyRoughnessTexture.png")
textureOrder = [emptyDiffuseTex, emptyNormalTex, emptySpecularTex, emptyRoughnessTex]
textureSorts = [0, 10, 20, 30]
# Prepare the textures
for tex in textureOrder:
tex.setMinfilter(SamplerState.FTLinear)
tex.setMagfilter(SamplerState.FTLinear)
tex.setFormat(Texture.FRgba)
# Iterate over all geom nodes
for np in nodePath.findAllMatches("**/+GeomNode"):
# Check how many texture stages the nodepath already has
stages = np.findAllTextureStages()
numStages = len(stages)
# Fill the texture stages up
for i in xrange(numStages, 4):
stage = TextureStage("DefaultTexStage" + str(i))
stage.setSort(textureSorts[i])
stage.setMode(TextureStage.CMModulate)
stage.setColor(Vec4(0, 0, 0, 1))
np.setTexture(stage, textureOrder[i])
示例2: terrainFromHeightMap
# 需要导入模块: from panda3d.core import TextureStage [as 别名]
# 或者: from panda3d.core.TextureStage import setMode [as 别名]
def terrainFromHeightMap(self, main):
self.parentNodePath = NodePath("FloorNodePath")
self.parentNodePath.setPos(0, 0, -2)
self.parentNodePath.setScale(5, 5, 0.75)
# Heightfield (static)
height = 8.0
img = PNMImage(Filename('models/elevation.png'))
xdim = img.getXSize()
ydim = img.getYSize()
shape = BulletHeightfieldShape(img, height, ZUp)
shape.setUseDiamondSubdivision(True)
self.rigidNode = BulletRigidBodyNode('Heightfield')
self.rigidNode.notifyCollisions(False)
self.rigidNodePath = self.parentNodePath.attachNewNode(self.rigidNode)
self.rigidNodePath.node().addShape(shape)
self.rigidNodePath.setPos(0, 0, 0)
self.rigidNodePath.setCollideMask(BitMask32.allOn())
self.rigidNodePath.node().notifyCollisions(False)
main.world.attachRigidBody(self.rigidNodePath.node())
self.hf = self.rigidNodePath.node() # To enable/disable debug visualisation
self.terrain = GeoMipTerrain('terrain')
self.terrain.setHeightfield(img)
self.terrain.setBlockSize(32)
self.terrain.setNear(50)
self.terrain.setFar(100)
self.terrain.setFocalPoint(base.camera)
rootNP = self.terrain.getRoot()
rootNP.reparentTo(self.parentNodePath)
rootNP.setSz(8.0)
offset = img.getXSize() / 2.0 - 0.5
rootNP.setPos(-offset, -offset, -height / 2.0)
self.terrain.generate()
# Apply texture
diffuseTexture = loader.loadTexture(Filename('models/diffuseMap.jpg'))
diffuseTexture.setWrapU(Texture.WMRepeat)
diffuseTexture.setWrapV(Texture.WMRepeat)
rootNP.setTexture(diffuseTexture)
# Normal map
texStage = TextureStage('texStageNormal')
texStage.setMode(TextureStage.MNormal)
normalTexture = loader.loadTexture(Filename('models/normalMap.jpg'))
rootNP.setTexture(texStage, normalTexture)
# Glow map
texStage = TextureStage('texStageNormal')
texStage.setMode(TextureStage.MGlow)
glowTexture = loader.loadTexture(Filename('models/glowMap.jpg'))
rootNP.setTexture(texStage, glowTexture)
示例3: initSwitchSigns
# 需要导入模块: from panda3d.core import TextureStage [as 别名]
# 或者: from panda3d.core.TextureStage import setMode [as 别名]
def initSwitchSigns(self):
self.switchSigns = []
for i in range(11):
cm = CardMaker('card%d'%i)
cm.setColor(0,0,0,0)
cm.setFrame(-0.5, 0.5, -0.5, 0.5)
card = self.level.attachNewNode(cm.generate())
card.setAttrib(TransparencyAttrib.make(TransparencyAttrib.M_alpha))
tex = loader.loadTexture('%d.png'%i)
ts = TextureStage('ts')
ts.setMode(TextureStage.MReplace)
card.setTexture(ts, tex)
card.setEffect(BillboardEffect.makePointEye())
card.hide()
self.switchSigns.append(card)
示例4: on_pick
# 需要导入模块: from panda3d.core import TextureStage [as 别名]
# 或者: from panda3d.core.TextureStage import setMode [as 别名]
def on_pick(self):
if not self._update_pick_ray(): return
# traverse scene graph and determine nearest selection (if pickable)
self.pick_traverser.traverse(self.board_renderer.base.render)
self.pick_queue.sortEntries()
if not self.pick_queue.getNumEntries(): return
node = self.pick_queue.getEntry(0).getIntoNodePath().findNetTag('pickable')
if node.isEmpty() or node.getTag('pickable') == 'False': return
# add some color
ts = TextureStage('ts')
ts.setMode(TextureStage.MModulate)
colors = list(Game.player_colors)
colors.remove('white')
node.setTexture(ts, self.board_renderer.tileset.load_texture('textures/player%s.png' % random.choice(colors).capitalize()))
示例5: createFadeableImage
# 需要导入模块: from panda3d.core import TextureStage [as 别名]
# 或者: from panda3d.core.TextureStage import setMode [as 别名]
def createFadeableImage(img, tsName, big=False):
cm = CardMaker("FadableCard")
cm.setFrame(-1, 1, -1, 1)
image = NodePath(cm.generate())
image.setTransparency(TransparencyAttrib.MAlpha)
imageTex = loader.loadTexture(img)
imageTs = TextureStage(tsName)
imageTs.setMode(TextureStage.MReplace)
image.setTexture(imageTs, imageTex)
image.reparentTo(render2d)
if big:
image.setScale(0.75)
else:
image.setScale(0.5)
image.setPos(0, 0, 0.25)
image.hide()
return image
示例6: __create_terrain
# 需要导入模块: from panda3d.core import TextureStage [as 别名]
# 或者: from panda3d.core.TextureStage import setMode [as 别名]
def __create_terrain(self):
terrain = GeoMipTerrain("Terrain")
terrain.setHeightfield(self.__texture_path(self.__scene.get("scene", "heightmap")))
terrain.getRoot().reparentTo(self.render)
terrain.generate()
terrain.getRoot().setSx(1000.0 / 512)
terrain.getRoot().setSy(1000.0 / 512)
terrain.getRoot().setSz(74)
terrain.getRoot().setPos(-500, -500, 0)
black = self.loader.loadTexture(self.__texture_path(self.__scene.get("terrain", "black")))
black.setMinfilter(Texture.FTLinearMipmapNearest)
ts = TextureStage("stage-first")
ts.setSort(0)
ts.setMode(TextureStage.MReplace)
ts.setSavedResult(True)
terrain.getRoot().setTexture(ts, black)
terrain.getRoot().setTexScale(ts, 250, 250)
white = self.loader.loadTexture(self.__texture_path(self.__scene.get("terrain", "white")))
white.setMinfilter(Texture.FTLinearMipmapNearest)
ts = TextureStage("stage-second")
ts.setSort(1)
ts.setMode(TextureStage.MReplace)
terrain.getRoot().setTexture(ts, white)
terrain.getRoot().setTexScale(ts, 250, 250)
stencil = self.loader.loadTexture(self.__texture_path(self.__scene.get("scene", "stencil")))
ts = TextureStage("stage-stencil")
ts.setSort(2)
ts.setCombineRgb(TextureStage.CMInterpolate,
TextureStage.CSPrevious, TextureStage.COSrcColor,
TextureStage.CSLastSavedResult, TextureStage.COSrcColor,
TextureStage.CSTexture, TextureStage.COSrcColor)
terrain.getRoot().setTexture(ts, stencil)
ts = TextureStage("stage-vertexcolour")
ts.setSort(3)
ts.setCombineRgb(TextureStage.CMModulate, TextureStage.CSPrevious, TextureStage.COSrcColor,
TextureStage.CSPrimaryColor, TextureStage.COSrcColor)
terrain.getRoot().setTexture(ts, "final")
示例7: makeRenderState
# 需要导入模块: from panda3d.core import TextureStage [as 别名]
# 或者: from panda3d.core.TextureStage import setMode [as 别名]
def makeRenderState(material = None, diffuseTexture=None, normalTexture=None, glowTexture=None):
n = NodePath("n")
if not material:
material = makeMaterial((0,0,0,1), (1,1,1,1), (0.01,0.01,0.01,1), 1, (1,1,1,1))
n.setMaterial(material)
if diffuseTexture:
tsDiffuse = TextureStage('diffuse')
tsDiffuse.setMode(TextureStage.MModulate)
n.setTexture(tsDiffuse, diffuseTexture)
if glowTexture:
tsGlow = TextureStage('glow')
tsGlow.setMode(TextureStage.MGlow)
n.setTexture(tsGlow, glowTexture)
if normalTexture:
tsNormal = TextureStage('normal')
tsNormal.setMode(TextureStage.MNormal)
n.setTexture(tsNormal, normalTexture)
# weird bugs :|
#n.setTransparency(True)
#n.setColorOff()
return n.getState()
示例8: __init__
# 需要导入模块: from panda3d.core import TextureStage [as 别名]
# 或者: from panda3d.core.TextureStage import setMode [as 别名]
def __init__(self, bulletWorld):
self.sky = SkyDome()
# model used as collision mesh
collisionModel = loader.loadModel('models/walledTrack')
# model used as display model
model = loader.loadModel('models/FullTrack')
tex = loader.loadTexture("models/tex/Main.png")
ts = TextureStage('ts')
ts.setMode(TextureStage.MBlend)
model.setTexture(ts, tex, 2)
#model.setTexScale(ts, 70)
# renders track from two camera views
model.setTwoSided(True)
mesh = BulletTriangleMesh()
for geomNP in collisionModel.findAllMatches('**/+GeomNode'):
geomNode = geomNP.node()
ts = geomNP.getTransform(collisionModel)
for geom in geomNode.getGeoms():
mesh.addGeom(geom, ts)
shape = BulletTriangleMeshShape(mesh, dynamic=False)
self.rigidNode = BulletRigidBodyNode('Track')
self.rigidNode.notifyCollisions(False)
np = render.attachNewNode(self.rigidNode)
np.node().addShape(shape)
model.reparentTo(np)
np.setScale(70)
np.setPos(0, 0, -5)
np.setCollideMask(BitMask32(0xf0))
np.node().notifyCollisions(False)
bulletWorld.attachRigidBody(np.node())
self.hf = np.node() # To enable/disable debug visualisation
示例9: __init__
# 需要导入模块: from panda3d.core import TextureStage [as 别名]
# 或者: from panda3d.core.TextureStage import setMode [as 别名]
def __init__(self, name, bodyDB):
Body.__init__(self, name, bodyDB)
self.mesh.reparentTo(render)
self.spectral = bodyDB['spectral']
# We use the data from the spectral database to properly color our star.
color = colorDatabase[self.spectral]
self.mesh.setColor(color[0]/255.0,color[1]/255.0,color[2]/255.0,1)
# We will use a point light to cast our main light
self.light = self.mesh.attachNewNode( PointLight( "sunPointLight" ) )
# Color is set by spectral type. THIS IS NOT PROPER BLACKBODY!
self.light.node().setColor( Vec4(color[0]/255.0,color[1]/255.0,color[2]/255.0,1) )
# Attenuation controls how the light fades with distance. The numbers are
# The three values represent the three constants (constant, linear, and
# quadratic) in the internal lighting equation. The higher the numbers the
# shorter the light goes.
#self.light.node().setAttenuation( Vec3( .1, 0.04, 0.0 ) )
texture1 = loader.loadTexture('sun_1k_tex.jpg')
ts1 = TextureStage('textures1')
ts1.setMode(TextureStage.MGlow)
self.mesh.setTexture(ts1, texture1)
render.setLight( self.light )
starlights.append(self.light)
示例10: render_level
# 需要导入模块: from panda3d.core import TextureStage [as 别名]
# 或者: from panda3d.core.TextureStage import setMode [as 别名]
def render_level(map):
from direct.showbase.Loader import Loader
tex=Loader("foo").loadTexture("BrickOldSharp0215_2_thumbhuge.jpg")
nor=Loader("foo").loadTexture("BrickOldSharp0215_2_thumbhuge-n.jpg")
ts = TextureStage('ts')
ts.setMode(TextureStage.MNormal)
myMaterial = Material()
myMaterial.setShininess(0.0)
myMaterial.setAmbient(Vec4(0,0,0,1))
myMaterial.setEmission(Vec4(0.0,0.0,0.0,1))
myMaterial.setDiffuse(Vec4(0.2,0.2,0.2,1))
myMaterial.setSpecular(Vec4(0.5,0.5,0.5,1))
level_node = NodePath("level")
for i in range(0,22,1):
x = i * 2.0
for j in range(0,22,1):
y = j * 2.0
hideset = set()
cell = map[i][j]
if cell.north == OPEN: hideset.add(2)
if cell.west == OPEN: hideset.add(3)
if cell.south == OPEN: hideset.add(0)
if cell.east == OPEN: hideset.add(1)
xcube = makeCube(inverse=True, hide=hideset)
cube = NodePath(xcube)
cube.setTexture(tex)
cube.setTexture(ts,nor)
cube.reparentTo(level_node)
cube.setPos(x, y, 0 )
#cube.setMaterial(myMaterial)
return level_node
示例11: GUnit
# 需要导入模块: from panda3d.core import TextureStage [as 别名]
# 或者: from panda3d.core.TextureStage import setMode [as 别名]
class GUnit(GEntity):
def __init__(self,conf):
GEntity.__init__(self,conf)
self.p3dobject.reparentTo(self.gmap.units_node)
self.p3dobject.setTransparency(TransparencyAttrib.MAlpha)
#to be put under condition for non pickable units (bonuses npc for instance)
self.p3dobject.setTag('GUnit-pickable','1')
self.p3dobject.setPos(self.gmap.root.find('**/tile_'+str(conf['tileid'])),0,0,0)
#supposedly already a float, but will screw up if not, so just making sure.
self.move_speed=float(conf['move_speed'])
self.path=[]
self.popout_when_move_over=False
self.pid=conf['pid']
#highlight
self.ts_highlighted=TextureStage('ts_highlighted')
self.ts_highlighted.setMode(TextureStage.MDecal)
self.ts_highlighted.setSort(2)
#highlight
self.ts_selected=TextureStage('ts_selected')
self.ts_selected.setMode(TextureStage.MDecal)
self.ts_selected.setSort(3)
@staticmethod
def load_resources():
GUnit.textures={ 'highlighted':loader.loadTexture('data/models/highlighted.tex.png'),
'selected':loader.loadTexture('data/models/selected.tex.png'),
}
def dispose(self):
'''del method'''
GEntity.dispose(self)
self.popout_sequence.finish()
del self.popout_sequence
def add_path(self,data):
'''
adds tile to pass by.
'''
#check for data completeness
if not 'path' in data:
out('WARNING in GUnit.add_path: incomplete data:\n'+str(data))
return
elif not isinstance(data['path'],list):
out('WARNING in GUnit.add_path: invalid data:\n'+str(data))
return
#data considered valid
self.path.extend([self.instances[eid] for eid in data['path']])
if not self.update_move in update_list:
update_list.append(self.update_move)
#out('GUnit.add_path:'+str(data))
def finish_move_to(self,data):
'''triggered by server side unit, to indicate the need to popout at end of move.'''
out('GUnit.finish_move_to()'+str(data))
if self.update_move in update_list:
self.popout_when_move_over=True
else:
self.popout()
def popout(self):
'''sets up the popout animation at end of unit's mission'''
scale=self.p3dobject.scaleInterval(.5,(.1,.1,.1))
finish=Func(lambda:dispose_list.append(self))
self.popout_sequence=Sequence(scale,finish)
self.popout_sequence.start()
def set_highlighted(self):
self.p3dobject.setTexture(self.ts_highlighted,self.textures['highlighted'])
def unset_highlighted(self):
self.p3dobject.clearTexture(self.ts_highlighted)
def set_selected(self):
self.p3dobject.setTexture(self.ts_selected,self.textures['selected'])
def unset_selected(self):
self.p3dobject.clearTexture(self.ts_selected)
def update_move(self):
'''called every frame during while a move.'''
if len(self.path)==0:
out('WARNING in GUnit.update_move: path is empty, but method still called. removing it.')
update_list.remove(self.update_move)
return
if not hasattr(self,'move_interval'):
#start moving
#first 3 args=model,duration,pos, the duration=1/... is relative to server side tile side size
self.move_interval=LerpPosInterval(self.p3dobject,
(1/(self.move_speed*ConfigVariableDouble('clock-frame-rate').getValue())),
self.path[0].p3dobject.getPos(),
name='interval_unit_move_'+str(self.eid)
)
self.p3dobject.lookAt(self.path[0].p3dobject.getPos())
self.p3dobject.loop('run')
self.move_interval.start()
else:
#is move ~over ?
#t=self.move_interval.getT()
#d=self.move_interval.getDuration()
#.........这里部分代码省略.........
示例12: enterIntro
# 需要导入模块: from panda3d.core import TextureStage [as 别名]
# 或者: from panda3d.core.TextureStage import setMode [as 别名]
def enterIntro(self):
helper.hide_cursor()
cm = CardMaker("fade")
cm.setFrameFullscreenQuad()
self.gfLogo = NodePath(cm.generate())
self.gfLogo.setTransparency(TransparencyAttrib.MAlpha)
gfLogotex = loader.loadTexture('GrimFangLogo.png')
gfLogots = TextureStage('gfLogoTS')
gfLogots.setMode(TextureStage.MReplace)
self.gfLogo.setTexture(gfLogots, gfLogotex)
self.gfLogo.setY(-50)
self.gfLogo.reparentTo(render2d)
self.gfLogo.hide()
self.pandaLogo = NodePath(cm.generate())
self.pandaLogo.setTransparency(TransparencyAttrib.MAlpha)
pandaLogotex = loader.loadTexture('Panda3DLogo.png')
pandaLogots = TextureStage('pandaLogoTS')
pandaLogots.setMode(TextureStage.MReplace)
self.pandaLogo.setTexture(pandaLogots, pandaLogotex)
self.pandaLogo.setY(-50)
self.pandaLogo.reparentTo(render2d)
self.pandaLogo.hide()
gfFadeInInterval = LerpColorScaleInterval(
self.gfLogo,
2,
LVecBase4f(0.0,0.0,0.0,1.0),
LVecBase4f(0.0,0.0,0.0,0.0))
gfFadeOutInterval = LerpColorScaleInterval(
self.gfLogo,
2,
LVecBase4f(0.0,0.0,0.0,0.0),
LVecBase4f(0.0,0.0,0.0,1.0))
p3dFadeInInterval = LerpColorScaleInterval(
self.pandaLogo,
2,
LVecBase4f(0.0,0.0,0.0,1.0),
LVecBase4f(0.0,0.0,0.0,0.0))
p3dFadeOutInterval = LerpColorScaleInterval(
self.pandaLogo,
2,
LVecBase4f(0.0,0.0,0.0,0.0),
LVecBase4f(0.0,0.0,0.0,1.0))
self.fadeInOut = Sequence(
Func(self.pandaLogo.show),
p3dFadeInInterval,
Wait(1.0),
p3dFadeOutInterval,
Wait(0.5),
Func(self.pandaLogo.hide),
Func(self.gfLogo.show),
gfFadeInInterval,
Wait(1.0),
gfFadeOutInterval,
Wait(0.5),
Func(self.gfLogo.hide),
Func(self.request, "Menu"),
Func(helper.show_cursor),
name="fadeInOut")
self.fadeInOut.start()
示例13: PlayerBase
# 需要导入模块: from panda3d.core import TextureStage [as 别名]
# 或者: from panda3d.core.TextureStage import setMode [as 别名]
class PlayerBase(DirectObject):
def __init__(self):
# Player Model setup
self.player = Actor("Player",
{"Run":"Player-Run",
"Sidestep":"Player-Sidestep",
"Idle":"Player-Idle"})
self.player.setBlend(frameBlend = True)
self.player.setPos(0, 0, 0)
self.player.pose("Idle", 0)
self.player.reparentTo(render)
self.player.hide()
self.footstep = base.audio3d.loadSfx('footstep.ogg')
self.footstep.setLoop(True)
base.audio3d.attachSoundToObject(self.footstep, self.player)
# Create a brush to paint on the texture
splat = PNMImage("../data/Splat.png")
self.colorBrush = PNMBrush.makeImage(splat, 6, 6, 1)
CamMask = BitMask32.bit(0)
AvBufMask = BitMask32.bit(1)
self.avbuf = None
if base.win:
self.avbufTex = Texture('avbuf')
self.avbuf = base.win.makeTextureBuffer('avbuf', 256, 256, self.avbufTex, True)
cam = Camera('avbuf')
cam.setLens(base.camNode.getLens())
self.avbufCam = base.cam.attachNewNode(cam)
dr = self.avbuf.makeDisplayRegion()
dr.setCamera(self.avbufCam)
self.avbuf.setActive(False)
self.avbuf.setClearColor((1, 0, 0, 1))
cam.setCameraMask(AvBufMask)
base.camNode.setCameraMask(CamMask)
# avbuf renders everything it sees with the gradient texture.
tex = loader.loadTexture('gradient.png')
np = NodePath('np')
np.setTexture(tex, 100)
np.setColor((1, 1, 1, 1), 100)
np.setColorScaleOff(100)
np.setTransparency(TransparencyAttrib.MNone, 100)
np.setLightOff(100)
cam.setInitialState(np.getState())
#render.hide(AvBufMask)
# Setup a texture stage to paint on the player
self.paintTs = TextureStage('paintTs')
self.paintTs.setMode(TextureStage.MDecal)
self.paintTs.setSort(10)
self.paintTs.setPriority(10)
self.tex = Texture('paint_av_%s'%id(self))
# Setup a PNMImage that will hold the paintable texture of the player
self.imageSizeX = 64
self.imageSizeY = 64
self.p = PNMImage(self.imageSizeX, self.imageSizeY, 4)
self.p.fill(1)
self.p.alphaFill(0)
self.tex.load(self.p)
self.tex.setWrapU(self.tex.WMClamp)
self.tex.setWrapV(self.tex.WMClamp)
# Apply the paintable texture to the avatar
self.player.setTexture(self.paintTs, self.tex)
# team
self.playerTeam = ""
# A lable that will display the players team
self.lblTeam = DirectLabel(
scale = 1,
pos = (0, 0, 3),
frameColor = (0, 0, 0, 0),
text = "TEAM",
text_align = TextNode.ACenter,
text_fg = (0,0,0,1))
self.lblTeam.reparentTo(self.player)
self.lblTeam.setBillboardPointEye()
# basic player values
self.maxHits = 3
self.currentHits = 0
self.isOut = False
self.TorsorControl = self.player.controlJoint(None,"modelRoot","Torsor")
# setup the collision detection
# wall and object collision
self.playerSphere = CollisionSphere(0, 0, 1, 1)
self.playerCollision = self.player.attachNewNode(CollisionNode("playerCollision%d"%id(self)))
self.playerCollision.node().addSolid(self.playerSphere)
base.pusher.addCollider(self.playerCollision, self.player)
base.cTrav.addCollider(self.playerCollision, base.pusher)
# foot (walk) collision
self.playerFootRay = self.player.attachNewNode(CollisionNode("playerFootCollision%d"%id(self)))
self.playerFootRay.node().addSolid(CollisionRay(0, 0, 2, 0, 0, -1))
self.playerFootRay.node().setIntoCollideMask(0)
#.........这里部分代码省略.........
示例14: GTile
# 需要导入模块: from panda3d.core import TextureStage [as 别名]
# 或者: from panda3d.core.TextureStage import setMode [as 别名]
class GTile(GEntity):
def __init__(self,conf):
self.p3dobject=self.gmap.tile_matrix_node.attachNewNode('tile_'+str(conf['eid']))
self.p3dobject.setTransparency(TransparencyAttrib.MAlpha)
#self.test_sphere=loader.loadModel('data/models/test_sphere.egg')
#self.test_sphere.reparentTo(self.p3dobject)
GEntity.__init__(self,conf)
self.x,self.y=x,y=conf['x'],conf['y']
self.p3dobject.setTag('x',str(x))
self.p3dobject.setTag('y',str(y))
self.p3dobject.setPythonTag('ref',self)
#half of a tile side
t=self.gmap.tile_matrix_node.getScale()[0]/2.
self.p3dobject.setPos(self.gmap.tile_matrix_node,(-self.gmap.resx/2.+x+t)*2.,(y-self.gmap.resy/2.+t)*2.,0)
#preload texture holder quad
self.quad=GTile.resources['quad']()
self.quad.setTransparency(TransparencyAttrib.MAlpha)
#self.quad.reparentTo(self.p3dobject)
self.quad.reparentTo(self.gmap.tiles_quads_node)
self.quad.setPos(self.p3dobject.getPos())
self.quad.hide()
#pid of the player that owns the tile
self.pawner=None
self.ts_pawn=TextureStage('ts_pawn')
self.ts_pawn.setMode(TextureStage.MReplace)
self.ts_pawn.setSort(2)
#selection
self.is_selected=False
self.ts_selected=TextureStage('ts_selected')
self.ts_selected.setMode(TextureStage.MReplace)
self.ts_selected.setSort(3)
#highlight
self.is_highlighted=False
self.ts_highlighted=TextureStage('ts_highlighted')
self.ts_highlighted.setMode(TextureStage.MDecal)
self.ts_highlighted.setSort(4)
def __repr__(self):
return 'GTile{eid:'+str(self.eid)+'\n\
x/y:'+str(self.x)+'/'+str(self.y)+'\n\
pawner:'+str(self.pawner)+'\n\
selected:'+str(self.is_selected)+'\n\
highlighted:'+str(self.is_highlighted)+'\n\
}'
def __str__(self):
return self.__repr__()
@staticmethod
def load_resources():
#dict of texture
GTile.resources={ 'quad':lambda:loader.loadModel('data/models/tiles/tile.egg'),
}
GTile.textures={ 'highlighted':loader.loadTexture('data/models/tiles/tile.highlighted.tex.png'),
'selected':loader.loadTexture('data/models/tiles/tile.selected.tex.png'),
'pawn-0':loader.loadTexture('data/models/tiles/tile.pawned.black.tex.png'),
'pawn-1':loader.loadTexture('data/models/tiles/tile.pawned.white.tex.png'),
}
@property
def left_tile(self):
'''property getter'''
if self.x>0:return self.gmap.tile_matrix[self.x-1][self.y]
return None
@property
def lower_tile(self):
'''property getter'''
if self.y>0:return self.gmap.tile_matrix[self.x][self.y-1]
return None
@property
def right_tile(self):
'''property getter'''
if self.x<self.gmap.resx-1:return self.gmap.tile_matrix[self.x+1][self.y]
return None
@property
def upper_tile(self):
'''property getter'''
if self.y<self.gmap.resy-1:return self.gmap.tile_matrix[self.x][self.y+1]
return None
@property
def neighbors(self):
'''property getter'''
return filter(lambda t:t!=None,[self.left_tile,self.lower_tile,self.right_tile,self.upper_tile])
@property
def wall(self):
'''
returns a list of all tiles that form a wall connected to this tile.
a tile with no pawner doesn't belong to any wall.
'''
if self.pawner==None:
return []
wall=[]
#.........这里部分代码省略.........
示例15: Typist
# 需要导入模块: from panda3d.core import TextureStage [as 别名]
# 或者: from panda3d.core.TextureStage import setMode [as 别名]
class Typist(object):
TARGETS = { 'paper': {
'model': 'paper',
'textureRoot': 'Front',
'scale': Point3(0.85, 0.85, 1),
'hpr' : Point3(0, 0, 0),
}
}
def __init__(self, base, typewriterNP, underDeskClip, sounds):
self.base = base
self.sounds = sounds
self.underDeskClip = underDeskClip
self.typeIndex = 0
self.typewriterNP = typewriterNP
self.rollerAssemblyNP = typewriterNP.find("**/roller assembly")
assert self.rollerAssemblyNP
self.rollerNP = typewriterNP.find("**/roller")
assert self.rollerNP
self.carriageNP = typewriterNP.find("**/carriage")
assert self.carriageNP
self.baseCarriagePos = self.carriageNP.getPos()
self.carriageBounds = self.carriageNP.getTightBounds()
self.font = base.loader.loadFont('Harting.ttf', pointSize=32)
self.pnmFont = PNMTextMaker(self.font)
self.fontCharSize, _, _ = fonts.measureFont(self.pnmFont, 32)
print "font char size: ",self.fontCharSize
self.pixelsPerLine = int(round(self.pnmFont.getLineHeight()))
self.target = None
""" panda3d.core.NodePath """
self.targetRoot = None
""" panda3d.core.NodePath """
self.paperY = 0.0
""" range from 0 to 1 """
self.paperX = 0.0
""" range from 0 to 1 """
self.createRollerBase()
self.tex = None
self.texImage = None
self.setupTexture()
self.scheduler = Scheduler()
task = self.base.taskMgr.add(self.tick, 'timerTask')
task.setDelay(0.01)
def tick(self, task):
self.scheduler.tick(globalClock.getRealTime())
return task.cont
def setupTexture(self):
"""
This is the overlay/decal/etc. which contains the typed characters.
The texture size and the font size are currently tied together.
:return:
"""
self.texImage = PNMImage(1024, 1024)
self.texImage.addAlpha()
self.texImage.fill(1.0)
self.texImage.alphaFill(1.0)
self.tex = Texture('typing')
self.tex.setMagfilter(Texture.FTLinear)
self.tex.setMinfilter(Texture.FTLinear)
self.typingStage = TextureStage('typing')
self.typingStage.setMode(TextureStage.MModulate)
self.tex.load(self.texImage)
# ensure we can quickly update subimages
self.tex.setKeepRamImage(True)
# temp for drawing chars
self.chImage = PNMImage(*self.fontCharSize)
def drawCharacter(self, ch, px, py):
"""
Draw a character onto the texture
:param ch:
:param px: paperX
:param py: paperY
:return: the paper-relative size of the character
"""
h = self.fontCharSize[1]
if ch != ' ':
# position -> pixel, applying margins
x = int(self.tex.getXSize() * (px * 0.8 + 0.1))
y = int(self.tex.getYSize() * (py * 0.8 + 0.1))
#.........这里部分代码省略.........