-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[rmodels] Added implementation of UpdateModelAnimationBonesWithBlending()
function
#4578
base: master
Are you sure you want to change the base?
[rmodels] Added implementation of UpdateModelAnimationBonesWithBlending()
function
#4578
Conversation
…ing()` function Signed-off-by: Kirandeep-Singh-Khehra <[email protected]>
nice! |
…or blend factor Signed-off-by: Kirandeep-Singh-Khehra <[email protected]>
Added example to show blending using anim_blending_example-2024-12-07_22.58.26.mp4 |
Signed-off-by: Kirandeep-Singh-Khehra <[email protected]>
Signed-off-by: Kirandeep-Singh-Khehra <[email protected]>
@Kirandeep-Singh-Khehra This is a great addition! I find the function name In the same line, That way, |
While I agree that we need interpolation/blending support, I feel that this simple API does not go far enough.
I don't mind having a basic function that just updates the model's internal bone state, but I would like the lower level functions to be accessible for people who need more than a simple single model use case. |
@raysan5 @JeffM2501 When i started using raylib i was hoping for something like simple utility to work with skeleton and forward kinematics. And both these things were way complex. And i was unable to make a good looking 3d game without adding something to animations. But as Ray asked to unify animation functions. I discarded/upgraded this code and tried to create a one stop solution and i implemented most of it. Just minor adjustments are needed. I completely agree that the idea discussed below is lot complex(but code will be readable and simple to debug, i assure). But it will add things like blending, interpolation, split body animation. single call function for more complex animations(like add all animations in single call and user only need calculate weights(discussed below)) The idea is to create function
Example i used: UpdateModelAnimationBonesPro(model, fullBodyMask, 0, 2,
/* Anim | Frame | Weight */
anims[indexX], animFrameCounter, (double)abs(motion.x),
anims[indexY], animFrameCounter, (double)abs(motion.y)
/* More lines here */
); BoneMask is implemented but not yet used in function. I tested passing 1,2 and 3 animations and it passed with flying colors. (As far as i can see on screen). We can also pass Then we can replace/redefine #define UpdateModelAnimationBones(model, anim, frame) UpdateModelAnimationBonesPro(model, FullBodyMask(), 0, 1, anim, frame, 1)
#define UpdateModelAnimationBonesWithMask(model, animA, frameA, animB, frameB, blendFactor) UpdateModelAnimationBonesPro(model, FullBodyMask(), 0, 2, animA, frameA, (1-blendFactor), animB, frameB, blendFactor)
// This one will be interesting
void UpdateModelAnimationBonesWithTime(model, anim, time) {
int frameA = time / GLTF_ANIMDELAY;
int frameB = time / GLTF_ANIMDELAY;
float blendFactor = (time % GLTF_ANIMDELAY) / GLTF_ANIMDELAY;
UpdateModelAnimationBonesPro(model, FullBodyMask(), 0, 2,
anim, frameA, (1 - blendFactor),
anim, frameB, blendFactor)
}
// ... or many more such animation stuff can be done with this one function. If its not possible to have this then ... (Just let me know) .Or Do we have plans for official plugin system (separate repo for bunch of simple header files) to add such advanced functionality to raylib. I am also planning to work on state machine after this for animation but State machine will be lot less useful when added to raylib. So, it must be separate repo. But that's the story of another day. Looking forward for some feedback. |
That seems very complicated. This makes me wonder if a full animation system should be made external to raylib as a drop in. I would take blending out of this feature to start with. While I get that it's similar, I think it complicates something that should be a simple API (prevent feature creep). My thoughts are that we should add the following new API functions to start with.
These would give us basic interpolation using a simple API that works for both GPU and CPU users without code duplication. Someone doing GPU animation would just call I think it's important for people doing CPU animation to know that they are modifying vertex data. I don't think there is any benefit to locking in a 'pro' version of any function right now. I fear we may 'burn' the pro name on something that's not useful just to 'get something in'. We do not need to rush this. Blending is a big subject with a lot of requirements. I think to start for blending we should open a discussion about what those requirement and use cases are before we design any APIs. I think that for blending we are really going to need a way to define a model skeleton outside of the model structure and update it separately, then apply it back to the meshes, and that's a bigger design, something I feel that is outside the scope of a simple single PR. My fear is that a purely internal solution will be lacking in some regards, so an external drop in solution may be best (with API changes to support the access it needs). But we for sure need to design the API properly first, not just throw code around. |
…te verts from bones Signed-off-by: Kirandeep-Singh-Khehra <[email protected]>
Signed-off-by: Kirandeep-Singh-Khehra <[email protected]>
Updated the PR with functions suggested by JeffM2501. Example is also updated. To have both CPU and GPU skinning along with comments that user viewer can follow to make it use GPU skinning. Modified Tested GPU and CPU version and other examples using older void UpdateModelAnimationBonesLerp(Model model, ModelAnimation anim1, int frame1, ModelAnimation anim2, int frame2, float param); // computes a new set of bone matricies between two frames.
void UpdateModelVertsToCurrentBones(Model model); // takes the current set of bone matrices and applies to them to mesh verts (CPU Animation) |
This PR adds a function to blend between two different frames of different or same
ModelAnimation
. It can be used to blend between two animation or smoothly transition between two animation by interpolating between exiting and entering poses. Updates for bones only and need GPU skinningParams
Model model
: Target model to update bones.ModelAnimation animA
: First animation.int frameA
: Frame number of first animation.ModelAnimation animB
: Second animation.int frameB
: Frame number of second animationfloat blendFactor
: Ratio of blending betweenanimA
'sframeA
andanimB
'sframeB
. Value must be from0.0f
to1.0f
. Value0.0f
means useframeA
ofanimA
and1.0f
means useframeB
ofanimB
. And other values correspond to other values in between.Example usage(not-complete code)
TODOs
Dropped for nowAdding it see this commentI tested on a model downloaded from Mixamo and animated using Mixamo. Its in glb format. Not sure if it is acceptable as asset. If yes then i'll push that example. Otherwise i need to create a custom model.
Demo uses above example with 5 animations.
Idle
,Run
,RunBack
,RunLeft
andRunRight
. Idle is played by default and blending is done for diagonal motion.raylib_blend_demo_0.mp4