Swapping Right handed Quaternions to left handed from streaming data.

I am streaming skeleton data from Opti-tracks Motive software. Motive uses a Right handed system. Specifically, according to their documentation:

As an example, the OptiTrack Motive
software uses the following “Motive”
coordinate system convention: X
(Pitch), Y (Yaw), Z (Roll),
Right-Handed (RHS), Relative Axes (aka
‘local’)
https://www.optitrack.com/static/documents/NatNet%202.9.0%20API%20User%20Guide.pdf (page 13)

In the sample assets provided by motive to stream data into unity, there is a left handed conversion occurring apparently:


//== coordinate system conversion (right to left handed) ==–
z = -z;
qz = -qz;
qw = -qw;


I have tried turning this off and trying different configurations without finding a solution, or to be honest, understanding how this is effecting my end result.

Clearly the issue here is my lack of understanding of Quaternion Math. If anyone has any idea how to fix this, or can point me toward a good learning resource for Quaternions, I would really appreciate it.

edit
I Have tried to get the code formatted properly, but it just wont work for me. any tips?

I had a similar problem with the Autodesk FBX SDK. My conversion is to invert the x-axis of vertices, normals and object-positions, invert the winding-order of the triangles and invert the y- and z-component of the rotation-quaternion. Inverting y and z mirrors the quaternion on the yz-plane, which makes sense, since you have to invert one axis to convert from right-handed to left-handed (x-axis in my case).

You should also watch out for different rotation orders (Unity uses ZXY, often other programs use XYZ) if you do not receive quaternions directly from your software. Furthermore (but I think it is unlikely in this case) the inheritance order (order in which scale and rotation of parent and child are applied) could be a problem.