当前位置: 首页>>代码示例>>Python>>正文


Python Texture.load方法代码示例

本文整理汇总了Python中pandac.PandaModules.Texture.load方法的典型用法代码示例。如果您正苦于以下问题:Python Texture.load方法的具体用法?Python Texture.load怎么用?Python Texture.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandac.PandaModules.Texture的用法示例。


在下文中一共展示了Texture.load方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _createMapTextureCard

# 需要导入模块: from pandac.PandaModules import Texture [as 别名]
# 或者: from pandac.PandaModules.Texture import load [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
开发者ID:Keithybub,项目名称:ToonTownReviveOld,代码行数:27,代码来源:MazeMapGui.py

示例2: loadFlatQuad

# 需要导入模块: from pandac.PandaModules import Texture [as 别名]
# 或者: from pandac.PandaModules.Texture import load [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
开发者ID:BmanGames,项目名称:Toontown-Level-Editor,代码行数:35,代码来源:IssueFrame.py

示例3: make

# 需要导入模块: from pandac.PandaModules import Texture [as 别名]
# 或者: from pandac.PandaModules.Texture import load [as 别名]
	def make(self):
		TerrainTile.make(self)
		self.makeSlopeMap()
		textureMapper = self.terrain.texturer.textureMapper
		
		#try to read textureMaps
		readTexMaps = True
		texNum = 0
		for tex in textureMapper.textures:
			texNum += 1
			fileName = "maps/textures/" + self.name + "+_texture" + str(texNum) + ".png"
			if not tex.image.read(Filename(fileName)):
				readTexMaps = False
				
		#otherwise calculate textureMaps
		if not readTexMaps:
			self.terrain.texturer.textureMapper.calculateTextures(self)
			
		#copy textureMaps to this terrainTile and save if necessary
		texNum = 0
		for tex in self.terrain.texturer.textureMapper.textures:
			texNum += 1
			self.textureMaps.append(tex.image)
			if not readTexMaps:
				tex.image.write(Filename("maps/textures/" + self.name + "+_texture" + str(texNum) + ".png"))
				
		#load textureMaps as actual textures for the shaders use
		num = 0
		for tex in self.textureMaps:
			num += 1
			newTexture = Texture()
			newTexture.load(tex)
			ts = TextureStage('alp' + str(num))
			self.getRoot().setTexture(ts, newTexture)
开发者ID:Vetrik,项目名称:python-utils,代码行数:36,代码来源:terraintile.py

示例4: PerlinTest

# 需要导入模块: from pandac.PandaModules import Texture [as 别名]
# 或者: from pandac.PandaModules.Texture import load [as 别名]
class PerlinTest(DirectObject):
	
	
	def __init__(self):
		self.myTexture = Texture()
		self.imageObject = OnscreenImage(image = self.myTexture, pos = (0, 0, 0))
		self.run()
		self.accept("arrow_up", self.run)
		
	
	def run(self):
		size = 1024
		j = random.random()
		p1 = Perlin.Perlin( persistance = 0.500, smooth = False, seed = j )
		p2 = Perlin.Perlin( persistance = 0.000, smooth = False, seed = j )
		pb = Perlin.Perlin( persistance = 0.500, smooth = False, seed = random.random() )
		myImage = p1.imgNoise2D(size,True)
		myImage2 = p2.imgNoise2D(size,True)
		myImage3 = pb.imgNoise2D(size,True)
		
		for x in range(size):
			for y in range(size):
				gray = (myImage.getGray(x,y) - 0.5) * myImage3.getGray(x,y)
				gray = gray + (myImage2.getGray(x,y) - 0.5) * (1.0 - myImage3.getGray(x,y))
				myImage.setGray(x,y,gray + 0.5)
		
		self.myTexture.load(myImage)
开发者ID:borgified,项目名称:Hockfire,代码行数:29,代码来源:PerlinTest.py

示例5: get_heightmap_tex

# 需要导入模块: from pandac.PandaModules import Texture [as 别名]
# 或者: from pandac.PandaModules.Texture import load [as 别名]
    def get_heightmap_tex(self, size, filename = None):
        """Generate texture of map
        """
        mod = self.world_size / size
        image = PNMImage(size, size)
        for x in xrange(size):
            for y in xrange(size):
                px = x * mod
                py = y * mod
                height = self[px, py]
                color = height / 50
                r = 0
                g = 0
                b = 0
                if color > 255:
                    color = 255
                if color < 0:
                    color = abs(color)
                    b = color
                else:
                    g = color
                image.setPixel(x, y, (r, g, b))

        if filename != None:
            image.write(filename)

        #for x in xrange(-1, 2):
            #for y in xrange(-1, 2):
               #image.setPixel(int(world.chunks_map.charX)+x, int(world.chunks_map.charY)+y, (255, 0, 0))

        texture = Texture()
        texture.load(image)
        return texture
开发者ID:viatoriche,项目名称:suber,代码行数:35,代码来源:map3d.py

示例6: PerlinTest

# 需要导入模块: from pandac.PandaModules import Texture [as 别名]
# 或者: from pandac.PandaModules.Texture import load [as 别名]
class PerlinTest(DirectObject):
	
	
	def __init__(self):
		self.myTexture = Texture()
		self.imageObject = OnscreenImage(image = self.myTexture, pos = (0, 0, 0))
		self.run()
		self.accept("arrow_up", self.run)
		
	
	def run(self):
		size = 256
		pb = Perlin.Perlin( persistance = 0.500, smooth = False, seed = random.random() )
		myImage2 = pb.imgNoise2D(size,True)
		
		myImage=PNMImage(size,size)
		myImage.makeGrayscale()
		myImage.setMaxval( (2<<16)-1 )
		myImage.fill(0.5)
		line = lineDrawer.LineDrawer(myImage,(42,180),(13,253),13)
		
		for x in range(size):
			for y in range(size):
				gray = myImage.getGray(x,y) - 0.5
				gray = gray + (myImage2.getGray(x,y) - 0.5)
				myImage.setGray(x,y,gray + 0.5)
		

		self.myTexture.load(myImage)
开发者ID:borgified,项目名称:Hockfire,代码行数:31,代码来源:lineTest.py

示例7: generate_map_texture

# 需要导入模块: from pandac.PandaModules import Texture [as 别名]
# 或者: from pandac.PandaModules.Texture import load [as 别名]
def generate_map_texture(map_tree, factor):
    map_world = map_tree.map3d
    size = map_world.size / factor
    image = PNMImage(size, size)
    #image.fill(0,0,0)
    for x in xrange(size):
        for y in xrange(size):
            px = x * factor
            py = y * factor
            if map_world[(px, py)] <= map_world.water_z:
                image.setPixel(x, y, (0, 0, 100))
            else:
                image.setPixel(x, y, (0, 100, 0))
    char_x, char_y, char_z = map_tree.coords
    char_x = char_x / factor
    char_y = char_y / factor
    image.setPixel(char_x, char_y, (255, 0, 0))
    #if factor>2:
        #image.setPixel(char_x, char_y, (255, 0, 0))
    #else:
        #for x in xrange(char_x - 1, char_x+2):
            #cx = x
            #if cx > size-1: cx = size-1
            #if cx < 0: cx = 0
            #for y in xrange(char_y - 1, char_y+2):
                #cy = y
                #if cy > size-1: cy = size-1
                #if cy < 0: cy = 0
                #image.setPixel(cx, cy, (255, 0, 0))
    texture = Texture()
    texture.load(image)
    return texture
开发者ID:viatoriche,项目名称:suber,代码行数:34,代码来源:world.py

示例8: get_map_2d_tex

# 需要导入模块: from pandac.PandaModules import Texture [as 别名]
# 或者: from pandac.PandaModules.Texture import load [as 别名]
 def get_map_2d_tex(self, map2d, factor = 1):
     """Generate texture for map2d, factor - for size [size / factor]
     """
     size = map2d.size / factor
     image = PNMImage(size, size)
     for x in xrange(size):
         for y in xrange(size):
             px = x * factor
             py = y * factor
             if map2d[(px, py)] <= map2d.water_z:
                 image.setPixel(x, y, (0, 0, 100))
             else:
                 image.setPixel(x, y, (0, 100, 0))
     texture = Texture()
     texture.load(image)
     return texture
开发者ID:viatoriche,项目名称:suber,代码行数:18,代码来源:textures.py

示例9: get_map_3d_tex

# 需要导入模块: from pandac.PandaModules import Texture [as 别名]
# 或者: from pandac.PandaModules.Texture import load [as 别名]
    def get_map_3d_tex(self, size, filename = None, charPos = None):
        """Generate texture of map
        """
        mod = self.world_size / size
        image = PNMImage(size, size)
        for x in xrange(size):
            for y in xrange(size):
                px = x * mod
                py = y * mod
                height = self[px, py]
                if height <= 0:
                    color = (abs(height) / 50) + 50
                    if color > 255:
                        color = 255
                    image.setPixel(x, y, (0, 0, 255-color))
                else:
                    if height <= self.config.low_mount_level[1]:
                        color = height / 20
                        r = 0
                        g = 50+color
                        b = 0
                        image.setPixel(x, y, (r, g, b))
                    elif height > self.config.low_mount_level[1]:
                        color = height / 50
                        r = color
                        g = color
                        b = color
                        if r > 255:
                            r = 255
                        if g > 255:
                            r = 255
                        if b > 255:
                            b = 255
                        image.setPixel(x, y, (r, g, b))

        if filename != None:
            image.write(filename)

        if charPos != None:
            charX, charY = charPos
            for x in xrange(-1, 2):
                for y in xrange(-1, 2):
                   image.setPixel(int(charX/mod)+x, int(charY/mod)+y, (255, 0, 0))

        texture = Texture()
        texture.load(image)
        return texture
开发者ID:viatoriche,项目名称:suber,代码行数:49,代码来源:map3d.py

示例10: HtmlView

# 需要导入模块: from pandac.PandaModules import Texture [as 别名]
# 或者: from pandac.PandaModules.Texture import load [as 别名]

#.........这里部分代码省略.........
        ll = Point3()
        ur = Point3()
        self.quad.calcTightBounds(ll, ur)
        self.notify.debug('ll=%s ur=%s' % (ll, ur))
        offset = self.quad.getPos(aspect2d)
        self.notify.debug('offset = %s ' % offset)
        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()
开发者ID:AdrianF98,项目名称:Toontown-Rewritten,代码行数:70,代码来源:HtmlView.py

示例11: MazeMapGui

# 需要导入模块: from pandac.PandaModules import Texture [as 别名]
# 或者: from pandac.PandaModules.Texture import load [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
#.........这里部分代码省略.........
开发者ID:Keithybub,项目名称:ToonTownReviveOld,代码行数:103,代码来源:MazeMapGui.py

示例12: __init__

# 需要导入模块: from pandac.PandaModules import Texture [as 别名]
# 或者: from pandac.PandaModules.Texture import load [as 别名]

#.........这里部分代码省略.........
				posLeft = -(self.colSize/scale)*repeatX
				posRight = 0

			if anchorY == self.ALIGN_BOTTOM:
				posTop = 0
				posBottom = (self.rowSize/scale)*repeatY
			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.cards.append(self.node.attachNewNode(card.generate()))
			self.cards[-1].setH(i * 360/len(rowPerFace))

		# 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)
		self.setFrame(0)

	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 not taskMgr.hasTaskNamed("Animate sprite" + self.spriteNum):
开发者ID:ChrisCraik,项目名称:tinygame,代码行数:70,代码来源:sprite.py

示例13: PerlinTest

# 需要导入模块: from pandac.PandaModules import Texture [as 别名]
# 或者: from pandac.PandaModules.Texture import load [as 别名]
class PerlinTest(DirectObject):
    def __init__(self):
        self.size = 64
        self.p = Perlin.Perlin(numberOfOctaves=10, persistance=0.75, smooth=False)
        self.myImage = PNMImage(self.size, self.size)
        self.myImage.makeGrayscale()
        self.myTexture = Texture()
        self.myImage.fill(0.5)
        self.myTexture.load(self.myImage)
        self.imageObject = OnscreenImage(image=self.myTexture, pos=(0, 0, 0))
        self.myList = [None] * (self.size)
        for a in range(self.size):
            self.myList[a] = [0.5] * (self.size)
        taskMgr.add(self.noiseTaskVerySmart, "perlinNoiseTask")
        self.startTime = time()
        self.noiseTaskVerySmart()
        self.accept("arrow_up", self.run)
        self.i = [None] * (self.size + 1)
        for x in range(0, self.size + 1):
            self.i[x] = [None] * (self.size + 1)

    def run(self):
        for a in range(self.size):
            self.myList[a] = [0.5] * (self.size)
        self.startTime = time()
        taskMgr.add(self.noiseTaskVerySmart, "perlinNoiseTask")

    def noiseTask(self, Task=None):
        numLines = 8
        if Task == None:
            y = 0
        else:
            y = Task.frame * numLines

        for yNum in range(0, numLines):
            for x in range(0, self.size):
                i = self.p.noise2D(float(x) / self.size, float(y + yNum) / self.size)
                self.myImage.setGray(x, y + yNum, (i + 1.0) / 2)

        self.myTexture.load(self.myImage)
        if Task != None:
            if self.size >= y + numLines:
                return Task.cont
            else:
                self.myTexture.load(self.myImage)
                print time() - self.startTime
                return Task.done

    def noiseTaskSmart(self, Task=None):
        if Task == None:
            o = 0
        else:
            o = Task.frame
        p = Perlin.Perlin(numberOfOctaves=1, smooth=False, seed=0)
        freq = 2 ** o
        for x in range(0, freq + 1):
            for y in range(0, freq + 1):
                self.i[x][y] = p.intNoise2D(x * freq, y * freq)

        for y in range(0, self.size):
            for x in range(0, self.size):
                intX = (x * freq) / self.size
                fraX = (float(x) * freq) / self.size - intX
                intY = (y * freq) / self.size
                i1 = p.linearInterpolate(self.i[intX][intY], self.i[intX + 1][intY], fraX)
                i2 = p.linearInterpolate(self.i[intX][intY + 1], self.i[intX + 1][intY + 1], fraX)
                interNoise = p.linearInterpolate(i1, i2, (float(y) * freq) / self.size - intY)
                self.myList[x][y] += interNoise * (0.75 ** o) / 2
                self.myImage.setGray(x, y, self.myList[x][y])

        self.myTexture.load(self.myImage)
        if Task != None:
            if freq < self.size:
                return Task.cont
            else:
                print time() - self.startTime
                return Task.done

    def noiseTaskVerySmart(self, Task=None):
        if Task == None:
            o = 0
        else:
            o = Task.frame
        p = Perlin.Perlin(numberOfOctaves=1, smooth=False, seed=0)
        freq = 2 ** o
        self.oldImage = self.myImage
        self.myImage = PNMImage(freq + 1, freq + 1)
        self.myImage.makeGrayscale()
        self.myImage.gaussianFilterFrom(1.0, self.oldImage)

        for x in range(0, freq + 1):
            for y in range(0, freq + 1):
                self.myImage.setGray(
                    x, y, self.myImage.getGray(x, y) + p.intNoise2D(x * freq, y * freq) * (0.75 ** o) / 2
                )

        self.myTexture.load(self.myImage)
        if Task != None:
            if freq < self.size:
                return Task.cont
#.........这里部分代码省略.........
开发者ID:borgified,项目名称:Hockfire,代码行数:103,代码来源:PerlinTest.py

示例14: object

# 需要导入模块: from pandac.PandaModules import Texture [as 别名]
# 或者: from pandac.PandaModules.Texture import load [as 别名]
class Effect:
    baseWidth = 0
    baseHeight = 0
    effectWidth = 1
    effectHeight = 1
    effectTargetMS = 143
    noSampling = False
    tex = None
    loadedFormat = None
    # Animation variables
    internalFrameIndex = 1
    startIndex = 1
    endIndex = 1
    loopEffect = False
    # XML variables
    tree = None
    frames = None
    colors = None
    tweens = None
    compositeFrames = None
    # Nodes
    consumedNodesList = None
    # Accessible object (nodePath)
    effectCameraNodePath = None
    effectCardNodePath = None
    # Constant value; Unit comparison for card size; basis is from cure, which is [140x110]
    cardDimensionBasis = [-5.0, 5.0, 0.0, 10.0, 140.0, 110.0]
    pixelScaleX = cardDimensionBasis[4] / (cardDimensionBasis[1] - cardDimensionBasis[0])
    pixelScaleZ = cardDimensionBasis[5] / (cardDimensionBasis[3] - cardDimensionBasis[2])
    effectIsCentered = True
    effectAdjustment = [0, 0, 0]

    def __init__(self, effectFileName, parent=None, loop=False, effectIsCentered=True, effectAdjustment=[0, 0, 0]):
        self.effectAdjustment = effectAdjustment
        self.loopEffect = loop
        self.effectIsCentered = effectIsCentered
        self.loadedFormat = None
        if effectFileName != None:
            effectFileNameSplit = effectFileName.split(".")
            self.loadedFormat = effectFileNameSplit[len(effectFileNameSplit) - 2]  # Get value at penultimate index
            if self.loadedFormat == effectFileNameSplit[0]:
                self.loadedFormat = None  # Get rid of bad format name.
            pass

        # Load texture; supply alpha channel if it doesn't exist.
        p = transparencyKey(effectFileName)
        self.tex = Texture()
        self.tex.setup2dTexture(p.getXSize(), p.getYSize(), Texture.TUnsignedByte, Texture.FRgba)
        self.tex.load(p)
        if self.loadedFormat != None:
            try:
                self.tree = etree.parse("./" + GAME + "/effects/" + self.loadedFormat + "/sprite.xml")
            except IOError:
                self.loadedFormat = None
            pass
        if self.loadedFormat != None:
            root = self.tree.getroot()
            self.frames = root.find(".//frames")
            self.colors = root.find(".//colors")
            self.tweens = root.find(".//motion-tweens")
            self.compositeFrames = root.find(".//composite-frames")
            self.baseWidth = 0 if root.attrib.get("base-width") == None else float(root.attrib.get("base-width"))
            self.baseHeight = 0 if root.attrib.get("base-height") == None else float(root.attrib.get("base-height"))
            self.effectWidth = 1 if root.attrib.get("frame-width") == None else float(root.attrib.get("frame-width"))
            self.effectHeight = 1 if root.attrib.get("frame-height") == None else float(root.attrib.get("frame-height"))
            self.effectTargetMS = 143 if root.attrib.get("target-ms") == None else float(root.attrib.get("target-ms"))
            self.startIndex = 1 if root.attrib.get("target-start") == None else int(root.attrib.get("target-start"))
            self.endIndex = 1 if root.attrib.get("target-end") == None else int(root.attrib.get("target-end"))
            self.noSampling = False if root.attrib.get("no-sampling") == None else bool(root.attrib.get("no-sampling"))
            if self.noSampling == True:
                self.tex.setMagfilter(Texture.FTNearest)
                self.tex.setMinfilter(Texture.FTNearest)
            cm = CardMaker("card-" + effectFileName)
            cardDeltaX = self.effectWidth / self.pixelScaleX
            cardDeltaZ = self.effectHeight / self.pixelScaleZ
            if self.effectIsCentered == True:
                cm.setFrame(0, 0, 0, 0)
                deltaX = (cardDeltaX / 2.0) - (-cardDeltaX / 2.0)
                deltaY = 0
                deltaZ = (cardDeltaZ / 2.0) - (-cardDeltaZ / 2.0)
                # occluder = OccluderNode('effect-parent-occluder', Point3((-cardDeltaX/2.0), 0, (-cardDeltaZ/2.0)), Point3((-cardDeltaX/2.0), 0, (cardDeltaZ/2.0)), Point3((cardDeltaX/2.0), 0, (cardDeltaZ/2.0)), Point3((cardDeltaX/2.0), 0, (-cardDeltaZ/2.0)))
            else:
                cm.setFrame(0, 0, 0, 0)
                deltaX = (cardDeltaX / 2.0) - (-cardDeltaX / 2.0)
                deltaY = 0
                deltaZ = cardDeltaZ - 0
                # occluder = OccluderNode('effect-parent-occluder', Point3((-cardDeltaX/2.0), 0, 0), Point3((-cardDeltaX/2.0), 0, cardDeltaZ), Point3((cardDeltaX/2.0), 0, cardDeltaZ), Point3((cardDeltaX/2.0), 0, 0))
            self.effectCardNodePath = render.attachNewNode(cm.generate())
            self.effectCardNodePath.setBillboardPointEye()
            self.effectCardNodePath.reparentTo(parent)
            # occluder_nodepath = self.effectCardNodePath.attachNewNode(occluder)
            # self.effectCardNodePath.setOccluder(occluder_nodepath)
            emptyNode = NodePath("effect-parent-translator")
            emptyNode.reparentTo(self.effectCardNodePath)
            if effectIsCentered == True:
                emptyNode.setPos(
                    -deltaX / 2.0 + self.effectAdjustment[0],
                    0 + self.effectAdjustment[1],
                    deltaZ / 2.0 + self.effectAdjustment[2],
                )
#.........这里部分代码省略.........
开发者ID:GitNitneroc,项目名称:tethical,代码行数:103,代码来源:Effect.py


注:本文中的pandac.PandaModules.Texture.load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。