This isn’t really a scripting isseu but just something I don’t really
understand how to program it, ok here I go.
I’m developping an open-ended RPG, you have a character, where you can
walk with, fight with, etc.
you can also change the characters clothes and when the player changes
the characters clothes, the model of the current clothes
should change in another model (the model of the new clothes).
Thats where I have a problem, how do I program a character that can change clothes, can change weapons etc. without having problems with the walk cycle, fighting moves and other things the character can do ?
Here’s my suggestion: create a model that is wearing five pairs of pants at the same time. In other words, in maya (or max), model a pair of pants, then hide the pants and model another pair, then hide that pair and model a third, and so forth, then unhide all of them so that they’re all overlapping.
Rig and skin the model with all five pairs of pants. Export it that way.
Then, using panda calls, search the model for the five pairs of pants, and hide four of the five.
OK, so overlap 30 pairs of pants on the same model. If you’ve really got 30 different pairs of pants, you have to model them all somewhere. You might as well keep them all in the same file, and this is the best way to make sure they all animate with the character. Then when you hide 29 of them in-game, you won’t be paying the cost to animate them.
Although chances are good these aren’t actually 30 different pants models–I’ll bet a lot of them are really exactly the same shape, but with a different texture. You might really have just two or three different pairs of pants when you ignore the texture. If this is the case, then you can just overlap the two or three different pairs of pants on your model, and then swap the appropriate texture on at runtime.
Warning to casual users of Panda: the following discussion is to be considered for advanced users only. Performance tuning is an art, and it is easy to get bogged down in performance tuning at the detriment of coding. Panda is all about making things easy to use; usually, you should take advantage of this and write your application first, the easy way, and then go back and worry about performance tuning.
So. The fastest possible way to render a (possibly animated) model that includes several hidden parts.
nodePath.hide() on all of the hidden parts is the easiest, and is a perfectly acceptable; the node will no longer be visited by the render traversal (but it is still in the scene graph, and may still be visited by the collision traversal and other traversal).
nodePath.stash() might be a tiny bit faster, since it completely removes the node from the scene graph, so that most traversals will no longer visit it; also, the parent node’s bounding volume will be recomputed without the stashed node.
Both of these, of course, require that each separate pair of pants is its own geom node, which has its own implications on performance (rather than having a single monolothic geom node for the whole character), but this is the price you pay for runtime versatility. You can use the -flag options to egg-optchar to make each pair of pants its own geom node.
It is also possible to run character.flattenStrong() after you have stashed the other four pants to try to reduce the number of geom nodes as much as possible, but this operation is irreversible and means you’ll no longer be able to switch pants on that character without reloading it from scratch. Of course, it may be worth it for the tiny frame rate boost you can get. To maximize the effectiveness of the flattenStrong operation, you’ll need to ensure the character is using as few different textures (or different render states in general) as possible, so egg-palettize will be your best friend here. Of course, egg-palettize also makes runtime swapping of the pants textures problematic. The application (and the target hardware) will have to determine the right balance point.
To have a character that can have multiple clothings.
Solution(Besides the above ones):
-i export the rigged and animated character model with a single model.(like an ordinary actor)
-i model additional clothing models and export them as static non rigged non animated models(as separate files)
The clothing model can be stored as a simple array of vectors(so it would be way smaller than an ordinary model file)
-now if i want to change the clothing(the model) i so to say morph it by adding all the new vertex poses from the clothing model to the character model
This way has its limitations to what kinda clothings you can have but(the exceptions can be done by the above methods mentioned by josh and david)
The more flexibility you want to have with this way the better you have to think how to model your original character.
Another idea would be to have only one egg file containing the rigged/animated character who is “wearing” all clothes at once. Each piece of cloth is a single GeomNode. With cloth I mean skin parts too, so for example “left hand”, “pants”, “boots v1”, “boots v2”, “neck”, and so on.
After loading this model you can hide all nodes except for those which you want to be seen during the game.
Changing clothes should be easy too. Just hide the nodes you want to put off, and show those nodes you want to put on.