[rmodels] Optimized UpdateModelAnimationBones() function#4602
Conversation
- Updating bones only once instead for each mesh. - Updating only one `model.meshes[].boneMatrices` and then using deep copy for other meshes instead of calculating for each bone in each mesh. **Other points:** - Makes it a clean base/template/reference for bone updation functions. Because if using this as template then some calculations done in one mesh can affect bones in other mesh in next iteration(doubles the effect in for next mesh). Signed-off-by: Kirandeep-Singh-Khehra <kirandeepsinghkhehra@gmail.com>
|
@Kirandeep-Singh-Khehra Thanks for the review. Did you profile this change to verify the optimization gain? Also, could it happen that only one model mesh has bones info and not others? Won't this solution implement one specific mesh transformations to all other meshes? 🤔 |
Hi Ray, I have not profiled for optimization gain but i can explain in terms of time complexity. Initially matrix transformations were calculated in O(mn) (
Asserts are at same place as they were before. And there is a
Yes it will. As it was the same thing happening before. So, instead of calculating same boneMatrix array for each mesh i am calculating it only once. |
|
@Kirandeep-Singh-Khehra thanks for your answers and the details, now I better see the improvement. |
mesh.model.meshes[].boneMatricesand then using deep copy for other meshes instead of calculating for each bone in each mesh.Other points:
Makes it a clean base/template/reference for other/new bone updation functions. Because if using this as template or modifying it, then some calculations done in one mesh can affect bones in other mesh in next iteration(doubles the effect in for next mesh) If some new variable used in loops is declared outside loop.
This new template is helpful for me to create new functions to update bones of model for animation system I'm working on.
Tested and is working fine for me.