1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-13 13:31:48 +00:00

Merge pull request #21707 from JFonS/fix_instanced_selection

Fix selection of instanced scenes in 3D
This commit is contained in:
Rémi Verschelde
2018-09-05 18:11:56 +02:00
committed by GitHub
7 changed files with 34 additions and 60 deletions

View File

@@ -215,8 +215,8 @@ void PathSpatialGizmo::redraw() {
clear(); clear();
Ref<SpatialMaterial> path_material = gizmo_plugin->get_material("path_material"); Ref<SpatialMaterial> path_material = gizmo_plugin->get_material("path_material", this);
Ref<SpatialMaterial> path_thin_material = gizmo_plugin->get_material("path_thin_material"); Ref<SpatialMaterial> path_thin_material = gizmo_plugin->get_material("path_thin_material", this);
Ref<SpatialMaterial> handles_material = gizmo_plugin->get_material("handles"); Ref<SpatialMaterial> handles_material = gizmo_plugin->get_material("handles");
Ref<Curve3D> c = path->get_curve(); Ref<Curve3D> c = path->get_curve();
@@ -641,24 +641,8 @@ String PathSpatialGizmoPlugin::get_name() const {
PathSpatialGizmoPlugin::PathSpatialGizmoPlugin() { PathSpatialGizmoPlugin::PathSpatialGizmoPlugin() {
Color path_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/path", Color(0.5, 0.5, 1.0, 0.8)); Color path_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/path", Color(0.5, 0.5, 1.0, 0.8));
create_material("path_material", path_color);
Ref<SpatialMaterial> path_material = Ref<SpatialMaterial>(memnew(SpatialMaterial));
path_color.a = 0.8;
path_material->set_albedo(path_color);
path_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
path_material->set_line_width(3);
path_material->set_cull_mode(SpatialMaterial::CULL_DISABLED);
path_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
Ref<SpatialMaterial> path_thin_material = Ref<SpatialMaterial>(memnew(SpatialMaterial));
path_color.a = 0.4; path_color.a = 0.4;
path_thin_material->set_albedo(path_color); create_material("path_thin_material", path_color);
path_thin_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
path_thin_material->set_line_width(1);
path_thin_material->set_cull_mode(SpatialMaterial::CULL_DISABLED);
path_thin_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
add_material("path_material", path_material);
add_material("path_thin_material", path_thin_material);
create_handle_material("handles"); create_handle_material("handles");
} }

View File

@@ -276,7 +276,7 @@ void SpatialEditorViewport::_select_clicked(bool p_append, bool p_single) {
_select(sp, clicked_wants_append, true); _select(sp, clicked_wants_append, true);
} }
void SpatialEditorViewport::_select(Spatial *p_node, bool p_append, bool p_single) { void SpatialEditorViewport::_select(Node *p_node, bool p_append, bool p_single) {
if (!p_append) { if (!p_append) {
editor_selection->clear(); editor_selection->clear();
@@ -342,12 +342,10 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append,
continue; continue;
if (dist < closest_dist) { if (dist < closest_dist) {
//make sure that whathever is selected is editable
Node *owner = spat->get_owner(); item = Object::cast_to<Node>(spat);
if (owner != edited_scene && !edited_scene->is_editable_instance(owner)) { while (item->get_owner() && item->get_owner() != edited_scene && !edited_scene->is_editable_instance(item->get_owner())) {
item = owner; item = item->get_owner();
} else {
item = Object::cast_to<Node>(spat);
} }
closest = item->get_instance_id(); closest = item->get_instance_id();
@@ -498,7 +496,7 @@ void SpatialEditorViewport::_select_region() {
} }
Vector<ObjectID> instances = VisualServer::get_singleton()->instances_cull_convex(frustum, get_tree()->get_root()->get_world()->get_scenario()); Vector<ObjectID> instances = VisualServer::get_singleton()->instances_cull_convex(frustum, get_tree()->get_root()->get_world()->get_scenario());
Vector<Spatial *> selected; Vector<Node *> selected;
Node *edited_scene = get_tree()->get_edited_scene_root(); Node *edited_scene = get_tree()->get_edited_scene_root();
@@ -508,12 +506,12 @@ void SpatialEditorViewport::_select_region() {
if (!sp) if (!sp)
continue; continue;
Spatial *root_sp = sp; Node *item = Object::cast_to<Node>(sp);
while (root_sp && root_sp != edited_scene && root_sp->get_owner() != edited_scene && !edited_scene->is_editable_instance(root_sp->get_owner())) { while (item->get_owner() && item->get_owner() != edited_scene && !edited_scene->is_editable_instance(item->get_owner())) {
root_sp = Object::cast_to<Spatial>(root_sp->get_owner()); item = item->get_owner();
} }
if (selected.find(root_sp) != -1) continue; if (selected.find(item) != -1) continue;
Ref<EditorSpatialGizmo> seg = sp->get_gizmo(); Ref<EditorSpatialGizmo> seg = sp->get_gizmo();
@@ -521,7 +519,7 @@ void SpatialEditorViewport::_select_region() {
continue; continue;
if (seg->intersect_frustum(camera, frustum)) { if (seg->intersect_frustum(camera, frustum)) {
selected.push_back(root_sp); selected.push_back(item);
} }
} }
@@ -3913,8 +3911,9 @@ void _update_all_gizmos(Node *p_node) {
} }
} }
void SpatialEditor::update_all_gizmos() { void SpatialEditor::update_all_gizmos(Node *p_node) {
_update_all_gizmos(SceneTree::get_singleton()->get_root()); if (!p_node) p_node = SceneTree::get_singleton()->get_root();
_update_all_gizmos(p_node);
} }
Object *SpatialEditor::_get_editor_data(Object *p_what) { Object *SpatialEditor::_get_editor_data(Object *p_what) {
@@ -5663,7 +5662,7 @@ SpatialEditorPlugin::~SpatialEditorPlugin() {
void EditorSpatialGizmoPlugin::create_material(const String &p_name, const Color &p_color, bool p_billboard, bool p_on_top, bool p_use_vertex_color) { void EditorSpatialGizmoPlugin::create_material(const String &p_name, const Color &p_color, bool p_billboard, bool p_on_top, bool p_use_vertex_color) {
Color instanced_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/instanced", Color(0.7, 0.7, 0.7, 0.5)); Color instanced_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/instanced", Color(0.7, 0.7, 0.7, 0.6));
Vector<Ref<SpatialMaterial> > mats; Vector<Ref<SpatialMaterial> > mats;
@@ -5705,7 +5704,7 @@ void EditorSpatialGizmoPlugin::create_material(const String &p_name, const Color
void EditorSpatialGizmoPlugin::create_icon_material(const String &p_name, const Ref<Texture> &p_texture, bool p_on_top, const Color &p_albedo) { void EditorSpatialGizmoPlugin::create_icon_material(const String &p_name, const Ref<Texture> &p_texture, bool p_on_top, const Color &p_albedo) {
Color instanced_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/instanced", Color(0.7, 0.7, 0.7, 0.5)); Color instanced_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/instanced", Color(0.7, 0.7, 0.7, 0.6));
Vector<Ref<SpatialMaterial> > icons; Vector<Ref<SpatialMaterial> > icons;
@@ -5718,7 +5717,7 @@ void EditorSpatialGizmoPlugin::create_icon_material(const String &p_name, const
Color color = instanced ? instanced_color : p_albedo; Color color = instanced ? instanced_color : p_albedo;
if (!selected) { if (!selected) {
color.a *= 0.3; color.a *= 0.85;
} }
icon->set_albedo(color); icon->set_albedo(color);

View File

@@ -127,9 +127,7 @@ public:
virtual void redraw(); virtual void redraw();
virtual void free(); virtual void free();
//TODO remove (?)
virtual bool is_editable() const; virtual bool is_editable() const;
virtual bool can_draw() const;
void set_hidden(bool p_hidden); void set_hidden(bool p_hidden);
void set_plugin(EditorSpatialGizmoPlugin *p_gizmo); void set_plugin(EditorSpatialGizmoPlugin *p_gizmo);
@@ -226,7 +224,7 @@ private:
void _compute_edit(const Point2 &p_point); void _compute_edit(const Point2 &p_point);
void _clear_selected(); void _clear_selected();
void _select_clicked(bool p_append, bool p_single); void _select_clicked(bool p_append, bool p_single);
void _select(Spatial *p_node, bool p_append, bool p_single); void _select(Node *p_node, bool p_append, bool p_single);
ObjectID _select_ray(const Point2 &p_pos, bool p_append, bool &r_includes_current, int *r_gizmo_handle = NULL, bool p_alt_select = false); ObjectID _select_ray(const Point2 &p_pos, bool p_append, bool &r_includes_current, int *r_gizmo_handle = NULL, bool p_alt_select = false);
void _find_items_at_pos(const Point2 &p_pos, bool &r_includes_current, Vector<_RayResult> &results, bool p_alt_select = false); void _find_items_at_pos(const Point2 &p_pos, bool &r_includes_current, Vector<_RayResult> &results, bool p_alt_select = false);
Vector3 _get_ray_pos(const Vector2 &p_pos) const; Vector3 _get_ray_pos(const Vector2 &p_pos) const;
@@ -677,7 +675,7 @@ public:
Ref<ArrayMesh> get_scale_plane_gizmo(int idx) const { return scale_plane_gizmo[idx]; } Ref<ArrayMesh> get_scale_plane_gizmo(int idx) const { return scale_plane_gizmo[idx]; }
void update_transform_gizmo(); void update_transform_gizmo();
void update_all_gizmos(); void update_all_gizmos(Node *p_node = NULL);
void snap_selected_nodes_to_floor(); void snap_selected_nodes_to_floor();
void select_gizmo_highlight_axis(int p_axis); void select_gizmo_highlight_axis(int p_axis);
void set_custom_camera(Node *p_camera) { custom_camera = p_camera; } void set_custom_camera(Node *p_camera) { custom_camera = p_camera; }

View File

@@ -720,6 +720,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
node->set_scene_instance_load_placeholder(false); node->set_scene_instance_load_placeholder(false);
menu->set_item_checked(placeholder_item_idx, false); menu->set_item_checked(placeholder_item_idx, false);
} }
SpatialEditor::get_singleton()->update_all_gizmos(node);
scene_tree->update_tree(); scene_tree->update_tree();
} }
} }

View File

@@ -65,9 +65,6 @@
#define HANDLE_HALF_SIZE 9.5 #define HANDLE_HALF_SIZE 9.5
bool EditorSpatialGizmo::can_draw() const {
return is_editable();
}
bool EditorSpatialGizmo::is_editable() const { bool EditorSpatialGizmo::is_editable() const {
ERR_FAIL_COND_V(!spatial_node, false); ERR_FAIL_COND_V(!spatial_node, false);

View File

@@ -185,10 +185,8 @@ void Spatial::_notification(int p_what) {
if (data.gizmo.is_valid()) { if (data.gizmo.is_valid()) {
data.gizmo->create(); data.gizmo->create();
if (data.gizmo->can_draw()) { if (is_visible_in_tree()) {
if (is_visible_in_tree()) { data.gizmo->redraw();
data.gizmo->redraw();
}
} }
data.gizmo->transform(); data.gizmo->transform();
} }
@@ -423,10 +421,8 @@ void Spatial::set_gizmo(const Ref<SpatialGizmo> &p_gizmo) {
if (data.gizmo.is_valid() && is_inside_world()) { if (data.gizmo.is_valid() && is_inside_world()) {
data.gizmo->create(); data.gizmo->create();
if (data.gizmo->can_draw()) { if (is_visible_in_tree()) {
if (is_visible_in_tree()) { data.gizmo->redraw();
data.gizmo->redraw();
}
} }
data.gizmo->transform(); data.gizmo->transform();
} }
@@ -452,12 +448,10 @@ void Spatial::_update_gizmo() {
return; return;
data.gizmo_dirty = false; data.gizmo_dirty = false;
if (data.gizmo.is_valid()) { if (data.gizmo.is_valid()) {
if (data.gizmo->can_draw()) { if (is_visible_in_tree())
if (is_visible_in_tree()) data.gizmo->redraw();
data.gizmo->redraw(); else
else data.gizmo->clear();
data.gizmo->clear();
}
} }
#endif #endif
} }

View File

@@ -48,7 +48,6 @@ public:
virtual void clear() = 0; virtual void clear() = 0;
virtual void redraw() = 0; virtual void redraw() = 0;
virtual void free() = 0; virtual void free() = 0;
virtual bool can_draw() const = 0;
SpatialGizmo(); SpatialGizmo();
virtual ~SpatialGizmo() {} virtual ~SpatialGizmo() {}