本文整理汇总了Python中panda3d.core.Texture.setWrapU方法的典型用法代码示例。如果您正苦于以下问题:Python Texture.setWrapU方法的具体用法?Python Texture.setWrapU怎么用?Python Texture.setWrapU使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.Texture
的用法示例。
在下文中一共展示了Texture.setWrapU方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadFlatQuad
# 需要导入模块: from panda3d.core import Texture [as 别名]
# 或者: from panda3d.core.Texture import setWrapU [as 别名]
def loadFlatQuad(self, fullFilename):
cm = CardMaker('cm-%s' % fullFilename)
cm.setColor(1.0, 1.0, 1.0, 1.0)
aspect = base.camLens.getAspectRatio()
htmlWidth = 2.0 * aspect * WEB_WIDTH_PIXELS / float(WIN_WIDTH)
htmlHeight = 2.0 * float(WEB_HEIGHT_PIXELS) / float(WIN_HEIGHT)
cm.setFrame(-htmlWidth / 2.0, htmlWidth / 2.0, -htmlHeight / 2.0, htmlHeight / 2.0)
bottomRightX = WEB_WIDTH_PIXELS / float(WEB_WIDTH + 1)
bottomRightY = WEB_HEIGHT_PIXELS / float(WEB_HEIGHT + 1)
cm.setUvRange(Point2(0, 1 - bottomRightY), Point2(bottomRightX, 1))
card = cm.generate()
quad = NodePath(card)
jpgFile = PNMImage(WEB_WIDTH, WEB_HEIGHT)
smallerJpgFile = PNMImage()
readFile = smallerJpgFile.read(Filename(fullFilename))
if readFile:
jpgFile.copySubImage(smallerJpgFile, 0, 0)
guiTex = Texture('guiTex')
guiTex.setupTexture(Texture.TT2dTexture, WEB_WIDTH, WEB_HEIGHT, 1, Texture.TUnsignedByte, Texture.FRgba)
guiTex.setMinfilter(Texture.FTLinear)
guiTex.load(jpgFile)
guiTex.setWrapU(Texture.WMClamp)
guiTex.setWrapV(Texture.WMClamp)
ts = TextureStage('webTS')
quad.setTexture(ts, guiTex)
quad.setTransparency(0)
quad.setTwoSided(True)
quad.setColor(1.0, 1.0, 1.0, 1.0)
result = quad
else:
result = None
Texture.setTexturesPower2(1)
return result
示例2: _createMapTextureCard
# 需要导入模块: from panda3d.core import Texture [as 别名]
# 或者: from panda3d.core.Texture import setWrapU [as 别名]
def _createMapTextureCard(self):
mapImage = PNMImage(MAP_RESOLUTION, MAP_RESOLUTION)
mapImage.fill(*self._bgColor)
fgColor = VBase4D(*self._fgColor)
for x in xrange(self._mazeHeight):
for y in xrange(self._mazeWidth):
if self._mazeCollTable[y][x] == 1:
ax = float(x) / self._mazeWidth * MAP_RESOLUTION
invertedY = self._mazeHeight - 1 - y
ay = float(invertedY) / self._mazeHeight * MAP_RESOLUTION
self._drawSquare(mapImage, int(ax), int(ay), 10, fgColor)
mapTexture = Texture('mapTexture')
mapTexture.setupTexture(Texture.TT2dTexture, self._maskResolution, self._maskResolution, 1, Texture.TUnsignedByte, Texture.FRgba)
mapTexture.setMinfilter(Texture.FTLinear)
mapTexture.load(mapImage)
mapTexture.setWrapU(Texture.WMClamp)
mapTexture.setWrapV(Texture.WMClamp)
mapImage.clear()
del mapImage
cm = CardMaker('map_cardMaker')
cm.setFrame(-1.0, 1.0, -1.0, 1.0)
map = self.attachNewNode(cm.generate())
map.setTexture(mapTexture, 1)
return map
示例3: setupBackgroundImage
# 需要导入模块: from panda3d.core import Texture [as 别名]
# 或者: from panda3d.core.Texture import setWrapU [as 别名]
def setupBackgroundImage(self):
image_file = Filename(TestGameBase.__BACKGROUND_IMAGE_PATH__)
# check if image can be loaded
img_head = PNMImageHeader()
if not img_head.readHeader(image_file ):
raise IOError("PNMImageHeader could not read file %s. Try using absolute filepaths"%(image_file.c_str()))
sys.exit()
# Load the image with a PNMImage
w = img_head.getXSize()
h = img_head.getYSize()
img = PNMImage(w,h)
#img.alphaFill(0)
img.read(image_file)
texture = Texture()
texture.setXSize(w)
texture.setYSize(h)
texture.setZSize(1)
texture.load(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))
# creating CardMaker to hold the texture
cm = CardMaker('background')
cm.setFrame(-0.5*w,0.5*w,-0.5*h,0.5*h) # This configuration places the image's topleft corner at the origin (left, right, bottom, top)
background_np = NodePath(cm.generate())
background_np.setTexture(texture)
background_np.reparentTo(self.render)
background_np.setPos(TestGameBase.__BACKGROUND_POSITION__)
background_np.setScale(TestGameBase.__BACKGROUND_SCALE__)
示例4: init
# 需要导入模块: from panda3d.core import Texture [as 别名]
# 或者: from panda3d.core.Texture import setWrapU [as 别名]
def init(self):
""" Initializes the vertex buffers and makes them available as shader
inputs. """
self.vertexBuffers = []
for i in xrange(2):
vertexBuffer = Texture("VertexPositionBuffer-" + str(i))
vertexBuffer.setup2dTexture(self.split, self.maxVertexCount / self.split, Texture.TFloat, Texture.FRgba32)
vertexBuffer.setClearColor(Vec4(0))
vertexBuffer.clearImage()
MemoryMonitor.addTexture("DynamicObjectVtxBuffer"+str(i), vertexBuffer)
Globals.render.setShaderInput("dynamicObjectVtxBuffer"+str(i), vertexBuffer)
BufferViewerGUI.registerTexture("Vtx Positions " + str(i), vertexBuffer)
vertexBuffer.setWrapU(Texture.WMClamp)
vertexBuffer.setWrapV(Texture.WMClamp)
vertexBuffer.setMinfilter(Texture.FTNearest)
vertexBuffer.setMagfilter(Texture.FTNearest)
self.vertexBuffers.append(vertexBuffer)
Globals.render.setShaderInput("dynamicVtxSplit", self.split)
示例5: createSequenceNode
# 需要导入模块: from panda3d.core import Texture [as 别名]
# 或者: from panda3d.core.Texture import setWrapU [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
示例6: __init__
# 需要导入模块: from panda3d.core import Texture [as 别名]
# 或者: from panda3d.core.Texture import setWrapU [as 别名]
#.........这里部分代码省略.........
elif anchorY == self.ALIGN_CENTER:
posTop = -(self.rowSize/2.0/scale)*repeatY
posBottom = (self.rowSize/2.0/scale)*repeatY
elif anchorY == self.ALIGN_TOP:
posTop = -(self.rowSize/scale)*repeatY
posBottom = 0
card.setFrame(posLeft, posRight, posTop, posBottom)
card.setHasUvs(True)
self.card = self.node.attachNewNode(card.generate())
# Since the texture is padded, we need to set up offsets and scales to make
# the texture fit the whole card
self.offsetX = (float(self.colSize)/textureSizeX)
self.offsetY = (float(self.rowSize)/textureSizeY)
self.node.setTexScale(TextureStage.getDefault(), self.offsetX * repeatX, self.offsetY * repeatY)
self.node.setTexOffset(TextureStage.getDefault(), 0, 1-self.offsetY)
self.texture = Texture()
self.texture.setXSize(textureSizeX)
self.texture.setYSize(textureSizeY)
self.texture.setZSize(1)
# Load the padded PNMImage to the texture
self.texture.load(self.paddedImg)
self.texture.setMagfilter(Texture.FTNearest)
self.texture.setMinfilter(Texture.FTNearest)
#Set up texture clamps according to repeats
if repeatX > 1:
self.texture.setWrapU(Texture.WMRepeat)
else:
self.texture.setWrapU(Texture.WMClamp)
if repeatY > 1:
self.texture.setWrapV(Texture.WMRepeat)
else:
self.texture.setWrapV(Texture.WMClamp)
self.node.setTexture(self.texture)
def nextsize(self, num):
""" Finds the next power of two size for the given integer. """
p2x=max(1,log(num,2))
notP2X=modf(p2x)[0]>0
return 2**int(notP2X+p2x)
def setFrame(self, frame=0):
""" Sets the current sprite to the given frame """
self.frameInterrupt = True # A flag to tell the animation task to shut it up ur face
self.currentFrame = frame
self.flipTexture()
def playAnim(self, animName, loop=False):
""" Sets the sprite to animate the given named animation. Booleon to loop animation"""
if hasattr(self, "task"):
#if not self.task.isRemoved():
taskMgr.remove(self.task)
self.frameInterrupt = False # Clear any previous interrupt flags
self.loopAnim = loop
self.currentAnim = self.animations[animName]
self.currentAnim.playhead = 0
self.task = taskMgr.doMethodLater(1.0/self.currentAnim.fps,self.animPlayer, "Animate sprite")
示例7: GlobalIllumination
# 需要导入模块: from panda3d.core import Texture [as 别名]
# 或者: from panda3d.core.Texture import setWrapU [as 别名]
#.........这里部分代码省略.........
self.helperLight.setPos(Vec3(50,50,100))
self.helperLight.setShadowMapResolution(512)
self.helperLight.setFilmSize(math.sqrt( (self.voxelGridSizeWS.x**2) * 2) * 2 )
self.helperLight.setCastsShadows(True)
self.pipeline.addLight(self.helperLight)
self.targetSpace.setShaderInput("giLightUVSize",
float(self.helperLight.shadowResolution) / self.pipeline.settings.shadowAtlasSize)
self._updateGridPos()
def setup(self):
""" Setups everything for the GI to work """
# Create the voxelize pass which is used to voxelize the scene from
# several directions
self.voxelizePass = VoxelizePass()
self.voxelizePass.setVoxelGridResolution(self.voxelGridResolution)
self.voxelizePass.setVoxelGridSize(self.voxelGridSizeWS)
self.voxelizePass.initVoxelStorage()
self.pipeline.getRenderPassManager().registerPass(self.voxelizePass)
# Create 3D Texture which is a copy of the voxel generation grid but
# stable, as the generation grid is updated part by part and that would
# lead to flickering
self.voxelStableTex = Texture("VoxelsStable")
self.voxelStableTex.setup3dTexture(self.voxelGridResolution.x, self.voxelGridResolution.y,
self.voxelGridResolution.z, Texture.TFloat, Texture.FRgba8)
# Set appropriate filter types:
# The stable texture has mipmaps, which are generated during the process.
# This is required for cone tracing.
self.voxelStableTex.setMagfilter(SamplerState.FTLinear)
self.voxelStableTex.setMinfilter(SamplerState.FTLinearMipmapLinear)
self.voxelStableTex.setWrapU(SamplerState.WMBorderColor)
self.voxelStableTex.setWrapV(SamplerState.WMBorderColor)
self.voxelStableTex.setWrapW(SamplerState.WMBorderColor)
self.voxelStableTex.setBorderColor(Vec4(0,0,0,0))
MemoryMonitor.addTexture("Voxel Grid Texture", self.voxelStableTex)
# Setups the render target to convert the voxel grid
self.convertBuffer = RenderTarget("VoxelConvertBuffer")
self.convertBuffer.setSize(self.voxelGridResolution.x, self.voxelGridResolution.y)
self.convertBuffer.setColorWrite(False)
# self.convertBuffer.addColorTexture()
self.convertBuffer.prepareOffscreenBuffer()
self.convertBuffer.setShaderInput("src", self.voxelizePass.getVoxelTex())
self.convertBuffer.setShaderInput("dest", self.voxelStableTex)
self.convertBuffer.setActive(False)
# Store the frame index, we need that to decide which step we are currently
# doing
self.frameIndex = 0
# Create the various render targets to generate the mipmaps of the stable voxel grid
self.mipmapTargets = []
computeSize = LVecBase3i(self.voxelGridResolution)
currentMipmap = 0
while computeSize.z > 1:
computeSize /= 2
target = RenderTarget("GIMiplevel" + str(currentMipmap))
target.setSize(computeSize.x, computeSize.y)
target.setColorWrite(False)
# target.addColorTexture()
target.prepareOffscreenBuffer()
示例8: GPUFFT
# 需要导入模块: from panda3d.core import Texture [as 别名]
# 或者: from panda3d.core.Texture import setWrapU [as 别名]
class GPUFFT(DebugObject):
""" This is a collection of compute shaders to generate the inverse
fft efficiently on the gpu, with butterfly FFT and precomputed weights """
def __init__(self, N, sourceTex, normalizationFactor):
""" Creates a new fft instance. The source texture has to specified
from the begining, as the shaderAttributes are pregenerated for
performance reasons """
DebugObject.__init__(self, "GPU-FFT")
self.size = N
self.log2Size = int(math.log(N, 2))
self.normalizationFactor = normalizationFactor
# Create a ping and a pong texture, because we can't write to the
# same texture while reading to it (that would lead to unexpected
# behaviour, we could solve that by using an appropriate thread size,
# but it works fine so far)
self.pingTexture = Texture("FFTPing")
self.pingTexture.setup2dTexture(
self.size, self.size, Texture.TFloat, Texture.FRgba32)
self.pongTexture = Texture("FFTPong")
self.pongTexture.setup2dTexture(
self.size, self.size, Texture.TFloat, Texture.FRgba32)
self.sourceTex = sourceTex
for tex in [self.pingTexture, self.pongTexture, sourceTex]:
tex.setMinfilter(Texture.FTNearest)
tex.setMagfilter(Texture.FTNearest)
tex.setWrapU(Texture.WMClamp)
tex.setWrapV(Texture.WMClamp)
# Pregenerate weights & indices for the shaders
self._computeWeighting()
# Pre generate the shaders, we have 2 passes: Horizontal and Vertical
# which both execute log2(N) times with varying radii
self.horizontalFFTShader = BetterShader.loadCompute(
"Shader/Water/HorizontalFFT.compute")
self.horizontalFFT = NodePath("HorizontalFFT")
self.horizontalFFT.setShader(self.horizontalFFTShader)
self.horizontalFFT.setShaderInput(
"precomputedWeights", self.weightsLookupTex)
self.horizontalFFT.setShaderInput("N", LVecBase2i(self.size))
self.verticalFFTShader = BetterShader.loadCompute(
"Shader/Water/VerticalFFT.compute")
self.verticalFFT = NodePath("VerticalFFT")
self.verticalFFT.setShader(self.verticalFFTShader)
self.verticalFFT.setShaderInput(
"precomputedWeights", self.weightsLookupTex)
self.verticalFFT.setShaderInput("N", LVecBase2i(self.size))
# Create a texture where the result is stored
self.resultTexture = Texture("Result")
self.resultTexture.setup2dTexture(
self.size, self.size, Texture.TFloat, Texture.FRgba16)
self.resultTexture.setMinfilter(Texture.FTLinear)
self.resultTexture.setMagfilter(Texture.FTLinear)
# Prepare the shader attributes, so we don't have to regenerate them
# every frame -> That is VERY slow (3ms per fft instance)
self._prepareAttributes()
def getResultTexture(self):
""" Returns the result texture, only contains valid data after execute
was called at least once """
return self.resultTexture
def _generateIndices(self, storageA, storageB):
""" This method generates the precompute indices, see
http://cnx.org/content/m12012/latest/image1.png """
numIter = self.size
offset = 1
step = 0
for i in xrange(self.log2Size):
numIter = numIter >> 1
step = offset
for j in xrange(self.size):
goLeft = (j / step) % 2 == 1
indexA, indexB = 0, 0
if goLeft:
indexA, indexB = j - step, j
else:
indexA, indexB = j, j + step
storageA[i][j] = indexA
storageB[i][j] = indexB
offset = offset << 1
def _generateWeights(self, storage):
""" This method generates the precomputed weights """
# Using a custom pi variable should force the calculations to use
# high precision (I hope so)
pi = 3.141592653589793238462643383
numIter = self.size / 2
numK = 1
resolutionFloat = float(self.size)
#.........这里部分代码省略.........
示例9: HtmlView
# 需要导入模块: from panda3d.core import Texture [as 别名]
# 或者: from panda3d.core.Texture import setWrapU [as 别名]
class HtmlView(DirectObject):
notify = DirectNotifyGlobal.directNotify.newCategory('HtmlView')
useHalfTexture = base.config.GetBool('news-half-texture', 0)
def __init__(self, parent = aspect2d):
global GlobalWebcore
self.parent_ = parent
self.mx = 0
self.my = 0
self.htmlFile = 'index.html'
self.transparency = False
if GlobalWebcore:
pass
else:
GlobalWebcore = AwWebCore(AwWebCore.LOGVERBOSE, True, AwWebCore.PFBGRA)
GlobalWebcore.setBaseDirectory('.')
for errResponse in xrange(400, 600):
GlobalWebcore.setCustomResponsePage(errResponse, 'error.html')
self.webView = GlobalWebcore.createWebView(WEB_WIDTH, WEB_HEIGHT, self.transparency, False, 70)
frameName = ''
inGameNewsUrl = self.getInGameNewsUrl()
self.imgBuffer = array.array('B')
for i in xrange(WEB_WIDTH * WEB_HEIGHT):
self.imgBuffer.append(0)
self.imgBuffer.append(0)
self.imgBuffer.append(0)
self.imgBuffer.append(255)
if self.useHalfTexture:
self.leftBuffer = array.array('B')
for i in xrange(WEB_HALF_WIDTH * WEB_HEIGHT):
self.leftBuffer.append(0)
self.leftBuffer.append(0)
self.leftBuffer.append(0)
self.leftBuffer.append(255)
self.rightBuffer = array.array('B')
for i in xrange(WEB_HALF_WIDTH * WEB_HEIGHT):
self.rightBuffer.append(0)
self.rightBuffer.append(0)
self.rightBuffer.append(0)
self.rightBuffer.append(255)
self.setupTexture()
if self.useHalfTexture:
self.setupHalfTextures()
self.accept('mouse1', self.mouseDown, [AwWebView.LEFTMOUSEBTN])
self.accept('mouse3', self.mouseDown, [AwWebView.RIGHTMOUSEBTN])
self.accept('mouse1-up', self.mouseUp, [AwWebView.LEFTMOUSEBTN])
self.accept('mouse3-up', self.mouseUp, [AwWebView.RIGHTMOUSEBTN])
def getInGameNewsUrl(self):
result = base.config.GetString('fallback-news-url', 'http://cdn.toontown.disney.go.com/toontown/en/gamenews/')
override = base.config.GetString('in-game-news-url', '')
if override:
self.notify.info('got an override url, using %s for in a game news' % override)
result = override
else:
try:
launcherUrl = base.launcher.getValue('GAME_IN_GAME_NEWS_URL', '')
if launcherUrl:
result = launcherUrl
self.notify.info('got GAME_IN_GAME_NEWS_URL from launcher using %s' % result)
else:
self.notify.info('blank GAME_IN_GAME_NEWS_URL from launcher, using %s' % result)
except:
self.notify.warning('got exception getting GAME_IN_GAME_NEWS_URL from launcher, using %s' % result)
return result
def setupTexture(self):
cm = CardMaker('quadMaker')
cm.setColor(1.0, 1.0, 1.0, 1.0)
aspect = base.camLens.getAspectRatio()
htmlWidth = 2.0 * aspect * WEB_WIDTH_PIXELS / float(WIN_WIDTH)
htmlHeight = 2.0 * float(WEB_HEIGHT_PIXELS) / float(WIN_HEIGHT)
cm.setFrame(-htmlWidth / 2.0, htmlWidth / 2.0, -htmlHeight / 2.0, htmlHeight / 2.0)
bottomRightX = WEB_WIDTH_PIXELS / float(WEB_WIDTH + 1)
bottomRightY = WEB_HEIGHT_PIXELS / float(WEB_HEIGHT + 1)
cm.setUvRange(Point2(0, 1 - bottomRightY), Point2(bottomRightX, 1))
card = cm.generate()
self.quad = NodePath(card)
self.quad.reparentTo(self.parent_)
self.guiTex = Texture('guiTex')
self.guiTex.setupTexture(Texture.TT2dTexture, WEB_WIDTH, WEB_HEIGHT, 1, Texture.TUnsignedByte, Texture.FRgba)
self.guiTex.setMinfilter(Texture.FTLinear)
self.guiTex.setKeepRamImage(True)
self.guiTex.makeRamImage()
self.guiTex.setWrapU(Texture.WMRepeat)
self.guiTex.setWrapV(Texture.WMRepeat)
ts = TextureStage('webTS')
self.quad.setTexture(ts, self.guiTex)
self.quad.setTexScale(ts, 1.0, -1.0)
self.quad.setTransparency(0)
self.quad.setTwoSided(True)
self.quad.setColor(1.0, 1.0, 1.0, 1.0)
self.calcMouseLimits()
def setupHalfTextures(self):
#.........这里部分代码省略.........
示例10: CloudManager
# 需要导入模块: from panda3d.core import Texture [as 别名]
# 或者: from panda3d.core.Texture import setWrapU [as 别名]
class CloudManager(DebugObject):
def __init__(self, pipeline):
""" Creates the manager """
DebugObject.__init__(self, "CloudManager")
self.pipeline = pipeline#
self.create()
def create(self):
""" Creates the passes """
self.cloudStartHeight = 900.0
self.cloudEndHeight = 3300.0
self.cloudResolution = 768
self.cloudResolutionH = 128
self.voxelGrid = Texture("CloudVoxelGrid")
self.voxelGrid.setup3dTexture(self.cloudResolution, self.cloudResolution, self.cloudResolutionH, Texture.TFloat, Texture.FR16)
self.voxelGrid.setWrapU(Texture.WMRepeat)
self.voxelGrid.setWrapV(Texture.WMRepeat)
self.voxelGrid.setWrapW(Texture.WMClamp)
self.cloudNoise = Texture("CloudNoise")
self.cloudNoise.setup3dTexture(64, 64, 64, Texture.TFloat, Texture.FR16)
self.cloudNoise.setWrapU(Texture.WMRepeat)
self.cloudNoise.setWrapV(Texture.WMRepeat)
self.cloudNoise.setWrapW(Texture.WMRepeat)
MemoryMonitor.addTexture("CloudVoxelGrid", self.voxelGrid)
MemoryMonitor.addTexture("CloudNoise", self.cloudNoise)
self._createInitialGrid()
self.renderPass = CloudRenderPass()
self.pipeline.getRenderPassManager().registerPass(self.renderPass)
self.pipeline.getRenderPassManager().registerStaticVariable("cloudVoxelGrid", self.voxelGrid)
self.pipeline.getRenderPassManager().registerStaticVariable("cloudStartHeight", self.cloudStartHeight)
self.pipeline.getRenderPassManager().registerStaticVariable("cloudEndHeight", self.cloudEndHeight)
self.pipeline.getRenderPassManager().registerStaticVariable("cloudNoise", self.cloudNoise)
self.pipeline.getRenderPassManager().registerDefine("CLOUDS_ENABLED", 1)
def update(self):
""" Updates the clouds """
def _createInitialGrid(self):
""" Creates the initial cloud grid """
shader = Shader.loadCompute(Shader.SLGLSL, "Shader/Clouds/InitialGrid.compute")
dummy = NodePath("dummy")
dummy.setShader(shader)
dummy.setShaderInput("cloudGrid", self.voxelGrid)
sattr = dummy.getAttrib(ShaderAttrib)
Globals.base.graphicsEngine.dispatch_compute(
(self.cloudResolution / 8, self.cloudResolution / 8, self.cloudResolutionH / 8), sattr, Globals.base.win.getGsg())
shader = Shader.loadCompute(Shader.SLGLSL, "Shader/Clouds/CloudNoise.compute")
dummy = NodePath("dummy")
dummy.setShader(shader)
dummy.setShaderInput("noiseGrid", self.cloudNoise)
sattr = dummy.getAttrib(ShaderAttrib)
Globals.base.graphicsEngine.dispatch_compute(
(64 / 8, 64 / 8, 64 / 8), sattr, Globals.base.win.getGsg())
示例11: VoxelizePass
# 需要导入模块: from panda3d.core import Texture [as 别名]
# 或者: from panda3d.core.Texture import setWrapU [as 别名]
class VoxelizePass(RenderPass):
""" This pass manages voxelizing the scene from multiple directions to generate
a 3D voxel grid. It handles the camera setup and provides a simple interface. """
def __init__(self):
RenderPass.__init__(self)
def getID(self):
return "VoxelizePass"
def getRequiredInputs(self):
return {
}
def setVoxelGridResolution(self, voxelGridResolution):
""" Sets the voxel grid resolution, this is the amount of voxels in every
direction, so the voxel grid will have voxelGridResolution**3 total voxels. """
self.voxelGridResolution = voxelGridResolution
def setVoxelGridSize(self, voxelGridSize):
""" Sets the size of the voxel grid in world space units. This is the
size going from the mid of the voxel grid, so the effective voxel grid
will have twice the size specified in voxelGridSize """
self.voxelGridSize = voxelGridSize
def setPhotonScaleFactor(self, factor):
""" Sets the density of the photon grid. A number of 1 means that for
every bright voxel 1 photon will be spawned. A number of 4 for example
means that for ever bright voxel 4x4x4 = 64 Photons will be spawned. """
self.photonScaleFactor = factor
def setActive(self, active):
""" Enables and disables this pass """
self.target.setActive(active)
def initVoxelStorage(self):
""" Creates t he 3D Texture to store the voxel generation grid """
self.voxelGenTex = Texture("VoxelsTemp")
self.voxelGenTex.setup3dTexture(self.voxelGridResolution.x, self.voxelGridResolution.y,
self.voxelGridResolution.z, Texture.TInt, Texture.FR32i)
# Set appropriate filter types
self.voxelGenTex.setMinfilter(SamplerState.FTNearest)
self.voxelGenTex.setMagfilter(Texture.FTNearest)
self.voxelGenTex.setWrapU(Texture.WMClamp)
self.voxelGenTex.setWrapV(Texture.WMClamp)
self.voxelGenTex.setWrapW(Texture.WMClamp)
self.voxelGenTex.setClearColor(Vec4(0))
# Register texture
MemoryMonitor.addTexture("Voxel Temp Texture", self.voxelGenTex)
def getVoxelTex(self):
""" Returns a handle to the generated voxel texture """
return self.voxelGenTex
def clearGrid(self):
""" Clears the voxel grid """
self.voxelGenTex.clearImage()
def create(self):
# Create voxelize camera
self.voxelizeCamera = Camera("VoxelizeScene")
self.voxelizeCamera.setCameraMask(BitMask32.bit(4))
self.voxelizeCameraNode = Globals.render.attachNewNode(self.voxelizeCamera)
self.voxelizeLens = OrthographicLens()
self.voxelizeLens.setFilmSize(self.voxelGridSize.x*2, self.voxelGridSize.y*2)
self.voxelizeLens.setNearFar(0.0, self.voxelGridSize.x*2)
self.voxelizeCamera.setLens(self.voxelizeLens)
self.voxelizeCamera.setTagStateKey("VoxelizePassShader")
Globals.render.setTag("VoxelizePassShader", "Default")
# Create voxelize tareet
self.target = RenderTarget("VoxelizePass")
self.target.setSize(self.voxelGridResolution.x * self.photonScaleFactor)
# self.target.setColorWrite(False)
self.target.addColorTexture()
self.target.setCreateOverlayQuad(False)
self.target.setSource(self.voxelizeCameraNode, Globals.base.win)
self.target.prepareSceneRender()
self.target.setActive(False)
self.target.getInternalRegion().setSort(-400)
self.target.getInternalBuffer().setSort(-399)
def voxelizeSceneFromDirection(self, gridPos, direction="x"):
""" Voxelizes the scene from a given direction. This method handles setting
the camera position aswell as the near and far plane. If the pass was disabled,
it also enables this pass. """
assert(direction in "x y z".split())
self.setActive(True)
if direction == "x":
self.voxelizeLens.setFilmSize(self.voxelGridSize.y*2, self.voxelGridSize.z*2)
self.voxelizeLens.setNearFar(0.0, self.voxelGridSize.x*2)
self.voxelizeCameraNode.setPos(gridPos - Vec3(self.voxelGridSize.x, 0, 0))
self.voxelizeCameraNode.lookAt(gridPos)
elif direction == "y":
self.voxelizeLens.setFilmSize(self.voxelGridSize.x*2, self.voxelGridSize.z*2)
#.........这里部分代码省略.........
示例12: __init__
# 需要导入模块: from panda3d.core import Texture [as 别名]
# 或者: from panda3d.core.Texture import setWrapU [as 别名]
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)
# Create 3 FFTs
self.fftX = GPUFFT(self.options.size, self.heightTextures[0],
self.options.normalizationFactor)
self.fftY = GPUFFT(self.options.size, self.heightTextures[1],
#.........这里部分代码省略.........
示例13: setup
# 需要导入模块: from panda3d.core import Texture [as 别名]
# 或者: from panda3d.core.Texture import setWrapU [as 别名]
def setup(self):
""" Setups everything for the GI to work """
assert(self.distributionSteps % 2 == 0)
self._createDebugTexts()
self.pipeline.getRenderPassManager().registerDefine("USE_GLOBAL_ILLUMINATION", 1)
self.pipeline.getRenderPassManager().registerDefine("GI_SLIDE_COUNT", self.slideCount)
self.pipeline.getRenderPassManager().registerDefine("GI_QUALITY_LEVEL", self.qualityLevelIndex)
# make the grid resolution a constant
self.pipeline.getRenderPassManager().registerDefine("GI_GRID_RESOLUTION", self.voxelGridResolution)
self.taskManager.addTask(3, self.stepVoxelize)
self.taskManager.addTask(self.distributionSteps, self.stepDistribute)
# Create the voxelize pass which is used to voxelize the scene from
# several directions
self.voxelizePass = VoxelizePass(self.pipeline)
self.voxelizePass.setVoxelGridResolution(self.voxelGridResolution)
self.voxelizePass.setVoxelGridSize(self.voxelGridSize)
self.voxelizePass.setGridResolutionMultiplier(1)
self.pipeline.getRenderPassManager().registerPass(self.voxelizePass)
self.generationTextures = []
# Create the buffers used to create the voxel grid
for color in "rgb":
tex = Texture("VoxelGeneration-" + color)
tex.setup3dTexture(self.voxelGridResolution, self.voxelGridResolution, self.voxelGridResolution, Texture.TInt, Texture.FR32)
tex.setClearColor(Vec4(0))
self.generationTextures.append(tex)
Globals.render.setShaderInput("voxelGenDest" + color.upper(), tex)
MemoryMonitor.addTexture("VoxelGenerationTex-" + color.upper(), tex)
self.bindTo(Globals.render, "giData")
self.convertGridTarget = RenderTarget("ConvertGIGrid")
self.convertGridTarget.setSize(self.voxelGridResolution * self.slideCount, self.voxelGridResolution * self.slideVertCount)
if self.pipeline.settings.useDebugAttachments:
self.convertGridTarget.addColorTexture()
self.convertGridTarget.prepareOffscreenBuffer()
# Set a near-filter to the texture
if self.pipeline.settings.useDebugAttachments:
self.convertGridTarget.getColorTexture().setMinfilter(Texture.FTNearest)
self.convertGridTarget.getColorTexture().setMagfilter(Texture.FTNearest)
self.clearGridTarget = RenderTarget("ClearGIGrid")
self.clearGridTarget.setSize(self.voxelGridResolution * self.slideCount, self.voxelGridResolution * self.slideVertCount)
if self.pipeline.settings.useDebugAttachments:
self.clearGridTarget.addColorTexture()
self.clearGridTarget.prepareOffscreenBuffer()
for idx, color in enumerate("rgb"):
self.convertGridTarget.setShaderInput("voxelGenSrc" + color.upper(), self.generationTextures[idx])
self.clearGridTarget.setShaderInput("voxelGenTex" + color.upper(), self.generationTextures[idx])
# Create the data textures
self.dataTextures = []
self.directions = ["PosX", "NegX", "PosY", "NegY", "PosZ", "NegZ"]
for i, direction in enumerate(self.directions):
tex = Texture("GIDataTex" + direction)
tex.setup3dTexture(self.voxelGridResolution, self.voxelGridResolution, self.voxelGridResolution, Texture.TFloat, Texture.FR11G11B10)
MemoryMonitor.addTexture("VoxelDataTex-" + direction, tex)
self.dataTextures.append(tex)
self.pipeline.getRenderPassManager().registerStaticVariable("giVoxelData" + direction, tex)
# Create ping / pong textures
self.pingDataTextures = []
self.pongDataTextures = []
for i, direction in enumerate(self.directions):
texPing = Texture("GIPingDataTex" + direction)
texPing.setup3dTexture(self.voxelGridResolution, self.voxelGridResolution, self.voxelGridResolution, Texture.TFloat, Texture.FR11G11B10)
MemoryMonitor.addTexture("VoxelPingDataTex-" + direction, texPing)
self.pingDataTextures.append(texPing)
texPong = Texture("GIPongDataTex" + direction)
texPong.setup3dTexture(self.voxelGridResolution, self.voxelGridResolution, self.voxelGridResolution, Texture.TFloat, Texture.FR11G11B10)
MemoryMonitor.addTexture("VoxelPongDataTex-" + direction, texPong)
self.pongDataTextures.append(texPong)
self.convertGridTarget.setShaderInput("voxelDataDest"+direction, self.pingDataTextures[i])
# self.clearGridTarget.setShaderInput("voxelDataDest" + str(i), self.pongDataTextures[i])
# Set texture wrap modes
for tex in self.pingDataTextures + self.pongDataTextures + self.dataTextures + self.generationTextures:
tex.setMinfilter(Texture.FTLinear)
tex.setMagfilter(Texture.FTLinear)
tex.setWrapU(Texture.WMBorderColor)
tex.setWrapV(Texture.WMBorderColor)
tex.setWrapW(Texture.WMBorderColor)
tex.setAnisotropicDegree(0)
tex.setBorderColor(Vec4(0))
#.........这里部分代码省略.........
示例14: MazeMapGui
# 需要导入模块: from panda3d.core import Texture [as 别名]
# 或者: from panda3d.core.Texture import setWrapU [as 别名]
class MazeMapGui(DirectFrame):
notify = directNotify.newCategory('MazeMapGui')
def __init__(self, mazeCollTable, maskResolution = None, radiusRatio = None, bgColor = (0.8, 0.8, 0.8), fgColor = (0.5, 0.5, 0.5, 1.0)):
DirectFrame.__init__(self, relief=None, state=DGG.NORMAL, sortOrder=DGG.BACKGROUND_SORT_INDEX)
self.hide()
self._bgColor = bgColor
self._fgColor = fgColor
self._mazeCollTable = mazeCollTable
self._mazeWidth = len(self._mazeCollTable[0])
self._mazeHeight = len(self._mazeCollTable)
self._maskResolution = maskResolution or DEFAULT_MASK_RESOLUTION
if radiusRatio is None:
self._radius = self._maskResolution * DEFAULT_RADIUS_RATIO
else:
self._radius = self._maskResolution * radiusRatio
self._revealedCells = []
for y in xrange(self._mazeHeight):
self._revealedCells.append([])
for u in xrange(self._mazeWidth):
self._revealedCells[y].append(False)
self._revealFunctions = {MazeRevealType.SmoothCircle: self._revealSmoothCircle,
MazeRevealType.HardCircle: self._revealHardCircle,
MazeRevealType.Square: self._revealSquare}
self._revealFunction = MAZE_REVEAL_TYPE
self.map = self._createMapTextureCard()
self.map.reparentTo(self)
self.maskedLayer = self.attachNewNode('maskedLayer')
self.mask = self._createMaskTextureCard()
self.mask.reparentTo(self)
self.visibleLayer = self.attachNewNode('visibleLayer')
self._laffMeterModel = loader.loadModel('phase_3/models/gui/laff_o_meter')
self._toon2marker = {}
return
def _createMapTextureCard(self):
mapImage = PNMImage(MAP_RESOLUTION, MAP_RESOLUTION)
mapImage.fill(*self._bgColor)
fgColor = VBase4D(*self._fgColor)
for x in xrange(self._mazeHeight):
for y in xrange(self._mazeWidth):
if self._mazeCollTable[y][x] == 1:
ax = float(x) / self._mazeWidth * MAP_RESOLUTION
invertedY = self._mazeHeight - 1 - y
ay = float(invertedY) / self._mazeHeight * MAP_RESOLUTION
self._drawSquare(mapImage, int(ax), int(ay), 10, fgColor)
mapTexture = Texture('mapTexture')
mapTexture.setupTexture(Texture.TT2dTexture, self._maskResolution, self._maskResolution, 1, Texture.TUnsignedByte, Texture.FRgba)
mapTexture.setMinfilter(Texture.FTLinear)
mapTexture.load(mapImage)
mapTexture.setWrapU(Texture.WMClamp)
mapTexture.setWrapV(Texture.WMClamp)
mapImage.clear()
del mapImage
cm = CardMaker('map_cardMaker')
cm.setFrame(-1.0, 1.0, -1.0, 1.0)
map = self.attachNewNode(cm.generate())
map.setTexture(mapTexture, 1)
return map
def _createMaskTextureCard(self):
self._maskImage = PNMImage(self._maskResolution, self._maskResolution, 4)
for x in xrange(self._maskResolution):
for y in xrange(self._maskResolution):
self._maskImage.setXelA(x, y, 0, 0, 0, 1)
self.maskTexture = Texture('maskTexture')
self.maskTexture.setupTexture(Texture.TT2dTexture, self._maskResolution, self._maskResolution, 1, Texture.TUnsignedByte, Texture.FRgba)
self.maskTexture.setMinfilter(Texture.FTLinear)
self.maskTexture.setWrapU(Texture.WMClamp)
self.maskTexture.setWrapV(Texture.WMClamp)
self.maskTexture.load(self._maskImage)
base.graphicsEngine.renderFrame()
cm = CardMaker('mask_cardMaker')
cm.setFrame(-1.1, 1.1, -1.1, 1.1)
mask = self.attachNewNode(cm.generate())
mask.setTexture(self.maskTexture, 1)
mask.setTransparency(1)
return mask
def _drawSquare(self, image, ulx, uly, size, color):
x = int(ulx)
while x <= ulx + size:
y = int(uly)
while y <= uly + size:
if x > 0 and y > 0 and x < image.getXSize() and y < image.getYSize():
image.setXelA(x, y, color)
y += 1
x += 1
def destroy(self):
del self._mazeCollTable
del self._maskResolution
del self._radius
del self._revealedCells
del self._revealFunctions
del self._revealFunction
#.........这里部分代码省略.........
示例15: PlayerBase
# 需要导入模块: from panda3d.core import Texture [as 别名]
# 或者: from panda3d.core.Texture import setWrapU [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)
#.........这里部分代码省略.........