@quenty/draw 2.1.0 → 2.2.1-canary.238.f89c386.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.2.1-canary.238.f89c386.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/draw@2.2.0...@quenty/draw@2.2.1-canary.238.f89c386.0) (2021-12-30)
7
+
8
+ **Note:** Version bump only for package @quenty/draw
9
+
10
+
11
+
12
+
13
+
14
+ # [2.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/draw@2.1.0...@quenty/draw@2.2.0) (2021-10-02)
15
+
16
+
17
+ ### Features
18
+
19
+ * Can update ray appearance for performance reasons ([ae6cbd3](https://github.com/Quenty/NevermoreEngine/commit/ae6cbd35f22105519fa2ca11c1e456be8b4d6771))
20
+
21
+
22
+
23
+
24
+
6
25
  # [2.1.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/draw@2.0.0...@quenty/draw@2.1.0) (2021-09-22)
7
26
 
8
27
 
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2014 Quenty
3
+ Copyright (c) 2014-2021 Quenty
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  ## Draw
2
2
  <div align="center">
3
- <a href="http://quenty.github.io/api/">
4
- <img src="https://img.shields.io/badge/docs-website-green.svg" alt="Documentation" />
3
+ <a href="http://quenty.github.io/NevermoreEngine/">
4
+ <img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/docs.yml/badge.svg" alt="Documentation status" />
5
5
  </a>
6
6
  <a href="https://discord.gg/mhtGUS8">
7
- <img src="https://img.shields.io/badge/discord-nevermore-blue.svg" alt="Discord" />
7
+ <img src="https://img.shields.io/discord/385151591524597761?color=5865F2&label=discord&logo=discord&logoColor=white" alt="Discord" />
8
8
  </a>
9
9
  <a href="https://github.com/Quenty/NevermoreEngine/actions">
10
10
  <img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/build.yml/badge.svg" alt="Build and release status" />
@@ -13,6 +13,8 @@
13
13
 
14
14
  A utility library to debug things in 3D space for Roblox. Each method will always return an object you can use to cleanup the resulting drawing.
15
15
 
16
+ <div align="center"><a href="https://quenty.github.io/NevermoreEngine/api/Draw">View docs →</a></div>
17
+
16
18
  ## Installation
17
19
  ```
18
20
  npm install @quenty/draw --save
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/draw",
3
- "version": "2.1.0",
3
+ "version": "2.2.1-canary.238.f89c386.0",
4
4
  "description": "A utility library to debug things in 3D space for Roblox.",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -28,5 +28,5 @@
28
28
  "publishConfig": {
29
29
  "access": "public"
30
30
  },
31
- "gitHead": "6288c63115f31544fce6663d018826e81ef01c7f"
31
+ "gitHead": "f89c3863db94c96adc936ea31a49e0c770756dd0"
32
32
  }
@@ -1,5 +1,25 @@
1
- --- Debug drawing library useful for debugging 3D abstractions
2
- -- @module Draw
1
+ --[=[
2
+ Debug drawing library useful for debugging 3D abstractions. One of
3
+ the more useful utility libraries.
4
+
5
+ These functions are incredibly easy to invoke for quick debugging.
6
+ This can make debugging any sort of 3D geometry really easy.
7
+
8
+ ```lua
9
+ -- A sample of a few API uses
10
+ Draw.point(Vector3.new(0, 0, 0))
11
+ Draw.terrainCell(Vector3.new(0, 0, 0))
12
+ Draw.cframe(CFrame.new(0, 10, 0))
13
+ Draw.text(Vector3.new(0, -10, 0), "Testing!")
14
+ ```
15
+
16
+ :::tip
17
+ This library should not be used to render things in production for
18
+ normal players, as it is optimized for debug experience over performance.
19
+ :::
20
+
21
+ @class Draw
22
+ ]=]
3
23
 
4
24
  local Workspace = game:GetService("Workspace")
5
25
  local RunService = game:GetService("RunService")
@@ -12,27 +32,43 @@ local ORIGINAL_DEFAULT_COLOR = Color3.new(1, 0, 0)
12
32
  local Draw = {}
13
33
  Draw._defaultColor = ORIGINAL_DEFAULT_COLOR
14
34
 
15
- --- Sets the Draw's drawing color
16
- -- @tparam {Color3} color The color to set
35
+ --[=[
36
+ Sets the Draw's drawing color.
37
+ @param color Color3 -- The color to set
38
+ ]=]
17
39
  function Draw.setColor(color)
18
40
  Draw._defaultColor = color
19
41
  end
20
42
 
43
+ --[=[
44
+ Resets the drawing color.
45
+ ]=]
21
46
  function Draw.resetColor()
22
47
  Draw._defaultColor = ORIGINAL_DEFAULT_COLOR
23
48
  end
24
49
 
25
- --- Sets the Draw library to use a random color
50
+ --[=[
51
+ Sets the Draw library to use a random color.
52
+ ]=]
26
53
  function Draw.setRandomColor()
27
54
  Draw.setColor(Color3.fromHSV(math.random(), 0.5+0.5*math.random(), 1))
28
55
  end
29
56
 
30
- --- Draws a ray for debugging
31
- -- @param ray The ray to Draw
32
- -- @tparam[opt] {color3} color The color to Draw in
33
- -- @tparam[opt] {Instance} parent
34
- -- @tparam[opt] {number} diameter
35
- -- @tparam[opt] {number} meshDiameter
57
+ --[=[
58
+ Draws a ray for debugging.
59
+
60
+ ```lua
61
+ local ray = Ray.new(Vector3.new(0, 0, 0), Vector3.new(0, 10, 0))
62
+ Draw.ray(ray)
63
+ ```
64
+
65
+ @param ray Ray
66
+ @param color Color3? -- Optional color to draw in
67
+ @param parent Instance? -- Optional parent
68
+ @param diameter number? -- Optional diameter
69
+ @param meshDiameter number? -- Optional mesh diameter
70
+ @return BasePart
71
+ ]=]
36
72
  function Draw.ray(ray, color, parent, meshDiameter, diameter)
37
73
  assert(typeof(ray) == "Ray", "Bad typeof(ray) for Ray")
38
74
 
@@ -58,6 +94,7 @@ function Draw.ray(ray, color, parent, meshDiameter, diameter)
58
94
  part.Transparency = 0.5
59
95
 
60
96
  local rotatedPart = Instance.new("Part")
97
+ rotatedPart.Name = "RotatedPart"
61
98
  rotatedPart.Anchored = true
62
99
  rotatedPart.Archivable = false
63
100
  rotatedPart.CanCollide = false
@@ -68,6 +105,7 @@ function Draw.ray(ray, color, parent, meshDiameter, diameter)
68
105
  rotatedPart.Parent = part
69
106
 
70
107
  local lineHandleAdornment = Instance.new("LineHandleAdornment")
108
+ lineHandleAdornment.Name = "DrawRayLineHandleAdornment"
71
109
  lineHandleAdornment.Length = ray.Direction.Magnitude
72
110
  lineHandleAdornment.Thickness = 5*diameter
73
111
  lineHandleAdornment.ZIndex = 3
@@ -78,6 +116,7 @@ function Draw.ray(ray, color, parent, meshDiameter, diameter)
78
116
  lineHandleAdornment.Parent = rotatedPart
79
117
 
80
118
  local mesh = Instance.new("SpecialMesh")
119
+ mesh.Name = "DrawRayMesh"
81
120
  mesh.Scale = Vector3.new(0, 1, 0) + Vector3.new(meshDiameter, 0, meshDiameter) / diameter
82
121
  mesh.Parent = part
83
122
 
@@ -86,6 +125,61 @@ function Draw.ray(ray, color, parent, meshDiameter, diameter)
86
125
  return part
87
126
  end
88
127
 
128
+ --[=[
129
+ Updates the rendered ray to the new color and position.
130
+ Used for certain scenarios when updating a ray on
131
+ renderstepped would impact performance, even in debug mode.
132
+
133
+ ```lua
134
+ local ray = Ray.new(Vector3.new(0, 0, 0), Vector3.new(0, 10, 0))
135
+ local drawn = Draw.ray(ray)
136
+
137
+ RunService.RenderStepped:Connect(function()
138
+ local newRay = Ray.new(Vector3.new(0, 0, 0), Vector3.new(0, 10*math.sin(os.clock()), 0))
139
+ Draw.updateRay(drawn, newRay Color3.new(1, 0.5, 0.5))
140
+ end)
141
+ ```
142
+
143
+ @param part Ray part
144
+ @param ray Ray
145
+ @param color Color3
146
+ ]=]
147
+ function Draw.updateRay(part, ray, color)
148
+ color = color or part.Color
149
+
150
+ local diameter = part.Size.x
151
+ local rayCenter = ray.Origin + ray.Direction/2
152
+
153
+ part.CFrame = CFrame.new(rayCenter, ray.Origin + ray.Direction) * CFrame.Angles(math.pi/2, 0, 0)
154
+ part.Size = Vector3.new(diameter, ray.Direction.Magnitude, diameter)
155
+ part.Color = color
156
+
157
+ local rotatedPart = part:FindFirstChild("RotatedPart")
158
+ if rotatedPart then
159
+ rotatedPart.CFrame = CFrame.new(ray.Origin, ray.Origin + ray.Direction)
160
+ end
161
+
162
+ local lineHandleAdornment = rotatedPart and rotatedPart:FindFirstChild("DrawRayLineHandleAdornment")
163
+ if lineHandleAdornment then
164
+ lineHandleAdornment.Length = ray.Direction.Magnitude
165
+ lineHandleAdornment.Thickness = 5*diameter
166
+ lineHandleAdornment.Color3 = color
167
+ end
168
+ end
169
+
170
+ --[=[
171
+ Render text in 3D for debugging. The text container will
172
+ be sized to fit the text.
173
+
174
+ ```lua
175
+ Draw.text(Vector3.new(0, 10, 0), "Point")
176
+ ```
177
+
178
+ @param adornee Instance | Vector3 -- Adornee to rener on
179
+ @param text string -- Text to render
180
+ @param color Color3? -- Optional color to render
181
+ @return Instance
182
+ ]=]
89
183
  function Draw.text(adornee, text, color)
90
184
  if typeof(adornee) == "Vector3" then
91
185
  local attachment = Instance.new("Attachment")
@@ -177,21 +271,44 @@ function Draw._textOnAdornee(adornee, text, color)
177
271
  return billboardGui
178
272
  end
179
273
 
180
- function Draw.sphere(vector3, radius, color, parent)
181
- return Draw.point(vector3, color, parent, radius*2)
274
+ --[=[
275
+ Renders a sphere at the given point in 3D space.
276
+
277
+ ```lua
278
+ Draw.sphere(Vector3.new(0, 10, 0), 10)
279
+ ```
280
+
281
+ Great for debugging explosions and stuff.
282
+
283
+ @param position Vector3 -- Position of the sphere
284
+ @param radius number -- Radius of the sphere
285
+ @param color Color3? -- Optional color
286
+ @param parent Instance? -- Optional parent
287
+ @return BasePart
288
+ ]=]
289
+ function Draw.sphere(position, radius, color, parent)
290
+ return Draw.point(position, color, parent, radius*2)
182
291
  end
183
292
 
184
- --- Draws a point for debugging
185
- -- @tparam {Vector3} vector3 Point to Draw
186
- -- @tparam[opt] {color3} color The color to Draw in
187
- -- @tparam[opt] {Instance} parent
188
- -- @tparam[opt] {number} diameter
189
- function Draw.point(vector3, color, parent, diameter)
190
- if typeof(vector3) == "CFrame" then
191
- vector3 = vector3.p
293
+ --[=[
294
+ Draws a point for debugging in 3D space.
295
+
296
+ ```lua
297
+ Draw.point(Vector3.new(0, 25, 0), Color3.new(0.5, 1, 0.5))
298
+ ```
299
+
300
+ @param position Vector3 | CFrame -- Point to Draw
301
+ @param color Color3? -- Optional color
302
+ @param parent Instance? -- Optional parent
303
+ @param diameter number? -- Optional diameter
304
+ @return BasePart
305
+ ]=]
306
+ function Draw.point(position, color, parent, diameter)
307
+ if typeof(position) == "CFrame" then
308
+ position = position.p
192
309
  end
193
310
 
194
- assert(typeof(vector3) == "Vector3", "Bad vector3")
311
+ assert(typeof(position) == "Vector3", "Bad position")
195
312
 
196
313
  color = color or Draw._defaultColor
197
314
  parent = parent or Draw.getDefaultParent()
@@ -204,7 +321,7 @@ function Draw.point(vector3, color, parent, diameter)
204
321
  part.BottomSurface = Enum.SurfaceType.Smooth
205
322
  part.CanCollide = false
206
323
  part.CastShadow = false
207
- part.CFrame = CFrame.new(vector3)
324
+ part.CFrame = CFrame.new(position)
208
325
  part.Color = color
209
326
  part.Name = "DebugPoint"
210
327
  part.Shape = Enum.PartType.Ball
@@ -226,18 +343,41 @@ function Draw.point(vector3, color, parent, diameter)
226
343
  return part
227
344
  end
228
345
 
229
- function Draw.labelledPoint(vector3, label, color, parent)
230
- if typeof(vector3) == "CFrame" then
231
- vector3 = vector3.p
346
+ --[=[
347
+ Renders a point with a label in 3D space.
348
+
349
+ ```lua
350
+ Draw.labelledPoint(Vector3.new(0, 10, 0), "AI target")
351
+ ```
352
+
353
+ @param position Vector3 | CFrame -- Position to render
354
+ @param label string -- Label to render on the point
355
+ @param color Color3? -- Optional color
356
+ @param parent Instance? -- Optional parent
357
+ @return BasePart
358
+ ]=]
359
+ function Draw.labelledPoint(position, label, color, parent)
360
+ if typeof(position) == "CFrame" then
361
+ position = position.p
232
362
  end
233
363
 
234
- local part = Draw.point(vector3, color, parent)
364
+ local part = Draw.point(position, color, parent)
235
365
 
236
366
  Draw.text(part, label, color)
237
367
 
238
368
  return part
239
369
  end
240
370
 
371
+ --[=[
372
+ Renders a CFrame in 3D space. Includes each axis.
373
+
374
+ ```lua
375
+ Draw.cframe(CFrame.Angles(0, math.pi/8, 0))
376
+ ```
377
+
378
+ @param cframe CFrame
379
+ @return Model
380
+ ]=]
241
381
  function Draw.cframe(cframe)
242
382
  local model = Instance.new("Model")
243
383
  model.Name = "DebugCFrame"
@@ -268,6 +408,17 @@ function Draw.cframe(cframe)
268
408
  return model
269
409
  end
270
410
 
411
+ --[=[
412
+ Renders a box in 3D space. Great for debugging bounding boxes.
413
+
414
+ ```lua
415
+ Draw.box(Vector3.new(0, 5, 0), Vector3.new(10, 10, 10))
416
+ ```
417
+ @param cframe CFrame | Vector3 -- CFrame of the box
418
+ @param size Vector3 -- Size of the box
419
+ @param color Color3 -- Optional Color3
420
+ @return BasePart
421
+ ]=]
271
422
  function Draw.box(cframe, size, color)
272
423
  assert(typeof(size) == "Vector3", "Bad size")
273
424
 
@@ -302,10 +453,33 @@ function Draw.box(cframe, size, color)
302
453
  return part
303
454
  end
304
455
 
456
+ --[=[
457
+ Renders a region3 in 3D space.
458
+
459
+ ```lua
460
+ Draw.region3(Region3.new(Vector3.new(0, 0, 0), Vector3.new(10, 10, 10)))
461
+ ```
462
+
463
+ @param region3 Region3 -- Region3 to render
464
+ @param color Color3? -- Optional color3
465
+ @return BasePart
466
+ ]=]
305
467
  function Draw.region3(region3, color)
306
468
  return Draw.box(region3.CFrame, region3.Size, color)
307
469
  end
308
470
 
471
+ --[=[
472
+ Renders a terrain cell in 3D space. Snaps the position
473
+ to the nearest position.
474
+
475
+ ```lua
476
+ Draw.terrainCell(Vector3.new(0, 0, 0))
477
+ ```
478
+
479
+ @param position Vector3 -- World space position
480
+ @param color Color3? -- Optional color to render
481
+ @return BasePart
482
+ ]=]
309
483
  function Draw.terrainCell(position, color)
310
484
  local size = Vector3.new(4, 4, 4)
311
485
 
@@ -318,16 +492,38 @@ function Draw.terrainCell(position, color)
318
492
  return part
319
493
  end
320
494
 
495
+ --[=[
496
+ Draws a vector in 3D space.
497
+
498
+ ```lua
499
+ Draw.vector(Vector3.new(0, 0, 0), Vector3.new(0, 1, 0))
500
+ ```
501
+
502
+ @param position Vector3 -- Position of the vector
503
+ @param direction Vector3 -- Direction of the vector. Determines length.
504
+ @param color Color3? -- Optional color
505
+ @param parent Instance? -- Optional instance
506
+ @param meshDiameter number? -- Optional diameter
507
+ @return BasePart
508
+ ]=]
321
509
  function Draw.vector(position, direction, color, parent, meshDiameter)
322
510
  return Draw.ray(Ray.new(position, direction), color, parent, meshDiameter)
323
511
  end
324
512
 
513
+ --[=[
514
+ Retrieves the default parent for the current execution context.
515
+ @return Instance
516
+ ]=]
325
517
  function Draw.getDefaultParent()
326
518
  if not RunService:IsRunning() then
327
519
  return Workspace.CurrentCamera
328
520
  end
329
521
 
330
- return RunService:IsServer() and Workspace or Workspace.CurrentCamera
522
+ if RunService:IsServer() then
523
+ return Workspace
524
+ else
525
+ return Workspace.CurrentCamera
526
+ end
331
527
  end
332
528
 
333
529
  return Draw