Path problems

Hi,

I am new to Panda but have been scripting in Python for a few years.

I am following tutorials and have had no problems until I started making my own textures and height fields. I want to use relative paths but Panda always returns the same error:

:grutil(error): Failed to load heightfield image assets/heightmap!
:grutil(error): No valid heightfield image has been set!

I am using forward slashes in the latest stable release of Panda (1.7x). When I have done tutorials using models in the standard Panda install, it works .g.:
self.environ = self.loader.loadModel(“models/environment”)

But when I create my own textures I get an error. I have tried chdir. I have tried relative paths (dotted). I have tried full paths with forward slashes. My python script and the images on on my D drive - does Panda only honour the C drive? Does Panda not like PNG files? I have used file to

I’m all out of ideas! Help please!!

Thanks

loader.loadModel() searches along the model-path. What is your model-path set to? Does it include the root directory of your models tree? You can add additional model-path lines in your Config.prc file with something like:

model-path /d/my/models/root

Also, note that it won’t load models from the current directory unless your current directory is on the model-path:

model-path .

David

You can try this too:


		#portability stuff
		mydir = os.path.abspath(sys.path[0])
		mydir = Filename.fromOsSpecific(mydir).getFullpath()	
self.environ = loader.loadModel(mydir + "/graphics/arena2.egg")

graphics is a directory inside the directory i run the code and arena2.egg is my model.

Thanks guys. Although I’d switched my slashes, I left the colon in after the drive letter and didn’t add a slash at the front of the path.

DOH! :confused:

I am so brainwashed by Windoze that I couldn’t see my error because it looked correct. :unamused:

Bad:
“D:/myPath/someFolder/assets/nicePiccie.png”

Good:
“/d/myPath/someFolder/assets/nicePiccie.png”

For the record, that code won’t work in the web plugin, only in the interpreter. This is a better and easier alternative:

self.environ = loader.loadModel("$MAIN_DIR/graphics/arena2.egg")

Tried at windows and didn’t work for me.

Are you sure? It should refer to the directory in which the main.py is located. You can always try:

from panda3d.core import ExecutionEnvironment
print ExecutionEnvironment.getEnvironmentVariable("MAIN_DIR")

and you’ll see what it refers to, so that you can find out where it goes wrong.