Ejemplo n.º 1
0
    def __init__(self):
        #load all known music files
        log.debug('Audio: loading music')

        self.music_manager=base.musicManager
        self.sfx_manager=base.sfxManagerList[0]

        self.music={}
        music_dir=listdir(path+'music')
        for music_file in music_dir:
            name=Filename(music_file)
            if  name.getExtension() in ('wav', 'mp3', 'ogg'):
                self.music[name.getBasenameWoExtension()]=loader.loadMusic(path+'music/'+music_file)
        #load all known sfx files
        log.debug('Audio: loading sounds')
        self.sfx={}
        sfx_dir=listdir(path+'sounds')
        for sfx_file in sfx_dir:
            name=Filename(sfx_file)
            if  name.getExtension() in ('wav', 'mp3', 'ogg'):
                self.sfx[name.getBasenameWoExtension()]=loader.loadSound(self.sfx_manager, path+'sounds/'+sfx_file, True)
        #list of music files to be played
        self.playlist=None
        self.current_track=None
        #set volume
        self.music_volume=cfg['music-volume']
        self.music_manager.setVolume(self.music_volume)
        self.sfx_volume=cfg['sound-volume']
        self.sfx_manager.setVolume(self.sfx_volume)
        #shufle
        self.shufle=False
        #some other stuff...
        self.seq=None
        self.pause_time=0.0
        #list of sounds attached to objects
        self.attached_sounds=[]

        self.sfx_manager.audio3dSetDistanceFactor(cfg['sfx-distance-factor'])
        self.sfx_manager.audio3dSetDopplerFactor(cfg['sfx-doppler-factor'])

        #fp = FilterProperties()
        #fp.addDistort(1.0)
        #self.sfx_manager.configureFilters(fp)

        self.setSpeakerMode(cfg['speakermode'])

        log.debug('Audio started')

        #event handling
        self.accept('audio-sfx',self.playSound)
        self.accept('audio-reset-volume',self.resetVolume)

        #task
        taskMgr.add(self.update, 'audio_update')
Ejemplo n.º 2
0
 def load_base_settings(self, plugin_dir):
     """ Loads the base settings of all plugins, even of disabled plugins.
     This is required to verify all overrides. """
     for entry in listdir(plugin_dir):
         abspath = join(plugin_dir, entry)
         if isdir(abspath) and entry not in ("__pycache__", "plugin_prefab"):
             self.load_plugin_settings(entry, abspath)
Ejemplo n.º 3
0
 def load_base_settings(self, plugin_dir):
     """ Loads the base settings of all plugins, even of disabled plugins.
     This is required to verify all overrides. """
     for entry in listdir(plugin_dir):
         abspath = join(plugin_dir, entry)
         if isdir(abspath) and entry not in ("__pycache__",
                                             "plugin_prefab"):
             self.load_plugin_settings(entry, abspath)
 def create_shaders(self):
     """ Creates all the shaders used for precomputing """
     self.shaders = {}
     resource_path = self.handle.get_shader_resource("eric_bruneton")
     for fname in listdir(resource_path):
         fpath = join(resource_path, fname)
         if isfile(fpath) and fname.endswith(".compute.glsl"):
             shader_name = fname.split(".")[0]
             shader_obj = RPLoader.load_shader(fpath)
             self.shaders[shader_name] = shader_obj
Ejemplo n.º 5
0
    def loadIESProfiles(self, directory):
        """ Loads all ies profiles from a given directory """
        self.debug("Loading IES Profiles from", directory)

        files = listdir(directory)

        for entry in files:
            if entry.lower().endswith(".ies"):
                combinedPath = os.path.join(directory, entry)
                self._loadIESProfile(entry.split(".")[0], combinedPath)
 def get_available_plugins(self):
     """ Returns a list of all installed plugins, no matter if they are
     enabled or not. This also does no check if the plugin names are valid. """
     plugins = []
     files = listdir(join(self._base_dir, "Plugins"))
     for fname in files:
         abspath = join(self._base_dir, "Plugins", fname)
         if isdir(abspath) and fname not in ["PluginPrefab"]:
             plugins.append(fname)
     return plugins
Ejemplo n.º 7
0
 def _create_shaders(self):
     """ Creates all the shaders used for precomputing """
     self._shaders = {}
     resource_path = self._handle.get_shader_resource("eric_bruneton")
     for fname in listdir(resource_path):
         fpath = join(resource_path, fname)
         if isfile(fpath) and fname.endswith(".compute.glsl"):
             shader_name = fname.split(".")[0]
             shader_obj = Shader.load_compute(Shader.SL_GLSL, fpath)
             self._shaders[shader_name] = shader_obj
Ejemplo n.º 8
0
    def loadIESProfiles(self, directory):
        """ Loads all ies profiles from a given directory """
        self.debug("Loading IES Profiles from", directory)

        files = listdir(directory)

        for entry in files:
            if entry.lower().endswith(".ies"):
                combinedPath = os.path.join(directory, entry)
                self._loadIESProfile(entry.split(".")[0], combinedPath)
Ejemplo n.º 9
0
def findAnims(model):
    temp=model.split('_m_')
    path=temp[0]
    anim_name='_a_'+temp[1][:-4]
    name_len=len(anim_name)
    anim_dict={}
    dirList=listdir(Filename(path).toOsSpecific())
    for fname in dirList:                        
        if Filename(fname).getExtension() in ('egg', 'bam'): 
            if fname.startswith(anim_name):
                anim_dict[fname[name_len:-4]]=path+fname
    return anim_dict
Ejemplo n.º 10
0
def findAnims(model):
    temp = model.split('_m_')
    path = temp[0]
    anim_name = '_a_' + temp[1][:-4]
    name_len = len(anim_name)
    anim_dict = {}
    dirList = listdir(Filename(path).toOsSpecific())
    for fname in dirList:
        if Filename(fname).getExtension() in ('egg', 'bam'):
            if fname.startswith(anim_name):
                anim_dict[fname[name_len:-4]] = path + fname
    return anim_dict
Ejemplo n.º 11
0
 def loadActor(self, model):        
     dir_name=Filename(model).getDirname()+'/'
     model_name=Filename(model).getBasename()[3:]
     name_len=len(model_name)        
     anim_dict={}
     dirList=listdir(Filename(dir_name).toOsSpecific())
     for fname in dirList:                        
         if Filename(fname).getExtension() in ('egg', 'bam'): 
             if fname.startswith("_a_"+model_name):
                 anim_dict[fname[4+name_len:-4]]=dir_name+fname[:-4]
     actor=loadModel(model,dir_name+"_c_"+model_name,anim_dict)            
     self.actors.append(actor)
     self.currentObject=self.actors[-1]
     self.currentObject.reparentTo(render)
     self.currentObject.setPythonTag('props', '')
     self.currentObject.setHpr(self.currentHPR[0],self.currentHPR[1],self.currentHPR[2])
     self.currentObject.setZ(self.currentZ)
     self.currentObject.setScale(self.currentScale)  
Ejemplo n.º 12
0
def loadModel(file, collision=None, animation=None):
    model = None
    if animation:
        collision = file + '/collision'
        anims = {}
        dirList = listdir(file + '/animation')
        for fname in dirList:
            anims[fname[:-4]] = file + '/animation/' + fname
        #print anims
        model = Actor(file + '/model', anims)
        #default anim
        if 'default' in anims:
            model.loop('default')
        elif 'idle' in animation:
            model.loop('idle')
        else:  #some first, random anim
            model.loop(anims.items()[0])
    else:
        model = loader.loadModel(file)
    model.setPythonTag('model_file', file)
    #load shaders
    for geom in model.findAllMatches('**/+GeomNode'):
        if geom.hasTag('light'):
            model.setPythonTag('hasLight', True)
        if geom.hasTag('particle'):
            file = 'particle/' + geom.getTag('particle')
            if exists(file):
                with open(file) as f:
                    values = json.load(f)
                p = createEffect(values)
                model.setPythonTag('particle', p)
                p.start(parent=model, renderParent=render)
        if geom.hasTag('cg_shader'):
            geom.setShader(
                loader.loadShader("shaders/" + geom.getTag('cg_shader')))
        elif geom.hasTag('glsl_shader'):
            glsl_shader = geom.getTag('glsl_shader')
            model.setShader(
                Shader.load(Shader.SLGLSL,
                            "shaders/{0}_v.glsl".format(glsl_shader),
                            "shaders/{0}_f.glsl".format(glsl_shader)))
        else:
            #geom.setShader(loader.loadShader("shaders/default.cg"))
            model.setShader(
                Shader.load(Shader.SLGLSL, "shaders/default_v.glsl",
                            "shaders/default_f.glsl"), 1)
            print "default shader!"
    #collisions
    model.setCollideMask(BitMask32.allOff())
    if collision:
        coll = loader.loadModel(collision)
        coll.reparentTo(model)
        coll.find('**/collision').setCollideMask(BitMask32.bit(2))
        coll.find('**/collision').setPythonTag('object', model)
        if animation:
            model.setPythonTag('actor_files', [file, anims, coll])
    else:
        try:
            model.find('**/collision').setCollideMask(BitMask32.bit(2))
            model.find('**/collision').setPythonTag('object', model)
        except:
            print "WARNING: Model {0} has no collision geometry!\nGenerating collision sphere...".format(
                file)
            bounds = model.getBounds()
            radi = bounds.getRadius()
            cent = bounds.getCenter()
            coll_sphere = model.attachNewNode(CollisionNode('collision'))
            coll_sphere.node().addSolid(
                CollisionSphere(cent[0], cent[1], cent[2], radi))
            coll_sphere.setCollideMask(BitMask32.bit(2))
            coll_sphere.setPythonTag('object', model)
            #coll_sphere.show()
            if animation:
                model.setPythonTag('actor_files', [file, animation, None])
    if ConfigVariableBool('framebuffer-srgb', False).getValue():
        fixSrgbTextures(model)
    return model
Ejemplo n.º 13
0
def loadModel(file, collision=None, animation=None):
    model=None
    if animation:
        collision=file+'/collision'
        anims={}
        dirList=listdir(file+'/animation')
        for fname in dirList:                            
            anims[fname[:-4]]=file+'/animation/'+fname
        #print anims    
        model=Actor(file+'/model', anims)                   
        #default anim
        if 'default' in anims:
            model.loop('default')
        elif 'idle' in animation:
            model.loop('idle')
        else: #some first, random anim
             model.loop(anims.items()[0])
    else:
        model=loader.loadModel(file)
    model.setPythonTag('model_file', file)
    #load shaders
    for geom in model.findAllMatches('**/+GeomNode'):
        if geom.hasTag('light'):
            model.setPythonTag('hasLight', True)
        if geom.hasTag('particle'):
            file='particle/'+geom.getTag('particle')
            if exists(file):
                with open(file) as f:  
                    values=json.load(f)
                p=createEffect(values)                
                model.setPythonTag('particle', p)    
                p.start(parent=model, renderParent=render) 
        if geom.hasTag('cg_shader'):            
            geom.setShader(loader.loadShader("shaders/"+geom.getTag('cg_shader')))
        elif geom.hasTag('glsl_shader'):  
            glsl_shader=geom.getTag('glsl_shader')  
            model.setShader(Shader.load(Shader.SLGLSL, "shaders/{0}_v.glsl".format(glsl_shader),"shaders/{0}_f.glsl".format(glsl_shader)))
        else:
            #geom.setShader(loader.loadShader("shaders/default.cg"))
            model.setShader(Shader.load(Shader.SLGLSL, "shaders/default_v.glsl","shaders/default_f.glsl"), 1)
            print "default shader!"
    #collisions        
    model.setCollideMask(BitMask32.allOff())
    if collision:
        coll=loader.loadModel(collision)
        coll.reparentTo(model)
        coll.find('**/collision').setCollideMask(BitMask32.bit(2))        
        coll.find('**/collision').setPythonTag('object', model)
        if animation:
            model.setPythonTag('actor_files', [file,anims,coll]) 
    else:
        try:
            model.find('**/collision').setCollideMask(BitMask32.bit(2))        
            model.find('**/collision').setPythonTag('object', model)        
        except:
            print "WARNING: Model {0} has no collision geometry!\nGenerating collision sphere...".format(file)
            bounds=model.getBounds()
            radi=bounds.getRadius()
            cent=bounds.getCenter()
            coll_sphere=model.attachNewNode(CollisionNode('collision'))
            coll_sphere.node().addSolid(CollisionSphere(cent[0],cent[1],cent[2], radi)) 
            coll_sphere.setCollideMask(BitMask32.bit(2))        
            coll_sphere.setPythonTag('object', model)
            #coll_sphere.show()
            if animation:
                model.setPythonTag('actor_files', [file,animation,None])
    if ConfigVariableBool('framebuffer-srgb',False).getValue():
        fixSrgbTextures(model)            
    return model