Skip to content

Commit

Permalink
Allow editing VSG
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometror committed Nov 4, 2024
1 parent f3de8f6 commit 803a12e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 75 deletions.
7 changes: 7 additions & 0 deletions editor/plugins/visual_shader_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2440,6 +2440,13 @@ void VisualShaderEditor::_set_mode(int p_which) {

void VisualShaderEditor::_edit_group(int p_idx) {
print_line("Edit group: " + itos(p_idx));

Ref<VisualShaderNodeGroup> group = editing_shader_graph->get_node(p_idx);
ERR_FAIL_COND(group.is_null());
editing_visual_shader_group = group->get_group();
editing_shader_graph = editing_visual_shader_group->get_graph().ptr();

_update_graph();
}

Size2 VisualShaderEditor::get_minimum_size() const {
Expand Down
2 changes: 1 addition & 1 deletion scene/resources/visual_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void ShaderGraph::_bind_methods() {
ClassDB::bind_method(D_METHOD("disconnect_nodes", "from_node", "from_port", "to_node", "to_port"), &ShaderGraph::disconnect_nodes);
ClassDB::bind_method(D_METHOD("connect_nodes_forced", "from_node", "from_port", "to_node", "to_port"), &ShaderGraph::connect_nodes_forced);

ClassDB::bind_method(D_METHOD("get_node_connections", "type"), &ShaderGraph::get_node_connections);
// ClassDB::bind_method(D_METHOD("get_node_connections", "type"), &ShaderGraph::get_node_connections);

ClassDB::bind_method(D_METHOD("attach_node_to_frame", "id", "frame"), &ShaderGraph::attach_node_to_frame);
ClassDB::bind_method(D_METHOD("detach_node_from_frame", "id"), &ShaderGraph::detach_node_from_frame);
Expand Down
148 changes: 74 additions & 74 deletions scene/resources/visual_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,80 +328,6 @@ VARIANT_ENUM_CAST(VisualShader::Type)
VARIANT_ENUM_CAST(VisualShader::VaryingMode)
VARIANT_ENUM_CAST(VisualShader::VaryingType)

class VisualShaderGroup : public Resource {
GDCLASS(VisualShaderGroup, Resource);

public:
struct Port {
VisualShaderNode::PortType type = VisualShaderNode::PortType::PORT_TYPE_MAX;
String name;
};

private:
HashMap<int, Port> input_ports;
HashMap<int, Port> output_ports;

Ref<ShaderGraph> graph;

inline static int NODE_ID_GROUP_INPUT = 0;
inline static int NODE_ID_GROUP_OUTPUT = 1;

protected:
static void _bind_methods();

public:
Ref<ShaderGraph> get_graph() const;

void add_input_port(int p_id, VisualShaderNode::PortType p_type, const String &p_name);
Port get_input_port(int p_id) const;
Vector<Port> get_input_ports() const;
void remove_input_port(int p_id);

void add_output_port(int p_id, VisualShaderNode::PortType p_type, const String &p_name);
Port get_output_port(int p_id) const;
Vector<Port> get_output_ports() const;
void remove_output_port(int p_id);

void add_node(const Ref<VisualShaderNode> &p_node, const Vector2 &p_position, int p_id);
void set_node_position(int p_id, const Vector2 &p_position);
Vector2 get_node_position(int p_id) const;
Ref<VisualShaderNode> get_node(int p_id) const;

Vector<int> get_node_ids() const;
int get_valid_node_id() const;
int find_node_id(const Ref<VisualShaderNode> &p_node) const;
void remove_node(int p_id);
void replace_node(int p_id, const StringName &p_new_class);

// TODO: Rename this method and evaluate whether it is necessary.
bool are_nodes_connected(int p_from_node, int p_from_port, int p_to_node, int p_to_port) const;

// TODO: Do you need the graph as a parameter
bool is_nodes_connected_relatively(int p_node, int p_target) const;
bool can_connect_nodes(int p_from_node, int p_from_port, int p_to_node, int p_to_port) const;
Error connect_nodes(int p_from_node, int p_from_port, int p_to_node, int p_to_port);
void disconnect_nodes(int p_from_node, int p_from_port, int p_to_node, int p_to_port);
void connect_nodes_forced(int p_from_node, int p_from_port, int p_to_node, int p_to_port);
bool is_port_types_compatible(int p_a, int p_b) const;

void attach_node_to_frame(int p_node, int p_frame);
void detach_node_from_frame(int p_node);

String get_reroute_parameter_name(int p_reroute_node) const;

// TODO: Maybe change this method to use a return type.

void get_node_connections(List<ShaderGraph::Connection> *r_connections) const;
// TODO: Implement?
String generate_preview_shader(int p_node, int p_port, Vector<ShaderGraph::DefaultTextureParam> &r_default_tex_params) const;

String validate_port_name(const String &p_port_name, VisualShaderNode *p_node, int p_port_id, bool p_output) const;
// TODO: Implement?
String validate_parameter_name(const String &p_name, const Ref<VisualShaderNodeParameter> &p_parameter) const;

VisualShaderGroup();
};

class VisualShaderNode : public Resource {
GDCLASS(VisualShaderNode, Resource);

Expand Down Expand Up @@ -527,6 +453,80 @@ class VisualShaderNode : public Resource {

VARIANT_ENUM_CAST(VisualShaderNode::PortType)

class VisualShaderGroup : public Resource {
GDCLASS(VisualShaderGroup, Resource);

public:
struct Port {
VisualShaderNode::PortType type = VisualShaderNode::PortType::PORT_TYPE_MAX;
String name;
};

private:
HashMap<int, Port> input_ports;
HashMap<int, Port> output_ports;

Ref<ShaderGraph> graph;

inline static int NODE_ID_GROUP_INPUT = 0;
inline static int NODE_ID_GROUP_OUTPUT = 1;

protected:
static void _bind_methods();

public:
Ref<ShaderGraph> get_graph() const;

void add_input_port(int p_id, VisualShaderNode::PortType p_type, const String &p_name);
Port get_input_port(int p_id) const;
Vector<Port> get_input_ports() const;
void remove_input_port(int p_id);

void add_output_port(int p_id, VisualShaderNode::PortType p_type, const String &p_name);
Port get_output_port(int p_id) const;
Vector<Port> get_output_ports() const;
void remove_output_port(int p_id);

void add_node(const Ref<VisualShaderNode> &p_node, const Vector2 &p_position, int p_id);
void set_node_position(int p_id, const Vector2 &p_position);
Vector2 get_node_position(int p_id) const;
Ref<VisualShaderNode> get_node(int p_id) const;

Vector<int> get_node_ids() const;
int get_valid_node_id() const;
int find_node_id(const Ref<VisualShaderNode> &p_node) const;
void remove_node(int p_id);
void replace_node(int p_id, const StringName &p_new_class);

// TODO: Rename this method and evaluate whether it is necessary.
bool are_nodes_connected(int p_from_node, int p_from_port, int p_to_node, int p_to_port) const;

// TODO: Do you need the graph as a parameter
bool is_nodes_connected_relatively(int p_node, int p_target) const;
bool can_connect_nodes(int p_from_node, int p_from_port, int p_to_node, int p_to_port) const;
Error connect_nodes(int p_from_node, int p_from_port, int p_to_node, int p_to_port);
void disconnect_nodes(int p_from_node, int p_from_port, int p_to_node, int p_to_port);
void connect_nodes_forced(int p_from_node, int p_from_port, int p_to_node, int p_to_port);
bool is_port_types_compatible(int p_a, int p_b) const;

void attach_node_to_frame(int p_node, int p_frame);
void detach_node_from_frame(int p_node);

String get_reroute_parameter_name(int p_reroute_node) const;

// TODO: Maybe change this method to use a return type.

void get_node_connections(List<ShaderGraph::Connection> *r_connections) const;
// TODO: Implement?
String generate_preview_shader(int p_node, int p_port, Vector<ShaderGraph::DefaultTextureParam> &r_default_tex_params) const;

String validate_port_name(const String &p_port_name, VisualShaderNode *p_node, int p_port_id, bool p_output) const;
// TODO: Implement?
String validate_parameter_name(const String &p_name, const Ref<VisualShaderNodeParameter> &p_parameter) const;

VisualShaderGroup();
};

class VisualShaderNodeCustom : public VisualShaderNode {
GDCLASS(VisualShaderNodeCustom, VisualShaderNode);

Expand Down

0 comments on commit 803a12e

Please sign in to comment.