Beispiel #1
0
    def test(self):

        print "\n\nAdding children with attach_sprite"

        src1 = TexturePool.loadTexture("../Res/btn_left.png")
        src2 = TexturePool.loadTexture("../Res/btn_right.png")

        start = time.time()
        iterations = 100000
        for i in xrange(iterations):
            sprite = self.attach_sprite(src1, i * 10.0, 0.0)
            # sprite.set_right(50)
        dur = (time.time() - start) * 1000.0
        print iterations, "Sprites created in", round(dur, 2), "ms, that is", round(dur / iterations, 8), "ms per sprite"


        # self.ls()

        print "\n\nMoving children with set_left"
        start = time.time()
        iterations = self.get_child_count()
        for sprite in self.children():
            sprite.set_left(10)
        dur = (time.time() - start) * 1000.0
        print iterations, "Sprites moved in", round(dur, 2), "ms, that is", round(dur / iterations, 8), "ms per sprite"

        print "\n\nChanging sprite images with set_texture"
        start = time.time()
        iterations = self.get_child_count()
        for sprite in self.children():
            sprite.set_texture(src2)

        dur = (time.time() - start) * 1000.0
        print iterations, "Sprites changed in", round(dur, 2), "ms, that is", round(dur / iterations, 8), "ms per iteration"

        # self.ls()

        print "\n\nRemoving all childrens (child by child, with remove_child)"
        start = time.time()
        iterations = self.get_child_count()
        for sprite in self.children():
            self.remove_child(sprite)
        dur = (time.time() - start) * 1000.0
        print iterations, "Sprites removed in", round(dur, 2), "ms, that is", round(dur / iterations, 8), "ms per sprite"

        print "Sprites left: ", self.get_child_count()



        print "\n\nDone"
Beispiel #2
0
    def __init__(self, filename):
        vfs = VirtualFileSystem.getGlobalPtr()
        #self.material = BSPMaterial.getFromFile(filename)
        self.material = TexturePool.loadTexture(filename)
        self.filename = filename
        if self.material:  #.hasKeyvalue("$basetexture"):
            # baseTexturePath = self.material.getKeyvalue("$basetexture")

            if True:  #vfs.exists(baseTexturePath):
                #imageData = bytes(VirtualFileSystem.getGlobalPtr().readFile(baseTexturePath, True))

                pimage = PNMImage()
                self.material.store(pimage, 0, 0)
                ss = StringStream()
                pimage.write(ss, "tmp.png")
                imageData = bytes(ss)

                byteArray = QtCore.QByteArray.fromRawData(imageData)
                image = QtGui.QImage.fromData(byteArray)
                self.pixmap = QtGui.QPixmap.fromImage(image)
                self.icon = QtGui.QIcon(self.pixmap)
                self.size = LVector2i(pimage.getXSize(), pimage.getYSize())

                print(pimage, self.size)
            else:
                self.size = LVector2i(64, 64)
                self.icon = None
                self.pixmap = None
        else:
            self.size = LVector2i(64, 64)
            self.icon = None
            self.pixmap = None
Beispiel #3
0
def p_store_texture(p):
    filename = p[4]
    if len(p) == 7:
        filename = p[5]
    name = p[3]
    if len(p) == 7:
        name = p[4]
        p.parser.dnaStore.storeCatalogCode(p[3], name)
    texture = TexturePool.loadTexture(Filename(filename))
    p.parser.dnaStore.storeTexture(name, texture)
Beispiel #4
0
    def setBlurredHeightmap(self, hmap_path):
        assert(self._parent)

        self.blurred_heightmap_tex = TexturePool.loadTexture(Filename.fromOsSpecific(hmap_path))
        self.blurred_heightmap_tex.setWrapU(SamplerState.WMClamp)
        self.blurred_heightmap_tex.setWrapV(SamplerState.WMClamp)
        self.blurred_heightmap_tex.setFormat(Texture.F_r16)
        self.blurred_heightmap_tex.setKeepRamImage(False)
        self.blurred_heightmap_tex.setMinfilter(SamplerState.FTLinearMipmapLinear)
        self.blurred_heightmap_tex.setMagfilter(SamplerState.FTLinear)
        self.blurred_heightmap_tex.setAnisotropicDegree(0)

        print "set blurred heightmap"
        self._element_node.setShaderInput("blurredHeightmap", self.blurred_heightmap_tex)
Beispiel #5
0
    def setHeightmap(self, hmap_path):
        assert (self._parent)

        self.heightmap_tex = TexturePool.loadTexture(
            Filename.fromOsSpecific(hmap_path))
        # self.heightmap_tex = loader.loadTexture(hmap_path)

        self.heightmap_tex.setWrapU(SamplerState.WMClamp)
        self.heightmap_tex.setWrapV(SamplerState.WMClamp)
        self.heightmap_tex.setFormat(Texture.F_r16)
        self.heightmap_tex.setKeepRamImage(False)
        self.heightmap_tex.setMinfilter(SamplerState.FTLinearMipmapLinear)
        self.heightmap_tex.setMagfilter(SamplerState.FTLinear)
        self.heightmap_tex.setAnisotropicDegree(0)

        self._element_node.setShaderInput("heightmap", self.heightmap_tex)
Beispiel #6
0
    def __init__(self, text):
        LUIObject.__init__(self, 50, 30)

        print "\nTest case 1: Setting & Getting size"
        print self.get_size()
        self.set_size(100, 200)
        print self.get_size()

        print "\nTest case 2: Using 'default:image'"
        self.imgMid = LUISprite(self, "btn_mid", "default")

        print "\nTest case 3: Attaching an arbitrary image"
        self.imgRight3 = LUISprite(self, "../Res/btn_mid.png", 32, 32)

        print "\nTest case 4: Attaching a texture object"
        self.imgRight4 = LUISprite(self, 
            TexturePool.loadTexture("../Res/btn_right.png"))

        print "\nTest case 5: Attaching a non-existing image"
        self.imgRight5 = LUISprite(self, "Res/DoesNotExist.png")

        print "\nTest case 6: Attaching a sprite, but not storing a reference"
        LUISprite(self, "btn_right", "default")

        print "\nTest case 7: Attaching and instantly removing a sprite"
        tmp = LUISprite(self, "btn_right", "default")
        self.remove_child(tmp)

        print "\nTest case 8: Resizing widget"
        self.set_size(30, 40)

        print "\nTest case 9: Positioning widget"
        self.set_pos(50, 50)

        print "\nTesting if all pointers are still valid"

        for sprite in self.children:
            start = LTexCoord()
            end = LTexCoord()
            sprite.get_uv_range(start, end)
            sprite.print_vertices()

        print "Test passed."
    def __init__(self, name, size=10000, resolution=1024):
        """Arguments:
        size -- Edge length of the water square.
        resolution -- Texture size of the rendered reflection buffer.
        """
        # Uncomment to see the output of the refclection buffer.
        base.bufferViewer.toggleEnable()

        AssetBase.__init__(self)
        self.name = name

        self.cm = CardMaker("water surface")
        self.cm.setFrame(-0.5 * size, 0.5 * size, -0.5 * size, 0.5 * size)
        self.cm.setHasUvs(True)
        self.node = NodePath(self.cm.generate())

        self.node.setP(self.node, -90)
        self.node.flattenLight()
        self.node.hide(BitMask32.bit(1))
        # self.node.setTwoSided(True)
        self.node.setShaderOff()

        # size of one texture tile in meters
        self.tex_size = 100.0

        diffuse = TexturePool.loadTexture("textures/water.diffuse.png")
        diffuse.setWrapU(Texture.WMRepeat)
        diffuse.setWrapV(Texture.WMRepeat)
        diffuse.setMinfilter(Texture.FTLinearMipmapLinear)
        diffuse.setMagfilter(Texture.FTLinearMipmapLinear)
        self.diffuse_stage = TextureStage("diffuse")
        self.diffuse_stage.setSort(2)
        self.node.setTexture(self.diffuse_stage, diffuse)
        self.node.setTexScale(self.diffuse_stage, size / self.tex_size, size / self.tex_size)

        # Reflection camera renders to 'buffer' which is projected onto the
        # water surface.
        buffer = base.win.makeTextureBuffer("water reflection", resolution, resolution)
        buffer.setClearColor(Vec4(0, 0, 0, 1))

        self.refl_cam = base.makeCamera(buffer)
        self.refl_cam.reparentTo(self.node)
        self.refl_cam.node().setCameraMask(BitMask32.bit(1))
        self.refl_cam.node().getLens().setFov(base.camLens.getFov())
        self.refl_cam.node().getLens().setNearFar(1, 100000)

        plane = PlaneNode("water culling plane", Plane(Vec3(0, 0, 1), Point3(0, 0, 0)))
        cfa = CullFaceAttrib.makeReverse()
        cpa = ClipPlaneAttrib.make(PlaneNode.CEVisible, plane)
        rs = RenderState.make(cfa, cpa)
        self.refl_cam.node().setInitialState(rs)

        reflection = buffer.getTexture()
        reflection.setMinfilter(Texture.FTLinear)
        reflection.setMagfilter(Texture.FTLinear)
        self.refl_stage = TextureStage("reflection")
        self.refl_stage.setSort(1)
        self.node.projectTexture(self.refl_stage, reflection, base.cam)
        self.node.setTexture(self.refl_stage, reflection)

        # Blend between diffuse and reflection.
        self.diffuse_stage.setColor(VBase4(1, 1, 1, 0.2))  # opacity of 20%
        self.diffuse_stage.setCombineRgb(
            TextureStage.CMInterpolate,
            TextureStage.CSTexture,
            TextureStage.COSrcColor,
            TextureStage.CSPrevious,
            TextureStage.COSrcColor,
            TextureStage.CSConstant,
            TextureStage.COSrcAlpha,
        )

        self.addTask(self.update, name="water update", sort=1, taskChain="world")
Beispiel #8
0
    def __init__(self, name, size=10000, resolution=1024):
        """Arguments:
        size -- Edge length of the water square.
        resolution -- Texture size of the rendered reflection buffer.
        """
        # Uncomment to see the output of the refclection buffer.
        base.bufferViewer.toggleEnable()

        AssetBase.__init__(self)
        self.name = name

        self.cm = CardMaker("water surface")
        self.cm.setFrame(-0.5 * size, 0.5 * size, -0.5 * size, 0.5 * size)
        self.cm.setHasUvs(True)
        self.node = NodePath(self.cm.generate())

        self.node.setP(self.node, -90)
        self.node.flattenLight()
        self.node.hide(BitMask32.bit(1))
        #self.node.setTwoSided(True)
        self.node.setShaderOff()

        # size of one texture tile in meters
        self.tex_size = 100.0

        diffuse = TexturePool.loadTexture("textures/water.diffuse.png")
        diffuse.setWrapU(Texture.WMRepeat)
        diffuse.setWrapV(Texture.WMRepeat)
        diffuse.setMinfilter(Texture.FTLinearMipmapLinear)
        diffuse.setMagfilter(Texture.FTLinearMipmapLinear)
        self.diffuse_stage = TextureStage("diffuse")
        self.diffuse_stage.setSort(2)
        self.node.setTexture(self.diffuse_stage, diffuse)
        self.node.setTexScale(self.diffuse_stage, size / self.tex_size,
                              size / self.tex_size)

        # Reflection camera renders to 'buffer' which is projected onto the
        # water surface.
        buffer = base.win.makeTextureBuffer("water reflection", resolution,
                                            resolution)
        buffer.setClearColor(Vec4(0, 0, 0, 1))

        self.refl_cam = base.makeCamera(buffer)
        self.refl_cam.reparentTo(self.node)
        self.refl_cam.node().setCameraMask(BitMask32.bit(1))
        self.refl_cam.node().getLens().setFov(base.camLens.getFov())
        self.refl_cam.node().getLens().setNearFar(1, 100000)

        plane = PlaneNode("water culling plane",
                          Plane(Vec3(0, 0, 1), Point3(0, 0, 0)))
        cfa = CullFaceAttrib.makeReverse()
        cpa = ClipPlaneAttrib.make(PlaneNode.CEVisible, plane)
        rs = RenderState.make(cfa, cpa)
        self.refl_cam.node().setInitialState(rs)

        reflection = buffer.getTexture()
        reflection.setMinfilter(Texture.FTLinear)
        reflection.setMagfilter(Texture.FTLinear)
        self.refl_stage = TextureStage("reflection")
        self.refl_stage.setSort(1)
        self.node.projectTexture(self.refl_stage, reflection, base.cam)
        self.node.setTexture(self.refl_stage, reflection)

        # Blend between diffuse and reflection.
        self.diffuse_stage.setColor(VBase4(1, 1, 1, 0.2))  # opacity of 20%
        self.diffuse_stage.setCombineRgb(
            TextureStage.CMInterpolate, TextureStage.CSTexture,
            TextureStage.COSrcColor, TextureStage.CSPrevious,
            TextureStage.COSrcColor, TextureStage.CSConstant,
            TextureStage.COSrcAlpha)

        self.addTask(self.update,
                     name="water update",
                     sort=1,
                     taskChain="world")