本文整理汇总了Python中panda3d.core.PNMImage.setRed方法的典型用法代码示例。如果您正苦于以下问题:Python PNMImage.setRed方法的具体用法?Python PNMImage.setRed怎么用?Python PNMImage.setRed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.PNMImage
的用法示例。
在下文中一共展示了PNMImage.setRed方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeTextureMap
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import setRed [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: GPUFFT
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import setRed [as 别名]
#.........这里部分代码省略.........
val = (val << 1) | t
temp = temp >> 1
indices[j] = val
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
示例3: generateWorld
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import setRed [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)