暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using UnityEngine;
  3. using Unity.Mathematics;
  4. namespace UnityEngine.Rendering
  5. {
  6. [Serializable]
  7. internal partial struct AABB
  8. {
  9. public float3 center;
  10. public float3 extents; // half the size, must be 0 or greater
  11. public float3 min { get { return center - extents; } }
  12. public float3 max { get { return center + extents; } }
  13. /// <summary>Returns a string representation of the AABB.</summary>
  14. public override string ToString()
  15. {
  16. return $"AABB(Center:{center}, Extents:{extents}";
  17. }
  18. static float3 RotateExtents(float3 extents, float3 m0, float3 m1, float3 m2)
  19. {
  20. return math.abs(m0 * extents.x) + math.abs(m1 * extents.y) + math.abs(m2 * extents.z);
  21. }
  22. public static AABB Transform(float4x4 transform, AABB localBounds)
  23. {
  24. AABB transformed;
  25. transformed.extents = RotateExtents(localBounds.extents, transform.c0.xyz, transform.c1.xyz, transform.c2.xyz);
  26. transformed.center = math.transform(transform, localBounds.center);
  27. return transformed;
  28. }
  29. }
  30. internal static class AABBExtensions
  31. {
  32. public static AABB ToAABB(this Bounds bounds)
  33. {
  34. return new AABB { center = bounds.center, extents = bounds.extents };
  35. }
  36. public static Bounds ToBounds(this AABB aabb)
  37. {
  38. return new Bounds { center = aabb.center, extents = aabb.extents };
  39. }
  40. }
  41. }