I spent more time working on attaching clothing with code dynamically at run-time (as opposed to doing it in the SDK like I was in the video I made in a previous reply) and it appears it’s not nearly as easy as I was expecting and implying.
In my video, I had to save and re-open the clothed model’s j3o file in the SDK to get the animations to register on the newly attached pieces. Apparently there is code that gets run in the SkeletonControl or AnimControl 's read method that is necessary for making the animations effect the newly attached clothing/armor.
So to get my clothing to work with animations at run-time, I had to use this code to do the following:
-
Attach clothing to the animated model.
-
Detach the animated model from the scene
-
Save the animated model to a temporary file in assets folder
-
Immediately re-load this file with assetManager (this triggers the controls’ read methods which appears to contain protected code necessary to make things work)
-
Re-attach the newly loaded model, and clothing pieces are now animated
Node cosmeticNode = agent.getCosmeticNode(); //node to attach clothing and other cosmetics to Node parentNode = cosmeticNode.getParent(); cosmeticNode.attachChild(clothingSpatial); parentNode.detachChild(cosmeticNode); File tempSaveFile = new File("assets/tempAnimHold.j3o"); BinaryExporter be = BinaryExporter.getInstance(); try { be.save(cosmeticNode, tempSaveFile); } catch (Exception ex) { ex.printStackTrace(); } cosmeticNode = (Node) agent.getApp().getAssetManager().loadModel("tempAnimHold.j3o"); agent.setCosmeticNode(cosmeticNode); parentNode.attachChild(cosmeticNode);
So I would say this is a bug in the function of AnimControl or SkeletonControl, and although I have not yet tested with the same with AnimComposer and Armature, I presume it has the same issue since the new anim system only worked for me in the SDK, and was giving the OP similar troubles when doing the same with code.
Or i could be wrong that its a bug, I’m only assuming that the read methods have the code thats magically fixing things, since that appears to be the only type of initiation code that would get called on load that I can’t call directly myself. Hopefully someone with more knowledge about the animation system can provide some more insight.