def Set( self, dirPath ): # Check project definition file exists if not os.path.exists( os.path.join( dirPath, PROJECT_DEF_NAME ) ): self.path = None return # Set the project directory oldPath = self.path self.path = dirPath # Clear the model search path and add the new project path. Make sure # to prepend the new directory or else Panda might search in-built # paths first and supply the incorrect model. base.ResetModelPath() modelPath = pm.Filename.fromOsSpecific( self.path ) pm.getModelPath().prependDirectory( modelPath ) # Remove the old project path from sys.path and add the new one if oldPath in sys.path: sys.path.remove( oldPath ) sys.path.insert( 0, self.path ) # Set paths self.SetDirectories() # Set directory watcher root path and start it self.dirWatcher.setDirectory( self.path ) if not self.dirWatcher.running: self.dirWatcher.start()
def ResetModelPath(self): """ Clears the model path, making sure to restore the current working directory (so editor models can still be found). """ pm.getModelPath().clear() pm.getModelPath().prependDirectory('.')
def ResetModelPath( self ): """ Clears the model path, making sure to restore the current working directory (so editor models can still be found). """ pm.getModelPath().clear() pm.getModelPath().prependDirectory( '.' )
def GetRelModelPath( self, pandaPath ): """ Attempt to find the indicated file path on one of the model search paths. If found then return a path relative to it. Also make sure to remove all extensions so we can load both egg and bam files. """ relPath = pm.Filename( pandaPath ) index = relPath.findOnSearchpath( pm.getModelPath().getValue() ) if index >= 0: basePath = pm.getModelPath().getDirectories()[index] relPath.makeRelativeTo( basePath ) # Remove all extensions modelPath = str( relPath ) while True: modelPath, ext = os.path.splitext( modelPath ) if not ext: break return modelPath
import os import os.path from panda3d.core import Filename from pandac import PandaModules as PM #set up some loading constants DIR = str(Filename.fromOsSpecific(os.path.dirname(os.path.abspath(__file__)))) #convert back to base string from panda type ASSET_DIR = DIR + "/assets/" PM.getModelPath().appendPath(ASSET_DIR) class TextureManager(object): def __init__(self, app): self.rocks = app.loader.loadTexture('rocks.png') for icon in ['arrow_out', 'asterisk_orange', 'bug', 'user']: setattr(self, icon, app.loader.loadTexture('icons/' + icon + '.png')) TEXTURES = None def init(app): global TEXTURES TEXTURES = TextureManager(app)