本文整理汇总了Python中panda3d.core.PNMImage.addAlpha方法的典型用法代码示例。如果您正苦于以下问题:Python PNMImage.addAlpha方法的具体用法?Python PNMImage.addAlpha怎么用?Python PNMImage.addAlpha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.PNMImage
的用法示例。
在下文中一共展示了PNMImage.addAlpha方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeTextureMap
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import addAlpha [as 别名]
def makeTextureMap(self):
'''Citymania function that generates and sets the 4 channel texture map'''
self.colorTextures = []
for terrain in self.terrains:
terrain.getRoot().clearTexture()
heightmap = terrain.heightfield()
colormap = PNMImage(heightmap.getXSize()-1, heightmap.getYSize()-1)
colormap.addAlpha()
slopemap = terrain.makeSlopeImage()
for x in range(0, colormap.getXSize()):
for y in range(0, colormap.getYSize()):
# Else if statements used to make sure one channel is used per pixel
# Also for some optimization
# Snow. We do things funky here as alpha will be 1 already.
if heightmap.getGrayVal(x, y) < 200:
colormap.setAlpha(x, y, 0)
else:
colormap.setAlpha(x, y, 1)
# Beach. Estimations from http://www.simtropolis.com/omnibus/index.cfm/Main.SimCity_4.Custom_Content.Custom_Terrains_and_Using_USGS_Data
if heightmap.getGrayVal(x,y) < 62:
colormap.setBlue(x, y, 1)
# Rock
elif slopemap.getGrayVal(x, y) > 170:
colormap.setRed(x, y, 1)
else:
colormap.setGreen(x, y, 1)
colorTexture = Texture()
colorTexture.load(colormap)
colorTS = TextureStage('color')
colorTS.setSort(0)
colorTS.setPriority(1)
self.colorTextures.append((colorTexture, colorTS))
示例2: loadSpriteImages
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import addAlpha [as 别名]
def loadSpriteImages(self,file_path,cols,rows,flipx = False,flipy = False):
"""
Loads an image file containing individual animation frames and returns then in a list of PNMImages
inputs:
- file_path
- cols
- rows
- flipx
- flipy
Output:
- tuple ( bool , list[PNMImage] )
"""
# Make a filepath
image_file = Filename(file_path)
if image_file .empty():
raise IOError("File not found")
return (False, [])
# Instead of loading it outright, check with the PNMImageHeader if we can open
# the file.
img_head = PNMImageHeader()
if not img_head.readHeader(image_file ):
raise IOError("PNMImageHeader could not read file %s. Try using absolute filepaths"%(file_path))
return (False, [])
# Load the image with a PNMImage
full_image = PNMImage(img_head.getXSize(),img_head.getYSize())
full_image.alphaFill(0)
full_image.read(image_file)
if flipx or flipy:
full_image.flip(flipx,flipy,False)
w = int(full_image.getXSize()/cols)
h = int(full_image.getYSize()/rows)
images = []
counter = 0
for i in range(0,cols):
for j in range(0,rows):
sub_img = PNMImage(w,h)
sub_img.addAlpha()
sub_img.alphaFill(0)
sub_img.fill(1,1,1)
sub_img.copySubImage(full_image ,0 ,0 ,i*w ,j*h ,w ,h)
images.append(sub_img)
return (True, images)
示例3: transparencyKey
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import addAlpha [as 别名]
def transparencyKey(filename):
image = PNMImage(GAME+'/textures/effects/'+filename)
image.addAlpha()
backgroundColor = None
for y in range(image.getYSize()):
for x in range(image.getXSize()):
if backgroundColor == None:
backgroundColor = Color(image.getRedVal(x, y), image.getGreenVal(x, y), image.getGreenVal(x, y), 0)
if image.getRedVal(x, y) == backgroundColor.R and \
image.getGreenVal(x, y) == backgroundColor.G and \
image.getGreenVal(x, y) == backgroundColor.B:
# Transparent
image.setAlpha(x, y, 0.0)
else:
# Opaque
image.setAlpha(x, y, 1.0)
return image
示例4: createSequenceNode
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import addAlpha [as 别名]
def createSequenceNode(self,name,img,cols,rows,scale_x,scale_y,frame_rate):
seq = SequenceNode(name)
w = int(img.getXSize()/cols)
h = int(img.getYSize()/rows)
counter = 0
for i in range(0,cols):
for j in range(0,rows):
sub_img = PNMImage(w,h)
sub_img.addAlpha()
sub_img.alphaFill(0)
sub_img.fill(1,1,1)
sub_img.copySubImage(img ,0 ,0 ,i*w ,j*h ,w ,h)
# Load the image onto the texture
texture = Texture()
texture.setXSize(w)
texture.setYSize(h)
texture.setZSize(1)
texture.load(sub_img)
texture.setWrapU(Texture.WM_border_color) # gets rid of odd black edges around image
texture.setWrapV(Texture.WM_border_color)
texture.setBorderColor(LColor(0,0,0,0))
cm = CardMaker(name + '_' + str(counter))
cm.setFrame(-0.5*scale_x,0.5*scale_x,-0.5*scale_y,0.5*scale_y)
card = NodePath(cm.generate())
seq.addChild(card.node(),counter)
card.setTexture(texture)
sub_img.clear()
counter+=1
seq.setFrameRate(frame_rate)
print "Sequence Node %s contains %i frames of size %s"%(name,seq.getNumFrames(),str((w,h)))
return seq
示例5: Typist
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import addAlpha [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))
#.........这里部分代码省略.........
示例6: generateWorld
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import addAlpha [as 别名]
def generateWorld(self, heightmap, tiles, cities, container):
self.heightmap = heightmap
self.terrain = PagedGeoMipTerrain("surface")
#self.terrain = GeoMipTerrain("surface")
self.terrain.setHeightfield(self.heightmap)
#self.terrain.setFocalPoint(base.camera)
self.terrain.setBruteforce(True)
self.terrain.setBlockSize(64)
self.terrain.generate()
root = self.terrain.getRoot()
root.reparentTo(render)
#root.setSz(100)
self.terrain.setSz(100)
messenger.send('makePickable', [root])
if self.heightmap.getXSize() > self.heightmap.getYSize():
self.size = self.heightmap.getXSize()-1
else:
self.size = self.heightmap.getYSize()-1
self.xsize = self.heightmap.getXSize()-1
self.ysize = self.heightmap.getYSize()-1
# Set multi texture
# Source http://www.panda3d.org/phpbb2/viewtopic.php?t=4536
self.generateSurfaceTextures()
self.generateWaterMap()
self.generateOwnerTexture(tiles, cities)
#self.terrain.makeTextureMap()
colormap = PNMImage(heightmap.getXSize()-1, heightmap.getYSize()-1)
colormap.addAlpha()
slopemap = self.terrain.makeSlopeImage()
for x in range(0, colormap.getXSize()):
for y in range(0, colormap.getYSize()):
# Else if statements used to make sure one channel is used per pixel
# Also for some optimization
# Snow. We do things funky here as alpha will be 1 already.
if heightmap.getGrayVal(x, y) < 200:
colormap.setAlpha(x, y, 0)
else:
colormap.setAlpha(x, y, 1)
# Beach. Estimations from http://www.simtropolis.com/omnibus/index.cfm/Main.SimCity_4.Custom_Content.Custom_Terrains_and_Using_USGS_Data
if heightmap.getGrayVal(x,y) < 62:
colormap.setBlue(x, y, 1)
# Rock
elif slopemap.getGrayVal(x, y) > 170:
colormap.setRed(x, y, 1)
else:
colormap.setGreen(x, y, 1)
self.colorTexture = Texture()
self.colorTexture.load(colormap)
self.colorTS = TextureStage('color')
self.colorTS.setSort(0)
self.colorTS.setPriority(1)
self.setSurfaceTextures()
self.generateWater(2)
taskMgr.add(self.updateTerrain, "updateTerrain")
print "Done with terrain generation"
messenger.send("finishedTerrainGen", [[self.xsize, self.ysize]])
self.terrain.getRoot().analyze()
self.accept("h", self.switchWater)