When i load model twice, it loads the cached model instead of the modified model in the disk

I am a newbie to Panda3D. I am writing a script that takes an actor name or a static model name and loads it but with some random texture. Unfortunately i couldn’t use the find method to set a texture because every model or actor will have different names for the parts i want to change the texture for. I used a stupid trick and replaced the texture images with another images in the script before loading the model. The problem is that Panda3D caches the models. So this trick doesn’t work if i loaded the same model twice because in the second time the model isn’t read again with the newly replaced textures but it is loaded from the cache. What should i do?
Any help would be appreciated.
Thanks in advance.

Try loader.loadModel (“model.egg”, noCache = True)

Thank you very much for your reply. Unfortunately, i tries this solution but it did’t work and this parameter doesn’t exist also in Actor.
I also tried removing those lines from the configuration file
model-cache-dir $USER_APPDATA/Panda3D-1.7.0/cache
model-cache-textures #f
but that didn’t work also =(

In any case, you need to consider changing the texture with code.

I tried that too. I stored the names of the parts that i want to change in each model but find method returned not found for some models and i don’t know what is wrong. I also tried setTexture without directly on the actor without using find and it made a strange texture on my model some sort of blended texture from the original and the new one.

This thread might be of use to you. Based on a quick test–albeit with a non-animated model, rather than an Actor–the specific post to which I link there seemed to work. However, if it doesn’t, then perhaps one of the other approaches given in the thread will!

Thank you very much for your reply.
According to what i understood from the thread, i have to find the texture stage of te texture i want to replace. My model have multiple textures so it have multiple texture stages. I found all of te texture i my models using this function [findAllTextures] and to find the texture stage of the texture i want to change i use this function [findTextureStage] but it returns None although i used the names in the list returned from [findAllTextures]. What i am doing wrong ?
Thanks in advance.

findTextureStage takes the name of a texture stage, not that of a texture. So unfortunately it looks like you would need to recurse over the node graph to find where exactly the texture is applied.

Would it help you if we added a replaceTexture() function that replaced occurrences of a given texture with a different one?

(And for the record, the way to use noCache with Actor is to pass the result of loadModel into where you would otherwise have passed the path to the model.)

I am not sure that i know how to find where a texture is applied can you give me any hints please?
Yes, i think that this function would help me a lot.
For the record i read this thread freeing actors/models/textures and modified the configuration file according to it. The models stopped loading from the cache but unfortunately all the models used the last replaced image in my directory (although i replaced these images each time i loaded the model but the models use only the last replaced one) and i don’t know why.

There is another thing that i don’t understand. I know that a texture stage holds only one texture for the model. But this call len(self.myActor.findAllTextures()) returns 8 and this call self.myActor.findTextureStage(’’) returns a single texture stage which i don’t understand. I expected self.myActor.findTextureStage(’’) to return 8 texture stages. what is wrong with that?
Thanks in advance.

I assume in this case that the model has different sub-parts, which have different textures applied to them, on the same texture stage.
Try calling model.ls() to show the hierarchy of the model.

I will try it. Thank you very much for help =D

I’ve just checked in this change; as of Panda3D 1.10.4, it will be possible to call model.replaceTexture(tex1, tex2) to replace all occurrences of tex1 with tex2.

1 Like