-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathShowDebugShape.cs
More file actions
298 lines (213 loc) · 7.28 KB
/
ShowDebugShape.cs
File metadata and controls
298 lines (213 loc) · 7.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
using ProtoBuf;
using Sandbox.Game.Entities;
using Sandbox.Game.World;
using Sandbox.ModAPI;
using System;
using System.Collections.Generic;
using VRage.Game;
using VRage.Game.Entity;
using VRage.Game.ModAPI.Ingame;
using VRageMath;
using Color = VRageMath.Color;
namespace Torch.Mod.Messages
{
[ProtoContract]
public class DrawDebug : MessageBase
{
//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
public static Dictionary<string, DrawDebug> AllDraws = new Dictionary<string, DrawDebug>();
//Used as an identifier if you only want to remove one draw group
[ProtoMember(301)]
public string uniqueName;
[ProtoMember(302)]
public List<drawObject> drawObjects = new List<drawObject>();
[ProtoMember(303)]
public bool remove = false;
[ProtoMember(304)]
public bool removeAll = false;
public DrawDebug() { }
public DrawDebug(string uniqueName)
{
this.uniqueName = uniqueName;
}
public override void ProcessClient()
{
//must have a unique name
if (string.IsNullOrEmpty(uniqueName))
return;
if (remove)
{
clear(uniqueName);
}
else if (removeAll)
{
clearAll();
}
//MyAPIGateway.Utilities.ShowMessage("Torch", $"Hit process client on debug draw!");
//If its the same unique name, we can add it
if(AllDraws.ContainsKey(uniqueName))
{
AllDraws[uniqueName].drawObjects.AddList(drawObjects);
}
else
{
AllDraws.Add(uniqueName, this);
}
//If both are not false, then we have new items to draw
}
public override void ProcessServer()
{
//Nothing to do server side
}
public void addOBB(BoundingBoxD box, Vector3D position, Vector3D forward, Vector3D up, Color color, MySimpleObjectRasterizer raster, float intensity, float linethickness)
{
drawObject obj = new drawObject(drawObject.drawtype.OBB);
obj.box = box;
obj.position = position;
obj.forward = forward;
obj.up = up;
obj.color = color;
obj.intensity = intensity;
obj.linethickness = linethickness;
obj.raster = raster;
drawObjects.Add(obj);
}
public void addOBBLinkedEntity(long entityID, Color color, MySimpleObjectRasterizer raster, float intensity, float linethickness)
{
drawObject obj = new drawObject(drawObject.drawtype.OBBEntity);
obj.entityID = entityID;
obj.color = color;
obj.intensity = intensity;
obj.linethickness = linethickness;
obj.raster = raster;
drawObjects.Add(obj);
}
public void addSphere(Vector3D position, float radius, Color color, MySimpleObjectRasterizer raster, float intensity, float linethickness)
{
drawObject obj = new drawObject(drawObject.drawtype.Sphere);
obj.position = position;
obj.radius = radius;
obj.color = color;
obj.intensity = intensity;
obj.linethickness = linethickness;
obj.raster = raster;
drawObjects.Add(obj);
}
public static void clear(string uniquename)
{
if (AllDraws.ContainsKey(uniquename))
AllDraws.Remove(uniquename);
}
public static void clearAll()
{
AllDraws.Clear();
}
//Updates individual method
public void refreshDraw()
{
foreach (var draw in drawObjects)
{
draw.update();
}
}
//static update to update all draws
public static void refreshAllDraws()
{
try
{
foreach (var draw in AllDraws)
{
draw.Value.refreshDraw();
}
}catch(Exception ex)
{
//do nothings
}
}
}
[ProtoContract]
public class drawObject
{
public MyEntity entRef;
public int searchAttempts = 0;
public drawObject() { }
public drawObject(drawtype type) { this.type = type; }
[ProtoMember(100)]
public drawtype type;
[ProtoMember(101)]
public Vector3D position;
[ProtoMember(102)]
public VRageMath.Color color;
[ProtoMember(103)]
public MySimpleObjectRasterizer raster;
[ProtoMember(104)]
public BoundingBoxD box;
[ProtoMember(105)]
public Vector3D forward;
[ProtoMember(106)]
public Vector3D up;
[ProtoMember(118)]
public int wireDivideRatio = 0;
[ProtoMember(120)]
public float radius;
[ProtoMember(121)]
public float intensity;
[ProtoMember(122)]
public float linethickness = -1;
[ProtoMember(123)]
public long entityID = 0;
//[ProtoMember(100)]
//public MyOrientedBoundingBoxD obb;
public enum drawtype
{
OBB,
Sphere,
OBBEntity,
}
public void update()
{
switch (type)
{
case drawtype.OBB:
drawOBB();
break;
case drawtype.Sphere:
drawSphere();
break;
case drawtype.OBBEntity:
drawOBBEntity();
break;
}
}
public void drawOBB()
{
MatrixD worldMatrix = MatrixD.CreateWorld(position, forward, up);
var material = TorchModCore.id;
MySimpleObjectDraw.DrawTransparentBox(ref worldMatrix, ref box, ref color, raster, wireDivideRatio, linethickness, material, material, intensity: intensity);
}
public void drawSphere()
{
var material = TorchModCore.id;
var transform = MatrixD.CreateTranslation(position);
MySimpleObjectDraw.DrawTransparentSphere(ref transform, radius, ref color, raster, wireDivideRatio, material, material, linethickness, intensity: intensity);
}
public void drawOBBEntity()
{
//This will keep updating the draw for live grid box preview
//Do not keep searching for entity on draw
if (searchAttempts > 250 || entityID == 0)
return;
entRef = MyEntities.GetEntityById(entityID);
if (entRef == null )
{
searchAttempts++;
return;
}
var material = TorchModCore.id;
var Matrix = entRef.WorldMatrix;
BoundingBoxD myAabb = entRef.PositionComp.LocalAABB;
MySimpleObjectDraw.DrawTransparentBox(ref Matrix, ref myAabb, ref color, raster, wireDivideRatio, linethickness, material, material);
}
}
}