@quenty/draw 2.2.0 → 2.2.2

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.2](https://github.com/Quenty/NevermoreEngine/compare/@quenty/draw@2.2.1...@quenty/draw@2.2.2) (2022-01-16)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Disable CanTouch and CanQuery ([#246](https://github.com/Quenty/NevermoreEngine/issues/246)) ([2f5d6e0](https://github.com/Quenty/NevermoreEngine/commit/2f5d6e006176ac4b5e15b29efe8f3b8b842a1a7b))
12
+
13
+
14
+
15
+
16
+
17
+ ## [2.2.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/draw@2.2.0...@quenty/draw@2.2.1) (2021-12-30)
18
+
19
+ **Note:** Version bump only for package @quenty/draw
20
+
21
+
22
+
23
+
24
+
6
25
  # [2.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/draw@2.1.0...@quenty/draw@2.2.0) (2021-10-02)
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.2.0",
3
+ "version": "2.2.2",
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": "2cae4b40a33765f444e6f0b1f3d6e181489dfa57"
31
+ "gitHead": "e5be9e38e7fbbaed3296c3c83bd40f8745425ac3"
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
 
@@ -48,6 +84,8 @@ function Draw.ray(ray, color, parent, meshDiameter, diameter)
48
84
  part.Anchored = true
49
85
  part.Archivable = false
50
86
  part.CanCollide = false
87
+ part.CanQuery = false
88
+ part.CanTouch = false
51
89
  part.CastShadow = false
52
90
  part.CFrame = CFrame.new(rayCenter, ray.Origin + ray.Direction) * CFrame.Angles(math.pi/2, 0, 0)
53
91
  part.Color = color
@@ -62,6 +100,8 @@ function Draw.ray(ray, color, parent, meshDiameter, diameter)
62
100
  rotatedPart.Anchored = true
63
101
  rotatedPart.Archivable = false
64
102
  rotatedPart.CanCollide = false
103
+ part.CanQuery = false
104
+ part.CanTouch = false
65
105
  rotatedPart.CastShadow = false
66
106
  rotatedPart.CFrame = CFrame.new(ray.Origin, ray.Origin + ray.Direction)
67
107
  rotatedPart.Transparency = 1
@@ -89,6 +129,25 @@ function Draw.ray(ray, color, parent, meshDiameter, diameter)
89
129
  return part
90
130
  end
91
131
 
132
+ --[=[
133
+ Updates the rendered ray to the new color and position.
134
+ Used for certain scenarios when updating a ray on
135
+ renderstepped would impact performance, even in debug mode.
136
+
137
+ ```lua
138
+ local ray = Ray.new(Vector3.new(0, 0, 0), Vector3.new(0, 10, 0))
139
+ local drawn = Draw.ray(ray)
140
+
141
+ RunService.RenderStepped:Connect(function()
142
+ local newRay = Ray.new(Vector3.new(0, 0, 0), Vector3.new(0, 10*math.sin(os.clock()), 0))
143
+ Draw.updateRay(drawn, newRay Color3.new(1, 0.5, 0.5))
144
+ end)
145
+ ```
146
+
147
+ @param part Ray part
148
+ @param ray Ray
149
+ @param color Color3
150
+ ]=]
92
151
  function Draw.updateRay(part, ray, color)
93
152
  color = color or part.Color
94
153
 
@@ -112,6 +171,19 @@ function Draw.updateRay(part, ray, color)
112
171
  end
113
172
  end
114
173
 
174
+ --[=[
175
+ Render text in 3D for debugging. The text container will
176
+ be sized to fit the text.
177
+
178
+ ```lua
179
+ Draw.text(Vector3.new(0, 10, 0), "Point")
180
+ ```
181
+
182
+ @param adornee Instance | Vector3 -- Adornee to rener on
183
+ @param text string -- Text to render
184
+ @param color Color3? -- Optional color to render
185
+ @return Instance
186
+ ]=]
115
187
  function Draw.text(adornee, text, color)
116
188
  if typeof(adornee) == "Vector3" then
117
189
  local attachment = Instance.new("Attachment")
@@ -203,21 +275,44 @@ function Draw._textOnAdornee(adornee, text, color)
203
275
  return billboardGui
204
276
  end
205
277
 
206
- function Draw.sphere(vector3, radius, color, parent)
207
- return Draw.point(vector3, color, parent, radius*2)
278
+ --[=[
279
+ Renders a sphere at the given point in 3D space.
280
+
281
+ ```lua
282
+ Draw.sphere(Vector3.new(0, 10, 0), 10)
283
+ ```
284
+
285
+ Great for debugging explosions and stuff.
286
+
287
+ @param position Vector3 -- Position of the sphere
288
+ @param radius number -- Radius of the sphere
289
+ @param color Color3? -- Optional color
290
+ @param parent Instance? -- Optional parent
291
+ @return BasePart
292
+ ]=]
293
+ function Draw.sphere(position, radius, color, parent)
294
+ return Draw.point(position, color, parent, radius*2)
208
295
  end
209
296
 
210
- --- Draws a point for debugging
211
- -- @tparam {Vector3} vector3 Point to Draw
212
- -- @tparam[opt] {color3} color The color to Draw in
213
- -- @tparam[opt] {Instance} parent
214
- -- @tparam[opt] {number} diameter
215
- function Draw.point(vector3, color, parent, diameter)
216
- if typeof(vector3) == "CFrame" then
217
- vector3 = vector3.p
297
+ --[=[
298
+ Draws a point for debugging in 3D space.
299
+
300
+ ```lua
301
+ Draw.point(Vector3.new(0, 25, 0), Color3.new(0.5, 1, 0.5))
302
+ ```
303
+
304
+ @param position Vector3 | CFrame -- Point to Draw
305
+ @param color Color3? -- Optional color
306
+ @param parent Instance? -- Optional parent
307
+ @param diameter number? -- Optional diameter
308
+ @return BasePart
309
+ ]=]
310
+ function Draw.point(position, color, parent, diameter)
311
+ if typeof(position) == "CFrame" then
312
+ position = position.p
218
313
  end
219
314
 
220
- assert(typeof(vector3) == "Vector3", "Bad vector3")
315
+ assert(typeof(position) == "Vector3", "Bad position")
221
316
 
222
317
  color = color or Draw._defaultColor
223
318
  parent = parent or Draw.getDefaultParent()
@@ -229,8 +324,10 @@ function Draw.point(vector3, color, parent, diameter)
229
324
  part.Archivable = false
230
325
  part.BottomSurface = Enum.SurfaceType.Smooth
231
326
  part.CanCollide = false
327
+ part.CanQuery = false
328
+ part.CanTouch = false
232
329
  part.CastShadow = false
233
- part.CFrame = CFrame.new(vector3)
330
+ part.CFrame = CFrame.new(position)
234
331
  part.Color = color
235
332
  part.Name = "DebugPoint"
236
333
  part.Shape = Enum.PartType.Ball
@@ -252,18 +349,41 @@ function Draw.point(vector3, color, parent, diameter)
252
349
  return part
253
350
  end
254
351
 
255
- function Draw.labelledPoint(vector3, label, color, parent)
256
- if typeof(vector3) == "CFrame" then
257
- vector3 = vector3.p
352
+ --[=[
353
+ Renders a point with a label in 3D space.
354
+
355
+ ```lua
356
+ Draw.labelledPoint(Vector3.new(0, 10, 0), "AI target")
357
+ ```
358
+
359
+ @param position Vector3 | CFrame -- Position to render
360
+ @param label string -- Label to render on the point
361
+ @param color Color3? -- Optional color
362
+ @param parent Instance? -- Optional parent
363
+ @return BasePart
364
+ ]=]
365
+ function Draw.labelledPoint(position, label, color, parent)
366
+ if typeof(position) == "CFrame" then
367
+ position = position.p
258
368
  end
259
369
 
260
- local part = Draw.point(vector3, color, parent)
370
+ local part = Draw.point(position, color, parent)
261
371
 
262
372
  Draw.text(part, label, color)
263
373
 
264
374
  return part
265
375
  end
266
376
 
377
+ --[=[
378
+ Renders a CFrame in 3D space. Includes each axis.
379
+
380
+ ```lua
381
+ Draw.cframe(CFrame.Angles(0, math.pi/8, 0))
382
+ ```
383
+
384
+ @param cframe CFrame
385
+ @return Model
386
+ ]=]
267
387
  function Draw.cframe(cframe)
268
388
  local model = Instance.new("Model")
269
389
  model.Name = "DebugCFrame"
@@ -294,6 +414,17 @@ function Draw.cframe(cframe)
294
414
  return model
295
415
  end
296
416
 
417
+ --[=[
418
+ Renders a box in 3D space. Great for debugging bounding boxes.
419
+
420
+ ```lua
421
+ Draw.box(Vector3.new(0, 5, 0), Vector3.new(10, 10, 10))
422
+ ```
423
+ @param cframe CFrame | Vector3 -- CFrame of the box
424
+ @param size Vector3 -- Size of the box
425
+ @param color Color3 -- Optional Color3
426
+ @return BasePart
427
+ ]=]
297
428
  function Draw.box(cframe, size, color)
298
429
  assert(typeof(size) == "Vector3", "Bad size")
299
430
 
@@ -306,6 +437,8 @@ function Draw.box(cframe, size, color)
306
437
  part.Name = "DebugPart"
307
438
  part.Anchored = true
308
439
  part.CanCollide = false
440
+ part.CanQuery = false
441
+ part.CanTouch = false
309
442
  part.CastShadow = false
310
443
  part.Archivable = false
311
444
  part.BottomSurface = Enum.SurfaceType.Smooth
@@ -328,10 +461,33 @@ function Draw.box(cframe, size, color)
328
461
  return part
329
462
  end
330
463
 
464
+ --[=[
465
+ Renders a region3 in 3D space.
466
+
467
+ ```lua
468
+ Draw.region3(Region3.new(Vector3.new(0, 0, 0), Vector3.new(10, 10, 10)))
469
+ ```
470
+
471
+ @param region3 Region3 -- Region3 to render
472
+ @param color Color3? -- Optional color3
473
+ @return BasePart
474
+ ]=]
331
475
  function Draw.region3(region3, color)
332
476
  return Draw.box(region3.CFrame, region3.Size, color)
333
477
  end
334
478
 
479
+ --[=[
480
+ Renders a terrain cell in 3D space. Snaps the position
481
+ to the nearest position.
482
+
483
+ ```lua
484
+ Draw.terrainCell(Vector3.new(0, 0, 0))
485
+ ```
486
+
487
+ @param position Vector3 -- World space position
488
+ @param color Color3? -- Optional color to render
489
+ @return BasePart
490
+ ]=]
335
491
  function Draw.terrainCell(position, color)
336
492
  local size = Vector3.new(4, 4, 4)
337
493
 
@@ -344,16 +500,38 @@ function Draw.terrainCell(position, color)
344
500
  return part
345
501
  end
346
502
 
503
+ --[=[
504
+ Draws a vector in 3D space.
505
+
506
+ ```lua
507
+ Draw.vector(Vector3.new(0, 0, 0), Vector3.new(0, 1, 0))
508
+ ```
509
+
510
+ @param position Vector3 -- Position of the vector
511
+ @param direction Vector3 -- Direction of the vector. Determines length.
512
+ @param color Color3? -- Optional color
513
+ @param parent Instance? -- Optional instance
514
+ @param meshDiameter number? -- Optional diameter
515
+ @return BasePart
516
+ ]=]
347
517
  function Draw.vector(position, direction, color, parent, meshDiameter)
348
518
  return Draw.ray(Ray.new(position, direction), color, parent, meshDiameter)
349
519
  end
350
520
 
521
+ --[=[
522
+ Retrieves the default parent for the current execution context.
523
+ @return Instance
524
+ ]=]
351
525
  function Draw.getDefaultParent()
352
526
  if not RunService:IsRunning() then
353
527
  return Workspace.CurrentCamera
354
528
  end
355
529
 
356
- return RunService:IsServer() and Workspace or Workspace.CurrentCamera
530
+ if RunService:IsServer() then
531
+ return Workspace
532
+ else
533
+ return Workspace.CurrentCamera
534
+ end
357
535
  end
358
536
 
359
537
  return Draw