This showed up while profiling my game. I have a bunch animated models where I need to convert translation, rotation, and scale components into a skinning matrix.
The current implementation first normalizes the rotation quaternion. For my purposes I can skip this step because rotation quaternions are usually already normalized.
Then 3 mat4 matrices are generated and multiplied.
I swapped out Mat4.recompose with my own implementation: https://github.com/fabioarnold/3d-game/commit/396eb858d2d65a3564a64463075dece379e0b908
I added a function to convert a Quat into a Mat3. This could be useful on its own. Then I set the components of the result matrix directly. This of course saves the matrix multiplications. You could also go a step further and combine this with the quat to mat3 conversion function.
Is this worthy of a contribution to this project or do you prefer more understandable and correct (normalize rotation first) code? Please let me know and I could create a PR. :)
Thanks, I would be definitely interested! So if you make a PR, and comment the code explaining a bit why you made it like that, why its more optimised (like this post in fact); I will happily merged your PR!
This showed up while profiling my game. I have a bunch animated models where I need to convert translation, rotation, and scale components into a skinning matrix.
The current implementation first normalizes the rotation quaternion. For my purposes I can skip this step because rotation quaternions are usually already normalized. Then 3 mat4 matrices are generated and multiplied.
I swapped out
Mat4.recompose
with my own implementation: https://github.com/fabioarnold/3d-game/commit/396eb858d2d65a3564a64463075dece379e0b908 I added a function to convert aQuat
into aMat3
. This could be useful on its own. Then I set the components of the result matrix directly. This of course saves the matrix multiplications. You could also go a step further and combine this with the quat to mat3 conversion function.Is this worthy of a contribution to this project or do you prefer more understandable and correct (normalize rotation first) code? Please let me know and I could create a PR. :)