You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-17 14:11:06 +00:00
Added drag&drop possibility for textures from filesystem to visual shader
This commit is contained in:
@@ -1213,9 +1213,14 @@ void VisualShaderEditor::_edit_port_default_input(Object *p_button, int p_node,
|
|||||||
editing_port = p_port;
|
editing_port = p_port;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualShaderEditor::_add_node(int p_idx, int p_op_idx) {
|
void VisualShaderEditor::_add_texture_node(const String &p_path) {
|
||||||
|
VisualShaderNodeTexture *texture = (VisualShaderNodeTexture *)_add_node(texture_node_option_idx, -1);
|
||||||
|
texture->set_texture(ResourceLoader::load(p_path));
|
||||||
|
}
|
||||||
|
|
||||||
ERR_FAIL_INDEX(p_idx, add_options.size());
|
VisualShaderNode *VisualShaderEditor::_add_node(int p_idx, int p_op_idx) {
|
||||||
|
|
||||||
|
ERR_FAIL_INDEX_V(p_idx, add_options.size(), NULL);
|
||||||
|
|
||||||
Ref<VisualShaderNode> vsnode;
|
Ref<VisualShaderNode> vsnode;
|
||||||
|
|
||||||
@@ -1223,7 +1228,7 @@ void VisualShaderEditor::_add_node(int p_idx, int p_op_idx) {
|
|||||||
|
|
||||||
if (!is_custom && add_options[p_idx].type != String()) {
|
if (!is_custom && add_options[p_idx].type != String()) {
|
||||||
VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instance(add_options[p_idx].type));
|
VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instance(add_options[p_idx].type));
|
||||||
ERR_FAIL_COND(!vsn);
|
ERR_FAIL_COND_V(!vsn, NULL);
|
||||||
|
|
||||||
VisualShaderNodeScalarConstant *constant = Object::cast_to<VisualShaderNodeScalarConstant>(vsn);
|
VisualShaderNodeScalarConstant *constant = Object::cast_to<VisualShaderNodeScalarConstant>(vsn);
|
||||||
|
|
||||||
@@ -1309,10 +1314,10 @@ void VisualShaderEditor::_add_node(int p_idx, int p_op_idx) {
|
|||||||
|
|
||||||
vsnode = Ref<VisualShaderNode>(vsn);
|
vsnode = Ref<VisualShaderNode>(vsn);
|
||||||
} else {
|
} else {
|
||||||
ERR_FAIL_COND(add_options[p_idx].script.is_null());
|
ERR_FAIL_COND_V(add_options[p_idx].script.is_null(), NULL);
|
||||||
String base_type = add_options[p_idx].script->get_instance_base_type();
|
String base_type = add_options[p_idx].script->get_instance_base_type();
|
||||||
VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instance(base_type));
|
VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instance(base_type));
|
||||||
ERR_FAIL_COND(!vsn);
|
ERR_FAIL_COND_V(!vsn, NULL);
|
||||||
vsnode = Ref<VisualShaderNode>(vsn);
|
vsnode = Ref<VisualShaderNode>(vsn);
|
||||||
vsnode->set_script(add_options[p_idx].script.get_ref_ptr());
|
vsnode->set_script(add_options[p_idx].script.get_ref_ptr());
|
||||||
}
|
}
|
||||||
@@ -1367,6 +1372,7 @@ void VisualShaderEditor::_add_node(int p_idx, int p_op_idx) {
|
|||||||
undo_redo->add_do_method(this, "_update_graph");
|
undo_redo->add_do_method(this, "_update_graph");
|
||||||
undo_redo->add_undo_method(this, "_update_graph");
|
undo_redo->add_undo_method(this, "_update_graph");
|
||||||
undo_redo->commit_action();
|
undo_redo->commit_action();
|
||||||
|
return vsnode.ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualShaderEditor::_node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node) {
|
void VisualShaderEditor::_node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node) {
|
||||||
@@ -2038,6 +2044,9 @@ bool VisualShaderEditor::can_drop_data_fw(const Point2 &p_point, const Variant &
|
|||||||
if (d.has("id")) {
|
if (d.has("id")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (d.has("files")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -2054,6 +2063,20 @@ void VisualShaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
|
|||||||
saved_node_pos = p_point;
|
saved_node_pos = p_point;
|
||||||
saved_node_pos_dirty = true;
|
saved_node_pos_dirty = true;
|
||||||
_add_node(idx, add_options[idx].sub_func);
|
_add_node(idx, add_options[idx].sub_func);
|
||||||
|
} else if (d.has("files")) {
|
||||||
|
if (d["files"].get_type() == Variant::POOL_STRING_ARRAY) {
|
||||||
|
|
||||||
|
PoolStringArray arr = d["files"];
|
||||||
|
for (int i = 0; i < arr.size(); i++) {
|
||||||
|
|
||||||
|
String type = ResourceLoader::get_resource_type(arr[i]);
|
||||||
|
if (ClassDB::get_parent_class(type) == "Texture") {
|
||||||
|
saved_node_pos = p_point + Vector2(0, i * 210 * EDSCALE);
|
||||||
|
saved_node_pos_dirty = true;
|
||||||
|
_add_texture_node(arr[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2558,6 +2581,7 @@ VisualShaderEditor::VisualShaderEditor() {
|
|||||||
// TEXTURES
|
// TEXTURES
|
||||||
|
|
||||||
add_options.push_back(AddOption("CubeMap", "Textures", "Functions", "VisualShaderNodeCubeMap", TTR("Perform the cubic texture lookup."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR));
|
add_options.push_back(AddOption("CubeMap", "Textures", "Functions", "VisualShaderNodeCubeMap", TTR("Perform the cubic texture lookup."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR));
|
||||||
|
texture_node_option_idx = add_options.size();
|
||||||
add_options.push_back(AddOption("Texture", "Textures", "Functions", "VisualShaderNodeTexture", TTR("Perform the texture lookup."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR));
|
add_options.push_back(AddOption("Texture", "Textures", "Functions", "VisualShaderNodeTexture", TTR("Perform the texture lookup."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR));
|
||||||
|
|
||||||
add_options.push_back(AddOption("CubeMapUniform", "Textures", "Variables", "VisualShaderNodeCubeMapUniform", TTR("Cubic texture uniform lookup."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR));
|
add_options.push_back(AddOption("CubeMapUniform", "Textures", "Variables", "VisualShaderNodeCubeMapUniform", TTR("Cubic texture uniform lookup."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR));
|
||||||
|
|||||||
@@ -148,11 +148,13 @@ class VisualShaderEditor : public VBoxContainer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Vector<AddOption> add_options;
|
Vector<AddOption> add_options;
|
||||||
|
int texture_node_option_idx;
|
||||||
List<String> keyword_list;
|
List<String> keyword_list;
|
||||||
|
|
||||||
void _draw_color_over_button(Object *obj, Color p_color);
|
void _draw_color_over_button(Object *obj, Color p_color);
|
||||||
|
|
||||||
void _add_node(int p_idx, int p_op_idx = -1);
|
void _add_texture_node(const String &p_path);
|
||||||
|
VisualShaderNode *_add_node(int p_idx, int p_op_idx = -1);
|
||||||
void _update_custom_nodes();
|
void _update_custom_nodes();
|
||||||
void _update_options_menu();
|
void _update_options_menu();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user