How to add clothing to character model

  1. I have character model with animation
  2. I have armor

How to attach armor node to character node what would the armor move with the character

The armor model needs to have vertex groups setup to match the animated character. Then if you attach the armor piece to the same node containing the AnimControl/Composer in JME, the armor will follow the animations.

You can set up the vertex groups in blender using a tool for vertex weight transfers (I havenā€™t done it in a while to remember the details, but you can find lots of video tutorials showing how to do it on youtube).
Basically you will just load both the character and the armor into the same blender scene, position the armor on the character in the right spot, and then use the weights transfer tool to apply the vertex group/weights from the character model to the armor/clothing model. Then export that armor piece by itself and you can attach it to the character dynamically in jme as needed.

It might also take some tweaking and manual adjustments to the vertex weights after using the tool in order to make sure the armor piece doesnā€™t clip and that it moves smoothly when animations are playing. Thereā€™s also more advanced methods to cleaning up attached armor/clothing during animations, but I havenā€™t done much in that regard yet to give more insight.

1 Like
  1. make character
  2. make armor
  3. attach armor to cahracter in blender
  4. make weights for armor
  5. delete character
  6. export armor to jmonkey
  7. attach armor to character

and armor move with character right?
what code to use to attach the armor model?

https://javadoc.jmonkeyengine.org/v3.5.1-stable/com/jme3/scene/Node.html#attachChild-com.jme3.scene.Spatial-

You can attach it to a bone so it will move with the bone (e.g. attaching a sword to hand).

This is only true if the armor is separate static pieces. If they are animated with the mesh as described earlier then they need to be attached to the model like any other child.

ā€¦though now that Iā€™ve said that, I donā€™t know if you need to do anything special to get the animcomposer and/or skinning controls to coordinate.

2 Likes

Yeah in my case Iā€™ve only ever done this with the old animation system (AnimControl and SkeletonControl) so I cannot say for sure if thereā€™s anything else that needs done if youā€™re using the new anim system (AnimComposer and SkinningControl).

But in my case I simply attach parts to the animated spatial prior to attaching it to the rootNode, and the clothing animation all works.

@Override
public void initSpatial(AssetManager assetManager) {
     
   Spatial baseFemaleSpatial = assetManager.loadModel("Models/CharacterBuilder/CharacterModels/woodElf_female/baseFemaleSpatial_0.j3o");

     Spatial bandeauSpatial = assetManager.loadModel("Models/CharacterBuilder/Clothing/Female/elvenSleevedCropTop0/elvenSleevedCropTop0.j3o");
     Spatial hairSpatial = assetManager.loadModel("Models/CharacterBuilder/Hair/Female/frenchBraid0/frenchBraid0.j3o");
     Spatial skirtSpatial = assetManager.loadModel("Models/CharacterBuilder/Clothing/Female/elvenShortSkirt0/elvenShortSkirt0.j3o");
               
    ((Node)baseFemaleSpatial).attachChild(bandeauSpatial);
    ((Node)baseFemaleSpatial).attachChild(hairSpatial);
    ((Node)baseFemaleSpatial).attachChild(skirtSpatial);        
  
    spatial = baseFemaleSpatial;
}
1 Like
  1. make character
  2. make armor
  3. attach armor to cahracter in blender
  4. make weights for armor
  5. delete character
  6. export armor to jmonkey
  7. attach armor to character

just a tip also about 4. (btw. you no need step 5. since you can export objects you want)

still got some old screnshot, here is how you can easly configure them more precisly.

1 Like

Yes, I mean there is no need to weight paint armor if OP wants to use attachment node.

1 Like

I have 2 errors

  1. boots move separately from the model in blender
  2. in jmonkey boots not move
character = assetManager.loadModel("Models/char.glb");
        rootNode.attachChild(character);
        character.setLocalTranslation(1.2311511f, -0.5f, 6.1211777f);
        character.setLocalScale(0.15f);
        character.rotate(0, -1.7f, 0);
        
        //AnimComposer animComposer = character.getControl(AnimComposer.class);
       // animComposer.setCurrentAction("run");
       Node charNode = (Node)character;
       Node armature = (Node)charNode.getChild("Armature");
       AnimComposer animComposer = armature.getControl(AnimComposer.class);
       animComposer.setCurrentAction("run");
       
        Spatial boots = assetManager.loadModel("Models/boots.glb");
        charNode.attachChild(boots);

where is the mistake?

Hmm, it seems to me they are not correctly weight painted to bones.

charNode.attachChild(boots);

change the above line to

armature.attachChild(boots);

and see if it makes any difference.

1 Like

charNode.attachChild(boots);

exported boots have a buildable skeleton
who made rpg tell me how please

If the boot are made properly and setup in their own j3o scene correctly, then they should work from simply attaching them to the node that contains the AnimComposer

That means:

  1. the boots should have proper vertex weights/groups

  2. the boots should be positioned so that they are overtop of the feet when you attach them

  3. the j3o file containting the boots model should not have an AnimComposer or Armature - its vertex groups are stored in the mesh, so thereā€™s no need for any extra controls for the boots.

  4. The clothing and the model youā€™re attaching the armor/clothing to should have locataion/rotation/scale applied before export. Not sure if you did this but I see it hasnā€™t been mentioned in this thread so heres that info just in case: Importing models with animations from Blender - #9 by silentsword.

If you still have trouble, I can try to post a video showing how I attach a compatible clothing piece to my base character model in the Scene Composer, but if you have everything with the boots and character model set up its just as easy as attaching the boots to the Spatial that has the Armatureā€¦

Edit: one other thing to note: when i do this in the SDK scene composer, I have to close and reopen the scene for the animations to register after Iā€™ve attached the clothing. At run-time I attach clothing prior to the model being attached to the rootNode, so attachment order seems to matter as well.

So, why not attaching the boots before the animation starts ? A better design would be creating a common node from the start and name it character and add the character body and the boot to it then create an armature animation for the common node.

And btw, i noticed that your animation runs only on the armature part, you should get another animcomposer for the boots and run it (if it has separate keyframes).

the boots have proper vertex weights/groups

in my presence there is a skeleton and animation, how to export without a skeleton and animation?

i apply rotation scale and location to models

new code

character = assetManager.loadModel("Models/char.glb");
        character.setLocalTranslation(1.2311511f, -0.5f, 6.1211777f);
        character.setLocalScale(0.15f);
        character.rotate(0, -1.7f, 0);
        
        //AnimComposer animComposer = character.getControl(AnimComposer.class);
       // animComposer.setCurrentAction("run");
       Node charNode = (Node)character;
       Node charArmature = (Node)charNode.getChild("Armature");
       
       
        Spatial boots = assetManager.loadModel("Models/boots.glb");
        charNode.attachChild(boots);
        
        rootNode.attachChild(character);
        
        
       AnimComposer animComposer = charArmature.getControl(AnimComposer.class);
       animComposer.setCurrentAction("run");

can you record video with glb example

i think character model have armature and boots attach to armature with animation

which animcomposer use?

An armature would have joints and joints or bones can run different animations, i will send an example for an armature control.

Character with boots boots.blend ā€” ŠÆŠ½Š“ŠµŠŗс.Š”ŠøсŠŗ
Look please

I think you also need to apply them on the Armature.