diff options
Diffstat (limited to 'scene/resources')
25 files changed, 574 insertions, 490 deletions
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index e3cf9183a0..255d0ececd 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -3998,13 +3998,12 @@ bool Animation::_blend_shape_track_optimize_key(const TKey<float> &t0, const TKe float v1 = t1.value; float v2 = t2.value; - if (Math::is_equal_approx(v1, v2, p_allowed_unit_error)) { + if (Math::is_equal_approx(v1, v2, (float)p_allowed_unit_error)) { //0 and 2 are close, let's see if 1 is close - if (!Math::is_equal_approx(v0, v1, p_allowed_unit_error)) { + if (!Math::is_equal_approx(v0, v1, (float)p_allowed_unit_error)) { //not close, not optimizable return false; } - } else { /* TODO eventually discuss a way to optimize these better. diff --git a/scene/resources/curve.cpp b/scene/resources/curve.cpp index b87639de6a..bf3efd7599 100644 --- a/scene/resources/curve.cpp +++ b/scene/resources/curve.cpp @@ -33,15 +33,15 @@ #include "core/core_string_names.h" template <class T> -static _FORCE_INLINE_ T _bezier_interp(real_t t, T start, T control_1, T control_2, T end) { +static _FORCE_INLINE_ T _bezier_interp(real_t p_t, T p_start, T p_control_1, T p_control_2, T p_end) { /* Formula from Wikipedia article on Bezier curves. */ - real_t omt = (1.0 - t); + real_t omt = (1.0 - p_t); real_t omt2 = omt * omt; real_t omt3 = omt2 * omt; - real_t t2 = t * t; - real_t t3 = t2 * t; + real_t t2 = p_t * p_t; + real_t t3 = t2 * p_t; - return start * omt3 + control_1 * omt2 * t * 3.0 + control_2 * omt * t2 * 3.0 + end * t3; + return p_start * omt3 + p_control_1 * omt2 * p_t * 3.0 + p_control_2 * omt * t2 * 3.0 + p_end * t3; } const char *Curve::SIGNAL_RANGE_CHANGED = "range_changed"; @@ -49,46 +49,46 @@ const char *Curve::SIGNAL_RANGE_CHANGED = "range_changed"; Curve::Curve() { } -int Curve::add_point(Vector2 p_pos, real_t left_tangent, real_t right_tangent, TangentMode left_mode, TangentMode right_mode) { +int Curve::add_point(Vector2 p_position, real_t p_left_tangent, real_t p_right_tangent, TangentMode p_left_mode, TangentMode p_right_mode) { // Add a point and preserve order // Curve bounds is in 0..1 - if (p_pos.x > MAX_X) { - p_pos.x = MAX_X; - } else if (p_pos.x < MIN_X) { - p_pos.x = MIN_X; + if (p_position.x > MAX_X) { + p_position.x = MAX_X; + } else if (p_position.x < MIN_X) { + p_position.x = MIN_X; } int ret = -1; if (_points.size() == 0) { - _points.push_back(Point(p_pos, left_tangent, right_tangent, left_mode, right_mode)); + _points.push_back(Point(p_position, p_left_tangent, p_right_tangent, p_left_mode, p_right_mode)); ret = 0; } else if (_points.size() == 1) { // TODO Is the `else` able to handle this block already? - real_t diff = p_pos.x - _points[0].pos.x; + real_t diff = p_position.x - _points[0].position.x; if (diff > 0) { - _points.push_back(Point(p_pos, left_tangent, right_tangent, left_mode, right_mode)); + _points.push_back(Point(p_position, p_left_tangent, p_right_tangent, p_left_mode, p_right_mode)); ret = 1; } else { - _points.insert(0, Point(p_pos, left_tangent, right_tangent, left_mode, right_mode)); + _points.insert(0, Point(p_position, p_left_tangent, p_right_tangent, p_left_mode, p_right_mode)); ret = 0; } } else { - int i = get_index(p_pos.x); + int i = get_index(p_position.x); - if (i == 0 && p_pos.x < _points[0].pos.x) { + if (i == 0 && p_position.x < _points[0].position.x) { // Insert before anything else - _points.insert(0, Point(p_pos, left_tangent, right_tangent, left_mode, right_mode)); + _points.insert(0, Point(p_position, p_left_tangent, p_right_tangent, p_left_mode, p_right_mode)); ret = 0; } else { // Insert between i and i+1 ++i; - _points.insert(i, Point(p_pos, left_tangent, right_tangent, left_mode, right_mode)); + _points.insert(i, Point(p_position, p_left_tangent, p_right_tangent, p_left_mode, p_right_mode)); ret = i; } } @@ -100,7 +100,7 @@ int Curve::add_point(Vector2 p_pos, real_t left_tangent, real_t right_tangent, T return ret; } -int Curve::get_index(real_t offset) const { +int Curve::get_index(real_t p_offset) const { // Lower-bound float binary search int imin = 0; @@ -109,13 +109,13 @@ int Curve::get_index(real_t offset) const { while (imax - imin > 1) { int m = (imin + imax) / 2; - real_t a = _points[m].pos.x; - real_t b = _points[m + 1].pos.x; + real_t a = _points[m].position.x; + real_t b = _points[m + 1].position.x; - if (a < offset && b < offset) { + if (a < p_offset && b < p_offset) { imin = m; - } else if (a > offset) { + } else if (a > p_offset) { imax = m; } else { @@ -124,7 +124,7 @@ int Curve::get_index(real_t offset) const { } // Will happen if the offset is out of bounds - if (offset > _points[imax].pos.x) { + if (p_offset > _points[imax].position.x) { return imax; } return imin; @@ -134,7 +134,7 @@ void Curve::clean_dupes() { bool dirty = false; for (int i = 1; i < _points.size(); ++i) { - real_t diff = _points[i - 1].pos.x - _points[i].pos.x; + real_t diff = _points[i - 1].position.x - _points[i].position.x; if (diff <= CMP_EPSILON) { _points.remove_at(i); --i; @@ -147,62 +147,62 @@ void Curve::clean_dupes() { } } -void Curve::set_point_left_tangent(int i, real_t tangent) { - ERR_FAIL_INDEX(i, _points.size()); - _points.write[i].left_tangent = tangent; - _points.write[i].left_mode = TANGENT_FREE; +void Curve::set_point_left_tangent(int p_index, real_t p_tangent) { + ERR_FAIL_INDEX(p_index, _points.size()); + _points.write[p_index].left_tangent = p_tangent; + _points.write[p_index].left_mode = TANGENT_FREE; mark_dirty(); } -void Curve::set_point_right_tangent(int i, real_t tangent) { - ERR_FAIL_INDEX(i, _points.size()); - _points.write[i].right_tangent = tangent; - _points.write[i].right_mode = TANGENT_FREE; +void Curve::set_point_right_tangent(int p_index, real_t p_tangent) { + ERR_FAIL_INDEX(p_index, _points.size()); + _points.write[p_index].right_tangent = p_tangent; + _points.write[p_index].right_mode = TANGENT_FREE; mark_dirty(); } -void Curve::set_point_left_mode(int i, TangentMode p_mode) { - ERR_FAIL_INDEX(i, _points.size()); - _points.write[i].left_mode = p_mode; - if (i > 0) { +void Curve::set_point_left_mode(int p_index, TangentMode p_mode) { + ERR_FAIL_INDEX(p_index, _points.size()); + _points.write[p_index].left_mode = p_mode; + if (p_index > 0) { if (p_mode == TANGENT_LINEAR) { - Vector2 v = (_points[i - 1].pos - _points[i].pos).normalized(); - _points.write[i].left_tangent = v.y / v.x; + Vector2 v = (_points[p_index - 1].position - _points[p_index].position).normalized(); + _points.write[p_index].left_tangent = v.y / v.x; } } mark_dirty(); } -void Curve::set_point_right_mode(int i, TangentMode p_mode) { - ERR_FAIL_INDEX(i, _points.size()); - _points.write[i].right_mode = p_mode; - if (i + 1 < _points.size()) { +void Curve::set_point_right_mode(int p_index, TangentMode p_mode) { + ERR_FAIL_INDEX(p_index, _points.size()); + _points.write[p_index].right_mode = p_mode; + if (p_index + 1 < _points.size()) { if (p_mode == TANGENT_LINEAR) { - Vector2 v = (_points[i + 1].pos - _points[i].pos).normalized(); - _points.write[i].right_tangent = v.y / v.x; + Vector2 v = (_points[p_index + 1].position - _points[p_index].position).normalized(); + _points.write[p_index].right_tangent = v.y / v.x; } } mark_dirty(); } -real_t Curve::get_point_left_tangent(int i) const { - ERR_FAIL_INDEX_V(i, _points.size(), 0); - return _points[i].left_tangent; +real_t Curve::get_point_left_tangent(int p_index) const { + ERR_FAIL_INDEX_V(p_index, _points.size(), 0); + return _points[p_index].left_tangent; } -real_t Curve::get_point_right_tangent(int i) const { - ERR_FAIL_INDEX_V(i, _points.size(), 0); - return _points[i].right_tangent; +real_t Curve::get_point_right_tangent(int p_index) const { + ERR_FAIL_INDEX_V(p_index, _points.size(), 0); + return _points[p_index].right_tangent; } -Curve::TangentMode Curve::get_point_left_mode(int i) const { - ERR_FAIL_INDEX_V(i, _points.size(), TANGENT_FREE); - return _points[i].left_mode; +Curve::TangentMode Curve::get_point_left_mode(int p_index) const { + ERR_FAIL_INDEX_V(p_index, _points.size(), TANGENT_FREE); + return _points[p_index].left_mode; } -Curve::TangentMode Curve::get_point_right_mode(int i) const { - ERR_FAIL_INDEX_V(i, _points.size(), TANGENT_FREE); - return _points[i].right_mode; +Curve::TangentMode Curve::get_point_right_mode(int p_index) const { + ERR_FAIL_INDEX_V(p_index, _points.size(), TANGENT_FREE); + return _points[p_index].right_mode; } void Curve::remove_point(int p_index) { @@ -216,18 +216,18 @@ void Curve::clear_points() { mark_dirty(); } -void Curve::set_point_value(int p_index, real_t pos) { +void Curve::set_point_value(int p_index, real_t p_position) { ERR_FAIL_INDEX(p_index, _points.size()); - _points.write[p_index].pos.y = pos; + _points.write[p_index].position.y = p_position; update_auto_tangents(p_index); mark_dirty(); } -int Curve::set_point_offset(int p_index, float offset) { +int Curve::set_point_offset(int p_index, real_t p_offset) { ERR_FAIL_INDEX_V(p_index, _points.size(), -1); Point p = _points[p_index]; remove_point(p_index); - int i = add_point(Vector2(offset, p.pos.y)); + int i = add_point(Vector2(p_offset, p.position.y)); _points.write[i].left_tangent = p.left_tangent; _points.write[i].right_tangent = p.right_tangent; _points.write[i].left_mode = p.left_mode; @@ -241,7 +241,7 @@ int Curve::set_point_offset(int p_index, float offset) { Vector2 Curve::get_point_position(int p_index) const { ERR_FAIL_INDEX_V(p_index, _points.size(), Vector2(0, 0)); - return _points[p_index].pos; + return _points[p_index].position; } Curve::Point Curve::get_point(int p_index) const { @@ -249,35 +249,35 @@ Curve::Point Curve::get_point(int p_index) const { return _points[p_index]; } -void Curve::update_auto_tangents(int i) { - Point &p = _points.write[i]; +void Curve::update_auto_tangents(int p_index) { + Point &p = _points.write[p_index]; - if (i > 0) { + if (p_index > 0) { if (p.left_mode == TANGENT_LINEAR) { - Vector2 v = (_points[i - 1].pos - p.pos).normalized(); + Vector2 v = (_points[p_index - 1].position - p.position).normalized(); p.left_tangent = v.y / v.x; } - if (_points[i - 1].right_mode == TANGENT_LINEAR) { - Vector2 v = (_points[i - 1].pos - p.pos).normalized(); - _points.write[i - 1].right_tangent = v.y / v.x; + if (_points[p_index - 1].right_mode == TANGENT_LINEAR) { + Vector2 v = (_points[p_index - 1].position - p.position).normalized(); + _points.write[p_index - 1].right_tangent = v.y / v.x; } } - if (i + 1 < _points.size()) { + if (p_index + 1 < _points.size()) { if (p.right_mode == TANGENT_LINEAR) { - Vector2 v = (_points[i + 1].pos - p.pos).normalized(); + Vector2 v = (_points[p_index + 1].position - p.position).normalized(); p.right_tangent = v.y / v.x; } - if (_points[i + 1].left_mode == TANGENT_LINEAR) { - Vector2 v = (_points[i + 1].pos - p.pos).normalized(); - _points.write[i + 1].left_tangent = v.y / v.x; + if (_points[p_index + 1].left_mode == TANGENT_LINEAR) { + Vector2 v = (_points[p_index + 1].position - p.position).normalized(); + _points.write[p_index + 1].left_tangent = v.y / v.x; } } } #define MIN_Y_RANGE 0.01 -void Curve::set_min_value(float p_min) { +void Curve::set_min_value(real_t p_min) { if (_minmax_set_once & 0b11 && p_min > _max_value - MIN_Y_RANGE) { _min_value = _max_value - MIN_Y_RANGE; } else { @@ -289,7 +289,7 @@ void Curve::set_min_value(float p_min) { emit_signal(SNAME(SIGNAL_RANGE_CHANGED)); } -void Curve::set_max_value(float p_max) { +void Curve::set_max_value(real_t p_max) { if (_minmax_set_once & 0b11 && p_max < _min_value + MIN_Y_RANGE) { _max_value = _min_value + MIN_Y_RANGE; } else { @@ -299,32 +299,32 @@ void Curve::set_max_value(float p_max) { emit_signal(SNAME(SIGNAL_RANGE_CHANGED)); } -real_t Curve::interpolate(real_t offset) const { +real_t Curve::interpolate(real_t p_offset) const { if (_points.size() == 0) { return 0; } if (_points.size() == 1) { - return _points[0].pos.y; + return _points[0].position.y; } - int i = get_index(offset); + int i = get_index(p_offset); if (i == _points.size() - 1) { - return _points[i].pos.y; + return _points[i].position.y; } - real_t local = offset - _points[i].pos.x; + real_t local = p_offset - _points[i].position.x; if (i == 0 && local <= 0) { - return _points[0].pos.y; + return _points[0].position.y; } return interpolate_local_nocheck(i, local); } -real_t Curve::interpolate_local_nocheck(int index, real_t local_offset) const { - const Point a = _points[index]; - const Point b = _points[index + 1]; +real_t Curve::interpolate_local_nocheck(int p_index, real_t p_local_offset) const { + const Point a = _points[p_index]; + const Point b = _points[p_index + 1]; /* Cubic bezier * @@ -341,16 +341,16 @@ real_t Curve::interpolate_local_nocheck(int index, real_t local_offset) const { */ // Control points are chosen at equal distances - real_t d = b.pos.x - a.pos.x; - if (Math::abs(d) <= CMP_EPSILON) { - return b.pos.y; + real_t d = b.position.x - a.position.x; + if (Math::is_zero_approx(d)) { + return b.position.y; } - local_offset /= d; + p_local_offset /= d; d /= 3.0; - real_t yac = a.pos.y + d * a.right_tangent; - real_t ybc = b.pos.y - d * b.left_tangent; + real_t yac = a.position.y + d * a.right_tangent; + real_t ybc = b.position.y - d * b.left_tangent; - real_t y = _bezier_interp(local_offset, a.pos.y, yac, ybc, b.pos.y); + real_t y = _bezier_interp(p_local_offset, a.position.y, yac, ybc, b.position.y); return y; } @@ -369,7 +369,7 @@ Array Curve::get_data() const { const Point p = _points[j]; int i = j * ELEMS; - output[i] = p.pos; + output[i] = p.position; output[i + 1] = p.left_tangent; output[i + 2] = p.right_tangent; output[i + 3] = p.left_mode; @@ -379,39 +379,39 @@ Array Curve::get_data() const { return output; } -void Curve::set_data(Array input) { +void Curve::set_data(const Array p_input) { const unsigned int ELEMS = 5; - ERR_FAIL_COND(input.size() % ELEMS != 0); + ERR_FAIL_COND(p_input.size() % ELEMS != 0); _points.clear(); // Validate input - for (int i = 0; i < input.size(); i += ELEMS) { - ERR_FAIL_COND(input[i].get_type() != Variant::VECTOR2); - ERR_FAIL_COND(!input[i + 1].is_num()); - ERR_FAIL_COND(input[i + 2].get_type() != Variant::FLOAT); + for (int i = 0; i < p_input.size(); i += ELEMS) { + ERR_FAIL_COND(p_input[i].get_type() != Variant::VECTOR2); + ERR_FAIL_COND(!p_input[i + 1].is_num()); + ERR_FAIL_COND(p_input[i + 2].get_type() != Variant::FLOAT); - ERR_FAIL_COND(input[i + 3].get_type() != Variant::INT); - int left_mode = input[i + 3]; + ERR_FAIL_COND(p_input[i + 3].get_type() != Variant::INT); + int left_mode = p_input[i + 3]; ERR_FAIL_COND(left_mode < 0 || left_mode >= TANGENT_MODE_COUNT); - ERR_FAIL_COND(input[i + 4].get_type() != Variant::INT); - int right_mode = input[i + 4]; + ERR_FAIL_COND(p_input[i + 4].get_type() != Variant::INT); + int right_mode = p_input[i + 4]; ERR_FAIL_COND(right_mode < 0 || right_mode >= TANGENT_MODE_COUNT); } - _points.resize(input.size() / ELEMS); + _points.resize(p_input.size() / ELEMS); for (int j = 0; j < _points.size(); ++j) { Point &p = _points.write[j]; int i = j * ELEMS; - p.pos = input[i]; - p.left_tangent = input[i + 1]; - p.right_tangent = input[i + 2]; + p.position = p_input[i]; + p.left_tangent = p_input[i + 1]; + p.right_tangent = p_input[i + 2]; // TODO For some reason the compiler won't convert from Variant to enum - int left_mode = input[i + 3]; - int right_mode = input[i + 4]; + int left_mode = p_input[i + 3]; + int right_mode = p_input[i + 4]; p.left_mode = (TangentMode)left_mode; p.right_mode = (TangentMode)right_mode; } @@ -431,8 +431,8 @@ void Curve::bake() { } if (_points.size() != 0) { - _baked_cache.write[0] = _points[0].pos.y; - _baked_cache.write[_baked_cache.size() - 1] = _points[_points.size() - 1].pos.y; + _baked_cache.write[0] = _points[0].position.y; + _baked_cache.write[_baked_cache.size() - 1] = _points[_points.size() - 1].position.y; } _baked_cache_dirty = false; @@ -445,7 +445,7 @@ void Curve::set_bake_resolution(int p_resolution) { _baked_cache_dirty = true; } -real_t Curve::interpolate_baked(real_t offset) const { +real_t Curve::interpolate_baked(real_t p_offset) const { if (_baked_cache_dirty) { // Last-second bake if not done already const_cast<Curve *>(this)->bake(); @@ -456,13 +456,13 @@ real_t Curve::interpolate_baked(real_t offset) const { if (_points.size() == 0) { return 0; } - return _points[0].pos.y; + return _points[0].position.y; } else if (_baked_cache.size() == 1) { return _baked_cache[0]; } // Get interpolation index - real_t fi = offset * _baked_cache.size(); + real_t fi = p_offset * _baked_cache.size(); int i = Math::floor(fi); if (i < 0) { i = 0; @@ -481,7 +481,7 @@ real_t Curve::interpolate_baked(real_t offset) const { } } -void Curve::ensure_default_setup(float p_min, float p_max) { +void Curve::ensure_default_setup(real_t p_min, real_t p_max) { if (_points.size() == 0 && _min_value == 0 && _max_value == 1) { add_point(Vector2(0, 1)); add_point(Vector2(1, 1)); @@ -535,9 +535,9 @@ int Curve2D::get_point_count() const { return points.size(); } -void Curve2D::add_point(const Vector2 &p_pos, const Vector2 &p_in, const Vector2 &p_out, int p_atpos) { +void Curve2D::add_point(const Vector2 &p_position, const Vector2 &p_in, const Vector2 &p_out, int p_atpos) { Point n; - n.pos = p_pos; + n.position = p_position; n.in = p_in; n.out = p_out; if (p_atpos >= 0 && p_atpos < points.size()) { @@ -550,17 +550,17 @@ void Curve2D::add_point(const Vector2 &p_pos, const Vector2 &p_in, const Vector2 emit_signal(CoreStringNames::get_singleton()->changed); } -void Curve2D::set_point_position(int p_index, const Vector2 &p_pos) { +void Curve2D::set_point_position(int p_index, const Vector2 &p_position) { ERR_FAIL_INDEX(p_index, points.size()); - points.write[p_index].pos = p_pos; + points.write[p_index].position = p_position; baked_cache_dirty = true; emit_signal(CoreStringNames::get_singleton()->changed); } Vector2 Curve2D::get_point_position(int p_index) const { ERR_FAIL_INDEX_V(p_index, points.size(), Vector2()); - return points[p_index].pos; + return points[p_index].position; } void Curve2D::set_point_in(int p_index, const Vector2 &p_in) { @@ -604,19 +604,19 @@ void Curve2D::clear_points() { } } -Vector2 Curve2D::interpolate(int p_index, float p_offset) const { +Vector2 Curve2D::interpolate(int p_index, const real_t p_offset) const { int pc = points.size(); ERR_FAIL_COND_V(pc == 0, Vector2()); if (p_index >= pc - 1) { - return points[pc - 1].pos; + return points[pc - 1].position; } else if (p_index < 0) { - return points[0].pos; + return points[0].position; } - Vector2 p0 = points[p_index].pos; + Vector2 p0 = points[p_index].position; Vector2 p1 = p0 + points[p_index].out; - Vector2 p3 = points[p_index + 1].pos; + Vector2 p3 = points[p_index + 1].position; Vector2 p2 = p3 + points[p_index + 1].in; return _bezier_interp(p_offset, p0, p1, p2, p3); @@ -632,15 +632,15 @@ Vector2 Curve2D::interpolatef(real_t p_findex) const { return interpolate((int)p_findex, Math::fmod(p_findex, (real_t)1.0)); } -void Curve2D::_bake_segment2d(Map<float, Vector2> &r_bake, float p_begin, float p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_max_depth, float p_tol) const { - float mp = p_begin + (p_end - p_begin) * 0.5; +void Curve2D::_bake_segment2d(Map<real_t, Vector2> &r_bake, real_t p_begin, real_t p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_max_depth, real_t p_tol) const { + real_t mp = p_begin + (p_end - p_begin) * 0.5; Vector2 beg = _bezier_interp(p_begin, p_a, p_a + p_out, p_b + p_in, p_b); Vector2 mid = _bezier_interp(mp, p_a, p_a + p_out, p_b + p_in, p_b); Vector2 end = _bezier_interp(p_end, p_a, p_a + p_out, p_b + p_in, p_b); Vector2 na = (mid - beg).normalized(); Vector2 nb = (end - mid).normalized(); - float dp = na.dot(nb); + real_t dp = na.dot(nb); if (dp < Math::cos(Math::deg2rad(p_tol))) { r_bake[mp] = mid; @@ -668,47 +668,47 @@ void Curve2D::_bake() const { if (points.size() == 1) { baked_point_cache.resize(1); - baked_point_cache.set(0, points[0].pos); + baked_point_cache.set(0, points[0].position); baked_dist_cache.resize(1); baked_dist_cache.set(0, 0.0); return; } - Vector2 pos = points[0].pos; - float dist = 0.0; + Vector2 position = points[0].position; + real_t dist = 0.0; List<Vector2> pointlist; - List<float> distlist; + List<real_t> distlist; - pointlist.push_back(pos); //start always from origin + pointlist.push_back(position); //start always from origin distlist.push_back(0.0); for (int i = 0; i < points.size() - 1; i++) { - float step = 0.1; // at least 10 substeps ought to be enough? - float p = 0.0; + real_t step = 0.1; // at least 10 substeps ought to be enough? + real_t p = 0.0; while (p < 1.0) { - float np = p + step; + real_t np = p + step; if (np > 1.0) { np = 1.0; } - Vector2 npp = _bezier_interp(np, points[i].pos, points[i].pos + points[i].out, points[i + 1].pos + points[i + 1].in, points[i + 1].pos); - float d = pos.distance_to(npp); + Vector2 npp = _bezier_interp(np, points[i].position, points[i].position + points[i].out, points[i + 1].position + points[i + 1].in, points[i + 1].position); + real_t d = position.distance_to(npp); if (d > bake_interval) { // OK! between P and NP there _has_ to be Something, let's go searching! int iterations = 10; //lots of detail! - float low = p; - float hi = np; - float mid = low + (hi - low) * 0.5; + real_t low = p; + real_t hi = np; + real_t mid = low + (hi - low) * 0.5; for (int j = 0; j < iterations; j++) { - npp = _bezier_interp(mid, points[i].pos, points[i].pos + points[i].out, points[i + 1].pos + points[i + 1].in, points[i + 1].pos); - d = pos.distance_to(npp); + npp = _bezier_interp(mid, points[i].position, points[i].position + points[i].out, points[i + 1].position + points[i + 1].in, points[i + 1].position); + d = position.distance_to(npp); if (bake_interval < d) { hi = mid; @@ -718,11 +718,11 @@ void Curve2D::_bake() const { mid = low + (hi - low) * 0.5; } - pos = npp; + position = npp; p = mid; dist += d; - pointlist.push_back(pos); + pointlist.push_back(position); distlist.push_back(dist); } else { p = np; @@ -730,9 +730,9 @@ void Curve2D::_bake() const { } } - Vector2 lastpos = points[points.size() - 1].pos; + Vector2 lastpos = points[points.size() - 1].position; - float rem = pos.distance_to(lastpos); + real_t rem = position.distance_to(lastpos); dist += rem; baked_max_ofs = dist; pointlist.push_back(lastpos); @@ -742,7 +742,7 @@ void Curve2D::_bake() const { baked_dist_cache.resize(distlist.size()); Vector2 *w = baked_point_cache.ptrw(); - float *wd = baked_dist_cache.ptrw(); + real_t *wd = baked_dist_cache.ptrw(); for (int i = 0; i < pointlist.size(); i++) { w[i] = pointlist[i]; @@ -750,7 +750,7 @@ void Curve2D::_bake() const { } } -float Curve2D::get_baked_length() const { +real_t Curve2D::get_baked_length() const { if (baked_cache_dirty) { _bake(); } @@ -758,7 +758,7 @@ float Curve2D::get_baked_length() const { return baked_max_ofs; } -Vector2 Curve2D::interpolate_baked(float p_offset, bool p_cubic) const { +Vector2 Curve2D::interpolate_baked(real_t p_offset, bool p_cubic) const { if (baked_cache_dirty) { _bake(); } @@ -784,7 +784,7 @@ Vector2 Curve2D::interpolate_baked(float p_offset, bool p_cubic) const { int start = 0, end = bpc, idx = (end + start) / 2; // binary search to find baked points while (start < idx) { - float offset = baked_dist_cache[idx]; + real_t offset = baked_dist_cache[idx]; if (p_offset <= offset) { end = idx; } else { @@ -793,13 +793,13 @@ Vector2 Curve2D::interpolate_baked(float p_offset, bool p_cubic) const { idx = (end + start) / 2; } - float offset_begin = baked_dist_cache[idx]; - float offset_end = baked_dist_cache[idx + 1]; + real_t offset_begin = baked_dist_cache[idx]; + real_t offset_end = baked_dist_cache[idx + 1]; - float idx_interval = offset_end - offset_begin; + real_t idx_interval = offset_end - offset_begin; ERR_FAIL_COND_V_MSG(p_offset < offset_begin || p_offset > offset_end, Vector2(), "failed to find baked segment"); - float frac = (p_offset - offset_begin) / idx_interval; + real_t frac = (p_offset - offset_begin) / idx_interval; if (p_cubic) { Vector2 pre = idx > 0 ? r[idx - 1] : r[idx]; @@ -818,13 +818,13 @@ PackedVector2Array Curve2D::get_baked_points() const { return baked_point_cache; } -void Curve2D::set_bake_interval(float p_tolerance) { +void Curve2D::set_bake_interval(real_t p_tolerance) { bake_interval = p_tolerance; baked_cache_dirty = true; emit_signal(CoreStringNames::get_singleton()->changed); } -float Curve2D::get_bake_interval() const { +real_t Curve2D::get_bake_interval() const { return bake_interval; } @@ -846,16 +846,16 @@ Vector2 Curve2D::get_closest_point(const Vector2 &p_to_point) const { const Vector2 *r = baked_point_cache.ptr(); Vector2 nearest; - float nearest_dist = -1.0f; + real_t nearest_dist = -1.0f; for (int i = 0; i < pc - 1; i++) { Vector2 origin = r[i]; Vector2 direction = (r[i + 1] - origin) / bake_interval; - float d = CLAMP((p_to_point - origin).dot(direction), 0.0f, bake_interval); + real_t d = CLAMP((p_to_point - origin).dot(direction), 0.0f, bake_interval); Vector2 proj = origin + direction * d; - float dist = proj.distance_squared_to(p_to_point); + real_t dist = proj.distance_squared_to(p_to_point); if (nearest_dist < 0.0f || dist < nearest_dist) { nearest = proj; @@ -866,7 +866,7 @@ Vector2 Curve2D::get_closest_point(const Vector2 &p_to_point) const { return nearest; } -float Curve2D::get_closest_offset(const Vector2 &p_to_point) const { +real_t Curve2D::get_closest_offset(const Vector2 &p_to_point) const { // Brute force method if (baked_cache_dirty) { @@ -883,18 +883,18 @@ float Curve2D::get_closest_offset(const Vector2 &p_to_point) const { const Vector2 *r = baked_point_cache.ptr(); - float nearest = 0.0f; - float nearest_dist = -1.0f; - float offset = 0.0f; + real_t nearest = 0.0f; + real_t nearest_dist = -1.0f; + real_t offset = 0.0f; for (int i = 0; i < pc - 1; i++) { Vector2 origin = r[i]; Vector2 direction = (r[i + 1] - origin) / bake_interval; - float d = CLAMP((p_to_point - origin).dot(direction), 0.0f, bake_interval); + real_t d = CLAMP((p_to_point - origin).dot(direction), 0.0f, bake_interval); Vector2 proj = origin + direction * d; - float dist = proj.distance_squared_to(p_to_point); + real_t dist = proj.distance_squared_to(p_to_point); if (nearest_dist < 0.0f || dist < nearest_dist) { nearest = offset + d; @@ -917,7 +917,7 @@ Dictionary Curve2D::_get_data() const { for (int i = 0; i < points.size(); i++) { w[i * 3 + 0] = points[i].in; w[i * 3 + 1] = points[i].out; - w[i * 3 + 2] = points[i].pos; + w[i * 3 + 2] = points[i].position; } dc["points"] = d; @@ -937,42 +937,42 @@ void Curve2D::_set_data(const Dictionary &p_data) { for (int i = 0; i < points.size(); i++) { points.write[i].in = r[i * 3 + 0]; points.write[i].out = r[i * 3 + 1]; - points.write[i].pos = r[i * 3 + 2]; + points.write[i].position = r[i * 3 + 2]; } baked_cache_dirty = true; } -PackedVector2Array Curve2D::tessellate(int p_max_stages, float p_tolerance) const { +PackedVector2Array Curve2D::tessellate(int p_max_stages, real_t p_tolerance) const { PackedVector2Array tess; if (points.size() == 0) { return tess; } - Vector<Map<float, Vector2>> midpoints; + Vector<Map<real_t, Vector2>> midpoints; midpoints.resize(points.size() - 1); int pc = 1; for (int i = 0; i < points.size() - 1; i++) { - _bake_segment2d(midpoints.write[i], 0, 1, points[i].pos, points[i].out, points[i + 1].pos, points[i + 1].in, 0, p_max_stages, p_tolerance); + _bake_segment2d(midpoints.write[i], 0, 1, points[i].position, points[i].out, points[i + 1].position, points[i + 1].in, 0, p_max_stages, p_tolerance); pc++; pc += midpoints[i].size(); } tess.resize(pc); Vector2 *bpw = tess.ptrw(); - bpw[0] = points[0].pos; + bpw[0] = points[0].position; int pidx = 0; for (int i = 0; i < points.size() - 1; i++) { - for (const KeyValue<float, Vector2> &E : midpoints[i]) { + for (const KeyValue<real_t, Vector2> &E : midpoints[i]) { pidx++; bpw[pidx] = E.value; } pidx++; - bpw[pidx] = points[i + 1].pos; + bpw[pidx] = points[i + 1].position; } return tess; @@ -1026,9 +1026,9 @@ int Curve3D::get_point_count() const { return points.size(); } -void Curve3D::add_point(const Vector3 &p_pos, const Vector3 &p_in, const Vector3 &p_out, int p_atpos) { +void Curve3D::add_point(const Vector3 &p_position, const Vector3 &p_in, const Vector3 &p_out, int p_atpos) { Point n; - n.pos = p_pos; + n.position = p_position; n.in = p_in; n.out = p_out; if (p_atpos >= 0 && p_atpos < points.size()) { @@ -1041,20 +1041,20 @@ void Curve3D::add_point(const Vector3 &p_pos, const Vector3 &p_in, const Vector3 emit_signal(CoreStringNames::get_singleton()->changed); } -void Curve3D::set_point_position(int p_index, const Vector3 &p_pos) { +void Curve3D::set_point_position(int p_index, const Vector3 &p_position) { ERR_FAIL_INDEX(p_index, points.size()); - points.write[p_index].pos = p_pos; + points.write[p_index].position = p_position; baked_cache_dirty = true; emit_signal(CoreStringNames::get_singleton()->changed); } Vector3 Curve3D::get_point_position(int p_index) const { ERR_FAIL_INDEX_V(p_index, points.size(), Vector3()); - return points[p_index].pos; + return points[p_index].position; } -void Curve3D::set_point_tilt(int p_index, float p_tilt) { +void Curve3D::set_point_tilt(int p_index, real_t p_tilt) { ERR_FAIL_INDEX(p_index, points.size()); points.write[p_index].tilt = p_tilt; @@ -1062,7 +1062,7 @@ void Curve3D::set_point_tilt(int p_index, float p_tilt) { emit_signal(CoreStringNames::get_singleton()->changed); } -float Curve3D::get_point_tilt(int p_index) const { +real_t Curve3D::get_point_tilt(int p_index) const { ERR_FAIL_INDEX_V(p_index, points.size(), 0); return points[p_index].tilt; } @@ -1108,19 +1108,19 @@ void Curve3D::clear_points() { } } -Vector3 Curve3D::interpolate(int p_index, float p_offset) const { +Vector3 Curve3D::interpolate(int p_index, real_t p_offset) const { int pc = points.size(); ERR_FAIL_COND_V(pc == 0, Vector3()); if (p_index >= pc - 1) { - return points[pc - 1].pos; + return points[pc - 1].position; } else if (p_index < 0) { - return points[0].pos; + return points[0].position; } - Vector3 p0 = points[p_index].pos; + Vector3 p0 = points[p_index].position; Vector3 p1 = p0 + points[p_index].out; - Vector3 p3 = points[p_index + 1].pos; + Vector3 p3 = points[p_index + 1].position; Vector3 p2 = p3 + points[p_index + 1].in; return _bezier_interp(p_offset, p0, p1, p2, p3); @@ -1136,15 +1136,15 @@ Vector3 Curve3D::interpolatef(real_t p_findex) const { return interpolate((int)p_findex, Math::fmod(p_findex, (real_t)1.0)); } -void Curve3D::_bake_segment3d(Map<float, Vector3> &r_bake, float p_begin, float p_end, const Vector3 &p_a, const Vector3 &p_out, const Vector3 &p_b, const Vector3 &p_in, int p_depth, int p_max_depth, float p_tol) const { - float mp = p_begin + (p_end - p_begin) * 0.5; +void Curve3D::_bake_segment3d(Map<real_t, Vector3> &r_bake, real_t p_begin, real_t p_end, const Vector3 &p_a, const Vector3 &p_out, const Vector3 &p_b, const Vector3 &p_in, int p_depth, int p_max_depth, real_t p_tol) const { + real_t mp = p_begin + (p_end - p_begin) * 0.5; Vector3 beg = _bezier_interp(p_begin, p_a, p_a + p_out, p_b + p_in, p_b); Vector3 mid = _bezier_interp(mp, p_a, p_a + p_out, p_b + p_in, p_b); Vector3 end = _bezier_interp(p_end, p_a, p_a + p_out, p_b + p_in, p_b); Vector3 na = (mid - beg).normalized(); Vector3 nb = (end - mid).normalized(); - float dp = na.dot(nb); + real_t dp = na.dot(nb); if (dp < Math::cos(Math::deg2rad(p_tol))) { r_bake[mp] = mid; @@ -1173,7 +1173,7 @@ void Curve3D::_bake() const { if (points.size() == 1) { baked_point_cache.resize(1); - baked_point_cache.set(0, points[0].pos); + baked_point_cache.set(0, points[0].position); baked_tilt_cache.resize(1); baked_tilt_cache.set(0, points[0].tilt); baked_dist_cache.resize(1); @@ -1189,39 +1189,39 @@ void Curve3D::_bake() const { return; } - Vector3 pos = points[0].pos; - float dist = 0.0; + Vector3 position = points[0].position; + real_t dist = 0.0; List<Plane> pointlist; - List<float> distlist; + List<real_t> distlist; - pointlist.push_back(Plane(pos, points[0].tilt)); + pointlist.push_back(Plane(position, points[0].tilt)); distlist.push_back(0.0); for (int i = 0; i < points.size() - 1; i++) { - float step = 0.1; // at least 10 substeps ought to be enough? - float p = 0.0; + real_t step = 0.1; // at least 10 substeps ought to be enough? + real_t p = 0.0; while (p < 1.0) { - float np = p + step; + real_t np = p + step; if (np > 1.0) { np = 1.0; } - Vector3 npp = _bezier_interp(np, points[i].pos, points[i].pos + points[i].out, points[i + 1].pos + points[i + 1].in, points[i + 1].pos); - float d = pos.distance_to(npp); + Vector3 npp = _bezier_interp(np, points[i].position, points[i].position + points[i].out, points[i + 1].position + points[i + 1].in, points[i + 1].position); + real_t d = position.distance_to(npp); if (d > bake_interval) { // OK! between P and NP there _has_ to be Something, let's go searching! int iterations = 10; //lots of detail! - float low = p; - float hi = np; - float mid = low + (hi - low) * 0.5; + real_t low = p; + real_t hi = np; + real_t mid = low + (hi - low) * 0.5; for (int j = 0; j < iterations; j++) { - npp = _bezier_interp(mid, points[i].pos, points[i].pos + points[i].out, points[i + 1].pos + points[i + 1].in, points[i + 1].pos); - d = pos.distance_to(npp); + npp = _bezier_interp(mid, points[i].position, points[i].position + points[i].out, points[i + 1].position + points[i + 1].in, points[i + 1].position); + d = position.distance_to(npp); if (bake_interval < d) { hi = mid; @@ -1231,10 +1231,10 @@ void Curve3D::_bake() const { mid = low + (hi - low) * 0.5; } - pos = npp; + position = npp; p = mid; Plane post; - post.normal = pos; + post.normal = position; post.d = Math::lerp(points[i].tilt, points[i + 1].tilt, mid); dist += d; @@ -1246,10 +1246,10 @@ void Curve3D::_bake() const { } } - Vector3 lastpos = points[points.size() - 1].pos; - float lastilt = points[points.size() - 1].tilt; + Vector3 lastpos = points[points.size() - 1].position; + real_t lastilt = points[points.size() - 1].tilt; - float rem = pos.distance_to(lastpos); + real_t rem = position.distance_to(lastpos); dist += rem; baked_max_ofs = dist; pointlist.push_back(Plane(lastpos, lastilt)); @@ -1266,7 +1266,7 @@ void Curve3D::_bake() const { Vector3 *up_write = baked_up_vector_cache.ptrw(); baked_dist_cache.resize(pointlist.size()); - float *wd = baked_dist_cache.ptrw(); + real_t *wd = baked_dist_cache.ptrw(); Vector3 sideways; Vector3 up; @@ -1288,7 +1288,7 @@ void Curve3D::_bake() const { forward = idx > 0 ? (w[idx] - w[idx - 1]).normalized() : prev_forward; - float y_dot = prev_up.dot(forward); + real_t y_dot = prev_up.dot(forward); if (y_dot > (1.0f - CMP_EPSILON)) { sideways = prev_sideways; @@ -1315,7 +1315,7 @@ void Curve3D::_bake() const { } } -float Curve3D::get_baked_length() const { +real_t Curve3D::get_baked_length() const { if (baked_cache_dirty) { _bake(); } @@ -1323,7 +1323,7 @@ float Curve3D::get_baked_length() const { return baked_max_ofs; } -Vector3 Curve3D::interpolate_baked(float p_offset, bool p_cubic) const { +Vector3 Curve3D::interpolate_baked(real_t p_offset, bool p_cubic) const { if (baked_cache_dirty) { _bake(); } @@ -1349,7 +1349,7 @@ Vector3 Curve3D::interpolate_baked(float p_offset, bool p_cubic) const { int start = 0, end = bpc, idx = (end + start) / 2; // binary search to find baked points while (start < idx) { - float offset = baked_dist_cache[idx]; + real_t offset = baked_dist_cache[idx]; if (p_offset <= offset) { end = idx; } else { @@ -1358,13 +1358,13 @@ Vector3 Curve3D::interpolate_baked(float p_offset, bool p_cubic) const { idx = (end + start) / 2; } - float offset_begin = baked_dist_cache[idx]; - float offset_end = baked_dist_cache[idx + 1]; + real_t offset_begin = baked_dist_cache[idx]; + real_t offset_end = baked_dist_cache[idx + 1]; - float idx_interval = offset_end - offset_begin; + real_t idx_interval = offset_end - offset_begin; ERR_FAIL_COND_V_MSG(p_offset < offset_begin || p_offset > offset_end, Vector3(), "failed to find baked segment"); - float frac = (p_offset - offset_begin) / idx_interval; + real_t frac = (p_offset - offset_begin) / idx_interval; if (p_cubic) { Vector3 pre = idx > 0 ? r[idx - 1] : r[idx]; @@ -1375,7 +1375,7 @@ Vector3 Curve3D::interpolate_baked(float p_offset, bool p_cubic) const { } } -float Curve3D::interpolate_baked_tilt(float p_offset) const { +real_t Curve3D::interpolate_baked_tilt(real_t p_offset) const { if (baked_cache_dirty) { _bake(); } @@ -1399,7 +1399,7 @@ float Curve3D::interpolate_baked_tilt(float p_offset) const { } int idx = Math::floor((double)p_offset / (double)bake_interval); - float frac = Math::fmod(p_offset, bake_interval); + real_t frac = Math::fmod(p_offset, bake_interval); if (idx >= bpc - 1) { return r[bpc - 1]; @@ -1414,7 +1414,7 @@ float Curve3D::interpolate_baked_tilt(float p_offset) const { return Math::lerp(r[idx], r[idx + 1], (real_t)frac); } -Vector3 Curve3D::interpolate_baked_up_vector(float p_offset, bool p_apply_tilt) const { +Vector3 Curve3D::interpolate_baked_up_vector(real_t p_offset, bool p_apply_tilt) const { if (baked_cache_dirty) { _bake(); } @@ -1432,10 +1432,10 @@ Vector3 Curve3D::interpolate_baked_up_vector(float p_offset, bool p_apply_tilt) const Vector3 *rp = baked_point_cache.ptr(); const real_t *rt = baked_tilt_cache.ptr(); - float offset = CLAMP(p_offset, 0.0f, baked_max_ofs); + real_t offset = CLAMP(p_offset, 0.0f, baked_max_ofs); int idx = Math::floor((double)offset / (double)bake_interval); - float frac = Math::fmod(offset, bake_interval) / bake_interval; + real_t frac = Math::fmod(offset, bake_interval) / bake_interval; if (idx == count - 1) { return p_apply_tilt ? r[idx].rotated((rp[idx] - rp[idx - 1]).normalized(), rt[idx]) : r[idx]; @@ -1503,16 +1503,16 @@ Vector3 Curve3D::get_closest_point(const Vector3 &p_to_point) const { const Vector3 *r = baked_point_cache.ptr(); Vector3 nearest; - float nearest_dist = -1.0f; + real_t nearest_dist = -1.0f; for (int i = 0; i < pc - 1; i++) { Vector3 origin = r[i]; Vector3 direction = (r[i + 1] - origin) / bake_interval; - float d = CLAMP((p_to_point - origin).dot(direction), 0.0f, bake_interval); + real_t d = CLAMP((p_to_point - origin).dot(direction), 0.0f, bake_interval); Vector3 proj = origin + direction * d; - float dist = proj.distance_squared_to(p_to_point); + real_t dist = proj.distance_squared_to(p_to_point); if (nearest_dist < 0.0f || dist < nearest_dist) { nearest = proj; @@ -1523,7 +1523,7 @@ Vector3 Curve3D::get_closest_point(const Vector3 &p_to_point) const { return nearest; } -float Curve3D::get_closest_offset(const Vector3 &p_to_point) const { +real_t Curve3D::get_closest_offset(const Vector3 &p_to_point) const { // Brute force method if (baked_cache_dirty) { @@ -1540,18 +1540,18 @@ float Curve3D::get_closest_offset(const Vector3 &p_to_point) const { const Vector3 *r = baked_point_cache.ptr(); - float nearest = 0.0f; - float nearest_dist = -1.0f; - float offset = 0.0f; + real_t nearest = 0.0f; + real_t nearest_dist = -1.0f; + real_t offset = 0.0f; for (int i = 0; i < pc - 1; i++) { Vector3 origin = r[i]; Vector3 direction = (r[i + 1] - origin) / bake_interval; - float d = CLAMP((p_to_point - origin).dot(direction), 0.0f, bake_interval); + real_t d = CLAMP((p_to_point - origin).dot(direction), 0.0f, bake_interval); Vector3 proj = origin + direction * d; - float dist = proj.distance_squared_to(p_to_point); + real_t dist = proj.distance_squared_to(p_to_point); if (nearest_dist < 0.0f || dist < nearest_dist) { nearest = offset + d; @@ -1564,13 +1564,13 @@ float Curve3D::get_closest_offset(const Vector3 &p_to_point) const { return nearest; } -void Curve3D::set_bake_interval(float p_tolerance) { +void Curve3D::set_bake_interval(real_t p_tolerance) { bake_interval = p_tolerance; baked_cache_dirty = true; emit_signal(CoreStringNames::get_singleton()->changed); } -float Curve3D::get_bake_interval() const { +real_t Curve3D::get_bake_interval() const { return bake_interval; } @@ -1597,7 +1597,7 @@ Dictionary Curve3D::_get_data() const { for (int i = 0; i < points.size(); i++) { w[i * 3 + 0] = points[i].in; w[i * 3 + 1] = points[i].out; - w[i * 3 + 2] = points[i].pos; + w[i * 3 + 2] = points[i].position; wt[i] = points[i].tilt; } @@ -1622,43 +1622,43 @@ void Curve3D::_set_data(const Dictionary &p_data) { for (int i = 0; i < points.size(); i++) { points.write[i].in = r[i * 3 + 0]; points.write[i].out = r[i * 3 + 1]; - points.write[i].pos = r[i * 3 + 2]; + points.write[i].position = r[i * 3 + 2]; points.write[i].tilt = rt[i]; } baked_cache_dirty = true; } -PackedVector3Array Curve3D::tessellate(int p_max_stages, float p_tolerance) const { +PackedVector3Array Curve3D::tessellate(int p_max_stages, real_t p_tolerance) const { PackedVector3Array tess; if (points.size() == 0) { return tess; } - Vector<Map<float, Vector3>> midpoints; + Vector<Map<real_t, Vector3>> midpoints; midpoints.resize(points.size() - 1); int pc = 1; for (int i = 0; i < points.size() - 1; i++) { - _bake_segment3d(midpoints.write[i], 0, 1, points[i].pos, points[i].out, points[i + 1].pos, points[i + 1].in, 0, p_max_stages, p_tolerance); + _bake_segment3d(midpoints.write[i], 0, 1, points[i].position, points[i].out, points[i + 1].position, points[i + 1].in, 0, p_max_stages, p_tolerance); pc++; pc += midpoints[i].size(); } tess.resize(pc); Vector3 *bpw = tess.ptrw(); - bpw[0] = points[0].pos; + bpw[0] = points[0].position; int pidx = 0; for (int i = 0; i < points.size() - 1; i++) { - for (const KeyValue<float, Vector3> &E : midpoints[i]) { + for (const KeyValue<real_t, Vector3> &E : midpoints[i]) { pidx++; bpw[pidx] = E.value; } pidx++; - bpw[pidx] = points[i + 1].pos; + bpw[pidx] = points[i + 1].position; } return tess; diff --git a/scene/resources/curve.h b/scene/resources/curve.h index 5808fd6508..16facda85a 100644 --- a/scene/resources/curve.h +++ b/scene/resources/curve.h @@ -50,7 +50,7 @@ public: }; struct Point { - Vector2 pos; + Vector2 position; real_t left_tangent = 0.0; real_t right_tangent = 0.0; TangentMode left_mode = TANGENT_FREE; @@ -59,12 +59,12 @@ public: Point() { } - Point(Vector2 p_pos, + Point(const Vector2 &p_position, real_t p_left = 0.0, real_t p_right = 0.0, TangentMode p_left_mode = TANGENT_FREE, TangentMode p_right_mode = TANGENT_FREE) { - pos = p_pos; + position = p_position; left_tangent = p_left; right_tangent = p_right; left_mode = p_left_mode; @@ -76,7 +76,7 @@ public: int get_point_count() const { return _points.size(); } - int add_point(Vector2 p_pos, + int add_point(Vector2 p_position, real_t left_tangent = 0, real_t right_tangent = 0, TangentMode left_mode = TANGENT_FREE, @@ -85,34 +85,34 @@ public: void remove_point(int p_index); void clear_points(); - int get_index(real_t offset) const; + int get_index(real_t p_offset) const; - void set_point_value(int p_index, real_t pos); - int set_point_offset(int p_index, float offset); + void set_point_value(int p_index, real_t p_position); + int set_point_offset(int p_index, real_t p_offset); Vector2 get_point_position(int p_index) const; Point get_point(int p_index) const; - float get_min_value() const { return _min_value; } - void set_min_value(float p_min); + real_t get_min_value() const { return _min_value; } + void set_min_value(real_t p_min); - float get_max_value() const { return _max_value; } - void set_max_value(float p_max); + real_t get_max_value() const { return _max_value; } + void set_max_value(real_t p_max); - real_t interpolate(real_t offset) const; - real_t interpolate_local_nocheck(int index, real_t local_offset) const; + real_t interpolate(real_t p_offset) const; + real_t interpolate_local_nocheck(int p_index, real_t p_local_offset) const; void clean_dupes(); - void set_point_left_tangent(int i, real_t tangent); - void set_point_right_tangent(int i, real_t tangent); - void set_point_left_mode(int i, TangentMode p_mode); - void set_point_right_mode(int i, TangentMode p_mode); + void set_point_left_tangent(int p_index, real_t p_tangent); + void set_point_right_tangent(int p_index, real_t p_tangent); + void set_point_left_mode(int p_index, TangentMode p_mode); + void set_point_right_mode(int p_index, TangentMode p_mode); - real_t get_point_left_tangent(int i) const; - real_t get_point_right_tangent(int i) const; - TangentMode get_point_left_mode(int i) const; - TangentMode get_point_right_mode(int i) const; + real_t get_point_left_tangent(int p_index) const; + real_t get_point_right_tangent(int p_index) const; + TangentMode get_point_left_mode(int p_index) const; + TangentMode get_point_right_mode(int p_index) const; void update_auto_tangents(int i); @@ -122,9 +122,9 @@ public: void bake(); int get_bake_resolution() const { return _bake_resolution; } void set_bake_resolution(int p_resolution); - real_t interpolate_baked(real_t offset) const; + real_t interpolate_baked(real_t p_offset) const; - void ensure_default_setup(float p_min, float p_max); + void ensure_default_setup(real_t p_min, real_t p_max); protected: static void _bind_methods(); @@ -136,8 +136,8 @@ private: bool _baked_cache_dirty = false; Vector<real_t> _baked_cache; int _bake_resolution = 100; - float _min_value = 0.0; - float _max_value = 1.0; + real_t _min_value = 0.0; + real_t _max_value = 1.0; int _minmax_set_once = 0b00; // Encodes whether min and max have been set a first time, first bit for min and second for max. }; @@ -149,26 +149,26 @@ class Curve2D : public Resource { struct Point { Vector2 in; Vector2 out; - Vector2 pos; + Vector2 position; }; Vector<Point> points; struct BakedPoint { - float ofs = 0.0; + real_t ofs = 0.0; Vector2 point; }; mutable bool baked_cache_dirty = false; mutable PackedVector2Array baked_point_cache; - mutable PackedFloat32Array baked_dist_cache; - mutable float baked_max_ofs = 0.0; + mutable Vector<real_t> baked_dist_cache; + mutable real_t baked_max_ofs = 0.0; void _bake() const; - float bake_interval = 5.0; + real_t bake_interval = 5.0; - void _bake_segment2d(Map<float, Vector2> &r_bake, float p_begin, float p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_max_depth, float p_tol) const; + void _bake_segment2d(Map<real_t, Vector2> &r_bake, real_t p_begin, real_t p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_max_depth, real_t p_tol) const; Dictionary _get_data() const; void _set_data(const Dictionary &p_data); @@ -177,8 +177,8 @@ protected: public: int get_point_count() const; - void add_point(const Vector2 &p_pos, const Vector2 &p_in = Vector2(), const Vector2 &p_out = Vector2(), int p_atpos = -1); - void set_point_position(int p_index, const Vector2 &p_pos); + void add_point(const Vector2 &p_position, const Vector2 &p_in = Vector2(), const Vector2 &p_out = Vector2(), int p_atpos = -1); + void set_point_position(int p_index, const Vector2 &p_position); Vector2 get_point_position(int p_index) const; void set_point_in(int p_index, const Vector2 &p_in); Vector2 get_point_in(int p_index) const; @@ -187,19 +187,19 @@ public: void remove_point(int p_index); void clear_points(); - Vector2 interpolate(int p_index, float p_offset) const; + Vector2 interpolate(int p_index, real_t p_offset) const; Vector2 interpolatef(real_t p_findex) const; - void set_bake_interval(float p_tolerance); - float get_bake_interval() const; + void set_bake_interval(real_t p_tolerance); + real_t get_bake_interval() const; - float get_baked_length() const; - Vector2 interpolate_baked(float p_offset, bool p_cubic = false) const; + real_t get_baked_length() const; + Vector2 interpolate_baked(real_t p_offset, bool p_cubic = false) const; PackedVector2Array get_baked_points() const; //useful for going through Vector2 get_closest_point(const Vector2 &p_to_point) const; - float get_closest_offset(const Vector2 &p_to_point) const; + real_t get_closest_offset(const Vector2 &p_to_point) const; - PackedVector2Array tessellate(int p_max_stages = 5, float p_tolerance = 4) const; //useful for display + PackedVector2Array tessellate(int p_max_stages = 5, real_t p_tolerance = 4) const; //useful for display Curve2D(); }; @@ -210,14 +210,14 @@ class Curve3D : public Resource { struct Point { Vector3 in; Vector3 out; - Vector3 pos; - float tilt = 0.0; + Vector3 position; + real_t tilt = 0.0; }; Vector<Point> points; struct BakedPoint { - float ofs = 0.0; + real_t ofs = 0.0; Vector3 point; }; @@ -225,15 +225,15 @@ class Curve3D : public Resource { mutable PackedVector3Array baked_point_cache; mutable Vector<real_t> baked_tilt_cache; mutable PackedVector3Array baked_up_vector_cache; - mutable PackedFloat32Array baked_dist_cache; - mutable float baked_max_ofs = 0.0; + mutable Vector<real_t> baked_dist_cache; + mutable real_t baked_max_ofs = 0.0; void _bake() const; - float bake_interval = 0.2; + real_t bake_interval = 0.2; bool up_vector_enabled = true; - void _bake_segment3d(Map<float, Vector3> &r_bake, float p_begin, float p_end, const Vector3 &p_a, const Vector3 &p_out, const Vector3 &p_b, const Vector3 &p_in, int p_depth, int p_max_depth, float p_tol) const; + void _bake_segment3d(Map<real_t, Vector3> &r_bake, real_t p_begin, real_t p_end, const Vector3 &p_a, const Vector3 &p_out, const Vector3 &p_b, const Vector3 &p_in, int p_depth, int p_max_depth, real_t p_tol) const; Dictionary _get_data() const; void _set_data(const Dictionary &p_data); @@ -242,11 +242,11 @@ protected: public: int get_point_count() const; - void add_point(const Vector3 &p_pos, const Vector3 &p_in = Vector3(), const Vector3 &p_out = Vector3(), int p_atpos = -1); - void set_point_position(int p_index, const Vector3 &p_pos); + void add_point(const Vector3 &p_position, const Vector3 &p_in = Vector3(), const Vector3 &p_out = Vector3(), int p_atpos = -1); + void set_point_position(int p_index, const Vector3 &p_position); Vector3 get_point_position(int p_index) const; - void set_point_tilt(int p_index, float p_tilt); - float get_point_tilt(int p_index) const; + void set_point_tilt(int p_index, real_t p_tilt); + real_t get_point_tilt(int p_index) const; void set_point_in(int p_index, const Vector3 &p_in); Vector3 get_point_in(int p_index) const; void set_point_out(int p_index, const Vector3 &p_out); @@ -254,25 +254,25 @@ public: void remove_point(int p_index); void clear_points(); - Vector3 interpolate(int p_index, float p_offset) const; + Vector3 interpolate(int p_index, real_t p_offset) const; Vector3 interpolatef(real_t p_findex) const; - void set_bake_interval(float p_tolerance); - float get_bake_interval() const; + void set_bake_interval(real_t p_tolerance); + real_t get_bake_interval() const; void set_up_vector_enabled(bool p_enable); bool is_up_vector_enabled() const; - float get_baked_length() const; - Vector3 interpolate_baked(float p_offset, bool p_cubic = false) const; - float interpolate_baked_tilt(float p_offset) const; - Vector3 interpolate_baked_up_vector(float p_offset, bool p_apply_tilt = false) const; + real_t get_baked_length() const; + Vector3 interpolate_baked(real_t p_offset, bool p_cubic = false) const; + real_t interpolate_baked_tilt(real_t p_offset) const; + Vector3 interpolate_baked_up_vector(real_t p_offset, bool p_apply_tilt = false) const; PackedVector3Array get_baked_points() const; //useful for going through Vector<real_t> get_baked_tilts() const; //useful for going through PackedVector3Array get_baked_up_vectors() const; Vector3 get_closest_point(const Vector3 &p_to_point) const; - float get_closest_offset(const Vector3 &p_to_point) const; + real_t get_closest_offset(const Vector3 &p_to_point) const; - PackedVector3Array tessellate(int p_max_stages = 5, float p_tolerance = 4) const; //useful for display + PackedVector3Array tessellate(int p_max_stages = 5, real_t p_tolerance = 4) const; //useful for display Curve3D(); }; diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index d88a2c557b..e5740472c6 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -1152,11 +1152,11 @@ void Font::_bind_methods() { ClassDB::bind_method(D_METHOD("get_underline_position", "size"), &Font::get_underline_position, DEFVAL(DEFAULT_FONT_SIZE)); ClassDB::bind_method(D_METHOD("get_underline_thickness", "size"), &Font::get_underline_thickness, DEFVAL(DEFAULT_FONT_SIZE)); - ClassDB::bind_method(D_METHOD("get_string_size", "text", "size", "align", "width", "flags"), &Font::get_string_size, DEFVAL(DEFAULT_FONT_SIZE), DEFVAL(HALIGN_LEFT), DEFVAL(-1), DEFVAL(TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND)); + ClassDB::bind_method(D_METHOD("get_string_size", "text", "size", "alignment", "width", "flags"), &Font::get_string_size, DEFVAL(DEFAULT_FONT_SIZE), DEFVAL(HORIZONTAL_ALIGNMENT_LEFT), DEFVAL(-1), DEFVAL(TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND)); ClassDB::bind_method(D_METHOD("get_multiline_string_size", "text", "width", "size", "flags"), &Font::get_multiline_string_size, DEFVAL(-1), DEFVAL(DEFAULT_FONT_SIZE), DEFVAL(TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND)); - ClassDB::bind_method(D_METHOD("draw_string", "canvas_item", "pos", "text", "align", "width", "size", "modulate", "outline_size", "outline_modulate", "flags"), &Font::draw_string, DEFVAL(HALIGN_LEFT), DEFVAL(-1), DEFVAL(DEFAULT_FONT_SIZE), DEFVAL(Color(1, 1, 1)), DEFVAL(0), DEFVAL(Color(1, 1, 1, 0)), DEFVAL(TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND)); - ClassDB::bind_method(D_METHOD("draw_multiline_string", "canvas_item", "pos", "text", "align", "width", "max_lines", "size", "modulate", "outline_size", "outline_modulate", "flags"), &Font::draw_multiline_string, DEFVAL(HALIGN_LEFT), DEFVAL(-1), DEFVAL(-1), DEFVAL(DEFAULT_FONT_SIZE), DEFVAL(Color(1, 1, 1)), DEFVAL(0), DEFVAL(Color(1, 1, 1, 0)), DEFVAL(TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND | TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND)); + ClassDB::bind_method(D_METHOD("draw_string", "canvas_item", "pos", "text", "alignment", "width", "size", "modulate", "outline_size", "outline_modulate", "flags"), &Font::draw_string, DEFVAL(HORIZONTAL_ALIGNMENT_LEFT), DEFVAL(-1), DEFVAL(DEFAULT_FONT_SIZE), DEFVAL(Color(1, 1, 1)), DEFVAL(0), DEFVAL(Color(1, 1, 1, 0)), DEFVAL(TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND)); + ClassDB::bind_method(D_METHOD("draw_multiline_string", "canvas_item", "pos", "text", "alignment", "width", "max_lines", "size", "modulate", "outline_size", "outline_modulate", "flags"), &Font::draw_multiline_string, DEFVAL(HORIZONTAL_ALIGNMENT_LEFT), DEFVAL(-1), DEFVAL(-1), DEFVAL(DEFAULT_FONT_SIZE), DEFVAL(Color(1, 1, 1)), DEFVAL(0), DEFVAL(Color(1, 1, 1, 0)), DEFVAL(TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND | TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND)); ClassDB::bind_method(D_METHOD("get_char_size", "char", "next", "size"), &Font::get_char_size, DEFVAL(0), DEFVAL(DEFAULT_FONT_SIZE)); ClassDB::bind_method(D_METHOD("draw_char", "canvas_item", "pos", "char", "next", "size", "modulate", "outline_size", "outline_modulate"), &Font::draw_char, DEFVAL(0), DEFVAL(DEFAULT_FONT_SIZE), DEFVAL(Color(1, 1, 1)), DEFVAL(0), DEFVAL(Color(1, 1, 1, 0))); @@ -1449,7 +1449,7 @@ real_t Font::get_underline_thickness(int p_size) const { return ret; } -Size2 Font::get_string_size(const String &p_text, int p_size, HAlign p_align, real_t p_width, uint16_t p_flags) const { +Size2 Font::get_string_size(const String &p_text, int p_size, HorizontalAlignment p_alignment, float p_width, uint16_t p_flags) const { ERR_FAIL_COND_V(data.is_empty(), Size2()); for (int i = 0; i < data.size(); i++) { @@ -1457,7 +1457,7 @@ Size2 Font::get_string_size(const String &p_text, int p_size, HAlign p_align, re } uint64_t hash = p_text.hash64(); - if (p_align == HALIGN_FILL) { + if (p_alignment == HORIZONTAL_ALIGNMENT_FILL) { hash = hash_djb2_one_64(hash_djb2_one_float(p_width), hash); hash = hash_djb2_one_64(p_flags, hash); } @@ -1474,7 +1474,7 @@ Size2 Font::get_string_size(const String &p_text, int p_size, HAlign p_align, re return buffer->get_size(); } -Size2 Font::get_multiline_string_size(const String &p_text, real_t p_width, int p_size, uint16_t p_flags) const { +Size2 Font::get_multiline_string_size(const String &p_text, float p_width, int p_size, uint16_t p_flags) const { ERR_FAIL_COND_V(data.is_empty(), Size2()); for (int i = 0; i < data.size(); i++) { @@ -1511,7 +1511,7 @@ Size2 Font::get_multiline_string_size(const String &p_text, real_t p_width, int return ret; } -void Font::draw_string(RID p_canvas_item, const Point2 &p_pos, const String &p_text, HAlign p_align, real_t p_width, int p_size, const Color &p_modulate, int p_outline_size, const Color &p_outline_modulate, uint16_t p_flags) const { +void Font::draw_string(RID p_canvas_item, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment, float p_width, int p_size, const Color &p_modulate, int p_outline_size, const Color &p_outline_modulate, uint16_t p_flags) const { ERR_FAIL_COND(data.is_empty()); for (int i = 0; i < data.size(); i++) { @@ -1519,7 +1519,7 @@ void Font::draw_string(RID p_canvas_item, const Point2 &p_pos, const String &p_t } uint64_t hash = p_text.hash64(); - if (p_align == HALIGN_FILL) { + if (p_alignment == HORIZONTAL_ALIGNMENT_FILL) { hash = hash_djb2_one_64(hash_djb2_one_float(p_width), hash); hash = hash_djb2_one_64(p_flags, hash); } @@ -1542,7 +1542,7 @@ void Font::draw_string(RID p_canvas_item, const Point2 &p_pos, const String &p_t } buffer->set_width(p_width); - buffer->set_align(p_align); + buffer->set_horizontal_alignment(p_alignment); buffer->set_flags(p_flags); if (p_outline_size > 0 && p_outline_modulate.a != 0.0f) { @@ -1551,7 +1551,7 @@ void Font::draw_string(RID p_canvas_item, const Point2 &p_pos, const String &p_t buffer->draw(p_canvas_item, ofs, p_modulate); } -void Font::draw_multiline_string(RID p_canvas_item, const Point2 &p_pos, const String &p_text, HAlign p_align, float p_width, int p_max_lines, int p_size, const Color &p_modulate, int p_outline_size, const Color &p_outline_modulate, uint16_t p_flags) const { +void Font::draw_multiline_string(RID p_canvas_item, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment, float p_width, int p_max_lines, int p_size, const Color &p_modulate, int p_outline_size, const Color &p_outline_modulate, uint16_t p_flags) const { ERR_FAIL_COND(data.is_empty()); for (int i = 0; i < data.size(); i++) { @@ -1574,7 +1574,7 @@ void Font::draw_multiline_string(RID p_canvas_item, const Point2 &p_pos, const S cache_wrap.insert(wrp_hash, lines_buffer); } - lines_buffer->set_align(p_align); + lines_buffer->set_alignment(p_alignment); Vector2 lofs = p_pos; for (int i = 0; i < lines_buffer->get_line_count(); i++) { @@ -1588,7 +1588,7 @@ void Font::draw_multiline_string(RID p_canvas_item, const Point2 &p_pos, const S } } if (p_width > 0) { - lines_buffer->set_align(p_align); + lines_buffer->set_alignment(p_alignment); } if (p_outline_size > 0 && p_outline_modulate.a != 0.0f) { diff --git a/scene/resources/font.h b/scene/resources/font.h index 4d9ee72c84..fb662037a1 100644 --- a/scene/resources/font.h +++ b/scene/resources/font.h @@ -273,11 +273,11 @@ public: virtual real_t get_underline_thickness(int p_size = DEFAULT_FONT_SIZE) const; // Drawing string. - virtual Size2 get_string_size(const String &p_text, int p_size = DEFAULT_FONT_SIZE, HAlign p_align = HALIGN_LEFT, real_t p_width = -1, uint16_t p_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND) const; - virtual Size2 get_multiline_string_size(const String &p_text, real_t p_width = -1, int p_size = DEFAULT_FONT_SIZE, uint16_t p_flags = TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND) const; + virtual Size2 get_string_size(const String &p_text, int p_size = DEFAULT_FONT_SIZE, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, uint16_t p_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND) const; + virtual Size2 get_multiline_string_size(const String &p_text, float p_width = -1, int p_size = DEFAULT_FONT_SIZE, uint16_t p_flags = TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND) const; - virtual void draw_string(RID p_canvas_item, const Point2 &p_pos, const String &p_text, HAlign p_align = HALIGN_LEFT, real_t p_width = -1, int p_size = DEFAULT_FONT_SIZE, const Color &p_modulate = Color(1, 1, 1), int p_outline_size = 0, const Color &p_outline_modulate = Color(1, 1, 1, 0), uint16_t p_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND) const; - virtual void draw_multiline_string(RID p_canvas_item, const Point2 &p_pos, const String &p_text, HAlign p_align = HALIGN_LEFT, real_t p_width = -1, int p_max_lines = -1, int p_size = DEFAULT_FONT_SIZE, const Color &p_modulate = Color(1, 1, 1), int p_outline_size = 0, const Color &p_outline_modulate = Color(1, 1, 1, 0), uint16_t p_flags = TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND | TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND) const; + virtual void draw_string(RID p_canvas_item, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_size = DEFAULT_FONT_SIZE, const Color &p_modulate = Color(1, 1, 1), int p_outline_size = 0, const Color &p_outline_modulate = Color(1, 1, 1, 0), uint16_t p_flags = TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND) const; + virtual void draw_multiline_string(RID p_canvas_item, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, float p_width = -1, int p_max_lines = -1, int p_size = DEFAULT_FONT_SIZE, const Color &p_modulate = Color(1, 1, 1), int p_outline_size = 0, const Color &p_outline_modulate = Color(1, 1, 1, 0), uint16_t p_flags = TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND | TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND) const; // Helper functions. virtual bool has_char(char32_t p_char) const; diff --git a/scene/resources/immediate_mesh.cpp b/scene/resources/immediate_mesh.cpp index fe7124de9e..4f9a055bfb 100644 --- a/scene/resources/immediate_mesh.cpp +++ b/scene/resources/immediate_mesh.cpp @@ -144,6 +144,7 @@ void ImmediateMesh::surface_add_vertex_2d(const Vector2 &p_vertex) { active_surface_data.vertex_2d = true; } + void ImmediateMesh::surface_end() { ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it."); ERR_FAIL_COND_MSG(!vertices.size(), "No vertices were added, surface can't be created."); @@ -185,7 +186,7 @@ void ImmediateMesh::surface_end() { vtx[2] = vertices[i].z; } if (i == 0) { - aabb.position = vertices[i]; + aabb = AABB(vertices[i], SMALL_VEC3); // Must have a bit of size. } else { aabb.expand_to(vertices[i]); } diff --git a/scene/resources/immediate_mesh.h b/scene/resources/immediate_mesh.h index 6673ee6f3d..92bf91441d 100644 --- a/scene/resources/immediate_mesh.h +++ b/scene/resources/immediate_mesh.h @@ -75,6 +75,8 @@ class ImmediateMesh : public Mesh { Vector<uint8_t> surface_vertex_create_cache; Vector<uint8_t> surface_attribute_create_cache; + const Vector3 SMALL_VEC3 = Vector3(CMP_EPSILON, CMP_EPSILON, CMP_EPSILON); + protected: static void _bind_methods(); diff --git a/scene/resources/importer_mesh.cpp b/scene/resources/importer_mesh.cpp index 7afa4c91f0..b2b90f019e 100644 --- a/scene/resources/importer_mesh.cpp +++ b/scene/resources/importer_mesh.cpp @@ -485,7 +485,7 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli raycaster->intersect(rays); LocalVector<Vector3> ray_normals; - LocalVector<float> ray_normal_weights; + LocalVector<real_t> ray_normal_weights; ray_normals.resize(new_index_count); ray_normal_weights.resize(new_index_count); @@ -517,10 +517,10 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli Vector3 normal = n0 * w + n1 * u + n2 * v; Vector2 orig_uv = ray_uvs[j]; - float orig_bary[3] = { 1.0f - orig_uv.x - orig_uv.y, orig_uv.x, orig_uv.y }; + real_t orig_bary[3] = { 1.0f - orig_uv.x - orig_uv.y, orig_uv.x, orig_uv.y }; for (int k = 0; k < 3; k++) { int idx = orig_tri_id * 3 + k; - float weight = orig_bary[k]; + real_t weight = orig_bary[k]; ray_normals[idx] += normal * weight; ray_normal_weights[idx] += weight; } @@ -653,7 +653,7 @@ Ref<ArrayMesh> ImporterMesh::get_mesh(const Ref<ArrayMesh> &p_base) { if (surfaces[i].material.is_valid()) { mesh->surface_set_material(mesh->get_surface_count() - 1, surfaces[i].material); } - if (surfaces[i].name != String()) { + if (!surfaces[i].name.is_empty()) { mesh->surface_set_name(mesh->get_surface_count() - 1, surfaces[i].name); } } @@ -839,7 +839,7 @@ Dictionary ImporterMesh::_get_data() const { d["material"] = surfaces[i].material; } - if (surfaces[i].name != String()) { + if (!surfaces[i].name.is_empty()) { d["name"] = surfaces[i].name; } diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 8399b14a56..87aee0aae4 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -695,7 +695,7 @@ void BaseMaterial3D::_update_shader() { } if (features[FEATURE_ANISOTROPY]) { code += "uniform float anisotropy_ratio : hint_range(0,256);\n"; - code += "uniform sampler2D texture_flowmap : hint_aniso," + texfilter_str + ";\n"; + code += "uniform sampler2D texture_flowmap : hint_anisotropy," + texfilter_str + ";\n"; } if (features[FEATURE_AMBIENT_OCCLUSION]) { code += "uniform sampler2D texture_ambient_occlusion : hint_white, " + texfilter_str + ";\n"; @@ -1658,13 +1658,28 @@ bool BaseMaterial3D::get_feature(Feature p_feature) const { void BaseMaterial3D::set_texture(TextureParam p_param, const Ref<Texture2D> &p_texture) { ERR_FAIL_INDEX(p_param, TEXTURE_MAX); + + if (get_texture(TEXTURE_ROUGHNESS).is_null() && p_texture.is_valid() && p_param == TEXTURE_ROUGHNESS) { + // If no roughness texture is currently set, automatically set the recommended value + // for roughness when using a roughness map. + set_roughness(1.0); + } + + if (get_texture(TEXTURE_METALLIC).is_null() && p_texture.is_valid() && p_param == TEXTURE_METALLIC) { + // If no metallic texture is currently set, automatically set the recommended value + // for metallic when using a metallic map. + set_metallic(1.0); + } + textures[p_param] = p_texture; RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); RS::get_singleton()->material_set_param(_get_material(), shader_names->texture_names[p_param], rid); + if (p_texture.is_valid() && p_param == TEXTURE_ALBEDO) { RS::get_singleton()->material_set_param(_get_material(), shader_names->albedo_texture_size, Vector2i(p_texture->get_width(), p_texture->get_height())); } + notify_property_list_changed(); _queue_shader_change(); } @@ -2884,7 +2899,7 @@ bool StandardMaterial3D::_set(const StringName &p_name, const Variant &p_value) idx++; } - print_line("remapped parameter not found: " + String(p_name)); + WARN_PRINT("Godot 3.x SpatialMaterial remapped parameter not found: " + String(p_name)); return true; } diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 51b4e1fbd8..bd63d17424 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -994,9 +994,9 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { } //clear unused flags - print_line("format pre: " + itos(old_format)); + print_verbose("Mesh format pre-conversion: " + itos(old_format)); - print_line("format post: " + itos(new_format)); + print_verbose("Mesh format post-conversion: " + itos(new_format)); ERR_FAIL_COND_V(!d.has("aabb"), false); AABB aabb = d["aabb"]; @@ -1104,7 +1104,7 @@ Array ArrayMesh::_get_surfaces() const { data["material"] = surfaces[i].material; } - if (surfaces[i].name != String()) { + if (!surfaces[i].name.is_empty()) { data["name"] = surfaces[i].name; } diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index c39f59d535..e6b499d4f1 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -417,7 +417,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map // save the child instantiated scenes that are chosen as editable, so they can be restored // upon load back - if (p_node != p_owner && p_node->get_scene_file_path() != String() && p_owner->is_editable_instance(p_node)) { + if (p_node != p_owner && !p_node->get_scene_file_path().is_empty() && p_owner->is_editable_instance(p_node)) { editable_instances.push_back(p_owner->get_path_to(p_node)); // Node is the root of an editable instance. is_editable_instance = true; @@ -451,7 +451,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map bool instantiated_by_owner = false; Vector<SceneState::PackState> states_stack = PropertyUtils::get_node_states_stack(p_node, p_owner, &instantiated_by_owner); - if (p_node->get_scene_file_path() != String() && p_node->get_owner() == p_owner && instantiated_by_owner) { + if (!p_node->get_scene_file_path().is_empty() && p_node->get_owner() == p_owner && instantiated_by_owner) { if (p_node->get_scene_instance_load_placeholder()) { //it's a placeholder, use the placeholder path nd.instance = _vm_get_variant(p_node->get_scene_file_path(), variant_map); @@ -656,7 +656,7 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName ERR_CONTINUE(!common_parent); - if (common_parent != p_owner && common_parent->get_scene_file_path() == String()) { + if (common_parent != p_owner && common_parent->get_scene_file_path().is_empty()) { common_parent = common_parent->get_owner(); } @@ -716,7 +716,7 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName nl = nullptr; } else { - if (nl->get_scene_file_path() != String()) { + if (!nl->get_scene_file_path().is_empty()) { //is an instance Ref<SceneState> state = nl->get_scene_instance_state(); if (state.is_valid()) { diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp index e77f5a0be7..90ef78ccd9 100644 --- a/scene/resources/particles_material.cpp +++ b/scene/resources/particles_material.cpp @@ -85,6 +85,7 @@ void ParticlesMaterial::init_shaders() { shader_names->color = "color_value"; shader_names->color_ramp = "color_ramp"; + shader_names->color_initial_ramp = "color_initial_ramp"; shader_names->emission_sphere_radius = "emission_sphere_radius"; shader_names->emission_box_extents = "emission_box_extents"; @@ -232,6 +233,10 @@ void ParticlesMaterial::_update_shader() { code += "uniform sampler2D color_ramp;\n"; } + if (color_initial_ramp.is_valid()) { + code += "uniform sampler2D color_initial_ramp;\n"; + } + if (tex_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) { code += "uniform sampler2D linear_velocity_texture;\n"; } @@ -311,6 +316,9 @@ void ParticlesMaterial::_update_shader() { code += " float scale_rand = rand_from_seed(alt_seed);\n"; code += " float hue_rot_rand = rand_from_seed(alt_seed);\n"; code += " float anim_offset_rand = rand_from_seed(alt_seed);\n"; + if (color_initial_ramp.is_valid()) { + code += " float color_initial_rand = rand_from_seed(alt_seed);\n"; + } code += " float pi = 3.14159;\n"; code += " float degree_to_rad = pi / 180.0;\n"; code += "\n"; @@ -462,6 +470,10 @@ void ParticlesMaterial::_update_shader() { code += " float scale_rand = rand_from_seed(alt_seed);\n"; code += " float hue_rot_rand = rand_from_seed(alt_seed);\n"; code += " float anim_offset_rand = rand_from_seed(alt_seed);\n"; + if (color_initial_ramp.is_valid()) { + code += " float color_initial_rand = rand_from_seed(alt_seed);\n"; + } + code += " float pi = 3.14159;\n"; code += " float degree_to_rad = pi / 180.0;\n"; code += "\n"; @@ -584,7 +596,7 @@ void ParticlesMaterial::_update_shader() { code += " float base_angle = (tex_angle) * mix(initial_angle_min, initial_angle_max, rand_from_seed(alt_seed));\n"; code += " base_angle += CUSTOM.y * LIFETIME * (tex_angular_velocity) * mix(angular_velocity_min,angular_velocity_max, rand_from_seed(alt_seed));\n"; code += " CUSTOM.x = base_angle * degree_to_rad;\n"; // angle - code += " CUSTOM.z = (tex_anim_offset) * mix(anim_offset_min, anim_offset_max, rand_from_seed(alt_seed)) + CUSTOM.y * tex_anim_speed * mix(anim_speed_min, anim_speed_max, rand_from_seed(alt_seed));\n"; // angle + code += " CUSTOM.z = (tex_anim_offset) * mix(anim_offset_min, anim_offset_max, rand_from_seed(alt_seed)) + tv * tex_anim_speed * mix(anim_speed_min, anim_speed_max, rand_from_seed(alt_seed));\n"; // angle // apply color // apply hue rotation @@ -620,6 +632,12 @@ void ParticlesMaterial::_update_shader() { } else { code += " COLOR = hue_rot_mat * color_value;\n"; } + + if (color_initial_ramp.is_valid()) { + code += " vec4 start_color = textureLod(color_initial_ramp, vec2(color_initial_rand, 0.0), 0.0);\n"; + code += " COLOR *= start_color;\n"; + } + if (emission_color_texture.is_valid() && (emission_shape == EMISSION_SHAPE_POINTS || emission_shape == EMISSION_SHAPE_DIRECTED_POINTS)) { code += " COLOR *= texelFetch(emission_texture_color, emission_tex_ofs, 0);\n"; } @@ -988,6 +1006,18 @@ Ref<Texture2D> ParticlesMaterial::get_color_ramp() const { return color_ramp; } +void ParticlesMaterial::set_color_initial_ramp(const Ref<Texture2D> &p_texture) { + color_initial_ramp = p_texture; + RID tex_rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); + RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->color_initial_ramp, tex_rid); + _queue_shader_change(); + notify_property_list_changed(); +} + +Ref<Texture2D> ParticlesMaterial::get_color_initial_ramp() const { + return color_initial_ramp; +} + void ParticlesMaterial::set_particle_flag(ParticleFlags p_particle_flag, bool p_enable) { ERR_FAIL_INDEX(p_particle_flag, PARTICLE_FLAG_MAX); particle_flags[p_particle_flag] = p_enable; @@ -1282,6 +1312,9 @@ void ParticlesMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_color_ramp", "ramp"), &ParticlesMaterial::set_color_ramp); ClassDB::bind_method(D_METHOD("get_color_ramp"), &ParticlesMaterial::get_color_ramp); + ClassDB::bind_method(D_METHOD("set_color_initial_ramp", "ramp"), &ParticlesMaterial::set_color_initial_ramp); + ClassDB::bind_method(D_METHOD("get_color_initial_ramp"), &ParticlesMaterial::get_color_initial_ramp); + ClassDB::bind_method(D_METHOD("set_particle_flag", "particle_flag", "enable"), &ParticlesMaterial::set_particle_flag); ClassDB::bind_method(D_METHOD("get_particle_flag", "particle_flag"), &ParticlesMaterial::get_particle_flag); @@ -1414,6 +1447,7 @@ void ParticlesMaterial::_bind_methods() { ADD_GROUP("Color", ""); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "color_ramp", PROPERTY_HINT_RESOURCE_TYPE, "GradientTexture1D"), "set_color_ramp", "get_color_ramp"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "color_initial_ramp", PROPERTY_HINT_RESOURCE_TYPE, "GradientTexture1D"), "set_color_initial_ramp", "get_color_initial_ramp"); ADD_GROUP("Hue Variation", "hue_"); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "hue_variation_min", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_param_min", "get_param_min", PARAM_HUE_VARIATION); diff --git a/scene/resources/particles_material.h b/scene/resources/particles_material.h index 36bc456978..9c0bbe3b5d 100644 --- a/scene/resources/particles_material.h +++ b/scene/resources/particles_material.h @@ -194,6 +194,7 @@ private: StringName color; StringName color_ramp; + StringName color_initial_ramp; StringName emission_sphere_radius; StringName emission_box_extents; @@ -237,6 +238,7 @@ private: Ref<Texture2D> tex_parameters[PARAM_MAX]; Color color; Ref<Texture2D> color_ramp; + Ref<Texture2D> color_initial_ramp; bool particle_flags[PARTICLE_FLAG_MAX]; @@ -299,6 +301,9 @@ public: void set_color_ramp(const Ref<Texture2D> &p_texture); Ref<Texture2D> get_color_ramp() const; + void set_color_initial_ramp(const Ref<Texture2D> &p_texture); + Ref<Texture2D> get_color_initial_ramp() const; + void set_particle_flag(ParticleFlags p_particle_flag, bool p_enable); bool get_particle_flag(ParticleFlags p_particle_flag) const; diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp index cead42b4e2..0e354ebff4 100644 --- a/scene/resources/resource_format_text.cpp +++ b/scene/resources/resource_format_text.cpp @@ -274,12 +274,12 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars } } - if (assign != String()) { + if (!assign.is_empty()) { int nameidx = packed_scene->get_state()->add_name(assign); int valueidx = packed_scene->get_state()->add_value(value); packed_scene->get_state()->add_node_property(node_id, nameidx, valueidx); //it's assignment - } else if (next_tag.name != String()) { + } else if (!next_tag.name.is_empty()) { break; } } @@ -575,12 +575,12 @@ Error ResourceLoaderText::load() { return error; } - if (assign != String()) { + if (!assign.is_empty()) { if (do_assign) { res->set(assign, value); } //it's assignment - } else if (next_tag.name != String()) { + } else if (!next_tag.name.is_empty()) { error = OK; break; } else { @@ -659,10 +659,10 @@ Error ResourceLoaderText::load() { return error; } - if (assign != String()) { + if (!assign.is_empty()) { resource->set(assign, value); //it's assignment - } else if (next_tag.name != String()) { + } else if (!next_tag.name.is_empty()) { error = ERR_FILE_CORRUPT; error_text = "Extra tag found when parsing main resource file"; _printerr(); @@ -1166,13 +1166,13 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path) return error; } - if (assign != String()) { + if (!assign.is_empty()) { Map<StringName, int> empty_string_map; //unused bs_save_unicode_string(wf2, assign, true); ResourceFormatSaverBinaryInstance::write_variant(wf2, value, dummy_read.resource_index_map, dummy_read.external_resources, empty_string_map); prop_count++; - } else if (next_tag.name != String()) { + } else if (!next_tag.name.is_empty()) { error = OK; break; } else { @@ -1350,7 +1350,7 @@ RES ResourceFormatLoaderText::load(const String &p_path, const String &p_origina ERR_FAIL_COND_V_MSG(err != OK, RES(), "Cannot open file '" + p_path + "'."); ResourceLoaderText loader; - String path = p_original_path != "" ? p_original_path : p_path; + String path = !p_original_path.is_empty() ? p_original_path : p_path; loader.cache_mode = p_cache_mode; loader.use_sub_threads = p_use_sub_threads; loader.local_path = ProjectSettings::get_singleton()->localize_path(path); @@ -1369,7 +1369,7 @@ RES ResourceFormatLoaderText::load(const String &p_path, const String &p_origina } void ResourceFormatLoaderText::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const { - if (p_type == "") { + if (p_type.is_empty()) { get_recognized_extensions(p_extensions); return; } @@ -1655,7 +1655,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r Set<String> cached_ids_found; for (KeyValue<RES, String> &E : external_resources) { String cached_id = E.key->get_id_for_path(local_path); - if (cached_id == "" || cached_ids_found.has(cached_id)) { + if (cached_id.is_empty() || cached_ids_found.has(cached_id)) { int sep_pos = E.value.find("_"); if (sep_pos != -1) { E.value = E.value.substr(0, sep_pos + 1); // Keep the order found, for improved thread loading performance. @@ -1729,7 +1729,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) { RES res = E->get(); if (E->next() && res->is_built_in()) { - if (res->get_scene_unique_id() != "") { + if (!res->get_scene_unique_id().is_empty()) { if (used_unique_ids.has(res->get_scene_unique_id())) { res->set_scene_unique_id(""); // Repeated. } else { @@ -1752,7 +1752,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r f->store_line("[resource]"); } else { String line = "[sub_resource "; - if (res->get_scene_unique_id() == "") { + if (res->get_scene_unique_id().is_empty()) { String new_id; while (true) { new_id = res->get_class() + "_" + Resource::generate_scene_unique_id(); @@ -1866,7 +1866,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r f->store_string(header); - if (instance_placeholder != String()) { + if (!instance_placeholder.is_empty()) { String vars; f->store_string(" instance_placeholder="); VariantWriter::write_to_string(instance_placeholder, vars, _write_resources, this); diff --git a/scene/resources/syntax_highlighter.cpp b/scene/resources/syntax_highlighter.cpp index cfb5ac2ca6..800752d597 100644 --- a/scene/resources/syntax_highlighter.cpp +++ b/scene/resources/syntax_highlighter.cpp @@ -493,7 +493,7 @@ void CodeHighlighter::add_color_region(const String &p_start_key, const String & color_region.color = p_color; color_region.start_key = p_start_key; color_region.end_key = p_end_key; - color_region.line_only = p_line_only || p_end_key == ""; + color_region.line_only = p_line_only || p_end_key.is_empty(); color_regions.insert(at, color_region); clear_highlighting_cache(); } @@ -529,7 +529,7 @@ void CodeHighlighter::set_color_regions(const Dictionary &p_color_regions) { String start_key = key.get_slice(" ", 0); String end_key = key.get_slice_count(" ") > 1 ? key.get_slice(" ", 1) : String(); - add_color_region(start_key, end_key, p_color_regions[key], end_key == ""); + add_color_region(start_key, end_key, p_color_regions[key], end_key.is_empty()); } clear_highlighting_cache(); } diff --git a/scene/resources/text_file.cpp b/scene/resources/text_file.cpp index 33bb0a83e9..1dc46711f8 100644 --- a/scene/resources/text_file.cpp +++ b/scene/resources/text_file.cpp @@ -33,7 +33,7 @@ #include "core/io/file_access.h" bool TextFile::has_text() const { - return text != ""; + return !text.is_empty(); } String TextFile::get_text() const { diff --git a/scene/resources/text_line.cpp b/scene/resources/text_line.cpp index 0094518967..cfd7e1d876 100644 --- a/scene/resources/text_line.cpp +++ b/scene/resources/text_line.cpp @@ -56,18 +56,18 @@ void TextLine::_bind_methods() { ClassDB::bind_method(D_METHOD("set_bidi_override", "override"), &TextLine::set_bidi_override); ClassDB::bind_method(D_METHOD("add_string", "text", "fonts", "size", "opentype_features", "language"), &TextLine::add_string, DEFVAL(Dictionary()), DEFVAL("")); - ClassDB::bind_method(D_METHOD("add_object", "key", "size", "inline_align", "length"), &TextLine::add_object, DEFVAL(INLINE_ALIGN_CENTER), DEFVAL(1)); - ClassDB::bind_method(D_METHOD("resize_object", "key", "size", "inline_align"), &TextLine::resize_object, DEFVAL(INLINE_ALIGN_CENTER)); + ClassDB::bind_method(D_METHOD("add_object", "key", "size", "inline_align", "length"), &TextLine::add_object, DEFVAL(INLINE_ALIGNMENT_CENTER), DEFVAL(1)); + ClassDB::bind_method(D_METHOD("resize_object", "key", "size", "inline_align"), &TextLine::resize_object, DEFVAL(INLINE_ALIGNMENT_CENTER)); ClassDB::bind_method(D_METHOD("set_width", "width"), &TextLine::set_width); ClassDB::bind_method(D_METHOD("get_width"), &TextLine::get_width); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "width"), "set_width", "get_width"); - ClassDB::bind_method(D_METHOD("set_align", "align"), &TextLine::set_align); - ClassDB::bind_method(D_METHOD("get_align"), &TextLine::get_align); + ClassDB::bind_method(D_METHOD("set_horizontal_alignment", "alignment"), &TextLine::set_horizontal_alignment); + ClassDB::bind_method(D_METHOD("get_horizontal_alignment"), &TextLine::get_horizontal_alignment); - ADD_PROPERTY(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), "set_align", "get_align"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "alignment", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), "set_horizontal_alignment", "get_horizontal_alignment"); ClassDB::bind_method(D_METHOD("tab_align", "tab_stops"), &TextLine::tab_align); @@ -135,14 +135,14 @@ void TextLine::_shape() { break; } - if (align == HALIGN_FILL) { + if (alignment == HORIZONTAL_ALIGNMENT_FILL) { TS->shaped_text_fit_to_width(rid, width, flags); overrun_flags |= TextServer::OVERRUN_JUSTIFICATION_AWARE; TS->shaped_text_overrun_trim_to_width(rid, width, overrun_flags); } else { TS->shaped_text_overrun_trim_to_width(rid, width, overrun_flags); } - } else if (align == HALIGN_FILL) { + } else if (alignment == HORIZONTAL_ALIGNMENT_FILL) { TS->shaped_text_fit_to_width(rid, width, flags); } dirty = false; @@ -209,13 +209,13 @@ bool TextLine::add_string(const String &p_text, const Ref<Font> &p_fonts, int p_ return res; } -bool TextLine::add_object(Variant p_key, const Size2 &p_size, InlineAlign p_inline_align, int p_length) { +bool TextLine::add_object(Variant p_key, const Size2 &p_size, InlineAlignment p_inline_align, int p_length) { bool res = TS->shaped_text_add_object(rid, p_key, p_size, p_inline_align, p_length); dirty = true; return res; } -bool TextLine::resize_object(Variant p_key, const Size2 &p_size, InlineAlign p_inline_align) { +bool TextLine::resize_object(Variant p_key, const Size2 &p_size, InlineAlignment p_inline_align) { const_cast<TextLine *>(this)->_shape(); return TS->shaped_text_resize_object(rid, p_key, p_size, p_inline_align); } @@ -228,19 +228,19 @@ Rect2 TextLine::get_object_rect(Variant p_key) const { return TS->shaped_text_get_object_rect(rid, p_key); } -void TextLine::set_align(HAlign p_align) { - if (align != p_align) { - if (align == HALIGN_FILL || p_align == HALIGN_FILL) { - align = p_align; +void TextLine::set_horizontal_alignment(HorizontalAlignment p_alignment) { + if (alignment != p_alignment) { + if (alignment == HORIZONTAL_ALIGNMENT_FILL || p_alignment == HORIZONTAL_ALIGNMENT_FILL) { + alignment = p_alignment; dirty = true; } else { - align = p_align; + alignment = p_alignment; } } } -HAlign TextLine::get_align() const { - return align; +HorizontalAlignment TextLine::get_horizontal_alignment() const { + return alignment; } void TextLine::tab_align(const Vector<float> &p_tab_stops) { @@ -272,7 +272,7 @@ TextLine::OverrunBehavior TextLine::get_text_overrun_behavior() const { void TextLine::set_width(float p_width) { width = p_width; - if (align == HALIGN_FILL || overrun_behavior != OVERRUN_NO_TRIMMING) { + if (alignment == HORIZONTAL_ALIGNMENT_FILL || overrun_behavior != OVERRUN_NO_TRIMMING) { dirty = true; } } @@ -322,18 +322,18 @@ void TextLine::draw(RID p_canvas, const Vector2 &p_pos, const Color &p_color) co float length = TS->shaped_text_get_width(rid); if (width > 0) { - switch (align) { - case HALIGN_FILL: - case HALIGN_LEFT: + switch (alignment) { + case HORIZONTAL_ALIGNMENT_FILL: + case HORIZONTAL_ALIGNMENT_LEFT: break; - case HALIGN_CENTER: { + case HORIZONTAL_ALIGNMENT_CENTER: { if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) { ofs.x += Math::floor((width - length) / 2.0); } else { ofs.y += Math::floor((width - length) / 2.0); } } break; - case HALIGN_RIGHT: { + case HORIZONTAL_ALIGNMENT_RIGHT: { if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) { ofs.x += width - length; } else { @@ -361,18 +361,18 @@ void TextLine::draw_outline(RID p_canvas, const Vector2 &p_pos, int p_outline_si float length = TS->shaped_text_get_width(rid); if (width > 0) { - switch (align) { - case HALIGN_FILL: - case HALIGN_LEFT: + switch (alignment) { + case HORIZONTAL_ALIGNMENT_FILL: + case HORIZONTAL_ALIGNMENT_LEFT: break; - case HALIGN_CENTER: { + case HORIZONTAL_ALIGNMENT_CENTER: { if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) { ofs.x += Math::floor((width - length) / 2.0); } else { ofs.y += Math::floor((width - length) / 2.0); } } break; - case HALIGN_RIGHT: { + case HORIZONTAL_ALIGNMENT_RIGHT: { if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) { ofs.x += width - length; } else { diff --git a/scene/resources/text_line.h b/scene/resources/text_line.h index 43739f27ec..bab17a3024 100644 --- a/scene/resources/text_line.h +++ b/scene/resources/text_line.h @@ -57,7 +57,7 @@ private: float width = -1.0; uint16_t flags = TextServer::JUSTIFICATION_WORD_BOUND | TextServer::JUSTIFICATION_KASHIDA; - HAlign align = HALIGN_LEFT; + HorizontalAlignment alignment = HORIZONTAL_ALIGNMENT_LEFT; OverrunBehavior overrun_behavior = OVERRUN_TRIM_ELLIPSIS; Vector<float> tab_stops; @@ -87,11 +87,11 @@ public: bool get_preserve_control() const; bool add_string(const String &p_text, const Ref<Font> &p_fonts, int p_size, const Dictionary &p_opentype_features = Dictionary(), const String &p_language = ""); - bool add_object(Variant p_key, const Size2 &p_size, InlineAlign p_inline_align = INLINE_ALIGN_CENTER, int p_length = 1); - bool resize_object(Variant p_key, const Size2 &p_size, InlineAlign p_inline_align = INLINE_ALIGN_CENTER); + bool add_object(Variant p_key, const Size2 &p_size, InlineAlignment p_inline_align = INLINE_ALIGNMENT_CENTER, int p_length = 1); + bool resize_object(Variant p_key, const Size2 &p_size, InlineAlignment p_inline_align = INLINE_ALIGNMENT_CENTER); - void set_align(HAlign p_align); - HAlign get_align() const; + void set_horizontal_alignment(HorizontalAlignment p_alignment); + HorizontalAlignment get_horizontal_alignment() const; void tab_align(const Vector<float> &p_tab_stops); diff --git a/scene/resources/text_paragraph.cpp b/scene/resources/text_paragraph.cpp index 1b7fc64267..130b83ea99 100644 --- a/scene/resources/text_paragraph.cpp +++ b/scene/resources/text_paragraph.cpp @@ -64,13 +64,13 @@ void TextParagraph::_bind_methods() { ClassDB::bind_method(D_METHOD("clear_dropcap"), &TextParagraph::clear_dropcap); ClassDB::bind_method(D_METHOD("add_string", "text", "fonts", "size", "opentype_features", "language"), &TextParagraph::add_string, DEFVAL(Dictionary()), DEFVAL("")); - ClassDB::bind_method(D_METHOD("add_object", "key", "size", "inline_align", "length"), &TextParagraph::add_object, DEFVAL(INLINE_ALIGN_CENTER), DEFVAL(1)); - ClassDB::bind_method(D_METHOD("resize_object", "key", "size", "inline_align"), &TextParagraph::resize_object, DEFVAL(INLINE_ALIGN_CENTER)); + ClassDB::bind_method(D_METHOD("add_object", "key", "size", "inline_align", "length"), &TextParagraph::add_object, DEFVAL(INLINE_ALIGNMENT_CENTER), DEFVAL(1)); + ClassDB::bind_method(D_METHOD("resize_object", "key", "size", "inline_align"), &TextParagraph::resize_object, DEFVAL(INLINE_ALIGNMENT_CENTER)); - ClassDB::bind_method(D_METHOD("set_align", "align"), &TextParagraph::set_align); - ClassDB::bind_method(D_METHOD("get_align"), &TextParagraph::get_align); + ClassDB::bind_method(D_METHOD("set_alignment", "alignment"), &TextParagraph::set_alignment); + ClassDB::bind_method(D_METHOD("get_alignment"), &TextParagraph::get_alignment); - ADD_PROPERTY(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), "set_align", "get_align"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "alignment", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), "set_alignment", "get_alignment"); ClassDB::bind_method(D_METHOD("tab_align", "tab_stops"), &TextParagraph::tab_align); @@ -223,7 +223,7 @@ void TextParagraph::_shape_lines() { if (lines_hidden) { overrun_flags |= TextServer::OVERRUN_ENFORCE_ELLIPSIS; } - if (align == HALIGN_FILL) { + if (alignment == HORIZONTAL_ALIGNMENT_FILL) { for (int i = 0; i < lines_rid.size(); i++) { if (i < visible_lines - 1 || lines_rid.size() == 1) { TS->shaped_text_fit_to_width(lines_rid[i], width, flags); @@ -239,7 +239,7 @@ void TextParagraph::_shape_lines() { } else { // Autowrap disabled. for (int i = 0; i < lines_rid.size(); i++) { - if (align == HALIGN_FILL) { + if (alignment == HORIZONTAL_ALIGNMENT_FILL) { TS->shaped_text_fit_to_width(lines_rid[i], width, flags); overrun_flags |= TextServer::OVERRUN_JUSTIFICATION_AWARE; TS->shaped_text_overrun_trim_to_width(lines_rid[i], width, overrun_flags); @@ -366,31 +366,31 @@ void TextParagraph::set_bidi_override(const Array &p_override) { lines_dirty = true; } -bool TextParagraph::add_object(Variant p_key, const Size2 &p_size, InlineAlign p_inline_align, int p_length) { +bool TextParagraph::add_object(Variant p_key, const Size2 &p_size, InlineAlignment p_inline_align, int p_length) { bool res = TS->shaped_text_add_object(rid, p_key, p_size, p_inline_align, p_length); lines_dirty = true; return res; } -bool TextParagraph::resize_object(Variant p_key, const Size2 &p_size, InlineAlign p_inline_align) { +bool TextParagraph::resize_object(Variant p_key, const Size2 &p_size, InlineAlignment p_inline_align) { bool res = TS->shaped_text_resize_object(rid, p_key, p_size, p_inline_align); lines_dirty = true; return res; } -void TextParagraph::set_align(HAlign p_align) { - if (align != p_align) { - if (align == HALIGN_FILL || p_align == HALIGN_FILL) { - align = p_align; +void TextParagraph::set_alignment(HorizontalAlignment p_alignment) { + if (alignment != p_alignment) { + if (alignment == HORIZONTAL_ALIGNMENT_FILL || p_alignment == HORIZONTAL_ALIGNMENT_FILL) { + alignment = p_alignment; lines_dirty = true; } else { - align = p_align; + alignment = p_alignment; } } } -HAlign TextParagraph::get_align() const { - return align; +HorizontalAlignment TextParagraph::get_alignment() const { + return alignment; } void TextParagraph::tab_align(const Vector<float> &p_tab_stops) { @@ -596,8 +596,8 @@ void TextParagraph::draw(RID p_canvas, const Vector2 &p_pos, const Color &p_colo } float line_width = TS->shaped_text_get_width(lines_rid[i]); if (width > 0) { - switch (align) { - case HALIGN_FILL: + switch (alignment) { + case HORIZONTAL_ALIGNMENT_FILL: if (TS->shaped_text_get_direction(lines_rid[i]) == TextServer::DIRECTION_RTL) { if (TS->shaped_text_get_orientation(lines_rid[i]) == TextServer::ORIENTATION_HORIZONTAL) { ofs.x += l_width - line_width; @@ -606,16 +606,16 @@ void TextParagraph::draw(RID p_canvas, const Vector2 &p_pos, const Color &p_colo } } break; - case HALIGN_LEFT: + case HORIZONTAL_ALIGNMENT_LEFT: break; - case HALIGN_CENTER: { + case HORIZONTAL_ALIGNMENT_CENTER: { if (TS->shaped_text_get_orientation(lines_rid[i]) == TextServer::ORIENTATION_HORIZONTAL) { ofs.x += Math::floor((l_width - line_width) / 2.0); } else { ofs.y += Math::floor((l_width - line_width) / 2.0); } } break; - case HALIGN_RIGHT: { + case HORIZONTAL_ALIGNMENT_RIGHT: { if (TS->shaped_text_get_orientation(lines_rid[i]) == TextServer::ORIENTATION_HORIZONTAL) { ofs.x += l_width - line_width; } else { @@ -688,8 +688,8 @@ void TextParagraph::draw_outline(RID p_canvas, const Vector2 &p_pos, int p_outli } float length = TS->shaped_text_get_width(lines_rid[i]); if (width > 0) { - switch (align) { - case HALIGN_FILL: + switch (alignment) { + case HORIZONTAL_ALIGNMENT_FILL: if (TS->shaped_text_get_direction(lines_rid[i]) == TextServer::DIRECTION_RTL) { if (TS->shaped_text_get_orientation(lines_rid[i]) == TextServer::ORIENTATION_HORIZONTAL) { ofs.x += l_width - length; @@ -698,16 +698,16 @@ void TextParagraph::draw_outline(RID p_canvas, const Vector2 &p_pos, int p_outli } } break; - case HALIGN_LEFT: + case HORIZONTAL_ALIGNMENT_LEFT: break; - case HALIGN_CENTER: { + case HORIZONTAL_ALIGNMENT_CENTER: { if (TS->shaped_text_get_orientation(lines_rid[i]) == TextServer::ORIENTATION_HORIZONTAL) { ofs.x += Math::floor((l_width - length) / 2.0); } else { ofs.y += Math::floor((l_width - length) / 2.0); } } break; - case HALIGN_RIGHT: { + case HORIZONTAL_ALIGNMENT_RIGHT: { if (TS->shaped_text_get_orientation(lines_rid[i]) == TextServer::ORIENTATION_HORIZONTAL) { ofs.x += l_width - length; } else { diff --git a/scene/resources/text_paragraph.h b/scene/resources/text_paragraph.h index 4c4af43d14..1faa3f3a7b 100644 --- a/scene/resources/text_paragraph.h +++ b/scene/resources/text_paragraph.h @@ -66,7 +66,7 @@ private: uint16_t flags = TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND | TextServer::JUSTIFICATION_WORD_BOUND | TextServer::JUSTIFICATION_KASHIDA; OverrunBehavior overrun_behavior = OVERRUN_NO_TRIMMING; - HAlign align = HALIGN_LEFT; + HorizontalAlignment alignment = HORIZONTAL_ALIGNMENT_LEFT; Vector<float> tab_stops; @@ -103,11 +103,11 @@ public: void clear_dropcap(); bool add_string(const String &p_text, const Ref<Font> &p_fonts, int p_size, const Dictionary &p_opentype_features = Dictionary(), const String &p_language = ""); - bool add_object(Variant p_key, const Size2 &p_size, InlineAlign p_inline_align = INLINE_ALIGN_CENTER, int p_length = 1); - bool resize_object(Variant p_key, const Size2 &p_size, InlineAlign p_inline_align = INLINE_ALIGN_CENTER); + bool add_object(Variant p_key, const Size2 &p_size, InlineAlignment p_inline_align = INLINE_ALIGNMENT_CENTER, int p_length = 1); + bool resize_object(Variant p_key, const Size2 &p_size, InlineAlignment p_inline_align = INLINE_ALIGNMENT_CENTER); - void set_align(HAlign p_align); - HAlign get_align() const; + void set_alignment(HorizontalAlignment p_alignment); + HorizontalAlignment get_alignment() const; void tab_align(const Vector<float> &p_tab_stops); diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 311bd9524b..13c3f6ea1d 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -553,7 +553,7 @@ Error StreamTexture2D::load(const String &p_path) { path_to_file = p_path; format = image->get_format(); - if (get_path() == String()) { + if (get_path().is_empty()) { //temporarily set path if no path set for resource, helps find errors RenderingServer::get_singleton()->texture_set_path(texture, p_path); } @@ -927,7 +927,7 @@ Error StreamTexture3D::load(const String &p_path) { path_to_file = p_path; - if (get_path() == String()) { + if (get_path().is_empty()) { //temporarily set path if no path set for resource, helps find errors RenderingServer::get_singleton()->texture_set_path(texture, p_path); } @@ -2680,7 +2680,7 @@ Error StreamTextureLayered::load(const String &p_path) { path_to_file = p_path; - if (get_path() == String()) { + if (get_path().is_empty()) { //temporarily set path if no path set for resource, helps find errors RenderingServer::get_singleton()->texture_set_path(texture, p_path); } diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index 41e78e0bc8..10e75fb023 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -979,7 +979,7 @@ String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port String VisualShader::validate_port_name(const String &p_port_name, VisualShaderNode *p_node, int p_port_id, bool p_output) const { String name = p_port_name; - if (name == String()) { + if (name.is_empty()) { return String(); } @@ -987,7 +987,7 @@ String VisualShader::validate_port_name(const String &p_port_name, VisualShaderN name = name.substr(1, name.length() - 1); } - if (name != String()) { + if (!name.is_empty()) { String valid_name; for (int i = 0; i < name.length(); i++) { @@ -1031,7 +1031,7 @@ String VisualShader::validate_uniform_name(const String &p_name, const Ref<Visua while (name.length() && !IS_INITIAL_CHAR(name[0])) { name = name.substr(1, name.length() - 1); } - if (name != String()) { + if (!name.is_empty()) { String valid_name; for (int i = 0; i < name.length(); i++) { @@ -1045,7 +1045,7 @@ String VisualShader::validate_uniform_name(const String &p_name, const Ref<Visua name = valid_name; } - if (name == String()) { + if (name.is_empty()) { name = p_uniform->get_caption(); } @@ -1075,7 +1075,7 @@ String VisualShader::validate_uniform_name(const String &p_name, const Ref<Visua while (name.length() && name[name.length() - 1] >= '0' && name[name.length() - 1] <= '9') { name = name.substr(0, name.length() - 1); } - ERR_FAIL_COND_V(name == String(), String()); + ERR_FAIL_COND_V(name.is_empty(), String()); name += itos(attempt); } else { break; @@ -1568,7 +1568,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui } node_code += vsnode->generate_code(get_mode(), type, node, inputs, outputs, for_preview); - if (node_code != String()) { + if (!node_code.is_empty()) { code += node_name; code += node_code; code += "\n"; @@ -1664,7 +1664,7 @@ void VisualShader::_update_shader() const { String mode = ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader_mode))[i]; if (mode.begins_with(render_mode_enums[idx].string)) { if (count == which) { - if (render_mode != String()) { + if (!render_mode.is_empty()) { render_mode += ", "; } render_mode += mode; @@ -1682,7 +1682,7 @@ void VisualShader::_update_shader() const { for (int i = 0; i < ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader_mode)).size(); i++) { String mode = ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader_mode))[i]; if (flags.has(mode)) { - if (render_mode != String()) { + if (!render_mode.is_empty()) { render_mode += ", "; } render_mode += mode; @@ -1690,7 +1690,7 @@ void VisualShader::_update_shader() const { } } - if (render_mode != String()) { + if (!render_mode.is_empty()) { global_code += "render_mode " + render_mode + ";\n\n"; } @@ -2468,7 +2468,7 @@ String VisualShaderNodeInput::generate_code(Shader::Mode p_mode, VisualShader::T idx++; } - if (code == String()) { + if (code.is_empty()) { switch (get_output_port_type(0)) { case PORT_TYPE_SCALAR: { code = " " + p_output_vars[0] + " = 0.0;\n"; @@ -2502,7 +2502,7 @@ String VisualShaderNodeInput::generate_code(Shader::Mode p_mode, VisualShader::T idx++; } - if (code == String()) { + if (code.is_empty()) { code = " " + p_output_vars[0] + " = 0.0;\n"; //default (none found) is scalar } @@ -2605,7 +2605,7 @@ void VisualShaderNodeInput::_validate_property(PropertyInfo &property) const { while (ports[idx].mode != Shader::MODE_MAX) { if (ports[idx].mode == shader_mode && ports[idx].shader_type == shader_type) { - if (port_list != String()) { + if (!port_list.is_empty()) { port_list += ","; } port_list += ports[idx].name; @@ -2613,7 +2613,7 @@ void VisualShaderNodeInput::_validate_property(PropertyInfo &property) const { idx++; } - if (port_list == "") { + if (port_list.is_empty()) { port_list = TTR("None"); } property.hint_string = port_list; @@ -3063,7 +3063,7 @@ String VisualShaderNodeOutput::generate_code(Shader::Mode p_mode, VisualShader:: String code; while (ports[idx].mode != Shader::MODE_MAX) { if (ports[idx].mode == shader_mode && ports[idx].shader_type == shader_type) { - if (p_input_vars[count] != String()) { + if (!p_input_vars[count].is_empty()) { String s = ports[idx].string; if (s.find(":") != -1) { code += " " + s.get_slicec(':', 0) + " = " + p_input_vars[count] + "." + s.get_slicec(':', 1) + ";\n"; diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp index 951870fe34..9e60a1243f 100644 --- a/scene/resources/visual_shader_nodes.cpp +++ b/scene/resources/visual_shader_nodes.cpp @@ -535,15 +535,15 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader: if (source == SOURCE_TEXTURE) { String id = make_unique_id(p_type, p_id, "tex"); String code; - if (p_input_vars[0] == String()) { // Use UV by default. + if (p_input_vars[0].is_empty()) { // Use UV by default. - if (p_input_vars[1] == String()) { + if (p_input_vars[1].is_empty()) { code += " vec4 " + id + "_read = texture(" + id + ", " + default_uv + ");\n"; } else { code += " vec4 " + id + "_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n"; } - } else if (p_input_vars[1] == String()) { + } else if (p_input_vars[1].is_empty()) { //no lod code += " vec4 " + id + "_read = texture(" + id + ", " + p_input_vars[0] + ".xy);\n"; } else { @@ -560,18 +560,18 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader: String code; code += " {\n"; - if (id == String()) { + if (id.is_empty()) { code += " vec4 " + id + "_tex_read = vec4(0.0);\n"; } else { - if (p_input_vars[0] == String()) { // Use UV by default. + if (p_input_vars[0].is_empty()) { // Use UV by default. - if (p_input_vars[1] == String()) { + if (p_input_vars[1].is_empty()) { code += " vec4 " + id + "_tex_read = texture(" + id + ", " + default_uv + ");\n"; } else { code += " vec4 " + id + "_tex_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n"; } - } else if (p_input_vars[1] == String()) { + } else if (p_input_vars[1].is_empty()) { //no lod code += " vec4 " + id + "_tex_read = texture(" + id + ", " + p_input_vars[0] + ".xy);\n"; } else { @@ -587,15 +587,15 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader: if (source == SOURCE_SCREEN && (p_mode == Shader::MODE_SPATIAL || p_mode == Shader::MODE_CANVAS_ITEM) && p_type == VisualShader::TYPE_FRAGMENT) { String code = " {\n"; - if (p_input_vars[0] == String() || p_for_preview) { // Use UV by default. + if (p_input_vars[0].is_empty() || p_for_preview) { // Use UV by default. - if (p_input_vars[1] == String()) { + if (p_input_vars[1].is_empty()) { code += " vec4 _tex_read = textureLod(SCREEN_TEXTURE, " + default_uv + ", 0.0 );\n"; } else { code += " vec4 _tex_read = textureLod(SCREEN_TEXTURE, " + default_uv + ", " + p_input_vars[1] + ");\n"; } - } else if (p_input_vars[1] == String()) { + } else if (p_input_vars[1].is_empty()) { //no lod code += " vec4 _tex_read = textureLod(SCREEN_TEXTURE, " + p_input_vars[0] + ".xy, 0.0);\n"; } else { @@ -610,15 +610,15 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader: if (source == SOURCE_2D_TEXTURE && p_mode == Shader::MODE_CANVAS_ITEM && p_type == VisualShader::TYPE_FRAGMENT) { String code = " {\n"; - if (p_input_vars[0] == String()) { // Use UV by default. + if (p_input_vars[0].is_empty()) { // Use UV by default. - if (p_input_vars[1] == String()) { + if (p_input_vars[1].is_empty()) { code += " vec4 _tex_read = texture(TEXTURE, " + default_uv + ");\n"; } else { code += " vec4 _tex_read = textureLod(TEXTURE, " + default_uv + ", " + p_input_vars[1] + ");\n"; } - } else if (p_input_vars[1] == String()) { + } else if (p_input_vars[1].is_empty()) { //no lod code += " vec4 _tex_read = texture(TEXTURE, " + p_input_vars[0] + ".xy);\n"; } else { @@ -633,15 +633,15 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader: if (source == SOURCE_2D_NORMAL && p_mode == Shader::MODE_CANVAS_ITEM && p_type == VisualShader::TYPE_FRAGMENT) { String code = " {\n"; - if (p_input_vars[0] == String()) { // Use UV by default. + if (p_input_vars[0].is_empty()) { // Use UV by default. - if (p_input_vars[1] == String()) { + if (p_input_vars[1].is_empty()) { code += " vec4 _tex_read = texture(NORMAL_TEXTURE, " + default_uv + ");\n"; } else { code += " vec4 _tex_read = textureLod(NORMAL_TEXTURE, " + default_uv + ", " + p_input_vars[1] + ");\n"; } - } else if (p_input_vars[1] == String()) { + } else if (p_input_vars[1].is_empty()) { //no lod code += " vec4 _tex_read = texture(NORMAL_TEXTURE, " + p_input_vars[0] + ".xy);\n"; } else { @@ -666,15 +666,15 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader: if (source == SOURCE_DEPTH && p_mode == Shader::MODE_SPATIAL && p_type == VisualShader::TYPE_FRAGMENT) { String code = " {\n"; - if (p_input_vars[0] == String()) { // Use UV by default. + if (p_input_vars[0].is_empty()) { // Use UV by default. - if (p_input_vars[1] == String()) { + if (p_input_vars[1].is_empty()) { code += " float _depth = texture(DEPTH_TEXTURE, " + default_uv + ").r;\n"; } else { code += " float _depth = textureLod(DEPTH_TEXTURE, " + default_uv + ", " + p_input_vars[1] + ").r;\n"; } - } else if (p_input_vars[1] == String()) { + } else if (p_input_vars[1].is_empty()) { //no lod code += " float _depth = texture(DEPTH_TEXTURE, " + p_input_vars[0] + ".xy).r;\n"; } else { @@ -883,7 +883,7 @@ String VisualShaderNodeCurveTexture::generate_global(Shader::Mode p_mode, Visual } String VisualShaderNodeCurveTexture::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) const { - if (p_input_vars[0] == String()) { + if (p_input_vars[0].is_empty()) { return " " + p_output_vars[0] + " = 0.0;\n"; } String id = make_unique_id(p_type, p_id, "curve"); @@ -968,7 +968,7 @@ String VisualShaderNodeCurveXYZTexture::generate_global(Shader::Mode p_mode, Vis } String VisualShaderNodeCurveXYZTexture::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) const { - if (p_input_vars[0] == String()) { + if (p_input_vars[0].is_empty()) { return " " + p_output_vars[0] + " = vec3(0.0);\n"; } String id = make_unique_id(p_type, p_id, "curve3d"); @@ -1076,14 +1076,14 @@ String VisualShaderNodeSample3D::generate_code(Shader::Mode p_mode, VisualShader } else { id = p_input_vars[2]; } - if (id != String()) { - if (p_input_vars[0] == String()) { // Use UV by default. - if (p_input_vars[1] == String()) { + if (!id.is_empty()) { + if (p_input_vars[0].is_empty()) { // Use UV by default. + if (p_input_vars[1].is_empty()) { code += " vec4 " + id + "_tex_read = texture(" + id + ", " + default_uv + ");\n"; } else { code += " vec4 " + id + "_tex_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n"; } - } else if (p_input_vars[1] == String()) { + } else if (p_input_vars[1].is_empty()) { //no lod code += " vec4 " + id + "_tex_read = texture(" + id + ", " + p_input_vars[0] + ");\n"; } else { @@ -1364,7 +1364,7 @@ String VisualShaderNodeCubemap::generate_code(Shader::Mode p_mode, VisualShader: code += " {\n"; - if (id == String()) { + if (id.is_empty()) { code += " vec4 " + id + "_read = vec4(0.0);\n"; code += " " + p_output_vars[0] + " = " + id + "_read.rgb;\n"; code += " " + p_output_vars[1] + " = " + id + "_read.a;\n"; @@ -1372,15 +1372,15 @@ String VisualShaderNodeCubemap::generate_code(Shader::Mode p_mode, VisualShader: return code; } - if (p_input_vars[0] == String()) { // Use UV by default. + if (p_input_vars[0].is_empty()) { // Use UV by default. - if (p_input_vars[1] == String()) { + if (p_input_vars[1].is_empty()) { code += " vec4 " + id + "_read = texture(" + id + ", " + default_uv + ");\n"; } else { code += " vec4 " + id + "_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + " );\n"; } - } else if (p_input_vars[1] == String()) { + } else if (p_input_vars[1].is_empty()) { //no lod code += " vec4 " + id + "_read = texture(" + id + ", " + p_input_vars[0] + ");\n"; } else { @@ -1647,6 +1647,21 @@ String VisualShaderNodeIntOp::generate_code(Shader::Mode p_mode, VisualShader::T case OP_MIN: code += "min(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; break; + case OP_BITWISE_AND: + code += p_input_vars[0] + " & " + p_input_vars[1] + ";\n"; + break; + case OP_BITWISE_OR: + code += p_input_vars[0] + " | " + p_input_vars[1] + ";\n"; + break; + case OP_BITWISE_XOR: + code += p_input_vars[0] + " ^ " + p_input_vars[1] + ";\n"; + break; + case OP_BITWISE_LEFT_SHIFT: + code += p_input_vars[0] + " << " + p_input_vars[1] + ";\n"; + break; + case OP_BITWISE_RIGHT_SHIFT: + code += p_input_vars[0] + " >> " + p_input_vars[1] + ";\n"; + break; default: break; } @@ -1677,7 +1692,7 @@ void VisualShaderNodeIntOp::_bind_methods() { ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualShaderNodeIntOp::set_operator); ClassDB::bind_method(D_METHOD("get_operator"), &VisualShaderNodeIntOp::get_operator); - ADD_PROPERTY(PropertyInfo(Variant::INT, "operator", PROPERTY_HINT_ENUM, "Add,Subtract,Multiply,Divide,Remainder,Max,Min"), "set_operator", "get_operator"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "operator", PROPERTY_HINT_ENUM, "Add,Subtract,Multiply,Divide,Remainder,Max,Min,Bitwise AND,Bitwise OR,Bitwise XOR,Bitwise Left Shift,Bitwise Right Shift"), "set_operator", "get_operator"); BIND_ENUM_CONSTANT(OP_ADD); BIND_ENUM_CONSTANT(OP_SUB); @@ -1686,6 +1701,11 @@ void VisualShaderNodeIntOp::_bind_methods() { BIND_ENUM_CONSTANT(OP_MOD); BIND_ENUM_CONSTANT(OP_MAX); BIND_ENUM_CONSTANT(OP_MIN); + BIND_ENUM_CONSTANT(OP_BITWISE_AND); + BIND_ENUM_CONSTANT(OP_BITWISE_OR); + BIND_ENUM_CONSTANT(OP_BITWISE_XOR); + BIND_ENUM_CONSTANT(OP_BITWISE_LEFT_SHIFT); + BIND_ENUM_CONSTANT(OP_BITWISE_RIGHT_SHIFT); BIND_ENUM_CONSTANT(OP_ENUM_SIZE); } @@ -2333,7 +2353,8 @@ String VisualShaderNodeIntFunc::generate_code(Shader::Mode p_mode, VisualShader: static const char *functions[FUNC_MAX] = { "abs($)", "-($)", - "sign($)" + "sign($)", + "~($)" }; return " " + p_output_vars[0] + " = " + String(functions[func]).replace("$", p_input_vars[0]) + ";\n"; @@ -2362,11 +2383,12 @@ void VisualShaderNodeIntFunc::_bind_methods() { ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeIntFunc::set_function); ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeIntFunc::get_function); - ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, "Abs,Negate,Sign"), "set_function", "get_function"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, "Abs,Negate,Sign,Bitwise NOT"), "set_function", "get_function"); BIND_ENUM_CONSTANT(FUNC_ABS); BIND_ENUM_CONSTANT(FUNC_NEGATE); BIND_ENUM_CONSTANT(FUNC_SIGN); + BIND_ENUM_CONSTANT(FUNC_BITWISE_NOT); BIND_ENUM_CONSTANT(FUNC_MAX); } @@ -4855,8 +4877,8 @@ String VisualShaderNodeTextureUniform::generate_global(Shader::Mode p_mode, Visu case TYPE_NORMAL_MAP: code += " : hint_normal;\n"; break; - case TYPE_ANISO: - code += " : hint_aniso;\n"; + case TYPE_ANISOTROPY: + code += " : hint_anisotropy;\n"; break; default: code += ";\n"; @@ -4880,13 +4902,13 @@ String VisualShaderNodeTextureUniform::generate_code(Shader::Mode p_mode, Visual String id = get_uniform_name(); String code = " {\n"; - if (p_input_vars[0] == String()) { // Use UV by default. - if (p_input_vars[1] == String()) { + if (p_input_vars[0].is_empty()) { // Use UV by default. + if (p_input_vars[1].is_empty()) { code += " vec4 n_tex_read = texture(" + id + ", " + default_uv + ");\n"; } else { code += " vec4 n_tex_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n"; } - } else if (p_input_vars[1] == String()) { + } else if (p_input_vars[1].is_empty()) { //no lod code += " vec4 n_tex_read = texture(" + id + ", " + p_input_vars[0] + ".xy);\n"; } else { @@ -4945,7 +4967,7 @@ void VisualShaderNodeTextureUniform::_bind_methods() { BIND_ENUM_CONSTANT(TYPE_DATA); BIND_ENUM_CONSTANT(TYPE_COLOR); BIND_ENUM_CONSTANT(TYPE_NORMAL_MAP); - BIND_ENUM_CONSTANT(TYPE_ANISO); + BIND_ENUM_CONSTANT(TYPE_ANISOTROPY); BIND_ENUM_CONSTANT(TYPE_MAX); BIND_ENUM_CONSTANT(COLOR_DEFAULT_WHITE); @@ -5048,11 +5070,11 @@ String VisualShaderNodeTextureUniformTriplanar::generate_code(Shader::Mode p_mod String id = get_uniform_name(); String code = " {\n"; - if (p_input_vars[0] == String() && p_input_vars[1] == String()) { + if (p_input_vars[0].is_empty() && p_input_vars[1].is_empty()) { code += " vec4 n_tex_read = triplanar_texture(" + id + ", triplanar_power_normal, triplanar_pos);\n"; - } else if (p_input_vars[0] != String() && p_input_vars[1] == String()) { + } else if (!p_input_vars[0].is_empty() && p_input_vars[1].is_empty()) { code += " vec4 n_tex_read = triplanar_texture(" + id + ", " + p_input_vars[0] + ", triplanar_pos);\n"; - } else if (p_input_vars[0] == String() && p_input_vars[1] != String()) { + } else if (p_input_vars[0].is_empty() && !p_input_vars[1].is_empty()) { code += " vec4 n_tex_read = triplanar_texture(" + id + ", triplanar_power_normal, " + p_input_vars[1] + ");\n"; } else { code += " vec4 n_tex_read = triplanar_texture(" + id + ", " + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; @@ -5132,8 +5154,8 @@ String VisualShaderNodeTexture2DArrayUniform::generate_global(Shader::Mode p_mod case TYPE_NORMAL_MAP: code += " : hint_normal;\n"; break; - case TYPE_ANISO: - code += " : hint_aniso;\n"; + case TYPE_ANISOTROPY: + code += " : hint_anisotropy;\n"; break; default: code += ";\n"; @@ -5205,8 +5227,8 @@ String VisualShaderNodeTexture3DUniform::generate_global(Shader::Mode p_mode, Vi case TYPE_NORMAL_MAP: code += " : hint_normal;\n"; break; - case TYPE_ANISO: - code += " : hint_aniso;\n"; + case TYPE_ANISOTROPY: + code += " : hint_anisotropy;\n"; break; default: code += ";\n"; @@ -5278,8 +5300,8 @@ String VisualShaderNodeCubemapUniform::generate_global(Shader::Mode p_mode, Visu case TYPE_NORMAL_MAP: code += " : hint_normal;\n"; break; - case TYPE_ANISO: - code += " : hint_aniso;\n"; + case TYPE_ANISOTROPY: + code += " : hint_anisotropy;\n"; break; default: code += ";\n"; @@ -5578,12 +5600,12 @@ bool VisualShaderNodeFresnel::is_generate_input_var(int p_port) const { String VisualShaderNodeFresnel::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) const { String normal; String view; - if (p_input_vars[0] == String()) { + if (p_input_vars[0].is_empty()) { normal = "NORMAL"; } else { normal = p_input_vars[0]; } - if (p_input_vars[1] == String()) { + if (p_input_vars[1].is_empty()) { view = "VIEW"; } else { view = p_input_vars[1]; diff --git a/scene/resources/visual_shader_nodes.h b/scene/resources/visual_shader_nodes.h index 2c952300fe..a9ad762b32 100644 --- a/scene/resources/visual_shader_nodes.h +++ b/scene/resources/visual_shader_nodes.h @@ -579,6 +579,11 @@ public: OP_MOD, OP_MAX, OP_MIN, + OP_BITWISE_AND, + OP_BITWISE_OR, + OP_BITWISE_XOR, + OP_BITWISE_LEFT_SHIFT, + OP_BITWISE_RIGHT_SHIFT, OP_ENUM_SIZE, }; @@ -882,6 +887,7 @@ public: FUNC_ABS, FUNC_NEGATE, FUNC_SIGN, + FUNC_BITWISE_NOT, FUNC_MAX, }; @@ -1937,7 +1943,7 @@ public: TYPE_DATA, TYPE_COLOR, TYPE_NORMAL_MAP, - TYPE_ANISO, + TYPE_ANISOTROPY, TYPE_MAX, }; diff --git a/scene/resources/visual_shader_sdf_nodes.cpp b/scene/resources/visual_shader_sdf_nodes.cpp index 14c655b129..0fe7c33396 100644 --- a/scene/resources/visual_shader_sdf_nodes.cpp +++ b/scene/resources/visual_shader_sdf_nodes.cpp @@ -61,7 +61,7 @@ String VisualShaderNodeSDFToScreenUV::get_output_port_name(int p_port) const { } String VisualShaderNodeSDFToScreenUV::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) const { - return " " + p_output_vars[0] + " = vec3(sdf_to_screen_uv(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n"; + return " " + p_output_vars[0] + " = vec3(sdf_to_screen_uv(" + (p_input_vars[0].is_empty() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n"; } VisualShaderNodeSDFToScreenUV::VisualShaderNodeSDFToScreenUV() { @@ -105,7 +105,7 @@ String VisualShaderNodeScreenUVToSDF::get_input_port_default_hint(int p_port) co } String VisualShaderNodeScreenUVToSDF::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) const { - return " " + p_output_vars[0] + " = vec3(screen_uv_to_sdf(" + (p_input_vars[0] == String() ? "SCREEN_UV" : p_input_vars[0] + ".xy") + "), 0.0f);\n"; + return " " + p_output_vars[0] + " = vec3(screen_uv_to_sdf(" + (p_input_vars[0].is_empty() ? "SCREEN_UV" : p_input_vars[0] + ".xy") + "), 0.0f);\n"; } VisualShaderNodeScreenUVToSDF::VisualShaderNodeScreenUVToSDF() { @@ -142,7 +142,7 @@ String VisualShaderNodeTextureSDF::get_output_port_name(int p_port) const { } String VisualShaderNodeTextureSDF::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) const { - return " " + p_output_vars[0] + " = texture_sdf(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + ");\n"; + return " " + p_output_vars[0] + " = texture_sdf(" + (p_input_vars[0].is_empty() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + ");\n"; } VisualShaderNodeTextureSDF::VisualShaderNodeTextureSDF() { @@ -179,7 +179,7 @@ String VisualShaderNodeTextureSDFNormal::get_output_port_name(int p_port) const } String VisualShaderNodeTextureSDFNormal::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) const { - return " " + p_output_vars[0] + " = vec3(texture_sdf_normal(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n"; + return " " + p_output_vars[0] + " = vec3(texture_sdf_normal(" + (p_input_vars[0].is_empty() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n"; } VisualShaderNodeTextureSDFNormal::VisualShaderNodeTextureSDFNormal() { @@ -242,13 +242,13 @@ String VisualShaderNodeSDFRaymarch::generate_code(Shader::Mode p_mode, VisualSha code += " {\n"; - if (p_input_vars[0] == String()) { + if (p_input_vars[0].is_empty()) { code += " vec2 __from_pos = vec2(0.0f);\n"; } else { code += " vec2 __from_pos = " + p_input_vars[0] + ".xy;\n"; } - if (p_input_vars[1] == String()) { + if (p_input_vars[1].is_empty()) { code += " vec2 __to_pos = vec2(0.0f);\n"; } else { code += " vec2 __to_pos = " + p_input_vars[1] + ".xy;\n"; |