- Home /
[C#] How would I create skeleton bone transforms from a TRS matrix?
I've been writing a runtime importer for the Inter-Quake Model (IQM) format, and while I can load vertices, triangles, UV-coordinates, etc correctly, I can't seem to figure out how to correctly create the bone transforms from the information supplied in the IQM model.
The information I have is a translation (Vector3), scale (Vector3) and rotation (Quaternion).
http://sauerbraten.org/iqm/iqm.txt
According to the IQM spec (linked above):
translate is translation <Tx, Ty, Tz>, and rotate is quaternion rotation <Qx, Qy, Qz, Qw>
rotation is in relative/parent local space
scale is pre-scaling <Sx, Sy, Sz>
output = (input*scale)*rotation + translation
It's also important to note that the coordinates are right-handed z-up, whilst Unity is left-handed y-up.
I've been converting coordinates with the formula iqm(x, y, z) = unity(z, -x, y)
You can find a minimal sample project with necessary code and the sample IQM model "mrfixit" here: https://github.com/DaZombieKiller/unity-answers-iqm-help
See Assets/Scripts/IQM.cs, lines 303-321 (or search for the // UNITYHELP
comment)
When I attempt to create the bone transforms, they are quite clearly in the wrong positions. Here is the model loaded in Unity (the bones are represented by sphere primitives):
And here it is loaded in Noesis:
When I enable the bindposes (uncomment line 335), the model becomes a deformed mess:
Any ideas as to what I may be doing wrong? Matrices aren't exactly my forte so I'm assuming I'm royally screwing up there.
Your answer
![](https://koobas.hobune.stream/wayback/20220612125127im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do you set the positions of a ragdoll to that of bones in the last frame of played animation? 1 Answer
Multiple Cars not working 1 Answer
How to control bones with code? 0 Answers
Distribute terrain in zones 3 Answers
How to play animation (C#) 3 Answers