本文整理汇总了Python中panda3d.core.PNMImage.setXel方法的典型用法代码示例。如果您正苦于以下问题:Python PNMImage.setXel方法的具体用法?Python PNMImage.setXel怎么用?Python PNMImage.setXel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.PNMImage
的用法示例。
在下文中一共展示了PNMImage.setXel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: WaterManager
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import setXel [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)
#.........这里部分代码省略.........
示例2: generateNode
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import setXel [as 别名]
def generateNode(self, name, DB, parentNode):
log.debug("Setting up " + name)
bodyEntity = sandbox.createEntity()
component = CelestialComponent()
if DB["type"] == "solid":
body = Body(name)
elif DB["type"] == "moon":
body = Body(name)
body.kind = "moon"
elif DB["type"] == "star":
body = Star(name)
body.absoluteM = DB["absolute magnitude"]
body.spectral = DB["spectral"]
elif DB["type"] == "barycenter":
body = BaryCenter(name)
component.kind = TYPES[DB["type"]]
if DB["type"] != "barycenter":
component.mass = DB["mass"]
body.radius = DB["radius"]
body.rotation = DB["rotation"]
if "orbit" in DB:
component.orbit = DB["orbit"]
body.period = DB["period"]
# body.setPos(self.get2DBodyPosition(component, universals.day))
component.truePos = self.get2DBodyPosition(component, universals.day)
if name == "Earth":
# universals.spawn = component.truePos + LPoint3d(0, 6671, 0)
universals.spawn = component.truePos + LPoint3d(6671, 0, 0)
if parentNode == universals.solarSystemRoot:
universals.defaultSOIid = bodyEntity.id
component.soi = 0
elif DB["type"] != "star" or DB["type"] != "barycenter":
component.soi = self.getSOI(component.mass, self.bodies[0].mass, component.orbit["a"])
body.type = DB["type"]
body.reparentTo(parentNode)
component.nodePath = body
self.bodies.append(component)
bodyEntity.addComponent(component)
if universals.runClient and DB["type"] == "star":
component = graphicsComponents.RenderComponent()
# component.mesh = NodePath(name)
# self.sphere.copyTo(component.mesh)
# component.mesh = shapeGenerator.Sphere(body.radius, 128, name)
component.mesh = shapeGenerator.Sphere(body.radius, 64, name)
# component.mesh.setScale(body.radius)
component.mesh.reparentTo(sandbox.base.render)
sandbox.send("makePickable", [component.mesh])
# texture = sandbox.base.loader.loadTexture('planets/' + DB['texture'])
# texture.setMinfilter(Texture.FTLinearMipmapLinear)
# ts1 = TextureStage('textures1')
# ts1.setMode(TextureStage.MGlow)
# component.mesh.setTexture(ts1, texture)
# component.mesh.setTexture(texture, 1)
component.light = component.mesh.attachNewNode(PointLight("sunPointLight"))
component.light.node().setColor(Vec4(1, 1, 1, 1))
sandbox.base.render.setLight(component.light)
bodyEntity.addComponent(component)
# Shader test
componentStar = graphicsComponents.StarRender()
componentStar.noise_texture = Texture("noise")
componentStar.noise_texture.setup2dTexture()
img = PNMImage(1024, 1024)
for y in range(1024):
for x in range(1024):
img.setXel(x, y, componentStar.noise.noise(x, y))
# print componentStar.noise.noise(x, y)
componentStar.noise_texture.load(img)
# componentStar.noise_texture.write('test.png')
# component.mesh.setTexture(componentStar.noise_texture, 1)
texture = sandbox.base.loader.loadTexture("planets/" + DB["texture"])
ts1 = TextureStage("textures1")
ts1.setMode(TextureStage.MGlow)
component.mesh.setTexture(ts1, componentStar.noise_texture)
# component.mesh.setTexture(ts1, texture)
component.mesh.setShaderInput("time", universals.get_day_in_seconds())
shaders = Shader.load(Shader.SLGLSL, "vortexVertex.glsl", "starFrag.glsl")
component.mesh.setShader(shaders)
sandbox.send("makePickable", [component.mesh])
if universals.runClient and (DB["type"] == "solid" or DB["type"] == "moon"):
component = graphicsComponents.RenderComponent()
# component.mesh = shapeGenerator.Sphere(body.radius, 128, name)
# component.mesh = shapeGenerator.Sphere(body.radius, 64, name)
component.mesh = surface_mesh.make_planet(name=name, scale=body.radius)
# sandbox.send('makePickable', [component.mesh])
sandbox.send("makePickable", [component.mesh.node_path])
# component.mesh.setScale(body.radius)
component.mesh.reparent_to(sandbox.base.render)
# Doing world text
text = TextNode("node name")
#.........这里部分代码省略.........
示例3: fBm
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import setXel [as 别名]
def fBm(x, y, per, octs):
val = 0
for o in range(octs):
val += 0.5**o * noise(x*2**o, y*2**o, per*2**o)
return val
size, freq, octs, data = 128, 1/32.0, 5, []
p = PNMImage(128, 128)
for y in range(size):
for x in range(size):
#data.append(fBm(x*freq, y*freq, int(size*freq), octs))
p.setXel(x, y, fBm(x*freq, y*freq, int(size*freq), octs))
#skysphere.setTexGen(TextureStage.getDefault(), TexGenAttrib.MEyeSphereMap)
tex.load(p)
skysphere.setTexture(tex)
'''skysphere.setTexGen(TextureStage.getDefault(), TexGenAttrib.MWorldPosition)
skysphere.setTexProjector(TextureStage.getDefault(), sandbox.base.render, skysphere)
skysphere.setTexPos(TextureStage.getDefault(), 0.5, 0.5, 0.5)
skysphere.setTexScale(TextureStage.getDefault(), 0.2)
''''''mesh = sandbox.base.loader.loadModel('ships/hyperion/hyperion')
mesh.setScale(0.001)
mesh.reparentTo(sandbox.base.render)''''''
#noise = PerlinNoise3(32, 32, 32, 256, 1)
noise = StackedPerlinNoise3(16, 16, 16, 3, 1, 0.5, 256, 1)
示例4: TerrainManager
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import setXel [as 别名]
#.........这里部分代码省略.........
if x > self.waterXMax:
self.waterXMax = x
if y > self.waterYMin:
self.waterYMin = y
# Transform y coords
self.waterYMin = self.size-64 - self.waterYMin
self.waterYMax = self.size-64 - self.waterYMax
def generateOwnerTexture(self, tiles, cities):
'''Generates a simple colored texture to be applied to the city info region overlay.
Due to different coordinate systems (terrain org bottom left, texture top left)
some conversions are needed,
Also creates and sends a citylabels dict for the region view
'''
self.citymap = PNMImage(self.xsize, self.ysize)
citylabels = cities
scratch = {}
# Setup for city labels
for ident in cities:
scratch[ident] = []
# conversion for y axis
ycon = []
s = self.ysize - 1
for y in range(self.ysize):
ycon.append(s)
s -= 1
for ident, city in cities.items():
if ident not in self.citycolors:
self.citycolors[ident] = VBase3D(random.random(), random.random(), random.random())
for tile in tiles:
self.citymap.setXel(tile.coords[0], ycon[tile.coords[1]], self.citycolors[tile.cityid])
# Scratch for labeling
if tile.cityid:
scratch[tile.cityid].append((tile.coords[0], tile.coords[1]))
for ident, values in scratch.items():
xsum = 0
ysum = 0
n = 0
for coords in values:
xsum += coords[0]
ysum += coords[1]
n += 1
xavg = xsum/n
yavg = ysum/n
print "Elevation:", self.terrain.getElevation(xavg, yavg)
z = self.terrain.getElevation(xavg, yavg)*100
citylabels[ident]["position"] = (xavg, yavg, z+15)
print "Citylabels:", citylabels
messenger.send("updateCityLabels", [citylabels, self.terrain])
def generateSurfaceTextures(self):
# Textureize
self.grassTexture = loader.loadTexture("Textures/grass.png")
self.grassTS = TextureStage('grass')
self.grassTS.setSort(1)
self.rockTexture = loader.loadTexture("Textures/rock.jpg")
self.rockTS = TextureStage('rock')
self.rockTS.setSort(2)
self.rockTS.setCombineRgb(TextureStage.CMAdd, TextureStage.CSLastSavedResult, TextureStage.COSrcColor, TextureStage.CSTexture, TextureStage.COSrcColor)
self.sandTexture = loader.loadTexture("Textures/sand.jpg")
self.sandTS = TextureStage('sand')
示例5: PerlinNoise2
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import setXel [as 别名]
planet.reparentTo(sandbox.base.render)
planet.setPos(5, 20, 0)
mesh = shapeGenerator.Sphere(1, 64, 'star')
mesh.reparentTo(sandbox.base.render)
mesh.setPos(-5, 20, 0)
noise = PerlinNoise2(64, 64)
texture = Texture('noise')
texture.setup2dTexture()
img = PNMImage(1024, 1024)
for y in range(1024):
for x in range(1024):
img.setXel(x, y, noise.noise(x, y))
texture.load(img)
mesh.setTexture(texture, 1)
mesh.setShaderInput('time', 0)
#shaders = Shader.load(Shader.SLGLSL, 'vortexVertex.glsl', 'starFrag2.glsl')
shaders = Shader.load(Shader.SLGLSL, 'sphereVertex.glsl', 'starFrag2.glsl')
mesh.setShader(shaders)
light = mesh.attachNewNode(PointLight("sun"))
light.node().setColor(Vec4(1, 1, 1, 1))
sandbox.base.render.setLight(light)
def time_update(task):
mesh.setShaderInput('time', task.time)
示例6: PNMImage
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import setXel [as 别名]
from panda3d.core import PNMImage, Vec3
lutSize = 32
image = PNMImage(lutSize * lutSize, lutSize, 3, 2**16 - 1)
for r in xrange(lutSize):
for g in xrange(lutSize):
for b in xrange(lutSize):
image.setXel(r + b * lutSize, g, r / float(lutSize), g / float(lutSize), b / float(lutSize))
image.write("Default.png")