_Extensions.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.Xna.Framework;
  5. namespace SharpGLTF.Runtime
  6. {
  7. static class _Extensions
  8. {
  9. public static Vector2 ToXna(this System.Numerics.Vector2 v)
  10. {
  11. return new Vector2(v.X, v.Y);
  12. }
  13. public static Vector3 ToXna(this System.Numerics.Vector3 v)
  14. {
  15. return new Vector3(v.X, v.Y, v.Z);
  16. }
  17. public static Vector4 ToXna(this System.Numerics.Vector4 v)
  18. {
  19. return new Vector4(v.X, v.Y, v.Z, v.W);
  20. }
  21. public static Matrix ToXna(this System.Numerics.Matrix4x4 m)
  22. {
  23. return new Matrix
  24. (
  25. m.M11, m.M12, m.M13, m.M14,
  26. m.M21, m.M22, m.M23, m.M24,
  27. m.M31, m.M32, m.M33, m.M34,
  28. m.M41, m.M42, m.M43, m.M44
  29. );
  30. }
  31. public static BoundingSphere CreateBoundingSphere(this Schema2.Mesh mesh)
  32. {
  33. var points = mesh
  34. .Primitives
  35. .Select(item => item.GetVertexAccessor("POSITION"))
  36. .Where(item => item != null)
  37. .SelectMany(item => item.AsVector3Array())
  38. .Select(item => item.ToXna());
  39. return BoundingSphere.CreateFromPoints(points);
  40. }
  41. }
  42. }