Ejemplo n.º 1
0
 def loadShader(self, name):
     '''
     Loads the shader specified by the given name.
     @param name: The name of the shader, by convention it will be used as the basename
     of the shader file to load.
     @return: A pandac.PandaModules.Shader instance or None if the file was not found or could not get loaded.
     '''
     exts = ResourcesTypes.getExtensions(PanoConstants.RES_TYPE_SHADERS)
     if len(exts) == 1:
         return self._loadInternal(PanoConstants.RES_TYPE_SHADERS,
                                   name + exts[0])
     else:
         return self._loadInternal(PanoConstants.RES_TYPE_SHADERS, name)
Ejemplo n.º 2
0
class DirectoryResourcesLocation(AbstractResourceLocation):
    '''
    Offers services for finding loading files from directories.
    '''
    def __init__(self,
                 directory,
                 name,
                 description,
                 resTypes,
                 hotswap=True,
                 checkPeriod=10):
        AbstractResourceLocation.__init__(self, name, description, resTypes,
                                          hotswap, checkPeriod)

        self.log = logging.getLogger('pano.directoryResource')

        # the directory to look into for supported resource types
        self.directory = directory

        # a sorted list of all filenames of supported types that were found in self.directory
        self.resourcesNames = []

    def dispose(self):
        self.resourcesNames = None

    def indexResources(self):

        # get a listing of the directory and match filenames against
        # all supported resource types
        try:
            filenames = dircache.listdir(self.directory)
        except Exception, e:
            # dircache.listdir can throw
            self.log.exception('error while calling dircache.listdir')
            return

        suffixes = []
        for resType in self.resTypes:
            suffixes.extend(ResourcesTypes.getExtensions(resType))

        suffixes = tuple(suffixes)
        self.resourcesNames = [
            item for item in filenames if item.endswith(suffixes)
        ]
        self.resourcesNames.sort()