Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silk.NET.Assimp Quaternions are incorrect #796

Closed
Kermalis opened this issue Feb 2, 2022 · 2 comments · Fixed by #836
Closed

Silk.NET.Assimp Quaternions are incorrect #796

Kermalis opened this issue Feb 2, 2022 · 2 comments · Fixed by #836
Assignees
Labels
area-Assimp bug Something isn't working

Comments

@Kermalis
Copy link

Kermalis commented Feb 2, 2022

Summary

Upon parsing Quaternions from NodeAnim*, I was stumbling upon incorrect Quaternions. The aiQuaterniont struct puts W first, but System.Numerics.Quaternion is X first. So it appears Silk.NET is casting those aiQuaternionT* to System.Numerics.Quaternion or something, which results in W being at X which is wrong.

Here's my workaround for parsing them:

NodeAnim* chan = a->MChannels[j];

var positions = new (float, Vector3)[chan->MNumPositionKeys];
for (int k = 0; k < positions.Length; k++)
{
    VectorKey pos = chan->MPositionKeys[k];
    positions[k] = ((float)pos.MTime, pos.MValue);
}
var rotations = new (float, Quaternion)[chan->MNumRotationKeys];
for (int k = 0; k < rotations.Length; k++)
{
    QuatKey rot = chan->MRotationKeys[k];
    rotations[k] = ((float)rot.MTime, new Quaternion(rot.MValue.Y, rot.MValue.Z, rot.MValue.W, rot.MValue.X)); // HERE: Incorrectly casted by library, so order is shifted by one field
}
var scales = new (float, Vector3)[chan->MNumScalingKeys];
for (int k = 0; k < scales.Length; k++)
{
    VectorKey scl = chan->MScalingKeys[k];
    scales[k] = ((float)scl.MTime, scl.MValue);
}

Comments

  • Platform: Desktop
  • Framework Version: .NET 6.0
  • API: OpenGL 3.3 Core

I'm not sure if this is unique to NodeAnim or if it applies all over the library, so it needs some looking into

@Kermalis Kermalis added the bug Something isn't working label Feb 2, 2022
@HurricanKai
Copy link
Member

See https://github.com/dotnet/Silk.NET/blob/main/generator.json#L695
We don't at this time support rewriting types, so we probably just have to remove the mapping and fix this for real in 3.0

@Kermalis
Copy link
Author

Kermalis commented Feb 2, 2022

Well this is also similarly the case with Matrix4x4. The assimp ones are column major, but the System.Numerics ones are row major. Having it be consistent with the rest of .net makes it way easier. At the moment, you have to transpose the matrices you get from Silk.NET.Assimp. If these inconsistencies were addressed it'd be a lot easier to follow tutorials (and make a proper example project with)
Edit: Could also apply to Matrix3x3 although I didn't check any of those

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Assimp bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants