InverseBindMatrixTest.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Numerics;
  4. using System.Text;
  5. using NUnit.Framework;
  6. namespace SharpGLTF.Transforms
  7. {
  8. [Category("Core.Transforms")]
  9. public class InverseBindMatrixTest
  10. {
  11. [TestCase(0, 0, 0, 0, 0, 0)]
  12. [TestCase(1, 2, 4, 3, 2, 1)]
  13. [TestCase(-1, 1, 3, 2, 0, 1)]
  14. [TestCase(0, 0, 1, 0, 1, 0)]
  15. [TestCase(0, -1, 1, -2, 1, 0)]
  16. public void CalculateInverseBindMatrix(float mx, float my, float mz, float jx, float jy, float jz)
  17. {
  18. var model = Matrix4x4.CreateFromYawPitchRoll(mx, my, mz);
  19. var joint = Matrix4x4.CreateFromYawPitchRoll(jx, jy, jz);
  20. joint.Translation = new Vector3(jx, jy, jz);
  21. var invBindMatrix = SkinTransform.CalculateInverseBinding(model, joint);
  22. Matrix4x4.Invert(model, out Matrix4x4 xform);
  23. Matrix4x4.Invert(joint * xform, out Matrix4x4 result);
  24. NumericsAssert.AreEqual(result, invBindMatrix, 0.000001f);
  25. Matrix4x4.Invert(joint, out Matrix4x4 invJoint);
  26. result = model * invJoint;
  27. NumericsAssert.AreEqual(result, invBindMatrix, 0.000001f);
  28. }
  29. }
  30. }