diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-08-26 00:40:45 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-08-26 00:47:28 -0300 |
commit | 1894157c9fab05984428d83a743b0fe1d720c80c (patch) | |
tree | 817530eb75258c3dc6c73d4eb276af7b61761b06 /editor | |
parent | d9e94fa0c308f8f157e71fb03bab5834308b56ee (diff) |
-Massive clean up to gizmos
-Make sure handles are always visible (on top)
-Fixed instanced scene selection (should work properly now)
-Added interpolated camera
-Customizable gizmo colors in editor settings
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_settings.cpp | 6 | ||||
-rw-r--r-- | editor/editor_settings.h | 3 | ||||
-rw-r--r-- | editor/import/resource_importer_scene.cpp | 4 | ||||
-rw-r--r-- | editor/plugins/spatial_editor_plugin.cpp | 94 | ||||
-rw-r--r-- | editor/plugins/spatial_editor_plugin.h | 3 | ||||
-rw-r--r-- | editor/spatial_editor_gizmos.cpp | 362 | ||||
-rw-r--r-- | editor/spatial_editor_gizmos.h | 65 |
7 files changed, 374 insertions, 163 deletions
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 88c8c368d4..08ee8c3c9e 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -216,6 +216,12 @@ Variant _EDITOR_DEF(const String &p_var, const Variant &p_default) { return p_default; } +Variant _EDITOR_GET(const String &p_var) { + + ERR_FAIL_COND_V(!EditorSettings::get_singleton()->has(p_var), Variant()) + return EditorSettings::get_singleton()->get(p_var); +} + static Dictionary _get_builtin_script_templates() { Dictionary templates; diff --git a/editor/editor_settings.h b/editor/editor_settings.h index a99d7e0ad5..b479d21dfb 100644 --- a/editor/editor_settings.h +++ b/editor/editor_settings.h @@ -180,6 +180,9 @@ public: #define EDITOR_DEF(m_var, m_val) _EDITOR_DEF(m_var, Variant(m_val)) Variant _EDITOR_DEF(const String &p_var, const Variant &p_default); +#define EDITOR_GET(m_var) _EDITOR_GET(m_var) +Variant _EDITOR_GET(const String &p_var); + #define ED_IS_SHORTCUT(p_name, p_ev) (EditorSettings::get_singleton()->is_shortcut(p_name, p_ev)) Ref<ShortCut> ED_SHORTCUT(const String &p_path, const String &p_name, uint32_t p_keycode = 0); Ref<ShortCut> ED_GET_SHORTCUT(const String &p_path); diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index 5bba289492..59cd16c0b8 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -537,7 +537,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Array s->set_transform(Transform()); p_node = bv; - +#if 0 } else if (_teststr(name, "room") && Object::cast_to<MeshInstance>(p_node)) { if (isroot) @@ -657,7 +657,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Array p_node->replace_by(portal); memdelete(p_node); p_node = portal; - +#endif } else if (Object::cast_to<MeshInstance>(p_node)) { //last attempt, maybe collision insde the mesh data diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index b269f29036..e2c8caae1f 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -63,17 +63,45 @@ #define MIN_FOV 0.01 #define MAX_FOV 179 -void SpatialEditorViewport::_update_camera() { +void SpatialEditorViewport::_update_camera(float p_interp_delta) { if (orthogonal) { //camera->set_orthogonal(size.width*cursor.distance,get_znear(),get_zfar()); camera->set_orthogonal(2 * cursor.distance, 0.1, 8192); } else camera->set_perspective(get_fov(), get_znear(), get_zfar()); - Transform camera_transform = to_camera_transform(cursor); + Transform new_transform = to_camera_transform(cursor); + Transform old_transform = camera->get_global_transform(); + Transform transform; - if (camera->get_global_transform() != camera_transform) { - camera->set_global_transform(camera_transform); + if (p_interp_delta && Input::get_singleton()->get_mouse_button_mask() == 0) { + //interpolate + float interp_speed = 14; //maybe should be made configuration + transform = old_transform.interpolate_with(new_transform, MIN(1.0, p_interp_delta * interp_speed)); + } else { + transform = new_transform; + } + + float tolerance = 0.0001; + bool equal = true; + for (int i = 0; i < 3; i++) { + if (transform.basis[i].distance_to(old_transform.basis[i]) > tolerance) { + equal = false; + break; + } + } + + if (equal && transform.origin.distance_to(old_transform.origin) > tolerance) { + equal = false; + } + + if (equal) { + transform = new_transform; + } + + if (!equal || p_interp_delta == 0) { + //print_line(transform); + camera->set_global_transform(transform); update_transform_gizmo_view(); } } @@ -257,14 +285,12 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, Vector<ObjectID> instances = VisualServer::get_singleton()->instances_cull_ray(pos, ray, get_tree()->get_root()->get_world()->get_scenario()); Set<Ref<SpatialEditorGizmo> > found_gizmos; + Node *edited_scene = get_tree()->get_edited_scene_root(); ObjectID closest = 0; Spatial *item = NULL; float closest_dist = 1e20; int selected_handle = -1; - Vector<Spatial *> subscenes = Vector<Spatial *>(); - Vector<Vector3> subscenes_positions = Vector<Vector3>(); - for (int i = 0; i < instances.size(); i++) { Spatial *spat = Object::cast_to<Spatial>(ObjectDB::get_instance(instances[i])); @@ -275,19 +301,6 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, Ref<SpatialEditorGizmo> seg = spat->get_gizmo(); if ((!seg.is_valid()) || found_gizmos.has(seg)) { - - Node *subscene_candidate = spat; - Vector3 source_click_spatial_pos = spat->get_global_transform().origin; - - while ((subscene_candidate->get_owner() != NULL) && (subscene_candidate->get_owner() != editor->get_edited_scene())) - subscene_candidate = subscene_candidate->get_owner(); - - spat = Object::cast_to<Spatial>(subscene_candidate); - if (spat && (spat->get_filename() != "") && (subscene_candidate->get_owner() != NULL)) { - subscenes.push_back(spat); - subscenes_positions.push_back(source_click_spatial_pos); - } - continue; } @@ -307,32 +320,26 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, continue; if (dist < closest_dist) { - closest = instances[i]; - closest_dist = dist; - selected_handle = handle; - item = spat; + //make sure that whathever is selected is editable + while (spat && spat != edited_scene && spat->get_owner() != edited_scene && !edited_scene->is_editable_instance(spat->get_owner())) { + + spat = Object::cast_to<Spatial>(spat->get_owner()); + } + + if (spat) { + item = spat; + closest = spat->get_instance_id(); + closest_dist = dist; + selected_handle = handle; + } else { + ERR_PRINT("Bug?"); + } } // if (editor_selection->is_selected(spat)) // r_includes_current=true; } - for (int idx_subscene = 0; idx_subscene < subscenes.size(); idx_subscene++) { - - Spatial *subscene = subscenes.get(idx_subscene); - float dist = ray.cross(subscenes_positions.get(idx_subscene) - pos).length(); - - if ((dist < 0) || (dist > 1.2)) - continue; - - if (dist < closest_dist) { - closest = subscene->get_instance_id(); - closest_dist = dist; - item = subscene; - selected_handle = -1; - } - } - if (!item) return 0; @@ -1678,7 +1685,7 @@ void SpatialEditorViewport::_notification(int p_what) { set_process(visible); if (visible) - _update_camera(); + _update_camera(0); call_deferred("update_transform_gizmo_view"); } @@ -1710,7 +1717,7 @@ void SpatialEditorViewport::_notification(int p_what) { _update_freelook(delta); - _update_camera(); + _update_camera(get_process_delta_time()); Map<Node *, Object *> &selection = editor_selection->get_selection(); @@ -3677,7 +3684,7 @@ void SpatialEditor::_request_gizmo(Object *p_obj) { Spatial *sp = Object::cast_to<Spatial>(p_obj); if (!sp) return; - if (editor->get_edited_scene() && (sp == editor->get_edited_scene() || sp->get_owner() == editor->get_edited_scene() || editor->get_edited_scene()->is_editable_instance(sp->get_owner()))) { + if (editor->get_edited_scene() && (sp == editor->get_edited_scene() || (sp->get_owner() && editor->get_edited_scene()->is_a_parent_of(sp)))) { Ref<SpatialEditorGizmo> seg; @@ -3691,7 +3698,6 @@ void SpatialEditor::_request_gizmo(Object *p_obj) { if (!seg.is_valid()) { seg = gizmos->get_gizmo(sp); } - if (seg.is_valid()) { sp->set_gizmo(seg); } diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index 2fd72739df..7797a657c0 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -49,6 +49,7 @@ class SpatialEditorGizmo : public SpatialGizmo { GDCLASS(SpatialEditorGizmo, SpatialGizmo); bool selected; + bool instanced; public: void set_selected(bool p_selected) { selected = p_selected; } @@ -240,7 +241,7 @@ private: void set_message(String p_message, float p_time = 5); // - void _update_camera(); + void _update_camera(float p_interp_delta); Transform to_camera_transform(const Cursor &p_cursor) const; void _draw(); diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp index e80fa603ce..45d622c9d2 100644 --- a/editor/spatial_editor_gizmos.cpp +++ b/editor/spatial_editor_gizmos.cpp @@ -45,6 +45,24 @@ #define HANDLE_HALF_SIZE 0.05 +bool EditorSpatialGizmo::can_draw() const { + return is_editable(); +} +bool EditorSpatialGizmo::is_editable() const { + + ERR_FAIL_COND_V(!spatial_node, false); + Node *edited_root = spatial_node->get_tree()->get_edited_scene_root(); + if (spatial_node == edited_root) + return true; + if (spatial_node->get_owner() == edited_root) + return true; + + if (edited_root->is_editable_instance(spatial_node->get_owner())) + return true; + + return false; +} + void EditorSpatialGizmo::clear() { for (int i = 0; i < instances.size(); i++) { @@ -211,7 +229,7 @@ void EditorSpatialGizmo::add_handles(const Vector<Vector3> &p_handles, bool p_bi billboard_handle = p_billboard; - if (!is_selected()) + if (!is_selected() || !is_editable()) return; ERR_FAIL_COND(!spatial_node); @@ -560,6 +578,94 @@ void EditorSpatialGizmo::free() { valid = false; } +Ref<SpatialMaterial> EditorSpatialGizmo::create_material(const String &p_name, const Color &p_color, bool p_billboard, bool p_on_top, bool p_use_vertex_color) { + + String name = p_name; + + if (!is_editable()) { + name += "@readonly"; + } else if (is_selected()) { + name += "@selected"; + } + + if (SpatialEditorGizmos::singleton->material_cache.has(name)) { + return SpatialEditorGizmos::singleton->material_cache[name]; + } + + Color color = p_color; + + if (!is_editable()) { + color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/instanced"); + } else if (!is_selected()) { + color.a *= 0.5; + } + + Ref<SpatialMaterial> line_material; + line_material.instance(); + line_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true); + line_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); + if (p_use_vertex_color) { + line_material->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + line_material->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); + } + + if (p_billboard) { + line_material->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED); + } + + if (p_on_top && is_selected()) { + line_material->set_flag(SpatialMaterial::FLAG_ONTOP, true); + } + + line_material->set_albedo(color); + + SpatialEditorGizmos::singleton->material_cache[name] = line_material; + + return line_material; +} + +Ref<SpatialMaterial> EditorSpatialGizmo::create_icon_material(const String &p_name, const Ref<Texture> &p_texture, bool p_on_top, const Color &p_albedo) { + + String name = p_name; + + if (!is_editable()) { + name += "@readonly"; + } else if (is_selected()) { + name += "@selected"; + } + + if (SpatialEditorGizmos::singleton->material_cache.has(name)) { + return SpatialEditorGizmos::singleton->material_cache[name]; + } + + Color color = p_albedo; + + if (!is_editable()) { + color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/instanced"); + } else if (!is_selected()) { + color.a *= 0.5; + } + + Ref<SpatialMaterial> icon; + icon.instance(); + icon->set_flag(SpatialMaterial::FLAG_UNSHADED, true); + icon->set_cull_mode(SpatialMaterial::CULL_DISABLED); + icon->set_depth_draw_mode(SpatialMaterial::DEPTH_DRAW_DISABLED); + icon->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); + icon->set_albedo(color); + icon->set_texture(SpatialMaterial::TEXTURE_ALBEDO, p_texture); + icon->set_flag(SpatialMaterial::FLAG_FIXED_SIZE, true); + icon->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED); + + if (p_on_top && is_selected()) { + icon->set_flag(SpatialMaterial::FLAG_ONTOP, true); + } + + SpatialEditorGizmos::singleton->material_cache[name] = icon; + + return icon; +} + void EditorSpatialGizmo::_bind_methods() { ClassDB::bind_method(D_METHOD("add_lines", "lines", "material", "billboard"), &EditorSpatialGizmo::add_lines, DEFVAL(false)); @@ -713,8 +819,13 @@ void LightSpatialGizmo::commit_handle(int p_idx, const Variant &p_restore, bool void LightSpatialGizmo::redraw() { + Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/light"); + if (Object::cast_to<DirectionalLight>(light)) { + 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; Vector3 arrow[arrow_points] = { Vector3(0, 0, 2), @@ -746,13 +857,15 @@ void LightSpatialGizmo::redraw() { } } - add_lines(lines, SpatialEditorGizmos::singleton->light_material); + add_lines(lines, material); add_collision_segments(lines); - add_unscaled_billboard(SpatialEditorGizmos::singleton->light_material_directional_icon, 0.05); + add_unscaled_billboard(icon, 0.05); } if (Object::cast_to<OmniLight>(light)) { + Ref<Material> material = create_material("light_omni_material", gizmo_color, true); + Ref<Material> icon = create_icon_material("light_omni_icon", SpatialEditor::get_singleton()->get_icon("GizmoLight", "EditorIcons")); clear(); OmniLight *on = Object::cast_to<OmniLight>(light); @@ -776,10 +889,10 @@ void LightSpatialGizmo::redraw() { points.push_back(Vector3(b.x, b.y, 0)); } - add_lines(points, SpatialEditorGizmos::singleton->light_material_omni, true); + add_lines(points, material, true); add_collision_segments(points); - add_unscaled_billboard(SpatialEditorGizmos::singleton->light_material_omni_icon, 0.05); + add_unscaled_billboard(icon, 0.05); Vector<Vector3> handles; handles.push_back(Vector3(r, 0, 0)); @@ -788,6 +901,9 @@ 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")); + clear(); Vector<Vector3> points; @@ -821,7 +937,7 @@ void LightSpatialGizmo::redraw() { points.push_back(Vector3(0, 0, -r)); points.push_back(Vector3()); - add_lines(points, SpatialEditorGizmos::singleton->light_material); + add_lines(points, material); Vector<Vector3> handles; handles.push_back(Vector3(0, 0, -r)); @@ -855,7 +971,7 @@ void LightSpatialGizmo::redraw() { add_handles(handles); add_collision_segments(collision_segments); - add_unscaled_billboard(SpatialEditorGizmos::singleton->light_material_omni_icon, 0.05); + add_unscaled_billboard(icon, 0.05); } } @@ -937,7 +1053,13 @@ void AudioStreamPlayer3DSpatialGizmo::redraw() { clear(); + Ref<Material> icon = create_icon_material("stream_player_3d_material", SpatialEditor::get_singleton()->get_icon("GizmoSpatialSamplePlayer", "EditorIcons")); + if (player->is_emission_angle_enabled()) { + + Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/stream_player_3d"); + Ref<Material> material = create_material("stream_player_3d_material", gizmo_color); + float pc = player->get_emission_angle(); Vector<Vector3> points; @@ -968,7 +1090,7 @@ void AudioStreamPlayer3DSpatialGizmo::redraw() { points[200 + i * 2 + 1] = Vector3(); } - add_lines(points, SpatialEditorGizmos::singleton->car_wheel_material); + add_lines(points, material); add_collision_segments(points); Vector<Vector3> handles; @@ -977,7 +1099,7 @@ void AudioStreamPlayer3DSpatialGizmo::redraw() { add_handles(handles); } - add_unscaled_billboard(SpatialEditorGizmos::singleton->sample_player_icon, 0.05); + add_unscaled_billboard(icon, 0.05); } AudioStreamPlayer3DSpatialGizmo::AudioStreamPlayer3DSpatialGizmo(AudioStreamPlayer3D *p_player) { @@ -1068,6 +1190,9 @@ void CameraSpatialGizmo::redraw() { Vector<Vector3> lines; Vector<Vector3> handles; + Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/camera"); + Ref<Material> material = create_material("camera_material", gizmo_color); + switch (camera->get_projection()) { case Camera::PROJECTION_PERSPECTIVE: { @@ -1135,7 +1260,7 @@ void CameraSpatialGizmo::redraw() { } break; } - add_lines(lines, SpatialEditorGizmos::singleton->camera_material); + add_lines(lines, material); add_collision_segments(lines); add_handles(handles); } @@ -1148,6 +1273,9 @@ CameraSpatialGizmo::CameraSpatialGizmo(Camera *p_camera) { ////// +bool MeshInstanceSpatialGizmo::can_draw() const { + return true; //mesh can always draw (even though nothing is displayed) +} void MeshInstanceSpatialGizmo::redraw() { Ref<Mesh> m = mesh->get_mesh(); @@ -1194,10 +1322,13 @@ void SkeletonSpatialGizmo::redraw() { clear(); + Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/skeleton"); + Ref<Material> material = create_material("skeleton_material", gizmo_color); + Ref<SurfaceTool> surface_tool(memnew(SurfaceTool)); surface_tool->begin(Mesh::PRIMITIVE_LINES); - surface_tool->set_material(SpatialEditorGizmos::singleton->skeleton_material); + surface_tool->set_material(material); Vector<Transform> grests; grests.resize(skel->get_bone_count()); @@ -1378,7 +1509,7 @@ SkeletonSpatialGizmo::SkeletonSpatialGizmo(Skeleton *p_skel) { skel = p_skel; set_spatial_node(p_skel); } - +#if 0 void RoomSpatialGizmo::redraw() { clear(); @@ -1481,6 +1612,7 @@ PortalSpatialGizmo::PortalSpatialGizmo(Portal *p_portal) { portal = p_portal; } +#endif ///// void RayCastSpatialGizmo::redraw() { @@ -1492,7 +1624,10 @@ void RayCastSpatialGizmo::redraw() { lines.push_back(Vector3()); lines.push_back(raycast->get_cast_to()); - add_lines(lines, SpatialEditorGizmos::singleton->raycast_material); + Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/shape"); + Ref<Material> material = create_material("shape_material", gizmo_color); + + add_lines(lines, material); add_collision_segments(lines); } @@ -1550,7 +1685,10 @@ void VehicleWheelSpatialGizmo::redraw() { points.push_back(Vector3(0, -r, r * 2)); points.push_back(Vector3(-r * 2 * 0.2, -r, r * 2 * 0.8)); - add_lines(points, SpatialEditorGizmos::singleton->car_wheel_material); + Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/shape"); + Ref<Material> material = create_material("shape_material", gizmo_color); + + add_lines(points, material); add_collision_segments(points); } @@ -1778,6 +1916,9 @@ void CollisionShapeSpatialGizmo::redraw() { if (s.is_null()) return; + Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/shape"); + Ref<Material> material = create_material("shape_material", gizmo_color); + if (Object::cast_to<SphereShape>(*s)) { Ref<SphereShape> sp = s; @@ -1817,7 +1958,7 @@ void CollisionShapeSpatialGizmo::redraw() { collision_segments.push_back(Vector3(b.x, b.y, 0)); } - add_lines(points, SpatialEditorGizmos::singleton->shape_material); + add_lines(points, material); add_collision_segments(collision_segments); Vector<Vector3> handles; handles.push_back(Vector3(r, 0, 0)); @@ -1848,7 +1989,7 @@ void CollisionShapeSpatialGizmo::redraw() { handles.push_back(ax); } - add_lines(lines, SpatialEditorGizmos::singleton->shape_material); + add_lines(lines, material); add_collision_segments(lines); add_handles(handles); } @@ -1889,7 +2030,7 @@ void CollisionShapeSpatialGizmo::redraw() { points.push_back(Vector3(b.y, 0, b.x) + dud); } - add_lines(points, SpatialEditorGizmos::singleton->shape_material); + add_lines(points, material); Vector<Vector3> collision_segments; @@ -1955,7 +2096,7 @@ void CollisionShapeSpatialGizmo::redraw() { points.push_back(p.normal * p.d); points.push_back(p.normal * p.d + p.normal * 3); - add_lines(points, SpatialEditorGizmos::singleton->shape_material); + add_lines(points, material); add_collision_segments(points); } @@ -1977,7 +2118,7 @@ void CollisionShapeSpatialGizmo::redraw() { points[i * 2 + 1] = md.vertices[md.edges[i].b]; } - add_lines(points, SpatialEditorGizmos::singleton->shape_material); + add_lines(points, material); add_collision_segments(points); } } @@ -1990,7 +2131,7 @@ void CollisionShapeSpatialGizmo::redraw() { Vector<Vector3> points; points.push_back(Vector3()); points.push_back(Vector3(0, 0, rs->get_length())); - add_lines(points, SpatialEditorGizmos::singleton->shape_material); + add_lines(points, material); add_collision_segments(points); Vector<Vector3> handles; handles.push_back(Vector3(0, 0, rs->get_length())); @@ -2024,7 +2165,10 @@ void CollisionPolygonSpatialGizmo::redraw() { lines.push_back(Vector3(points[i].x, points[i].y, -depth)); } - add_lines(lines, SpatialEditorGizmos::singleton->shape_material); + Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/shape"); + Ref<Material> material = create_material("shape_material", gizmo_color); + + add_lines(lines, material); add_collision_segments(lines); } @@ -2092,6 +2236,9 @@ void VisibilityNotifierGizmo::commit_handle(int p_idx, const Variant &p_restore, void VisibilityNotifierGizmo::redraw() { + Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/visibility_notifier"); + Ref<Material> material = create_material("visibility_notifier_material", gizmo_color); + clear(); Vector<Vector3> lines; @@ -2113,7 +2260,7 @@ void VisibilityNotifierGizmo::redraw() { handles.push_back(ax); } - add_lines(lines, SpatialEditorGizmos::singleton->visibility_notifier_material); + add_lines(lines, material); //add_unscaled_billboard(SpatialEditorGizmos::singleton->visi,0.05); add_collision_segments(lines); add_handles(handles); @@ -2238,7 +2385,10 @@ void ParticlesGizmo::redraw() { lines.push_back(center + ax); } - add_lines(lines, SpatialEditorGizmos::singleton->particles_material); + Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/particles"); + Ref<Material> material = create_material("particles_material", gizmo_color); + + add_lines(lines, material); add_collision_segments(lines); //add_unscaled_billboard(SpatialEditorGizmos::singleton->visi,0.05); add_handles(handles); @@ -2384,8 +2534,15 @@ void ReflectionProbeGizmo::redraw() { lines.push_back(orig_handle); } - add_lines(lines, SpatialEditorGizmos::singleton->reflection_probe_material); - add_lines(internal_lines, SpatialEditorGizmos::singleton->reflection_probe_material_internal); + Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/reflection_probe"); + Ref<Material> material = create_material("reflection_probe_material", gizmo_color); + + Color gizmo_color_internal = gizmo_color; + gizmo_color_internal.a = 0.5; + Ref<Material> material_internal = create_material("reflection_internal_material", gizmo_color_internal); + + add_lines(lines, material); + add_lines(internal_lines, material_internal); //add_unscaled_billboard(SpatialEditorGizmos::singleton->visi,0.05); add_collision_segments(lines); add_handles(handles); @@ -2458,6 +2615,12 @@ void GIProbeGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p_can 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); + 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); + clear(); Vector<Vector3> lines; @@ -2476,7 +2639,7 @@ void GIProbeGizmo::redraw() { lines.push_back(b); } - add_lines(lines, SpatialEditorGizmos::singleton->gi_probe_material); + add_lines(lines, material); add_collision_segments(lines); lines.clear(); @@ -2521,7 +2684,7 @@ void GIProbeGizmo::redraw() { } } - add_lines(lines, SpatialEditorGizmos::singleton->gi_probe_material_internal); + add_lines(lines, material_internal); Vector<Vector3> handles; @@ -2544,6 +2707,11 @@ GIProbeGizmo::GIProbeGizmo(GIProbe *p_probe) { void NavigationMeshSpatialGizmo::redraw() { + Ref<Material> edge_material = create_material("navigation_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/navigation_edge")); + Ref<Material> edge_material_disabled = create_material("navigation_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/navigation_edge_disabled")); + Ref<Material> solid_material = create_material("navigation_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/navigation_solid")); + Ref<Material> solid_material_disabled = create_material("navigation_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/navigation_solid_disabled")); + clear(); Ref<NavigationMesh> navmeshie = navmesh->get_navigation_mesh(); if (navmeshie.is_null()) @@ -2616,14 +2784,14 @@ void NavigationMeshSpatialGizmo::redraw() { tmesh->create(tmeshfaces); if (lines.size()) - add_lines(lines, navmesh->is_enabled() ? SpatialEditorGizmos::singleton->navmesh_edge_material : SpatialEditorGizmos::singleton->navmesh_edge_material_disabled); + add_lines(lines, navmesh->is_enabled() ? edge_material : edge_material_disabled); add_collision_triangles(tmesh); Ref<ArrayMesh> m = memnew(ArrayMesh); Array a; a.resize(Mesh::ARRAY_MAX); a[0] = tmeshfaces; m->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, a); - m->surface_set_material(0, navmesh->is_enabled() ? SpatialEditorGizmos::singleton->navmesh_solid_material : SpatialEditorGizmos::singleton->navmesh_solid_material_disabled); + m->surface_set_material(0, navmesh->is_enabled() ? solid_material : solid_material_disabled); add_mesh(m); add_collision_segments(lines); } @@ -2650,7 +2818,10 @@ void PinJointSpatialGizmo::redraw() { cursor_points.push_back(Vector3(0, 0, +cs)); cursor_points.push_back(Vector3(0, 0, -cs)); add_collision_segments(cursor_points); - add_lines(cursor_points, SpatialEditorGizmos::singleton->joint_material); + + Ref<Material> material = create_material("joint_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/joint")); + + add_lines(cursor_points, material); } PinJointSpatialGizmo::PinJointSpatialGizmo(PinJoint *p_p3d) { @@ -2720,8 +2891,11 @@ void HingeJointSpatialGizmo::redraw() { cursor_points.push_back(to); } } + + Ref<Material> material = create_material("joint_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/joint")); + add_collision_segments(cursor_points); - add_lines(cursor_points, SpatialEditorGizmos::singleton->joint_material); + add_lines(cursor_points, material); } HingeJointSpatialGizmo::HingeJointSpatialGizmo(HingeJoint *p_p3d) { @@ -2824,8 +2998,11 @@ void SliderJointSpatialGizmo::redraw() { cursor_points.push_back(to); } } + + Ref<Material> material = create_material("joint_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/joint")); + add_collision_segments(cursor_points); - add_lines(cursor_points, SpatialEditorGizmos::singleton->joint_material); + add_lines(cursor_points, material); } SliderJointSpatialGizmo::SliderJointSpatialGizmo(SliderJoint *p_p3d) { @@ -2896,8 +3073,9 @@ void ConeTwistJointSpatialGizmo::redraw() { points.push_back(Vector3(cn, b.x, b.y)); } + Ref<Material> material = create_material("joint_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/joint")); add_collision_segments(points); - add_lines(points, SpatialEditorGizmos::singleton->joint_material); + add_lines(points, material); } ConeTwistJointSpatialGizmo::ConeTwistJointSpatialGizmo(ConeTwistJoint *p_p3d) { @@ -3080,8 +3258,9 @@ void Generic6DOFJointSpatialGizmo::redraw() { #undef ADD_VTX #undef SET_VTX + Ref<Material> material = create_material("joint_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/joint")); add_collision_segments(cursor_points); - add_lines(cursor_points, SpatialEditorGizmos::singleton->joint_material); + add_lines(cursor_points, material); } Generic6DOFJointSpatialGizmo::Generic6DOFJointSpatialGizmo(Generic6DOFJoint *p_p3d) { @@ -3128,11 +3307,11 @@ Ref<SpatialEditorGizmo> SpatialEditorGizmos::get_gizmo(Spatial *p_spatial) { return misg; } - if (Object::cast_to<Room>(p_spatial)) { + /*if (Object::cast_to<Room>(p_spatial)) { Ref<RoomSpatialGizmo> misg = memnew(RoomSpatialGizmo(Object::cast_to<Room>(p_spatial))); return misg; - } + }*/ if (Object::cast_to<NavigationMeshInstance>(p_spatial)) { @@ -3145,13 +3324,13 @@ Ref<SpatialEditorGizmo> SpatialEditorGizmos::get_gizmo(Spatial *p_spatial) { Ref<RayCastSpatialGizmo> misg = memnew(RayCastSpatialGizmo(Object::cast_to<RayCast>(p_spatial))); return misg; } - + /* if (Object::cast_to<Portal>(p_spatial)) { Ref<PortalSpatialGizmo> misg = memnew(PortalSpatialGizmo(Object::cast_to<Portal>(p_spatial))); return misg; } - +*/ if (Object::cast_to<CollisionShape>(p_spatial)) { Ref<CollisionShapeSpatialGizmo> misg = memnew(CollisionShapeSpatialGizmo(Object::cast_to<CollisionShape>(p_spatial))); @@ -3231,35 +3410,13 @@ Ref<SpatialEditorGizmo> SpatialEditorGizmos::get_gizmo(Spatial *p_spatial) { return Ref<SpatialEditorGizmo>(); } -Ref<SpatialMaterial> SpatialEditorGizmos::create_line_material(const Color &p_base_color) { - - Ref<SpatialMaterial> line_material = Ref<SpatialMaterial>(memnew(SpatialMaterial)); - line_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true); - line_material->set_line_width(3.0); - line_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); - //line_material->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); - //->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); - line_material->set_albedo(p_base_color); - - return line_material; -} - -Ref<SpatialMaterial> SpatialEditorGizmos::create_solid_material(const Color &p_base_color) { - - Ref<SpatialMaterial> line_material = Ref<SpatialMaterial>(memnew(SpatialMaterial)); - line_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true); - line_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); - line_material->set_albedo(p_base_color); - - return line_material; -} - SpatialEditorGizmos::SpatialEditorGizmos() { singleton = this; handle_material = Ref<SpatialMaterial>(memnew(SpatialMaterial)); handle_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true); + handle_material->set_flag(SpatialMaterial::FLAG_ONTOP, true); handle_material->set_albedo(Color(0.8, 0.8, 0.8)); handle_material_billboard = handle_material->duplicate(); handle_material_billboard->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED); @@ -3274,9 +3431,29 @@ SpatialEditorGizmos::SpatialEditorGizmos() { handle2_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); handle2_material->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); handle2_material->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); + handle2_material->set_flag(SpatialMaterial::FLAG_ONTOP, true); handle2_material_billboard = handle2_material->duplicate(); handle2_material_billboard->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED); - + handle2_material_billboard->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED); + handle2_material_billboard->set_flag(SpatialMaterial::FLAG_ONTOP, true); + + EDITOR_DEF("editors/3d_gizmos/gizmo_colors/light", Color(1, 1, 0.2)); + EDITOR_DEF("editors/3d_gizmos/gizmo_colors/stream_player_3d", Color(0.4, 0.8, 1)); + EDITOR_DEF("editors/3d_gizmos/gizmo_colors/camera", Color(0.8, 0.4, 0.8)); + EDITOR_DEF("editors/3d_gizmos/gizmo_colors/skeleton", Color(1, 0.8, 0.4)); + EDITOR_DEF("editors/3d_gizmos/gizmo_colors/visibility_notifier", Color(0.8, 0.5, 0.7)); + EDITOR_DEF("editors/3d_gizmos/gizmo_colors/particles", Color(0.8, 0.7, 0.4)); + EDITOR_DEF("editors/3d_gizmos/gizmo_colors/reflection_probe", Color(0.6, 1, 0.5)); + EDITOR_DEF("editors/3d_gizmos/gizmo_colors/gi_probe", Color(0.5, 1, 0.6)); + EDITOR_DEF("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1)); + EDITOR_DEF("editors/3d_gizmos/gizmo_colors/joint", Color(0.5, 0.8, 1)); + EDITOR_DEF("editors/3d_gizmos/gizmo_colors/navigation_edge", Color(0.5, 1, 1)); + EDITOR_DEF("editors/3d_gizmos/gizmo_colors/navigation_edge_disabled", Color(0.7, 0.7, 0.7)); + EDITOR_DEF("editors/3d_gizmos/gizmo_colors/navigation_solid", Color(0.5, 1, 1, 0.4)); + EDITOR_DEF("editors/3d_gizmos/gizmo_colors/navigation_solid_disabled", Color(0.7, 0.7, 0.7, 0.4)); + EDITOR_DEF("editors/3d_gizmos/gizmo_colors/instanced", Color(0.7, 0.7, 0.7, 0.5)); + +#if 0 light_material = create_line_material(Color(1, 1, 0.2)); light_material_omni = create_line_material(Color(1, 1, 0.2)); light_material_omni->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED); @@ -3289,6 +3466,7 @@ SpatialEditorGizmos::SpatialEditorGizmos() { light_material_omni_icon->set_albedo(Color(1, 1, 1, 0.9)); light_material_omni_icon->set_texture(SpatialMaterial::TEXTURE_ALBEDO, SpatialEditor::get_singleton()->get_icon("GizmoLight", "EditorIcons")); light_material_omni_icon->set_flag(SpatialMaterial::FLAG_FIXED_SIZE, true); + light_material_omni_icon->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED); light_material_directional_icon = Ref<SpatialMaterial>(memnew(SpatialMaterial)); light_material_directional_icon->set_flag(SpatialMaterial::FLAG_UNSHADED, true); @@ -3297,6 +3475,8 @@ SpatialEditorGizmos::SpatialEditorGizmos() { light_material_directional_icon->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); light_material_directional_icon->set_albedo(Color(1, 1, 1, 0.9)); light_material_directional_icon->set_texture(SpatialMaterial::TEXTURE_ALBEDO, SpatialEditor::get_singleton()->get_icon("GizmoDirectionalLight", "EditorIcons")); + light_material_directional_icon->set_billboard_mode(SpatialMaterial::BILLBOARD_ENABLED); + light_material_directional_icon->set_depth_scale(1); camera_material = create_line_material(Color(1.0, 0.5, 1.0)); @@ -3463,4 +3643,62 @@ SpatialEditorGizmos::SpatialEditorGizmos() { } shape_material = create_line_material(Color(0.2, 1, 1.0)); +#endif + + pos3d_mesh = Ref<ArrayMesh>(memnew(ArrayMesh)); + { + + PoolVector<Vector3> cursor_points; + PoolVector<Color> cursor_colors; + float cs = 0.25; + cursor_points.push_back(Vector3(+cs, 0, 0)); + cursor_points.push_back(Vector3(-cs, 0, 0)); + cursor_points.push_back(Vector3(0, +cs, 0)); + cursor_points.push_back(Vector3(0, -cs, 0)); + cursor_points.push_back(Vector3(0, 0, +cs)); + cursor_points.push_back(Vector3(0, 0, -cs)); + cursor_colors.push_back(Color(1, 0.5, 0.5, 0.7)); + cursor_colors.push_back(Color(1, 0.5, 0.5, 0.7)); + cursor_colors.push_back(Color(0.5, 1, 0.5, 0.7)); + cursor_colors.push_back(Color(0.5, 1, 0.5, 0.7)); + cursor_colors.push_back(Color(0.5, 0.5, 1, 0.7)); + cursor_colors.push_back(Color(0.5, 0.5, 1, 0.7)); + + Ref<SpatialMaterial> mat = memnew(SpatialMaterial); + mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); + mat->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + mat->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); + mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); + mat->set_line_width(3); + Array d; + d.resize(VS::ARRAY_MAX); + d[Mesh::ARRAY_VERTEX] = cursor_points; + d[Mesh::ARRAY_COLOR] = cursor_colors; + pos3d_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, d); + pos3d_mesh->surface_set_material(0, mat); + } + + listener_line_mesh = Ref<ArrayMesh>(memnew(ArrayMesh)); + { + + PoolVector<Vector3> cursor_points; + PoolVector<Color> cursor_colors; + cursor_points.push_back(Vector3(0, 0, 0)); + cursor_points.push_back(Vector3(0, 0, -1.0)); + cursor_colors.push_back(Color(0.5, 0.5, 0.5, 0.7)); + cursor_colors.push_back(Color(0.5, 0.5, 0.5, 0.7)); + + Ref<SpatialMaterial> mat = memnew(SpatialMaterial); + mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); + mat->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + mat->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); + mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); + mat->set_line_width(3); + Array d; + d.resize(VS::ARRAY_MAX); + d[Mesh::ARRAY_VERTEX] = cursor_points; + d[Mesh::ARRAY_COLOR] = cursor_colors; + listener_line_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, d); + listener_line_mesh->surface_set_material(0, mat); + } } diff --git a/editor/spatial_editor_gizmos.h b/editor/spatial_editor_gizmos.h index 4769e5d765..fa5484c3d9 100644 --- a/editor/spatial_editor_gizmos.h +++ b/editor/spatial_editor_gizmos.h @@ -107,6 +107,9 @@ protected: static void _bind_methods(); + Ref<SpatialMaterial> create_material(const String &p_name, const Color &p_color, bool p_billboard = false, bool p_on_top = false, bool p_use_vertex_color = false); + Ref<SpatialMaterial> create_icon_material(const String &p_name, const Ref<Texture> &p_texture, bool p_on_top = false, const Color &p_albedo = Color(1, 1, 1, 1)); + public: virtual Vector3 get_handle_pos(int p_idx) const; virtual bool intersect_frustum(const Camera *p_camera, const Vector<Plane> &p_frustum); @@ -117,6 +120,8 @@ public: void transform(); virtual void redraw(); void free(); + virtual bool is_editable() const; + virtual bool can_draw() const; EditorSpatialGizmo(); ~EditorSpatialGizmo(); @@ -177,6 +182,7 @@ class MeshInstanceSpatialGizmo : public EditorSpatialGizmo { MeshInstance *mesh; public: + virtual bool can_draw() const; void redraw(); MeshInstanceSpatialGizmo(MeshInstance *p_mesh = NULL); }; @@ -203,25 +209,7 @@ public: SkeletonSpatialGizmo(Skeleton *p_skel = NULL); }; -class RoomSpatialGizmo : public EditorSpatialGizmo { - - GDCLASS(RoomSpatialGizmo, EditorSpatialGizmo); - - struct _EdgeKey { - - Vector3 from; - Vector3 to; - - bool operator<(const _EdgeKey &p_with) const { return from == p_with.from ? to < p_with.to : from < p_with.from; } - }; - - Room *room; - -public: - void redraw(); - RoomSpatialGizmo(Room *p_room = NULL); -}; - +#if 0 class PortalSpatialGizmo : public EditorSpatialGizmo { GDCLASS(PortalSpatialGizmo, EditorSpatialGizmo); @@ -232,6 +220,7 @@ public: void redraw(); PortalSpatialGizmo(Portal *p_portal = NULL); }; +#endif class VisibilityNotifierGizmo : public EditorSpatialGizmo { @@ -420,51 +409,19 @@ public: }; class SpatialEditorGizmos { + public: - Ref<SpatialMaterial> create_line_material(const Color &p_base_color); - Ref<SpatialMaterial> create_solid_material(const Color &p_base_color); + HashMap<String, Ref<SpatialMaterial> > material_cache; + Ref<SpatialMaterial> handle2_material; Ref<SpatialMaterial> handle2_material_billboard; Ref<SpatialMaterial> handle_material; Ref<SpatialMaterial> handle_material_billboard; - Ref<SpatialMaterial> light_material; - Ref<SpatialMaterial> light_material_omni; - Ref<SpatialMaterial> light_material_omni_icon; - Ref<SpatialMaterial> light_material_directional_icon; - Ref<SpatialMaterial> camera_material; - Ref<SpatialMaterial> skeleton_material; - Ref<SpatialMaterial> reflection_probe_material; - Ref<SpatialMaterial> reflection_probe_material_internal; - Ref<SpatialMaterial> gi_probe_material; - Ref<SpatialMaterial> gi_probe_material_internal; - Ref<SpatialMaterial> room_material; - Ref<SpatialMaterial> portal_material; - Ref<SpatialMaterial> raycast_material; - Ref<SpatialMaterial> visibility_notifier_material; - Ref<SpatialMaterial> particles_material; - Ref<SpatialMaterial> car_wheel_material; - Ref<SpatialMaterial> joint_material; - - Ref<SpatialMaterial> navmesh_edge_material; - Ref<SpatialMaterial> navmesh_solid_material; - Ref<SpatialMaterial> navmesh_edge_material_disabled; - Ref<SpatialMaterial> navmesh_solid_material_disabled; - - Ref<SpatialMaterial> listener_icon; - - Ref<SpatialMaterial> sample_player_icon; - Ref<SpatialMaterial> stream_player_icon; - Ref<SpatialMaterial> visibility_notifier_icon; - - Ref<SpatialMaterial> shape_material; Ref<Texture> handle_t; - Ref<ArrayMesh> pos3d_mesh; Ref<ArrayMesh> listener_line_mesh; static SpatialEditorGizmos *singleton; - Ref<TriangleMesh> test_cube_tm; - Ref<SpatialEditorGizmo> get_gizmo(Spatial *p_spatial); SpatialEditorGizmos(); |