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


Python core.Texture类代码示例

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


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

示例1: createMaskedTexture

    def createMaskedTexture(self, name):
        name = self.prepTextureName(name)
        original_name = name[len('masked-'):]
        if self.textures.has_key(original_name):
            tc = self.textures[original_name]   # get the original texture
            bm = tc.image_file
            img_type = tc.image_type

            if img_type == 'DDS':
                mtex = TextureContainer(name, tc.panda_texture, tc.image_file, img_type)
                self.textures[name] = mtex
                return mtex
                
            if img_type != 'IMG':
                print 'ERROR in createMaskedTexture(): cant create masked texture from non IMG type image'
                return None
                
            # print type(bm)
            # print len(bm)
            
            # FIXME: this just copies the original right now! Need to implement the alpha-mask bit still
            m_img = self.maskImg(bm, tc.panda_texture.getXSize() * tc.panda_texture.getYSize())

            t = Texture()               # create empty texture object
            component_type = Texture.TUnsignedByte
            format = Texture.FRgba 
            t.setup2dTexture(tc.panda_texture.getXSize(),tc.panda_texture.getYSize(), component_type, format)
            t.setRamImage(m_img)
            
            mtex = TextureContainer(name, t, m_img, img_type)
            self.textures[name] = mtex
            return mtex
        else:
            print 'TextureManager::createMaskedTexture() failed, original texture:%s not found' % (original_name)
            return None
开发者ID:aportner,项目名称:panda-zonewalk,代码行数:35,代码来源:texture.py

示例2: createTexture

    def createTexture(self, image):
        (width, height) = cv.GetSize(image)
	
        #Panda3D interpreta las imagenes al reves que OpenCV (verticalmente invertidas), por lo que es necesario tener esto en cuenta
        cv.Flip(image, image, 0)
	
        #OpenCV permite convertir la representacion interna de las imagenes a un formato descomprimido que puede ser guardado en un archivo.
        #Esto puede utilizarse desde Panda3D para tomar la imagen y utilizarla como una textura.
        imageString = image.tostring()
        #PTAUchar es una clase que permite tomar un bloque de datos y utilizarlo desde componentes de Panda3D (en particular es util para texturas)
        imagePointer = PTAUchar.emptyArray(0)
        imagePointer.setData(imageString)
        
        try:
            self.count += 1
            #Crea un nuevo objeto textura
            texture = Texture('image' + str(self.count))
            #Establece propiedades de la textura, como tamanio, tipo de datos y modelo de color. Las imagenes de OpenCV las estamos manejando
            #como RGB, donde cada canal es de 8bits (un numero entero)
            texture.setup2dTexture(width, height, Texture.TUnsignedByte, Texture.FRgb)
            #Indicamos que utilice el bloque de datos obtenido anteriormente como origen de datos para la textura
            texture.setRamImage(CPTAUchar(imagePointer), MovieTexture.CMOff)
        except:
            texture = None
        
        return texture
开发者ID:bat78827,项目名称:JuegoPrueba,代码行数:26,代码来源:faceDetection.py

示例3: getTextureRAM

def getTextureRAM(mesh):
    total_image_area = 0
    for cimg in mesh.images:
        pilimg = cimg.pilimage

        if pilimg:
            total_image_area += pilimg.size[0] * pilimg.size[1] * len(pilimg.getbands())
        else:
            # PIL doesn't support DDS, so if loading failed, try and load it as a DDS with panda3d
            imgdata = cimg.data

            # if we can't even load the image's data, can't convert
            if imgdata is None:
                continue

            try:
                from panda3d.core import Texture
                from panda3d.core import StringStream
            except ImportError:
                # if panda3d isn't installed and PIL failed, can't convert
                continue

            t = Texture()
            try:
                success = t.readDds(StringStream(imgdata))
            except:
                success = 1
            if success == 0:
                # failed to load as DDS, so let's give up
                continue
            total_image_area += t.getXSize() * t.getYSize() * 3

    return total_image_area
开发者ID:QuelleVille,项目名称:-deprecated-meshtool,代码行数:33,代码来源:print_render_info.py

示例4: write

 def write(self, pth):
     """ Writes the image to disk """
     Globals.base.graphicsEngine.extract_texture_data(self, Globals.base.win.get_gsg())
     if self.get_texture_type() in [Texture.TT_3d_texture, Texture.TT_cube_map]:
         Texture.write(self, "#_" + pth, 0, 0, True, False)
     else:
         Texture.write(self, pth)
开发者ID:aimoonchen,项目名称:RenderPipeline,代码行数:7,代码来源:image.py

示例5: 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)
开发者ID:cesarmarinhorj,项目名称:RenderPipeline,代码行数:31,代码来源:CloudManager.py

示例6: makeTextureMap

 def makeTextureMap(self):
     '''Citymania function that generates and sets the 4 channel texture map'''
     self.colorTextures = []
     for terrain in self.terrains:
         terrain.getRoot().clearTexture()
         heightmap = terrain.heightfield()
         colormap = PNMImage(heightmap.getXSize()-1, heightmap.getYSize()-1)
         colormap.addAlpha()
         slopemap = terrain.makeSlopeImage()
         for x in range(0, colormap.getXSize()):
             for y in range(0, colormap.getYSize()):
                 # Else if statements used to make sure one channel is used per pixel
                 # Also for some optimization
                 # Snow. We do things funky here as alpha will be 1 already.
                 if heightmap.getGrayVal(x, y) < 200:
                     colormap.setAlpha(x, y, 0)
                 else:
                     colormap.setAlpha(x, y, 1)
                 # Beach. Estimations from http://www.simtropolis.com/omnibus/index.cfm/Main.SimCity_4.Custom_Content.Custom_Terrains_and_Using_USGS_Data
                 if heightmap.getGrayVal(x,y) < 62:
                     colormap.setBlue(x, y, 1)
                 # Rock
                 elif slopemap.getGrayVal(x, y) > 170:
                     colormap.setRed(x, y, 1)
                 else:
                     colormap.setGreen(x, y, 1)
         colorTexture = Texture()
         colorTexture.load(colormap)
         colorTS = TextureStage('color')
         colorTS.setSort(0)
         colorTS.setPriority(1)
         self.colorTextures.append((colorTexture, colorTS))
开发者ID:croxis,项目名称:CityMania,代码行数:32,代码来源:PagedGeoMipTerrain.py

示例7: __init__

    def __init__(self):
        load_prc_file_data("", """
            textures-power-2 none
            window-type offscreen
            win-size 100 100
            gl-coordinate-system default
            notify-level-display error
            print-pipe-types #f
        """)

        ShowBase.__init__(self)

        dest_tex = Texture()
        dest_tex.setup_2d_texture(2048, 2048, Texture.T_unsigned_byte, Texture.F_rgba8)
        cshader = Shader.load_compute(Shader.SL_GLSL, "grain.compute.glsl")
        node = NodePath("")
        node.set_shader(cshader)
        node.set_shader_input("DestTex", dest_tex)
        attr = node.get_attrib(ShaderAttrib)
        self.graphicsEngine.dispatch_compute(
            (2048 // 16, 2048 // 16, 1), attr, self.win.get_gsg())

        base.graphicsEngine.extract_texture_data(dest_tex, base.win.get_gsg())

        # Convert to single channel
        img = PNMImage(2048, 2048, 1, 255)
        dest_tex.store(img)
        img.set_num_channels(1)

        tex = Texture()
        tex.load(img)
        tex.write("grain.txo.pz")
开发者ID:aimoonchen,项目名称:RenderPipeline,代码行数:32,代码来源:generate.py

示例8: MatPlotLibDemo

class MatPlotLibDemo(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        base.setFrameRateMeter(True)

        m = loader.loadModel("models/smiley")
        m.reparent_to(render)
        m.set_pos(0, 5, 0)

        x_size, y_size = 640, 480
        xy_ratio = float(y_size) / float(x_size)
        self.plot = Plot(x_size, y_size)

        self.input_img = PNMImage(x_size, y_size)
        self.input_tex = Texture()
        self.input_tex.load(self.input_img)

        self.card = CardMaker('pygame_card')
        self.card.setUvRange(Point2(0, 1),  # ll
                             Point2(1, 1),  # lr
                             Point2(1, 0),  # ur
                             Point2(0, 0))  # ul
        self.screen = render.attach_new_node(self.card.generate())
        self.screen.set_scale(1, 1, xy_ratio)
        self.screen.set_pos(-0.5, 2, -0.5 * xy_ratio)
        self.screen.setTexture(self.input_tex)
        # FIXME: Apparently mpl's print_to_buffer() doesn't write
        # alpha values properly. 
        self.screen.setTransparency(TransparencyAttrib.MAlpha)

        taskMgr.add(self.update, "update plot")

    def update(self, task):
        self.input_tex.set_ram_image_as(self.plot.draw(), "RGBA")
        return task.cont
开发者ID:TheCheapestPixels,项目名称:panda_examples,代码行数:35,代码来源:matplotlib_to_panda3d.py

示例9: __init__

    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()
开发者ID:aurodev,项目名称:RenderPipeline,代码行数:59,代码来源:GPUFFT.py

示例10: __init__

 def __init__(self, name):
     """ Internal method to create a new image """
     RPObject.__init__(self, name)
     Texture.__init__(self, name)
     Image.REGISTERED_IMAGES.append(self)
     self.set_clear_color(0)
     self.clear_image()
     self.sort = RenderTarget.CURRENT_SORT
开发者ID:ELMERzark,项目名称:RenderPipeline,代码行数:8,代码来源:image.py

示例11: add_render_texture

    def add_render_texture(output, mode=None, bitplane=None):
        """Add render texture to `output`.

        Args:
            output (GraphicsOutput): Graphics output.

        Keyword Args:
            mode (GraphicsOutput.RenderTextureMode):
                | RTMNode
                | RTMBindOrCopy
                | RTMCopyTexture
                | RTMCopyRam
                | RTMTriggeredCopyTexture
                | RTMTriggeredCopyRam
            bitplane (DrawableRegion.RenderTexturePlane):
                | RTPStencil
                | RTPDepthStencil
                | RTPColor
                | RTPAuxRgba0
                | RTPAuxRgba1
                | RTPAuxRgba2
                | RTPAuxRgba3
                | RTPAuxHrgba0
                | RTPAuxHrgba1
                | RTPAuxHrgba2
                | RTPAuxHrgba3
                | RTPAuxFloat0
                | RTPAuxFloat1
                | RTPAuxFloat2
                | RTPAuxFloat3
                | RTPDepth
                | RTPCOUNT

        Return:
            (Texture): Texture object.

        """
        # Mode.
        if mode is None:
            mode = GraphicsOutput.RTMBindOrCopy
        elif isinstance(mode, str):
            mode = getattr(GraphicsOutput, mode)
        if bitplane is None:
            bitplane = GraphicsOutput.RTPColor
        elif isinstance(bitplane, str):
            bitplane = getattr(GraphicsOutput, bitplane)
        # Bitplane.
        if bitplane is GraphicsOutput.RTPColor:
            fmt = Texture.FLuminance
        elif bitplane is GraphicsOutput.RTPDepth:
            fmt = Texture.FDepthComponent
        # Get a handle to the texture.
        tex = Texture()
        tex.setFormat(fmt)
        # Add the texture to the buffer.
        output.addRenderTexture(tex, mode, bitplane)
        tex.clearRamImage()
        return tex
开发者ID:jhamrick,项目名称:scenesim,代码行数:58,代码来源:lightbase.py

示例12: _load_noise_tex

 def _load_noise_tex(self):
     """ Loads the default 4x4 noise tex """
     random.seed(42)
     img = PNMImage(4, 4, 3)
     for x in range(16):
         img.set_xel(x%4, x//4, random.random(), random.random(), random.random())
     tex = Texture("Random4x4")
     tex.load(img)
     self._pipeline.stage_mgr.add_input("Noise4x4", tex)
开发者ID:wdmwdm,项目名称:RenderPipeline,代码行数:9,代码来源:CommonResources.py

示例13: initTransparencyPass

    def initTransparencyPass(self):
        """ Creates the pass which renders the transparent objects into the scene """
        self.transparencyPass = TransparencyPass()
        self.pipeline.getRenderPassManager().registerPass(self.transparencyPass)

        # Create the atomic counter which stores the amount of rendered transparent
        # pixels. For now this a 1x1 texture, as atomic counters are not implemented.
        self.pixelCountBuffer = Texture("MaterialCountBuffer")
        self.pixelCountBuffer.setup2dTexture(1, 1, Texture.TInt, Texture.FR32i)

        # Creates the buffer which stores all transparent pixels. Pixels are inserted
        # into the buffer in the order they are rendered, using the pixelCountBuffer
        # to determine their index 
        self.materialDataBuffer = Texture("MaterialDataBuffer")
        self.materialDataBuffer.setupBufferTexture(self.maxPixelCount, Texture.TFloat, 
            Texture.FRgba32, GeomEnums.UH_static)

        # Creates the list head buffer, which stores the first transparent pixel for
        # each window pixel. The index stored in this buffer is the index into the 
        # materialDataBuffer
        self.listHeadBuffer = Texture("ListHeadBuffer")
        self.listHeadBuffer.setup2dTexture(self.pipeline.getSize().x, self.pipeline.getSize().y, 
            Texture.TInt, Texture.FR32i)

        # Creates the spinlock buffer, which ensures that writing to the listHeadBuffer
        # is sequentially
        self.spinLockBuffer = Texture("SpinLockBuffer")
        self.spinLockBuffer.setup2dTexture(self.pipeline.getSize().x, self.pipeline.getSize().y, 
            Texture.TInt, Texture.FR32i)

        # Set the buffers as input to the main scene. Maybe we can do this more elegant
        target = self.pipeline.showbase.render
        target.setShaderInput("pixelCountBuffer", self.pixelCountBuffer)
        target.setShaderInput("spinLockBuffer", self.spinLockBuffer)
        target.setShaderInput("materialDataBuffer", self.materialDataBuffer)
        target.setShaderInput("listHeadBuffer", self.listHeadBuffer)

        # Provides the buffers as global shader inputs
        self.pipeline.getRenderPassManager().registerStaticVariable("transpPixelCountBuffer", self.pixelCountBuffer)
        self.pipeline.getRenderPassManager().registerStaticVariable("transpSpinLockBuffer", self.spinLockBuffer)
        self.pipeline.getRenderPassManager().registerStaticVariable("transpListHeadBuffer", self.listHeadBuffer)
        self.pipeline.getRenderPassManager().registerStaticVariable("transpMaterialDataBuffer", self.materialDataBuffer)

        # Registers the transparency settings to the shaders
        self.pipeline.getRenderPassManager().registerDefine("USE_TRANSPARENCY", 1)
        self.pipeline.getRenderPassManager().registerDefine("MAX_TRANSPARENCY_LAYERS", 
            self.pipeline.settings.maxTransparencyLayers)

        self.pixelCountBuffer.setClearColor(Vec4(0, 0, 0, 0))
        self.spinLockBuffer.setClearColor(Vec4(0, 0, 0, 0))
        self.listHeadBuffer.setClearColor(Vec4(0, 0, 0, 0))

        MemoryMonitor.addTexture("MaterialCountBuffer", self.pixelCountBuffer)
        MemoryMonitor.addTexture("MaterialDataBuffer", self.materialDataBuffer)
        MemoryMonitor.addTexture("ListHeadBuffer", self.listHeadBuffer)
        MemoryMonitor.addTexture("SpinLockBuffer", self.spinLockBuffer)
开发者ID:croxis,项目名称:RenderPipeline,代码行数:56,代码来源:TransparencyManager.py

示例14: __init__

 def __init__(self):
   Texture.__init__(self)
   
   self.axisx = 0 # offset distance to the right side of the sprite from the origin. X+ is to the right
   self.axisy = 0 # offset distance to the top side of the sprite from the origin. Y+ is up
   self.group = 0
   self.no = 0
   
   self.hit_boxes = []
   self.damage_boxes = []
开发者ID:jrgnicho,项目名称:platformer_games_project,代码行数:10,代码来源:sprite.py

示例15: __apply_Textures

 def __apply_Textures(self, recipe, tex_dict):
     for i, ter_dict in enumerate(recipe['terrains']):
         tex_img = PNMImage()
         tex_img.read(Filename("{}/tex/{}".format(recipe['planet_path'], ter_dict['texture'])))
         tex = Texture()
         tex.load(tex_img)
         tex.setMinfilter(Texture.FTLinear)
         ts = TextureStage(str(i))
         ts.setSort(i)
         self.NP.setTexture(ts, tex, i*10)
开发者ID:svfgit,项目名称:solex,代码行数:10,代码来源:model.py


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