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


Python PNMImage.setXelA方法代码示例

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


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

示例1: _storeIESProfile

# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import setXelA [as 别名]
    def _storeIESProfile(self, name, lampRadialGradientData, lampGradientData):
        """ Internal method to convert the array of data into a texture to load
        into the texture array """

        def interpolateValue(dataset, percentageVal):
            """ Interpolates over an array, accepting float values from 0.0 to 1.0 """
            percentageValClamped = max(0.0, min(0.99999, percentageVal))
            scaledVal = percentageValClamped * len(dataset)
            index = int(scaledVal)
            indexBy1 = min(index + 1, len(dataset) -1)
            lerpFactor = scaledVal % 1.0
            return dataset[indexBy1] * lerpFactor + dataset[index] * (1.0 - lerpFactor)

        # Add profile name to the list of loaded profiles
        if name in self.profileNames:
            # self.error("Cannot register profile",name,"twice")
            return False
        profileIndex = len(self.profileNames)
        self.profileNames.append(name)

        # Generate gradient texture
        img = PNMImage(self.IESTableResolution, 1, 4, 2 ** 16 - 1)

        for offset in xrange(self.IESTableResolution):
            radialGradientValR = interpolateValue(lampRadialGradientData,
                (offset + 5.0) / float(self.IESTableResolution))
            radialGradientValG = interpolateValue(lampRadialGradientData,
                offset / float(self.IESTableResolution))
            radialGradientValB = interpolateValue(lampRadialGradientData,
                (offset - 5.0) / float(self.IESTableResolution))

            gradientVal = interpolateValue(lampGradientData, offset / float(self.IESTableResolution))

            img.setXelA(offset, 0, radialGradientValR, radialGradientValG, radialGradientValB, gradientVal)

        # Store gradient texture
        self.storage.load(img, profileIndex, 0)
开发者ID:cesarmarinhorj,项目名称:RenderPipeline,代码行数:39,代码来源:IESLoader.py

示例2: MazeMapGui

# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import setXelA [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:nate97,项目名称:src,代码行数:103,代码来源:MazeMapGui.py


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