summaryrefslogtreecommitdiffstats
path: root/editor/plugins/gizmos
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugins/gizmos')
-rw-r--r--editor/plugins/gizmos/camera_3d_gizmo_plugin.cpp20
-rw-r--r--editor/plugins/gizmos/camera_3d_gizmo_plugin.h1
-rw-r--r--editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.cpp75
-rw-r--r--editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.h2
4 files changed, 61 insertions, 37 deletions
diff --git a/editor/plugins/gizmos/camera_3d_gizmo_plugin.cpp b/editor/plugins/gizmos/camera_3d_gizmo_plugin.cpp
index 13fc56921d..8e16fc68d8 100644
--- a/editor/plugins/gizmos/camera_3d_gizmo_plugin.cpp
+++ b/editor/plugins/gizmos/camera_3d_gizmo_plugin.cpp
@@ -48,24 +48,6 @@ Camera3DGizmoPlugin::Camera3DGizmoPlugin() {
create_handle_material("handles");
}
-Size2i Camera3DGizmoPlugin::_get_viewport_size(Camera3D *p_camera) {
- Viewport *viewport = p_camera->get_viewport();
-
- Window *window = Object::cast_to<Window>(viewport);
- if (window) {
- return window->get_size();
- }
-
- SubViewport *sub_viewport = Object::cast_to<SubViewport>(viewport);
- ERR_FAIL_NULL_V(sub_viewport, Size2i());
-
- if (sub_viewport == EditorNode::get_singleton()->get_scene_root()) {
- return Size2(GLOBAL_GET("display/window/size/viewport_width"), GLOBAL_GET("display/window/size/viewport_height"));
- }
-
- return sub_viewport->get_size();
-}
-
bool Camera3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
return Object::cast_to<Camera3D>(p_spatial) != nullptr;
}
@@ -168,7 +150,7 @@ void Camera3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
Ref<Material> material = get_material("camera_material", p_gizmo);
Ref<Material> icon = get_material("camera_icon", p_gizmo);
- const Size2i viewport_size = _get_viewport_size(camera);
+ const Size2i viewport_size = Node3DEditor::get_camera_viewport_size(camera);
const real_t viewport_aspect = viewport_size.x > 0 && viewport_size.y > 0 ? viewport_size.aspect() : 1.0;
const Size2 size_factor = viewport_aspect > 1.0 ? Size2(1.0, 1.0 / viewport_aspect) : Size2(viewport_aspect, 1.0);
diff --git a/editor/plugins/gizmos/camera_3d_gizmo_plugin.h b/editor/plugins/gizmos/camera_3d_gizmo_plugin.h
index 63e573907b..9a591d4d06 100644
--- a/editor/plugins/gizmos/camera_3d_gizmo_plugin.h
+++ b/editor/plugins/gizmos/camera_3d_gizmo_plugin.h
@@ -39,7 +39,6 @@ class Camera3DGizmoPlugin : public EditorNode3DGizmoPlugin {
GDCLASS(Camera3DGizmoPlugin, EditorNode3DGizmoPlugin);
private:
- static Size2i _get_viewport_size(Camera3D *p_camera);
static float _find_closest_angle_to_half_pi_arc(const Vector3 &p_from, const Vector3 &p_to, float p_arc_radius, const Transform3D &p_arc_xform);
public:
diff --git a/editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.cpp b/editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.cpp
index 2c852c718b..bfe31d7811 100644
--- a/editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.cpp
+++ b/editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.cpp
@@ -51,17 +51,47 @@
CollisionShape3DGizmoPlugin::CollisionShape3DGizmoPlugin() {
helper.instantiate();
- const Color gizmo_color = SceneTree::get_singleton()->get_debug_collisions_color();
- 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);
+
+ create_collision_material("shape_material", 2.0);
+ create_collision_material("shape_material_arraymesh", 0.0625);
+
+ create_collision_material("shape_material_disabled", 0.0625);
+ create_collision_material("shape_material_arraymesh_disabled", 0.015625);
+
create_handle_material("handles");
}
CollisionShape3DGizmoPlugin::~CollisionShape3DGizmoPlugin() {
}
+void CollisionShape3DGizmoPlugin::create_collision_material(const String &p_name, float p_alpha) {
+ Vector<Ref<StandardMaterial3D>> mats;
+
+ const Color collision_color(1.0, 1.0, 1.0, p_alpha);
+
+ for (int i = 0; i < 4; i++) {
+ bool instantiated = i < 2;
+
+ Ref<StandardMaterial3D> material = memnew(StandardMaterial3D);
+
+ Color color = collision_color;
+ color.a *= instantiated ? 0.25 : 1.0;
+
+ material->set_albedo(color);
+ material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
+ material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
+ material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 1);
+ material->set_cull_mode(StandardMaterial3D::CULL_BACK);
+ material->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
+ material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
+ material->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);
+
+ mats.push_back(material);
+ }
+
+ materials[p_name] = mats;
+}
+
bool CollisionShape3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
return Object::cast_to<CollisionShape3D>(p_spatial) != nullptr;
}
@@ -313,9 +343,20 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
return;
}
- const Ref<Material> material =
+ const Ref<StandardMaterial3D> material =
get_material(!cs->is_disabled() ? "shape_material" : "shape_material_disabled", p_gizmo);
- Ref<Material> handles_material = get_material("handles");
+ const Ref<StandardMaterial3D> material_arraymesh =
+ get_material(!cs->is_disabled() ? "shape_material_arraymesh" : "shape_material_arraymesh_disabled", p_gizmo);
+ const Ref<Material> handles_material = get_material("handles");
+
+ const Color collision_color = cs->is_disabled() ? Color(1.0, 1.0, 1.0, 0.75) : cs->get_debug_color();
+
+ if (cs->get_debug_fill_enabled()) {
+ Ref<ArrayMesh> array_mesh = s->get_debug_arraymesh_faces(collision_color);
+ if (array_mesh.is_valid()) {
+ p_gizmo->add_mesh(array_mesh, material_arraymesh);
+ }
+ }
if (Object::cast_to<SphereShape3D>(*s)) {
Ref<SphereShape3D> sp = s;
@@ -353,7 +394,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
collision_segments.push_back(Vector3(b.x, b.y, 0));
}
- p_gizmo->add_lines(points, material);
+ p_gizmo->add_lines(points, material, false, collision_color);
p_gizmo->add_collision_segments(collision_segments);
Vector<Vector3> handles;
handles.push_back(Vector3(r, 0, 0));
@@ -376,7 +417,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
const Vector<Vector3> handles = helper->box_get_handles(bs->get_size());
- p_gizmo->add_lines(lines, material);
+ p_gizmo->add_lines(lines, material, false, collision_color);
p_gizmo->add_collision_segments(lines);
p_gizmo->add_handles(handles, handles_material);
}
@@ -414,7 +455,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
points.push_back(Vector3(b.y, b.x, 0) + dud);
}
- p_gizmo->add_lines(points, material);
+ p_gizmo->add_lines(points, material, false, collision_color);
Vector<Vector3> collision_segments;
@@ -478,7 +519,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
}
}
- p_gizmo->add_lines(points, material);
+ p_gizmo->add_lines(points, material, false, collision_color);
Vector<Vector3> collision_segments;
@@ -533,7 +574,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
p.normal * p.d + p.normal * 3
};
- p_gizmo->add_lines(points, material);
+ p_gizmo->add_lines(points, material, false, collision_color);
p_gizmo->add_collision_segments(points);
}
@@ -551,7 +592,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
lines.write[i * 2 + 0] = md.vertices[md.edges[i].vertex_a];
lines.write[i * 2 + 1] = md.vertices[md.edges[i].vertex_b];
}
- p_gizmo->add_lines(lines, material);
+ p_gizmo->add_lines(lines, material, false, collision_color);
p_gizmo->add_collision_segments(lines);
}
}
@@ -560,7 +601,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
if (Object::cast_to<ConcavePolygonShape3D>(*s)) {
Ref<ConcavePolygonShape3D> cs2 = s;
Ref<ArrayMesh> mesh = cs2->get_debug_mesh();
- p_gizmo->add_mesh(mesh, material);
+ p_gizmo->add_lines(cs2->get_debug_mesh_lines(), material, false, collision_color);
p_gizmo->add_collision_segments(cs2->get_debug_mesh_lines());
}
@@ -571,7 +612,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
Vector3(),
Vector3(0, 0, rs->get_length())
};
- p_gizmo->add_lines(points, material);
+ p_gizmo->add_lines(points, material, false, collision_color);
p_gizmo->add_collision_segments(points);
Vector<Vector3> handles;
handles.push_back(Vector3(0, 0, rs->get_length()));
@@ -581,7 +622,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
if (Object::cast_to<HeightMapShape3D>(*s)) {
Ref<HeightMapShape3D> hms = s;
- Ref<ArrayMesh> mesh = hms->get_debug_mesh();
- p_gizmo->add_mesh(mesh, material);
+ Vector<Vector3> lines = hms->get_debug_mesh_lines();
+ p_gizmo->add_lines(lines, material, false, collision_color);
}
}
diff --git a/editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.h b/editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.h
index 0b6cd9164a..46af8f14fe 100644
--- a/editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.h
+++ b/editor/plugins/gizmos/collision_shape_3d_gizmo_plugin.h
@@ -40,6 +40,8 @@ class Gizmo3DHelper;
class CollisionShape3DGizmoPlugin : public EditorNode3DGizmoPlugin {
GDCLASS(CollisionShape3DGizmoPlugin, EditorNode3DGizmoPlugin);
+ void create_collision_material(const String &p_name, float p_alpha);
+
Ref<Gizmo3DHelper> helper;
public: