@@ -91,6 +91,72 @@ public static DebugDrawCommandList CurrentList
9191 }
9292 }
9393
94+ public static void PushStyleColor ( DebugDrawCol col , Vector4 color )
95+ {
96+ if ( currentContext == null )
97+ {
98+ throw new InvalidOperationException ( "DebugDraw context is not set. Call DebugDraw.SetContext() before drawing." ) ;
99+ }
100+
101+ currentContext . Style . PushStyleColor ( col , color ) ;
102+ }
103+
104+ public static void PopStyleColor ( )
105+ {
106+ if ( currentContext == null )
107+ {
108+ throw new InvalidOperationException ( "DebugDraw context is not set. Call DebugDraw.SetContext() before drawing." ) ;
109+ }
110+
111+ currentContext . Style . PopStyleColor ( ) ;
112+ }
113+
114+ public static void PopStyleColor ( int count )
115+ {
116+ if ( currentContext == null )
117+ {
118+ throw new InvalidOperationException ( "DebugDraw context is not set. Call DebugDraw.SetContext() before drawing." ) ;
119+ }
120+
121+ while ( count -- != 0 )
122+ {
123+ currentContext . Style . PopStyleColor ( ) ;
124+ }
125+ }
126+
127+ public static void PushStyleVar ( DebugDrawStyleVar var , float value )
128+ {
129+ if ( currentContext == null )
130+ {
131+ throw new InvalidOperationException ( "DebugDraw context is not set. Call DebugDraw.SetContext() before drawing." ) ;
132+ }
133+
134+ currentContext . Style . PushStyleVar ( var , value ) ;
135+ }
136+
137+ public static void PopStyleVar ( )
138+ {
139+ if ( currentContext == null )
140+ {
141+ throw new InvalidOperationException ( "DebugDraw context is not set. Call DebugDraw.SetContext() before drawing." ) ;
142+ }
143+
144+ currentContext . Style . PopStyleVar ( ) ;
145+ }
146+
147+ public static void PopStyleVar ( int count )
148+ {
149+ if ( currentContext == null )
150+ {
151+ throw new InvalidOperationException ( "DebugDraw context is not set. Call DebugDraw.SetContext() before drawing." ) ;
152+ }
153+
154+ while ( count -- != 0 )
155+ {
156+ currentContext . Style . PopStyleVar ( ) ;
157+ }
158+ }
159+
94160 /// <summary>
95161 /// Saturates a float value to the range [0, 1].
96162 /// </summary>
@@ -1437,7 +1503,6 @@ public static void DrawQuadBillboard(Vector3 origin, Vector3 camOrigin, Vector3
14371503 /// <param name="matrix">The transformation matrix defining the orientation and position of the grid.</param>
14381504 /// <param name="size">The size of the grid (half-extent in each dimension).</param>
14391505 /// <param name="col">The color of the grid lines.</param>
1440- ///
14411506 public static void DrawGrid ( Matrix4x4 matrix , int size , Vector4 col )
14421507 {
14431508 CurrentList . BeginDraw ( ) ;
@@ -1476,5 +1541,105 @@ public static void DrawGrid(Matrix4x4 matrix, int size, Vector4 col)
14761541
14771542 CurrentList . RecordCmd ( DebugDrawPrimitiveTopology . LineList ) ;
14781543 }
1544+
1545+ /// <summary>
1546+ /// Draws a 3D grid in world space.
1547+ /// </summary>
1548+ /// <param name="matrix"> The transformation matrix defining the orientation and position of the grid.</param>
1549+ /// <param name="flags"> The flags that determine which elements of the grid to draw.</param>
1550+ /// <exception cref="InvalidOperationException"> The DebugDraw context is not set. Call DebugDraw.SetContext() before drawing.</exception>
1551+ public static void DrawGrid ( Matrix4x4 matrix , GridFlags flags )
1552+ {
1553+ if ( currentContext == null )
1554+ {
1555+ throw new InvalidOperationException ( "DebugDraw context is not set. Call DebugDraw.SetContext() before drawing." ) ;
1556+ }
1557+
1558+ var style = currentContext . Style ;
1559+ var size = ( int ) style . GridSize ;
1560+ var spacing = style . GridSpacing ;
1561+
1562+ CurrentList . BeginDraw ( ) ;
1563+ bool axis = ( flags & GridFlags . DrawAxis ) != 0 ;
1564+
1565+ uint vertexCount = 2u * ( uint ) size * 2u + 4 ;
1566+
1567+ if ( axis )
1568+ {
1569+ vertexCount += 6 ;
1570+ }
1571+
1572+ uint color = style . GetColorU32 ( DebugDrawCol . Grid ) ;
1573+
1574+ CurrentList . ReserveGeometry ( vertexCount , vertexCount ) ;
1575+ var indices = CurrentList . Indices + CurrentList . IndexCount ;
1576+ var vertices = CurrentList . Vertices + CurrentList . VertexCount ;
1577+
1578+ int half = size / 2 ;
1579+
1580+ uint i = 0 ;
1581+ for ( int x = - half ; x <= half ; x ++ )
1582+ {
1583+ var pos0 = Vector3 . Transform ( new Vector3 ( x * spacing , 0 , - half ) , matrix ) ;
1584+ var pos1 = Vector3 . Transform ( new Vector3 ( x * spacing , 0 , half ) , matrix ) ;
1585+ vertices [ i ] = new ( pos0 , default , color ) ;
1586+ vertices [ i + 1 ] = new ( pos1 , default , color ) ;
1587+ indices [ i ] = i ;
1588+ indices [ i + 1 ] = i + 1 ;
1589+ i += 2 ;
1590+ }
1591+
1592+ for ( int z = - half ; z <= half ; z ++ )
1593+ {
1594+ var pos0 = Vector3 . Transform ( new Vector3 ( - half , 0 , z * spacing ) , matrix ) ;
1595+ var pos1 = Vector3 . Transform ( new Vector3 ( half , 0 , z * spacing ) , matrix ) ;
1596+ vertices [ i ] = new ( pos0 , default , color ) ;
1597+ vertices [ i + 1 ] = new ( pos1 , default , color ) ;
1598+ indices [ i ] = i ;
1599+ indices [ i + 1 ] = i + 1 ;
1600+ i += 2 ;
1601+ }
1602+ if ( axis )
1603+ {
1604+ var colX = style . GetColorU32 ( DebugDrawCol . GridAxisX ) ;
1605+ var colY = style . GetColorU32 ( DebugDrawCol . GridAxisY ) ;
1606+ var colZ = style . GetColorU32 ( DebugDrawCol . GridAxisZ ) ;
1607+ var axisSize = style . GridAxisSize ;
1608+
1609+ {
1610+ var pos0 = Vector3 . Transform ( new Vector3 ( - axisSize , 0 , 0 ) , matrix ) ;
1611+ var pos1 = Vector3 . Transform ( new Vector3 ( axisSize , 0 , 0 ) , matrix ) ;
1612+
1613+ vertices [ i ] = new ( pos0 , default , colX ) ;
1614+ vertices [ i + 1 ] = new ( pos1 , default , colX ) ;
1615+ indices [ i ] = i ;
1616+ indices [ i + 1 ] = i + 1 ;
1617+ i += 2 ;
1618+ }
1619+
1620+ {
1621+ var pos0 = Vector3 . Transform ( new Vector3 ( 0 , - axisSize , 0 ) , matrix ) ;
1622+ var pos1 = Vector3 . Transform ( new Vector3 ( 0 , axisSize , 0 ) , matrix ) ;
1623+
1624+ vertices [ i ] = new ( pos0 , default , colY ) ;
1625+ vertices [ i + 1 ] = new ( pos1 , default , colY ) ;
1626+ indices [ i ] = i ;
1627+ indices [ i + 1 ] = i + 1 ;
1628+ i += 2 ;
1629+ }
1630+
1631+ {
1632+ var pos0 = Vector3 . Transform ( new Vector3 ( 0 , 0 , - axisSize ) , matrix ) ;
1633+ var pos1 = Vector3 . Transform ( new Vector3 ( 0 , 0 , axisSize ) , matrix ) ;
1634+ vertices [ i ] = new ( pos0 , default , colZ ) ;
1635+ vertices [ i + 1 ] = new ( pos1 , default , colZ ) ;
1636+ indices [ i ] = i ;
1637+ indices [ i + 1 ] = i + 1 ;
1638+ i += 2 ;
1639+ }
1640+ }
1641+
1642+ CurrentList . RecordCmd ( DebugDrawPrimitiveTopology . LineList ) ;
1643+ }
14791644 }
14801645}
0 commit comments