i’m currently doing a fps game on panda in c++. the game will allow multiple occurance of the same character(same model & animations used). so i’m trying 2 find out if there is anyway tat the model and/or animation can be loaded only once with the animation of tat model stil being controllable separately 4 each occurance of the character.
Just create a different Actor for each instance. Panda will internally ensure that the model (and its animation files) are only loaded from disk once.
cough drwr, I think he’s using c++.
But anyway, I think Panda3D will do the same for c++ models… store them in cache, right?
Oops, right, my bad. But, yeah, Panda’s model caching is handled via the ModelPool. Assuming you are using ModelPool to load your models, you will only hit the disk the first time you load each particular model or animation file.
no i’m not using the modelPool 2 do loading, i did not even noe tat it existed, so thx but can pls explain how this modelPool is used in c++ or point me 2 some reference tat i can use coz its kinda hard 2 find code examples 4 it.
i’m having probs trying 2 use modelPool. i tried 2 load and render the model in this way:
_characters[charId]->model = ModelPool::load_model(charModel[RALPH].modelFileName);
i got an assertion error when i try run the programme, saying !is_empty() at line 944 of panda/src/pgraph/nodePath.cxx. hence, i think i loaded the model wrongly, can some1 pls help me.
The manual also states:
Note that the default behavior is thus to make instances: use with caution. Use the copy_subgraph() method on Node (or use NodePath::copy_to) to make modifiable copies of the node.
does tat mean i hav 2 make copies of the node tat the model is loaded in2 2 control the animations separately?
I’m sorry, I’m giving you bad advice again. There is a C++ Loader class, it is the best class to use for loading models. It handles some of the dirty details like looking along the model-path and making a copy of the result returned from ModelPool. (ModelPool is a lower-level class, and you shouldn’t have to use it directly, because we have the Loader class.)
To use Loader, do something like this:
Loader loader; PT(ModelNode) model = loader.load_sync(load_model(charModel[RALPH].modelFileName)); characters[charId]->model = NodePath(model);
PT(PandaNode) instead of PT(ModelNode) has 2 be used 2 make the code runable.
PT(PandaNode) model; model = model_loader.load_sync(charModel[RALPH].modelFileName); _characters[charId]->model = NodePath(model); _characters[charId]->model.reparent_to(_WindowFramework->get_render());
hmm… is there a way i can check if the model is loaded or is a ptr 2 the model being returned so i can check if de code is working. n how would animation file be loaded in? if the animation files r loaded in the same way, how should the animations be binded 2 the model.
current way of loading n binding animation files:
_WindowFramework->load_model(_characters[charId]->model, charModel[charType].runAnimFileName); _WindowFramework->load_model(_characters[charId]->model,charModel[charType].jumpAnimFileName); auto_bind(_characters[charId]->model.node(),_characters[charId]->ModelAnimControl, PartGroup::HMF_ok_part_extra | PartGroup::HMF_ok_anim_extra | PartGroup::HMF_ok_wrong_root_name);
Using the WindowFramework::load_model is also acceptable; it all filters through the ModelPool eventually.
You can call ModelPool::list_contents() to list the models that are cached in the model pool.
aaaahhhh. looks liked i hav been fooled by panda again. coz when using Windowframework::load_model, it will always output a message on the console saying tat its loading a model despite it just returning the nodepath of an already loaded model, not actual loading of the model again. thx anyway 4 ur help, it at the very least helped in understanding the panda framework.