[SOLVED] Cloth system

i have 2 model with 1 on armature
1 leg with run animation
2 i add object add weights and delete leg

need that the necessary objects moved along with one skeleton
i get leg sekeleton
remove boots skeleton
and add leg skeleton to boots

try this code

   @Override
    public void simpleInitApp() {
        Node player= (Node)assetManager.loadModel("Models/test.glb");
        Node playerArmature = (Node)player.getChild("Armature");
 
        AnimComposer playerAnim = playerArmature.getControl(AnimComposer.class); 
        SkinningControl skeletonPlayer = playerArmature.getControl(SkinningControl.class);

        Node boots= (Node)assetManager.loadModel("Models/test2.glb");
        Node bootsArmature= (Node)boots.getChild("Armature");
        AnimComposer bootsAnim = playerArmature.getControl(AnimComposer.class); 

        //SkinningControl skeletonBoots = bootsArmature.getControl(SkinningControl.class);
        bootsArmature.removeControl(SkinningControl.class);
        bootsArmature.addControl(skeletonPlayer);
        
        player.attachChild(boots);
        
        

        rootNode.attachChild(player);

        playerAnim.setCurrentAction("run");        
        setUpLight();
    }

java.lang.IllegalStateException: This control has already been added to a Spatial
at com.jme3.scene.control.AbstractControl.setSpatial(AbstractControl.java:61)
at com.jme3.anim.SkinningControl.setSpatial(SkinningControl.java:238)
at com.jme3.scene.Spatial.addControl(Spatial.java:777)
at tests.Tests.simpleInitApp(Tests.java:50)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:240)
at com.jme3.system.lwjgl.LwjglWindow.initInThread(LwjglWindow.java:548)
at com.jme3.system.lwjgl.LwjglWindow.run(LwjglWindow.java:662)
at java.base/java.lang.Thread.run(Thread.java:829)

try add leg anim to boots

    @Override
    public void simpleInitApp() {
        Node player= (Node)assetManager.loadModel("Models/test.glb");
        Node playerArmature = (Node)player.getChild("Armature");
 
        AnimComposer playerAnim = playerArmature.getControl(AnimComposer.class); 
        SkinningControl skeletonPlayer = playerArmature.getControl(SkinningControl.class);

        Node boots= (Node)assetManager.loadModel("Models/test2.glb");
        Node bootsArmature= (Node)boots.getChild("Armature");
        AnimComposer bootsAnim = playerArmature.getControl(AnimComposer.class); 
bootsArmature.removeControl(bootsAnim);
bootsArmature.addControl(playerAnim);
        //SkinningControl skeletonBoots = bootsArmature.getControl(SkinningControl.class);
        //bootsArmature.removeControl(SkinningControl.class);
       // bootsArmature.addControl(skeletonPlayer);
        
        player.attachChild(boots);
        
        

        rootNode.attachChild(player);

        playerAnim.setCurrentAction("run");        
        setUpLight();
    }

IllegalStateException: This control has already been added to a Spatial

As this error states, you are trying to add the playerAnim AnimComposer to the boots when playerAnim is still added to the player.

To get rid of this error, you would first need to remove the playerAnim from the player Node, but then your player will no longer be animated and things won’t work how you want.

The proper way to do clothing is to have a single AnimControl and SkinningControl for the player model. Then attach your boots to the player node that contains the existent animControl and skinningControl.

The last few replies I left in this thread should explain how to get animated clothing/armor working: How to add clothing to character model - #38 by yaRnMcDonuts

2 Likes

i re read topic and try this:

        Node player= (Node)assetManager.loadModel("Models/test.glb");
        Node playerArmature = (Node)player.getChild("Armature");
        
        AnimComposer playerAnim = playerArmature.getControl(AnimComposer.class); 

        rootNode.attachChild(player);
        
        Node boots= (Node)assetManager.loadModel("Models/test2.glb");
        
        //1. Attach clothing to the animated model.
        player.attachChild(boots);
        
        //2 Detach the animated model from the scene
        rootNode.detachChild(player);
        
        //3 reload 
        SkinningControl skinningControl = ((Node) playerArmature).getControl(SkinningControl.class);    

        if(skinningControl != null){
           Armature armature = skinningControl.getArmature();
            playerArmature.removeControl(skinningControl);

            playerArmature.addControl(new SkinningControl(armature));
        }
        //4 attach 
        rootNode.attachChild(player);
        
        playerAnim.setCurrentAction("run");        
        setUpLight();

not working
what am I doing wrong ?

The boots need to be attached to the Node that contains your SkinningControl, so it looks like you instead need to call playerArmature.attachChild(boots);

2 Likes
 Node player= (Node)assetManager.loadModel("Models/test.glb");
        Node playerArmature = (Node)player.getChild("Armature");
        
        AnimComposer playerAnim = playerArmature.getControl(AnimComposer.class); 

        rootNode.attachChild(player);
        
        Node boots= (Node)assetManager.loadModel("Models/test2.glb");
        
        //1. Attach clothing to the animated model.
        playerArmature.attachChild(boots);
        
        //2 Detach the animated model from the scene
        rootNode.detachChild(player);
        
        //3 reload 
        SkinningControl skinningControl = ((Node) playerArmature).getControl(SkinningControl.class);    

        if(skinningControl != null){
           Armature armature = skinningControl.getArmature();
            playerArmature.removeControl(skinningControl);

            playerArmature.addControl(new SkinningControl(armature));
        }
        //4 attach 
        rootNode.attachChild(player);
        
        playerAnim.setCurrentAction("run");        
        setUpLight();

not work

i need to delete from boots armature or nim composer?

The boots need both the Armature and AnimComposer deleted after you convert the model to j3o format.

The boots also need to have vertex groups setup properly to match the Armature that they’re being added to.

1 Like

i delete anim composer
in scene viewer i cant delete armature ( no such menu)

i re re read theme and

    @Override
    public void simpleInitApp() {
        Node player= (Node)assetManager.loadModel("Models/test.glb");
        Node playerArmature = (Node)player.getChild("Armature");
        
        AnimComposer playerAnim = playerArmature.getControl(AnimComposer.class); 

        rootNode.attachChild(player);
        
        Node boots= (Node)assetManager.loadModel("Models/test2.j3o");
        Geometry bootsGeom= (Geometry)boots.getChild("Sphere");

        

        //1. Attach clothing to the animated model.
        playerArmature.attachChild(bootsGeom);
        
        //2 Detach the animated model from the scene
        rootNode.detachChild(player);
        
        //3 reload 
        SkinningControl skinningControl = ((Node) playerArmature).getControl(SkinningControl.class);    

        if(skinningControl != null){
           Armature armature = skinningControl.getArmature();
            playerArmature.removeControl(skinningControl);

            playerArmature.addControl(new SkinningControl(armature));
        }
        //4 attach 
        rootNode.attachChild(player);
        
        playerAnim.setCurrentAction("run");        
        setUpLight();
    }

it work s!!!

this was the main question on the way to a possible rpg thanks a lot

I quit making games because of this

I think the developers should make it more convenient for users and add a tutorial

4 Likes

also if you want physics movement based cloth parts, then you can use Minie for that.