Can someone help to explain very odd behavior of the model loader? Bear with the extremely long description. The behavior I see in the end strikes me as so weird that I don’t want to assume any piece of this is irrelevant.
First of all, I’m using Eclipse with PyDev under Windows and Panda3D 1.6.2. Broadly what I’m trying to do is work out a folder structure within a PyDev project that makes sense to me, and figure out what the configuration and code have to do to work with that structure. So I started with the Roaming Ralph sample.
Step 1:
I created a PyDev project called Roaming-Ralph. This gets me a project folder with nothing in it but an empty “src” subfolder and some hidden Eclipse information files.
Step 2:
I copied the following into the /src folder from the Roaming-Ralph folder of Panda: the Tut-Roaming-Ralph.py script, and all the .jpg and .egg.pz files in the models folder. Eclipse’s Import keeps them in their original structure, so I now have:
/src/Tut-Roaming-Ralph.py
/src/models/ground.jpg
/src/models/hedge.jpg
/src/models/ralph.egg.pz
etc.
At this point, if I run the .py file, it works perfectly. However, I don’t want my model, texture, and animation data in my /src folder, so…
Step 3:
I moved the models folder up one level. Now I have:
/src/Tut-Roaming-Ralph.py
/models/ground.jpg
/models/hedge.jpg
/models/ralph.egg.pz
etc.
When I run now I get “IOError: Could not load model file(s): [‘models/world’]”. This doesn’t surprise me; I figure I need a configuration change for the loader to find the models at their new home. But since a configuration file is again neither source nor a model…
Step 4:
I created a new folder in the project called “config”, and I create a “config.prc” file in it. The PRC contains only one line, which reads “model-path $THIS_PRC_DIR/…”. I noticed that the code gives all the model paths as “model/foo”, so I figure it expects to start in the parent folder of models. I don’t want to change the code just yet, except to have it load my custom config. So after the lines that “from pandac.PandaModules import” a bunch of stuff, I add another: “from pandac.PandaModules import loadPrcFile”. And then as soon as it’s done with all the imports I add “loadPrcFile(”…/config/config.prc")
At this point it again runs perfectly, so I’m making progress. But I’m still not satisfied. I’d rather consider “models” to be a subset of “resources”. There could be other data that falls under resources, such as localized messages, and those would get their own separate subfolder.
Step 5:
I created a “resources” folder in the project and moved the models folder under it. Now I have:
/src/Tut-Roaming-Ralph.py
/config/config.prc
/resources/models/ground.jpg
/resources/models/hedge.jpg
/resources/models/ralph.egg.pz
etc.
Then I changed the model-path in the PRC file from “$THIS_PRC_DIR/…” to “$THIS_PRC_DIR/…/resources”.
Still, the program runs just fine, so I’m going to go for one more refinement. As far as I’m concerned, textures are not “models” and don’t belong in the “models” folder. (I’ll worry about the animations later.)
Step 6:
I created a second subfolder of resources called “textures” and moved the .jpg files into it. Now I have:
/src/Tut-Roaming-Ralph.py
/config/config.prc
/resources/textures/ground.jpg
/resources/textures/hedge.jpg
/resources/models/ralph.egg.pz
etc.
Now, I’m not surprised that the program gives me problems at this point. The glaring one is that the display is stark black and white, no textures. When I look at the Python console, I see error messages, two for each texture:
:gobj(error): Texture::read() - couldn’t read: ralph.jpg
:gobj(error): Unable to find texture “ralph.jpg” on model-path /c/Documents and Settings/ […]
The model-path given includes a good path to my resources folder, as well as my src folder and a couple irrelevant ones inside the Panda installation. Okay, so apparently textures are not looked for in subfolders of the model-path. However, even before I start trying to resolve that I notice that things start to get fishy. If I run the program again with no changes, the display remains the same, but this time there are no errors on the console. Huh?
Okay, I just want to get it back to working now. So I undo the changes of Step 6, getting the project back to exactly what it looked like after Step 5. But it still doesn’t work. No errors on the console, but still no textures in the display. I can fix this, but only by doing something bizarre: I have to copy the original .egg.pz files from the Panda installation over the ones in my project.
What on earth is going on? Is the model loader actually corrupting my egg files when it can’t find the right textures? I’ll admit I haven’t yet read the full documentation on how egg files work or how to use the tools that generate them, but can someone at least tell me if this is documented, as-designed behavior? Cause it sure feels like a bug to this programmer.