本文整理汇总了Python中panda3d.core.PNMImage.copySubImage方法的典型用法代码示例。如果您正苦于以下问题:Python PNMImage.copySubImage方法的具体用法?Python PNMImage.copySubImage怎么用?Python PNMImage.copySubImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.PNMImage
的用法示例。
在下文中一共展示了PNMImage.copySubImage方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadFlatQuad
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import copySubImage [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: generate
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import copySubImage [as 别名]
def generate(self):
'''(Re)generate the entire terrain erasing any current changes'''
factor = self.blockSize*self.chunkSize
#print "Factor:", factor
for terrain in self.terrains:
terrain.getRoot().removeNode()
self.terrains = []
# Breaking master heightmap into subimages
heightmaps = []
self.xchunks = (self.heightfield.getXSize()-1)/factor
self.ychunks = (self.heightfield.getYSize()-1)/factor
#print "X,Y chunks:", self.xchunks, self.ychunks
n = 0
for y in range(0, self.ychunks):
for x in range(0, self.xchunks):
heightmap = PNMImage(factor+1, factor+1)
heightmap.copySubImage(self.heightfield, 0, 0, xfrom = x*factor, yfrom = y*factor)
heightmaps.append(heightmap)
n += 1
# Generate GeoMipTerrains
n = 0
y = self.ychunks-1
x = 0
for heightmap in heightmaps:
terrain = GeoMipTerrain(str(n))
terrain.setHeightfield(heightmap)
terrain.setBruteforce(self.bruteForce)
terrain.setBlockSize(self.blockSize)
terrain.generate()
self.terrains.append(terrain)
root = terrain.getRoot()
root.reparentTo(self.root)
root.setPos(n%self.xchunks*factor, (y)*factor, 0)
# In order to texture span properly we need to reiterate through every vertex
# and redefine the uv coordinates based on our size, not the subGeoMipTerrain's
root = terrain.getRoot()
children = root.getChildren()
for child in children:
geomNode = child.node()
for i in range(geomNode.getNumGeoms()):
geom = geomNode.modifyGeom(i)
vdata = geom.modifyVertexData()
texcoord = GeomVertexWriter(vdata, 'texcoord')
vertex = GeomVertexReader(vdata, 'vertex')
while not vertex.isAtEnd():
v = vertex.getData3f()
t = texcoord.setData2f((v[0]+ self.blockSize/2 + self.blockSize*x)/(self.xsize - 1),
(v[1] + self.blockSize/2 + self.blockSize*y)/(self.ysize - 1))
x += 1
if x >= self.xchunks:
x = 0
y -= 1
n += 1
示例3: makeSlopeImage
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import copySubImage [as 别名]
def makeSlopeImage(self):
'''Returns a greyscale PNMImage containing the slope angles.
This is composited from the assorted GeoMipTerrains.'''
slopeImage = PNMImage(self.heightfield.getXSize(), self.heightfield.getYSize())
factor = self.blockSize*self.chunkSize
n = 0
for y in range(0, self.ychunks):
for x in range(0, self.xchunks):
slopei = self.terrains[n].makeSlopeImage()
#slopeImage.copySubImage(slopei, x*factor, y*factor, 0, 0)
slopeImage.copySubImage(slopei, x*factor, y*factor)
n += 1
return slopeImage
示例4: loadSpriteImages
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import copySubImage [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)
示例5: createSequenceNode
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import copySubImage [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: HtmlView
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import copySubImage [as 别名]
#.........这里部分代码省略.........
ll.setZ(ll.getZ() + offset.getZ())
ur.setZ(ur.getZ() + offset.getZ())
self.notify.debug('new LL=%s, UR=%s' % (ll, ur))
relPointll = self.quad.getRelativePoint(aspect2d, ll)
self.notify.debug('relPoint = %s' % relPointll)
self.mouseLL = (aspect2d.getScale()[0] * ll[0], aspect2d.getScale()[2] * ll[2])
self.mouseUR = (aspect2d.getScale()[0] * ur[0], aspect2d.getScale()[2] * ur[2])
self.notify.debug('original mouseLL=%s, mouseUR=%s' % (self.mouseLL, self.mouseUR))
def writeTex(self, filename = 'guiText.png'):
self.notify.debug('writing texture')
self.guiTex.generateRamMipmapImages()
self.guiTex.write(filename)
def toggleRotation(self):
if self.interval.isPlaying():
self.interval.finish()
else:
self.interval.loop()
def mouseDown(self, button):
messenger.send('wakeup')
self.webView.injectMouseDown(button)
def mouseUp(self, button):
self.webView.injectMouseUp(button)
def reload(self):
pass
def zoomIn(self):
self.webView.zoomIn()
def zoomOut(self):
self.webView.zoomOut()
def toggleTransparency(self):
self.transparency = not self.transparency
self.webView.setTransparent(self.transparency)
def update(self, task):
if base.mouseWatcherNode.hasMouse():
x, y = self._translateRelativeCoordinates(base.mouseWatcherNode.getMouseX(), base.mouseWatcherNode.getMouseY())
if self.mx - x != 0 or self.my - y != 0:
self.webView.injectMouseMove(x, y)
self.mx, self.my = x, y
if self.webView.isDirty():
self.webView.render(self.imgBuffer.buffer_info()[0], WEB_WIDTH * 4, 4)
Texture.setTexturesPower2(2)
textureBuffer = self.guiTex.modifyRamImage()
textureBuffer.setData(self.imgBuffer.tostring())
if self.useHalfTexture:
self.guiTex.store(self.fullPnmImage)
self.leftPnmImage.copySubImage(self.fullPnmImage, 0, 0, 0, 0, WEB_HALF_WIDTH, WEB_HEIGHT)
self.rightPnmImage.copySubImage(self.fullPnmImage, 0, 0, WEB_HALF_WIDTH, 0, WEB_HALF_WIDTH, WEB_HEIGHT)
self.leftGuiTex.load(self.leftPnmImage)
self.rightGuiTex.load(self.rightPnmImage)
self.quad.hide()
Texture.setTexturesPower2(1)
GlobalWebcore.update()
return Task.cont
def _translateRelativeCoordinates(self, x, y):
sx = int((x - self.mouseLL[0]) / (self.mouseUR[0] - self.mouseLL[0]) * WEB_WIDTH_PIXELS)
sy = WEB_HEIGHT_PIXELS - int((y - self.mouseLL[1]) / (self.mouseUR[1] - self.mouseLL[1]) * WEB_HEIGHT_PIXELS)
return (sx, sy)
def unload(self):
self.ignoreAll()
self.webView.destroy()
self.webView = None
return
def onCallback(self, name, args):
if name == 'requestFPS':
pass
def onBeginNavigation(self, url, frameName):
pass
def onBeginLoading(self, url, frameName, statusCode, mimeType):
pass
def onFinishLoading(self):
self.notify.debug('finished loading')
def onReceiveTitle(self, title, frameName):
pass
def onChangeTooltip(self, tooltip):
pass
def onChangeCursor(self, cursor):
pass
def onChangeKeyboardFocus(self, isFocused):
pass
def onChangeTargetURL(self, url):
pass
示例7: Typist
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import copySubImage [as 别名]
#.........这里部分代码省略.........
: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))
# always draw onto the paper, to capture
# incremental character overstrikes
self.pnmFont.generateInto(ch, self.texImage, x, y)
if False:
#print ch,"to",x,y,"w=",g.getWidth()
self.tex.load(self.texImage)
else:
# copy an area (presumably) encompassing the character
g = self.pnmFont.getGlyph(ord(ch))
cx, cy = self.fontCharSize
# a glyph is minimally sized and "moves around" in its text box
# (think ' vs. ,), so it has been drawn somewhere relative to
# the 'x' and 'y' we wanted.
x += g.getLeft()
y -= g.getTop()
self.chImage.copySubImage(
self.texImage,
0, 0, # from
x, y, # to
cx, cy # size
)
self.tex.loadSubImage(self.chImage, x, y)
# toggle for a typewriter that uses non-proportional spacing
#w = self.paperCharWidth(g.getWidth())
w = self.paperCharWidth()
else:
w = self.paperCharWidth()
return w, h
def start(self):
self.target = None
self.setTarget('paper')
self.hookKeyboard()
def createRollerBase(self):
""" The paper moves such that it is tangent to the roller.
This nodepath keeps a coordinate space relative to that, so that
the paper can be positioned from (0,0,0) to (0,0,1) to "roll" it
along the roller.
"""
示例8: __init__
# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import copySubImage [as 别名]
def __init__(self, pipeline):
DebugObject.__init__(self, "BugReporter")
self.debug("Creating bug report")
reportDir = "BugReports/" + str(int(time.time())) + "/"
reportFname = "BugReports/" + str(int(time.time())) + ""
if not isdir(reportDir):
os.makedirs(reportDir)
# Generate general log
DebugLog = "Pipeline Bug-Report\n"
DebugLog += "Created: " + datetime.datetime.now().isoformat() + "\n"
DebugLog += "System: " + sys.platform + " / " + os.name + " (" + str(8 * struct.calcsize("P")) + " Bit)\n"
with open(join(reportDir, "general.log"), "w") as handle:
handle.write(DebugLog)
# Write stdout and stderr
with open(join(reportDir, "stdout.log"), "w") as handle:
handle.write(sys.stdout.getLog())
with open(join(reportDir, "stderr.log"), "w") as handle:
handle.write(sys.stderr.getLog())
# Write the scene graph
handle = OFileStream(join(reportDir, "scene_graph.log"))
Globals.render.ls(handle)
handle.close()
# Write the pipeline settings
SettingLog = "# Pipeline Settings Diff File:\n\n"
for key, val in pipeline.settings.settings.iteritems():
if val.value != val.default:
SettingLog += key + " = " + str(val.value) + " (Default " + str(val.default) + ")\n"
with open(join(reportDir, "pipeline.ini"), "w") as handle:
handle.write(SettingLog)
# Write the panda settings
handle = OFileStream(join(reportDir, "pandacfg.log"))
ConfigVariableManager.getGlobalPtr().writePrcVariables(handle)
handle.close()
# Write lights and shadow sources
with open(join(reportDir, "lights.log"), "w") as handle:
pp = pprint.PrettyPrinter(indent=4, stream=handle)
handle.write("\nLights:\n")
pp.pprint(pipeline.lightManager.lightSlots)
handle.write("\n\nShadowSources:\n")
pp.pprint(pipeline.lightManager.shadowSourceSlots)
# Extract buffers
bufferDir = join(reportDir, "buffers")
if not isdir(bufferDir):
os.makedirs(bufferDir)
for name, (size, entry) in MemoryMonitor.memoryEntries.iteritems():
if type(entry) == Texture:
w, h = entry.getXSize(), entry.getYSize()
# Ignore buffers
if h < 2:
continue
pipeline.showbase.graphicsEngine.extractTextureData(entry, pipeline.showbase.win.getGsg())
if not entry.hasRamImage():
print "Ignoring", name
continue
pnmSrc = PNMImage(w, h, 4, 2 ** 16 - 1)
entry.store(pnmSrc)
pnmColor = PNMImage(w, h, 3, 2 ** 16 - 1)
pnmColor.copySubImage(pnmSrc, 0, 0, 0, 0, w, h)
pnmColor.write(join(bufferDir, name + "-color.png"))
pnmAlpha = PNMImage(w, h, 3, 2 ** 16 - 1)
pnmAlpha.copyChannel(pnmSrc, 3, 0)
pnmAlpha.write(join(bufferDir, name + "-alpha.png"))
shutil.make_archive(reportFname, "zip", reportDir)
shutil.rmtree(reportDir)
self.debug("Bug report saved: ", reportFname + ".zip")