loader's path

I know that Panda takes paths relative to the current working directory. I would like to know if there is any existing feature in the loader that can load models/textures/shaders, from a preset list of paths ?

e.g. loader.SetSearchPath([ “.”, “…”, “/d/dir1”])

such that if I called loader.loadModel(“models/ball.egg”)
It will try to load from ./models/ball.egg, then …/models/ball.egg then /d/dir1/models/ball.egg

If not, what is a better way to implement this ? The straight forward way is to sub-class the loader class and have my application to use this loader class. Any other good suggestions ?

Use the model-path config variable. Put:

model-path .
model-path ..
model-path /d/dir1

in your Config.prc file.


Thank you for the answer.

I need to make it dynamic, I try:
config = ConfigVariableSearchPath(‘model-path’)
It looks like it can make a local change on my own variable but the Panda system is not affected. How to make Panda aware of my new path ?

You can try this:

from pandac.PandaModules import loadPrcFileData
your_path = "path/to/models/"
loadPrcFileData("", "model-path %s" % your_path)

It works perfectly. Thank you.

You can also use:

config = getModelPath()


GeoMipTerrain.setHeightfield() seems not using the default loader ? Is there any ways to add a search path for it ?

Hmm, I never really thought about that. It just internally uses PNMImageHeader.readHeader and PNMImage.read.