-
Notifications
You must be signed in to change notification settings - Fork 2
/
debug_draw.gd
54 lines (46 loc) · 1.2 KB
/
debug_draw.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
45
46
47
48
49
50
51
52
53
54
tool
extends ImmediateGeometry
##
## @author: Pit Henrich
## @desc: A class for enabling in-editor debug drawing.
##
var material = SpatialMaterial.new()
var lines = []
class Line:
func _init(p0, p1, color):
self.p0 = p0
self.p1 = p1
self.color = color
var p0
var p1
var color
func draw_line(p0, p1, color : Color = Color(1,0,0,1)):
lines.push_back(Line.new(p0, p1, color))
func draw_line_world_space(object, p0, p1, color : Color = Color(1,0,0,1)):
lines.push_back(Line.new(p0 - object.get_global_transform().origin, p1 - object.get_global_transform().origin, color))
func _enter_tree():
if Engine.is_editor_hint():
set_process(true)
material.flags_use_point_size = true
material.vertex_color_use_as_albedo = true
material.flags_unshaded = true
material.flags_transparent = true
func _process(delta):
if Engine.is_editor_hint():
clear()
for l in lines:
if l.p0 == null or l.p1 == null:
continue
set_material_override(material)
# Draw points
#begin(Mesh.PRIMITIVE_POINTS, null)
#add_vertex(l.p0)
#add_vertex(l.p1)
#end()
# Draw lines
begin(Mesh.PRIMITIVE_LINE_STRIP, null)
set_color(l.color)
add_vertex(l.p0)
add_vertex(l.p1)
end()
lines.clear()