summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/plugins/mesh_instance_3d_editor_plugin.cpp1
-rw-r--r--editor/plugins/visual_shader_editor_plugin.cpp103
-rw-r--r--editor/plugins/visual_shader_editor_plugin.h5
3 files changed, 40 insertions, 69 deletions
diff --git a/editor/plugins/mesh_instance_3d_editor_plugin.cpp b/editor/plugins/mesh_instance_3d_editor_plugin.cpp
index 1b65987af0..5b241deab0 100644
--- a/editor/plugins/mesh_instance_3d_editor_plugin.cpp
+++ b/editor/plugins/mesh_instance_3d_editor_plugin.cpp
@@ -138,6 +138,7 @@ void MeshInstance3DEditor::_menu_option(int p_option) {
CollisionShape3D *cshape = memnew(CollisionShape3D);
cshape->set_shape(shape);
+ cshape->set_transform(node->get_transform());
Node *owner = node->get_owner();
diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp
index 991d012d59..e34f0855b2 100644
--- a/editor/plugins/visual_shader_editor_plugin.cpp
+++ b/editor/plugins/visual_shader_editor_plugin.cpp
@@ -142,42 +142,8 @@ void VisualShaderGraphPlugin::update_property_editor(VisualShader::Type p_type,
if (p_type != visual_shader->get_shader_type() || !links.has(p_node_id)) {
return;
}
- Control *custom_editor = links[p_node_id].custom_editor;
- if (custom_editor != nullptr) {
- links[p_node_id].graph_node->remove_child(custom_editor);
- memdelete(custom_editor);
- custom_editor = nullptr;
- }
-
- links[p_node_id].visual_node->set_meta("id", p_node_id);
- links[p_node_id].visual_node->set_meta("shader_type", (int)p_type);
-
- for (int i = 0; i < VisualShaderEditor::get_singleton()->plugins.size(); i++) {
- custom_editor = VisualShaderEditor::get_singleton()->plugins.write[i]->create_editor(visual_shader, links[p_node_id].visual_node);
- if (custom_editor) {
- break;
- }
- }
- links[p_node_id].visual_node->remove_meta("id");
- links[p_node_id].visual_node->remove_meta("shader_type");
- links[p_node_id].custom_editor = custom_editor;
- if (custom_editor) {
- links[p_node_id].graph_node->add_child(custom_editor);
- links[p_node_id].graph_node->move_child(custom_editor, links[p_node_id].editor_pos);
-
- Ref<VisualShaderNode> vsnode = Ref<VisualShaderNode>(links[p_node_id].visual_node);
- Ref<VisualShaderNodeFloatUniform> float_uniform = vsnode;
- Ref<VisualShaderNodeIntUniform> int_uniform = vsnode;
- Ref<VisualShaderNodeVec3Uniform> vec3_uniform = vsnode;
- Ref<VisualShaderNodeColorUniform> color_uniform = vsnode;
- Ref<VisualShaderNodeBooleanUniform> bool_uniform = vsnode;
- Ref<VisualShaderNodeTransformUniform> transform_uniform = vsnode;
-
- if (float_uniform.is_valid() || int_uniform.is_valid() || vec3_uniform.is_valid() || color_uniform.is_valid() || bool_uniform.is_valid() || transform_uniform.is_valid()) {
- custom_editor->call_deferred("_show_prop_names", true);
- }
- }
- links[p_node_id].graph_node->set_size(Vector2(-1, -1));
+ remove_node(p_type, p_node_id);
+ add_node(p_type, p_node_id);
}
void VisualShaderGraphPlugin::set_input_port_default_value(VisualShader::Type p_type, int p_node_id, int p_port_id, Variant p_value) {
@@ -247,21 +213,13 @@ void VisualShaderGraphPlugin::make_dirty(bool p_enabled) {
}
void VisualShaderGraphPlugin::register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphNode *p_graph_node) {
- links.insert(p_id, { p_type, p_visual_node, p_graph_node, p_visual_node->get_output_port_for_preview() != -1, -1, Map<int, InputPort>(), Map<int, Port>(), nullptr, nullptr, -1 });
+ links.insert(p_id, { p_type, p_visual_node, p_graph_node, p_visual_node->get_output_port_for_preview() != -1, -1, Map<int, InputPort>(), Map<int, Port>(), nullptr });
}
void VisualShaderGraphPlugin::register_output_port(int p_node_id, int p_port, TextureButton *p_button) {
links[p_node_id].output_ports.insert(p_port, { p_button });
}
-void VisualShaderGraphPlugin::register_custom_editor(int p_node_id, Control *p_custom_editor) {
- links[p_node_id].custom_editor = p_custom_editor;
-}
-
-void VisualShaderGraphPlugin::register_editor_pos(int p_node_id, int p_pos) {
- links[p_node_id].editor_pos = p_pos;
-}
-
void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) {
if (p_type != visual_shader->get_shader_type()) {
return;
@@ -379,10 +337,8 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) {
if (custom_editor && !float_uniform.is_valid() && !int_uniform.is_valid() && !vec3_uniform.is_valid() && !bool_uniform.is_valid() && !transform_uniform.is_valid() && vsnode->get_output_port_count() > 0 && vsnode->get_output_port_name(0) == "" && (vsnode->get_input_port_count() == 0 || vsnode->get_input_port_name(0) == "")) {
//will be embedded in first port
} else if (custom_editor) {
- register_editor_pos(p_id, port_offset);
port_offset++;
node->add_child(custom_editor);
- register_custom_editor(p_id, custom_editor);
if (color_uniform.is_valid()) {
custom_editor->call_deferred("_show_prop_names", true);
}
@@ -454,12 +410,14 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) {
default_value = vsnode->get_input_port_default_value(i);
}
+ Button *button = memnew(Button);
+ hb->add_child(button);
+ register_default_input_button(p_id, i, button);
+ button->connect("pressed", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_edit_port_default_input), varray(button, p_id, i));
if (default_value.get_type() != Variant::NIL) { // only a label
- Button *button = memnew(Button);
- hb->add_child(button);
- button->connect("pressed", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_edit_port_default_input), varray(button, p_id, i));
- register_default_input_button(p_id, i, button);
set_input_port_default_value(p_type, p_id, i, default_value);
+ } else {
+ button->hide();
}
if (i == 0 && custom_editor) {
@@ -654,12 +612,19 @@ void VisualShaderGraphPlugin::remove_node(VisualShader::Type p_type, int p_id) {
void VisualShaderGraphPlugin::connect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) {
if (visual_shader->get_shader_type() == p_type) {
VisualShaderEditor::get_singleton()->graph->connect_node(itos(p_from_node), p_from_port, itos(p_to_node), p_to_port);
+ if (links[p_to_node].input_ports.has(p_to_port) && links[p_to_node].input_ports[p_to_port].default_input_button != nullptr) {
+ links[p_to_node].input_ports[p_to_port].default_input_button->hide();
+ }
}
}
void VisualShaderGraphPlugin::disconnect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) {
if (visual_shader->get_shader_type() == p_type) {
VisualShaderEditor::get_singleton()->graph->disconnect_node(itos(p_from_node), p_from_port, itos(p_to_node), p_to_port);
+ if (links[p_to_node].input_ports.has(p_to_port) && links[p_to_node].input_ports[p_to_port].default_input_button != nullptr && links[p_to_node].visual_node->get_input_port_default_value(p_to_port).get_type() != Variant::NIL) {
+ links[p_to_node].input_ports[p_to_port].default_input_button->show();
+ set_input_port_default_value(p_type, p_to_node, p_to_port, links[p_to_node].visual_node->get_input_port_default_value(p_to_port));
+ }
}
}
@@ -690,19 +655,7 @@ void VisualShaderEditor::edit(VisualShader *p_visual_shader) {
}
#endif
visual_shader->set_graph_offset(graph->get_scroll_ofs() / EDSCALE);
-
- if (visual_shader->get_mode() == VisualShader::MODE_PARTICLES) {
- edit_type_standart->set_visible(false);
- edit_type_particles->set_visible(true);
- edit_type = edit_type_particles;
- particles_mode = true;
- } else {
- edit_type_particles->set_visible(false);
- edit_type_standart->set_visible(true);
- edit_type = edit_type_standart;
- particles_mode = false;
- }
- visual_shader->set_shader_type(get_current_shader_type());
+ _set_mode(visual_shader->get_mode());
} else {
if (visual_shader.is_valid()) {
if (visual_shader->is_connected("changed", callable_mp(this, &VisualShaderEditor::_update_preview))) {
@@ -1010,6 +963,21 @@ void VisualShaderEditor::_update_options_menu() {
}
}
+void VisualShaderEditor::_set_mode(int p_which) {
+ if (p_which == VisualShader::MODE_PARTICLES) {
+ edit_type_standart->set_visible(false);
+ edit_type_particles->set_visible(true);
+ edit_type = edit_type_particles;
+ particles_mode = true;
+ } else {
+ edit_type_particles->set_visible(false);
+ edit_type_standart->set_visible(true);
+ edit_type = edit_type_standart;
+ particles_mode = false;
+ }
+ visual_shader->set_shader_type(get_current_shader_type());
+}
+
Size2 VisualShaderEditor::get_minimum_size() const {
return Size2(10, 200);
}
@@ -2308,7 +2276,7 @@ void VisualShaderEditor::_delete_nodes() {
}
void VisualShaderEditor::_mode_selected(int p_id) {
- visual_shader->set_shader_type(VisualShader::Type(p_id));
+ visual_shader->set_shader_type(particles_mode ? VisualShader::Type(p_id + 3) : VisualShader::Type(p_id));
_update_options_menu();
_update_graph();
}
@@ -2611,6 +2579,7 @@ void VisualShaderEditor::_bind_methods() {
ClassDB::bind_method("_set_node_size", &VisualShaderEditor::_set_node_size);
ClassDB::bind_method("_clear_buffer", &VisualShaderEditor::_clear_buffer);
ClassDB::bind_method("_update_uniforms", &VisualShaderEditor::_update_uniforms);
+ ClassDB::bind_method("_set_mode", &VisualShaderEditor::_set_mode);
ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &VisualShaderEditor::get_drag_data_fw);
ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &VisualShaderEditor::can_drop_data_fw);
@@ -3628,6 +3597,10 @@ void EditorPropertyShaderMode::_option_selected(int p_which) {
//do is easy
undo_redo->add_do_method(visual_shader.ptr(), "set_mode", p_which);
undo_redo->add_undo_method(visual_shader.ptr(), "set_mode", visual_shader->get_mode());
+
+ undo_redo->add_do_method(VisualShaderEditor::get_singleton(), "_set_mode", p_which);
+ undo_redo->add_undo_method(VisualShaderEditor::get_singleton(), "_set_mode", visual_shader->get_mode());
+
//now undo is hell
//1. restore connections to output
diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h
index c961a05f45..056d4c6a11 100644
--- a/editor/plugins/visual_shader_editor_plugin.h
+++ b/editor/plugins/visual_shader_editor_plugin.h
@@ -71,8 +71,6 @@ private:
Map<int, InputPort> input_ports;
Map<int, Port> output_ports;
VBoxContainer *preview_box;
- Control *custom_editor;
- int editor_pos;
};
Ref<VisualShader> visual_shader;
@@ -88,8 +86,6 @@ public:
void set_connections(List<VisualShader::Connection> &p_connections);
void register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphNode *p_graph_node);
void register_output_port(int p_id, int p_port, TextureButton *p_button);
- void register_custom_editor(int p_node_id, Control *p_custom_editor);
- void register_editor_pos(int p_node_id, int p_pos);
void clear_links();
void set_shader_type(VisualShader::Type p_type);
bool is_preview_visible(int p_id) const;
@@ -251,6 +247,7 @@ class VisualShaderEditor : public VBoxContainer {
void _add_texture_node(const String &p_path);
VisualShaderNode *_add_node(int p_idx, int p_op_idx = -1);
void _update_options_menu();
+ void _set_mode(int p_which);
void _show_preview_text();
void _update_preview();