diff options
Diffstat (limited to 'editor/spatial_editor_gizmos.cpp')
-rw-r--r-- | editor/spatial_editor_gizmos.cpp | 94 |
1 files changed, 67 insertions, 27 deletions
diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp index 48c359b027..d86b255f38 100644 --- a/editor/spatial_editor_gizmos.cpp +++ b/editor/spatial_editor_gizmos.cpp @@ -36,6 +36,7 @@ #include "scene/resources/capsule_shape.h" #include "scene/resources/convex_polygon_shape.h" #include "scene/resources/plane_shape.h" +#include "scene/resources/primitive_meshes.h" #include "scene/resources/ray_shape.h" #include "scene/resources/sphere_shape.h" #include "scene/resources/surface_tool.h" @@ -130,9 +131,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.6); + w[i] = Color(1, 1, 1, 0.8); else - w[i] = Color(1, 1, 1, 0.25); + w[i] = Color(1, 1, 1, 0.2); } } @@ -175,10 +176,10 @@ void EditorSpatialGizmo::add_unscaled_billboard(const Ref<Material> &p_material, vs.push_back(Vector3(p_scale, -p_scale, 0)); vs.push_back(Vector3(-p_scale, -p_scale, 0)); - uv.push_back(Vector2(1, 0)); uv.push_back(Vector2(0, 0)); - uv.push_back(Vector2(0, 1)); + uv.push_back(Vector2(1, 0)); uv.push_back(Vector2(1, 1)); + uv.push_back(Vector2(0, 1)); Ref<ArrayMesh> mesh = memnew(ArrayMesh); Array a; @@ -296,6 +297,15 @@ void EditorSpatialGizmo::add_handles(const Vector<Vector3> &p_handles, bool p_bi } } +void EditorSpatialGizmo::add_solid_box(Ref<Material> &p_material, Vector3 size) { + CubeMesh cubem; + cubem.set_size(size); + Ref<ArrayMesh> m = memnew(ArrayMesh); + m->add_surface_from_arrays(cubem.surface_get_primitive_type(0), cubem.surface_get_arrays(0)); + m->surface_set_material(0, p_material); + add_mesh(m); +} + void EditorSpatialGizmo::set_spatial_node(Spatial *p_node) { ERR_FAIL_NULL(p_node); @@ -540,8 +550,9 @@ Ref<SpatialMaterial> EditorSpatialGizmo::create_material(const String &p_name, c if (!is_editable()) { color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/instanced"); - } else if (!is_selected()) { - color.a *= 0.5; + } + if (!is_selected()) { + color.a *= 0.3; } Ref<SpatialMaterial> line_material; @@ -587,7 +598,7 @@ Ref<SpatialMaterial> EditorSpatialGizmo::create_icon_material(const String &p_na if (!is_editable()) { color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/instanced"); } else if (!is_selected()) { - color.a *= 0.5; + color.a *= 0.3; } Ref<SpatialMaterial> icon; @@ -774,34 +785,32 @@ void LightSpatialGizmo::redraw() { Ref<Material> material = create_material("light_directional_material", gizmo_color); Ref<Material> icon = create_icon_material("light_directional_icon", SpatialEditor::get_singleton()->get_icon("GizmoDirectionalLight", "EditorIcons")); - const int arrow_points = 5; + const int arrow_points = 7; + const float arrow_length = 1.5; + Vector3 arrow[arrow_points] = { - Vector3(0, 0, 2), - Vector3(1, 1, 2), - Vector3(1, 1, -1), - Vector3(2, 2, -1), - Vector3(0, 0, -3) + Vector3(0, 0, -1), + Vector3(0, 0.8, 0), + Vector3(0, 0.3, 0), + Vector3(0, 0.3, arrow_length), + Vector3(0, -0.3, arrow_length), + Vector3(0, -0.3, 0), + Vector3(0, -0.8, 0) }; - int arrow_sides = 4; + int arrow_sides = 2; Vector<Vector3> lines; for (int i = 0; i < arrow_sides; i++) { + for (int j = 0; j < arrow_points; j++) { + Basis ma(Vector3(0, 0, 1), Math_PI * i / arrow_sides); - Basis ma(Vector3(0, 0, 1), Math_PI * 2 * float(i) / arrow_sides); - Basis mb(Vector3(0, 0, 1), Math_PI * 2 * float(i + 1) / arrow_sides); - - for (int j = 1; j < arrow_points - 1; j++) { + Vector3 v1 = arrow[j] - Vector3(0, 0, arrow_length); + Vector3 v2 = arrow[(j + 1) % arrow_points] - Vector3(0, 0, arrow_length); - if (j != 2) { - lines.push_back(ma.xform(arrow[j])); - lines.push_back(ma.xform(arrow[j + 1])); - } - if (j < arrow_points - 1) { - lines.push_back(ma.xform(arrow[j])); - lines.push_back(mb.xform(arrow[j])); - } + lines.push_back(ma.xform(v1)); + lines.push_back(ma.xform(v2)); } } @@ -850,7 +859,7 @@ void LightSpatialGizmo::redraw() { if (Object::cast_to<SpotLight>(light)) { Ref<Material> material = create_material("light_spot_material", gizmo_color, true); - Ref<Material> icon = create_icon_material("light_spot_icon", SpatialEditor::get_singleton()->get_icon("GizmoLight", "EditorIcons")); + Ref<Material> icon = create_icon_material("light_spot_icon", SpatialEditor::get_singleton()->get_icon("GizmoSpotLight", "EditorIcons")); clear(); @@ -1140,6 +1149,7 @@ void CameraSpatialGizmo::redraw() { Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/camera"); Ref<Material> material = create_material("camera_material", gizmo_color); + Ref<Material> icon = create_icon_material("camera_icon", SpatialEditor::get_singleton()->get_icon("GizmoCamera", "EditorIcons")); switch (camera->get_projection()) { @@ -1210,6 +1220,7 @@ void CameraSpatialGizmo::redraw() { add_lines(lines, material); add_collision_segments(lines); + add_unscaled_billboard(icon, 0.05); add_handles(handles); } @@ -2335,10 +2346,20 @@ void ParticlesGizmo::redraw() { Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/particles"); Ref<Material> material = create_material("particles_material", gizmo_color); + Ref<Material> icon = create_icon_material("particles_icon", SpatialEditor::get_singleton()->get_icon("GizmoParticles", "EditorIcons")); add_lines(lines, material); add_collision_segments(lines); + + if (is_selected()) { + + gizmo_color.a = 0.1; + Ref<Material> solid_material = create_material("particles_solid_material", gizmo_color); + add_solid_box(solid_material, aabb.get_size()); + } + //add_unscaled_billboard(SpatialEditorGizmos::singleton->visi,0.05); + add_unscaled_billboard(icon, 0.05); add_handles(handles); } ParticlesGizmo::ParticlesGizmo(Particles *p_particles) { @@ -2484,6 +2505,7 @@ void ReflectionProbeGizmo::redraw() { Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/reflection_probe"); Ref<Material> material = create_material("reflection_probe_material", gizmo_color); + Ref<Material> icon = create_icon_material("reflection_probe_icon", SpatialEditor::get_singleton()->get_icon("GizmoReflectionProbe", "EditorIcons")); Color gizmo_color_internal = gizmo_color; gizmo_color_internal.a = 0.5; @@ -2491,7 +2513,16 @@ void ReflectionProbeGizmo::redraw() { add_lines(lines, material); add_lines(internal_lines, material_internal); + + if (is_selected()) { + + gizmo_color.a = 0.1; + Ref<Material> solid_material = create_material("reflection_probe_solid_material", gizmo_color); + add_solid_box(solid_material, probe->get_extents() * 2.0); + } + //add_unscaled_billboard(SpatialEditorGizmos::singleton->visi,0.05); + add_unscaled_billboard(icon, 0.05); add_collision_segments(lines); add_handles(handles); } @@ -2565,6 +2596,7 @@ void GIProbeGizmo::redraw() { Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/gi_probe"); Ref<Material> material = create_material("gi_probe_material", gizmo_color); + Ref<Material> icon = create_icon_material("gi_probe_icon", SpatialEditor::get_singleton()->get_icon("GizmoGIProbe", "EditorIcons")); Color gizmo_color_internal = gizmo_color; gizmo_color_internal.a = 0.1; Ref<Material> material_internal = create_material("gi_probe_internal_material", gizmo_color_internal); @@ -2643,6 +2675,14 @@ void GIProbeGizmo::redraw() { handles.push_back(ax); } + if (is_selected()) { + + gizmo_color.a = 0.1; + Ref<Material> solid_material = create_material("gi_probe_solid_material", gizmo_color); + add_solid_box(solid_material, aabb.get_size()); + } + + add_unscaled_billboard(icon, 0.05); add_handles(handles); } GIProbeGizmo::GIProbeGizmo(GIProbe *p_probe) { |