UPDATE: On further investigation, it’s not the cloning which is causing the mesh to render properly, but switching to hardware skinning. Anyone know what might be missing that’s causing the software skinning to not work properly? Ideally, this should work whether or not hardware skinning is being used.
I have written some code to retarget a Mesh from one Skeleton to another Skeleton of which the structure of the first Skeleton is a substructure. I do this by altering the BoneIndex (or HWBoneIndex) buffer on the mesh so that it points to the correct bone in the new Skeleton. Not surprisingly, doing that alone is not enough for things to work properly. The updated mesh’s vertices go all over the place when an animation is run. However, I have noticed that when I clone (using Spatial.clone(false)) a Geometry on which I’ve retargeted the Mesh, the Mesh on the cloned copy animates properly. Seemingly, something in the cloning processes triggers an update that is causing the BoneIndex buffer information to be used properly. I’ve dug into the cloning code, but haven’t stumbled on anything that is obviously doing what I want to do. I thought Spatial.forceRefresh(true, true, true) might do what I needed, but that has no effect. Anyone know what I need to do to get the updated BoneIndex information to be used properly?
Thanks for replying and sharing your code. I am aware about the BoneWeight buffer, but it should remain unchanged for my purposes. The trick is that I need to figure out either how to get jMonkeyEngine to recalculate anything that’s dependent on the BoneIndex buffer or how to do it myself. I’ll have to look at your code again later when I’m not on my phone, but I didn’t see any way to do that in your code, since you seem to only be making new objects out of old ones rather than altering olds ones directly.
The reason I know I’m altering the BoneIndex properly is because if I alter it any other way then the animations display improperly with hardware skinning, but they display properly with hardware skinning when I alter them the way that I am.
I’m going to try prepareForAnim(true) as @nehon suggested and if that doesn’t work I’ll probably post my code.