@quenty/draw 4.2.0 → 4.2.1-canary.405.6fa018e.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,17 @@
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.405.6fa018e.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/draw@4.2.0...@quenty/draw@4.2.1-canary.405.6fa018e.0) (2023-08-14)
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
+
13
+
14
+
15
+
16
+
6
17
  # [4.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/draw@4.1.1...@quenty/draw@4.2.0) (2022-10-11)
7
18
 
8
19
 
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.405.6fa018e.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": "6fa018eb1f165230fe1eb0417d8d6951010e4971"
32
32
  }
@@ -55,6 +55,86 @@ 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 start 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(start, direction, color, parent, meshDiameter, diameter)
89
+ start = assert(Draw._toVector3(start), "Bad start")
90
+ direction = assert(Draw._toVector3(direction), "Bad direction")
91
+ color = Draw._toColor3(color)
92
+
93
+ return Draw.ray(Ray.new(start, 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
+
58
138
  --[=[
59
139
  Draws a ray for debugging.
60
140
 
@@ -73,7 +153,7 @@ end
73
153
  function Draw.ray(ray, color, parent, meshDiameter, diameter)
74
154
  assert(typeof(ray) == "Ray", "Bad typeof(ray) for Ray")
75
155
 
76
- color = color or Draw._defaultColor
156
+ color = Draw._toColor3(color) or Draw._defaultColor
77
157
  parent = parent or Draw.getDefaultParent()
78
158
  meshDiameter = meshDiameter or 0.2
79
159
  diameter = diameter or 0.2
@@ -150,7 +230,7 @@ end
150
230
  @param color Color3
151
231
  ]=]
152
232
  function Draw.updateRay(part, ray, color)
153
- color = color or part.Color
233
+ color = Draw._toColor3(color) or part.Color
154
234
 
155
235
  local diameter = part.Size.x
156
236
  local rayCenter = ray.Origin + ray.Direction/2
@@ -186,6 +266,8 @@ end
186
266
  @return Instance
187
267
  ]=]
188
268
  function Draw.text(adornee, text, color)
269
+ color = Draw._toColor3(color)
270
+
189
271
  if typeof(adornee) == "Vector3" then
190
272
  local attachment = Instance.new("Attachment")
191
273
  attachment.WorldPosition = adornee
@@ -309,13 +391,9 @@ end
309
391
  @return BasePart
310
392
  ]=]
311
393
  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")
394
+ position = assert(Draw._toVector3(position), "Bad position")
395
+ color = Draw._toColor3(color) or Draw._defaultColor
317
396
 
318
- color = color or Draw._defaultColor
319
397
  parent = parent or Draw.getDefaultParent()
320
398
  diameter = diameter or 1
321
399
 
@@ -364,9 +442,8 @@ end
364
442
  @return BasePart
365
443
  ]=]
366
444
  function Draw.labelledPoint(position, label, color, parent)
367
- if typeof(position) == "CFrame" then
368
- position = position.Position
369
- end
445
+ position = assert(Draw._toVector3(position), "Bad position")
446
+ color = Draw._toColor3(color)
370
447
 
371
448
  local part = Draw.point(position, color, parent)
372
449
 
@@ -386,6 +463,8 @@ end
386
463
  @return Model
387
464
  ]=]
388
465
  function Draw.cframe(cframe)
466
+ cframe = assert(Draw._toCFrame(cframe), "Bad cframe")
467
+
389
468
  local model = Instance.new("Model")
390
469
  model.Name = "DebugCFrame"
391
470
 
@@ -430,6 +509,8 @@ end
430
509
  ]=]
431
510
  function Draw.part(template, cframe, color, transparency)
432
511
  assert(typeof(template) == "Instance" and template:IsA("BasePart"), "Bad template")
512
+ cframe = Draw._toCFrame(cframe)
513
+ color = Draw._toColor3(color)
433
514
 
434
515
  local part = template:Clone()
435
516
  for _, child in pairs(part:GetChildren()) do
@@ -486,10 +567,14 @@ end
486
567
  @return BasePart
487
568
  ]=]
488
569
  function Draw.box(cframe, size, color)
570
+ cframe = assert(Draw._toCFrame(cframe), "Bad cframe")
571
+ size = assert(Draw._toVector3(size), "Bad size")
572
+ color = Draw._toColor3(color)
573
+
574
+ assert(typeof(cframe) == "CFrame", "Bad cframe")
489
575
  assert(typeof(size) == "Vector3", "Bad size")
490
576
 
491
577
  color = color or Draw._defaultColor
492
- cframe = typeof(cframe) == "Vector3" and CFrame.new(cframe) or cframe
493
578
 
494
579
  local part = Instance.new("Part")
495
580
  part.Color = color
@@ -533,6 +618,8 @@ end
533
618
  @return BasePart
534
619
  ]=]
535
620
  function Draw.region3(region3, color)
621
+ color = Draw._toColor3(color)
622
+
536
623
  return Draw.box(region3.CFrame, region3.Size, color)
537
624
  end
538
625
 
@@ -549,6 +636,9 @@ end
549
636
  @return BasePart
550
637
  ]=]
551
638
  function Draw.terrainCell(position, color)
639
+ position = assert(Draw._toVector3(position), "Bad position")
640
+ color = Draw._toColor3(color)
641
+
552
642
  local size = Vector3.new(4, 4, 4)
553
643
 
554
644
  local solidCell = Terrain:WorldToCell(position)
@@ -560,9 +650,9 @@ function Draw.terrainCell(position, color)
560
650
  return part
561
651
  end
562
652
 
563
-
564
-
565
653
  function Draw.screenPointLine(a, b, parent, color)
654
+ color = Draw._toColor3(color)
655
+
566
656
  local offset = (b - a)
567
657
  local pos = a + offset/2
568
658
 
@@ -601,6 +691,8 @@ function Draw.screenPointLine(a, b, parent, color)
601
691
  end
602
692
 
603
693
  function Draw.screenPoint(position, parent, color, diameter)
694
+ color = Draw._toColor3(color)
695
+
604
696
  local frame = Instance.new("Frame")
605
697
  frame.Name = "DebugScreenPoint"
606
698
  frame.Size = UDim2.new(0, diameter, 0, diameter)
@@ -634,6 +726,10 @@ end
634
726
  @return BasePart
635
727
  ]=]
636
728
  function Draw.vector(position, direction, color, parent, meshDiameter)
729
+ position = assert(Draw._toVector3(position), "Bad position")
730
+ direction = assert(Draw._toVector3(direction), "Bad direction")
731
+ color = Draw._toColor3(color)
732
+
637
733
  return Draw.ray(Ray.new(position, direction), color, parent, meshDiameter)
638
734
  end
639
735
 
@@ -652,6 +748,9 @@ end
652
748
  @return BasePart
653
749
  ]=]
654
750
  function Draw.ring(ringPos, ringNorm, ringRadius, color, parent)
751
+ ringPos = assert(Draw._toVector3(ringPos), "Bad ringPos")
752
+ ringNorm = assert(Draw._toVector3(ringNorm), "Bad ringNorm")
753
+
655
754
  local ringCFrame = CFrame.new(ringPos, ringPos + ringNorm)
656
755
 
657
756
  local points = {}
@@ -677,6 +776,62 @@ function Draw.ring(ringPos, ringNorm, ringRadius, color, parent)
677
776
  return folder
678
777
  end
679
778
 
779
+ function Draw._toVector3(position)
780
+ if typeof(position) == "Vector3" then
781
+ return position
782
+ elseif typeof(position) == "CFrame" then
783
+ return position.Position
784
+ elseif typeof(position) == "Instance" then
785
+ if position:IsA("Attachment") then
786
+ return position.WorldPosition
787
+ elseif position:IsA("BasePart") then
788
+ return position.Position
789
+ elseif position:IsA("Model") then
790
+ return position:GetBoundingBox().p
791
+ else
792
+ return nil
793
+ end
794
+ else
795
+ return nil
796
+ end
797
+ end
798
+
799
+ function Draw._toColor3(color)
800
+ if typeof(color) == "Color3" then
801
+ return color
802
+ elseif typeof(color) == "BrickColor" then
803
+ return color.Color
804
+ elseif typeof(color) == "Instance" then
805
+ if color:IsA("BasePart") then
806
+ return color.Color
807
+ else
808
+ return nil
809
+ end
810
+ else
811
+ return nil
812
+ end
813
+ end
814
+
815
+ function Draw._toCFrame(cframe)
816
+ if typeof(cframe) == "CFrame" then
817
+ return cframe
818
+ elseif typeof(cframe) == "Vector3" then
819
+ return CFrame.new(cframe)
820
+ elseif typeof(cframe) == "Instance" then
821
+ if cframe:IsA("Attachment") then
822
+ return cframe.WorldCFrame
823
+ elseif cframe:IsA("BasePart") then
824
+ return cframe.CFrame
825
+ elseif cframe:IsA("Model") then
826
+ return (cframe:GetBoundingBox())
827
+ else
828
+ return nil
829
+ end
830
+ else
831
+ return nil
832
+ end
833
+ end
834
+
680
835
  --[=[
681
836
  Retrieves the default parent for the current execution context.
682
837
  @return Instance