2023-11-08 14:28:55 +11:00
|
|
|
@tool
|
2024-02-22 06:22:22 +11:00
|
|
|
class_name DebugMesh extends MeshInstance3D
|
2023-11-08 14:28:55 +11:00
|
|
|
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
func _ready() -> void:
|
|
|
|
var mat: StandardMaterial3D = StandardMaterial3D.new()
|
2023-11-08 14:28:55 +11:00
|
|
|
mesh = ImmediateMesh.new()
|
|
|
|
mat.no_depth_test = true
|
|
|
|
mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
|
|
|
|
mat.vertex_color_use_as_albedo = true
|
|
|
|
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
|
|
|
|
set_material_override(mat)
|
|
|
|
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
func clear() -> void:
|
2023-11-08 14:28:55 +11:00
|
|
|
mesh.clear_surfaces()
|
|
|
|
|
|
|
|
|
|
|
|
func draw_line(begin_pos: Vector3, end_pos: Vector3, color: Color = Color.RED) -> void:
|
|
|
|
mesh.surface_begin(Mesh.PRIMITIVE_LINES)
|
|
|
|
mesh.surface_set_color(color)
|
|
|
|
mesh.surface_add_vertex(begin_pos)
|
|
|
|
mesh.surface_add_vertex(end_pos)
|
|
|
|
mesh.surface_end()
|
|
|
|
|
|
|
|
|
|
|
|
func draw_sphere(center: Vector3, radius: float = 1.0, color: Color = Color.RED) -> void:
|
|
|
|
var step: int = 30
|
|
|
|
var sppi: float = 2 * PI / step
|
2024-02-22 06:22:22 +11:00
|
|
|
var axes: Array = [
|
2023-11-08 14:28:55 +11:00
|
|
|
[Vector3.UP, Vector3.RIGHT],
|
|
|
|
[Vector3.RIGHT, Vector3.FORWARD],
|
|
|
|
[Vector3.FORWARD, Vector3.UP]
|
|
|
|
]
|
2024-02-22 06:22:22 +11:00
|
|
|
for axis: Array in axes:
|
2023-11-08 14:28:55 +11:00
|
|
|
mesh.surface_begin(Mesh.PRIMITIVE_LINE_STRIP)
|
|
|
|
mesh.surface_set_color(color)
|
2024-02-22 06:22:22 +11:00
|
|
|
for i: int in range(step + 1):
|
2023-11-08 14:28:55 +11:00
|
|
|
mesh.surface_add_vertex(center + (axis[0] * radius)
|
|
|
|
.rotated(axis[1], sppi * (i % step)))
|
|
|
|
mesh.surface_end()
|