-
Notifications
You must be signed in to change notification settings - Fork 5
/
DebugDraw3D.gd
44 lines (31 loc) · 1.08 KB
/
DebugDraw3D.gd
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
# This is used to draw vectors in 3D
#Source : https://kidscancode.org/godot_recipes/3d/debug_overlay/
extends Control
class Vector:
var object # The node to follow
var property # The property to draw
var scale # Scale factor
var width # Line width
var color # Draw color
func _init(_object, _property, _scale, _width, _color):
object = _object
property = _property
scale = _scale
width = _width
color = _color
func draw(node, camera):
var start = camera.unproject_position(object.global_transform.origin)
var end = camera.unproject_position(object.global_transform.origin + object.get(property) * scale)
node.draw_line(start, end, color, width)
# node.draw_triangle(end, start.direction_to(end), width*2, color)
var vectors = [] # Array to hold all registered values.
func _process(delta):
if not visible:
return
update()
func _draw():
var camera = get_viewport().get_camera()
for vector in vectors:
vector.draw(self, camera)
func add_vector(object, property, scale, width, color):
vectors.append(Vector.new(object, property, scale, width, color))