Merge pull request #56713 from Chaosus/vs_sampler_connection
Auto-set a port source for texture nodes created by dragged connection
This commit is contained in:
commit
b2ae6f838a
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue