Hello,
I’m trying to rotate bones on an animated character i’ve searched for it on old threads but all i could find was a “setUserTransforms()” method on “Bone” class which is deprecated.i’m using “AnimComposer” and i have this code :
It works as long as the Character has no animation / action running.but if run animation it just jumps from rotation above to animation’s rotation and back and it just doesn’t work.(i tried to use Slerp and nothing’s changed and problem is still there.)
Is there any way to rotate bone and run the animation on it at the same time ?
Yes, it can be done. I suggest using an ArmatureMask to disable animation on the joint in question. (Bones in the new animation system are called joints.)
And it works but the leg gets kinda stretches out.and if you don’t run the animation, model gets completely destroyed when you call “saveBindPose” or “applyBindPose” methods.not sure why.
I don’t think this is possible with JME’s animation system currently.
But I think it would be a useful feature for jme’s animation system to support this.
I’ve been wanting to do something like this to use inverse kinematics to allow an animated model’s feet/legs to be repositioned so they don’t clip through the ground while playing a walk animation and going up and down stairs and slopes.
Are you trying to do something similar to this? or something else?
I have recently encountered the same bug while trying to make a character editor for scaling a character model’s height and weight. The more times you call saveBindPose(), the worse the issue seems to get. Issue calling Armature.saveBindPose()
I plan to work on fixing this bug very soon, but I don’t have much experience working with the backend of jme’s animation system, so I’ll probably be posting back to the forum for help from the community on this issue.
It seems to be possible to do in JMonkeyengine.currently i have this :
I did this with code above.and leg’s bone is rotated like 90 degree and still animation is running on it.but as i said it is deformed.maybe it’s because of the rotation or something.but same rotation works completely fine without animation running and calling “applyBindPose”.
The way I would approach this would be to not modify the bind pose, and instead I would just modify the position of the foot every frame after the animation system has positioned the foot.
So every frame I’d do a ray cast from the foot’s position towards the ground (after the foot is positioned by the walk animation for that frame) and then do inverse kinematics math to calculate the rotation of the foot and knee that is required in order for the foot to be in the position that the ray collided with the ground.
But there’s definitely more than 1 way to achieve the same thing in other ways, and I haven’t done any testing with this yet, just planning so far mostly.
I tried to modify the rotation of the leg every frame but it just jumps from the rotation i gave to it to rotation animation have and back.it just doesn’t work for me without “applyBindPose” or disabling the animation on the bone. ( and i’m not trying to do foot ik tho i was just trying to test if it’s possible to rotate bones in Jmonkeyengine while they have an animation running.i was using legs just for testing)
Not sure if it’s a bug or not but “ArmatureMask” gives me exception : ClassCastException: class com.jme3.scene.Node cannot be cast to class com.jme3.anim.Joint
In Jmonkeyengine “3.7.0-stable” while same code works in JMonkeyengine “3.6.1-stable”
Edit :
You can use “AnimationMask” instead of “ArmatureMask” in Jmonkeyengine “3.7.0-stable” like this :
AnimationMask mask = new AnimationMask() {
@Override
public boolean contains(Object o) {
return !(o instanceof Node) && !((Joint)o).getName().equals("mixamorig:LeftUpLeg");
}
};
Without that “instanceof” part i still get exception above in Jmonkeyengine “3.7.0-stable”.
I dont know where you guys are updating the animation but the anim control gets updated in the controlRender and not update. Just a fyi in case there is some race condition and you want to write stuff after jme’s anim control
I tried to use “simpleUpdate” method for rotating the bone and it didn’t work for me.in that gif above i just rotated the bone once (without calling it in any update methods) and then called “applyBindPose” before and “saveBindPose” after applying the rotation.
Not sure if there is any other update methods that can solve this problem (other than simpleUpdate).i’m new Jmonkeyengine myself was working with other game engines for a while just returned to JMonkeyengine.
I am not familiar enough with the anim system. My best guess is that you have to add a control to the same spatial with the anim control, overwrite the controlRender method, get the bone transforms from the anim control, update them and probably you have to update the material as well.
I did something similar but completely differently. I tell you what I did and you need to figure out if it applies to your situation or not.
I needed to make an idle character that looks toward the mouse. What this means is that the character needed to play an ‘idle’ animation meanwhile it rotated to the left or to the right from the waist following the mouse meanwhile playing said ‘idle’ animation. I initially wanted to mess around with bone transform but came up with a different solution.
My solution was to add a rotation animation for a specific bone and blend the two animations together. I created a ‘rotation’ animation: 0th keyframe the waist bone was completely rotated to the left and on the 100th keyframe the bone was completely rotated to the right.
With AnimComposer you have the ability to blend animations together and control this blend with weights.
So I ended up playing the ‘idle’ animation on the character continuously and blended it with the ‘rotation’ animation using weights and the weights were based on a value between 0f and 1f calculated from the mouse cursor’s position relative to the character’s center. So if the mouse was on the left, the weight was near 1f and the rotation animation applied fully. If the mouse was on the middle, the weight was 0.5f and the rotation animation was applied with half weight, making the character centered. If the mouse was on the right, the weight was 0f and the character was looking to the right. And also in-between values were nicely blended so it gave the illusion that the character was looking at the mouse.
You can even programmatically create basic transform animation clips and don’t have to go to the modelling software to create said animation. There is a helper class for that in the new animation system’s package. I don’t remember its name. Then use mask for specific bones and weight blend them with the animation. Important: it will merge the two animation together. If you have rotation keyframes on your basic animation and then apply a rotation animation to the same bone it will merge/add-up so it may end up looking ugly. You maybe need to modify your original animation or add helper bones. Up to you and your situation.