summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Roubinsky <chaosus89@gmail.com>2022-01-12 16:07:09 +0300
committerGitHub <noreply@github.com>2022-01-12 16:07:09 +0300
commitb2ae6f838ac04cce8358434901f59c2b7198184a (patch)
tree2d5dcb764fce31cc1a907e3e6b756f4ba73aa84e
parent74d701b5b1a08d8db7cc5cc08f380949ea978562 (diff)
parentc381990fca6ecae7f510864548edd8b7ee392b42 (diff)
Merge pull request #56713 from Chaosus/vs_sampler_connection
Auto-set a port source for texture nodes created by dragged connection
-rw-r--r--editor/plugins/visual_shader_editor_plugin.cpp40
1 files changed, 26 insertions, 14 deletions
diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp
index 80419bb7da..f05ff72e5d 100644
--- a/editor/plugins/visual_shader_editor_plugin.cpp
+++ b/editor/plugins/visual_shader_editor_plugin.cpp
@@ -2445,6 +2445,14 @@ void VisualShaderEditor::_add_node(int p_idx, int p_op_idx, String p_resource_pa
vsnode->set_script(add_options[p_idx].script);
}
+ bool is_texture2d = (Object::cast_to<VisualShaderNodeTexture>(vsnode.ptr()) != nullptr);
+ bool is_texture3d = (Object::cast_to<VisualShaderNodeTexture3D>(vsnode.ptr()) != nullptr);
+ bool is_texture2d_array = (Object::cast_to<VisualShaderNodeTexture2DArray>(vsnode.ptr()) != nullptr);
+ bool is_cubemap = (Object::cast_to<VisualShaderNodeCubemap>(vsnode.ptr()) != nullptr);
+ bool is_curve = (Object::cast_to<VisualShaderNodeCurveTexture>(vsnode.ptr()) != nullptr);
+ bool is_curve_xyz = (Object::cast_to<VisualShaderNodeCurveXYZTexture>(vsnode.ptr()) != nullptr);
+ bool is_uniform = (Object::cast_to<VisualShaderNodeUniform>(vsnode.ptr()) != nullptr);
+
Point2 position = graph->get_scroll_ofs();
if (saved_node_pos_dirty) {
@@ -2570,23 +2578,32 @@ void VisualShaderEditor::_add_node(int p_idx, int p_op_idx, String p_resource_pa
}
}
}
+
+ if (output_port_type == VisualShaderNode::PORT_TYPE_SAMPLER) {
+ if (is_texture2d) {
+ undo_redo->add_do_method(vsnode.ptr(), "set_source", VisualShaderNodeTexture::SOURCE_PORT);
+ }
+ if (is_texture3d || is_texture2d_array) {
+ undo_redo->add_do_method(vsnode.ptr(), "set_source", VisualShaderNodeSample3D::SOURCE_PORT);
+ }
+ if (is_cubemap) {
+ undo_redo->add_do_method(vsnode.ptr(), "set_source", VisualShaderNodeCubemap::SOURCE_PORT);
+ }
+ }
}
}
_member_cancel();
- VisualShaderNodeUniform *uniform = Object::cast_to<VisualShaderNodeUniform>(vsnode.ptr());
- if (uniform) {
+ if (is_uniform) {
undo_redo->add_do_method(this, "_update_uniforms", true);
undo_redo->add_undo_method(this, "_update_uniforms", true);
}
- VisualShaderNodeCurveTexture *curve = Object::cast_to<VisualShaderNodeCurveTexture>(vsnode.ptr());
- if (curve) {
+ if (is_curve) {
graph_plugin->call_deferred(SNAME("update_curve"), id_to_use);
}
- VisualShaderNodeCurveXYZTexture *curve_xyz = Object::cast_to<VisualShaderNodeCurveXYZTexture>(vsnode.ptr());
- if (curve_xyz) {
+ if (is_curve_xyz) {
graph_plugin->call_deferred(SNAME("update_curve_xyz"), id_to_use);
}
@@ -2595,22 +2612,17 @@ void VisualShaderEditor::_add_node(int p_idx, int p_op_idx, String p_resource_pa
} else {
//post-initialization
- VisualShaderNodeTexture *texture2d = Object::cast_to<VisualShaderNodeTexture>(vsnode.ptr());
- VisualShaderNodeTexture3D *texture3d = Object::cast_to<VisualShaderNodeTexture3D>(vsnode.ptr());
-
- if (texture2d || texture3d || curve || curve_xyz) {
+ if (is_texture2d || is_texture3d || is_curve || is_curve_xyz) {
undo_redo->add_do_method(vsnode.ptr(), "set_texture", ResourceLoader::load(p_resource_path));
return;
}
- VisualShaderNodeCubemap *cubemap = Object::cast_to<VisualShaderNodeCubemap>(vsnode.ptr());
- if (cubemap) {
+ if (is_cubemap) {
undo_redo->add_do_method(vsnode.ptr(), "set_cube_map", ResourceLoader::load(p_resource_path));
return;
}
- VisualShaderNodeTexture2DArray *texture2d_array = Object::cast_to<VisualShaderNodeTexture2DArray>(vsnode.ptr());
- if (texture2d_array) {
+ if (is_texture2d_array) {
undo_redo->add_do_method(vsnode.ptr(), "set_texture_array", ResourceLoader::load(p_resource_path));
}
}