11
22using ProtoBuf ;
3+ using Sandbox . Game . Entities ;
4+ using Sandbox . Game . World ;
35using Sandbox . ModAPI ;
46using System . Collections . Generic ;
57using VRage . Game ;
8+ using VRage . Game . Entity ;
9+ using VRage . Game . ModAPI . Ingame ;
610using VRageMath ;
711using Color = VRageMath . Color ;
812
@@ -13,7 +17,7 @@ public class DrawDebug : MessageBase
1317 {
1418 //Since we can only clear all renders, we can keep track of each one sent such that we can remove one but keep the rest
1519 public static Dictionary < string , DrawDebug > AllDraws = new Dictionary < string , DrawDebug > ( ) ;
16-
20+
1721
1822 //Used as an identifier if you only want to remove one draw group
1923 [ ProtoMember ( 301 ) ]
@@ -42,23 +46,23 @@ public DrawDebug(string uniqueName)
4246 public override void ProcessClient ( )
4347 {
4448 //must have a unique name
45- if ( string . IsNullOrEmpty ( uniqueName ) )
49+ if ( string . IsNullOrEmpty ( uniqueName ) )
4650 return ;
4751
48- if ( remove )
52+ if ( remove )
4953 {
5054 clear ( uniqueName ) ;
5155 return ;
5256 }
53- else if ( removeAll )
57+ else if ( removeAll )
5458 {
5559 clearAll ( ) ;
5660 return ;
5761 }
5862
5963 //MyAPIGateway.Utilities.ShowMessage("Torch", $"Hit process client on debug draw!");
6064
61- if ( ! AllDraws . ContainsKey ( uniqueName ) )
65+ if ( ! AllDraws . ContainsKey ( uniqueName ) )
6266 AllDraws . Add ( uniqueName , this ) ;
6367
6468 //If both are not false, then we have new items to draw
@@ -79,10 +83,23 @@ public void addOBB(BoundingBoxD box, Vector3D position, Vector3D forward, Vector
7983 obj . position = position ;
8084 obj . forward = forward ;
8185 obj . up = up ;
82- obj . color = color ;
86+ obj . color = color ;
8387 obj . intensity = intensity ;
8488 obj . linethickness = linethickness ;
85- obj . raster = raster ;
89+ obj . raster = raster ;
90+
91+ drawObjects . Add ( obj ) ;
92+ }
93+
94+ public void addOBBLinkedEntity ( long entityID , Color color , MySimpleObjectRasterizer raster , float intensity , float linethickness )
95+ {
96+ drawObject obj = new drawObject ( drawObject . drawtype . OBBEntity ) ;
97+
98+ obj . entityID = entityID ;
99+ obj . color = color ;
100+ obj . intensity = intensity ;
101+ obj . linethickness = linethickness ;
102+ obj . raster = raster ;
86103
87104 drawObjects . Add ( obj ) ;
88105 }
@@ -93,19 +110,21 @@ public void addSphere(Vector3D position, float radius, Color color, MySimpleObje
93110
94111 obj . position = position ;
95112 obj . radius = radius ;
96- obj . color = color ;
113+ obj . color = color ;
97114 obj . intensity = intensity ;
98115 obj . linethickness = linethickness ;
99- obj . raster = raster ;
116+ obj . raster = raster ;
100117
101118 drawObjects . Add ( obj ) ;
102119 }
103120
121+
122+
104123
105124 public static void clear ( string uniquename )
106125 {
107- if ( AllDraws . ContainsKey ( uniquename ) )
108- AllDraws . Remove ( uniquename ) ;
126+ if ( AllDraws . ContainsKey ( uniquename ) )
127+ AllDraws . Remove ( uniquename ) ;
109128 }
110129
111130 public static void clearAll ( )
@@ -116,7 +135,7 @@ public static void clearAll()
116135 //Updates individual method
117136 public void refreshDraw ( )
118137 {
119- foreach ( var draw in drawObjects )
138+ foreach ( var draw in drawObjects )
120139 {
121140 draw . update ( ) ;
122141 }
@@ -136,14 +155,17 @@ public static void refreshAllDraws()
136155
137156 }
138157
139-
158+
140159 [ ProtoContract ]
141160 public class drawObject
142161 {
143-
162+
163+ public MyEntity entRef ;
164+ public int searchAttempts = 0 ;
165+
144166 public drawObject ( ) { }
145167
146- public drawObject ( drawtype type ) { this . type = type ; }
168+ public drawObject ( drawtype type ) { this . type = type ; }
147169
148170
149171
@@ -178,19 +200,23 @@ public drawObject() { }
178200 [ ProtoMember ( 122 ) ]
179201 public float linethickness = - 1 ;
180202
203+ [ ProtoMember ( 123 ) ]
204+ public long entityID = 0 ;
205+
181206 //[ProtoMember(100)]
182207 //public MyOrientedBoundingBoxD obb;
183208
184209
185210 public enum drawtype
186211 {
187212 OBB ,
188- Sphere
213+ Sphere ,
214+ OBBEntity ,
189215 }
190216
191217 public void update ( )
192218 {
193-
219+
194220 switch ( type )
195221 {
196222 case drawtype . OBB :
@@ -199,6 +225,9 @@ public void update()
199225 case drawtype . Sphere :
200226 drawSphere ( ) ;
201227 break ;
228+ case drawtype . OBBEntity :
229+ drawOBBEntity ( ) ;
230+ break ;
202231 }
203232 }
204233
@@ -217,11 +246,32 @@ public void drawSphere()
217246 MySimpleObjectDraw . DrawTransparentSphere ( ref transform , 10 , ref color , raster , 25 , material , material , - 1 ) ;
218247 }
219248
249+ public void drawOBBEntity ( )
250+ {
251+ //This will keep updating the draw for live grid box preview
252+ //Do not keep searching for entity on draw
253+ if ( searchAttempts > 10 )
254+ return ;
255+
256+ if ( entRef == null && entityID != 0 )
257+ {
258+ entRef = MyEntities . GetEntityById ( entityID ) ;
259+ searchAttempts ++ ;
260+ }
261+
262+
263+ var material = TorchModCore . id ;
264+ var Matrix = entRef . WorldMatrix ;
265+ BoundingBoxD myAabb = entRef . PositionComp . LocalAABB ;
266+
267+ MySimpleObjectDraw . DrawTransparentBox ( ref Matrix , ref myAabb , ref color , raster , 1 , linethickness , material , material ) ;
268+ }
269+
220270
221271
222272
223273
224274
225275 }
226-
276+
227277}
0 commit comments