@quenty/draw 4.2.0 → 4.2.1-canary.402.a911cda.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,18 @@
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
+ ## [4.2.1-canary.402.a911cda.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/draw@4.2.0...@quenty/draw@4.2.1-canary.402.a911cda.0) (2023-08-23)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add Draw.line, Draw.direction, Draw.sphereCast, Draw.blockCast, and better draw semantics ([6d78106](https://github.com/Quenty/NevermoreEngine/commit/6d78106879fb6daa5bf5a28711aed746ed0a6f3e))
12
+ * Add Draw.raycast() ([1071969](https://github.com/Quenty/NevermoreEngine/commit/10719695aede9bc9b16f7c311a98dcd5120c43ac))
13
+
14
+
15
+
16
+
17
+
6
18
  # [4.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/draw@4.1.1...@quenty/draw@4.2.0) (2022-10-11)
7
19
 
8
20
 
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2014-2022 Quenty
3
+ Copyright (c) 2014-2023 James Onnen (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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/draw",
3
- "version": "4.2.0",
3
+ "version": "4.2.1-canary.402.a911cda.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": "69c2153865684748d0a8d6806f1ff999685c2e55"
31
+ "gitHead": "a911cdaf4f1039b599528cec17b027f4660e4fd8"
32
32
  }
@@ -55,6 +55,105 @@ function Draw.setRandomColor()
55
55
  Draw.setColor(Color3.fromHSV(math.random(), 0.5+0.5*math.random(), 1))
56
56
  end
57
57
 
58
+ --[=[
59
+ Draws a line between two points
60
+
61
+ @param start Vector3
62
+ @param finish Vector3
63
+ @param color Color3 -- Optional
64
+ @param parent Instance? -- Optional
65
+ @param meshDiameter number -- Optional
66
+ @param diameter number -- Optional
67
+ @return Instance
68
+ ]=]
69
+ function Draw.line(start, finish, color, parent, meshDiameter, diameter)
70
+ start = assert(Draw._toVector3(start), "Bad start")
71
+ finish = assert(Draw._toVector3(finish), "Bad finish")
72
+ color = Draw._toColor3(color)
73
+
74
+ return Draw.ray(Ray.new(start, finish - start), color, parent, meshDiameter, diameter)
75
+ end
76
+
77
+ --[=[
78
+ Draws a line between directions
79
+
80
+ @param origin Vector3
81
+ @param direction Vector3
82
+ @param color Color3 -- Optional
83
+ @param parent Instance? -- Optional
84
+ @param meshDiameter number -- Optional
85
+ @param diameter number -- Optional
86
+ @return Instance
87
+ ]=]
88
+ function Draw.direction(origin, direction, color, parent, meshDiameter, diameter)
89
+ origin = assert(Draw._toVector3(origin), "Bad origin")
90
+ direction = assert(Draw._toVector3(direction), "Bad direction")
91
+ color = Draw._toColor3(color)
92
+
93
+ return Draw.ray(Ray.new(origin, direction), color, parent, meshDiameter, diameter)
94
+ end
95
+
96
+ --[=[
97
+ Draws a spherecast
98
+
99
+ @param origin Vector3
100
+ @param radius number
101
+ @param direction Vector3
102
+ @param color Color3
103
+ @param parent Parent
104
+ ]=]
105
+ function Draw.sphereCast(origin, radius, direction, color, parent)
106
+ return Draw.ray(Ray.new(origin, direction), color, parent, 2*radius)
107
+ end
108
+
109
+ --[=[
110
+ Draws a spherecast
111
+
112
+ @param cframe CFrame
113
+ @param size Vector3
114
+ @param direction Vector3
115
+ @param color Color3
116
+ @param parent Parent
117
+ ]=]
118
+ function Draw.blockcast(cframe, size, direction, color, parent)
119
+ cframe = assert(Draw._toCFrame(cframe), "Bad cframe")
120
+ size = assert(Draw._toVector3(size), "Bad size")
121
+ color = Draw._toColor3(color)
122
+ parent = parent or Draw.getDefaultParent()
123
+
124
+ local folder = Instance.new("Folder")
125
+ folder.Name = "Blockcast"
126
+ folder.Archivable = false
127
+
128
+ -- Draw beginning and end for now...
129
+ -- TODO: Convex hull
130
+ Draw.box(cframe, size, color).Parent = folder
131
+ Draw.box(cframe + direction, size, color).Parent = folder
132
+
133
+ folder.Parent = parent
134
+
135
+ return folder
136
+ end
137
+
138
+ --[=[
139
+ Draws a raycast for debugging
140
+
141
+ ```lua
142
+ Draw.raycast(origin, direction)
143
+ ```
144
+
145
+ @param origin Vector3
146
+ @param direction Vector3
147
+ @param color Color3 -- Optional
148
+ @param parent Instance? -- Optional
149
+ @param meshDiameter number -- Optional
150
+ @param diameter number -- Optional
151
+ @return Instance
152
+ ]=]
153
+ function Draw.raycast(origin, direction, color, parent, meshDiameter, diameter)
154
+ return Draw.direction(origin, direction, color, parent, meshDiameter, diameter)
155
+ end
156
+
58
157
  --[=[
59
158
  Draws a ray for debugging.
60
159
 
@@ -73,7 +172,7 @@ end
73
172
  function Draw.ray(ray, color, parent, meshDiameter, diameter)
74
173
  assert(typeof(ray) == "Ray", "Bad typeof(ray) for Ray")
75
174
 
76
- color = color or Draw._defaultColor
175
+ color = Draw._toColor3(color) or Draw._defaultColor
77
176
  parent = parent or Draw.getDefaultParent()
78
177
  meshDiameter = meshDiameter or 0.2
79
178
  diameter = diameter or 0.2
@@ -150,7 +249,7 @@ end
150
249
  @param color Color3
151
250
  ]=]
152
251
  function Draw.updateRay(part, ray, color)
153
- color = color or part.Color
252
+ color = Draw._toColor3(color) or part.Color
154
253
 
155
254
  local diameter = part.Size.x
156
255
  local rayCenter = ray.Origin + ray.Direction/2
@@ -186,6 +285,8 @@ end
186
285
  @return Instance
187
286
  ]=]
188
287
  function Draw.text(adornee, text, color)
288
+ color = Draw._toColor3(color)
289
+
189
290
  if typeof(adornee) == "Vector3" then
190
291
  local attachment = Instance.new("Attachment")
191
292
  attachment.WorldPosition = adornee
@@ -309,13 +410,9 @@ end
309
410
  @return BasePart
310
411
  ]=]
311
412
  function Draw.point(position, color, parent, diameter)
312
- if typeof(position) == "CFrame" then
313
- position = position.Position
314
- end
315
-
316
- assert(typeof(position) == "Vector3", "Bad position")
413
+ position = assert(Draw._toVector3(position), "Bad position")
414
+ color = Draw._toColor3(color) or Draw._defaultColor
317
415
 
318
- color = color or Draw._defaultColor
319
416
  parent = parent or Draw.getDefaultParent()
320
417
  diameter = diameter or 1
321
418
 
@@ -364,9 +461,8 @@ end
364
461
  @return BasePart
365
462
  ]=]
366
463
  function Draw.labelledPoint(position, label, color, parent)
367
- if typeof(position) == "CFrame" then
368
- position = position.Position
369
- end
464
+ position = assert(Draw._toVector3(position), "Bad position")
465
+ color = Draw._toColor3(color)
370
466
 
371
467
  local part = Draw.point(position, color, parent)
372
468
 
@@ -386,6 +482,8 @@ end
386
482
  @return Model
387
483
  ]=]
388
484
  function Draw.cframe(cframe)
485
+ cframe = assert(Draw._toCFrame(cframe), "Bad cframe")
486
+
389
487
  local model = Instance.new("Model")
390
488
  model.Name = "DebugCFrame"
391
489
 
@@ -430,6 +528,8 @@ end
430
528
  ]=]
431
529
  function Draw.part(template, cframe, color, transparency)
432
530
  assert(typeof(template) == "Instance" and template:IsA("BasePart"), "Bad template")
531
+ cframe = Draw._toCFrame(cframe)
532
+ color = Draw._toColor3(color)
433
533
 
434
534
  local part = template:Clone()
435
535
  for _, child in pairs(part:GetChildren()) do
@@ -486,10 +586,14 @@ end
486
586
  @return BasePart
487
587
  ]=]
488
588
  function Draw.box(cframe, size, color)
589
+ cframe = assert(Draw._toCFrame(cframe), "Bad cframe")
590
+ size = assert(Draw._toVector3(size), "Bad size")
591
+ color = Draw._toColor3(color)
592
+
593
+ assert(typeof(cframe) == "CFrame", "Bad cframe")
489
594
  assert(typeof(size) == "Vector3", "Bad size")
490
595
 
491
596
  color = color or Draw._defaultColor
492
- cframe = typeof(cframe) == "Vector3" and CFrame.new(cframe) or cframe
493
597
 
494
598
  local part = Instance.new("Part")
495
599
  part.Color = color
@@ -533,6 +637,8 @@ end
533
637
  @return BasePart
534
638
  ]=]
535
639
  function Draw.region3(region3, color)
640
+ color = Draw._toColor3(color)
641
+
536
642
  return Draw.box(region3.CFrame, region3.Size, color)
537
643
  end
538
644
 
@@ -549,6 +655,9 @@ end
549
655
  @return BasePart
550
656
  ]=]
551
657
  function Draw.terrainCell(position, color)
658
+ position = assert(Draw._toVector3(position), "Bad position")
659
+ color = Draw._toColor3(color)
660
+
552
661
  local size = Vector3.new(4, 4, 4)
553
662
 
554
663
  local solidCell = Terrain:WorldToCell(position)
@@ -560,9 +669,9 @@ function Draw.terrainCell(position, color)
560
669
  return part
561
670
  end
562
671
 
563
-
564
-
565
672
  function Draw.screenPointLine(a, b, parent, color)
673
+ color = Draw._toColor3(color)
674
+
566
675
  local offset = (b - a)
567
676
  local pos = a + offset/2
568
677
 
@@ -601,6 +710,8 @@ function Draw.screenPointLine(a, b, parent, color)
601
710
  end
602
711
 
603
712
  function Draw.screenPoint(position, parent, color, diameter)
713
+ color = Draw._toColor3(color)
714
+
604
715
  local frame = Instance.new("Frame")
605
716
  frame.Name = "DebugScreenPoint"
606
717
  frame.Size = UDim2.new(0, diameter, 0, diameter)
@@ -634,6 +745,10 @@ end
634
745
  @return BasePart
635
746
  ]=]
636
747
  function Draw.vector(position, direction, color, parent, meshDiameter)
748
+ position = assert(Draw._toVector3(position), "Bad position")
749
+ direction = assert(Draw._toVector3(direction), "Bad direction")
750
+ color = Draw._toColor3(color)
751
+
637
752
  return Draw.ray(Ray.new(position, direction), color, parent, meshDiameter)
638
753
  end
639
754
 
@@ -652,6 +767,9 @@ end
652
767
  @return BasePart
653
768
  ]=]
654
769
  function Draw.ring(ringPos, ringNorm, ringRadius, color, parent)
770
+ ringPos = assert(Draw._toVector3(ringPos), "Bad ringPos")
771
+ ringNorm = assert(Draw._toVector3(ringNorm), "Bad ringNorm")
772
+
655
773
  local ringCFrame = CFrame.new(ringPos, ringPos + ringNorm)
656
774
 
657
775
  local points = {}
@@ -677,6 +795,62 @@ function Draw.ring(ringPos, ringNorm, ringRadius, color, parent)
677
795
  return folder
678
796
  end
679
797
 
798
+ function Draw._toVector3(position)
799
+ if typeof(position) == "Vector3" then
800
+ return position
801
+ elseif typeof(position) == "CFrame" then
802
+ return position.Position
803
+ elseif typeof(position) == "Instance" then
804
+ if position:IsA("Attachment") then
805
+ return position.WorldPosition
806
+ elseif position:IsA("BasePart") then
807
+ return position.Position
808
+ elseif position:IsA("Model") then
809
+ return position:GetBoundingBox().p
810
+ else
811
+ return nil
812
+ end
813
+ else
814
+ return nil
815
+ end
816
+ end
817
+
818
+ function Draw._toColor3(color)
819
+ if typeof(color) == "Color3" then
820
+ return color
821
+ elseif typeof(color) == "BrickColor" then
822
+ return color.Color
823
+ elseif typeof(color) == "Instance" then
824
+ if color:IsA("BasePart") then
825
+ return color.Color
826
+ else
827
+ return nil
828
+ end
829
+ else
830
+ return nil
831
+ end
832
+ end
833
+
834
+ function Draw._toCFrame(cframe)
835
+ if typeof(cframe) == "CFrame" then
836
+ return cframe
837
+ elseif typeof(cframe) == "Vector3" then
838
+ return CFrame.new(cframe)
839
+ elseif typeof(cframe) == "Instance" then
840
+ if cframe:IsA("Attachment") then
841
+ return cframe.WorldCFrame
842
+ elseif cframe:IsA("BasePart") then
843
+ return cframe.CFrame
844
+ elseif cframe:IsA("Model") then
845
+ return (cframe:GetBoundingBox())
846
+ else
847
+ return nil
848
+ end
849
+ else
850
+ return nil
851
+ end
852
+ end
853
+
680
854
  --[=[
681
855
  Retrieves the default parent for the current execution context.
682
856
  @return Instance