Example #1
0
    def __init__(self, name, resource):
        """Arguments:
        resource -- name of a directory in assets/skyboxes that contains 6
        images.
        """
        ManagedAsset.__init__(self, "sky")
        self.name = name

        tex = None
        for ext in ("png", "jpg", "tga"):
            f = Filename("skyboxes/{}/0.{}".format(resource, ext))
            if f.resolveFilename(getModelPath().getValue()):
                tex = TexturePool.loadCubeMap("skyboxes/{}/#.{}".format(resource, ext))
                break

        if tex is None:
            raise ResourceLoadError("assets/skyboxes/%s" % resource,
                                 "maybe wrong names or different extensions?")
        
        self.node = loader.loadModel("misc/invcube")
        self.node.clearTexture()
        self.node.clearMaterial()
        self.node.setScale(10000)
        self.node.setTwoSided(True)
        self.node.setBin('background', 0)
        self.node.setDepthTest(False)
        self.node.setDepthWrite(False)
        self.node.setLightOff()
        self.node.setTexGen(TextureStage.getDefault(), TexGenAttrib.MWorldPosition)
        self.node.setTexProjector(TextureStage.getDefault(), render, self.node);
        self.node.setTexture(tex, 1)
        self.node.flattenLight()
        #self.node.setCompass()  # not needed with world-space-UVs
        self.addTask(self.update, "sky repositioning", sort=10,
                     taskChain="world")
Example #2
0
 def loadTexture(self, texpath, name, exts):
     tex = None
     if not texpath:
         texpath = '.'
     try:
         path = filesystem.toPanda(os.path.join(texpath, name + exts))
         fname = Filename(path)
         if fname.resolveFilename(getModelPath().getValue()):
             tex = self._base.loader.loadTexture(fname)
     except TypeError:       # exts is a list
         for e in exts:
             path = filesystem.toPanda(os.path.join(texpath, name + e))
             fname = Filename(path)
             if fname.resolveFilename(getModelPath().getValue()):
                 tex = self._base.loader.loadTexture(fname)
                 break
     if not tex:
         raise Exception("did not find any match for "+texpath+"/"+name+" with "+str(exts))
     return tex