there is a bug in the Bone class. It is not possible to set individual bind tranforms for each model of the same modelfile.
e.g. I have 3 elephants and want to scale their legs differently.
If I try to scale one elephants bone like this:
bone = skeletonControl.getSkeleton().getBone("leg.right");
bindScale = bone.getBindScale();
bindScale.set(scale, scale, scale);
all 3 elephants will be scaled instead of only the one.
After a bit of investigation I realized that the Bone constrcutor doesn’t create clones of the given Bone object parameter. So I fixed it and it worked. Here is the fix:
…
Bone(Bone source) {
this.name = source.name;
userControl = source.userControl;
bindPos = source.bindPos.clone();
bindRot = source.bindRot.clone();
bindScale = source.bindScale.clone();
modelBindInversePos = source.modelBindInversePos.clone();
modelBindInverseRot = source.modelBindInverseRot.clone();
modelBindInverseScale = source.modelBindInverseScale.clone();
// parent and children will be assigned manually..
}
Not necessarily related to your issue but in general getting a value and settings it values directly in JME is a big big no-no.
You need to find the right setter and use that instead… and then I suspect your issue might get fixed, also. (Edit: if you supply a new value to the setter instead of reusing.)
Yes, so if you set the values directly, around the API… then you will be setting the values of the shared objects… instead of swapping them out for new shared objects.
I’ve changed bone scales before without them affecting every other version of the skeleton.
If I set userControl true, the animations cannot control the bones anymore. I want to control the bones on my own and by the animation at the same time
setUserTransforms() requires that userControl is true. This is not the same as modifying the bind transforms. For example if I modify bindscale to make an arm bigger and the arm has an animation. The scale should only be applied to one model and may not shared between them.
Bind trasforms are the transforms to use when you reset the model.
Meaning it’s the transform in which the skeleton is reset on each frame before applying animation transforms.
They are shared to save memory and because they are supposed to be the same for all the instances of the same model.
If you need models with distinct mesh buffers you can use the deepClone method.
Ok I didn’t read thoroughly, you’re not modifying the mesh, but the bones of the skeleton.
I looked into the code and there is a bug indeed. Bones are cloned, but the transforms inside a bone are not cloned
You end up having different skeletons and diferent bones, but that share the same Vecotr3f…
However… there is this remark in the javadoc that let me think it’s on purpose. @Momoko_Fan, any insight on this?