Rotation hell - copying rotation from source mesh to parented target mesh

Hi everyone,

Context

I have been working on this for two weeks or so now. Initially I just wanted to port a Ragdoll script to the new Havok engine. The biggest road block turned out to be the matching of rotations between physics colliders to bone TransformNodes of the skeleton (under a GLTF root node). This can be condensed down a bit further.
Almost embarrassingly to the very simple problem of copying a rotation of one mesh to another one.

Code

Anyway, the first playground1 passes. Line 66 has the main function. Goal is to copy red to green:

Test1 :white_check_mark:

Up to the delta part is where I would say I understand sort of why I did that. Then, according to the docs, if you rotate in order of ZXY then this is like rotating local angles by YXZ. Since the delta angles are in World space, I have to use the ZXY order. Anyway, a pass is a pass so next.

Test2 :x:

It is basically the first playground but has the source rotated again. Fails. At first I thought I double rotate something. But I already only rotate by the delta angles! :face_with_spiral_eyes:

Test3 :x:

There is just a single rotation but the parent node has a negative scaling. I know that negative scaling does some weird shit to rotations. Maybe there is some magic “offset” missing which would fix test2 and test3?

Well I am stuck now. I have two other completely different approaches (wildly applying offsets [got me the furthest actually, lol]; normalising with de-/re-parenting). But all fail at some point. I am out of ideas now :pleading_face:

Best wishes
Joe

Basically, if you want to apply the same transformation to a node D than the transformation of a node S, you need to set for D the transformation from S from which you “subtract” the transformation of the parent of D. To “subtract” a transformation means multiplying by the inverse matrix of this transformation, so you must calculate Sw * Pw-1, where Sw is the world matrix corresponding to S and Pw-1 is the world matrix inverse of the parent of D:

As we only want to have the same orientation for the green mesh than for the red mesh, I update only the rotationQuaternion of S (line 66).

4 Likes

Yay, huge progress. Thanks @Evgeni_Popov :smiley: