mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Add custom debug shape thickness and color options to RayCast
This backports the improved RayCast debug drawing functionality from the `master` branch. `ArrayMesh.clear_surfaces()` was also backported from the `master` branch and exposed because the new debug drawing code requires it.
This commit is contained in:
parent
2827d6be19
commit
a6a6ad5c08
8 changed files with 236 additions and 40 deletions
|
@ -245,6 +245,58 @@ void EditorSpatialGizmo::add_lines(const Vector<Vector3> &p_lines, const Ref<Mat
|
|||
instances.push_back(ins);
|
||||
}
|
||||
|
||||
void EditorSpatialGizmo::add_vertices(const Vector<Vector3> &p_vertices, const Ref<Material> &p_material, Mesh::PrimitiveType p_primitive_type, bool p_billboard, const Color &p_modulate) {
|
||||
if (p_vertices.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ERR_FAIL_COND(!spatial_node);
|
||||
Instance ins;
|
||||
|
||||
Ref<ArrayMesh> mesh = memnew(ArrayMesh);
|
||||
Array a;
|
||||
a.resize(Mesh::ARRAY_MAX);
|
||||
|
||||
a[Mesh::ARRAY_VERTEX] = p_vertices;
|
||||
|
||||
PoolVector<Color> color;
|
||||
color.resize(p_vertices.size());
|
||||
{
|
||||
PoolVector<Color>::Write w = color.write();
|
||||
for (int i = 0; i < p_vertices.size(); i++) {
|
||||
if (is_selected()) {
|
||||
w[i] = Color(1, 1, 1, 0.8) * p_modulate;
|
||||
} else {
|
||||
w[i] = Color(1, 1, 1, 0.2) * p_modulate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
a[Mesh::ARRAY_COLOR] = color;
|
||||
|
||||
mesh->add_surface_from_arrays(p_primitive_type, a);
|
||||
mesh->surface_set_material(0, p_material);
|
||||
|
||||
if (p_billboard) {
|
||||
float md = 0;
|
||||
for (int i = 0; i < p_vertices.size(); i++) {
|
||||
md = MAX(0, p_vertices[i].length());
|
||||
}
|
||||
if (md) {
|
||||
mesh->set_custom_aabb(AABB(Vector3(-md, -md, -md), Vector3(md, md, md) * 2.0));
|
||||
}
|
||||
}
|
||||
|
||||
ins.billboard = p_billboard;
|
||||
ins.mesh = mesh;
|
||||
if (valid) {
|
||||
ins.create_instance(spatial_node, hidden);
|
||||
VS::get_singleton()->instance_set_transform(ins.instance, spatial_node->get_global_transform());
|
||||
}
|
||||
|
||||
instances.push_back(ins);
|
||||
}
|
||||
|
||||
void EditorSpatialGizmo::add_unscaled_billboard(const Ref<Material> &p_material, float p_scale, const Color &p_modulate) {
|
||||
ERR_FAIL_COND(!spatial_node);
|
||||
Instance ins;
|
||||
|
@ -1848,16 +1900,15 @@ void RayCastSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
|
|||
|
||||
p_gizmo->clear();
|
||||
|
||||
Vector<Vector3> lines;
|
||||
const Ref<SpatialMaterial> material = raycast->is_enabled() ? raycast->get_debug_material() : get_material("shape_material_disabled");
|
||||
|
||||
lines.push_back(Vector3());
|
||||
lines.push_back(raycast->get_cast_to());
|
||||
p_gizmo->add_lines(raycast->get_debug_line_vertices(), material);
|
||||
|
||||
const Ref<SpatialMaterial> material =
|
||||
get_material(raycast->is_enabled() ? "shape_material" : "shape_material_disabled", p_gizmo);
|
||||
if (raycast->get_debug_shape_thickness() > 1) {
|
||||
p_gizmo->add_vertices(raycast->get_debug_shape_vertices(), material, Mesh::PRIMITIVE_TRIANGLE_STRIP);
|
||||
}
|
||||
|
||||
p_gizmo->add_lines(lines, material);
|
||||
p_gizmo->add_collision_segments(lines);
|
||||
p_gizmo->add_collision_segments(raycast->get_debug_line_vertices());
|
||||
}
|
||||
|
||||
/////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue