Skip to content

Conversation

@ArmanOmmid
Copy link
Contributor

@ArmanOmmid ArmanOmmid commented Sep 25, 2025

I'm only looking at GLTF at the moment, but possible that the IQM logic would also appreciate a similar change given that it uses the same BuildPoseFromParentJoints.

Meanwhile, consider the following helper functions below (and exposing them with RLAPI)
I think these would be useful tools for animators to be able to use. I am currently using these for machine learning for animation on my personal fork.

Just let me know where you'd like me to put them (and their header declarations) if you agree :)

// Compose Model Space Transform
Transform ComposeTransform(Transform transform, Transform parentTransform)
{
    transform.rotation = QuaternionMultiply(parentTransform.rotation, transform.rotation);
    transform.scale = Vector3Multiply(transform.scale, parentTransform.scale);
    transform.translation = Vector3Multiply(transform.translation, parentTransform.scale);
    transform.translation = Vector3RotateByQuaternion(transform.translation, parentTransform.rotation);
    transform.translation = Vector3Add(transform.translation, parentTransform.translation);
    return transform;
}

// Extract Local Space Transform
Transform ComposeTransformInverse(Transform transform, Transform parentTransform)
{
    transform.rotation = QuaternionMultiply(QuaternionInvert(parentTransform.rotation), transform.rotation);
    transform.scale = Vector3Divide(transform.scale, parentTransform.scale);
    transform.translation = Vector3Subtract(transform.translation, parentTransform.translation);
    transform.translation = Vector3RotateByQuaternion(transform.translation, QuaternionInvert(parentTransform.rotation));
    transform.translation = Vector3Divide(transform.translation, parentTransform.scale);
    return transform;
}

@ArmanOmmid
Copy link
Contributor Author

ArmanOmmid commented Sep 25, 2025

Also yes, these were tested on Raylib GLTFs and others including some examples from Khronos Group.
The fix is apparent when using models whose world transform is not identity, for example:
KhronosCesiumMan
KhronosRiggedFigure

@ArmanOmmid ArmanOmmid changed the title GLTF Anim Correctly Inherits World Transform [rmodels] GLTF Anim Correctly Inherits World Transform Sep 25, 2025
@ArmanOmmid ArmanOmmid changed the title [rmodels] GLTF Anim Correctly Inherits World Transform [rmodel] GLTF Anim Correctly Inherits World Transform Sep 25, 2025
@ArmanOmmid ArmanOmmid changed the title [rmodel] GLTF Anim Correctly Inherits World Transform [rmodels] GLTF Anim Correctly Inherits World Transform Sep 25, 2025
@raysan5
Copy link
Owner

raysan5 commented Sep 26, 2025

@ArmanOmmid At the moment I prefer to keep the API simple and expose those functions... but you can add them to rmodels.c as a reference and maybe for the future.

@raysan5 raysan5 merged commit 15d234b into raysan5:master Sep 26, 2025
16 checks passed
@ArmanOmmid
Copy link
Contributor Author

ArmanOmmid commented Sep 26, 2025

@ArmanOmmid At the moment I prefer to keep the API simple and expose those functions... but you can add them to rmodels.c as a reference and maybe for the future.

@raysan5
I can add them to rmodels.c for now, can still be useful for internal anim function (i.e the ones modified in this PR).

Do you have a preference for where you'd like them to be in the file? Or just use my judgement on what location makes sense.

@ArmanOmmid ArmanOmmid deleted the fix-gltf-anim-world-transform branch September 27, 2025 22:10
psxdev pushed a commit to raylib4Consoles/raylib that referenced this pull request Oct 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants