summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/concave_polygon_shape_2d.cpp2
-rw-r--r--scene/resources/default_theme/default_theme.cpp2
-rw-r--r--scene/resources/multimesh.cpp8
-rw-r--r--scene/resources/particles_material.cpp35
-rw-r--r--scene/resources/particles_material.h5
-rw-r--r--scene/resources/primitive_meshes.cpp2
-rw-r--r--scene/resources/resource_format_text.cpp4
-rw-r--r--scene/resources/texture.cpp3
-rw-r--r--scene/resources/tile_set.cpp29
-rw-r--r--scene/resources/visual_shader.cpp48
-rw-r--r--scene/resources/visual_shader.h3
-rw-r--r--scene/resources/visual_shader_nodes.h8
12 files changed, 113 insertions, 36 deletions
diff --git a/scene/resources/concave_polygon_shape_2d.cpp b/scene/resources/concave_polygon_shape_2d.cpp
index 51dd91fff5..de853f0c30 100644
--- a/scene/resources/concave_polygon_shape_2d.cpp
+++ b/scene/resources/concave_polygon_shape_2d.cpp
@@ -104,4 +104,6 @@ void ConcavePolygonShape2D::_bind_methods() {
ConcavePolygonShape2D::ConcavePolygonShape2D() :
Shape2D(Physics2DServer::get_singleton()->concave_polygon_shape_create()) {
+ PoolVector<Vector2> empty;
+ set_segments(empty);
}
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp
index 2c5dfc375c..4e2fe1f9b2 100644
--- a/scene/resources/default_theme/default_theme.cpp
+++ b/scene/resources/default_theme/default_theme.cpp
@@ -398,6 +398,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_color("font_color", "LineEdit", control_font_color);
theme->set_color("font_color_selected", "LineEdit", Color(0, 0, 0));
+ theme->set_color("font_color_uneditable", "LineEdit", Color(control_font_color.r, control_font_color.g, control_font_color.b, 0.5f));
theme->set_color("cursor_color", "LineEdit", control_font_color_hover);
theme->set_color("selection_color", "LineEdit", font_color_selection);
theme->set_color("clear_button_color", "LineEdit", control_font_color);
@@ -439,6 +440,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_color("completion_font_color", "TextEdit", Color::html("aaaaaa"));
theme->set_color("font_color", "TextEdit", control_font_color);
theme->set_color("font_color_selected", "TextEdit", Color(0, 0, 0));
+ theme->set_color("font_color_readonly", "TextEdit", Color(control_font_color.r, control_font_color.g, control_font_color.b, 0.5f));
theme->set_color("selection_color", "TextEdit", font_color_selection);
theme->set_color("mark_color", "TextEdit", Color(1.0, 0.4, 0.4, 0.4));
theme->set_color("bookmark_color", "TextEdit", Color(0.08, 0.49, 0.98));
diff --git a/scene/resources/multimesh.cpp b/scene/resources/multimesh.cpp
index 5d8adc0c8d..99a17fb5b9 100644
--- a/scene/resources/multimesh.cpp
+++ b/scene/resources/multimesh.cpp
@@ -35,7 +35,7 @@ void MultiMesh::_set_transform_array(const PoolVector<Vector3> &p_array) {
if (transform_format != TRANSFORM_3D)
return;
- PoolVector<Vector3> xforms = p_array;
+ const PoolVector<Vector3> &xforms = p_array;
int len = xforms.size();
ERR_FAIL_COND((len / 4) != instance_count);
if (len == 0)
@@ -85,7 +85,7 @@ void MultiMesh::_set_transform_2d_array(const PoolVector<Vector2> &p_array) {
if (transform_format != TRANSFORM_2D)
return;
- PoolVector<Vector2> xforms = p_array;
+ const PoolVector<Vector2> &xforms = p_array;
int len = xforms.size();
ERR_FAIL_COND((len / 3) != instance_count);
if (len == 0)
@@ -130,7 +130,7 @@ PoolVector<Vector2> MultiMesh::_get_transform_2d_array() const {
void MultiMesh::_set_color_array(const PoolVector<Color> &p_array) {
- PoolVector<Color> colors = p_array;
+ const PoolVector<Color> &colors = p_array;
int len = colors.size();
if (len == 0)
return;
@@ -162,7 +162,7 @@ PoolVector<Color> MultiMesh::_get_color_array() const {
void MultiMesh::_set_custom_data_array(const PoolVector<Color> &p_array) {
- PoolVector<Color> custom_datas = p_array;
+ const PoolVector<Color> &custom_datas = p_array;
int len = custom_datas.size();
if (len == 0)
return;
diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp
index a80a57a09c..edca9e5171 100644
--- a/scene/resources/particles_material.cpp
+++ b/scene/resources/particles_material.cpp
@@ -45,6 +45,7 @@ void ParticlesMaterial::init_shaders() {
shader_names = memnew(ShaderNames);
+ shader_names->direction = "direction";
shader_names->spread = "spread";
shader_names->flatness = "flatness";
shader_names->initial_linear_velocity = "initial_linear_velocity";
@@ -144,6 +145,7 @@ void ParticlesMaterial::_update_shader() {
String code = "shader_type particles;\n";
+ code += "uniform vec3 direction;\n";
code += "uniform float spread;\n";
code += "uniform float flatness;\n";
code += "uniform float initial_linear_velocity;\n";
@@ -184,7 +186,8 @@ void ParticlesMaterial::_update_shader() {
} break;
case EMISSION_SHAPE_DIRECTED_POINTS: {
code += "uniform sampler2D emission_texture_normal : hint_black;\n";
- } //fallthrough
+ FALLTHROUGH;
+ }
case EMISSION_SHAPE_POINTS: {
code += "uniform sampler2D emission_texture_points : hint_black;\n";
code += "uniform int emission_texture_point_count;\n";
@@ -303,20 +306,20 @@ void ParticlesMaterial::_update_shader() {
if (flags[FLAG_DISABLE_Z]) {
- code += " float angle1_rad = rand_from_seed_m1_p1(alt_seed) * spread_rad;\n";
+ code += " float angle1_rad = atan(direction.y, direction.x) + rand_from_seed_m1_p1(alt_seed) * spread_rad;\n";
code += " vec3 rot = vec3(cos(angle1_rad), sin(angle1_rad), 0.0);\n";
code += " VELOCITY = rot * initial_linear_velocity * mix(1.0, rand_from_seed(alt_seed), initial_linear_velocity_random);\n";
} else {
//initiate velocity spread in 3D
- code += " float angle1_rad = rand_from_seed_m1_p1(alt_seed) * spread_rad;\n";
- code += " float angle2_rad = rand_from_seed_m1_p1(alt_seed) * spread_rad * (1.0 - flatness);\n";
+ code += " float angle1_rad = atan(direction.x, direction.z) + rand_from_seed_m1_p1(alt_seed) * spread_rad;\n";
+ code += " float angle2_rad = atan(direction.y, abs(direction.z)) + rand_from_seed_m1_p1(alt_seed) * spread_rad * (1.0 - flatness);\n";
code += " vec3 direction_xz = vec3(sin(angle1_rad), 0.0, cos(angle1_rad));\n";
code += " vec3 direction_yz = vec3(0.0, sin(angle2_rad), cos(angle2_rad));\n";
code += " direction_yz.z = direction_yz.z / max(0.0001,sqrt(abs(direction_yz.z))); // better uniform distribution\n";
- code += " vec3 direction = vec3(direction_xz.x * direction_yz.z, direction_yz.y, direction_xz.z * direction_yz.z);\n";
- code += " direction = normalize(direction);\n";
- code += " VELOCITY = direction * initial_linear_velocity * mix(1.0, rand_from_seed(alt_seed), initial_linear_velocity_random);\n";
+ code += " vec3 vec_direction = vec3(direction_xz.x * direction_yz.z, direction_yz.y, direction_xz.z * direction_yz.z);\n";
+ code += " vec_direction = normalize(vec_direction);\n";
+ code += " VELOCITY = vec_direction * initial_linear_velocity * mix(1.0, rand_from_seed(alt_seed), initial_linear_velocity_random);\n";
}
code += " float base_angle = (initial_angle + tex_angle) * mix(1.0, angle_rand, initial_angle_random);\n";
@@ -626,6 +629,17 @@ bool ParticlesMaterial::_is_shader_dirty() const {
return dirty;
}
+void ParticlesMaterial::set_direction(Vector3 p_direction) {
+
+ direction = p_direction;
+ VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->direction, direction);
+}
+
+Vector3 ParticlesMaterial::get_direction() const {
+
+ return direction;
+}
+
void ParticlesMaterial::set_spread(float p_spread) {
spread = p_spread;
@@ -1041,6 +1055,9 @@ Shader::Mode ParticlesMaterial::get_shader_mode() const {
void ParticlesMaterial::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_direction", "degrees"), &ParticlesMaterial::set_direction);
+ ClassDB::bind_method(D_METHOD("get_direction"), &ParticlesMaterial::get_direction);
+
ClassDB::bind_method(D_METHOD("set_spread", "degrees"), &ParticlesMaterial::set_spread);
ClassDB::bind_method(D_METHOD("get_spread"), &ParticlesMaterial::get_spread);
@@ -1114,7 +1131,8 @@ void ParticlesMaterial::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flag_align_y"), "set_flag", "get_flag", FLAG_ALIGN_Y_TO_VELOCITY);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flag_rotate_y"), "set_flag", "get_flag", FLAG_ROTATE_Y);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flag_disable_z"), "set_flag", "get_flag", FLAG_DISABLE_Z);
- ADD_GROUP("Spread", "");
+ ADD_GROUP("Direction", "");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "direction"), "set_direction", "get_direction");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "spread", PROPERTY_HINT_RANGE, "0,180,0.01"), "set_spread", "get_spread");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "flatness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_flatness", "get_flatness");
ADD_GROUP("Gravity", "");
@@ -1199,6 +1217,7 @@ void ParticlesMaterial::_bind_methods() {
ParticlesMaterial::ParticlesMaterial() :
element(this) {
+ set_direction(Vector3(1, 0, 0));
set_spread(45);
set_flatness(0);
set_param(PARAM_INITIAL_LINEAR_VELOCITY, 0);
diff --git a/scene/resources/particles_material.h b/scene/resources/particles_material.h
index 42bf60ff48..7f11bd794b 100644
--- a/scene/resources/particles_material.h
+++ b/scene/resources/particles_material.h
@@ -129,6 +129,7 @@ private:
static SelfList<ParticlesMaterial>::List *dirty_materials;
struct ShaderNames {
+ StringName direction;
StringName spread;
StringName flatness;
StringName initial_linear_velocity;
@@ -194,6 +195,7 @@ private:
_FORCE_INLINE_ void _queue_shader_change();
_FORCE_INLINE_ bool _is_shader_dirty() const;
+ Vector3 direction;
float spread;
float flatness;
@@ -230,6 +232,9 @@ protected:
virtual void _validate_property(PropertyInfo &property) const;
public:
+ void set_direction(Vector3 p_direction);
+ Vector3 get_direction() const;
+
void set_spread(float p_spread);
float get_spread() const;
diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp
index 04d13c8869..74a493d3b5 100644
--- a/scene/resources/primitive_meshes.cpp
+++ b/scene/resources/primitive_meshes.cpp
@@ -743,8 +743,6 @@ void CylinderMesh::_create_mesh_array(Array &p_arr) const {
int i, j, prevrow, thisrow, point;
float x, y, z, u, v, radius;
- radius = bottom_radius > top_radius ? bottom_radius : top_radius;
-
PoolVector<Vector3> points;
PoolVector<Vector3> normals;
PoolVector<float> tangents;
diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp
index efc1082a6b..339f008a3d 100644
--- a/scene/resources/resource_format_text.cpp
+++ b/scene/resources/resource_format_text.cpp
@@ -1324,7 +1324,7 @@ Error ResourceFormatLoaderText::convert_file_to_binary(const String &p_src_path,
ERR_FAIL_COND_V(err != OK, ERR_CANT_OPEN);
Ref<ResourceInteractiveLoaderText> ria = memnew(ResourceInteractiveLoaderText);
- String path = p_src_path;
+ const String &path = p_src_path;
ria->local_path = ProjectSettings::get_singleton()->localize_path(path);
ria->res_path = ria->local_path;
//ria->set_local_path( ProjectSettings::get_singleton()->localize_path(p_path) );
@@ -1441,7 +1441,7 @@ void ResourceFormatSaverTextInstance::_find_resources(const Variant &p_variant,
int len = varray.size();
for (int i = 0; i < len; i++) {
- Variant v = varray.get(i);
+ const Variant &v = varray.get(i);
_find_resources(v);
}
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index 6e0bc43296..a5e9351753 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -1487,8 +1487,10 @@ uint32_t CubeMap::get_flags() const {
void CubeMap::set_side(Side p_side, const Ref<Image> &p_image) {
+ ERR_FAIL_COND(p_image.is_null());
ERR_FAIL_COND(p_image->empty());
ERR_FAIL_INDEX(p_side, 6);
+
if (!_is_valid()) {
format = p_image->get_format();
w = p_image->get_width();
@@ -1502,6 +1504,7 @@ void CubeMap::set_side(Side p_side, const Ref<Image> &p_image) {
Ref<Image> CubeMap::get_side(Side p_side) const {
+ ERR_FAIL_INDEX_V(p_side, 6, Ref<Image>());
if (!valid[p_side])
return Ref<Image>();
return VS::get_singleton()->texture_get_data(cubemap, VS::CubeMapSide(p_side));
diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp
index f577a2e144..899abfc9f9 100644
--- a/scene/resources/tile_set.cpp
+++ b/scene/resources/tile_set.cpp
@@ -721,7 +721,7 @@ void TileSet::tile_set_shape(int p_id, int p_shape_id, const Ref<Shape2D> &p_sha
ERR_FAIL_COND(!tile_map.has(p_id));
ERR_FAIL_COND(p_shape_id < 0);
- if (tile_map[p_id].shapes_data.size() <= p_shape_id)
+ if (p_shape_id >= tile_map[p_id].shapes_data.size())
tile_map[p_id].shapes_data.resize(p_shape_id + 1);
tile_map[p_id].shapes_data.write[p_shape_id].shape = p_shape;
_decompose_convex_shape(p_shape);
@@ -731,17 +731,17 @@ void TileSet::tile_set_shape(int p_id, int p_shape_id, const Ref<Shape2D> &p_sha
Ref<Shape2D> TileSet::tile_get_shape(int p_id, int p_shape_id) const {
ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<Shape2D>());
- ERR_FAIL_INDEX_V(p_shape_id, tile_map[p_id].shapes_data.size(), Ref<Shape2D>());
+ if (p_shape_id < tile_map[p_id].shapes_data.size())
+ return tile_map[p_id].shapes_data[p_shape_id].shape;
- return tile_map[p_id].shapes_data[p_shape_id].shape;
+ return Ref<Shape2D>();
}
void TileSet::tile_set_shape_transform(int p_id, int p_shape_id, const Transform2D &p_offset) {
ERR_FAIL_COND(!tile_map.has(p_id));
- ERR_FAIL_INDEX(p_shape_id, tile_map[p_id].shapes_data.size());
- if (tile_map[p_id].shapes_data.size() <= p_shape_id)
+ if (p_shape_id >= tile_map[p_id].shapes_data.size())
tile_map[p_id].shapes_data.resize(p_shape_id + 1);
tile_map[p_id].shapes_data.write[p_shape_id].shape_transform = p_offset;
emit_changed();
@@ -750,9 +750,10 @@ void TileSet::tile_set_shape_transform(int p_id, int p_shape_id, const Transform
Transform2D TileSet::tile_get_shape_transform(int p_id, int p_shape_id) const {
ERR_FAIL_COND_V(!tile_map.has(p_id), Transform2D());
- ERR_FAIL_INDEX_V(p_shape_id, tile_map[p_id].shapes_data.size(), Transform2D());
+ if (p_shape_id < tile_map[p_id].shapes_data.size())
+ return tile_map[p_id].shapes_data[p_shape_id].shape_transform;
- return tile_map[p_id].shapes_data[p_shape_id].shape_transform;
+ return Transform2D();
}
void TileSet::tile_set_shape_offset(int p_id, int p_shape_id, const Vector2 &p_offset) {
@@ -770,7 +771,7 @@ void TileSet::tile_set_shape_one_way(int p_id, int p_shape_id, const bool p_one_
ERR_FAIL_COND(!tile_map.has(p_id));
ERR_FAIL_COND(p_shape_id < 0);
- if (tile_map[p_id].shapes_data.size() <= p_shape_id)
+ if (p_shape_id >= tile_map[p_id].shapes_data.size())
tile_map[p_id].shapes_data.resize(p_shape_id + 1);
tile_map[p_id].shapes_data.write[p_shape_id].one_way_collision = p_one_way;
emit_changed();
@@ -779,9 +780,10 @@ void TileSet::tile_set_shape_one_way(int p_id, int p_shape_id, const bool p_one_
bool TileSet::tile_get_shape_one_way(int p_id, int p_shape_id) const {
ERR_FAIL_COND_V(!tile_map.has(p_id), false);
- ERR_FAIL_INDEX_V(p_shape_id, tile_map[p_id].shapes_data.size(), false);
+ if (p_shape_id < tile_map[p_id].shapes_data.size())
+ return tile_map[p_id].shapes_data[p_shape_id].one_way_collision;
- return tile_map[p_id].shapes_data[p_shape_id].one_way_collision;
+ return false;
}
void TileSet::tile_set_shape_one_way_margin(int p_id, int p_shape_id, float p_margin) {
@@ -789,7 +791,7 @@ void TileSet::tile_set_shape_one_way_margin(int p_id, int p_shape_id, float p_ma
ERR_FAIL_COND(!tile_map.has(p_id));
ERR_FAIL_COND(p_shape_id < 0);
- if (tile_map[p_id].shapes_data.size() <= p_shape_id)
+ if (p_shape_id >= tile_map[p_id].shapes_data.size())
tile_map[p_id].shapes_data.resize(p_shape_id + 1);
tile_map[p_id].shapes_data.write[p_shape_id].one_way_collision_margin = p_margin;
emit_changed();
@@ -798,9 +800,10 @@ void TileSet::tile_set_shape_one_way_margin(int p_id, int p_shape_id, float p_ma
float TileSet::tile_get_shape_one_way_margin(int p_id, int p_shape_id) const {
ERR_FAIL_COND_V(!tile_map.has(p_id), 0);
- ERR_FAIL_INDEX_V(p_shape_id, tile_map[p_id].shapes_data.size(), 0.0);
+ if (p_shape_id < tile_map[p_id].shapes_data.size())
+ return tile_map[p_id].shapes_data[p_shape_id].one_way_collision_margin;
- return tile_map[p_id].shapes_data[p_shape_id].one_way_collision_margin;
+ return 0;
}
void TileSet::tile_set_light_occluder(int p_id, const Ref<OccluderPolygon2D> &p_light_occluder) {
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp
index dd595d9ff8..7265c9b457 100644
--- a/scene/resources/visual_shader.cpp
+++ b/scene/resources/visual_shader.cpp
@@ -257,7 +257,7 @@ bool VisualShader::can_connect_nodes(Type p_type, int p_from_node, int p_from_po
VisualShaderNode::PortType from_port_type = g->nodes[p_from_node].node->get_output_port_type(p_from_port);
VisualShaderNode::PortType to_port_type = g->nodes[p_to_node].node->get_input_port_type(p_to_port);
- if (MAX(0, from_port_type - 2) != (MAX(0, to_port_type - 2))) {
+ if (!is_port_types_compatible(from_port_type, to_port_type)) {
return false;
}
@@ -271,6 +271,10 @@ bool VisualShader::can_connect_nodes(Type p_type, int p_from_node, int p_from_po
return true;
}
+bool VisualShader::is_port_types_compatible(int p_a, int p_b) const {
+ return MAX(0, p_a - 2) == (MAX(0, p_b - 2));
+}
+
void VisualShader::connect_nodes_forced(Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) {
ERR_FAIL_INDEX(p_type, TYPE_MAX);
Graph *g = &graph[p_type];
@@ -295,8 +299,8 @@ Error VisualShader::connect_nodes(Type p_type, int p_from_node, int p_from_port,
VisualShaderNode::PortType from_port_type = g->nodes[p_from_node].node->get_output_port_type(p_from_port);
VisualShaderNode::PortType to_port_type = g->nodes[p_to_node].node->get_input_port_type(p_to_port);
- if (MAX(0, from_port_type - 2) != (MAX(0, to_port_type - 2))) {
- ERR_EXPLAIN("Incompatible port types (scalar/vec/bool with transform");
+ if (!is_port_types_compatible(from_port_type, to_port_type)) {
+ ERR_EXPLAIN("Incompatible port types (scalar/vec/bool) with transform");
ERR_FAIL_V(ERR_INVALID_PARAMETER);
return ERR_INVALID_PARAMETER;
}
@@ -1762,6 +1766,7 @@ void VisualShaderNodeGroupBase::set_inputs(const String &p_inputs) {
for (int i = 0; i < input_port_count; i++) {
Vector<String> arr = input_strings[i].split(",");
+ ERR_FAIL_COND(arr.size() != 3);
int port_idx = arr[0].to_int();
int port_type = arr[1].to_int();
@@ -1794,6 +1799,7 @@ void VisualShaderNodeGroupBase::set_outputs(const String &p_outputs) {
for (int i = 0; i < output_port_count; i++) {
Vector<String> arr = output_strings[i].split(",");
+ ERR_FAIL_COND(arr.size() != 3);
int port_idx = arr[0].to_int();
int port_type = arr[1].to_int();
@@ -1810,6 +1816,23 @@ String VisualShaderNodeGroupBase::get_outputs() const {
return outputs;
}
+bool VisualShaderNodeGroupBase::is_valid_port_name(const String &p_name) const {
+ if (!p_name.is_valid_identifier()) {
+ return false;
+ }
+ for (int i = 0; i < get_input_port_count(); i++) {
+ if (get_input_port_name(i) == p_name) {
+ return false;
+ }
+ }
+ for (int i = 0; i < get_output_port_count(); i++) {
+ if (get_output_port_name(i) == p_name) {
+ return false;
+ }
+ }
+ return true;
+}
+
void VisualShaderNodeGroupBase::add_input_port(int p_id, int p_type, const String &p_name) {
String str = itos(p_id) + "," + itos(p_type) + "," + p_name + ";";
@@ -1849,6 +1872,8 @@ void VisualShaderNodeGroupBase::add_input_port(int p_id, int p_type, const Strin
void VisualShaderNodeGroupBase::remove_input_port(int p_id) {
+ ERR_FAIL_COND(!has_input_port(p_id));
+
Vector<String> inputs_strings = inputs.split(";", false);
int count = 0;
int index = 0;
@@ -1917,6 +1942,8 @@ void VisualShaderNodeGroupBase::add_output_port(int p_id, int p_type, const Stri
void VisualShaderNodeGroupBase::remove_output_port(int p_id) {
+ ERR_FAIL_COND(!has_output_port(p_id));
+
Vector<String> outputs_strings = outputs.split(";", false);
int count = 0;
int index = 0;
@@ -1956,6 +1983,9 @@ void VisualShaderNodeGroupBase::clear_output_ports() {
void VisualShaderNodeGroupBase::set_input_port_type(int p_id, int p_type) {
+ ERR_FAIL_COND(!has_input_port(p_id));
+ ERR_FAIL_COND(p_type < 0 || p_type > PORT_TYPE_TRANSFORM);
+
if (input_ports[p_id].type == p_type)
return;
@@ -1986,6 +2016,9 @@ VisualShaderNodeGroupBase::PortType VisualShaderNodeGroupBase::get_input_port_ty
void VisualShaderNodeGroupBase::set_input_port_name(int p_id, const String &p_name) {
+ ERR_FAIL_COND(!has_input_port(p_id));
+ ERR_FAIL_COND(!is_valid_port_name(p_name));
+
if (input_ports[p_id].name == p_name)
return;
@@ -2016,6 +2049,9 @@ String VisualShaderNodeGroupBase::get_input_port_name(int p_id) const {
void VisualShaderNodeGroupBase::set_output_port_type(int p_id, int p_type) {
+ ERR_FAIL_COND(!has_output_port(p_id));
+ ERR_FAIL_COND(p_type < 0 || p_type > PORT_TYPE_TRANSFORM);
+
if (output_ports[p_id].type == p_type)
return;
@@ -2045,6 +2081,10 @@ VisualShaderNodeGroupBase::PortType VisualShaderNodeGroupBase::get_output_port_t
}
void VisualShaderNodeGroupBase::set_output_port_name(int p_id, const String &p_name) {
+
+ ERR_FAIL_COND(!has_output_port(p_id));
+ ERR_FAIL_COND(!is_valid_port_name(p_name));
+
if (output_ports[p_id].name == p_name)
return;
@@ -2125,6 +2165,8 @@ void VisualShaderNodeGroupBase::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_outputs", "outputs"), &VisualShaderNodeGroupBase::set_outputs);
ClassDB::bind_method(D_METHOD("get_outputs"), &VisualShaderNodeGroupBase::get_outputs);
+ ClassDB::bind_method(D_METHOD("is_valid_port_name", "name"), &VisualShaderNodeGroupBase::is_valid_port_name);
+
ClassDB::bind_method(D_METHOD("add_input_port", "id", "type", "name"), &VisualShaderNodeGroupBase::add_input_port);
ClassDB::bind_method(D_METHOD("remove_input_port", "id"), &VisualShaderNodeGroupBase::remove_input_port);
ClassDB::bind_method(D_METHOD("get_input_port_count"), &VisualShaderNodeGroupBase::get_input_port_count);
diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h
index 1ab3c0c9cc..83db51b1b0 100644
--- a/scene/resources/visual_shader.h
+++ b/scene/resources/visual_shader.h
@@ -138,6 +138,7 @@ public:
Error connect_nodes(Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port);
void disconnect_nodes(Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port);
void connect_nodes_forced(Type p_type, 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 rebuild();
void get_node_connections(Type p_type, List<Connection> *r_connections) const;
@@ -355,6 +356,8 @@ public:
void set_outputs(const String &p_outputs);
String get_outputs() const;
+ bool is_valid_port_name(const String &p_name) const;
+
void add_input_port(int p_id, int p_type, const String &p_name);
void remove_input_port(int p_id);
virtual int get_input_port_count() const;
diff --git a/scene/resources/visual_shader_nodes.h b/scene/resources/visual_shader_nodes.h
index df753276e4..ef64b50711 100644
--- a/scene/resources/visual_shader_nodes.h
+++ b/scene/resources/visual_shader_nodes.h
@@ -699,7 +699,7 @@ public:
virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
- void set_function(Function p_op);
+ void set_function(Function p_func);
Function get_function() const;
virtual Vector<StringName> get_editable_properties() const;
@@ -740,7 +740,7 @@ public:
virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
- void set_function(Function p_op);
+ void set_function(Function p_func);
Function get_function() const;
virtual Vector<StringName> get_editable_properties() const;
@@ -895,7 +895,7 @@ public:
virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
- void set_function(Function p_op);
+ void set_function(Function p_func);
Function get_function() const;
virtual Vector<StringName> get_editable_properties() const;
@@ -935,7 +935,7 @@ public:
virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
- void set_function(Function p_op);
+ void set_function(Function p_func);
Function get_function() const;
virtual Vector<StringName> get_editable_properties() const;