summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-07-29 08:07:13 +0200
committerGitHub <noreply@github.com>2022-07-29 08:07:13 +0200
commit7c93373008d29ed2df3c301ef8006258b0dec49c (patch)
tree437fbd488b03e98d687a69f745f8edfccb03d08d /editor
parent2bf8c4a6d0c553d450695d1988fac39df638ad9a (diff)
parent8cbb9b8b0abcb97c99c274aa6ce83f09c4c97ab2 (diff)
Merge pull request #63161 from PrecisionRender/master
Add `ShapeCast3D` node
Diffstat (limited to 'editor')
-rw-r--r--editor/icons/ShapeCast3D.svg1
-rw-r--r--editor/plugins/node_3d_editor_gizmos.cpp36
-rw-r--r--editor/plugins/node_3d_editor_gizmos.h12
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp1
4 files changed, 50 insertions, 0 deletions
diff --git a/editor/icons/ShapeCast3D.svg b/editor/icons/ShapeCast3D.svg
new file mode 100644
index 0000000000..c9f24a59b4
--- /dev/null
+++ b/editor/icons/ShapeCast3D.svg
@@ -0,0 +1 @@
+<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g fill="#fc7f7f"><path d="m7 1v9h-3l4 5 4-5h-3v-9z"/><circle cx="7.990566" cy="4.8202" r="4.009434"/></g></svg>
diff --git a/editor/plugins/node_3d_editor_gizmos.cpp b/editor/plugins/node_3d_editor_gizmos.cpp
index 1ac986ed36..f7a2915ea2 100644
--- a/editor/plugins/node_3d_editor_gizmos.cpp
+++ b/editor/plugins/node_3d_editor_gizmos.cpp
@@ -57,6 +57,7 @@
#include "scene/3d/position_3d.h"
#include "scene/3d/ray_cast_3d.h"
#include "scene/3d/reflection_probe.h"
+#include "scene/3d/shape_cast_3d.h"
#include "scene/3d/soft_dynamic_body_3d.h"
#include "scene/3d/spring_arm_3d.h"
#include "scene/3d/sprite_3d.h"
@@ -2540,6 +2541,41 @@ void RayCast3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
/////
+ShapeCast3DGizmoPlugin::ShapeCast3DGizmoPlugin() {
+ const Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/shape");
+ create_material("shape_material", gizmo_color);
+ const float gizmo_value = gizmo_color.get_v();
+ const Color gizmo_color_disabled = Color(gizmo_value, gizmo_value, gizmo_value, 0.65);
+ create_material("shape_material_disabled", gizmo_color_disabled);
+}
+
+bool ShapeCast3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
+ return Object::cast_to<ShapeCast3D>(p_spatial) != nullptr;
+}
+
+String ShapeCast3DGizmoPlugin::get_gizmo_name() const {
+ return "ShapeCast3D";
+}
+
+int ShapeCast3DGizmoPlugin::get_priority() const {
+ return -1;
+}
+
+void ShapeCast3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
+ ShapeCast3D *shapecast = Object::cast_to<ShapeCast3D>(p_gizmo->get_spatial_node());
+
+ p_gizmo->clear();
+
+ const Ref<StandardMaterial3D> material = shapecast->is_enabled() ? shapecast->get_debug_material() : get_material("shape_material_disabled");
+
+ p_gizmo->add_lines(shapecast->get_debug_shape_vertices(), material);
+ p_gizmo->add_lines(shapecast->get_debug_line_vertices(), material);
+
+ p_gizmo->add_collision_segments(shapecast->get_debug_line_vertices());
+}
+
+/////
+
void SpringArm3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
SpringArm3D *spring_arm = Object::cast_to<SpringArm3D>(p_gizmo->get_spatial_node());
diff --git a/editor/plugins/node_3d_editor_gizmos.h b/editor/plugins/node_3d_editor_gizmos.h
index a0d7715347..739bf1b929 100644
--- a/editor/plugins/node_3d_editor_gizmos.h
+++ b/editor/plugins/node_3d_editor_gizmos.h
@@ -373,6 +373,18 @@ public:
RayCast3DGizmoPlugin();
};
+class ShapeCast3DGizmoPlugin : public EditorNode3DGizmoPlugin {
+ GDCLASS(ShapeCast3DGizmoPlugin, EditorNode3DGizmoPlugin);
+
+public:
+ bool has_gizmo(Node3D *p_spatial) override;
+ String get_gizmo_name() const override;
+ int get_priority() const override;
+ void redraw(EditorNode3DGizmo *p_gizmo) override;
+
+ ShapeCast3DGizmoPlugin();
+};
+
class SpringArm3DGizmoPlugin : public EditorNode3DGizmoPlugin {
GDCLASS(SpringArm3DGizmoPlugin, EditorNode3DGizmoPlugin);
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index ffc60f9664..48f1a7c44e 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -7497,6 +7497,7 @@ void Node3DEditor::_register_all_gizmos() {
add_gizmo_plugin(Ref<Label3DGizmoPlugin>(memnew(Label3DGizmoPlugin)));
add_gizmo_plugin(Ref<Position3DGizmoPlugin>(memnew(Position3DGizmoPlugin)));
add_gizmo_plugin(Ref<RayCast3DGizmoPlugin>(memnew(RayCast3DGizmoPlugin)));
+ add_gizmo_plugin(Ref<ShapeCast3DGizmoPlugin>(memnew(ShapeCast3DGizmoPlugin)));
add_gizmo_plugin(Ref<SpringArm3DGizmoPlugin>(memnew(SpringArm3DGizmoPlugin)));
add_gizmo_plugin(Ref<VehicleWheel3DGizmoPlugin>(memnew(VehicleWheel3DGizmoPlugin)));
add_gizmo_plugin(Ref<VisibleOnScreenNotifier3DGizmoPlugin>(memnew(VisibleOnScreenNotifier3DGizmoPlugin)));