Changeable clothing

How to implement a changeable clothing system?

I know variants of this question have been asked here before and elsewhere on the web but I’m still a little confused as to which method is best but more importantly once I have made a decision I have no idea about how to implement it. Let me elaborate:

First the decision on how to achieve this:

  1. Create a base mesh and simply add clothing over the top of it. Meaning that if I have a character wearing a pair of trousers then the entire base mesh and the trousers will all be in the scene but the trousers will obscure some of the base mesh (not entirely a good idea as if the character is fully clothed then almost all of the base mesh hidden anyway)

  2. Create separate parts of the mesh for different aspects of the character then construct this character at runtime by selecting which parts to render. Here the mesh is broken up into parts, say head, torso (including arms), hands, legs and feet. This is favorable in terms of performance I think.

I am leaning towards option 2 and can achieve this in blender from the model I currently have quite easilly. However I am not entirely sure how to go about it. Therefore:

Secondly how to implement this:

And this is my real question as I’m pretty much set on option 2 above.

Do I create a separate object in my blender scene for every type of head, hands, torso, etc… all layered over one another (I guess I can hide layers else I’ll have trouble working with all the overlaying objects), so that I can rig them all to the same skeleton? I guess the answer to this is yes.

But once I have done this I’m a little unsure about the process. When I come to export the model will it all come in one object file or will it be broken up, will it need to be broken up even? And once it is loaded how do I select each part of the model to display and make sure that it syncs with the animation of the rest of the parts of the model?

I think option two is difficult since you need to set vertex weights properly for normal style bone animations. (Excapt you go for minecraft like non deformable characters)

Btw. depending on amount of stuff you have choice three:
Materialize all combinations for most of the gear, however this can quickly become a very large amount.
Benefit would be the ability to slightly tweak animations ect. for clothing so no hand trough sword animation bugs or similar appear.

Typically the way this is done is the rig (bone structure) has to be shared between all models in order for the clothes to be compatible. Then all the clothing and such would be created for that rig and exported separately.
In jME3, you have to import those clothes together with the rig (so it gets a SkeletonControl and all), then you can just take geometries from the clothes model and attach them to the character model. AFAIK, in jME3.0, the SkeletonControl automatically detects skinned meshes attached to the model and will animate them with the rest of the model.

Whilst my game is not actually going to have much in the way of choice for items I am attempting to do it in a scalable way for the practice/experience, so option 3 would work for me but it is not what I am trying to achieve for other reasons.

I don’t envisage option 2 being too difficult to achieve, but you may be right and I might look back on this decision with regret but I’m gonna stick with option 2. I’m going to make a quick animation test to see if it is really a terrible choice.

@Momoko_Fan The way I currently have it set up is to have all the different objects in different layers of the blender scene with the rig in its own as well. If I wanted to export these should I copy each object and the whole rig to a new file and then export it? (I’m not sure if using the ogre exporter I can do layer by layer)

Also what would constitute this:

the rig (bone structure) has to be shared between all models

do the bones just need to have the same names and transformations etc…? What could I do to make that statement invalid for my models (ie. what should I avoid)?

Pretty sure the ogre exporter supports exporting “selected objects only” which could be used in this case. Once jME’s FBX importer is finished, you could use the batch export feature to export all objects as separate files.

Actually I am not entirely certain how that would work with the ogre exporter… Since the order of how it reads the bones depends on the indices they get and hence their compatibility … So even an armature with exactly the same structure and transformations might still be incompatible. I guess if its coming from the same file it should be fine.

So I was able to get it to work, although there is an issue with my animation currently (looks all kinds of crazy).

I made all my objects in the same scene in blender, I just added them to separate layers for visibility sake and then I animated them all to the same armature. And everything went pretty smoothly actually.

When it came to exporting the objects I just selected everything and performed the ogre export. Each of the objects generated mesh.xml, .material and skeleton.xml files.

Loading the mesh into JME was done in the normal way. I was then able to switch the clothing pieces out for new ones on the fly, even during animations. However this does not come without its complications (ie removing a mesh from the root node essentially pauses the animation, so they don’t keep up with each other when they are disabled, and this is only the most basic case). I’m not sure the best way to handle all the animations to sync them properly yet but what I have done so far was only a proof of concept. I’m sure there are easy solutions.