-
Notifications
You must be signed in to change notification settings - Fork 1
/
debug_geometry_test.tscn
164 lines (136 loc) · 6.15 KB
/
debug_geometry_test.tscn
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
[gd_scene load_steps=3 format=3 uid="uid://dvuoy133l3hsd"]
[sub_resource type="GDScript" id="GDScript_u5hqw"]
script/source = "extends Node3D
func _ready() -> void:
DisplayServer.mouse_set_mode(DisplayServer.MOUSE_MODE_CAPTURED)
draw_stuff()
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventKey:
if event.is_pressed():
if event.keycode == KEY_SPACE:
spawn_random_shape()
func draw_stuff() -> void:
DebugGeometry.draw_debug_cube(10, Vector3(-1, 1, -1), 0.9 * Vector3(1, 1, 1), Color(10, 10, 0))
var grid_pos = Vector3(5, 0, -5)
var grid_normal = Vector3(-0.2, 1.0, 0.9).normalized()
var grid_tangent = Vector3(-2.0, 0.8, 1.0).normalized()
DebugGeometry.draw_debug_line(10, grid_pos, grid_pos + grid_normal, 0, Color(0, 10, 0))
DebugGeometry.draw_debug_line(10, grid_pos, grid_pos + grid_tangent, 0, Color(0, 0, 10))
DebugGeometry.draw_debug_grid(10, grid_pos, 10, 5, 20, 10, grid_normal, grid_tangent, Color(5, 5, 5))
DebugGeometry.draw_debug_grid(10, Vector3(), 10, 10, 10, 10, Vector3.RIGHT, Vector3.BACK, Color(10, 0, 0))
DebugGeometry.draw_debug_grid(10, Vector3(), 10, 10, 10, 10, Vector3.UP, Vector3.RIGHT, Color(0, 10, 0))
DebugGeometry.draw_debug_grid(10, Vector3(), 10, 10, 10, 10, Vector3.BACK, Vector3.RIGHT, Color(0, 0, 10))
DebugGeometry.draw_debug_cylinder(10, Vector3(2, -2, 1), Vector3(3, -1, 2), 1.0, 32, true, Color(5, 0, 5))
DebugGeometry.draw_debug_cone(10, Vector3(-4, 1, 0), Vector3(-4, 2, -1), 0.2, 0.5, 16, true, Color(0, 2, 0), false)
DebugGeometry.draw_debug_sphere(10, Vector3(-2, -2, 2), 36, 18, 1.5, Color(0, 2, 2))
DebugGeometry.draw_debug_line(10, Vector3(2, 1, 0), Vector3(-2, 0, 3), 0.1, Color(0.7, 0.2, 0.1))
DebugGeometry.draw_debug_coordinate_system(10, Vector3.ZERO, Vector3(1, 0, 0), Vector3(0, 1, 0), 1, 10)
DebugGeometry.draw_debug_cylinder(10, Vector3(4, 0, -3), Vector3(2, 1, -4), 0.5, 16, true, Color(1, 1, 1), true)
DebugGeometry.draw_debug_cone(10, Vector3(-3, 1, 0), Vector3(-3, 2, -1), 0.5, 0.2, 16, true, Color(0, 2, 0), true)
DebugGeometry.draw_debug_arrow(10, Vector3(4, 2, 1), Vector3(1, -3, 2), 2, Color(3, 2, 1))
DebugGeometry.draw_debug_point(10, Vector3(2, 3, 1), 0.1, Color(0, 0, 0))
DebugGeometry.draw_debug_coordinate_system(10, Vector3(-4, 0, -3), Vector3(3, 2, 1), Vector3(1, 1, 1), 0.5, 10)
func spawn_random_shape() -> void:
var random_shape := randi() % 9
var random_time := randf() * 4 + 1
match random_shape:
0:
DebugGeometry.draw_debug_cube(
random_time,
Vector3(randf() * 10 - 5, randf() * 10 - 5, randf() * 10 - 5),
Vector3(randf() * 2, randf() * 2, randf() * 2),
Color(randf(), randf(), randf()),
true if randf() > 0.5 else false)
1:
DebugGeometry.draw_debug_sphere(
random_time,
Vector3(randf() * 10 - 5, randf() * 10 - 5, randf() * 10 - 5),
16, 8, randf() * 2,
Color(randf(), randf(), randf()),
true if randf() > 0.5 else false)
2:
DebugGeometry.draw_debug_cylinder(
random_time,
Vector3(randf() * 10 - 5, randf() * 10 - 5, randf() * 10 - 5),
Vector3(randf() * 10 - 5, randf() * 10 - 5, randf() * 10 - 5),
randf() * 2, 16, true if randf() > 0.5 else false,
Color(randf(), randf(), randf()),
true if randf() > 0.5 else false)
3:
DebugGeometry.draw_debug_cone(
random_time,
Vector3(randf() * 10 - 5, randf() * 10 - 5, randf() * 10 - 5),
Vector3(randf() * 10 - 5, randf() * 10 - 5, randf() * 10 - 5),
randf() * 2, randf() * 2, 16, true if randf() > 0.5 else false,
Color(randf(), randf(), randf()),
true if randf() > 0.5 else false)
4:
DebugGeometry.draw_debug_arrow(
random_time,
Vector3(randf() * 10 - 5, randf() * 10 - 5, randf() * 10 - 5),
Vector3(randf() * 2 - 1, randf() * 2 - 1, randf() * 2 - 1).normalized(),
randf() * 3,
Color(randf(), randf(), randf()),
true if randf() > 0.5 else false)
5:
DebugGeometry.draw_debug_coordinate_system(
random_time,
Vector3(randf() * 10 - 5, randf() * 10 - 5, randf() * 10 - 5),
Vector3(randf() * 2 - 1, randf() * 2 - 1, randf() * 2 - 1).normalized(),
Vector3(randf() * 2 - 1, randf() * 2 - 1, randf() * 2 - 1).normalized(),
randf() * 2, randf(),
true if randf() > 0.5 else false)
6:
DebugGeometry.draw_debug_grid(
random_time,
Vector3(randf() * 10 - 5, randf() * 10 - 5, randf() * 10 - 5),
randf() * 5, randf() * 5, randi() % 5, randi() % 5,
Vector3(randf() * 2 - 1, randf() * 2 - 1, randf() * 2 - 1).normalized(),
Vector3(randf() * 2 - 1, randf() * 2 - 1, randf() * 2 - 1).normalized(),
Color(randf(), randf(), randf()))
7:
DebugGeometry.draw_debug_line(
random_time,
Vector3(randf() * 10 - 5, randf() * 10 - 5, randf() * 10 - 5),
Vector3(randf() * 10 - 5, randf() * 10 - 5, randf() * 10 - 5),
randf(),
Color(randf(), randf(), randf()))
8:
DebugGeometry.draw_debug_point(
random_time,
Vector3(randf() * 10 - 5, randf() * 10 - 5, randf() * 10 - 5),
randf(),
Color(randf(), randf(), randf()))
"
[sub_resource type="GDScript" id="GDScript_8htyx"]
script/source = "extends Node3D
@onready var camera := $Node3D/Camera3D as Camera3D
@onready var helper := $Node3D as Node3D
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouse:
if event is InputEventMouseMotion:
rotate_camera(event.relative)
elif event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
translate_camera(1.0)
elif event.button_index == MOUSE_BUTTON_WHEEL_UP:
translate_camera(-1.0)
func rotate_camera(delta: Vector2) -> void:
delta *= 0.001
helper.rotate_object_local(Vector3.RIGHT, delta.y)
rotate_y(delta.x)
func translate_camera(delta: float) -> void:
camera.translate_object_local(Vector3(0, 0, delta))
"
[node name="Node3D" type="Node3D"]
script = SubResource("GDScript_u5hqw")
[node name="Node3D" type="Node3D" parent="."]
script = SubResource("GDScript_8htyx")
[node name="Node3D" type="Node3D" parent="Node3D"]
[node name="Camera3D" type="Camera3D" parent="Node3D/Node3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 5)
[node name="Label" type="Label" parent="."]
offset_right = 40.0
offset_bottom = 23.0
text = "
Press Space to add random shapes"