本文整理汇总了Python中panda3d.core.PNMImage.setAlpha方法的典型用法代码示例。如果您正苦于以下问题:Python PNMImage.setAlpha方法的具体用法?Python PNMImage.setAlpha怎么用?Python PNMImage.setAlpha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.PNMImage
的用法示例。
在下文中一共展示了PNMImage.setAlpha方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeTextureMap
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import setAlpha [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: transparencyKey
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import setAlpha [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
示例3: GPUFFT
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import setAlpha [as 别名]
#.........这里部分代码省略.........
def _computeWeighting(self):
""" Precomputes the weights & indices, and stores them in a texture """
indicesA = [[0 for i in xrange(self.size)]
for k in xrange(self.log2Size)]
indicesB = [[0 for i in xrange(self.size)]
for k in xrange(self.log2Size)]
weights = [[Vec2(0.0) for i in xrange(self.size)]
for k in xrange(self.log2Size)]
self.debug("Pre-Generating indices ..")
self._generateIndices(indicesA, indicesB)
self._reverseRow(indicesA[0])
self._reverseRow(indicesB[0])
self.debug("Pre-Generating weights ..")
self._generateWeights(weights)
# Create storage for the weights & indices
self.weightsLookup = PNMImage(self.size, self.log2Size, 4)
self.weightsLookup.setMaxval((2 ** 16) - 1)
self.weightsLookup.fill(0.0)
# Populate storage
for x in xrange(self.size):
for y in xrange(self.log2Size):
indexA = indicesA[y][x]
indexB = indicesB[y][x]
weight = weights[y][x]
self.weightsLookup.setRed(x, y, indexA / float(self.size))
self.weightsLookup.setGreen(x, y, indexB / float(self.size))
self.weightsLookup.setBlue(x, y, weight.x * 0.5 + 0.5)
self.weightsLookup.setAlpha(x, y, weight.y * 0.5 + 0.5)
# Convert storage to texture so we can use it in a shader
self.weightsLookupTex = Texture("Weights Lookup")
self.weightsLookupTex.load(self.weightsLookup)
self.weightsLookupTex.setFormat(Texture.FRgba16)
self.weightsLookupTex.setMinfilter(Texture.FTNearest)
self.weightsLookupTex.setMagfilter(Texture.FTNearest)
self.weightsLookupTex.setWrapU(Texture.WMClamp)
self.weightsLookupTex.setWrapV(Texture.WMClamp)
def _prepareAttributes(self):
""" Prepares all shaderAttributes, so that we have a list of
ShaderAttributes we can simply walk through in the update method,
that is MUCH faster than using setShaderInput, as each call to
setShaderInput forces the generation of a new ShaderAttrib """
self.attributes = []
textures = [self.pingTexture, self.pongTexture]
currentIndex = 0
firstPass = True
# Horizontal
for step in xrange(self.log2Size):
source = textures[currentIndex]
dest = textures[1 - currentIndex]
if firstPass:
source = self.sourceTex
firstPass = False
index = self.log2Size - step - 1
self.horizontalFFT.setShaderInput("source", source)
示例4: WaterManager
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import setAlpha [as 别名]
class WaterManager(DebugObject):
""" Simple wrapper arround WaterDisplacement which combines 3 displacement
maps into one, and also generates a normal map """
def __init__(self):
DebugObject.__init__(self, "WaterManager")
self.options = OceanOptions()
self.options.size = 512
self.options.windDir.normalize()
self.options.waveAmplitude *= 1e-7
self.displacementTex = Texture("Displacement")
self.displacementTex.setup2dTexture(
self.options.size, self.options.size,
Texture.TFloat, Texture.FRgba16)
self.normalTex = Texture("Normal")
self.normalTex.setup2dTexture(
self.options.size, self.options.size,
Texture.TFloat, Texture.FRgba16)
self.combineShader = Shader.loadCompute(Shader.SLGLSL,
"Shader/WaterFFT/Combine.compute")
self.ptaTime = PTAFloat.emptyArray(1)
# Create a gaussian random texture, as shaders aren't well suited
# for that
setRandomSeed(523)
self.randomStorage = PNMImage(self.options.size, self.options.size, 4)
self.randomStorage.setMaxval((2 ** 16) - 1)
for x in xrange(self.options.size):
for y in xrange(self.options.size):
rand1 = self._getGaussianRandom() / 10.0 + 0.5
rand2 = self._getGaussianRandom() / 10.0 + 0.5
self.randomStorage.setXel(x, y, float(rand1), float(rand2), 0)
self.randomStorage.setAlpha(x, y, 1.0)
self.randomStorageTex = Texture("RandomStorage")
self.randomStorageTex.load(self.randomStorage)
self.randomStorageTex.setFormat(Texture.FRgba16)
self.randomStorageTex.setMinfilter(Texture.FTNearest)
self.randomStorageTex.setMagfilter(Texture.FTNearest)
# Create the texture wwhere the intial height (H0 + Omega0) is stored.
self.texInitialHeight = Texture("InitialHeight")
self.texInitialHeight.setup2dTexture(
self.options.size, self.options.size,
Texture.TFloat, Texture.FRgba16)
self.texInitialHeight.setMinfilter(Texture.FTNearest)
self.texInitialHeight.setMagfilter(Texture.FTNearest)
# Create the shader which populates the initial height texture
self.shaderInitialHeight = Shader.loadCompute(Shader.SLGLSL,
"Shader/WaterFFT/InitialHeight.compute")
self.nodeInitialHeight = NodePath("initialHeight")
self.nodeInitialHeight.setShader(self.shaderInitialHeight)
self.nodeInitialHeight.setShaderInput("dest", self.texInitialHeight)
self.nodeInitialHeight.setShaderInput(
"N", LVecBase2i(self.options.size))
self.nodeInitialHeight.setShaderInput(
"patchLength", self.options.patchLength)
self.nodeInitialHeight.setShaderInput("windDir", self.options.windDir)
self.nodeInitialHeight.setShaderInput(
"windSpeed", self.options.windSpeed)
self.nodeInitialHeight.setShaderInput(
"waveAmplitude", self.options.waveAmplitude)
self.nodeInitialHeight.setShaderInput(
"windDependency", self.options.windDependency)
self.nodeInitialHeight.setShaderInput(
"randomTex", self.randomStorageTex)
self.attrInitialHeight = self.nodeInitialHeight.getAttrib(ShaderAttrib)
self.heightTextures = []
for i in xrange(3):
tex = Texture("Height")
tex.setup2dTexture(self.options.size, self.options.size,
Texture.TFloat, Texture.FRgba16)
tex.setMinfilter(Texture.FTNearest)
tex.setMagfilter(Texture.FTNearest)
tex.setWrapU(Texture.WMClamp)
tex.setWrapV(Texture.WMClamp)
self.heightTextures.append(tex)
# Also create the shader which updates the spectrum
self.shaderUpdate = Shader.loadCompute(Shader.SLGLSL,
"Shader/WaterFFT/Update.compute")
self.nodeUpdate = NodePath("update")
self.nodeUpdate.setShader(self.shaderUpdate)
self.nodeUpdate.setShaderInput("outH0x", self.heightTextures[0])
self.nodeUpdate.setShaderInput("outH0y", self.heightTextures[1])
self.nodeUpdate.setShaderInput("outH0z", self.heightTextures[2])
self.nodeUpdate.setShaderInput("initialHeight", self.texInitialHeight)
self.nodeUpdate.setShaderInput("N", LVecBase2i(self.options.size))
self.nodeUpdate.setShaderInput("time", self.ptaTime)
self.attrUpdate = self.nodeUpdate.getAttrib(ShaderAttrib)
#.........这里部分代码省略.........
示例5: generateWorld
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import setAlpha [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)