diff options
Diffstat (limited to 'editor/spatial_editor_gizmos.cpp')
-rw-r--r-- | editor/spatial_editor_gizmos.cpp | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp index 999353df8d..29b6c12b23 100644 --- a/editor/spatial_editor_gizmos.cpp +++ b/editor/spatial_editor_gizmos.cpp @@ -201,7 +201,7 @@ void EditorSpatialGizmo::add_mesh(const Ref<ArrayMesh> &p_mesh, bool p_billboard instances.push_back(ins); } -void EditorSpatialGizmo::add_lines(const Vector<Vector3> &p_lines, const Ref<Material> &p_material, bool p_billboard) { +void EditorSpatialGizmo::add_lines(const Vector<Vector3> &p_lines, const Ref<Material> &p_material, bool p_billboard, const Color &p_modulate) { if (p_lines.empty()) { return; } @@ -221,9 +221,9 @@ void EditorSpatialGizmo::add_lines(const Vector<Vector3> &p_lines, const Ref<Mat PoolVector<Color>::Write w = color.write(); for (int i = 0; i < p_lines.size(); i++) { if (is_selected()) - w[i] = Color(1, 1, 1, 0.8); + w[i] = Color(1, 1, 1, 0.8) * p_modulate; else - w[i] = Color(1, 1, 1, 0.2); + w[i] = Color(1, 1, 1, 0.2) * p_modulate; } } @@ -253,13 +253,14 @@ void EditorSpatialGizmo::add_lines(const Vector<Vector3> &p_lines, const Ref<Mat instances.push_back(ins); } -void EditorSpatialGizmo::add_unscaled_billboard(const Ref<Material> &p_material, float p_scale) { +void EditorSpatialGizmo::add_unscaled_billboard(const Ref<Material> &p_material, float p_scale, const Color &p_modulate) { ERR_FAIL_COND(!spatial_node); Instance ins; Vector<Vector3> vs; Vector<Vector2> uv; + Vector<Color> colors; vs.push_back(Vector3(-p_scale, p_scale, 0)); vs.push_back(Vector3(p_scale, p_scale, 0)); @@ -271,11 +272,17 @@ void EditorSpatialGizmo::add_unscaled_billboard(const Ref<Material> &p_material, uv.push_back(Vector2(1, 1)); uv.push_back(Vector2(0, 1)); + colors.push_back(p_modulate); + colors.push_back(p_modulate); + colors.push_back(p_modulate); + colors.push_back(p_modulate); + Ref<ArrayMesh> mesh = memnew(ArrayMesh); Array a; a.resize(Mesh::ARRAY_MAX); a[Mesh::ARRAY_VERTEX] = vs; a[Mesh::ARRAY_TEX_UV] = uv; + a[Mesh::ARRAY_COLOR] = colors; mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLE_FAN, a); mesh->surface_set_material(0, p_material); @@ -784,11 +791,10 @@ Vector3 EditorSpatialGizmo::get_handle_pos(int p_idx) const { LightSpatialGizmoPlugin::LightSpatialGizmoPlugin() { - Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/light", Color(1, 1, 0.7)); - - create_material("lines_primary", gizmo_color); - create_material("lines_secondary", gizmo_color * Color(1, 1, 1, 0.35)); - create_material("lines_billboard", gizmo_color, true); + // Enable vertex colors for the materials below as the gizmo color depends on the light color. + create_material("lines_primary", Color(1, 1, 1), false, false, true); + create_material("lines_secondary", Color(1, 1, 1, 0.35), false, false, true); + create_material("lines_billboard", Color(1, 1, 1), true, false, true); create_icon_material("light_directional_icon", SpatialEditor::get_singleton()->get_icon("GizmoDirectionalLight", "EditorIcons")); create_icon_material("light_omni_icon", SpatialEditor::get_singleton()->get_icon("GizmoLight", "EditorIcons")); @@ -934,6 +940,10 @@ void LightSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { Light *light = Object::cast_to<Light>(p_gizmo->get_spatial_node()); + Color color = light->get_color(); + // Make the gizmo color as bright as possible for better visibility + color.set_hsv(color.get_h(), color.get_s(), 1); + p_gizmo->clear(); if (Object::cast_to<DirectionalLight>(light)) { @@ -970,8 +980,8 @@ void LightSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { } } - p_gizmo->add_lines(lines, material); - p_gizmo->add_unscaled_billboard(icon, 0.05); + p_gizmo->add_lines(lines, material, false, color); + p_gizmo->add_unscaled_billboard(icon, 0.05, color); } if (Object::cast_to<OmniLight>(light)) { @@ -1007,9 +1017,9 @@ void LightSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { points_billboard.push_back(Vector3(b.x, b.y, 0)); } - p_gizmo->add_lines(points, lines_material, true); - p_gizmo->add_lines(points_billboard, lines_billboard_material, true); - p_gizmo->add_unscaled_billboard(icon, 0.05); + p_gizmo->add_lines(points, lines_material, true, color); + p_gizmo->add_lines(points_billboard, lines_billboard_material, true, color); + p_gizmo->add_unscaled_billboard(icon, 0.05, color); Vector<Vector3> handles; handles.push_back(Vector3(r, 0, 0)); @@ -1051,8 +1061,8 @@ void LightSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { points_primary.push_back(Vector3(0, 0, -r)); points_primary.push_back(Vector3()); - p_gizmo->add_lines(points_primary, material_primary); - p_gizmo->add_lines(points_secondary, material_secondary); + p_gizmo->add_lines(points_primary, material_primary, false, color); + p_gizmo->add_lines(points_secondary, material_secondary, false, color); const float ra = 16 * Math_PI * 2.0 / 64.0; const Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * w; @@ -1062,7 +1072,7 @@ void LightSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { handles.push_back(Vector3(a.x, a.y, -d)); p_gizmo->add_handles(handles, get_material("handles")); - p_gizmo->add_unscaled_billboard(icon, 0.05); + p_gizmo->add_unscaled_billboard(icon, 0.05, color); } } |