| | | 1 | | //======================================================================= |
| | | 2 | | // GravitasDebugDrawCommand.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2026–present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using FixedMathSharp; |
| | | 9 | | using Gravitas.Colliders; |
| | | 10 | | using System; |
| | | 11 | | |
| | | 12 | | namespace Gravitas.Diagnostics; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Engine-agnostic debug draw command that host adapters can translate into renderer calls. |
| | | 16 | | /// </summary> |
| | | 17 | | public readonly struct GravitasDebugDrawCommand |
| | | 18 | | { |
| | | 19 | | internal GravitasDebugDrawCommand( |
| | | 20 | | int frame, |
| | | 21 | | int sequence, |
| | | 22 | | GravitasDebugDrawKind kind, |
| | | 23 | | int colliderId, |
| | | 24 | | GravitasColliderDimension colliderDimension, |
| | | 25 | | ColliderType colliderType, |
| | | 26 | | ColliderType2D collider2DType, |
| | | 27 | | Vector3d start, |
| | | 28 | | Vector3d end, |
| | | 29 | | Vector3d center, |
| | | 30 | | Vector3d halfExtents, |
| | | 31 | | Vector3d pointA, |
| | | 32 | | Vector3d pointB, |
| | | 33 | | Vector3d pointC, |
| | | 34 | | FixedQuaternion rotation, |
| | | 35 | | Fixed64 radius, |
| | | 36 | | Fixed64 axisLength, |
| | | 37 | | Fixed64 height, |
| | | 38 | | GravitasDiagnosticColor color) |
| | | 39 | | { |
| | 404 | 40 | | Frame = frame; |
| | 404 | 41 | | Sequence = sequence; |
| | 404 | 42 | | Kind = kind; |
| | 404 | 43 | | ColliderId = colliderId; |
| | 404 | 44 | | ColliderDimension = colliderDimension; |
| | 404 | 45 | | ColliderType = colliderType; |
| | 404 | 46 | | Collider2DType = collider2DType; |
| | 404 | 47 | | Start = start; |
| | 404 | 48 | | End = end; |
| | 404 | 49 | | Center = center; |
| | 404 | 50 | | HalfExtents = halfExtents; |
| | 404 | 51 | | PointA = pointA; |
| | 404 | 52 | | PointB = pointB; |
| | 404 | 53 | | PointC = pointC; |
| | 404 | 54 | | Rotation = rotation; |
| | 404 | 55 | | Radius = radius; |
| | 404 | 56 | | AxisLength = axisLength; |
| | 404 | 57 | | Height = height; |
| | 404 | 58 | | Color = color; |
| | 404 | 59 | | } |
| | | 60 | | |
| | | 61 | | /// <summary>Gets the simulation frame in which the command was captured.</summary> |
| | | 62 | | public int Frame { get; } |
| | | 63 | | |
| | | 64 | | /// <summary>Gets the command's sequence within its capture buffer.</summary> |
| | | 65 | | public int Sequence { get; } |
| | | 66 | | |
| | | 67 | | /// <summary>Gets the command kind that determines how its payload is interpreted.</summary> |
| | | 68 | | public GravitasDebugDrawKind Kind { get; } |
| | | 69 | | |
| | | 70 | | /// <summary>Gets the context-local collider identifier, or <c>-1</c> when unassociated.</summary> |
| | | 71 | | public int ColliderId { get; } |
| | | 72 | | |
| | | 73 | | /// <summary>Gets the dimensional runtime surface of the associated collider.</summary> |
| | | 74 | | public GravitasColliderDimension ColliderDimension { get; } |
| | | 75 | | |
| | | 76 | | /// <summary>Gets the associated 3D collider type.</summary> |
| | | 77 | | public ColliderType ColliderType { get; } |
| | | 78 | | |
| | | 79 | | /// <summary>Gets the associated 2D collider type.</summary> |
| | | 80 | | public ColliderType2D Collider2DType { get; } |
| | | 81 | | |
| | | 82 | | /// <summary>Gets the start point for line and ray commands.</summary> |
| | | 83 | | public Vector3d Start { get; } |
| | | 84 | | |
| | | 85 | | /// <summary>Gets the end point for line and ray commands.</summary> |
| | | 86 | | public Vector3d End { get; } |
| | | 87 | | |
| | | 88 | | /// <summary>Gets the center of a point or wireframe volume.</summary> |
| | | 89 | | public Vector3d Center { get; } |
| | | 90 | | |
| | | 91 | | /// <summary> |
| | | 92 | | /// Gets the center-relative half-extents for |
| | | 93 | | /// <see cref="GravitasDebugDrawKind.WireBox"/> commands. |
| | | 94 | | /// </summary> |
| | | 95 | | public Vector3d HalfExtents { get; } |
| | | 96 | | |
| | | 97 | | /// <summary>Gets the first vertex of a wireframe triangle.</summary> |
| | | 98 | | public Vector3d PointA { get; } |
| | | 99 | | |
| | | 100 | | /// <summary>Gets the second vertex of a wireframe triangle.</summary> |
| | | 101 | | public Vector3d PointB { get; } |
| | | 102 | | |
| | | 103 | | /// <summary>Gets the third vertex of a wireframe triangle.</summary> |
| | | 104 | | public Vector3d PointC { get; } |
| | | 105 | | |
| | | 106 | | /// <summary>Gets the orientation of a wireframe volume.</summary> |
| | | 107 | | public FixedQuaternion Rotation { get; } |
| | | 108 | | |
| | | 109 | | /// <summary>Gets the point or wireframe volume radius.</summary> |
| | | 110 | | public Fixed64 Radius { get; } |
| | | 111 | | |
| | | 112 | | /// <summary> |
| | | 113 | | /// Gets the full distance between hemisphere centers for |
| | | 114 | | /// <see cref="GravitasDebugDrawKind.WireCapsule"/> commands. |
| | | 115 | | /// </summary> |
| | | 116 | | public Fixed64 AxisLength { get; } |
| | | 117 | | |
| | | 118 | | /// <summary>Gets the full height of a cylinder or cone.</summary> |
| | | 119 | | public Fixed64 Height { get; } |
| | | 120 | | |
| | | 121 | | /// <summary>Gets the command color.</summary> |
| | | 122 | | public GravitasDiagnosticColor Color { get; } |
| | | 123 | | |
| | | 124 | | /// <summary> |
| | | 125 | | /// Dispatches this draw command to a typed debug draw visitor based on <see cref="Kind"/>. |
| | | 126 | | /// </summary> |
| | | 127 | | public void DispatchTo(GravitasDebugDrawCommandVisitor visitor) |
| | | 128 | | { |
| | 23 | 129 | | if (visitor == null) |
| | 1 | 130 | | throw new ArgumentNullException(nameof(visitor)); |
| | | 131 | | |
| | 22 | 132 | | switch (Kind) |
| | | 133 | | { |
| | | 134 | | case GravitasDebugDrawKind.Line: |
| | 3 | 135 | | visitor.VisitLine(new GravitasLineDebugDrawView(this)); |
| | 3 | 136 | | break; |
| | | 137 | | case GravitasDebugDrawKind.Ray: |
| | 2 | 138 | | visitor.VisitRay(new GravitasRayDebugDrawView(this)); |
| | 2 | 139 | | break; |
| | | 140 | | case GravitasDebugDrawKind.Point: |
| | 3 | 141 | | visitor.VisitPoint(new GravitasPointDebugDrawView(this)); |
| | 3 | 142 | | break; |
| | | 143 | | case GravitasDebugDrawKind.WireSphere: |
| | 2 | 144 | | visitor.VisitWireSphere(new GravitasWireSphereDebugDrawView(this)); |
| | 2 | 145 | | break; |
| | | 146 | | case GravitasDebugDrawKind.WireBox: |
| | 2 | 147 | | visitor.VisitWireBox(new GravitasWireBoxDebugDrawView(this)); |
| | 2 | 148 | | break; |
| | | 149 | | case GravitasDebugDrawKind.WireCapsule: |
| | 2 | 150 | | visitor.VisitWireCapsule(new GravitasWireCapsuleDebugDrawView(this)); |
| | 2 | 151 | | break; |
| | | 152 | | case GravitasDebugDrawKind.WireCylinder: |
| | 2 | 153 | | visitor.VisitWireCylinder(new GravitasWireCylinderDebugDrawView(this)); |
| | 2 | 154 | | break; |
| | | 155 | | case GravitasDebugDrawKind.WireTriangle: |
| | 2 | 156 | | visitor.VisitWireTriangle(new GravitasWireTriangleDebugDrawView(this)); |
| | 2 | 157 | | break; |
| | | 158 | | case GravitasDebugDrawKind.WireCone: |
| | 2 | 159 | | visitor.VisitWireCone(new GravitasWireConeDebugDrawView(this)); |
| | 2 | 160 | | break; |
| | | 161 | | default: |
| | 2 | 162 | | visitor.VisitUnknown(this); |
| | | 163 | | break; |
| | | 164 | | } |
| | 2 | 165 | | } |
| | | 166 | | } |