diff options
197 files changed, 3707 insertions, 1954 deletions
diff --git a/.gitignore b/.gitignore index 537ed7d32a..84aaefd736 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ core/version_generated.h drivers/gles2/shaders/*.h drivers/gles3/shaders/*.h drivers/unix/os_unix_global_settings_path.cpp +editor/authors.h editor/builtin_fonts.h editor/certs_compressed.h editor/doc_data_compressed.h diff --git a/core/helper/math_fieldwise.cpp b/core/helper/math_fieldwise.cpp index 2f176fb9bf..cf45902bf9 100644 --- a/core/helper/math_fieldwise.cpp +++ b/core/helper/math_fieldwise.cpp @@ -63,8 +63,8 @@ Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const SETUP_TYPE(Rect2) - /**/ TRY_TRANSFER_FIELD("x", pos.x) - else TRY_TRANSFER_FIELD("y", pos.y) + /**/ TRY_TRANSFER_FIELD("x", position.x) + else TRY_TRANSFER_FIELD("y", position.y) else TRY_TRANSFER_FIELD("w", size.x) else TRY_TRANSFER_FIELD("h", size.y) diff --git a/core/image.cpp b/core/image.cpp index deff2a81ca..2da91c7b13 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -59,8 +59,6 @@ const char *Image::format_names[Image::FORMAT_MAX] = { "DXT1 RGB8", //s3tc "DXT3 RGBA8", "DXT5 RGBA8", - "LATC Lum8", - "LATC LumAlpha8", "RGTC Red8", "RGTC RedGreen8", "BPTC_RGBA", @@ -131,10 +129,8 @@ int Image::get_format_pixel_size(Format p_format) { return 1; //bc2 case FORMAT_DXT5: return 1; //bc3 - case FORMAT_LATC_L: case FORMAT_RGTC_R: return 1; //bc4 - case FORMAT_LATC_LA: case FORMAT_RGTC_RG: return 1; //bc5 case FORMAT_BPTC_RGBA: @@ -171,8 +167,6 @@ void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) { case FORMAT_DXT1: //s3tc bc1 case FORMAT_DXT3: //bc2 case FORMAT_DXT5: //bc3 - case FORMAT_LATC_L: //bc4 - case FORMAT_LATC_LA: //bc4 case FORMAT_RGTC_R: //bc4 case FORMAT_RGTC_RG: { //bc5 case case FORMAT_DXT1: @@ -225,7 +219,7 @@ void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) { int Image::get_format_pixel_rshift(Format p_format) { - if (p_format == FORMAT_DXT1 || p_format == FORMAT_LATC_L || p_format == FORMAT_RGTC_R || p_format == FORMAT_PVRTC4 || p_format == FORMAT_PVRTC4A || p_format == FORMAT_ETC || p_format == FORMAT_ETC2_R11 || p_format == FORMAT_ETC2_R11S || p_format == FORMAT_ETC2_RGB8 || p_format == FORMAT_ETC2_RGB8A1) + if (p_format == FORMAT_DXT1 || p_format == FORMAT_RGTC_R || p_format == FORMAT_PVRTC4 || p_format == FORMAT_PVRTC4A || p_format == FORMAT_ETC || p_format == FORMAT_ETC2_R11 || p_format == FORMAT_ETC2_R11S || p_format == FORMAT_ETC2_RGB8 || p_format == FORMAT_ETC2_RGB8A1) return 1; else if (p_format == FORMAT_PVRTC2 || p_format == FORMAT_PVRTC2A) return 2; @@ -239,8 +233,6 @@ int Image::get_format_block_size(Format p_format) { case FORMAT_DXT1: //s3tc bc1 case FORMAT_DXT3: //bc2 case FORMAT_DXT5: //bc3 - case FORMAT_LATC_L: //bc4 - case FORMAT_LATC_LA: //bc4 case FORMAT_RGTC_R: //bc4 case FORMAT_RGTC_RG: { //bc5 case case FORMAT_DXT1: @@ -1500,14 +1492,14 @@ Error Image::decompress() { return OK; } -Error Image::compress(CompressMode p_mode) { +Error Image::compress(CompressMode p_mode, bool p_for_srgb) { switch (p_mode) { case COMPRESS_S3TC: { ERR_FAIL_COND_V(!_image_compress_bc_func, ERR_UNAVAILABLE); - _image_compress_bc_func(this); + _image_compress_bc_func(this, p_for_srgb); } break; case COMPRESS_PVRTC2: { @@ -1620,11 +1612,11 @@ void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Po ERR_FAIL_COND(srcdsize == 0); ERR_FAIL_COND(format != p_src->format); - Rect2i local_src_rect = Rect2i(0, 0, width, height).clip(Rect2i(p_dest + p_src_rect.pos, p_src_rect.size)); + Rect2i local_src_rect = Rect2i(0, 0, width, height).clip(Rect2i(p_dest + p_src_rect.position, p_src_rect.size)); if (local_src_rect.size.x <= 0 || local_src_rect.size.y <= 0) return; - Rect2i src_rect(p_src_rect.pos + (local_src_rect.pos - p_dest), local_src_rect.size); + Rect2i src_rect(p_src_rect.position + (local_src_rect.position - p_dest), local_src_rect.size); PoolVector<uint8_t>::Write wp = data.write(); uint8_t *dst_data_ptr = wp.ptr(); @@ -1638,11 +1630,11 @@ void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Po for (int j = 0; j < src_rect.size.x; j++) { - int src_x = src_rect.pos.x + j; - int src_y = src_rect.pos.y + i; + int src_x = src_rect.position.x + j; + int src_y = src_rect.position.y + i; - int dst_x = local_src_rect.pos.x + j; - int dst_y = local_src_rect.pos.y + i; + int dst_x = local_src_rect.position.x + j; + int dst_y = local_src_rect.position.y + i; const uint8_t *src = &src_data_ptr[(src_y * p_src->width + src_x) * pixel_size]; uint8_t *dst = &dst_data_ptr[(dst_y * width + dst_x) * pixel_size]; @@ -1657,7 +1649,7 @@ void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Po Ref<Image> (*Image::_png_mem_loader_func)(const uint8_t *, int) = NULL; Ref<Image> (*Image::_jpg_mem_loader_func)(const uint8_t *, int) = NULL; -void (*Image::_image_compress_bc_func)(Image *) = NULL; +void (*Image::_image_compress_bc_func)(Image *, bool) = NULL; void (*Image::_image_compress_pvrtc2_func)(Image *) = NULL; void (*Image::_image_compress_pvrtc4_func)(Image *) = NULL; void (*Image::_image_compress_etc_func)(Image *) = NULL; @@ -2116,8 +2108,6 @@ void Image::_bind_methods() { BIND_CONSTANT(FORMAT_DXT1); //s3tc bc1 BIND_CONSTANT(FORMAT_DXT3); //bc2 BIND_CONSTANT(FORMAT_DXT5); //bc3 - BIND_CONSTANT(FORMAT_LATC_L); - BIND_CONSTANT(FORMAT_LATC_LA); BIND_CONSTANT(FORMAT_RGTC_R); BIND_CONSTANT(FORMAT_RGTC_RG); BIND_CONSTANT(FORMAT_BPTC_RGBA); //btpc bc6h @@ -2152,7 +2142,7 @@ void Image::_bind_methods() { BIND_CONSTANT(COMPRESS_ETC2); } -void Image::set_compress_bc_func(void (*p_compress_func)(Image *)) { +void Image::set_compress_bc_func(void (*p_compress_func)(Image *, bool)) { _image_compress_bc_func = p_compress_func; } diff --git a/core/image.h b/core/image.h index 9ea01a94d4..2a78870f53 100644 --- a/core/image.h +++ b/core/image.h @@ -80,8 +80,6 @@ public: FORMAT_DXT1, //s3tc bc1 FORMAT_DXT3, //bc2 FORMAT_DXT5, //bc3 - FORMAT_LATC_L, - FORMAT_LATC_LA, FORMAT_RGTC_R, FORMAT_RGTC_RG, FORMAT_BPTC_RGBA, //btpc bc7 @@ -116,7 +114,7 @@ public: static Ref<Image> (*_png_mem_loader_func)(const uint8_t *p_png, int p_size); static Ref<Image> (*_jpg_mem_loader_func)(const uint8_t *p_png, int p_size); - static void (*_image_compress_bc_func)(Image *); + static void (*_image_compress_bc_func)(Image *, bool p_srgb); static void (*_image_compress_pvrtc2_func)(Image *); static void (*_image_compress_pvrtc4_func)(Image *); static void (*_image_compress_etc_func)(Image *); @@ -269,7 +267,7 @@ public: COMPRESS_ETC2, }; - Error compress(CompressMode p_mode = COMPRESS_S3TC); + Error compress(CompressMode p_mode = COMPRESS_S3TC, bool p_for_srgb = false); Error decompress(); bool is_compressed() const; @@ -283,7 +281,7 @@ public: Rect2 get_used_rect() const; Ref<Image> get_rect(const Rect2 &p_area) const; - static void set_compress_bc_func(void (*p_compress_func)(Image *)); + static void set_compress_bc_func(void (*p_compress_func)(Image *, bool)); static String get_format_name(Format p_format); Image(const uint8_t *p_mem_png_jpg, int p_len = -1); diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index dccf70ad7a..ceae543ff9 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -139,8 +139,8 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int ERR_FAIL_COND_V(len < (int)4 * 4, ERR_INVALID_DATA); Rect2 val; - val.pos.x = decode_float(&buf[0]); - val.pos.y = decode_float(&buf[4]); + val.position.x = decode_float(&buf[0]); + val.position.y = decode_float(&buf[4]); val.size.x = decode_float(&buf[8]); val.size.y = decode_float(&buf[12]); r_variant = val; @@ -861,8 +861,8 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) { if (buf) { Rect2 r2 = p_variant; - encode_float(r2.pos.x, &buf[0]); - encode_float(r2.pos.y, &buf[4]); + encode_float(r2.position.x, &buf[0]); + encode_float(r2.position.y, &buf[4]); encode_float(r2.size.x, &buf[8]); encode_float(r2.size.y, &buf[12]); } diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 26b53c2a31..01cad9d525 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -155,8 +155,8 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { case VARIANT_RECT2: { Rect2 v; - v.pos.x = f->get_real(); - v.pos.y = f->get_real(); + v.position.x = f->get_real(); + v.position.y = f->get_real(); v.size.x = f->get_real(); v.size.y = f->get_real(); r_v = v; @@ -1288,8 +1288,8 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant &p_property, f->store_32(VARIANT_RECT2); Rect2 val = p_property; - f->store_real(val.pos.x); - f->store_real(val.pos.y); + f->store_real(val.position.x); + f->store_real(val.position.y); f->store_real(val.size.x); f->store_real(val.size.y); diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp index 5b072b7c53..c26b12b0f0 100644 --- a/core/math/camera_matrix.cpp +++ b/core/math/camera_matrix.cpp @@ -507,8 +507,8 @@ void CameraMatrix::set_light_atlas_rect(const Rect2 &p_rect) { m[9] = 0.0, m[10] = 1.0, m[11] = 0.0, - m[12] = p_rect.pos.x, - m[13] = p_rect.pos.y, + m[12] = p_rect.position.x, + m[13] = p_rect.position.y, m[14] = 0.0, m[15] = 1.0; } diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp index 962a42acb9..52e240ed47 100644 --- a/core/math/math_2d.cpp +++ b/core/math/math_2d.cpp @@ -308,7 +308,7 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 for (int i = 0; i < 2; i++) { real_t seg_from = p_from[i]; real_t seg_to = p_to[i]; - real_t box_begin = pos[i]; + real_t box_begin = position[i]; real_t box_end = box_begin + size[i]; real_t cmin, cmax; real_t csign; diff --git a/core/math/math_2d.h b/core/math/math_2d.h index 128b74baf6..3369e2ec4f 100644 --- a/core/math/math_2d.h +++ b/core/math/math_2d.h @@ -207,24 +207,24 @@ struct Transform2D; struct Rect2 { - Point2 pos; + Point2 position; Size2 size; - const Vector2 &get_pos() const { return pos; } - void set_pos(const Vector2 &p_pos) { pos = p_pos; } + const Vector2 &get_position() const { return position; } + void set_position(const Vector2 &p_pos) { position = p_pos; } const Vector2 &get_size() const { return size; } void set_size(const Vector2 &p_size) { size = p_size; } real_t get_area() const { return size.width * size.height; } inline bool intersects(const Rect2 &p_rect) const { - if (pos.x >= (p_rect.pos.x + p_rect.size.width)) + if (position.x >= (p_rect.position.x + p_rect.size.width)) return false; - if ((pos.x + size.width) <= p_rect.pos.x) + if ((position.x + size.width) <= p_rect.position.x) return false; - if (pos.y >= (p_rect.pos.y + p_rect.size.height)) + if (position.y >= (p_rect.position.y + p_rect.size.height)) return false; - if ((pos.y + size.height) <= p_rect.pos.y) + if ((position.y + size.height) <= p_rect.position.y) return false; return true; @@ -234,17 +234,17 @@ struct Rect2 { real_t dist = 1e20; - if (p_point.x < pos.x) { - dist = MIN(dist, pos.x - p_point.x); + if (p_point.x < position.x) { + dist = MIN(dist, position.x - p_point.x); } - if (p_point.y < pos.y) { - dist = MIN(dist, pos.y - p_point.y); + if (p_point.y < position.y) { + dist = MIN(dist, position.y - p_point.y); } - if (p_point.x >= (pos.x + size.x)) { - dist = MIN(p_point.x - (pos.x + size.x), dist); + if (p_point.x >= (position.x + size.x)) { + dist = MIN(p_point.x - (position.x + size.x), dist); } - if (p_point.y >= (pos.y + size.y)) { - dist = MIN(p_point.y - (pos.y + size.y), dist); + if (p_point.y >= (position.y + size.y)) { + dist = MIN(p_point.y - (position.y + size.y), dist); } if (dist == 1e20) @@ -259,9 +259,9 @@ struct Rect2 { inline bool encloses(const Rect2 &p_rect) const { - return (p_rect.pos.x >= pos.x) && (p_rect.pos.y >= pos.y) && - ((p_rect.pos.x + p_rect.size.x) < (pos.x + size.x)) && - ((p_rect.pos.y + p_rect.size.y) < (pos.y + size.y)); + return (p_rect.position.x >= position.x) && (p_rect.position.y >= position.y) && + ((p_rect.position.x + p_rect.size.x) < (position.x + size.x)) && + ((p_rect.position.y + p_rect.size.y) < (position.y + size.y)); } inline bool has_no_area() const { @@ -275,14 +275,14 @@ struct Rect2 { if (!intersects(new_rect)) return Rect2(); - new_rect.pos.x = MAX(p_rect.pos.x, pos.x); - new_rect.pos.y = MAX(p_rect.pos.y, pos.y); + new_rect.position.x = MAX(p_rect.position.x, position.x); + new_rect.position.y = MAX(p_rect.position.y, position.y); - Point2 p_rect_end = p_rect.pos + p_rect.size; - Point2 end = pos + size; + Point2 p_rect_end = p_rect.position + p_rect.size; + Point2 end = position + size; - new_rect.size.x = MIN(p_rect_end.x, end.x) - new_rect.pos.x; - new_rect.size.y = MIN(p_rect_end.y, end.y) - new_rect.pos.y; + new_rect.size.x = MIN(p_rect_end.x, end.x) - new_rect.position.x; + new_rect.size.y = MIN(p_rect_end.y, end.y) - new_rect.position.y; return new_rect; } @@ -291,25 +291,25 @@ struct Rect2 { Rect2 new_rect; - new_rect.pos.x = MIN(p_rect.pos.x, pos.x); - new_rect.pos.y = MIN(p_rect.pos.y, pos.y); + new_rect.position.x = MIN(p_rect.position.x, position.x); + new_rect.position.y = MIN(p_rect.position.y, position.y); - new_rect.size.x = MAX(p_rect.pos.x + p_rect.size.x, pos.x + size.x); - new_rect.size.y = MAX(p_rect.pos.y + p_rect.size.y, pos.y + size.y); + new_rect.size.x = MAX(p_rect.position.x + p_rect.size.x, position.x + size.x); + new_rect.size.y = MAX(p_rect.position.y + p_rect.size.y, position.y + size.y); - new_rect.size = new_rect.size - new_rect.pos; //make relative again + new_rect.size = new_rect.size - new_rect.position; //make relative again return new_rect; }; inline bool has_point(const Point2 &p_point) const { - if (p_point.x < pos.x) + if (p_point.x < position.x) return false; - if (p_point.y < pos.y) + if (p_point.y < position.y) return false; - if (p_point.x >= (pos.x + size.x)) + if (p_point.x >= (position.x + size.x)) return false; - if (p_point.y >= (pos.y + size.y)) + if (p_point.y >= (position.y + size.y)) return false; return true; @@ -317,18 +317,37 @@ struct Rect2 { inline bool no_area() const { return (size.width <= 0 || size.height <= 0); } - bool operator==(const Rect2 &p_rect) const { return pos == p_rect.pos && size == p_rect.size; } - bool operator!=(const Rect2 &p_rect) const { return pos != p_rect.pos || size != p_rect.size; } + bool operator==(const Rect2 &p_rect) const { return position == p_rect.position && size == p_rect.size; } + bool operator!=(const Rect2 &p_rect) const { return position != p_rect.position || size != p_rect.size; } inline Rect2 grow(real_t p_by) const { Rect2 g = *this; - g.pos.x -= p_by; - g.pos.y -= p_by; + g.position.x -= p_by; + g.position.y -= p_by; g.size.width += p_by * 2; g.size.height += p_by * 2; return g; } + inline Rect2 grow_margin(Margin p_margin, real_t p_amount) const { + Rect2 g = *this; + g.grow_individual((MARGIN_LEFT == p_margin) ? p_amount : 0, + (MARGIN_TOP == p_margin) ? p_amount : 0, + (MARGIN_RIGHT == p_margin) ? p_amount : 0, + (MARGIN_BOTTOM == p_margin) ? p_amount : 0); + return g; + } + + inline Rect2 grow_individual(real_t p_left, real_t p_top, real_t p_right, real_t p_bottom) const { + + Rect2 g = *this; + g.pos.x -= p_left; + g.pos.y -= p_top; + g.size.width += p_left + p_right; + g.size.height += p_top + p_bottom; + + return g; + } inline Rect2 expand(const Vector2 &p_vector) const { @@ -339,8 +358,8 @@ struct Rect2 { inline void expand_to(const Vector2 &p_vector) { //in place function for speed - Vector2 begin = pos; - Vector2 end = pos + size; + Vector2 begin = position; + Vector2 end = position + size; if (p_vector.x < begin.x) begin.x = p_vector.x; @@ -352,19 +371,19 @@ struct Rect2 { if (p_vector.y > end.y) end.y = p_vector.y; - pos = begin; + position = begin; size = end - begin; } - operator String() const { return String(pos) + ", " + String(size); } + operator String() const { return String(position) + ", " + String(size); } Rect2() {} Rect2(real_t p_x, real_t p_y, real_t p_width, real_t p_height) { - pos = Point2(p_x, p_y); + position = Point2(p_x, p_y); size = Size2(p_width, p_height); } Rect2(const Point2 &p_pos, const Size2 &p_size) { - pos = p_pos; + position = p_pos; size = p_size; } }; @@ -434,24 +453,24 @@ typedef Point2i Size2i; struct Rect2i { - Point2i pos; + Point2i position; Size2i size; - const Point2i &get_pos() const { return pos; } - void set_pos(const Point2i &p_pos) { pos = p_pos; } + const Point2i &get_position() const { return position; } + void set_position(const Point2i &p_pos) { position = p_pos; } const Point2i &get_size() const { return size; } void set_size(const Point2i &p_size) { size = p_size; } int get_area() const { return size.width * size.height; } inline bool intersects(const Rect2i &p_rect) const { - if (pos.x > (p_rect.pos.x + p_rect.size.width)) + if (position.x > (p_rect.position.x + p_rect.size.width)) return false; - if ((pos.x + size.width) < p_rect.pos.x) + if ((position.x + size.width) < p_rect.position.x) return false; - if (pos.y > (p_rect.pos.y + p_rect.size.height)) + if (position.y > (p_rect.position.y + p_rect.size.height)) return false; - if ((pos.y + size.height) < p_rect.pos.y) + if ((position.y + size.height) < p_rect.position.y) return false; return true; @@ -459,9 +478,9 @@ struct Rect2i { inline bool encloses(const Rect2i &p_rect) const { - return (p_rect.pos.x >= pos.x) && (p_rect.pos.y >= pos.y) && - ((p_rect.pos.x + p_rect.size.x) < (pos.x + size.x)) && - ((p_rect.pos.y + p_rect.size.y) < (pos.y + size.y)); + return (p_rect.position.x >= position.x) && (p_rect.position.y >= position.y) && + ((p_rect.position.x + p_rect.size.x) < (position.x + size.x)) && + ((p_rect.position.y + p_rect.size.y) < (position.y + size.y)); } inline bool has_no_area() const { @@ -475,14 +494,14 @@ struct Rect2i { if (!intersects(new_rect)) return Rect2i(); - new_rect.pos.x = MAX(p_rect.pos.x, pos.x); - new_rect.pos.y = MAX(p_rect.pos.y, pos.y); + new_rect.position.x = MAX(p_rect.position.x, position.x); + new_rect.position.y = MAX(p_rect.position.y, position.y); - Point2 p_rect_end = p_rect.pos + p_rect.size; - Point2 end = pos + size; + Point2 p_rect_end = p_rect.position + p_rect.size; + Point2 end = position + size; - new_rect.size.x = (int)(MIN(p_rect_end.x, end.x) - new_rect.pos.x); - new_rect.size.y = (int)(MIN(p_rect_end.y, end.y) - new_rect.pos.y); + new_rect.size.x = (int)(MIN(p_rect_end.x, end.x) - new_rect.position.x); + new_rect.size.y = (int)(MIN(p_rect_end.y, end.y) - new_rect.position.y); return new_rect; } @@ -491,25 +510,25 @@ struct Rect2i { Rect2i new_rect; - new_rect.pos.x = MIN(p_rect.pos.x, pos.x); - new_rect.pos.y = MIN(p_rect.pos.y, pos.y); + new_rect.position.x = MIN(p_rect.position.x, position.x); + new_rect.position.y = MIN(p_rect.position.y, position.y); - new_rect.size.x = MAX(p_rect.pos.x + p_rect.size.x, pos.x + size.x); - new_rect.size.y = MAX(p_rect.pos.y + p_rect.size.y, pos.y + size.y); + new_rect.size.x = MAX(p_rect.position.x + p_rect.size.x, position.x + size.x); + new_rect.size.y = MAX(p_rect.position.y + p_rect.size.y, position.y + size.y); - new_rect.size = new_rect.size - new_rect.pos; //make relative again + new_rect.size = new_rect.size - new_rect.position; //make relative again return new_rect; }; bool has_point(const Point2 &p_point) const { - if (p_point.x < pos.x) + if (p_point.x < position.x) return false; - if (p_point.y < pos.y) + if (p_point.y < position.y) return false; - if (p_point.x >= (pos.x + size.x)) + if (p_point.x >= (position.x + size.x)) return false; - if (p_point.y >= (pos.y + size.y)) + if (p_point.y >= (position.y + size.y)) return false; return true; @@ -517,14 +536,14 @@ struct Rect2i { bool no_area() { return (size.width <= 0 || size.height <= 0); } - bool operator==(const Rect2i &p_rect) const { return pos == p_rect.pos && size == p_rect.size; } - bool operator!=(const Rect2i &p_rect) const { return pos != p_rect.pos || size != p_rect.size; } + bool operator==(const Rect2i &p_rect) const { return position == p_rect.position && size == p_rect.size; } + bool operator!=(const Rect2i &p_rect) const { return position != p_rect.position || size != p_rect.size; } Rect2i grow(int p_by) const { Rect2i g = *this; - g.pos.x -= p_by; - g.pos.y -= p_by; + g.position.x -= p_by; + g.position.y -= p_by; g.size.width += p_by * 2; g.size.height += p_by * 2; return g; @@ -532,8 +551,8 @@ struct Rect2i { inline void expand_to(const Point2i &p_vector) { - Point2i begin = pos; - Point2i end = pos + size; + Point2i begin = position; + Point2i end = position + size; if (p_vector.x < begin.x) begin.x = p_vector.x; @@ -545,24 +564,24 @@ struct Rect2i { if (p_vector.y > end.y) end.y = p_vector.y; - pos = begin; + position = begin; size = end - begin; } - operator String() const { return String(pos) + ", " + String(size); } + operator String() const { return String(position) + ", " + String(size); } - operator Rect2() const { return Rect2(pos, size); } + operator Rect2() const { return Rect2(position, size); } Rect2i(const Rect2 &p_r2) { - pos = p_r2.pos; + position = p_r2.position; size = p_r2.size; } Rect2i() {} Rect2i(int p_x, int p_y, int p_width, int p_height) { - pos = Point2(p_x, p_y); + position = Point2(p_x, p_y); size = Size2(p_width, p_height); } Rect2i(const Point2 &p_pos, const Size2 &p_size) { - pos = p_pos; + position = p_pos; size = p_size; } }; @@ -668,30 +687,30 @@ bool Rect2::intersects_transformed(const Transform2D &p_xform, const Rect2 &p_re //SAT intersection between local and transformed rect2 Vector2 xf_points[4] = { - p_xform.xform(p_rect.pos), - p_xform.xform(Vector2(p_rect.pos.x + p_rect.size.x, p_rect.pos.y)), - p_xform.xform(Vector2(p_rect.pos.x, p_rect.pos.y + p_rect.size.y)), - p_xform.xform(Vector2(p_rect.pos.x + p_rect.size.x, p_rect.pos.y + p_rect.size.y)), + p_xform.xform(p_rect.position), + p_xform.xform(Vector2(p_rect.position.x + p_rect.size.x, p_rect.position.y)), + p_xform.xform(Vector2(p_rect.position.x, p_rect.position.y + p_rect.size.y)), + p_xform.xform(Vector2(p_rect.position.x + p_rect.size.x, p_rect.position.y + p_rect.size.y)), }; real_t low_limit; //base rect2 first (faster) - if (xf_points[0].y > pos.y) + if (xf_points[0].y > position.y) goto next1; - if (xf_points[1].y > pos.y) + if (xf_points[1].y > position.y) goto next1; - if (xf_points[2].y > pos.y) + if (xf_points[2].y > position.y) goto next1; - if (xf_points[3].y > pos.y) + if (xf_points[3].y > position.y) goto next1; return false; next1: - low_limit = pos.y + size.y; + low_limit = position.y + size.y; if (xf_points[0].y < low_limit) goto next2; @@ -706,20 +725,20 @@ next1: next2: - if (xf_points[0].x > pos.x) + if (xf_points[0].x > position.x) goto next3; - if (xf_points[1].x > pos.x) + if (xf_points[1].x > position.x) goto next3; - if (xf_points[2].x > pos.x) + if (xf_points[2].x > position.x) goto next3; - if (xf_points[3].x > pos.x) + if (xf_points[3].x > position.x) goto next3; return false; next3: - low_limit = pos.x + size.x; + low_limit = position.x + size.x; if (xf_points[0].x < low_limit) goto next4; @@ -735,10 +754,10 @@ next3: next4: Vector2 xf_points2[4] = { - pos, - Vector2(pos.x + size.x, pos.y), - Vector2(pos.x, pos.y + size.y), - Vector2(pos.x + size.x, pos.y + size.y), + position, + Vector2(position.x + size.x, position.y), + Vector2(position.x, position.y + size.y), + Vector2(position.x + size.x, position.y + size.y), }; real_t maxa = p_xform.elements[0].dot(xf_points2[0]); @@ -847,10 +866,10 @@ Rect2 Transform2D::xform(const Rect2 &p_rect) const { Vector2 x = elements[0] * p_rect.size.x; Vector2 y = elements[1] * p_rect.size.y; - Vector2 pos = xform(p_rect.pos); + Vector2 pos = xform(p_rect.position); Rect2 new_rect; - new_rect.pos = pos; + new_rect.position = pos; new_rect.expand_to(pos + x); new_rect.expand_to(pos + y); new_rect.expand_to(pos + x + y); @@ -868,14 +887,14 @@ void Transform2D::set_rotation_and_scale(real_t p_rot, const Size2 &p_scale) { Rect2 Transform2D::xform_inv(const Rect2 &p_rect) const { Vector2 ends[4] = { - xform_inv(p_rect.pos), - xform_inv(Vector2(p_rect.pos.x, p_rect.pos.y + p_rect.size.y)), - xform_inv(Vector2(p_rect.pos.x + p_rect.size.x, p_rect.pos.y + p_rect.size.y)), - xform_inv(Vector2(p_rect.pos.x + p_rect.size.x, p_rect.pos.y)) + xform_inv(p_rect.position), + xform_inv(Vector2(p_rect.position.x, p_rect.position.y + p_rect.size.y)), + xform_inv(Vector2(p_rect.position.x + p_rect.size.x, p_rect.position.y + p_rect.size.y)), + xform_inv(Vector2(p_rect.position.x + p_rect.size.x, p_rect.position.y)) }; Rect2 new_rect; - new_rect.pos = ends[0]; + new_rect.position = ends[0]; new_rect.expand_to(ends[1]); new_rect.expand_to(ends[2]); new_rect.expand_to(ends[3]); diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 6a5e12c3ce..ca960aabad 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -51,9 +51,7 @@ class Math { public: Math() {} // useless to instance - enum { - RANDOM_MAX = 4294967295L - }; + static const uint64_t RANDOM_MAX = 4294967295; static _ALWAYS_INLINE_ double sin(double p_x) { return ::sin(p_x); } static _ALWAYS_INLINE_ float sin(float p_x) { return ::sinf(p_x); } diff --git a/core/method_ptrcall.h b/core/method_ptrcall.h index bcbf2e4531..c6dbfc2a7a 100644 --- a/core/method_ptrcall.h +++ b/core/method_ptrcall.h @@ -115,7 +115,6 @@ MAKE_PTRARG(PoolVector2Array); MAKE_PTRARG(PoolVector3Array); MAKE_PTRARG(PoolColorArray); MAKE_PTRARG(Variant); -MAKE_PTRARG(PowerState); //this is for Object diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 0d727f4bcb..dbdf9628e3 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -327,20 +327,20 @@ int InputEventMouse::get_button_mask() const { return button_mask; } -void InputEventMouse::set_pos(const Vector2 &p_pos) { +void InputEventMouse::set_position(const Vector2 &p_pos) { pos = p_pos; } -Vector2 InputEventMouse::get_pos() const { +Vector2 InputEventMouse::get_position() const { return pos; } -void InputEventMouse::set_global_pos(const Vector2 &p_global_pos) { +void InputEventMouse::set_global_position(const Vector2 &p_global_pos) { global_pos = p_global_pos; } -Vector2 InputEventMouse::get_global_pos() const { +Vector2 InputEventMouse::get_global_position() const { return global_pos; } @@ -350,15 +350,15 @@ void InputEventMouse::_bind_methods() { ClassDB::bind_method(D_METHOD("set_button_mask", "button_mask"), &InputEventMouse::set_button_mask); ClassDB::bind_method(D_METHOD("get_button_mask"), &InputEventMouse::get_button_mask); - ClassDB::bind_method(D_METHOD("set_pos", "pos"), &InputEventMouse::set_pos); - ClassDB::bind_method(D_METHOD("get_pos"), &InputEventMouse::get_pos); + ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventMouse::set_position); + ClassDB::bind_method(D_METHOD("get_position"), &InputEventMouse::get_position); - ClassDB::bind_method(D_METHOD("set_global_pos", "global_pos"), &InputEventMouse::set_global_pos); - ClassDB::bind_method(D_METHOD("get_global_pos"), &InputEventMouse::get_global_pos); + ClassDB::bind_method(D_METHOD("set_global_position", "global_position"), &InputEventMouse::set_global_position); + ClassDB::bind_method(D_METHOD("get_global_position"), &InputEventMouse::get_global_position); ADD_PROPERTY(PropertyInfo(Variant::INT, "button_mask"), "set_button_mask", "get_button_mask"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "pos"), "set_pos", "get_pos"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "global_pos"), "set_global_pos", "get_global_pos"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "global_position"), "set_global_position", "get_global_position"); } InputEventMouse::InputEventMouse() { @@ -407,8 +407,8 @@ bool InputEventMouseButton::is_doubleclick() const { Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { - Vector2 g = p_xform.xform(get_global_pos()); - Vector2 l = p_xform.xform(get_pos() + p_local_ofs); + Vector2 g = p_xform.xform(get_global_position()); + Vector2 l = p_xform.xform(get_position() + p_local_ofs); Ref<InputEventMouseButton> mb; mb.instance(); @@ -421,8 +421,8 @@ Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, co mb->set_control(get_control()); mb->set_metakey(get_metakey()); - mb->set_pos(l); - mb->set_global_pos(g); + mb->set_position(l); + mb->set_global_position(g); mb->set_button_mask(get_button_mask()); mb->set_pressed(pressed); @@ -492,8 +492,8 @@ Vector2 InputEventMouseMotion::get_speed() const { Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { - Vector2 g = p_xform.xform(get_global_pos()); - Vector2 l = p_xform.xform(get_pos() + p_local_ofs); + Vector2 g = p_xform.xform(get_global_position()); + Vector2 l = p_xform.xform(get_position() + p_local_ofs); Vector2 r = p_xform.basis_xform(get_relative()); Vector2 s = p_xform.basis_xform(get_speed()); @@ -508,8 +508,8 @@ Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, co mm->set_control(get_control()); mm->set_metakey(get_metakey()); - mm->set_pos(l); - mm->set_global_pos(g); + mm->set_position(l); + mm->set_global_position(g); mm->set_button_mask(get_button_mask()); mm->set_relative(r); @@ -653,11 +653,11 @@ int InputEventScreenTouch::get_index() const { return index; } -void InputEventScreenTouch::set_pos(const Vector2 &p_pos) { +void InputEventScreenTouch::set_position(const Vector2 &p_pos) { pos = p_pos; } -Vector2 InputEventScreenTouch::get_pos() const { +Vector2 InputEventScreenTouch::get_position() const { return pos; } @@ -678,7 +678,7 @@ Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, co st->set_id(get_id()); st->set_device(get_device()); st->set_index(index); - st->set_pos(p_xform.xform(pos + p_local_ofs)); + st->set_position(p_xform.xform(pos + p_local_ofs)); st->set_pressed(pressed); return st; @@ -689,14 +689,14 @@ void InputEventScreenTouch::_bind_methods() { ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenTouch::set_index); ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenTouch::get_index); - ClassDB::bind_method(D_METHOD("set_pos", "pos"), &InputEventScreenTouch::set_pos); - ClassDB::bind_method(D_METHOD("get_pos"), &InputEventScreenTouch::get_pos); + ClassDB::bind_method(D_METHOD("set_position", "pos"), &InputEventScreenTouch::set_position); + ClassDB::bind_method(D_METHOD("get_position"), &InputEventScreenTouch::get_position); ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventScreenTouch::set_pressed); //ClassDB::bind_method(D_METHOD("is_pressed"),&InputEventScreenTouch::is_pressed); ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "pos"), "set_pos", "get_pos"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed"); } @@ -718,11 +718,11 @@ int InputEventScreenDrag::get_index() const { return index; } -void InputEventScreenDrag::set_pos(const Vector2 &p_pos) { +void InputEventScreenDrag::set_position(const Vector2 &p_pos) { pos = p_pos; } -Vector2 InputEventScreenDrag::get_pos() const { +Vector2 InputEventScreenDrag::get_position() const { return pos; } @@ -755,7 +755,7 @@ Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, con sd->set_device(get_device()); sd->set_index(index); - sd->set_pos(p_xform.xform(pos + p_local_ofs)); + sd->set_position(p_xform.xform(pos + p_local_ofs)); sd->set_relative(p_xform.basis_xform(relative)); sd->set_speed(p_xform.basis_xform(speed)); @@ -767,8 +767,8 @@ void InputEventScreenDrag::_bind_methods() { ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenDrag::set_index); ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenDrag::get_index); - ClassDB::bind_method(D_METHOD("set_pos", "pos"), &InputEventScreenDrag::set_pos); - ClassDB::bind_method(D_METHOD("get_pos"), &InputEventScreenDrag::get_pos); + ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventScreenDrag::set_position); + ClassDB::bind_method(D_METHOD("get_position"), &InputEventScreenDrag::get_position); ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventScreenDrag::set_relative); ClassDB::bind_method(D_METHOD("get_relative"), &InputEventScreenDrag::get_relative); @@ -777,7 +777,7 @@ void InputEventScreenDrag::_bind_methods() { ClassDB::bind_method(D_METHOD("get_speed"), &InputEventScreenDrag::get_speed); ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "pos"), "set_pos", "get_pos"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative"), "set_relative", "get_relative"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed"); } diff --git a/core/os/input_event.h b/core/os/input_event.h index 31f88b295b..6a694df345 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -265,11 +265,11 @@ public: void set_button_mask(int p_mask); int get_button_mask() const; - void set_pos(const Vector2 &p_pos); - Vector2 get_pos() const; + void set_position(const Vector2 &p_pos); + Vector2 get_position() const; - void set_global_pos(const Vector2 &p_global_pos); - Vector2 get_global_pos() const; + void set_global_position(const Vector2 &p_global_pos); + Vector2 get_global_position() const; InputEventMouse(); }; @@ -390,8 +390,8 @@ public: void set_index(int p_index); int get_index() const; - void set_pos(const Vector2 &p_pos); - Vector2 get_pos() const; + void set_position(const Vector2 &p_pos); + Vector2 get_position() const; void set_pressed(bool p_pressed); virtual bool is_pressed() const; @@ -416,8 +416,8 @@ public: void set_index(int p_index); int get_index() const; - void set_pos(const Vector2 &p_pos); - Vector2 get_pos() const; + void set_position(const Vector2 &p_pos); + Vector2 get_position() const; void set_relative(const Vector2 &p_relative); Vector2 get_relative() const; diff --git a/core/os/os.h b/core/os/os.h index 037ce436c1..11fe8b44e3 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -413,4 +413,6 @@ public: virtual ~OS(); }; +VARIANT_ENUM_CAST(PowerState); + #endif diff --git a/core/variant.cpp b/core/variant.cpp index ae5141b8bf..0543dd6b79 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -2549,8 +2549,8 @@ uint32_t Variant::hash() const { } break; case RECT2: { - uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->pos.x); - hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->pos.y, hash); + uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->position.x); + hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->position.y, hash); hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->size.x, hash); return hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->size.y, hash); } break; @@ -2820,7 +2820,7 @@ bool Variant::hash_compare(const Variant &p_variant) const { const Rect2 *l = reinterpret_cast<const Rect2 *>(_data._mem); const Rect2 *r = reinterpret_cast<const Rect2 *>(p_variant._data._mem); - return (hash_compare_vector2(l->pos, r->pos)) && + return (hash_compare_vector2(l->position, r->position)) && (hash_compare_vector2(l->size, r->size)); } break; diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 6568dc877e..9ead727a80 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -354,6 +354,8 @@ struct _VariantCall { VCALL_LOCALMEM1R(Rect2, merge); VCALL_LOCALMEM1R(Rect2, has_point); VCALL_LOCALMEM1R(Rect2, grow); + VCALL_LOCALMEM2R(Rect2, grow_margin); + VCALL_LOCALMEM4R(Rect2, grow_individual); VCALL_LOCALMEM1R(Rect2, expand); VCALL_LOCALMEM0R(Vector3, min_axis); @@ -1433,6 +1435,8 @@ void register_variant_methods() { ADDFUNC1(RECT2, RECT2, Rect2, merge, RECT2, "b", varray()); ADDFUNC1(RECT2, BOOL, Rect2, has_point, VECTOR2, "point", varray()); ADDFUNC1(RECT2, RECT2, Rect2, grow, REAL, "by", varray()); + ADDFUNC2(RECT2, RECT2, Rect2, grow_margin, INT, "margin", REAL, "by", varray()); + ADDFUNC4(RECT2, RECT2, Rect2, grow_individual, REAL, "left", REAL, "top", REAL, "right", REAL, " bottom", varray()); ADDFUNC1(RECT2, RECT2, Rect2, expand, VECTOR2, "to", varray()); ADDFUNC0(VECTOR3, INT, Vector3, min_axis, varray()); diff --git a/core/variant_op.cpp b/core/variant_op.cpp index 7b9b7abd9e..4871df8918 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -1131,9 +1131,9 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) const String *str = reinterpret_cast<const String *>(p_index._data._mem); Rect2 *v = reinterpret_cast<Rect2 *>(_data._mem); - if (*str == "pos") { + if (*str == "position") { valid = true; - v->pos = p_value; + v->position = p_value; return; } else if (*str == "size") { valid = true; @@ -1141,7 +1141,7 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) return; } else if (*str == "end") { valid = true; - v->size = Vector2(p_value) - v->pos; + v->size = Vector2(p_value) - v->position; return; } } @@ -1589,15 +1589,15 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { const String *str = reinterpret_cast<const String *>(p_index._data._mem); const Rect2 *v = reinterpret_cast<const Rect2 *>(_data._mem); - if (*str == "pos") { + if (*str == "position") { valid = true; - return v->pos; + return v->position; } else if (*str == "size") { valid = true; return v->size; } else if (*str == "end") { valid = true; - return v->size + v->pos; + return v->size + v->position; } } } break; @@ -2111,7 +2111,7 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const { } break; // 5 case RECT2: { - p_list->push_back(PropertyInfo(Variant::VECTOR2, "pos")); + p_list->push_back(PropertyInfo(Variant::VECTOR2, "position")); p_list->push_back(PropertyInfo(Variant::VECTOR2, "size")); p_list->push_back(PropertyInfo(Variant::VECTOR2, "end")); @@ -2759,7 +2759,7 @@ void Variant::blend(const Variant &a, const Variant &b, float c, Variant &r_dst) case RECT2: { const Rect2 *ra = reinterpret_cast<const Rect2 *>(a._data._mem); const Rect2 *rb = reinterpret_cast<const Rect2 *>(b._data._mem); - r_dst = Rect2(ra->pos + rb->pos * c, ra->size + rb->size * c); + r_dst = Rect2(ra->position + rb->position * c, ra->size + rb->size * c); } return; case VECTOR3: { @@ -2879,7 +2879,7 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & } return; case RECT2: { - r_dst = Rect2(reinterpret_cast<const Rect2 *>(a._data._mem)->pos.linear_interpolate(reinterpret_cast<const Rect2 *>(b._data._mem)->pos, c), reinterpret_cast<const Rect2 *>(a._data._mem)->size.linear_interpolate(reinterpret_cast<const Rect2 *>(b._data._mem)->size, c)); + r_dst = Rect2(reinterpret_cast<const Rect2 *>(a._data._mem)->position.linear_interpolate(reinterpret_cast<const Rect2 *>(b._data._mem)->position, c), reinterpret_cast<const Rect2 *>(a._data._mem)->size.linear_interpolate(reinterpret_cast<const Rect2 *>(b._data._mem)->size, c)); } return; case VECTOR3: { diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index 55e2bb42e3..da78d98134 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -744,7 +744,12 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return err; if (token.type == TK_PARENTHESIS_CLOSE) { - + Reference *reference = obj->cast_to<Reference>(); + if (reference) { + value = REF(reference); + } else { + value = obj; + } return OK; } @@ -760,7 +765,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } } - get_token(p_stream, token, line, r_err_str); if (token.type != TK_STRING) { r_err_str = "Expected property name as string"; return ERR_PARSE_ERROR; @@ -1616,7 +1620,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str case Variant::RECT2: { Rect2 aabb = p_variant; - p_store_string_func(p_store_string_ud, "Rect2( " + rtosfix(aabb.pos.x) + ", " + rtosfix(aabb.pos.y) + ", " + rtosfix(aabb.size.x) + ", " + rtosfix(aabb.size.y) + " )"); + p_store_string_func(p_store_string_ud, "Rect2( " + rtosfix(aabb.position.x) + ", " + rtosfix(aabb.position.y) + ", " + rtosfix(aabb.size.x) + ", " + rtosfix(aabb.size.y) + " )"); } break; case Variant::VECTOR3: { diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp index 4f6d68de43..1121a07347 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.cpp +++ b/drivers/gles3/rasterizer_canvas_gles3.cpp @@ -473,7 +473,7 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item, Item *cur } Size2 texpixel_size(1.0 / texture->width, 1.0 / texture->height); - Rect2 src_rect = (rect->flags & CANVAS_RECT_REGION) ? Rect2(rect->source.pos * texpixel_size, rect->source.size * texpixel_size) : Rect2(0, 0, 1, 1); + Rect2 src_rect = (rect->flags & CANVAS_RECT_REGION) ? Rect2(rect->source.position * texpixel_size, rect->source.size * texpixel_size) : Rect2(0, 0, 1, 1); if (rect->flags & CANVAS_RECT_FLIP_H) { src_rect.size.x *= -1; @@ -489,8 +489,8 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item, Item *cur state.canvas_shader.set_uniform(CanvasShaderGLES3::COLOR_TEXPIXEL_SIZE, texpixel_size); - glVertexAttrib4f(1, rect->rect.pos.x, rect->rect.pos.y, rect->rect.size.x, rect->rect.size.y); - glVertexAttrib4f(2, src_rect.pos.x, src_rect.pos.y, src_rect.size.x, src_rect.size.y); + glVertexAttrib4f(1, rect->rect.position.x, rect->rect.position.y, rect->rect.size.x, rect->rect.size.y); + glVertexAttrib4f(2, src_rect.position.x, src_rect.position.y, src_rect.size.x, src_rect.size.y); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); if (untile) { @@ -500,7 +500,7 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item, Item *cur } else { - glVertexAttrib4f(1, rect->rect.pos.x, rect->rect.pos.y, rect->rect.size.x, rect->rect.size.y); + glVertexAttrib4f(1, rect->rect.position.x, rect->rect.position.y, rect->rect.size.x, rect->rect.size.y); glVertexAttrib4f(2, 0, 0, 1, 1); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } @@ -521,7 +521,7 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item, Item *cur if (!texture) { - glVertexAttrib4f(1, np->rect.pos.x, np->rect.pos.y, np->rect.size.x, np->rect.size.y); + glVertexAttrib4f(1, np->rect.position.x, np->rect.position.y, np->rect.size.x, np->rect.size.y); glVertexAttrib4f(2, 0, 0, 1, 1); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); continue; @@ -535,50 +535,50 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item, Item *cur #define SRCRECT(m_x, m_y, m_w, m_h) glVertexAttrib4f(2, (m_x)*texpixel_size.x, (m_y)*texpixel_size.y, (m_w)*texpixel_size.x, (m_h)*texpixel_size.y) //top left - DSTRECT(np->rect.pos.x, np->rect.pos.y, np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP]); - SRCRECT(np->source.pos.x, np->source.pos.y, np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP]); + DSTRECT(np->rect.position.x, np->rect.position.y, np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP]); + SRCRECT(np->source.position.x, np->source.position.y, np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP]); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); //top right - DSTRECT(np->rect.pos.x + np->rect.size.width - np->margin[MARGIN_RIGHT], np->rect.pos.y, np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]); - SRCRECT(np->source.pos.x + np->source.size.width - np->margin[MARGIN_RIGHT], np->source.pos.y, np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]); + DSTRECT(np->rect.position.x + np->rect.size.width - np->margin[MARGIN_RIGHT], np->rect.position.y, np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]); + SRCRECT(np->source.position.x + np->source.size.width - np->margin[MARGIN_RIGHT], np->source.position.y, np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); //bottom right - DSTRECT(np->rect.pos.x + np->rect.size.width - np->margin[MARGIN_RIGHT], np->rect.pos.y + np->rect.size.height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_RIGHT], np->margin[MARGIN_BOTTOM]); - SRCRECT(np->source.pos.x + np->source.size.width - np->margin[MARGIN_RIGHT], np->source.pos.y + np->source.size.height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_RIGHT], np->margin[MARGIN_BOTTOM]); + DSTRECT(np->rect.position.x + np->rect.size.width - np->margin[MARGIN_RIGHT], np->rect.position.y + np->rect.size.height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_RIGHT], np->margin[MARGIN_BOTTOM]); + SRCRECT(np->source.position.x + np->source.size.width - np->margin[MARGIN_RIGHT], np->source.position.y + np->source.size.height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_RIGHT], np->margin[MARGIN_BOTTOM]); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); //bottom left - DSTRECT(np->rect.pos.x, np->rect.pos.y + np->rect.size.height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_LEFT], np->margin[MARGIN_BOTTOM]); - SRCRECT(np->source.pos.x, np->source.pos.y + np->source.size.height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_LEFT], np->margin[MARGIN_BOTTOM]); + DSTRECT(np->rect.position.x, np->rect.position.y + np->rect.size.height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_LEFT], np->margin[MARGIN_BOTTOM]); + SRCRECT(np->source.position.x, np->source.position.y + np->source.size.height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_LEFT], np->margin[MARGIN_BOTTOM]); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); //top - DSTRECT(np->rect.pos.x + np->margin[MARGIN_LEFT], np->rect.pos.y, np->rect.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]); - SRCRECT(np->source.pos.x + np->margin[MARGIN_LEFT], np->source.pos.y, np->source.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]); + DSTRECT(np->rect.position.x + np->margin[MARGIN_LEFT], np->rect.position.y, np->rect.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]); + SRCRECT(np->source.position.x + np->margin[MARGIN_LEFT], np->source.position.y, np->source.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); //bottom - DSTRECT(np->rect.pos.x + np->margin[MARGIN_LEFT], np->rect.pos.y + np->rect.size.height - np->margin[MARGIN_BOTTOM], np->rect.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]); - SRCRECT(np->source.pos.x + np->margin[MARGIN_LEFT], np->source.pos.y + np->source.size.height - np->margin[MARGIN_BOTTOM], np->source.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP]); + DSTRECT(np->rect.position.x + np->margin[MARGIN_LEFT], np->rect.position.y + np->rect.size.height - np->margin[MARGIN_BOTTOM], np->rect.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]); + SRCRECT(np->source.position.x + np->margin[MARGIN_LEFT], np->source.position.y + np->source.size.height - np->margin[MARGIN_BOTTOM], np->source.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP]); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); //left - DSTRECT(np->rect.pos.x, np->rect.pos.y + np->margin[MARGIN_TOP], np->margin[MARGIN_LEFT], np->rect.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); - SRCRECT(np->source.pos.x, np->source.pos.y + np->margin[MARGIN_TOP], np->margin[MARGIN_LEFT], np->source.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); + DSTRECT(np->rect.position.x, np->rect.position.y + np->margin[MARGIN_TOP], np->margin[MARGIN_LEFT], np->rect.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); + SRCRECT(np->source.position.x, np->source.position.y + np->margin[MARGIN_TOP], np->margin[MARGIN_LEFT], np->source.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); //right - DSTRECT(np->rect.pos.x + np->rect.size.width - np->margin[MARGIN_RIGHT], np->rect.pos.y + np->margin[MARGIN_TOP], np->margin[MARGIN_RIGHT], np->rect.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); - SRCRECT(np->source.pos.x + np->source.size.width - np->margin[MARGIN_RIGHT], np->source.pos.y + np->margin[MARGIN_TOP], np->margin[MARGIN_RIGHT], np->source.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); + DSTRECT(np->rect.position.x + np->rect.size.width - np->margin[MARGIN_RIGHT], np->rect.position.y + np->margin[MARGIN_TOP], np->margin[MARGIN_RIGHT], np->rect.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); + SRCRECT(np->source.position.x + np->source.size.width - np->margin[MARGIN_RIGHT], np->source.position.y + np->margin[MARGIN_TOP], np->margin[MARGIN_RIGHT], np->source.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); if (np->draw_center) { //center - DSTRECT(np->rect.pos.x + np->margin[MARGIN_LEFT], np->rect.pos.y + np->margin[MARGIN_TOP], np->rect.size.x - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->rect.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); - SRCRECT(np->source.pos.x + np->margin[MARGIN_LEFT], np->source.pos.y + np->margin[MARGIN_TOP], np->source.size.x - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->source.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); + DSTRECT(np->rect.position.x + np->margin[MARGIN_LEFT], np->rect.position.y + np->margin[MARGIN_TOP], np->rect.size.x - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->rect.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); + SRCRECT(np->source.position.x + np->margin[MARGIN_LEFT], np->source.position.y + np->margin[MARGIN_TOP], np->source.size.x - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->source.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } @@ -670,8 +670,8 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item, Item *cur //glScissor(viewport.x+current_clip->final_clip_rect.pos.x,viewport.y+ (viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)), //current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height); - int x = current_clip->final_clip_rect.pos.x; - int y = storage->frame.current_rt->height - (current_clip->final_clip_rect.pos.y + current_clip->final_clip_rect.size.y); + int x = current_clip->final_clip_rect.position.x; + int y = storage->frame.current_rt->height - (current_clip->final_clip_rect.position.y + current_clip->final_clip_rect.size.y); int w = current_clip->final_clip_rect.size.x; int h = current_clip->final_clip_rect.size.y; @@ -787,7 +787,7 @@ void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list, int p_z, cons if (current_clip) { glEnable(GL_SCISSOR_TEST); - glScissor(current_clip->final_clip_rect.pos.x, (rt_size.height - (current_clip->final_clip_rect.pos.y + current_clip->final_clip_rect.size.height)), current_clip->final_clip_rect.size.width, current_clip->final_clip_rect.size.height); + glScissor(current_clip->final_clip_rect.position.x, (rt_size.height - (current_clip->final_clip_rect.position.y + current_clip->final_clip_rect.size.height)), current_clip->final_clip_rect.size.width, current_clip->final_clip_rect.size.height); } else { @@ -1108,7 +1108,7 @@ void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list, int p_z, cons if (reclip) { glEnable(GL_SCISSOR_TEST); - glScissor(current_clip->final_clip_rect.pos.x, (rt_size.height - (current_clip->final_clip_rect.pos.y + current_clip->final_clip_rect.size.height)), current_clip->final_clip_rect.size.width, current_clip->final_clip_rect.size.height); + glScissor(current_clip->final_clip_rect.position.x, (rt_size.height - (current_clip->final_clip_rect.position.y + current_clip->final_clip_rect.size.height)), current_clip->final_clip_rect.size.width, current_clip->final_clip_rect.size.height); } p_item_list = p_item_list->next; @@ -1340,8 +1340,8 @@ void RasterizerCanvasGLES3::reset_canvas() { void RasterizerCanvasGLES3::draw_generic_textured_rect(const Rect2 &p_rect, const Rect2 &p_src) { - glVertexAttrib4f(1, p_rect.pos.x, p_rect.pos.y, p_rect.size.x, p_rect.size.y); - glVertexAttrib4f(2, p_src.pos.x, p_src.pos.y, p_src.size.x, p_src.size.y); + glVertexAttrib4f(1, p_rect.position.x, p_rect.position.y, p_rect.size.x, p_rect.size.y); + glVertexAttrib4f(2, p_src.position.x, p_src.position.y, p_src.size.x, p_src.size.y); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp index aa4150cbe4..2262580d9a 100644 --- a/drivers/gles3/rasterizer_gles3.cpp +++ b/drivers/gles3/rasterizer_gles3.cpp @@ -301,18 +301,18 @@ void RasterizerGLES3::set_boot_image(const Ref<Image> &p_image, const Color &p_c //scale horizontally screenrect.size.y = window_h; screenrect.size.x = imgrect.size.x * window_h / imgrect.size.y; - screenrect.pos.x = (window_w - screenrect.size.x) / 2; + screenrect.position.x = (window_w - screenrect.size.x) / 2; } else { //scale vertically screenrect.size.x = window_w; screenrect.size.y = imgrect.size.y * window_w / imgrect.size.x; - screenrect.pos.y = (window_h - screenrect.size.y) / 2; + screenrect.position.y = (window_h - screenrect.size.y) / 2; } } else { screenrect = imgrect; - screenrect.pos += ((Size2(window_w, window_h) - screenrect.size) / 2.0).floor(); + screenrect.position += ((Size2(window_w, window_h) - screenrect.size) / 2.0).floor(); } RasterizerStorageGLES3::Texture *t = storage->texture_owner.get(texture); diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index 7138363796..af03819a16 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -933,6 +933,49 @@ void RasterizerSceneGLES3::environment_set_tonemap(RID p_env, VS::EnvironmentTon } void RasterizerSceneGLES3::environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, RID p_ramp) { + + Environment *env = environment_owner.getornull(p_env); + ERR_FAIL_COND(!env); + + env->adjustments_enabled = p_enable; + env->adjustments_brightness = p_brightness; + env->adjustments_contrast = p_contrast; + env->adjustments_saturation = p_saturation; + env->color_correction = p_ramp; +} + +void RasterizerSceneGLES3::environment_set_fog(RID p_env, bool p_enable, const Color &p_color, const Color &p_sun_color, float p_sun_amount) { + + Environment *env = environment_owner.getornull(p_env); + ERR_FAIL_COND(!env); + + env->fog_enabled = p_enable; + env->fog_color = p_color; + env->fog_sun_color = p_sun_color; + env->fog_sun_amount = p_sun_amount; +} + +void RasterizerSceneGLES3::environment_set_fog_depth(RID p_env, bool p_enable, float p_depth_begin, float p_depth_curve, bool p_transmit, float p_transmit_curve) { + + Environment *env = environment_owner.getornull(p_env); + ERR_FAIL_COND(!env); + + env->fog_depth_enabled = p_enable; + env->fog_depth_begin = p_depth_begin; + env->fog_depth_curve = p_depth_curve; + env->fog_transmit_enabled = p_transmit; + env->fog_transmit_curve = p_transmit_curve; +} + +void RasterizerSceneGLES3::environment_set_fog_height(RID p_env, bool p_enable, float p_min_height, float p_max_height, float p_height_curve) { + + Environment *env = environment_owner.getornull(p_env); + ERR_FAIL_COND(!env); + + env->fog_height_enabled = p_enable; + env->fog_height_min = p_min_height; + env->fog_height_max = p_max_height; + env->fog_height_curve = p_height_curve; } RID RasterizerSceneGLES3::light_instance_create(RID p_light) { @@ -1697,7 +1740,7 @@ void RasterizerSceneGLES3::_setup_light(RenderList::Element *e, const Transform GIProbeInstance *gipi = gi_probe_instance_owner.getptr(ridp[0]); - glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 10); + glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 9); glBindTexture(GL_TEXTURE_3D, gipi->tex_cache); state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_XFORM1, gipi->transform_to_data * p_view_transform); state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_BOUNDS1, gipi->bounds); @@ -1709,7 +1752,7 @@ void RasterizerSceneGLES3::_setup_light(RenderList::Element *e, const Transform GIProbeInstance *gipi2 = gi_probe_instance_owner.getptr(ridp[1]); - glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 11); + glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 10); glBindTexture(GL_TEXTURE_3D, gipi2->tex_cache); state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_XFORM2, gipi2->transform_to_data * p_view_transform); state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_BOUNDS2, gipi2->bounds); @@ -1751,8 +1794,6 @@ void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements, int p_ if (!p_shadow && !p_directional_add) { glBindBufferBase(GL_UNIFORM_BUFFER, 2, state.env_radiance_ubo); //bind environment radiance info - glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1); - glBindTexture(GL_TEXTURE_2D, state.brdf_texture); if (p_base_env) { glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 2); @@ -1934,7 +1975,7 @@ void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements, int p_ if (skeleton.is_valid()) { RasterizerStorageGLES3::Skeleton *sk = storage->skeleton_owner.getornull(skeleton); - glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 6); + glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1); glBindTexture(GL_TEXTURE_2D, sk->texture); } } @@ -2023,7 +2064,7 @@ void RasterizerSceneGLES3::_add_geometry(RasterizerStorageGLES3::Geometry *p_geo ERR_FAIL_COND(!m); - bool has_base_alpha = (m->shader->spatial.uses_alpha); + bool has_base_alpha = (m->shader->spatial.uses_alpha || m->shader->spatial.uses_screen_texture); bool has_blend_alpha = m->shader->spatial.blend_mode != RasterizerStorageGLES3::Shader::Spatial::BLEND_MODE_MIX || m->shader->spatial.ontop; bool has_alpha = has_base_alpha || has_blend_alpha; bool shadow = false; @@ -2038,6 +2079,10 @@ void RasterizerSceneGLES3::_add_geometry(RasterizerStorageGLES3::Geometry *p_geo state.used_sss = true; } + if (m->shader->spatial.uses_screen_texture) { + state.used_screen_texture = true; + } + if (p_shadow) { if (has_blend_alpha || (has_base_alpha && m->shader->spatial.depth_draw_mode != RasterizerStorageGLES3::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS)) @@ -2213,6 +2258,7 @@ void RasterizerSceneGLES3::_setup_environment(Environment *env, const CameraMatr state.ubo_data.time[i] = storage->frame.time[i]; } + state.ubo_data.z_far = p_cam_projection.get_z_far(); //bg and ambient if (env) { state.ubo_data.bg_energy = env->bg_energy; @@ -2244,6 +2290,30 @@ void RasterizerSceneGLES3::_setup_environment(Environment *env, const CameraMatr state.env_radiance_data.ambient_contribution = env->ambient_sky_contribution; state.ubo_data.ambient_occlusion_affect_light = env->ssao_light_affect; + + //fog + + Color linear_fog = env->fog_color.to_linear(); + state.ubo_data.fog_color_enabled[0] = linear_fog.r; + state.ubo_data.fog_color_enabled[1] = linear_fog.g; + state.ubo_data.fog_color_enabled[2] = linear_fog.b; + state.ubo_data.fog_color_enabled[3] = env->fog_enabled ? 1.0 : 0.0; + + Color linear_sun = env->fog_sun_color.to_linear(); + state.ubo_data.fog_sun_color_amount[0] = linear_sun.r; + state.ubo_data.fog_sun_color_amount[1] = linear_sun.g; + state.ubo_data.fog_sun_color_amount[2] = linear_sun.b; + state.ubo_data.fog_sun_color_amount[3] = env->fog_sun_amount; + state.ubo_data.fog_depth_enabled = env->fog_depth_enabled; + state.ubo_data.fog_depth_begin = env->fog_depth_begin; + state.ubo_data.fog_depth_curve = env->fog_depth_curve; + state.ubo_data.fog_transmit_enabled = env->fog_transmit_enabled; + state.ubo_data.fog_transmit_curve = env->fog_transmit_curve; + state.ubo_data.fog_height_enabled = env->fog_height_enabled; + state.ubo_data.fog_height_min = env->fog_height_min; + state.ubo_data.fog_height_max = env->fog_height_max; + state.ubo_data.fog_height_curve = env->fog_height_curve; + } else { state.ubo_data.bg_energy = 1.0; state.ubo_data.ambient_energy = 1.0; @@ -2261,6 +2331,8 @@ void RasterizerSceneGLES3::_setup_environment(Environment *env, const CameraMatr state.env_radiance_data.ambient_contribution = 0; state.ubo_data.ambient_occlusion_affect_light = 0; + + state.ubo_data.fog_color_enabled[3] = 0.0; } { @@ -2343,8 +2415,8 @@ void RasterizerSceneGLES3::_setup_directional_light(int p_index, const Transform for (int j = 0; j < shadow_count; j++) { - uint32_t x = li->directional_rect.pos.x; - uint32_t y = li->directional_rect.pos.y; + uint32_t x = li->directional_rect.position.x; + uint32_t y = li->directional_rect.position.y; uint32_t width = li->directional_rect.size.x; uint32_t height = li->directional_rect.size.y; @@ -2389,8 +2461,8 @@ void RasterizerSceneGLES3::_setup_directional_light(int p_index, const Transform store_camera(shadow_mtx, &ubo_data.shadow_matrix1[16 * j]); - ubo_data.light_clamp[0] = atlas_rect.pos.x; - ubo_data.light_clamp[1] = atlas_rect.pos.y; + ubo_data.light_clamp[0] = atlas_rect.position.x; + ubo_data.light_clamp[1] = atlas_rect.position.y; ubo_data.light_clamp[2] = atlas_rect.size.x; ubo_data.light_clamp[3] = atlas_rect.size.y; } @@ -2579,8 +2651,8 @@ void RasterizerSceneGLES3::_setup_lights(RID *p_light_cull_result, int p_light_c Rect2 rect(float(x) / atlas_size, float(y) / atlas_size, float(width) / atlas_size, float(height) / atlas_size); ubo_data.light_params[3] = 1.0; //means it has shadow - ubo_data.light_clamp[0] = rect.pos.x; - ubo_data.light_clamp[1] = rect.pos.y; + ubo_data.light_clamp[0] = rect.position.x; + ubo_data.light_clamp[1] = rect.position.y; ubo_data.light_clamp[2] = rect.size.x; ubo_data.light_clamp[3] = rect.size.y; @@ -2797,6 +2869,7 @@ void RasterizerSceneGLES3::_fill_render_list(InstanceBase **p_cull_result, int p current_geometry_index = 0; current_material_index = 0; state.used_sss = false; + state.used_screen_texture = false; //fill list @@ -2874,6 +2947,39 @@ void RasterizerSceneGLES3::_fill_render_list(InstanceBase **p_cull_result, int p } } +void RasterizerSceneGLES3::_blur_effect_buffer() { + + //blur diffuse into effect mipmaps using separatable convolution + //storage->shaders.copy.set_conditional(CopyShaderGLES3::GAUSSIAN_HORIZONTAL,true); + for (int i = 0; i < storage->frame.current_rt->effects.mip_maps[1].sizes.size(); i++) { + + int vp_w = storage->frame.current_rt->effects.mip_maps[1].sizes[i].width; + int vp_h = storage->frame.current_rt->effects.mip_maps[1].sizes[i].height; + glViewport(0, 0, vp_w, vp_h); + //horizontal pass + state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_HORIZONTAL, true); + state.effect_blur_shader.bind(); + state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h)); + state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::LOD, float(i)); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color); //previous level, since mipmaps[0] starts one level bigger + glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[1].sizes[i].fbo); + _copy_screen(); + state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_HORIZONTAL, false); + + //vertical pass + state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_VERTICAL, true); + state.effect_blur_shader.bind(); + state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h)); + state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::LOD, float(i)); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[1].color); + glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[i + 1].fbo); //next level, since mipmaps[0] starts one level bigger + _copy_screen(); + state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_VERTICAL, false); + } +} + void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_cam_projection) { glDepthMask(GL_FALSE); @@ -3028,8 +3134,8 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_ //copy normal and roughness to effect buffer glBindFramebuffer(GL_READ_FRAMEBUFFER, storage->frame.current_rt->buffers.fbo); glReadBuffer(GL_COLOR_ATTACHMENT3); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, storage->frame.current_rt->buffers.effect_fbo); - glBlitFramebuffer(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, 0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, GL_COLOR_BUFFER_BIT, GL_NEAREST); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, storage->frame.current_rt->effects.ssao.blur_fbo[0]); + glBlitFramebuffer(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, 0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, GL_COLOR_BUFFER_BIT, GL_LINEAR); state.sss_shader.set_conditional(SubsurfScatteringShaderGLES3::USE_11_SAMPLES, subsurface_scatter_quality == SSS_QUALITY_LOW); state.sss_shader.set_conditional(SubsurfScatteringShaderGLES3::USE_17_SAMPLES, subsurface_scatter_quality == SSS_QUALITY_MEDIUM); @@ -3045,8 +3151,11 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_ glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //disable filter (fixes bugs on AMD) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->buffers.effect); + glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.ssao.blur_red[0]); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->depth); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE); @@ -3056,10 +3165,15 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_ _copy_screen(); glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->color); state.sss_shader.set_uniform(SubsurfScatteringShaderGLES3::DIR, Vector2(0, 1)); glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo); // copy to base level _copy_screen(); + + glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color); //restore filter + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); } if (env->ssr_enabled) { @@ -3072,33 +3186,7 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_ //blur diffuse into effect mipmaps using separatable convolution //storage->shaders.copy.set_conditional(CopyShaderGLES3::GAUSSIAN_HORIZONTAL,true); - for (int i = 0; i < storage->frame.current_rt->effects.mip_maps[1].sizes.size(); i++) { - - int vp_w = storage->frame.current_rt->effects.mip_maps[1].sizes[i].width; - int vp_h = storage->frame.current_rt->effects.mip_maps[1].sizes[i].height; - glViewport(0, 0, vp_w, vp_h); - //horizontal pass - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_HORIZONTAL, true); - state.effect_blur_shader.bind(); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h)); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::LOD, float(i)); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color); //previous level, since mipmaps[0] starts one level bigger - glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[1].sizes[i].fbo); - _copy_screen(); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_HORIZONTAL, false); - - //vertical pass - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_VERTICAL, true); - state.effect_blur_shader.bind(); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::PIXEL_SIZE, Vector2(1.0 / vp_w, 1.0 / vp_h)); - state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::LOD, float(i)); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[1].color); - glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[i + 1].fbo); //next level, since mipmaps[0] starts one level bigger - _copy_screen(); - state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::GAUSSIAN_VERTICAL, false); - } + _blur_effect_buffer(); //perform SSR @@ -3151,6 +3239,8 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_ //copy reflection over diffuse, resolving SSR if needed state.resolve_shader.set_conditional(ResolveShaderGLES3::USE_SSR, env->ssr_enabled); state.resolve_shader.bind(); + state.resolve_shader.set_uniform(ResolveShaderGLES3::PIXEL_SIZE, Vector2(1.0 / storage->frame.current_rt->width, 1.0 / storage->frame.current_rt->height)); + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->color); if (env->ssr_enabled) { @@ -3167,6 +3257,13 @@ void RasterizerSceneGLES3::_render_mrts(Environment *env, const CameraMatrix &p_ glDisable(GL_BLEND); //end additive + if (state.used_screen_texture) { + _blur_effect_buffer(); + //restored framebuffer + glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo); + glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height); + } + state.effect_blur_shader.set_conditional(EffectBlurShaderGLES3::SIMPLE_COPY, true); state.effect_blur_shader.bind(); state.effect_blur_shader.set_uniform(EffectBlurShaderGLES3::LOD, float(0)); @@ -3584,6 +3681,17 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color); } + if (env->adjustments_enabled) { + + state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_BCS, true); + RasterizerStorageGLES3::Texture *tex = storage->texture_owner.getornull(env->color_correction); + if (tex) { + state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_COLOR_CORRECTION, true); + glActiveTexture(GL_TEXTURE3); + glBindTexture(tex->target, tex->tex_id); + } + } + state.tonemap_shader.bind(); state.tonemap_shader.set_uniform(TonemapShaderGLES3::EXPOSURE, env->tone_mapper_exposure); @@ -3606,6 +3714,11 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p state.tonemap_shader.set_uniform(TonemapShaderGLES3::AUTO_EXPOSURE_GREY, env->auto_exposure_grey); } + if (env->adjustments_enabled) { + + state.tonemap_shader.set_uniform(TonemapShaderGLES3::BCS, Vector3(env->adjustments_brightness, env->adjustments_contrast, env->adjustments_saturation)); + } + _copy_screen(); //turn off everything used @@ -3624,6 +3737,8 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_SCREEN, false); state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_SOFTLIGHT, false); state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_GLOW_FILTER_BICUBIC, false); + state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_BCS, false); + state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_COLOR_CORRECTION, false); } void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass) { @@ -3638,7 +3753,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const ReflectionAtlas *reflection_atlas = reflection_atlas_owner.getornull(p_reflection_atlas); if (shadow_atlas && shadow_atlas->size) { - glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 3); + glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 5); glBindTexture(GL_TEXTURE_2D, shadow_atlas->depth); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LESS); @@ -3647,7 +3762,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const } if (reflection_atlas && reflection_atlas->size) { - glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 5); + glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 3); glBindTexture(GL_TEXTURE_2D, reflection_atlas->color); } @@ -3711,7 +3826,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); //bind depth for read - glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 9); + glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 8); glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->depth); } @@ -3764,7 +3879,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const } else { - use_mrt = state.used_sss || (env && (env->ssao_enabled || env->ssr_enabled)); //only enable MRT rendering if any of these is enabled + use_mrt = env && (state.used_screen_texture || state.used_sss || env->ssao_enabled || env->ssr_enabled); //only enable MRT rendering if any of these is enabled glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height); @@ -3900,6 +4015,11 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const _render_mrts(env, p_cam_projection); } + if (state.used_screen_texture) { + glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 7); + glBindTexture(GL_TEXTURE_2D, storage->frame.current_rt->effects.mip_maps[0].color); + } + glEnable(GL_BLEND); glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); @@ -4157,15 +4277,15 @@ void RasterizerSceneGLES3::render_shadow(RID p_light, RID p_shadow_atlas, int p_ } else if (directional_shadow.light_count == 2) { light_instance->directional_rect = Rect2(0, 0, directional_shadow.size, directional_shadow.size / 2); if (light_instance->light_directional_index == 1) { - light_instance->directional_rect.pos.x += light_instance->directional_rect.size.x; + light_instance->directional_rect.position.x += light_instance->directional_rect.size.x; } } else { //3 and 4 light_instance->directional_rect = Rect2(0, 0, directional_shadow.size / 2, directional_shadow.size / 2); if (light_instance->light_directional_index & 1) { - light_instance->directional_rect.pos.x += light_instance->directional_rect.size.x; + light_instance->directional_rect.position.x += light_instance->directional_rect.size.x; } if (light_instance->light_directional_index / 2) { - light_instance->directional_rect.pos.y += light_instance->directional_rect.size.y; + light_instance->directional_rect.position.y += light_instance->directional_rect.size.y; } } } @@ -4173,8 +4293,8 @@ void RasterizerSceneGLES3::render_shadow(RID p_light, RID p_shadow_atlas, int p_ light_projection = light_instance->shadow_transform[p_pass].camera; light_transform = light_instance->shadow_transform[p_pass].transform; - x = light_instance->directional_rect.pos.x; - y = light_instance->directional_rect.pos.y; + x = light_instance->directional_rect.position.x; + y = light_instance->directional_rect.position.y; width = light_instance->directional_rect.size.x; height = light_instance->directional_rect.size.y; diff --git a/drivers/gles3/rasterizer_scene_gles3.h b/drivers/gles3/rasterizer_scene_gles3.h index 322343bc89..55d314a800 100644 --- a/drivers/gles3/rasterizer_scene_gles3.h +++ b/drivers/gles3/rasterizer_scene_gles3.h @@ -111,6 +111,9 @@ public: float time[4]; float ambient_light_color[4]; float bg_color[4]; + float fog_color_enabled[4]; + float fog_sun_color_amount[4]; + float ambient_energy; float bg_energy; float shadow_z_offset; @@ -120,10 +123,22 @@ public: float screen_pixel_size[2]; float shadow_atlas_pixel_size[2]; float shadow_directional_pixel_size[2]; + + float z_far; float reflection_multiplier; float subsurface_scatter_width; float ambient_occlusion_affect_light; + bool fog_depth_enabled; + float fog_depth_begin; + float fog_depth_curve; + bool fog_transmit_enabled; + float fog_transmit_curve; + bool fog_height_enabled; + float fog_height_min; + float fog_height_max; + float fog_height_curve; + } ubo_data; GLuint scene_ubo; @@ -170,6 +185,7 @@ public: bool cull_front; bool used_sss; + bool used_screen_texture; } state; @@ -389,6 +405,27 @@ public: float dof_blur_near_amount; VS::EnvironmentDOFBlurQuality dof_blur_near_quality; + bool adjustments_enabled; + float adjustments_brightness; + float adjustments_contrast; + float adjustments_saturation; + RID color_correction; + + bool fog_enabled; + Color fog_color; + Color fog_sun_color; + float fog_sun_amount; + + bool fog_depth_enabled; + float fog_depth_begin; + float fog_depth_curve; + bool fog_transmit_enabled; + float fog_transmit_curve; + bool fog_height_enabled; + float fog_height_min; + float fog_height_max; + float fog_height_curve; + Environment() { bg_mode = VS::ENV_BG_CLEAR_COLOR; sky_scale = 1.0; @@ -445,6 +482,29 @@ public: dof_blur_near_transition = 1; dof_blur_near_amount = 0.1; dof_blur_near_quality = VS::ENV_DOF_BLUR_QUALITY_MEDIUM; + + adjustments_enabled = false; + adjustments_brightness = 1.0; + adjustments_contrast = 1.0; + adjustments_saturation = 1.0; + + fog_enabled = false; + fog_color = Color(0.5, 0.5, 0.5); + fog_sun_color = Color(0.8, 0.8, 0.0); + fog_sun_amount = 0; + + fog_depth_enabled = true; + + fog_depth_begin = 10; + fog_depth_curve = 1; + + fog_transmit_enabled = true; + fog_transmit_curve = 1; + + fog_height_enabled = false; + fog_height_min = 0; + fog_height_max = 100; + fog_height_curve = 1; } }; @@ -472,6 +532,10 @@ public: virtual void environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, RID p_ramp); + virtual void environment_set_fog(RID p_env, bool p_enable, const Color &p_color, const Color &p_sun_color, float p_sun_amount); + virtual void environment_set_fog_depth(RID p_env, bool p_enable, float p_depth_begin, float p_depth_curve, bool p_transmit, float p_transmit_curve); + virtual void environment_set_fog_height(RID p_env, bool p_enable, float p_min_height, float p_max_height, float p_height_curve); + /* LIGHT INSTANCE */ struct LightDataUBO { @@ -711,6 +775,7 @@ public: void _fill_render_list(InstanceBase **p_cull_result, int p_cull_count, bool p_shadow); + void _blur_effect_buffer(); void _render_mrts(Environment *env, const CameraMatrix &p_cam_projection); void _post_process(Environment *env, const CameraMatrix &p_cam_projection); diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index 8baa1c6043..a503b6daa7 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -283,36 +283,6 @@ Ref<Image> RasterizerStorageGLES3::_get_gl_image_and_format(const Ref<Image> &p_ } } break; - case Image::FORMAT_LATC_L: { - - if (config.latc_supported) { - - r_gl_internal_format = _EXT_COMPRESSED_LUMINANCE_LATC1_EXT; - r_gl_format = GL_RGBA; - r_gl_type = GL_UNSIGNED_BYTE; - r_compressed = true; - srgb = true; - - } else { - - need_decompress = true; - } - - } break; - case Image::FORMAT_LATC_LA: { - - if (config.latc_supported) { - - r_gl_internal_format = _EXT_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT; - r_gl_format = GL_RGBA; - r_gl_type = GL_UNSIGNED_BYTE; - r_compressed = true; - } else { - - need_decompress = true; - } - - } break; case Image::FORMAT_RGTC_R: { if (config.rgtc_supported) { @@ -321,7 +291,6 @@ Ref<Image> RasterizerStorageGLES3::_get_gl_image_and_format(const Ref<Image> &p_ r_gl_format = GL_RGBA; r_gl_type = GL_UNSIGNED_BYTE; r_compressed = true; - srgb = true; } else { @@ -1494,6 +1463,7 @@ void RasterizerStorageGLES3::_update_shader(Shader *p_shader) const { p_shader->spatial.unshaded = false; p_shader->spatial.ontop = false; p_shader->spatial.uses_sss = false; + p_shader->spatial.uses_screen_texture = false; p_shader->spatial.uses_vertex = false; p_shader->spatial.writes_modelview_or_projection = false; @@ -1519,6 +1489,7 @@ void RasterizerStorageGLES3::_update_shader(Shader *p_shader) const { shaders.actions_scene.usage_flag_pointers["SSS_STRENGTH"] = &p_shader->spatial.uses_sss; shaders.actions_scene.usage_flag_pointers["DISCARD"] = &p_shader->spatial.uses_discard; + shaders.actions_scene.usage_flag_pointers["SCREEN_TEXTURE"] = &p_shader->spatial.uses_screen_texture; shaders.actions_scene.write_flag_pointers["MODELVIEW_MATRIX"] = &p_shader->spatial.writes_modelview_or_projection; shaders.actions_scene.write_flag_pointers["PROJECTION_MATRIX"] = &p_shader->spatial.writes_modelview_or_projection; @@ -1992,8 +1963,8 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy } else if (value.get_type() == Variant::RECT2) { Rect2 v = value; - gui[0] = v.pos.x; - gui[1] = v.pos.y; + gui[0] = v.position.x; + gui[1] = v.position.y; gui[2] = v.size.x; gui[3] = v.size.y; } else if (value.get_type() == Variant::QUAT) { @@ -5483,7 +5454,7 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) { glDeleteRenderbuffers(1, &rt->buffers.diffuse); glDeleteRenderbuffers(1, &rt->buffers.specular); glDeleteRenderbuffers(1, &rt->buffers.normal_rough); - glDeleteRenderbuffers(1, &rt->buffers.motion_sss); + glDeleteRenderbuffers(1, &rt->buffers.sss); glDeleteFramebuffers(1, &rt->buffers.effect_fbo); glDeleteTextures(1, &rt->buffers.effect); @@ -5672,15 +5643,15 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) { glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_RENDERBUFFER, rt->buffers.normal_rough); - glGenRenderbuffers(1, &rt->buffers.motion_sss); - glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.motion_sss); + glGenRenderbuffers(1, &rt->buffers.sss); + glBindRenderbuffer(GL_RENDERBUFFER, rt->buffers.sss); if (msaa == 0) - glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, rt->width, rt->height); + glRenderbufferStorage(GL_RENDERBUFFER, GL_R8, rt->width, rt->height); else - glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_RGBA8, rt->width, rt->height); + glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_R8, rt->width, rt->height); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_RENDERBUFFER, rt->buffers.motion_sss); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_RENDERBUFFER, rt->buffers.sss); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo); @@ -5700,8 +5671,8 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) { glGenTextures(1, &rt->buffers.effect); glBindTexture(GL_TEXTURE_2D, rt->buffers.effect); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, rt->width, rt->height, 0, - GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, color_internal_format, rt->width, rt->height, 0, + color_format, color_type, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index 7e107cfdf4..c8edeaefbf 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -411,6 +411,7 @@ public: bool uses_vertex; bool uses_discard; bool uses_sss; + bool uses_screen_texture; bool writes_modelview_or_projection; } spatial; @@ -1128,7 +1129,7 @@ public: GLuint specular; GLuint diffuse; GLuint normal_rough; - GLuint motion_sss; + GLuint sss; GLuint effect_fbo; GLuint effect; diff --git a/drivers/gles3/shader_compiler_gles3.cpp b/drivers/gles3/shader_compiler_gles3.cpp index 23bcb79b46..b1f7b4c9bd 100644 --- a/drivers/gles3/shader_compiler_gles3.cpp +++ b/drivers/gles3/shader_compiler_gles3.cpp @@ -574,6 +574,7 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener code += _dump_node_code(onode->arguments[2], p_level, r_gen_code, p_actions, p_default_actions); } break; + default: { code = "(" + _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions) + _opstr(onode->op) + _dump_node_code(onode->arguments[1], p_level, r_gen_code, p_actions, p_default_actions) + ")"; @@ -593,6 +594,10 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener code += _mktab(p_level) + "else\n"; code += _dump_node_code(cfnode->blocks[1], p_level + 1, r_gen_code, p_actions, p_default_actions); } + } else if (cfnode->flow_op == SL::FLOW_OP_WHILE) { + + code += _mktab(p_level) + "while (" + _dump_node_code(cfnode->expressions[0], p_level, r_gen_code, p_actions, p_default_actions) + ")\n"; + code += _dump_node_code(cfnode->blocks[0], p_level + 1, r_gen_code, p_actions, p_default_actions); } else if (cfnode->flow_op == SL::FLOW_OP_RETURN) { @@ -723,6 +728,7 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() { actions[VS::SHADER_SPATIAL].renames["NORMALMAP_DEPTH"] = "normaldepth"; actions[VS::SHADER_SPATIAL].renames["ALBEDO"] = "albedo"; actions[VS::SHADER_SPATIAL].renames["ALPHA"] = "alpha"; + actions[VS::SHADER_SPATIAL].renames["METALLIC"] = "metallic"; actions[VS::SHADER_SPATIAL].renames["SPECULAR"] = "specular"; actions[VS::SHADER_SPATIAL].renames["ROUGHNESS"] = "roughness"; actions[VS::SHADER_SPATIAL].renames["RIM"] = "rim"; @@ -739,6 +745,10 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() { //actions[VS::SHADER_SPATIAL].renames["SCREEN_UV"]=ShaderLanguage::TYPE_VEC2; actions[VS::SHADER_SPATIAL].renames["POINT_COORD"] = "gl_PointCoord"; actions[VS::SHADER_SPATIAL].renames["INSTANCE_CUSTOM"] = "instance_custom"; + actions[VS::SHADER_SPATIAL].renames["SCREEN_UV"] = "screen_uv"; + actions[VS::SHADER_SPATIAL].renames["SCREEN_TEXTURE"] = "screen_texture"; + actions[VS::SHADER_SPATIAL].renames["DEPTH_TEXTURE"] = "depth_buffer"; + actions[VS::SHADER_SPATIAL].renames["SIDE"] = "side"; actions[VS::SHADER_SPATIAL].usage_defines["TANGENT"] = "#define ENABLE_TANGENT_INTERP\n"; actions[VS::SHADER_SPATIAL].usage_defines["BINORMAL"] = "@TANGENT"; @@ -756,12 +766,18 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() { actions[VS::SHADER_SPATIAL].usage_defines["COLOR"] = "#define ENABLE_COLOR_INTERP\n"; actions[VS::SHADER_SPATIAL].usage_defines["INSTANCE_CUSTOM"] = "#define ENABLE_INSTANCE_CUSTOM\n"; - actions[VS::SHADER_SPATIAL].usage_defines["SSS_STRENGTH"] = "#define ENABLE_SSS_MOTION\n"; + actions[VS::SHADER_SPATIAL].usage_defines["SSS_STRENGTH"] = "#define ENABLE_SSS\n"; + actions[VS::SHADER_SPATIAL].usage_defines["SCREEN_TEXTURE"] = "#define SCREEN_TEXTURE_USED\n"; + actions[VS::SHADER_SPATIAL].usage_defines["SCREEN_UV"] = "#define SCREEN_UV_USED\n"; actions[VS::SHADER_SPATIAL].renames["SSS_STRENGTH"] = "sss_strength"; actions[VS::SHADER_SPATIAL].render_mode_defines["skip_default_transform"] = "#define SKIP_TRANSFORM_USED\n"; + actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_burley"] = "#define DIFFUSE_BURLEY\n"; + actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_oren_nayar"] = "#define DIFFUSE_OREN_NAYAR\n"; + actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_half_lambert"] = "#define DIFFUSE_HALF_LAMBERT\n"; + /* PARTICLES SHADER */ actions[VS::SHADER_PARTICLES].renames["COLOR"] = "out_color"; diff --git a/drivers/gles3/shader_gles3.cpp b/drivers/gles3/shader_gles3.cpp index bebc006032..8c6d15c3b7 100644 --- a/drivers/gles3/shader_gles3.cpp +++ b/drivers/gles3/shader_gles3.cpp @@ -100,14 +100,14 @@ void ShaderGLES3::bind_uniforms() { }; uniforms_dirty = false; -}; +} GLint ShaderGLES3::get_uniform_location(int p_idx) const { ERR_FAIL_COND_V(!version, -1); return version->uniform_location[p_idx]; -}; +} bool ShaderGLES3::bind() { @@ -399,14 +399,14 @@ ShaderGLES3::Version *ShaderGLES3::get_current_version() { strings.push_back(fragment_code2.get_data()); if (cc) { - code_string = cc->fragment.ascii(); + code_string = cc->light.ascii(); strings.push_back(code_string.get_data()); } strings.push_back(fragment_code3.get_data()); if (cc) { - code_string2 = cc->light.ascii(); + code_string2 = cc->fragment.ascii(); strings.push_back(code_string2.get_data()); } @@ -666,7 +666,7 @@ void ShaderGLES3::setup(const char **p_conditional_defines, int p_conditional_co //print_line("CODE1:\n"+String(fragment_code1.get_data())); String code2 = code.substr(cpos + material_tag.length(), code.length()); - cpos = code2.find(code_tag); + cpos = code2.find(light_code_tag); if (cpos == -1) { fragment_code2 = code2.ascii(); @@ -675,16 +675,16 @@ void ShaderGLES3::setup(const char **p_conditional_defines, int p_conditional_co fragment_code2 = code2.substr(0, cpos).ascii(); //print_line("CODE2:\n"+String(fragment_code2.get_data())); - String code3 = code2.substr(cpos + code_tag.length(), code2.length()); + String code3 = code2.substr(cpos + light_code_tag.length(), code2.length()); - cpos = code3.find(light_code_tag); + cpos = code3.find(code_tag); if (cpos == -1) { fragment_code3 = code3.ascii(); } else { fragment_code3 = code3.substr(0, cpos).ascii(); //print_line("CODE3:\n"+String(fragment_code3.get_data())); - fragment_code4 = code3.substr(cpos + light_code_tag.length(), code3.length()).ascii(); + fragment_code4 = code3.substr(cpos + code_tag.length(), code3.length()).ascii(); //print_line("CODE4:\n"+String(fragment_code4.get_data())); } } diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl index e6c72da8f1..017009015e 100644 --- a/drivers/gles3/shaders/canvas.glsl +++ b/drivers/gles3/shaders/canvas.glsl @@ -211,6 +211,18 @@ MATERIAL_UNIFORMS #endif + +void light_compute(inout vec3 light,vec3 light_vec,float light_height,vec4 light_color,vec2 light_uv,vec4 shadow,vec3 normal,vec2 uv,vec2 screen_uv,vec4 color) { + +#if defined(USE_LIGHT_SHADER_CODE) + +LIGHT_SHADER_CODE + +#endif + +} + + void main() { vec4 color = color_interp; @@ -285,11 +297,7 @@ FRAGMENT_SHADER_CODE #if defined(USE_LIGHT_SHADER_CODE) //light is written by the light shader - { - vec4 light_out=light*color; -LIGHT_SHADER_CODE - color=light_out; - } + light_compute(light,light_vec,light_height,light_color,light_uv,shadow,normal,uv,screen_uv,color); #else diff --git a/drivers/gles3/shaders/copy.glsl b/drivers/gles3/shaders/copy.glsl index c8985e6902..621ae83162 100644 --- a/drivers/gles3/shaders/copy.glsl +++ b/drivers/gles3/shaders/copy.glsl @@ -84,8 +84,24 @@ uniform vec2 pixel_size; in vec2 uv2_interp; + +#ifdef USE_BCS + +uniform vec3 bcs; + +#endif + +#ifdef USE_COLOR_CORRECTION + +uniform sampler2D color_correction; //texunit:1 + +#endif + layout(location = 0) out vec4 frag_color; + + + void main() { //vec4 color = color_interp; @@ -135,6 +151,21 @@ void main() { color+=texture( source, uv_interp+vec2( 0.0,-2.0)*pixel_size )*0.06136; #endif +#ifdef USE_BCS + + color.rgb = mix(vec3(0.0),color.rgb,bcs.x); + color.rgb = mix(vec3(0.5),color.rgb,bcs.y); + color.rgb = mix(vec3(dot(vec3(1.0),color.rgb)*0.33333),color.rgb,bcs.z); + +#endif + +#ifdef USE_COLOR_CORRECTION + + color.r = texture(color_correction,vec2(color.r,0.0)).r; + color.g = texture(color_correction,vec2(color.g,0.0)).g; + color.b = texture(color_correction,vec2(color.b,0.0)).b; +#endif + #ifdef USE_MULTIPLIER color.rgb*=multiplier; #endif diff --git a/drivers/gles3/shaders/particles.glsl b/drivers/gles3/shaders/particles.glsl index fa12dd7408..5d8a532f87 100644 --- a/drivers/gles3/shaders/particles.glsl +++ b/drivers/gles3/shaders/particles.glsl @@ -244,6 +244,10 @@ MATERIAL_UNIFORMS void main() { { +LIGHT_SHADER_CODE + } + + { FRAGMENT_SHADER_CODE } } diff --git a/drivers/gles3/shaders/resolve.glsl b/drivers/gles3/shaders/resolve.glsl index 6acc712299..181a3c99ec 100644 --- a/drivers/gles3/shaders/resolve.glsl +++ b/drivers/gles3/shaders/resolve.glsl @@ -20,7 +20,7 @@ in vec2 uv_interp; uniform sampler2D source_specular; //texunit:0 uniform sampler2D source_ssr; //texunit:1 -uniform float stuff; +uniform vec2 pixel_size; in vec2 uv2_interp; diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index 7750fd6293..8965f475d7 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -67,6 +67,10 @@ layout(std140) uniform SceneData { //ubo:0 highp vec4 ambient_light_color; highp vec4 bg_color; + + vec4 fog_color_enabled; + vec4 fog_sun_color_amount; + float ambient_energy; float bg_energy; @@ -79,10 +83,21 @@ layout(std140) uniform SceneData { //ubo:0 vec2 shadow_atlas_pixel_size; vec2 directional_shadow_pixel_size; + float z_far; float reflection_multiplier; float subsurface_scatter_width; float ambient_occlusion_affect_light; + bool fog_depth_enabled; + float fog_depth_begin; + float fog_depth_curve; + bool fog_transmit_enabled; + float fog_transmit_curve; + bool fog_height_enabled; + float fog_height_min; + float fog_height_max; + float fog_height_curve; + }; uniform highp mat4 world_transform; @@ -153,7 +168,7 @@ out highp float dp_clip; #define SKELETON_TEXTURE_WIDTH 256 #ifdef USE_SKELETON -uniform highp sampler2D skeleton_texture; //texunit:-6 +uniform highp sampler2D skeleton_texture; //texunit:-1 #endif out highp vec4 position_interp; @@ -338,7 +353,20 @@ VERTEX_SHADER_CODE [fragment] +/* texture unit usage, N is max_texture_unity-N +1-skeleton +2-radiance +3-reflection_atlas +4-directional_shadow +5-shadow_atlas +6-decal_atlas +7-screen +8-depth +9-probe1 +10-probe2 + +*/ #define M_PI 3.14159265359 @@ -370,7 +398,6 @@ in vec3 normal_interp; //used on forward mainly uniform bool no_ambient_light; -uniform sampler2D brdf_texture; //texunit:-1 #ifdef USE_RADIANCE_MAP @@ -413,6 +440,8 @@ layout(std140) uniform SceneData { highp vec4 ambient_light_color; highp vec4 bg_color; + vec4 fog_color_enabled; + vec4 fog_sun_color_amount; float ambient_energy; float bg_energy; @@ -426,10 +455,20 @@ layout(std140) uniform SceneData { vec2 shadow_atlas_pixel_size; vec2 directional_shadow_pixel_size; + float z_far; float reflection_multiplier; float subsurface_scatter_width; float ambient_occlusion_affect_light; + bool fog_depth_enabled; + float fog_depth_begin; + float fog_depth_curve; + bool fog_transmit_enabled; + float fog_transmit_curve; + bool fog_height_enabled; + float fog_height_min; + float fog_height_max; + float fog_height_curve; }; //directional light data @@ -482,7 +521,7 @@ layout(std140) uniform SpotLightData { //ubo:5 }; -uniform highp sampler2DShadow shadow_atlas; //texunit:-3 +uniform highp sampler2DShadow shadow_atlas; //texunit:-5 struct ReflectionData { @@ -500,7 +539,7 @@ layout(std140) uniform ReflectionProbeData { //ubo:6 ReflectionData reflections[MAX_REFLECTION_DATA_STRUCTS]; }; -uniform mediump sampler2D reflection_atlas; //texunit:-5 +uniform mediump sampler2D reflection_atlas; //texunit:-3 #ifdef USE_FORWARD_LIGHTING @@ -517,14 +556,19 @@ uniform int reflection_count; #endif +#if defined(SCREEN_TEXTURE_USED) + +uniform highp sampler2D screen_texture; //texunit:-7 + +#endif #ifdef USE_MULTIPLE_RENDER_TARGETS layout(location=0) out vec4 diffuse_buffer; layout(location=1) out vec4 specular_buffer; layout(location=2) out vec4 normal_mr_buffer; -#if defined (ENABLE_SSS_MOTION) -layout(location=3) out vec4 motion_ssr_buffer; +#if defined(ENABLE_SSS) +layout(location=3) out float sss_buffer; #endif #else @@ -534,7 +578,7 @@ layout(location=0) out vec4 frag_color; #endif in highp vec4 position_interp; -uniform highp sampler2D depth_buffer; //texunit:-9 +uniform highp sampler2D depth_buffer; //texunit:-8 float contact_shadow_compute(vec3 pos, vec3 dir, float max_distance) { @@ -596,7 +640,6 @@ float contact_shadow_compute(vec3 pos, vec3 dir, float max_distance) { return 1.0; } - // GGX Specular // Source: http://www.filmicworlds.com/images/ggx-opt/optimized-ggx.hlsl float G1V(float dotNV, float k) @@ -622,17 +665,68 @@ float GTR1(float NdotH, float a) -void light_compute(vec3 N, vec3 L,vec3 V,vec3 B, vec3 T,vec3 light_color,vec3 diffuse_color, vec3 specular_color, float specular_blob_intensity, float roughness, float rim,float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy,inout vec3 diffuse, inout vec3 specular) { +void light_compute(vec3 N, vec3 L,vec3 V,vec3 B, vec3 T,vec3 light_color,vec3 diffuse_color, float specular_blob_intensity, float roughness, float rim,float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy,inout vec3 diffuse, inout vec3 specular) { + +#if defined(USE_LIGHT_SHADER_CODE) +//light is written by the light shader + + +LIGHT_SHADER_CODE + + +#else float dotNL = max(dot(N,L), 0.0 ); - float dotNV = max(dot(N,V), 0.0 ); +#if defined(DIFFUSE_HALF_LAMBERT) + + float hl = dot(N,L) * 0.5 + 0.5; + diffuse += hl * light_color * diffuse_color; + +#elif defined(DIFFUSE_OREN_NAYAR) + + { + float LdotV = dot(L, V); + float NdotL = dot(L, N); + float NdotV = dot(N, V); + + float s = LdotV - NdotL * NdotV; + float t = mix(1.0, max(NdotL, NdotV), step(0.0, s)); + + float sigma2 = roughness * roughness; + vec3 A = 1.0 + sigma2 * (diffuse_color / (sigma2 + 0.13) + 0.5 / (sigma2 + 0.33)); + float B = 0.45 * sigma2 / (sigma2 + 0.09); + + diffuse += diffuse_color * max(0.0, NdotL) * (A + vec3(B) * s / t) / M_PI; + } + +#elif defined(DIFFUSE_BURLEY) + + { + float NdotL = dot(L, N); + float NdotV = dot(N, V); + float VdotH = dot(N, normalize(L+V)); + float energyBias = mix(roughness, 0.0, 0.5); + float energyFactor = mix(roughness, 1.0, 1.0 / 1.51); + float fd90 = energyBias + 2.0 * VdotH * VdotH * roughness; + float f0 = 1.0; + float lightScatter = f0 + (fd90 - f0) * pow(1.0 - NdotL, 5.0); + float viewScatter = f0 + (fd90 - f0) * pow(1.0 - NdotV, 5.0); + + diffuse+= light_color * diffuse_color * lightScatter * viewScatter * energyFactor; + } +#else + //lambert + diffuse += dotNL * light_color * diffuse_color; +#endif + + + float dotNV = max(dot(N,V), 0.0 ); #if defined(LIGHT_USE_RIM) float rim_light = pow(1.0-dotNV,(1.0-roughness)*16.0); diffuse += rim_light * rim * mix(vec3(1.0),diffuse_color,rim_tint) * light_color; #endif - diffuse += dotNL * light_color * diffuse_color; if (roughness > 0.0) { @@ -674,7 +768,7 @@ void light_compute(vec3 N, vec3 L,vec3 V,vec3 B, vec3 T,vec3 light_color,vec3 di float speci = dotNL * D * F * vis; - specular += speci * light_color /* specular_color*/ * specular_blob_intensity; + specular += speci * light_color * specular_blob_intensity; #if defined(LIGHT_USE_CLEARCOAT) float Dr = GTR1(dotNH, mix(.1,.001,clearcoat_gloss)); @@ -686,6 +780,7 @@ void light_compute(vec3 N, vec3 L,vec3 V,vec3 B, vec3 T,vec3 light_color,vec3 di } +#endif //defined(USE_LIGHT_SHADER_CODE) } @@ -733,6 +828,8 @@ in highp float dp_clip; #endif + + #if 0 //need to save texture depth for this @@ -762,7 +859,7 @@ vec3 light_transmittance(float translucency,vec3 light_vec, vec3 normal, vec3 po } #endif -void light_process_omni(int idx, vec3 vertex, vec3 eye_vec,vec3 normal,vec3 binormal, vec3 tangent, vec3 albedo, vec3 specular, float roughness, float rim, float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy,inout vec3 diffuse_light, inout vec3 specular_light) { +void light_process_omni(int idx, vec3 vertex, vec3 eye_vec,vec3 normal,vec3 binormal, vec3 tangent, vec3 albedo, float roughness, float rim, float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy,inout vec3 diffuse_light, inout vec3 specular_light) { vec3 light_rel_vec = omni_lights[idx].light_pos_inv_radius.xyz-vertex; float light_length = length( light_rel_vec ); @@ -813,11 +910,11 @@ void light_process_omni(int idx, vec3 vertex, vec3 eye_vec,vec3 normal,vec3 bino light_attenuation*=mix(omni_lights[idx].shadow_color_contact.rgb,vec3(1.0),shadow); } - light_compute(normal,normalize(light_rel_vec),eye_vec,binormal,tangent,omni_lights[idx].light_color_energy.rgb*light_attenuation,albedo,specular,omni_lights[idx].light_params.z,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); + light_compute(normal,normalize(light_rel_vec),eye_vec,binormal,tangent,omni_lights[idx].light_color_energy.rgb*light_attenuation,albedo,omni_lights[idx].light_params.z,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); } -void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 binormal, vec3 tangent,vec3 albedo, vec3 specular, float roughness, float rim,float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy, inout vec3 diffuse_light, inout vec3 specular_light) { +void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 binormal, vec3 tangent,vec3 albedo, float roughness, float rim,float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy, inout vec3 diffuse_light, inout vec3 specular_light) { vec3 light_rel_vec = spot_lights[idx].light_pos_inv_radius.xyz-vertex; float light_length = length( light_rel_vec ); @@ -846,11 +943,11 @@ void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 bi light_attenuation*=mix(spot_lights[idx].shadow_color_contact.rgb,vec3(1.0),shadow); } - light_compute(normal,normalize(light_rel_vec),eye_vec,binormal,tangent,spot_lights[idx].light_color_energy.rgb*light_attenuation,albedo,specular,spot_lights[idx].light_params.z,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); + light_compute(normal,normalize(light_rel_vec),eye_vec,binormal,tangent,spot_lights[idx].light_color_energy.rgb*light_attenuation,albedo,spot_lights[idx].light_params.z,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); } -void reflection_process(int idx, vec3 vertex, vec3 normal,vec3 binormal, vec3 tangent,float roughness,float anisotropy,vec3 ambient,vec3 skybox,vec2 brdf, inout highp vec4 reflection_accum,inout highp vec4 ambient_accum) { +void reflection_process(int idx, vec3 vertex, vec3 normal,vec3 binormal, vec3 tangent,float roughness,float anisotropy,vec3 ambient,vec3 skybox, inout highp vec4 reflection_accum,inout highp vec4 ambient_accum) { vec3 ref_vec = normalize(reflect(vertex,normal)); vec3 local_pos = (reflections[idx].local_matrix * vec4(vertex,1.0)).xyz; @@ -906,7 +1003,7 @@ void reflection_process(int idx, vec3 vertex, vec3 normal,vec3 binormal, vec3 ta splane.xy = clamp(splane.xy,clamp_rect.xy,clamp_rect.xy+clamp_rect.zw); highp vec4 reflection; - reflection.rgb = textureLod(reflection_atlas,splane.xy,roughness*5.0).rgb * brdf.x + brdf.y; + reflection.rgb = textureLod(reflection_atlas,splane.xy,roughness*5.0).rgb; if (reflections[idx].params.z < 0.5) { reflection.rgb = mix(skybox,reflection.rgb,blend); @@ -967,7 +1064,7 @@ void reflection_process(int idx, vec3 vertex, vec3 normal,vec3 binormal, vec3 ta #ifdef USE_GI_PROBES -uniform mediump sampler3D gi_probe1; //texunit:-11 +uniform mediump sampler3D gi_probe1; //texunit:-9 uniform highp mat4 gi_probe_xform1; uniform highp vec3 gi_probe_bounds1; uniform highp vec3 gi_probe_cell_size1; @@ -1087,7 +1184,7 @@ void gi_probe_compute(sampler3D probe, mat4 probe_xform, vec3 bounds,vec3 cell_s } -void gi_probes_compute(vec3 pos, vec3 normal, float roughness, vec3 specular, inout vec3 out_specular, inout vec3 out_ambient) { +void gi_probes_compute(vec3 pos, vec3 normal, float roughness, inout vec3 out_specular, inout vec3 out_ambient) { roughness = roughness * roughness; @@ -1160,7 +1257,8 @@ void main() { //lay out everything, whathever is unused is optimized away anyway highp vec3 vertex = vertex_interp; vec3 albedo = vec3(0.8,0.8,0.8); - vec3 specular = vec3(0.2,0.2,0.2); + float metallic = 0.0; + float specular = 0.5; vec3 emission = vec3(0.0,0.0,0.0); float roughness = 1.0; float rim = 0.0; @@ -1211,13 +1309,15 @@ void main() { float normaldepth=1.0; - +#if defined(SCREEN_UV_USED) + vec2 screen_uv = gl_FragCoord.xy*screen_pixel_size; +#endif #if defined(ENABLE_DISCARD) bool discard_=false; #endif -#if defined (ENABLE_SSS_MOTION) +#if defined (ENABLE_SSS) float sss_strength=0.0; #endif @@ -1275,13 +1375,7 @@ FRAGMENT_SHADER_CODE vec3 eye_vec = -normalize( vertex_interp ); -#ifndef RENDER_DEPTH - float ndotv = clamp(dot(normal,eye_vec),0.0,1.0); - vec2 brdf = texture(brdf_texture, vec2(roughness, ndotv)).xy; - brdf.x=1.0; - brdf.y=0.0; -#endif #ifdef USE_RADIANCE_MAP @@ -1297,9 +1391,9 @@ FRAGMENT_SHADER_CODE { //read radiance from dual paraboloid vec3 ref_vec = reflect(-eye_vec,normal); //2.0 * ndotv * normal - view; // reflect(v, n); - ref_vec=normalize((radiance_inverse_xform * vec4(ref_vec,0.0)).xyz); + ref_vec=normalize((radiance_inverse_xform * vec4(ref_vec,0.0)).xyz); vec3 radiance = textureDualParabolod(radiance_map,ref_vec,lod) * bg_energy; - specular_light = radiance * brdf.x + brdf.y; + specular_light = radiance; } //no longer a cubemap @@ -1467,13 +1561,14 @@ FRAGMENT_SHADER_CODE #endif //LIGHT_DIRECTIONAL_SHADOW - light_compute(normal,-light_direction_attenuation.xyz,eye_vec,binormal,tangent,light_color_energy.rgb*light_attenuation,albedo,specular,light_params.z,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); + light_compute(normal,-light_direction_attenuation.xyz,eye_vec,binormal,tangent,light_color_energy.rgb*light_attenuation,albedo,light_params.z,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); #endif //#USE_LIGHT_DIRECTIONAL #ifdef USE_GI_PROBES - gi_probes_compute(vertex,normal,roughness,specular,specular_light,ambient_light); + gi_probes_compute(vertex,normal,roughness,specular_light,ambient_light); + #endif @@ -1485,7 +1580,7 @@ FRAGMENT_SHADER_CODE for(int i=0;i<reflection_count;i++) { - reflection_process(reflection_indices[i],vertex,normal,binormal,tangent,roughness,anisotropy,ambient_light,specular_light,brdf,reflection_accum,ambient_accum); + reflection_process(reflection_indices[i],vertex,normal,binormal,tangent,roughness,anisotropy,ambient_light,specular_light,reflection_accum,ambient_accum); } if (reflection_accum.a>0.0) { @@ -1496,11 +1591,11 @@ FRAGMENT_SHADER_CODE } for(int i=0;i<omni_light_count;i++) { - light_process_omni(omni_light_indices[i],vertex,eye_vec,normal,binormal,tangent,albedo,specular,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); + light_process_omni(omni_light_indices[i],vertex,eye_vec,normal,binormal,tangent,albedo,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); } for(int i=0;i<spot_light_count;i++) { - light_process_spot(spot_light_indices[i],vertex,eye_vec,normal,binormal,tangent,albedo,specular,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); + light_process_spot(spot_light_indices[i],vertex,eye_vec,normal,binormal,tangent,albedo,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); } @@ -1510,14 +1605,7 @@ FRAGMENT_SHADER_CODE -#if defined(USE_LIGHT_SHADER_CODE) -//light is written by the light shader -{ - -LIGHT_SHADER_CODE -} -#endif #ifdef RENDER_DEPTH //nothing happens, so a tree-ssa optimizer will result in no fragment shader :) @@ -1530,10 +1618,72 @@ LIGHT_SHADER_CODE ambient_light*=ao; #endif - //energy conservation - diffuse_light=mix(diffuse_light,vec3(0.0),specular); - ambient_light=mix(ambient_light,vec3(0.0),specular); - specular_light *= max(vec3(0.04),specular); + + + + + + //energu conservation + diffuse_light=mix(diffuse_light,vec3(0.0),metallic); + ambient_light=mix(ambient_light,vec3(0.0),metallic); + { + //brdf approximation (Lazarov 2013) + float ndotv = clamp(dot(normal,eye_vec),0.0,1.0); + + //energy conservation + vec3 dielectric = vec3(0.034) * 0.5 * 2.0; + vec3 f0 = mix(dielectric, albedo, metallic); + const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022); + const vec4 c1 = vec4( 1.0, 0.0425, 1.04, -0.04); + vec4 r = roughness * c0 + c1; + float a004 = min( r.x * r.x, exp2( -9.28 * ndotv ) ) * r.x + r.y; + vec2 brdf = vec2( -1.04, 1.04 ) * a004 + r.zw; + + specular_light *= min(1.0,50.0 * f0.g) * brdf.y + brdf.x * f0; + } + + if (fog_color_enabled.a > 0.5) { + + float fog_amount=0; + + + +#ifdef USE_LIGHT_DIRECTIONAL + + vec3 fog_color = mix( fog_color_enabled.rgb, fog_sun_color_amount.rgb,fog_sun_color_amount.a * pow(max( dot(normalize(vertex),-light_direction_attenuation.xyz), 0.0),8.0) ); +#else + + vec3 fog_color = fog_color_enabled.rgb; +#endif + + //apply fog + + if (fog_depth_enabled) { + + float fog_z = smoothstep(fog_depth_begin,z_far,-vertex.z); + + fog_amount = pow(fog_z,fog_depth_curve); + if (fog_transmit_enabled) { + vec3 total_light = emission + ambient_light + specular_light + diffuse_light; + float transmit = pow(fog_z,fog_transmit_curve); + fog_color = mix(max(total_light,fog_color),fog_color,transmit); + } + } + + if (fog_height_enabled) { + float y = (camera_matrix * vec4(vertex,1.0)).y; + fog_amount = max(fog_amount,pow(1.0-smoothstep(fog_height_min,fog_height_max,y),fog_height_curve)); + } + + float rev_amount = 1.0 - fog_amount; + + + emission = emission * rev_amount + fog_color * fog_amount; + ambient_light*=rev_amount; + specular_light*rev_amount; + diffuse_light*=rev_amount; + + } #ifdef USE_MULTIPLE_RENDER_TARGETS @@ -1550,13 +1700,13 @@ LIGHT_SHADER_CODE #endif //ENABLE_AO diffuse_buffer=vec4(emission+diffuse_light+ambient_light,ambient_scale); - specular_buffer=vec4(specular_light,max(specular.r,max(specular.g,specular.b))); + specular_buffer=vec4(specular_light,metallic); normal_mr_buffer=vec4(normalize(normal)*0.5+0.5,roughness); -#if defined (ENABLE_SSS_MOTION) - motion_ssr_buffer = vec4(vec3(0.0),sss_strength); +#if defined (ENABLE_SSS) + sss_buffer = sss_strength; #endif #else diff --git a/drivers/gles3/shaders/ssao_blur.glsl b/drivers/gles3/shaders/ssao_blur.glsl index ff852487c0..ce4154f50c 100644 --- a/drivers/gles3/shaders/ssao_blur.glsl +++ b/drivers/gles3/shaders/ssao_blur.glsl @@ -24,7 +24,7 @@ layout(location = 0) out float visibility; // Tunable Parameters: /** Increase to make depth edges crisper. Decrease to reduce flicker. */ -#define EDGE_SHARPNESS (1.0) +#define EDGE_SHARPNESS (4.0) /** Step in 2-pixel intervals since we already blurred against neighbors in the first AO pass. This constant can be increased while R decreases to improve diff --git a/drivers/gles3/shaders/subsurf_scattering.glsl b/drivers/gles3/shaders/subsurf_scattering.glsl index eb329dbaed..569be6c5fe 100644 --- a/drivers/gles3/shaders/subsurf_scattering.glsl +++ b/drivers/gles3/shaders/subsurf_scattering.glsl @@ -107,14 +107,14 @@ uniform vec2 dir; in vec2 uv_interp; uniform sampler2D source_diffuse; //texunit:0 -uniform sampler2D source_motion_ss; //texunit:1 +uniform sampler2D source_sss; //texunit:1 uniform sampler2D source_depth; //texunit:2 layout(location = 0) out vec4 frag_color; void main() { - float strength = texture(source_motion_ss,uv_interp).a; + float strength = texture(source_sss,uv_interp).r; strength*=strength; //stored as sqrt // Fetch color of current pixel: diff --git a/drivers/gles3/shaders/tonemap.glsl b/drivers/gles3/shaders/tonemap.glsl index 8f7e0c7be3..b2615fa29c 100644 --- a/drivers/gles3/shaders/tonemap.glsl +++ b/drivers/gles3/shaders/tonemap.glsl @@ -39,6 +39,19 @@ uniform highp float glow_intensity; #endif +#ifdef USE_BCS + +uniform vec3 bcs; + +#endif + +#ifdef USE_COLOR_CORRECTION + +uniform sampler2D color_correction; //texunit:3 + +#endif + + layout(location = 0) out vec4 frag_color; #ifdef USE_GLOW_FILTER_BICUBIC @@ -255,6 +268,20 @@ void main() { color.rgb = mix( (vec3(1.0)+a)*pow(color.rgb,vec3(1.0/2.4))-a , 12.92*color.rgb , lessThan(color.rgb,vec3(0.0031308))); +#ifdef USE_BCS + + color.rgb = mix(vec3(0.0),color.rgb,bcs.x); + color.rgb = mix(vec3(0.5),color.rgb,bcs.y); + color.rgb = mix(vec3(dot(vec3(1.0),color.rgb)*0.33333),color.rgb,bcs.z); + +#endif + +#ifdef USE_COLOR_CORRECTION + + color.r = texture(color_correction,vec2(color.r,0.0)).r; + color.g = texture(color_correction,vec2(color.g,0.0)).g; + color.b = texture(color_correction,vec2(color.b,0.0)).b; +#endif frag_color=vec4(color.rgb,1.0); diff --git a/drivers/png/image_loader_png.cpp b/drivers/png/image_loader_png.cpp index 25ab767bed..33d271248c 100644 --- a/drivers/png/image_loader_png.cpp +++ b/drivers/png/image_loader_png.cpp @@ -256,6 +256,7 @@ static Ref<Image> _load_mem_png(const uint8_t *p_png, int p_size) { static Ref<Image> _lossless_unpack_png(const PoolVector<uint8_t> &p_data) { int len = p_data.size(); + ERR_FAIL_COND_V(len < 4, Ref<Image>()); PoolVector<uint8_t>::Read r = p_data.read(); ERR_FAIL_COND_V(r[0] != 'P' || r[1] != 'N' || r[2] != 'G' || r[3] != ' ', Ref<Image>()); return _load_mem_png(&r[4], len - 4); diff --git a/editor/SCsub b/editor/SCsub index d7392f8249..c46e443534 100644 --- a/editor/SCsub +++ b/editor/SCsub @@ -141,6 +141,30 @@ def make_translations_header(target, source, env): g.write("#endif") +def make_authors_header(target, source, env): + + src = source[0].srcnode().abspath + dst = target[0].srcnode().abspath + f = open(src, "rb") + g = open(dst, "wb") + + g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") + g.write("#ifndef _EDITOR_AUTHORS_H\n") + g.write("#define _EDITOR_AUTHORS_H\n") + g.write("static const char *dev_names[] = {\n") + + name_count = -1 + for line in f: + if name_count >= 0: + if line.startswith(" "): + g.write("\t\"" + line.strip() + "\",\n") + name_count += 1 + elif line.strip() == "## Developers": + name_count = 0 + g.write("\t0\n") + g.write("};\n") + g.write("#define AUTHORS_COUNT " + str(name_count) + "\n") + g.write("#endif\n") if (env["tools"] == "yes"): @@ -188,6 +212,10 @@ if (env["tools"] == "yes"): env.Depends('#editor/builtin_fonts.h', flist) env.Command('#editor/builtin_fonts.h', flist, make_fonts_header) + # Authors + env.Depends('#editor/authors.h', "../AUTHORS.md") + env.Command('#editor/authors.h', "../AUTHORS.md", make_authors_header) + env.add_source_files(env.editor_sources, "*.cpp") diff --git a/editor/animation_editor.cpp b/editor/animation_editor.cpp index a5de4fee88..1798e66e8a 100644 --- a/editor/animation_editor.cpp +++ b/editor/animation_editor.cpp @@ -76,7 +76,7 @@ private: Ref<StyleBox> sb = get_stylebox("normal", "LineEdit"); sb->draw(ci, r); r.size -= sb->get_minimum_size(); - r.pos += sb->get_offset(); + r.position += sb->get_offset(); //VisualServer::get_singleton()->canvas_item_add Ref<Font> f = get_font("font", "Label"); @@ -111,7 +111,7 @@ private: iflp = 1.0 - iflp; } - VisualServer::get_singleton()->canvas_item_add_line(ci, r.pos + Point2(iflp * r.size.width, prev * r.size.height), r.pos + Point2(ifl * r.size.width, h * r.size.height), mcolor); + VisualServer::get_singleton()->canvas_item_add_line(ci, r.position + Point2(iflp * r.size.width, prev * r.size.height), r.position + Point2(ifl * r.size.width, h * r.size.height), mcolor); prev = h; } @@ -138,7 +138,7 @@ private: iflp = 1.0 - iflp; } - VisualServer::get_singleton()->canvas_item_add_line(ci, r.pos + Point2(iflp * r.size.width, prev * r.size.height), r.pos + Point2(ifl * r.size.width, h * r.size.height), color); + VisualServer::get_singleton()->canvas_item_add_line(ci, r.position + Point2(iflp * r.size.width, prev * r.size.height), r.position + Point2(ifl * r.size.width, h * r.size.height), color); prev = h; } } @@ -1900,13 +1900,13 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) { - Point2 mpos = mb->get_pos() - ofs; + Point2 mpos = mb->get_position() - ofs; if (selection.size() == 0) { // Auto-select on right-click if nothing is selected // Note: This code is pretty much duplicated from the left click code, // both codes could be moved into a function to avoid the duplicated code. - Point2 mpos = mb->get_pos() - ofs; + Point2 mpos = mb->get_position() - ofs; if (mpos.y < h) { return; @@ -1951,7 +1951,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) if (key == -1) { click.click = ClickOver::CLICK_SELECT_KEYS; - click.at = mb->get_pos(); + click.at = mb->get_position(); click.to = click.at; click.shift = mb->get_shift(); selected_track = idx; @@ -1974,7 +1974,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) selection.insert(sk, ki); click.click = ClickOver::CLICK_MOVE_KEYS; - click.at = mb->get_pos(); + click.at = mb->get_position(); click.to = click.at; update(); selected_track = idx; @@ -2009,14 +2009,14 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) if (mb->is_pressed()) { - Point2 mpos = mb->get_pos() - ofs; + Point2 mpos = mb->get_position() - ofs; if (mpos.y < h) { if (mpos.x < name_limit && mpos.x > (name_limit - hsep - hsize_icon->get_width())) { click.click = ClickOver::CLICK_RESIZE_NAMES; - click.at = mb->get_pos(); + click.at = mb->get_position(); click.to = click.at; click.at.y = name_limit; } @@ -2035,7 +2035,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) pos = animation->get_length(); timeline_pos = pos; click.click = ClickOver::CLICK_DRAG_TIMELINE; - click.at = mb->get_pos(); + click.at = mb->get_position(); click.to = click.at; emit_signal("timeline_changed", pos, false); } @@ -2055,7 +2055,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) if (mpos.x >= name_limit && mpos.x < settings_limit) { click.click = ClickOver::CLICK_SELECT_KEYS; - click.at = mb->get_pos(); + click.at = mb->get_position(); click.to = click.at; //drag select region } @@ -2076,7 +2076,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) Rect2 area(ofs.x, ofs.y + ((int(mpos.y) / h) + 1) * h, name_limit, h); track_name->set_text(animation->track_get_path(idx)); - track_name->set_position(te->get_global_position() + area.pos); + track_name->set_position(te->get_global_position() + area.position); track_name->set_size(area.size); track_name->show_modal(); track_name->grab_focus(); @@ -2115,7 +2115,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) if (key == -1) { click.click = ClickOver::CLICK_SELECT_KEYS; - click.at = mb->get_pos(); + click.at = mb->get_position(); click.to = click.at; click.shift = mb->get_shift(); selected_track = idx; @@ -2138,7 +2138,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) selection.insert(sk, ki); click.click = ClickOver::CLICK_MOVE_KEYS; - click.at = mb->get_pos(); + click.at = mb->get_position(); click.to = click.at; update(); selected_track = idx; @@ -2601,7 +2601,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) float clickp = click.at.x - ofs.x; float dif = base - clickp; - float target = mm->get_pos().x + dif - ofs.x; + float target = mm->get_position().x + dif - ofs.x; float ratio = target / settings_limit; @@ -2615,7 +2615,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) } break; case ClickOver::CLICK_DRAG_TIMELINE: { - Point2 mpos = mm->get_pos() - ofs; + Point2 mpos = mm->get_position() - ofs; /* if (mpos.x<name_limit) mpos.x=name_limit; @@ -2646,7 +2646,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) } break; case ClickOver::CLICK_SELECT_KEYS: { - click.to = mm->get_pos(); + click.to = mm->get_position(); if (click.to.y < h && click.at.y > h && mm->get_relative().y < 0) { float prev = v_scroll->get_value(); @@ -2665,7 +2665,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) } break; case ClickOver::CLICK_MOVE_KEYS: { - click.to = mm->get_pos(); + click.to = mm->get_position(); } break; default: {} } @@ -2680,7 +2680,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) if (mm->get_button_mask() == 0) { - Point2 mpos = mm->get_pos() - ofs; + Point2 mpos = mm->get_position() - ofs; if (mpos.y < h) { #if 0 diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index 26029261b2..e3e5793ec8 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -342,7 +342,7 @@ void EditorAudioBus::_effect_edited() { if (effect->get_metadata(0) == Variant()) { Rect2 area = effects->get_item_rect(effect); - effect_options->set_position(effects->get_global_position() + area.pos + Vector2(0, area.size.y)); + effect_options->set_position(effects->get_global_position() + area.position + Vector2(0, area.size.y)); effect_options->popup(); //add effect } else { @@ -396,7 +396,7 @@ void EditorAudioBus::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid() && mb->get_button_index() == 2 && mb->is_pressed()) { - Vector2 pos = Vector2(mb->get_pos().x, mb->get_pos().y); + Vector2 pos = Vector2(mb->get_position().x, mb->get_position().y); delete_popup->set_position(get_global_position() + pos); delete_popup->popup(); } @@ -632,21 +632,24 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses) { solo = memnew(ToolButton); solo->set_text("S"); solo->set_toggle_mode(true); - solo->set_modulate(Color(0.8, 1.2, 0.8)); + solo->add_color_override("font_color_pressed", Color(0.2, 0.9, 0.2)); + solo->add_color_override("font_color_hover", Color(0.6, 0.9, 0.6)); solo->set_focus_mode(FOCUS_NONE); solo->connect("pressed", this, "_solo_toggled"); hbc->add_child(solo); mute = memnew(ToolButton); mute->set_text("M"); mute->set_toggle_mode(true); - mute->set_modulate(Color(1.2, 0.8, 0.8)); + mute->add_color_override("font_color_pressed", Color(0.9, 0.2, 0.2)); + mute->add_color_override("font_color_hover", Color(0.9, 0.6, 0.6)); mute->set_focus_mode(FOCUS_NONE); mute->connect("pressed", this, "_mute_toggled"); hbc->add_child(mute); bypass = memnew(ToolButton); bypass->set_text("B"); bypass->set_toggle_mode(true); - bypass->set_modulate(Color(1.1, 1.1, 0.8)); + bypass->add_color_override("font_color_pressed", Color(0.9, 0.9, 0.2)); + bypass->add_color_override("font_color_hover", Color(0.9, 0.9, 0.6)); bypass->set_focus_mode(FOCUS_NONE); bypass->connect("pressed", this, "_bypass_toggled"); hbc->add_child(bypass); diff --git a/editor/editor_fonts.cpp b/editor/editor_fonts.cpp index dc4c2b21bc..0873b90f22 100644 --- a/editor/editor_fonts.cpp +++ b/editor/editor_fonts.cpp @@ -49,8 +49,8 @@ static Ref<BitmapFont> make_font(int p_height, int p_ascent, int p_valign, int p int chr = c[0]; Rect2 frect; - frect.pos.x = c[1]; - frect.pos.y = c[2]; + frect.position.x = c[1]; + frect.position.y = c[2]; frect.size.x = c[3]; frect.size.y = c[4]; Point2 align(c[5], c[6] + p_valign); diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 8fb307a77d..11cb61370d 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -252,8 +252,8 @@ void EditorHelpSearch::_confirmed() { return; String mdata = ti->get_metadata(0); + EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT); emit_signal("go_to_help", mdata); - editor->call("_editor_select", EditorNode::EDITOR_SCRIPT); // in case EditorHelpSearch beeen invoked on top of other editor window // go to that hide(); } @@ -288,7 +288,6 @@ void EditorHelpSearch::_bind_methods() { EditorHelpSearch::EditorHelpSearch() { - editor = EditorNode::get_singleton(); VBoxContainer *vbc = memnew(VBoxContainer); add_child(vbc); @@ -362,8 +361,8 @@ void EditorHelpIndex::_tree_item_selected() { if (!s) return; + EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT); emit_signal("open_class", s->get_text(0)); - hide(); //_goto_desc(s->get_text(0)); @@ -371,12 +370,10 @@ void EditorHelpIndex::_tree_item_selected() { void EditorHelpIndex::select_class(const String &p_class) { - EditorNode *editor = EditorNode::get_singleton(); if (!tree_item_map.has(p_class)) return; tree_item_map[p_class]->select(0); class_list->ensure_cursor_is_visible(); - editor->call("_editor_select", EditorNode::EDITOR_SCRIPT); // in case EditorHelpIndex beeen invoked on top of other editor window } void EditorHelpIndex::popup() { @@ -1281,7 +1278,7 @@ Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) { void EditorHelp::_request_help(const String &p_string) { Error err = _goto_desc(p_string); if (err == OK) { - editor->call("_editor_select", EditorNode::EDITOR_SCRIPT); + EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT); } //100 palabras } @@ -1691,8 +1688,6 @@ void EditorHelp::_bind_methods() { EditorHelp::EditorHelp() { - editor = EditorNode::get_singleton(); - VBoxContainer *vbc = this; EDITOR_DEF("text_editor/help/sort_functions_alphabetically", true); diff --git a/editor/editor_help.h b/editor/editor_help.h index d6fc0e3bf2..46d83490f4 100644 --- a/editor/editor_help.h +++ b/editor/editor_help.h @@ -49,7 +49,6 @@ class EditorHelpSearch : public ConfirmationDialog { GDCLASS(EditorHelpSearch, ConfirmationDialog) - EditorNode *editor; LineEdit *search_box; Tree *search_options; String base_type; @@ -119,7 +118,6 @@ class EditorHelp : public VBoxContainer { String edited_class; - EditorNode *editor; Map<String, int> method_line; Map<String, int> signal_line; Map<String, int> property_line; diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index c1f422cce3..30e6d4ba93 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -30,6 +30,7 @@ #include "editor_node.h" #include "animation_editor.h" +#include "authors.h" #include "bind/core_bind.h" #include "class_db.h" #include "core/io/resource_loader.h" @@ -1084,6 +1085,7 @@ void EditorNode::_dialog_action(String p_file) { GlobalConfig::get_singleton()->set("application/main_scene", p_file); GlobalConfig::get_singleton()->save(); //would be nice to show the project manager opened with the highlighted field.. + _run(false, ""); // automatically run the project } break; case FILE_SAVE_OPTIMIZED: { @@ -1982,7 +1984,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } _menu_option(FILE_SAVE_AS_SCENE); - _menu_option_confirm(FILE_SAVE_AND_RUN, true); + _menu_option_confirm(FILE_SAVE_AND_RUN, false); } break; case FILE_SAVE_OPTIMIZED: { @@ -3736,7 +3738,7 @@ void EditorNode::_dock_select_input(const Ref<InputEvent> &p_input) { if (me.is_valid()) { - Vector2 point = me->get_pos(); + Vector2 point = me->get_position(); int nrect = -1; for (int i = 0; i < DOCK_SLOT_MAX; i++) { @@ -3846,7 +3848,7 @@ void EditorNode::_dock_select_draw() { unusable.a = 0.1; Rect2 unr(s.x * 2, 0, s.x * 2, s.y * 2); - unr.pos += Vector2(2, 5); + unr.position += Vector2(2, 5); unr.size -= Vector2(4, 7); dock_select->draw_rect(unr, unusable); @@ -3899,7 +3901,7 @@ void EditorNode::_dock_select_draw() { Rect2 r(ofs, s); dock_select_rect[i] = r; - r.pos += Vector2(2, 5); + r.position += Vector2(2, 5); r.size -= Vector2(4, 7); if (i == dock_select_rect_over) { @@ -5874,14 +5876,49 @@ EditorNode::EditorNode() { about->get_ok()->set_text(TTR("Thanks!")); about->set_hide_on_ok(true); gui_base->add_child(about); + VBoxContainer *vbc = memnew(VBoxContainer); HBoxContainer *hbc = memnew(HBoxContainer); - about->add_child(hbc); + hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL); + hbc->set_alignment(BoxContainer::ALIGN_CENTER); + about->add_child(vbc); + vbc->add_child(hbc); Label *about_text = memnew(Label); - about_text->set_text(VERSION_FULL_NAME "\n(c) 2008-2017 Juan Linietsky, Ariel Manzur.\n"); + about_text->set_text(VERSION_FULL_NAME + String::utf8("\n\u00A9 2007-2017 Juan Linietsky, Ariel Manzur.\n\u00A9 2014-2017 ") + TTR("Godot Engine contributors") + "\n"); TextureRect *logo = memnew(TextureRect); logo->set_texture(gui_base->get_icon("Logo", "EditorIcons")); hbc->add_child(logo); hbc->add_child(about_text); + TabContainer *tc = memnew(TabContainer); + tc->set_custom_minimum_size(Vector2(740, 300)); + vbc->add_child(tc); + ScrollContainer *dev_base = memnew(ScrollContainer); + dev_base->set_name(TTR("Developers")); + tc->add_child(dev_base); + HBoxContainer *dev_hbc = memnew(HBoxContainer); + dev_hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL); + dev_base->add_child(dev_hbc); + for (int i = 0; i < 3; i++) { + Label *dev_label = memnew(Label); + dev_label->set_h_size_flags(Control::SIZE_EXPAND); + dev_label->set_v_size_flags(Control::SIZE_FILL); + dev_hbc->add_child(dev_label); + } + int dev_name_index = 0; + int dev_name_column = 0; + const int dev_index_max = AUTHORS_COUNT / 3 + (AUTHORS_COUNT % 3 == 0 ? 0 : 1); + String dev_name = ""; + const char **dev_names_ptr = dev_names; + while (*dev_names_ptr) { + dev_name += String::utf8(*dev_names_ptr++); + if (++dev_name_index == dev_index_max || !*dev_names_ptr) { + dev_hbc->get_child(dev_name_column)->cast_to<Label>()->set_text(dev_name); + dev_name_column++; + dev_name = ""; + dev_name_index = 0; + } else { + dev_name += "\n"; + } + } warning = memnew(AcceptDialog); gui_base->add_child(warning); diff --git a/editor/editor_profiler.cpp b/editor/editor_profiler.cpp index 5aad903485..64cf275c3a 100644 --- a/editor/editor_profiler.cpp +++ b/editor/editor_profiler.cpp @@ -496,7 +496,7 @@ void EditorProfiler::_graph_tex_input(const Ref<InputEvent> &p_ev) { (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) || (mm.is_valid())) { - int x = me->get_pos().x; + int x = me->get_position().x; x = x * frame_metrics.size() / graph->get_size().width; bool show_hover = x >= 0 && x < frame_metrics.size(); diff --git a/editor/editor_run.cpp b/editor/editor_run.cpp index e0ebe985cd..c97dc9a88e 100644 --- a/editor/editor_run.cpp +++ b/editor/editor_run.cpp @@ -73,17 +73,17 @@ Error EditorRun::run(const String &p_scene, const String p_custom_args, const Li } Rect2 screen_rect; - screen_rect.pos = OS::get_singleton()->get_screen_position(screen); + screen_rect.position = OS::get_singleton()->get_screen_position(screen); screen_rect.size = OS::get_singleton()->get_screen_size(screen); Size2 desired_size; - desired_size.x = GlobalConfig::get_singleton()->get("display/width"); - desired_size.y = GlobalConfig::get_singleton()->get("display/height"); + desired_size.x = GlobalConfig::get_singleton()->get("display/window/width"); + desired_size.y = GlobalConfig::get_singleton()->get("display/window/height"); Size2 test_size; - test_size.x = GlobalConfig::get_singleton()->get("display/test_width"); - test_size.y = GlobalConfig::get_singleton()->get("display/test_height"); + test_size.x = GlobalConfig::get_singleton()->get("display/window/test_width"); + test_size.y = GlobalConfig::get_singleton()->get("display/window/test_height"); if (test_size.x > 0 && test_size.y > 0) { desired_size = test_size; @@ -95,21 +95,21 @@ Error EditorRun::run(const String &p_scene, const String p_custom_args, const Li case 0: { // default args.push_back("-p"); - args.push_back(itos(screen_rect.pos.x) + "x" + itos(screen_rect.pos.y)); + args.push_back(itos(screen_rect.position.x) + "x" + itos(screen_rect.position.y)); } break; case 1: { // centered - Vector2 pos = screen_rect.pos + ((screen_rect.size - desired_size) / 2).floor(); + Vector2 pos = screen_rect.position + ((screen_rect.size - desired_size) / 2).floor(); args.push_back("-p"); args.push_back(itos(pos.x) + "x" + itos(pos.y)); } break; case 2: { // custom pos Vector2 pos = EditorSettings::get_singleton()->get("run/window_placement/rect_custom_position"); - pos += screen_rect.pos; + pos += screen_rect.position; args.push_back("-p"); args.push_back(itos(pos.x) + "x" + itos(pos.y)); } break; case 3: { // force maximized - Vector2 pos = screen_rect.pos; + Vector2 pos = screen_rect.position; args.push_back("-p"); args.push_back(itos(pos.x) + "x" + itos(pos.y)); args.push_back("-mx"); @@ -117,7 +117,7 @@ Error EditorRun::run(const String &p_scene, const String p_custom_args, const Li } break; case 4: { // force fullscreen - Vector2 pos = screen_rect.pos; + Vector2 pos = screen_rect.position; args.push_back("-p"); args.push_back(itos(pos.x) + "x" + itos(pos.y)); args.push_back("-f"); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index df12c7c75f..3dab1707a1 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -556,6 +556,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { set("text_editor/line_numbers/line_length_guideline_column", 80); hints["text_editor/line_numbers/line_length_guideline_column"] = PropertyInfo(Variant::INT, "text_editor/line_numbers/line_length_guideline_column", PROPERTY_HINT_RANGE, "20, 160, 10"); + set("text_editor/open_scripts/show_members_overview", true); + set("text_editor/files/trim_trailing_whitespace_on_save", false); set("text_editor/completion/idle_parse_delay", 2); set("text_editor/tools/create_signal_callbacks", true); diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index bf15f43d32..b6952c3024 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -145,8 +145,8 @@ Ref<Theme> create_editor_theme() { theme->set_icon("unchecked", "PopupMenu", theme->get_icon("Unchecked", "EditorIcons")); // Editor background - Ref<StyleBoxFlat> style_background = make_flat_stylebox(dark_color_2, 4, 4, 4, 4); - theme->set_stylebox("Background", "EditorStyles", style_background); + Ref<StyleBoxFlat> style_panel = make_flat_stylebox(dark_color_2, 4, 4, 4, 4); + theme->set_stylebox("Background", "EditorStyles", style_panel); // Focus Ref<StyleBoxFlat> focus_sbt = make_flat_stylebox(light_color_1, 4, 4, 4, 4); @@ -193,9 +193,9 @@ Ref<Theme> create_editor_theme() { theme->set_stylebox("MenuHover", "EditorStyles", style_menu_hover_border); // Content of each tab - Ref<StyleBoxFlat> style_panel = make_flat_stylebox(base_color, 1, 4, 1, 1); - theme->set_stylebox("panel", "TabContainer", style_panel); - theme->set_stylebox("Content", "EditorStyles", style_panel); + Ref<StyleBoxFlat> style_content_panel = make_flat_stylebox(base_color, 1, 4, 1, 1); + theme->set_stylebox("panel", "TabContainer", style_content_panel); + theme->set_stylebox("Content", "EditorStyles", style_content_panel); // Button Ref<StyleBoxFlat> style_button = make_flat_stylebox(dark_color_1, 4, 4, 4, 4); @@ -247,6 +247,10 @@ Ref<Theme> create_editor_theme() { theme->set_icon("arrow_collapsed", "Tree", theme->get_icon("TreeArrowRight", "EditorIcons")); theme->set_icon("select_arrow", "Tree", theme->get_icon("Dropdown", "EditorIcons")); theme->set_stylebox("bg_focus", "Tree", focus_sbt); + theme->set_stylebox("custom_button", "Tree", style_button); + theme->set_stylebox("custom_button_pressed", "Tree", style_button); + theme->set_stylebox("custom_button_hover", "Tree", style_button); + theme->set_color("custom_button_font_highlight", "Tree", HIGHLIGHT_COLOR_LIGHT); Ref<StyleBox> style_tree_btn = make_flat_stylebox(light_color_1, 2, 4, 2, 4); theme->set_stylebox("button_pressed", "Tree", style_tree_btn); @@ -277,7 +281,7 @@ Ref<Theme> create_editor_theme() { theme->set_color("drop_position_color", "Tree", highlight_color); // ItemList - Ref<StyleBoxFlat> style_itemlist_cursor = make_flat_stylebox(highlight_color, 8, 8, 8, 8); + Ref<StyleBoxFlat> style_itemlist_cursor = make_flat_stylebox(highlight_color, 4, 4, 4, 4); style_itemlist_cursor->set_draw_center(false); style_itemlist_cursor->set_border_size(1 * EDSCALE); style_itemlist_cursor->set_light_color(light_color_1); @@ -288,6 +292,7 @@ Ref<Theme> create_editor_theme() { theme->set_stylebox("selected", "ItemList", style_tree_selected); theme->set_stylebox("bg_focus", "ItemList", focus_sbt); theme->set_stylebox("bg", "ItemList", style_bg); + theme->set_constant("vseparation", "ItemList", 5 * EDSCALE); Ref<StyleBoxFlat> style_tab_fg = make_flat_stylebox(base_color, 15, 5, 15, 5); Ref<StyleBoxFlat> style_tab_bg = make_flat_stylebox(base_color, 15, 5, 15, 5); @@ -390,6 +395,9 @@ Ref<Theme> create_editor_theme() { theme->set_icon("grabber", "VSlider", theme->get_icon("SliderGrabber", "EditorIcons")); theme->set_icon("grabber_highlight", "VSlider", theme->get_icon("SliderGrabberHl", "EditorIcons")); + // Panel + theme->set_stylebox("panel", "Panel", style_panel); + // TooltipPanel Ref<StyleBoxFlat> style_tooltip = make_flat_stylebox(Color(1, 1, 1, 0.8), 8, 8, 8, 8); style_tooltip->set_border_size(2 * EDSCALE); diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index 2cefcdbc4a..e0a2ea624e 100644 --- a/editor/import/editor_import_collada.cpp +++ b/editor/import/editor_import_collada.cpp @@ -72,7 +72,7 @@ struct ColladaImport { Map<String, NodeMap> node_map; //map from collada node to engine node Map<String, String> node_name_map; //map from collada node to engine node - Map<String, Ref<Mesh> > mesh_cache; + Map<String, Ref<ArrayMesh> > mesh_cache; Map<String, Ref<Curve3D> > curve_cache; Map<String, Ref<Material> > material_cache; Map<Collada::Node *, Skeleton *> skeleton_map; @@ -88,7 +88,7 @@ struct ColladaImport { Error _create_scene(Collada::Node *p_node, Spatial *p_parent); Error _create_resources(Collada::Node *p_node); Error _create_material(const String &p_material); - Error _create_mesh_surfaces(bool p_optimize, Ref<Mesh> &p_mesh, const Map<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *p_skin_data, const Collada::MorphControllerData *p_morph_data, Vector<Ref<Mesh> > p_morph_meshes = Vector<Ref<Mesh> >(), bool p_for_morph = false, bool p_use_mesh_material = false); + Error _create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_mesh, const Map<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *p_skin_data, const Collada::MorphControllerData *p_morph_data, Vector<Ref<ArrayMesh> > p_morph_meshes = Vector<Ref<ArrayMesh> >(), bool p_for_morph = false, bool p_use_mesh_material = false); Error load(const String &p_path, int p_flags, bool p_force_make_tangents = false); void _fix_param_animation_tracks(); void create_animation(int p_clip, bool p_make_tracks_in_all_bones, bool p_import_value_tracks); @@ -402,8 +402,8 @@ Error ColladaImport::_create_material(const String &p_target) { Ref<Texture> texture = ResourceLoader::load(texfile, "Texture"); if (texture.is_valid()) { - material->set_texture(SpatialMaterial::TEXTURE_SPECULAR, texture); - material->set_specular(Color(1, 1, 1, 1)); + material->set_texture(SpatialMaterial::TEXTURE_METALLIC, texture); + material->set_specular(1.0); //material->set_texture(SpatialMaterial::PARAM_SPECULAR,texture); //material->set_parameter(SpatialMaterial::PARAM_SPECULAR,Color(1,1,1,1)); @@ -411,8 +411,9 @@ Error ColladaImport::_create_material(const String &p_target) { missing_textures.push_back(texfile.get_file()); } } + } else { - material->set_metalness(effect.specular.color.get_v()); + material->set_metallic(effect.specular.color.get_v()); } // EMISSION @@ -553,10 +554,10 @@ static void _generate_tangents_and_binormals(const PoolVector<int> &p_indices, c tangent = Vector3(); } else { tangent = Vector3((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, - (t2 * z1 - t1 * z2) * r) + (t2 * z1 - t1 * z2) * r) .normalized(); binormal = Vector3((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, - (s1 * z2 - s2 * z1) * r) + (s1 * z2 - s2 * z1) * r) .normalized(); } @@ -590,7 +591,7 @@ static void _generate_tangents_and_binormals(const PoolVector<int> &p_indices, c } } -Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<Mesh> &p_mesh, const Map<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *skin_controller, const Collada::MorphControllerData *p_morph_data, Vector<Ref<Mesh> > p_morph_meshes, bool p_for_morph, bool p_use_mesh_material) { +Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_mesh, const Map<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *skin_controller, const Collada::MorphControllerData *p_morph_data, Vector<Ref<ArrayMesh> > p_morph_meshes, bool p_for_morph, bool p_use_mesh_material) { bool local_xform_mirror = p_local_xform.basis.determinant() < 0; @@ -1529,7 +1530,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) { String meshid; Transform apply_xform; Vector<int> bone_remap; - Vector<Ref<Mesh> > morphs; + Vector<Ref<ArrayMesh> > morphs; print_line("mesh: " + String(mi->get_name())); @@ -1620,9 +1621,9 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) { String meshid = names[i]; if (collada.state.mesh_data_map.has(meshid)) { - Ref<Mesh> mesh = Ref<Mesh>(memnew(Mesh)); + Ref<ArrayMesh> mesh = Ref<ArrayMesh>(memnew(ArrayMesh)); const Collada::MeshData &meshdata = collada.state.mesh_data_map[meshid]; - Error err = _create_mesh_surfaces(false, mesh, ng->material_map, meshdata, apply_xform, bone_remap, skin, NULL, Vector<Ref<Mesh> >(), true); + Error err = _create_mesh_surfaces(false, mesh, ng->material_map, meshdata, apply_xform, bone_remap, skin, NULL, Vector<Ref<ArrayMesh> >(), true); ERR_FAIL_COND_V(err, err); morphs.push_back(mesh); @@ -1647,7 +1648,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) { meshid = ng->source; } - Ref<Mesh> mesh; + Ref<ArrayMesh> mesh; if (mesh_cache.has(meshid)) { mesh = mesh_cache[meshid]; } else { @@ -1655,7 +1656,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) { //bleh, must ignore invalid ERR_FAIL_COND_V(!collada.state.mesh_data_map.has(meshid), ERR_INVALID_DATA); - mesh = Ref<Mesh>(memnew(Mesh)); + mesh = Ref<ArrayMesh>(memnew(ArrayMesh)); const Collada::MeshData &meshdata = collada.state.mesh_data_map[meshid]; mesh->set_name(meshdata.name); Error err = _create_mesh_surfaces(morphs.size() == 0, mesh, ng->material_map, meshdata, apply_xform, bone_remap, skin, morph, morphs, false, use_mesh_builtin_materials); diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index 21c2ae6eb3..8d0f3267f7 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -89,7 +89,7 @@ Error ResourceImporterOBJ::import(const String &p_source_file, const String &p_s FileAccessRef f = FileAccess::open(p_source_file, FileAccess::READ); ERR_FAIL_COND_V(!f, ERR_CANT_OPEN); - Ref<Mesh> mesh = Ref<Mesh>(memnew(Mesh)); + Ref<ArrayMesh> mesh = Ref<ArrayMesh>(memnew(ArrayMesh)); Map<String, Ref<Material> > name_map; bool generate_normals = p_options["generate/normals"]; diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index 755f4eb219..d2d2d45a47 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -137,7 +137,7 @@ static String _fixstr(const String &p_what, const String &p_str) { return p_what; } -Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>, Ref<Shape> > &collision_map) { +Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<ArrayMesh>, Ref<Shape> > &collision_map) { // children first.. for (int i = 0; i < p_node->get_child_count(); i++) { @@ -175,7 +175,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> mi->set_flag(GeometryInstance::FLAG_BILLBOARD, true); if (mi->get_mesh().is_valid()) { - Ref<Mesh> m = mi->get_mesh(); + Ref<ArrayMesh> m = mi->get_mesh(); for (int i = 0; i < m->get_surface_count(); i++) { Ref<SpatialMaterial> fm = m->surface_get_material(i); @@ -194,7 +194,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> MeshInstance *mi = p_node->cast_to<MeshInstance>(); - Ref<Mesh> m = mi->get_mesh(); + Ref<ArrayMesh> m = mi->get_mesh(); if (m.is_valid()) { @@ -275,7 +275,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> if (mi->get_mesh().is_valid()) { - Ref<Mesh> m = mi->get_mesh(); + Ref<ArrayMesh> m = mi->get_mesh(); for (int i = 0; i < m->get_surface_count(); i++) { Ref<SpatialMaterial> fm = m->surface_get_material(i); @@ -325,7 +325,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> /*if (mi->get_mesh().is_valid()) { - Ref<Mesh> m = mi->get_mesh(); + Ref<ArrayMesh> m = mi->get_mesh(); for(int i=0;i<m->get_surface_count();i++) { Ref<SpatialMaterial> fm = m->surface_get_material(i); @@ -477,7 +477,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> MeshInstance *mi = p_node->cast_to<MeshInstance>(); - Ref<Mesh> mesh = mi->get_mesh(); + Ref<ArrayMesh> mesh = mi->get_mesh(); ERR_FAIL_COND_V(mesh.is_null(), NULL); NavigationMeshInstance *nmi = memnew(NavigationMeshInstance); @@ -655,7 +655,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> MeshInstance *mi = p_node->cast_to<MeshInstance>(); - Ref<Mesh> mesh = mi->get_mesh(); + Ref<ArrayMesh> mesh = mi->get_mesh(); if (!mesh.is_null()) { if (_teststr(mesh->get_name(), "col")) { @@ -972,7 +972,7 @@ static String _make_extname(const String &p_str) { return ext_name; } -void ResourceImporterScene::_make_external_resources(Node *p_node, const String &p_base_path, bool p_make_materials, bool p_make_meshes, Map<Ref<Material>, Ref<Material> > &p_materials, Map<Ref<Mesh>, Ref<Mesh> > &p_meshes) { +void ResourceImporterScene::_make_external_resources(Node *p_node, const String &p_base_path, bool p_make_materials, bool p_make_meshes, Map<Ref<Material>, Ref<Material> > &p_materials, Map<Ref<ArrayMesh>, Ref<ArrayMesh> > &p_meshes) { List<PropertyInfo> pi; @@ -1005,7 +1005,7 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String } } else { - Ref<Mesh> mesh = p_node->get(E->get().name); + Ref<ArrayMesh> mesh = p_node->get(E->get().name); if (mesh.is_valid()) { @@ -1018,7 +1018,7 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String String ext_name = p_base_path + "." + _make_extname(mesh->get_name()) + ".msh"; if (FileAccess::exists(ext_name)) { //if exists, use it - Ref<Mesh> existing = ResourceLoader::load(ext_name); + Ref<ArrayMesh> existing = ResourceLoader::load(ext_name); p_meshes[mesh] = existing; } else { @@ -1059,7 +1059,7 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String } if (!p_make_meshes) { - p_meshes[mesh] = Ref<Mesh>(); //save it anyway, so it won't be checked again + p_meshes[mesh] = Ref<ArrayMesh>(); //save it anyway, so it won't be checked again } } } @@ -1192,7 +1192,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p float anim_optimizer_angerr = p_options["animation/optimizer/max_angular_error"]; float anim_optimizer_maxang = p_options["animation/optimizer/max_angle"]; - Map<Ref<Mesh>, Ref<Shape> > collision_map; + Map<Ref<ArrayMesh>, Ref<Shape> > collision_map; scene = _fix_node(scene, scene, collision_map); @@ -1230,7 +1230,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p if (external_materials || external_meshes) { Map<Ref<Material>, Ref<Material> > mat_map; - Map<Ref<Mesh>, Ref<Mesh> > mesh_map; + Map<Ref<ArrayMesh>, Ref<ArrayMesh> > mesh_map; _make_external_resources(scene, p_source_file.get_basename(), external_materials, external_meshes, mat_map, mesh_map); } diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h index 9f7b1a84e6..ede3028b29 100644 --- a/editor/import/resource_importer_scene.h +++ b/editor/import/resource_importer_scene.h @@ -32,6 +32,7 @@ #include "io/resource_import.h" #include "scene/resources/animation.h" +#include "scene/resources/mesh.h" #include "scene/resources/shape.h" class Material; @@ -100,9 +101,9 @@ public: virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const; virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const; - void _make_external_resources(Node *p_node, const String &p_base_path, bool p_make_materials, bool p_make_meshes, Map<Ref<Material>, Ref<Material> > &p_materials, Map<Ref<Mesh>, Ref<Mesh> > &p_meshes); + void _make_external_resources(Node *p_node, const String &p_base_path, bool p_make_materials, bool p_make_meshes, Map<Ref<Material>, Ref<Material> > &p_materials, Map<Ref<ArrayMesh>, Ref<ArrayMesh> > &p_meshes); - Node *_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>, Ref<Shape> > &collision_map); + Node *_fix_node(Node *p_node, Node *p_root, Map<Ref<ArrayMesh>, Ref<Shape> > &collision_map); void _create_clips(Node *scene, const Array &p_clips, bool p_bake_all); void _filter_anim_tracks(Ref<Animation> anim, Set<String> &keep); diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp index 17feeb1196..7e27f6c618 100644 --- a/editor/import/resource_importer_texture.cpp +++ b/editor/import/resource_importer_texture.cpp @@ -277,7 +277,7 @@ void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String if (p_force_rgbe && image->get_format() >= Image::FORMAT_R8 && image->get_format() <= Image::FORMAT_RGBE9995) { image->convert(Image::FORMAT_RGBE9995); } else { - image->compress(p_vram_compression); + image->compress(p_vram_compression, p_texture_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR); } format |= image->get_format(); diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp index fccd527ed6..d67832e10b 100644 --- a/editor/plugins/animation_tree_editor_plugin.cpp +++ b/editor/plugins/animation_tree_editor_plugin.cpp @@ -744,7 +744,7 @@ void AnimationTreeEditor::_gui_input(Ref<InputEvent> p_event) { if (mb->is_pressed()) { if (mb->get_button_index() == 1) { - click_pos = Point2(mb->get_pos().x, mb->get_pos().y); + click_pos = Point2(mb->get_position().x, mb->get_position().y); click_motion = click_pos; click_type = _locate_click(click_pos, &click_node, &click_slot); if (click_type != CLICK_NONE) { @@ -780,7 +780,7 @@ void AnimationTreeEditor::_gui_input(Ref<InputEvent> p_event) { } else { // try to disconnect/remove - Point2 rclick_pos = Point2(mb->get_pos().x, mb->get_pos().y); + Point2 rclick_pos = Point2(mb->get_position().x, mb->get_position().y); rclick_type = _locate_click(rclick_pos, &rclick_node, &rclick_slot); if (rclick_type == CLICK_INPUT_SLOT || rclick_type == CLICK_OUTPUT_SLOT) { @@ -820,7 +820,7 @@ void AnimationTreeEditor::_gui_input(Ref<InputEvent> p_event) { case CLICK_INPUT_SLOT: case CLICK_OUTPUT_SLOT: { - Point2 dst_click_pos = Point2(mb->get_pos().x, mb->get_pos().y); + Point2 dst_click_pos = Point2(mb->get_position().x, mb->get_position().y); StringName id; int slot; ClickType dst_click_type = _locate_click(dst_click_pos, &id, &slot); @@ -859,7 +859,7 @@ void AnimationTreeEditor::_gui_input(Ref<InputEvent> p_event) { if (mm->get_button_mask() & 1 && click_type != CLICK_NONE) { - click_motion = Point2(mm->get_pos().x, mm->get_pos().y); + click_motion = Point2(mm->get_position().x, mm->get_position().y); update(); } if ((mm->get_button_mask() & 4 || Input::get_singleton()->is_key_pressed(KEY_SPACE))) { @@ -876,7 +876,7 @@ void AnimationTreeEditor::_draw_cos_line(const Vector2 &p_from, const Vector2 &p static const int steps = 20; Rect2 r; - r.pos = p_from; + r.position = p_from; r.expand_to(p_to); Vector2 sign = Vector2((p_from.x < p_to.x) ? 1 : -1, (p_from.y < p_to.y) ? 1 : -1); bool flip = sign.x * sign.y < 0; @@ -888,7 +888,7 @@ void AnimationTreeEditor::_draw_cos_line(const Vector2 &p_from, const Vector2 &p float c = -Math::cos(d * Math_PI) * 0.5 + 0.5; if (flip) c = 1.0 - c; - Vector2 p = r.pos + Vector2(d * r.size.width, c * r.size.height); + Vector2 p = r.position + Vector2(d * r.size.width, c * r.size.height); if (i > 0) { diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index a626dffc3c..e6c08a9009 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -536,10 +536,10 @@ void CanvasItemEditor::_find_canvas_items_at_rect(const Rect2 &p_rect, Node *p_n Rect2 rect = c->get_item_rect(); Transform2D xform = p_parent_xform * p_canvas_xform * c->get_transform(); - if (p_rect.has_point(xform.xform(rect.pos)) && - p_rect.has_point(xform.xform(rect.pos + Vector2(rect.size.x, 0))) && - p_rect.has_point(xform.xform(rect.pos + Vector2(rect.size.x, rect.size.y))) && - p_rect.has_point(xform.xform(rect.pos + Vector2(0, rect.size.y)))) { + if (p_rect.has_point(xform.xform(rect.position)) && + p_rect.has_point(xform.xform(rect.position + Vector2(rect.size.x, 0))) && + p_rect.has_point(xform.xform(rect.position + Vector2(rect.size.x, rect.size.y))) && + p_rect.has_point(xform.xform(rect.position + Vector2(0, rect.size.y)))) { r_items->push_back(c); } @@ -652,7 +652,7 @@ void CanvasItemEditor::_key_move(const Vector2 &p_dir, bool p_snap, KeyMoveMODE // drag = transform.affine_inverse().basis_xform(p_dir); // zoom sensitive drag = canvas_item->get_global_transform_with_canvas().affine_inverse().basis_xform(drag); Rect2 local_rect = canvas_item->get_item_rect(); - local_rect.pos += drag; + local_rect.position += drag; undo_redo->add_do_method(canvas_item, "edit_set_rect", local_rect); } else { // p_move_mode==MOVE_LOCAL_BASE || p_move_mode==MOVE_LOCAL_WITH_ROT @@ -680,7 +680,7 @@ Point2 CanvasItemEditor::_find_topleftmost_point() { Vector2 tl = Point2(1e10, 1e10); Rect2 r2; - r2.pos = tl; + r2.position = tl; List<Node *> &selection = editor_selection->get_selected_node_list(); @@ -695,13 +695,13 @@ Point2 CanvasItemEditor::_find_topleftmost_point() { Rect2 rect = canvas_item->get_item_rect(); Transform2D xform = canvas_item->get_global_transform_with_canvas(); - r2.expand_to(xform.xform(rect.pos)); - r2.expand_to(xform.xform(rect.pos + Vector2(rect.size.x, 0))); - r2.expand_to(xform.xform(rect.pos + rect.size)); - r2.expand_to(xform.xform(rect.pos + Vector2(0, rect.size.y))); + r2.expand_to(xform.xform(rect.position)); + r2.expand_to(xform.xform(rect.position + Vector2(rect.size.x, 0))); + r2.expand_to(xform.xform(rect.position + rect.size)); + r2.expand_to(xform.xform(rect.position + Vector2(0, rect.size.y))); } - return r2.pos; + return r2.position; } int CanvasItemEditor::get_item_count() { @@ -759,18 +759,18 @@ CanvasItemEditor::DragType CanvasItemEditor::_find_drag_type(const Transform2D & Vector2 endpoints[4] = { - xform.xform(rect.pos), - xform.xform(rect.pos + Vector2(rect.size.x, 0)), - xform.xform(rect.pos + rect.size), - xform.xform(rect.pos + Vector2(0, rect.size.y)) + xform.xform(rect.position), + xform.xform(rect.position + Vector2(rect.size.x, 0)), + xform.xform(rect.position + rect.size), + xform.xform(rect.position + Vector2(0, rect.size.y)) }; Vector2 endpointsl[4] = { - xforml.xform(rect.pos), - xforml.xform(rect.pos + Vector2(rect.size.x, 0)), - xforml.xform(rect.pos + rect.size), - xforml.xform(rect.pos + Vector2(0, rect.size.y)) + xforml.xform(rect.position), + xforml.xform(rect.position + Vector2(rect.size.x, 0)), + xforml.xform(rect.position + rect.size), + xforml.xform(rect.position + Vector2(0, rect.size.y)) }; DragType dragger[] = { @@ -962,7 +962,7 @@ bool CanvasItemEditor::get_remove_list(List<Node *> *p_list) { void CanvasItemEditor::_list_select(const Ref<InputEventMouseButton> &b) { - Point2 click = b->get_pos(); + Point2 click = b->get_position(); Node *scene = editor->get_edited_scene(); if (!scene) @@ -1016,7 +1016,7 @@ void CanvasItemEditor::_list_select(const Ref<InputEventMouseButton> &b) { additive_selection = b->get_shift(); - selection_menu->set_global_position(b->get_global_pos()); + selection_menu->set_global_position(b->get_global_position()); selection_menu->popup(); selection_menu->call_deferred("grab_click_focus"); selection_menu->set_invalidate_click_until_motion(); @@ -1053,7 +1053,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { float prev_zoom = zoom; zoom = zoom * (1 - (0.05 * b->get_factor())); { - Point2 ofs = b->get_pos(); + Point2 ofs = b->get_position(); ofs = ofs / prev_zoom - ofs / zoom; h_scroll->set_value(h_scroll->get_value() + ofs.x); v_scroll->set_value(v_scroll->get_value() + ofs.y); @@ -1071,7 +1071,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { float prev_zoom = zoom; zoom = zoom * ((0.95 + (0.05 * b->get_factor())) / 0.95); { - Point2 ofs = b->get_pos(); + Point2 ofs = b->get_position(); ofs = ofs / prev_zoom - ofs / zoom; h_scroll->set_value(h_scroll->get_value() + ofs.x); v_scroll->set_value(v_scroll->get_value() + ofs.y); @@ -1156,7 +1156,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { if (b->get_button_index() == BUTTON_LEFT && tool == TOOL_EDIT_PIVOT) { if (b->is_pressed()) { - Point2 mouse_pos = b->get_pos(); + Point2 mouse_pos = b->get_position(); mouse_pos = transform.affine_inverse().xform(mouse_pos); mouse_pos = snap_point(mouse_pos); _edit_set_pivot(mouse_pos); @@ -1274,8 +1274,8 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { E->get().to }; - Vector2 p = Geometry::get_closest_point_to_segment_2d(b->get_pos(), s); - float d = p.distance_to(b->get_pos()); + Vector2 p = Geometry::get_closest_point_to_segment_2d(b->get_position(), s); + float d = p.distance_to(b->get_position()); if (d < bone_width && d < closest_dist) { Cbone = E; closest_dist = d; @@ -1342,7 +1342,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); ERR_FAIL_COND(!se); - Point2 click = b->get_pos(); + Point2 click = b->get_position(); if ((b->get_control() && tool == TOOL_SELECT) || tool == TOOL_ROTATE) { @@ -1388,7 +1388,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { //multi canvas_item edit - Point2 click = b->get_pos(); + Point2 click = b->get_position(); if ((b->get_alt() || tool == TOOL_MOVE) && get_item_count()) { _prepare_drag(click); @@ -1451,7 +1451,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { if (box_selecting) { - box_selecting_to = transform.affine_inverse().xform(m->get_pos()); + box_selecting_to = transform.affine_inverse().xform(m->get_position()); viewport->update(); return; } @@ -1497,7 +1497,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { } Vector2 dfrom = drag_from; - Vector2 dto = transform.affine_inverse().xform(m->get_pos()); + Vector2 dto = transform.affine_inverse().xform(m->get_position()); if (canvas_item->has_meta("_edit_lock_")) continue; @@ -1552,8 +1552,8 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { canvas_item->get_global_transform_with_canvas().affine_inverse().xform(dfrom); Rect2 local_rect = canvas_item->get_item_rect(); - Vector2 begin = local_rect.pos; - Vector2 end = local_rect.pos + local_rect.size; + Vector2 begin = local_rect.position; + Vector2 end = local_rect.position + local_rect.size; Vector2 minsize = canvas_item->edit_get_minimum_size(); if (uniform) { @@ -1645,7 +1645,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { if (!dragging_bone) { - local_rect.pos = begin; + local_rect.position = begin; local_rect.size = end - begin; canvas_item->edit_set_rect(local_rect); @@ -1868,10 +1868,10 @@ void CanvasItemEditor::_viewport_draw() { Vector2 endpoints[4] = { - xform.xform(rect.pos), - xform.xform(rect.pos + Vector2(rect.size.x, 0)), - xform.xform(rect.pos + rect.size), - xform.xform(rect.pos + Vector2(0, rect.size.y)) + xform.xform(rect.position), + xform.xform(rect.position + Vector2(rect.size.x, 0)), + xform.xform(rect.position + rect.size), + xform.xform(rect.position + Vector2(0, rect.size.y)) }; Color c = Color(1, 0.6, 0.4, 0.7); @@ -2212,7 +2212,7 @@ void CanvasItemEditor::_find_canvas_items_span(Node *p_node, Rect2 &r_rect, cons lock.group = c->has_meta("_edit_group_"); if (lock.group || lock.lock) { - lock.pos = xform.xform(rect.pos); + lock.pos = xform.xform(rect.position); lock_list.push_back(lock); } @@ -2228,10 +2228,10 @@ void CanvasItemEditor::_find_canvas_items_span(Node *p_node, Rect2 &r_rect, cons bone_list[id].last_pass = bone_last_frame; } - r_rect.expand_to(xform.xform(rect.pos)); - r_rect.expand_to(xform.xform(rect.pos + Point2(rect.size.x, 0))); - r_rect.expand_to(xform.xform(rect.pos + Point2(0, rect.size.y))); - r_rect.expand_to(xform.xform(rect.pos + rect.size)); + r_rect.expand_to(xform.xform(rect.position)); + r_rect.expand_to(xform.xform(rect.position + Point2(rect.size.x, 0))); + r_rect.expand_to(xform.xform(rect.position + Point2(0, rect.size.y))); + r_rect.expand_to(xform.xform(rect.position + rect.size)); } } @@ -2277,19 +2277,19 @@ void CanvasItemEditor::_update_scrollbars() { //expand area so it's easier to do animations and stuff at 0,0 canvas_item_rect.size += screen_rect * 2; - canvas_item_rect.pos -= screen_rect; + canvas_item_rect.position -= screen_rect; Point2 ofs; if (canvas_item_rect.size.height <= (local_rect.size.y / zoom)) { v_scroll->hide(); - ofs.y = canvas_item_rect.pos.y; + ofs.y = canvas_item_rect.position.y; } else { v_scroll->show(); - v_scroll->set_min(canvas_item_rect.pos.y); - v_scroll->set_max(canvas_item_rect.pos.y + canvas_item_rect.size.y); + v_scroll->set_min(canvas_item_rect.position.y); + v_scroll->set_max(canvas_item_rect.position.y + canvas_item_rect.size.y); v_scroll->set_page(local_rect.size.y / zoom); if (first_update) { //so 0,0 is visible @@ -2304,12 +2304,12 @@ void CanvasItemEditor::_update_scrollbars() { if (canvas_item_rect.size.width <= (local_rect.size.x / zoom)) { h_scroll->hide(); - ofs.x = canvas_item_rect.pos.x; + ofs.x = canvas_item_rect.position.x; } else { h_scroll->show(); - h_scroll->set_min(canvas_item_rect.pos.x); - h_scroll->set_max(canvas_item_rect.pos.x + canvas_item_rect.size.x); + h_scroll->set_min(canvas_item_rect.position.x); + h_scroll->set_max(canvas_item_rect.position.x + canvas_item_rect.size.x); h_scroll->set_page(local_rect.size.x / zoom); ofs.x = h_scroll->get_value(); } @@ -2977,7 +2977,7 @@ void CanvasItemEditor::_focus_selection(int p_op) { Transform2D t(angle, Vector2(0.f, 0.f)); item_rect = t.xform(item_rect); - Rect2 canvas_item_rect(pos + scale * item_rect.pos, scale * item_rect.size); + Rect2 canvas_item_rect(pos + scale * item_rect.position, scale * item_rect.size); if (count == 1) { rect = canvas_item_rect; } else { @@ -2988,7 +2988,7 @@ void CanvasItemEditor::_focus_selection(int p_op) { if (p_op == VIEW_CENTER_TO_SELECTION) { - center = rect.pos + rect.size / 2; + center = rect.position + rect.size / 2; Vector2 offset = viewport->get_size() / 2 - editor->get_scene_root()->get_global_canvas_transform().xform(center); h_scroll->set_value(h_scroll->get_value() - offset.x / zoom); v_scroll->set_value(v_scroll->get_value() - offset.y / zoom); diff --git a/editor/plugins/collision_polygon_2d_editor_plugin.cpp b/editor/plugins/collision_polygon_2d_editor_plugin.cpp index b7cfcaae02..43abea0131 100644 --- a/editor/plugins/collision_polygon_2d_editor_plugin.cpp +++ b/editor/plugins/collision_polygon_2d_editor_plugin.cpp @@ -104,7 +104,7 @@ bool CollisionPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) if (mb.is_valid()) { Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Vector2 gpoint = mb->get_pos(); + Vector2 gpoint = mb->get_position(); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); cpoint = canvas_item_editor->snap_point(cpoint); cpoint = node->get_global_transform().affine_inverse().xform(cpoint); @@ -289,7 +289,7 @@ bool CollisionPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) if (edited_point != -1 && (wip_active || mm->get_button_mask() & BUTTON_MASK_LEFT)) { - Vector2 gpoint = mm->get_pos(); + Vector2 gpoint = mm->get_position(); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); cpoint = canvas_item_editor->snap_point(cpoint); edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); diff --git a/editor/plugins/collision_shape_2d_editor_plugin.cpp b/editor/plugins/collision_shape_2d_editor_plugin.cpp index e2184c6158..9a6ee8153e 100644 --- a/editor/plugins/collision_shape_2d_editor_plugin.cpp +++ b/editor/plugins/collision_shape_2d_editor_plugin.cpp @@ -322,7 +322,7 @@ bool CollisionShape2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { Transform2D gt = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Point2 gpoint(mb->get_pos().x, mb->get_pos().y); + Point2 gpoint(mb->get_position().x, mb->get_position().y); if (mb->get_button_index() == BUTTON_LEFT) { if (mb->is_pressed()) { @@ -368,7 +368,7 @@ bool CollisionShape2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { return false; } - Point2 gpoint = mm->get_pos(); + Point2 gpoint = mm->get_position(); Point2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); cpoint = canvas_item_editor->snap_point(cpoint); cpoint = node->get_global_transform().affine_inverse().xform(cpoint); diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp index 6dd94863a1..d869d703f1 100644 --- a/editor/plugins/curve_editor_plugin.cpp +++ b/editor/plugins/curve_editor_plugin.cpp @@ -57,7 +57,7 @@ void CurveTextureEdit::_gui_input(const Ref<InputEvent> &p_event) { Vector2 size = get_size(); size.y -= font_h; - Point2 p = Vector2(mb->get_pos().x, mb->get_pos().y) / size; + Point2 p = Vector2(mb->get_position().x, mb->get_position().y) / size; p.y = CLAMP(1.0 - p.y, 0, 1) * (max - min) + min; grabbed = -1; grabbing = true; @@ -111,7 +111,7 @@ void CurveTextureEdit::_gui_input(const Ref<InputEvent> &p_event) { Vector2 size = get_size(); size.y -= font_h; - Point2 p = mm->get_pos() / size; + Point2 p = mm->get_position() / size; p.y = CLAMP(1.0 - p.y, 0, 1) * (max - min) + min; p.x = CLAMP(p.x, 0.0, 1.0); diff --git a/editor/plugins/gradient_texture_editor_plugin.cpp b/editor/plugins/gradient_texture_editor_plugin.cpp index 40f7de478d..bc985dcdf7 100644 --- a/editor/plugins/gradient_texture_editor_plugin.cpp +++ b/editor/plugins/gradient_texture_editor_plugin.cpp @@ -94,14 +94,14 @@ void GradientTextureEdit::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> mb = p_event; //Show color picker on double click. if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_doubleclick() && mb->is_pressed()) { - grabbed = _get_point_from_pos(mb->get_pos().x); + grabbed = _get_point_from_pos(mb->get_position().x); _show_color_picker(); accept_event(); } //Delete point on right click if (mb.is_valid() && mb->get_button_index() == 2 && mb->is_pressed()) { - grabbed = _get_point_from_pos(mb->get_pos().x); + grabbed = _get_point_from_pos(mb->get_position().x); if (grabbed != -1) { points.remove(grabbed); grabbed = -1; @@ -115,7 +115,7 @@ void GradientTextureEdit::_gui_input(const Ref<InputEvent> &p_event) { //Hold alt key to duplicate selected color if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed() && mb->get_alt()) { - int x = mb->get_pos().x; + int x = mb->get_position().x; grabbed = _get_point_from_pos(x); if (grabbed != -1) { @@ -140,7 +140,7 @@ void GradientTextureEdit::_gui_input(const Ref<InputEvent> &p_event) { if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) { update(); - int x = mb->get_pos().x; + int x = mb->get_position().x; int total_w = get_size().width - get_size().height - 3; //Check if color selector was clicked. @@ -220,7 +220,7 @@ void GradientTextureEdit::_gui_input(const Ref<InputEvent> &p_event) { int total_w = get_size().width - get_size().height - 3; - int x = mm->get_pos().x; + int x = mm->get_position().x; float newofs = CLAMP(x / float(total_w), 0, 1); //Snap to nearest point if holding shift diff --git a/editor/plugins/light_occluder_2d_editor_plugin.cpp b/editor/plugins/light_occluder_2d_editor_plugin.cpp index 9c9e010b47..09021446dc 100644 --- a/editor/plugins/light_occluder_2d_editor_plugin.cpp +++ b/editor/plugins/light_occluder_2d_editor_plugin.cpp @@ -118,7 +118,7 @@ bool LightOccluder2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Vector2 gpoint = mb->get_pos(); + Vector2 gpoint = mb->get_position(); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); cpoint = canvas_item_editor->snap_point(cpoint); cpoint = node->get_global_transform().affine_inverse().xform(cpoint); @@ -308,7 +308,7 @@ bool LightOccluder2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { if (edited_point != -1 && (wip_active || mm->get_button_mask() & BUTTON_MASK_LEFT)) { - Vector2 gpoint = mm->get_pos(); + Vector2 gpoint = mm->get_position(); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); cpoint = canvas_item_editor->snap_point(cpoint); edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); diff --git a/editor/plugins/line_2d_editor_plugin.cpp b/editor/plugins/line_2d_editor_plugin.cpp index 3497af3602..76906a5b93 100644 --- a/editor/plugins/line_2d_editor_plugin.cpp +++ b/editor/plugins/line_2d_editor_plugin.cpp @@ -87,7 +87,7 @@ bool Line2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { if (mb.is_valid()) { - Vector2 gpoint = mb->get_pos(); + Vector2 gpoint = mb->get_position(); Vector2 cpoint = mouse_to_local_pos(gpoint, mb->get_alt()); if (mb->is_pressed() && _dragging == false) { @@ -146,7 +146,7 @@ bool Line2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { if (mm.is_valid()) { if (_dragging) { - Vector2 cpoint = mouse_to_local_pos(mm->get_pos(), mm->get_alt()); + Vector2 cpoint = mouse_to_local_pos(mm->get_position(), mm->get_alt()); node->set_point_pos(action_point, cpoint); canvas_item_editor->get_viewport_control()->update(); return true; diff --git a/editor/plugins/navigation_polygon_editor_plugin.cpp b/editor/plugins/navigation_polygon_editor_plugin.cpp index a7fc1d5adb..1457b28ed1 100644 --- a/editor/plugins/navigation_polygon_editor_plugin.cpp +++ b/editor/plugins/navigation_polygon_editor_plugin.cpp @@ -134,7 +134,7 @@ bool NavigationPolygonEditor::forward_gui_input(const Ref<InputEvent> &p_event) Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Vector2 gpoint = mb->get_pos(); + Vector2 gpoint = mb->get_position(); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); cpoint = canvas_item_editor->snap_point(cpoint); cpoint = node->get_global_transform().affine_inverse().xform(cpoint); @@ -361,7 +361,7 @@ bool NavigationPolygonEditor::forward_gui_input(const Ref<InputEvent> &p_event) if (edited_point != -1 && (wip_active || mm->get_button_mask() & BUTTON_MASK_LEFT)) { - Vector2 gpoint = mm->get_pos(); + Vector2 gpoint = mm->get_position(); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); cpoint = canvas_item_editor->snap_point(cpoint); edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp index 73d5b28886..f9f16fea16 100644 --- a/editor/plugins/path_2d_editor_plugin.cpp +++ b/editor/plugins/path_2d_editor_plugin.cpp @@ -74,7 +74,7 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Vector2 gpoint = mb->get_pos(); + Vector2 gpoint = mb->get_position(); Vector2 cpoint = !mb->get_alt() ? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : @@ -431,7 +431,7 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { if (action != ACTION_NONE) { // Handle point/control movement. Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Vector2 gpoint = mm->get_pos(); + Vector2 gpoint = mm->get_position(); Vector2 cpoint = !mm->get_alt() ? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : diff --git a/editor/plugins/path_editor_plugin.cpp b/editor/plugins/path_editor_plugin.cpp index 20535d796e..877707d77b 100644 --- a/editor/plugins/path_editor_plugin.cpp +++ b/editor/plugins/path_editor_plugin.cpp @@ -285,7 +285,7 @@ bool PathEditorPlugin::forward_spatial_gui_input(Camera *p_camera, const Ref<Inp if (mb.is_valid()) { - Point2 mbpos(mb->get_pos().x, mb->get_pos().y); + Point2 mbpos(mb->get_position().x, mb->get_position().y); if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && (curve_create->is_pressed() || (curve_edit->is_pressed() && mb->get_control()))) { //click into curve, break it down diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index c2edc608ab..dd13ca0e63 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -212,7 +212,7 @@ bool Polygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Vector2 gpoint = mb->get_pos(); + Vector2 gpoint = mb->get_position(); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); cpoint = canvas_item_editor->snap_point(cpoint); cpoint = node->get_global_transform().affine_inverse().xform(cpoint); @@ -397,7 +397,7 @@ bool Polygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { if (edited_point != -1 && (wip_active || mm->get_button_mask() & BUTTON_MASK_LEFT)) { - Vector2 gpoint = mm->get_pos(); + Vector2 gpoint = mm->get_position(); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); cpoint = canvas_item_editor->snap_point(cpoint); edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); @@ -465,7 +465,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { if (mb->is_pressed()) { - uv_drag_from = Vector2(mb->get_pos().x, mb->get_pos().y); + uv_drag_from = Vector2(mb->get_position().x, mb->get_position().y); uv_drag = true; uv_prev = node->get_uv(); uv_move_current = uv_mode; @@ -485,7 +485,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { for (int i = 0; i < uv_prev.size(); i++) { Vector2 tuv = mtx.xform(uv_prev[i]); - if (tuv.distance_to(Vector2(mb->get_pos().x, mb->get_pos().y)) < 8) { + if (tuv.distance_to(Vector2(mb->get_position().x, mb->get_position().y)) < 8) { uv_drag_from = tuv; uv_drag_index = i; } @@ -537,7 +537,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { } else if (uv_drag) { - Vector2 uv_drag_to = mm->get_pos(); + Vector2 uv_drag_to = mm->get_position(); Vector2 drag = mtx.affine_inverse().xform(uv_drag_to) - mtx.affine_inverse().xform(uv_drag_from); switch (uv_move_current) { @@ -675,14 +675,14 @@ void Polygon2DEditor::_uv_draw() { rect = rect.grow(200); updating_uv_scroll = true; - uv_hscroll->set_min(rect.pos.x); - uv_hscroll->set_max(rect.pos.x + rect.size.x); + uv_hscroll->set_min(rect.position.x); + uv_hscroll->set_max(rect.position.x + rect.size.x); uv_hscroll->set_page(uv_edit_draw->get_size().x); uv_hscroll->set_value(uv_draw_ofs.x); uv_hscroll->set_step(0.001); - uv_vscroll->set_min(rect.pos.y); - uv_vscroll->set_max(rect.pos.y + rect.size.y); + uv_vscroll->set_min(rect.position.y); + uv_vscroll->set_max(rect.position.y + rect.size.y); uv_vscroll->set_page(uv_edit_draw->get_size().y); uv_vscroll->set_value(uv_draw_ofs.y); uv_vscroll->set_step(0.001); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index fde6d83aa8..f3941d6a16 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -410,7 +410,9 @@ void ScriptEditor::_go_to_tab(int p_idx) { c->set_meta("__editor_pass", ++edit_pass); _update_history_arrows(); _update_script_colors(); + _update_members_overview(); _update_selected_editor_menu(); + _update_members_overview_visibility(); } void ScriptEditor::_add_recent_script(String p_path) { @@ -540,6 +542,7 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save) { _update_history_arrows(); _update_script_names(); + _update_members_overview_visibility(); _save_layout(); } @@ -1025,6 +1028,7 @@ void ScriptEditor::_notification(int p_what) { editor->connect("script_add_function_request", this, "_add_callback"); editor->connect("resource_saved", this, "_res_saved_callback"); script_list->connect("item_selected", this, "_script_selected"); + members_overview->connect("item_selected", this, "_members_overview_selected"); script_split->connect("dragged", this, "_script_split_dragged"); autosave_timer->connect("timeout", this, "_autosave_scripts"); { @@ -1273,6 +1277,16 @@ void ScriptEditor::ensure_focus_current() { se->ensure_focus(); } +void ScriptEditor::_members_overview_selected(int p_idx) { + Node *current = tab_container->get_child(tab_container->get_current_tab()); + ScriptEditorBase *se = current->cast_to<ScriptEditorBase>(); + if (!se) { + return; + } + se->goto_line(members_overview->get_item_metadata(p_idx)); + se->ensure_focus(); +} + void ScriptEditor::_script_selected(int p_idx) { grab_focus_block = !Input::get_singleton()->is_mouse_button_pressed(1); //amazing hack, simply amazing @@ -1342,6 +1356,37 @@ struct _ScriptEditorItemData { } }; +void ScriptEditor::_update_members_overview_visibility() { + Node *current = tab_container->get_child(tab_container->get_current_tab()); + ScriptEditorBase *se = current->cast_to<ScriptEditorBase>(); + if (!se) { + members_overview->set_visible(false); + return; + } + + if (members_overview_enabled && se->show_members_overview()) { + members_overview->set_visible(true); + } else { + members_overview->set_visible(false); + } +} + +void ScriptEditor::_update_members_overview() { + members_overview->clear(); + + Node *current = tab_container->get_child(tab_container->get_current_tab()); + ScriptEditorBase *se = current->cast_to<ScriptEditorBase>(); + if (!se) { + return; + } + + Vector<String> functions = se->get_functions(); + for (int i = 0; i < functions.size(); i++) { + members_overview->add_item(functions[i].get_slice(":", 0)); + members_overview->set_item_metadata(i, functions[i].get_slice(":", 1).to_int() - 1); + } +} + void ScriptEditor::_update_script_colors() { bool script_temperature_enabled = EditorSettings::get_singleton()->get("text_editor/open_scripts/script_temperature_enabled"); @@ -1485,6 +1530,7 @@ void ScriptEditor::_update_script_names() { } } + _update_members_overview(); _update_script_colors(); } @@ -1733,6 +1779,9 @@ void ScriptEditor::_editor_settings_changed() { convert_indent_on_save = EditorSettings::get_singleton()->get("text_editor/indent/convert_indent_on_save"); use_space_indentation = EditorSettings::get_singleton()->get("text_editor/indent/type"); + members_overview_enabled = EditorSettings::get_singleton()->get("text_editor/open_scripts/show_members_overview"); + _update_members_overview_visibility(); + float autosave_time = EditorSettings::get_singleton()->get("text_editor/files/autosave_interval_secs"); if (autosave_time > 0) { autosave_timer->set_wait_time(autosave_time); @@ -2084,6 +2133,7 @@ void ScriptEditor::_bind_methods() { ClassDB::bind_method("_editor_settings_changed", &ScriptEditor::_editor_settings_changed); ClassDB::bind_method("_update_script_names", &ScriptEditor::_update_script_names); ClassDB::bind_method("_tree_changed", &ScriptEditor::_tree_changed); + ClassDB::bind_method("_members_overview_selected", &ScriptEditor::_members_overview_selected); ClassDB::bind_method("_script_selected", &ScriptEditor::_script_selected); ClassDB::bind_method("_script_created", &ScriptEditor::_script_created); ClassDB::bind_method("_script_split_dragged", &ScriptEditor::_script_split_dragged); @@ -2105,6 +2155,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { waiting_update_names = false; pending_auto_reload = false; auto_reload_running_scripts = false; + members_overview_enabled = true; editor = p_editor; menu_hb = memnew(HBoxContainer); @@ -2114,10 +2165,19 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { add_child(script_split); script_split->set_v_size_flags(SIZE_EXPAND_FILL); + list_split = memnew(VSplitContainer); + script_split->add_child(list_split); + list_split->set_v_size_flags(SIZE_EXPAND_FILL); + script_list = memnew(ItemList); - script_split->add_child(script_list); + list_split->add_child(script_list); script_list->set_custom_minimum_size(Size2(0, 0)); script_split->set_split_offset(140); + list_split->set_split_offset(500); + + members_overview = memnew(ItemList); + list_split->add_child(members_overview); + members_overview->set_custom_minimum_size(Size2(0, 0)); tab_container = memnew(TabContainer); tab_container->add_style_override("panel", p_editor->get_gui_base()->get_stylebox("ScriptPanel", "EditorStyles")); diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 455a888f0e..e036d1ed9c 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -102,6 +102,8 @@ public: virtual void set_debugger_active(bool p_active) = 0; virtual bool can_lose_focus_on_node_selection() { return true; } + virtual bool show_members_overview() = 0; + virtual void set_tooltip_request_func(String p_method, Object *p_obj) = 0; virtual Control *get_edit_menu() = 0; @@ -179,6 +181,9 @@ class ScriptEditor : public VBoxContainer { ItemList *script_list; HSplitContainer *script_split; + ItemList *members_overview; + bool members_overview_enabled; + VSplitContainer *list_split; TabContainer *tab_container; EditorFileDialog *file_dialog; ConfirmationDialog *erase_tab_confirm; @@ -278,8 +283,11 @@ class ScriptEditor : public VBoxContainer { void _editor_settings_changed(); void _autosave_scripts(); + void _update_members_overview_visibility(); + void _update_members_overview(); void _update_script_names(); + void _members_overview_selected(int p_idx); void _script_selected(int p_idx); void _find_scripts(Node *p_base, Node *p_current, Set<Ref<Script> > &used); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 2d3a14e525..9f76119374 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -218,6 +218,10 @@ void ScriptTextEditor::add_callback(const String &p_function, PoolStringArray p_ code_editor->get_text_edit()->cursor_set_column(1); } +bool ScriptTextEditor::show_members_overview() { + return true; +} + void ScriptTextEditor::update_settings() { code_editor->update_editor_settings(); @@ -1236,8 +1240,8 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { int col, row; TextEdit *tx = code_editor->get_text_edit(); - tx->_get_mouse_pos(mb->get_global_pos() - tx->get_global_position(), row, col); - Vector2 mpos = mb->get_global_pos() - tx->get_global_position(); + tx->_get_mouse_pos(mb->get_global_position() - tx->get_global_position(), row, col); + Vector2 mpos = mb->get_global_position() - tx->get_global_position(); bool have_selection = (tx->get_selection_text().length() > 0); bool have_color = (tx->get_word_at_pos(mpos) == "Color"); if (have_color) { diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index fdae03949c..ba40645161 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -149,6 +149,8 @@ public: virtual void add_callback(const String &p_function, PoolStringArray p_args); virtual void update_settings(); + virtual bool show_members_overview(); + virtual void set_tooltip_request_func(String p_method, Object *p_obj); virtual void set_debugger_active(bool p_active); diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index ff4b5e430e..61f6880433 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -636,7 +636,7 @@ void SpatialEditorViewport::_smouseenter() { void SpatialEditorViewport::_list_select(Ref<InputEventMouseButton> b) { - _find_items_at_pos(b->get_pos(), clicked_includes_current, selection_results, b->get_shift()); + _find_items_at_pos(b->get_position(), clicked_includes_current, selection_results, b->get_shift()); Node *scene = editor->get_edited_scene(); @@ -684,7 +684,7 @@ void SpatialEditorViewport::_list_select(Ref<InputEventMouseButton> b) { selection_menu->set_item_tooltip(i, String(spat->get_name()) + "\nType: " + spat->get_class() + "\nPath: " + node_path); } - selection_menu->set_global_position(b->get_global_pos()); + selection_menu->set_global_position(b->get_global_position()); selection_menu->popup(); selection_menu->call_deferred("grab_click_focus"); selection_menu->set_invalidate_click_until_motion(); @@ -818,7 +818,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { break; } - _edit.mouse_pos = b->get_pos(); + _edit.mouse_pos = b->get_position(); _edit.snap = false; _edit.mode = TRANSFORM_NONE; @@ -863,7 +863,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { break; //bye //handle rotate _edit.mode = TRANSFORM_ROTATE; - _compute_edit(b->get_pos()); + _compute_edit(b->get_position()); break; } @@ -873,7 +873,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { break; //bye //handle rotate _edit.mode = TRANSFORM_TRANSLATE; - _compute_edit(b->get_pos()); + _compute_edit(b->get_position()); break; } @@ -883,7 +883,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { break; //bye //handle rotate _edit.mode = TRANSFORM_SCALE; - _compute_edit(b->get_pos()); + _compute_edit(b->get_position()); break; } @@ -891,7 +891,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { int gizmo_handle = -1; - clicked = _select_ray(b->get_pos(), b->get_shift(), clicked_includes_current, &gizmo_handle, b->get_shift()); + clicked = _select_ray(b->get_position(), b->get_shift(), clicked_includes_current, &gizmo_handle, b->get_shift()); //clicking is always deferred to either move or release @@ -904,8 +904,8 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { //default to regionselect cursor.region_select = true; - cursor.region_begin = b->get_pos(); - cursor.region_end = b->get_pos(); + cursor.region_begin = b->get_position(); + cursor.region_end = b->get_position(); } if (clicked && gizmo_handle >= 0) { @@ -989,7 +989,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { if (m.is_valid()) { - _edit.mouse_pos = m->get_pos(); + _edit.mouse_pos = m->get_position(); if (spatial_editor->get_selected()) { @@ -1026,7 +1026,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { if (_edit.gizmo.is_valid()) { - _edit.gizmo->set_handle(_edit.gizmo_handle, camera, m->get_pos()); + _edit.gizmo->set_handle(_edit.gizmo_handle, camera, m->get_position()); Variant v = _edit.gizmo->get_handle_value(_edit.gizmo_handle); String n = _edit.gizmo->get_handle_name(_edit.gizmo_handle); set_message(n + ": " + String(v)); @@ -1058,7 +1058,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { if (cursor.region_select && nav_mode == NAVIGATION_NONE) { - cursor.region_end = m->get_pos(); + cursor.region_end = m->get_position(); surface->update(); return; } @@ -1066,8 +1066,8 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { if (_edit.mode == TRANSFORM_NONE && nav_mode == NAVIGATION_NONE) return; - Vector3 ray_pos = _get_ray_pos(m->get_pos()); - Vector3 ray = _get_ray(m->get_pos()); + Vector3 ray_pos = _get_ray_pos(m->get_position()); + Vector3 ray = _get_ray(m->get_position()); switch (_edit.mode) { @@ -1752,10 +1752,10 @@ static void stroke_rect(CanvasItem *ci, Rect2 rect, Color color, real_t width = // a---b // | | // c---d - Vector2 a(rect.pos); - Vector2 b(rect.pos.x + rect.size.x, rect.pos.y); - Vector2 c(rect.pos.x, rect.pos.y + rect.size.y); - Vector2 d(rect.pos + rect.size); + Vector2 a(rect.position); + Vector2 b(rect.position.x + rect.size.x, rect.position.y); + Vector2 c(rect.position.x, rect.position.y + rect.size.y); + Vector2 d(rect.position + rect.size); ci->draw_line(a, b, color, width); ci->draw_line(b, d, color, width); @@ -1804,15 +1804,15 @@ void SpatialEditorViewport::_draw() { case Camera::KEEP_WIDTH: { draw_rect.size = Size2(s.width, s.width / aspect); - draw_rect.pos.x = 0; - draw_rect.pos.y = (s.height - draw_rect.size.y) * 0.5; + draw_rect.position.x = 0; + draw_rect.position.y = (s.height - draw_rect.size.y) * 0.5; } break; case Camera::KEEP_HEIGHT: { draw_rect.size = Size2(s.height * aspect, s.height); - draw_rect.pos.y = 0; - draw_rect.pos.x = (s.width - draw_rect.size.x) * 0.5; + draw_rect.position.y = 0; + draw_rect.position.x = (s.width - draw_rect.size.x) * 0.5; } break; } @@ -1846,7 +1846,7 @@ void SpatialEditorViewport::_draw() { real_t sy = r.size.y * logscale_t; surface->draw_rect(r, Color(1, 1, 1, 0.2)); - surface->draw_rect(Rect2(r.pos.x, r.pos.y + r.size.y - sy, r.size.x, sy), Color(1, 1, 1, 0.6)); + surface->draw_rect(Rect2(r.position.x, r.position.y + r.size.y - sy, r.size.x, sy), Color(1, 1, 1, 0.6)); stroke_rect(surface, r.grow(1), Color(0, 0, 0, 0.7)); } } @@ -3055,8 +3055,8 @@ void SpatialEditor::_init_indicators() { for (int i = 0; i < 3; i++) { - move_gizmo[i] = Ref<Mesh>(memnew(Mesh)); - rotate_gizmo[i] = Ref<Mesh>(memnew(Mesh)); + move_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh)); + rotate_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh)); Ref<SpatialMaterial> mat = memnew(SpatialMaterial); mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index 88245ad0dc..394002db3b 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -330,13 +330,13 @@ private: bool grid_enable[3]; //should be always visible if true bool grid_enabled; - Ref<Mesh> move_gizmo[3], rotate_gizmo[3]; + Ref<ArrayMesh> move_gizmo[3], rotate_gizmo[3]; Ref<SpatialMaterial> gizmo_color[3]; Ref<SpatialMaterial> gizmo_hl; int over_gizmo_handle; - Ref<Mesh> selection_box; + Ref<ArrayMesh> selection_box; RID indicators; RID indicators_instance; RID cursor_mesh; @@ -472,8 +472,8 @@ public: float get_rotate_snap() const { return snap_rotate->get_text().to_double(); } float get_scale_snap() const { return snap_scale->get_text().to_double(); } - Ref<Mesh> get_move_gizmo(int idx) const { return move_gizmo[idx]; } - Ref<Mesh> get_rotate_gizmo(int idx) const { return rotate_gizmo[idx]; } + Ref<ArrayMesh> get_move_gizmo(int idx) const { return move_gizmo[idx]; } + Ref<ArrayMesh> get_rotate_gizmo(int idx) const { return rotate_gizmo[idx]; } void update_transform_gizmo(); diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index 799bfbf358..976a7b6271 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -114,10 +114,10 @@ void TextureRegionEditor::_region_draw() { for (List<Rect2>::Element *E = autoslice_cache.front(); E; E = E->next()) { Rect2 r = E->get(); Vector2 endpoints[4] = { - mtx.basis_xform(r.pos), - mtx.basis_xform(r.pos + Vector2(r.size.x, 0)), - mtx.basis_xform(r.pos + r.size), - mtx.basis_xform(r.pos + Vector2(0, r.size.y)) + mtx.basis_xform(r.position), + mtx.basis_xform(r.position + Vector2(r.size.x, 0)), + mtx.basis_xform(r.position + r.size), + mtx.basis_xform(r.position + Vector2(0, r.size.y)) }; for (int i = 0; i < 4; i++) { int next = (i + 1) % 4; @@ -132,10 +132,10 @@ void TextureRegionEditor::_region_draw() { scroll_rect.expand_to(mtx.basis_xform(edit_draw->get_size())); Vector2 endpoints[4] = { - mtx.basis_xform(rect.pos), - mtx.basis_xform(rect.pos + Vector2(rect.size.x, 0)), - mtx.basis_xform(rect.pos + rect.size), - mtx.basis_xform(rect.pos + Vector2(0, rect.size.y)) + mtx.basis_xform(rect.position), + mtx.basis_xform(rect.position + Vector2(rect.size.x, 0)), + mtx.basis_xform(rect.position + rect.size), + mtx.basis_xform(rect.position + Vector2(0, rect.size.y)) }; Color color(0.9, 0.5, 0.5); for (int i = 0; i < 4; i++) { @@ -162,14 +162,14 @@ void TextureRegionEditor::_region_draw() { scroll_rect = scroll_rect.grow(200); updating_scroll = true; - hscroll->set_min(scroll_rect.pos.x); - hscroll->set_max(scroll_rect.pos.x + scroll_rect.size.x); + hscroll->set_min(scroll_rect.position.x); + hscroll->set_max(scroll_rect.position.x + scroll_rect.size.x); hscroll->set_page(edit_draw->get_size().x); hscroll->set_value(draw_ofs.x); hscroll->set_step(0.001); - vscroll->set_min(scroll_rect.pos.y); - vscroll->set_max(scroll_rect.pos.y + scroll_rect.size.y); + vscroll->set_min(scroll_rect.position.y); + vscroll->set_max(scroll_rect.position.y + scroll_rect.size.y); vscroll->set_page(edit_draw->get_size().y); vscroll->set_value(draw_ofs.y); vscroll->set_step(0.001); @@ -208,14 +208,14 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { mtx.scale_basis(Vector2(draw_zoom, draw_zoom)); Vector2 endpoints[8] = { - mtx.xform(rect.pos) + Vector2(-4, -4), - mtx.xform(rect.pos + Vector2(rect.size.x / 2, 0)) + Vector2(0, -4), - mtx.xform(rect.pos + Vector2(rect.size.x, 0)) + Vector2(4, -4), - mtx.xform(rect.pos + Vector2(rect.size.x, rect.size.y / 2)) + Vector2(4, 0), - mtx.xform(rect.pos + rect.size) + Vector2(4, 4), - mtx.xform(rect.pos + Vector2(rect.size.x / 2, rect.size.y)) + Vector2(0, 4), - mtx.xform(rect.pos + Vector2(0, rect.size.y)) + Vector2(-4, 4), - mtx.xform(rect.pos + Vector2(0, rect.size.y / 2)) + Vector2(-4, 0) + mtx.xform(rect.position) + Vector2(-4, -4), + mtx.xform(rect.position + Vector2(rect.size.x / 2, 0)) + Vector2(0, -4), + mtx.xform(rect.position + Vector2(rect.size.x, 0)) + Vector2(4, -4), + mtx.xform(rect.position + Vector2(rect.size.x, rect.size.y / 2)) + Vector2(4, 0), + mtx.xform(rect.position + rect.size) + Vector2(4, 4), + mtx.xform(rect.position + Vector2(rect.size.x / 2, rect.size.y)) + Vector2(0, 4), + mtx.xform(rect.position + Vector2(0, rect.size.y)) + Vector2(-4, 4), + mtx.xform(rect.position + Vector2(0, rect.size.y / 2)) + Vector2(-4, 0) }; Ref<InputEventMouseButton> mb; @@ -239,31 +239,31 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { margins[3] = obj_styleBox->get_margin_size(MARGIN_RIGHT); } Vector2 pos[4] = { - mtx.basis_xform(rect.pos + Vector2(0, margins[0])) - draw_ofs, - mtx.basis_xform(rect.pos + rect.size - Vector2(0, margins[1])) - draw_ofs, - mtx.basis_xform(rect.pos + Vector2(margins[2], 0)) - draw_ofs, - mtx.basis_xform(rect.pos + rect.size - Vector2(margins[3], 0)) - draw_ofs + mtx.basis_xform(rect.position + Vector2(0, margins[0])) - draw_ofs, + mtx.basis_xform(rect.position + rect.size - Vector2(0, margins[1])) - draw_ofs, + mtx.basis_xform(rect.position + Vector2(margins[2], 0)) - draw_ofs, + mtx.basis_xform(rect.position + rect.size - Vector2(margins[3], 0)) - draw_ofs }; - if (Math::abs(mb->get_pos().y - pos[0].y) < 8) { + if (Math::abs(mb->get_position().y - pos[0].y) < 8) { edited_margin = 0; prev_margin = margins[0]; - } else if (Math::abs(mb->get_pos().y - pos[1].y) < 8) { + } else if (Math::abs(mb->get_position().y - pos[1].y) < 8) { edited_margin = 1; prev_margin = margins[1]; - } else if (Math::abs(mb->get_pos().x - pos[2].x) < 8) { + } else if (Math::abs(mb->get_position().x - pos[2].x) < 8) { edited_margin = 2; prev_margin = margins[2]; - } else if (Math::abs(mb->get_pos().x - pos[3].x) < 8) { + } else if (Math::abs(mb->get_position().x - pos[3].x) < 8) { edited_margin = 3; prev_margin = margins[3]; } if (edited_margin >= 0) { - drag_from = Vector2(mb->get_pos().x, mb->get_pos().y); + drag_from = Vector2(mb->get_position().x, mb->get_position().y); drag = true; } } if (edited_margin < 0 && snap_mode == SNAP_AUTOSLICE) { - Vector2 point = mtx.affine_inverse().xform(Vector2(mb->get_pos().x, mb->get_pos().y)); + Vector2 point = mtx.affine_inverse().xform(Vector2(mb->get_position().x, mb->get_position().y)); for (List<Rect2>::Element *E = autoslice_cache.front(); E; E = E->next()) { if (E->get().has_point(point)) { rect = E->get(); @@ -277,8 +277,8 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { r = obj_styleBox->get_region_rect(); else if (atlas_tex.is_valid()) r = atlas_tex->get_region(); - rect.expand_to(r.pos); - rect.expand_to(r.pos + r.size); + rect.expand_to(r.position); + rect.expand_to(r.position + r.size); } undo_redo->create_action("Set Region Rect"); if (node_sprite) { @@ -301,7 +301,7 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { } } } else if (edited_margin < 0) { - drag_from = mtx.affine_inverse().xform(Vector2(mb->get_pos().x, mb->get_pos().y)); + drag_from = mtx.affine_inverse().xform(Vector2(mb->get_position().x, mb->get_position().y)); if (snap_mode == SNAP_PIXEL) drag_from = drag_from.snapped(Vector2(1, 1)); else if (snap_mode == SNAP_GRID) @@ -318,7 +318,7 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { for (int i = 0; i < 8; i++) { Vector2 tuv = endpoints[i]; - if (tuv.distance_to(Vector2(mb->get_pos().x, mb->get_pos().y)) < 8) { + if (tuv.distance_to(Vector2(mb->get_position().x, mb->get_position().y)) < 8) { drag_index = i; } } @@ -408,13 +408,13 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { if (edited_margin >= 0) { float new_margin; if (edited_margin == 0) - new_margin = prev_margin + (mm->get_pos().y - drag_from.y) / draw_zoom; + new_margin = prev_margin + (mm->get_position().y - drag_from.y) / draw_zoom; else if (edited_margin == 1) - new_margin = prev_margin - (mm->get_pos().y - drag_from.y) / draw_zoom; + new_margin = prev_margin - (mm->get_position().y - drag_from.y) / draw_zoom; else if (edited_margin == 2) - new_margin = prev_margin + (mm->get_pos().x - drag_from.x) / draw_zoom; + new_margin = prev_margin + (mm->get_position().x - drag_from.x) / draw_zoom; else if (edited_margin == 3) - new_margin = prev_margin - (mm->get_pos().x - drag_from.x) / draw_zoom; + new_margin = prev_margin - (mm->get_position().x - drag_from.x) / draw_zoom; if (new_margin < 0) new_margin = 0; static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT }; @@ -423,7 +423,7 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { if (obj_styleBox.is_valid()) obj_styleBox->set_margin_size(m[edited_margin], new_margin); } else { - Vector2 new_pos = mtx.affine_inverse().xform(mm->get_pos()); + Vector2 new_pos = mtx.affine_inverse().xform(mm->get_position()); if (snap_mode == SNAP_PIXEL) new_pos = new_pos.snapped(Vector2(1, 1)); else if (snap_mode == SNAP_GRID) @@ -439,49 +439,49 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { switch (drag_index) { case 0: { - Vector2 p = rect_prev.pos + rect_prev.size; + Vector2 p = rect_prev.position + rect_prev.size; rect = Rect2(p, Size2()); rect.expand_to(new_pos); apply_rect(rect); } break; case 1: { - Vector2 p = rect_prev.pos + Vector2(0, rect_prev.size.y); + Vector2 p = rect_prev.position + Vector2(0, rect_prev.size.y); rect = Rect2(p, Size2(rect_prev.size.x, 0)); rect.expand_to(new_pos); apply_rect(rect); } break; case 2: { - Vector2 p = rect_prev.pos + Vector2(0, rect_prev.size.y); + Vector2 p = rect_prev.position + Vector2(0, rect_prev.size.y); rect = Rect2(p, Size2()); rect.expand_to(new_pos); apply_rect(rect); } break; case 3: { - Vector2 p = rect_prev.pos; + Vector2 p = rect_prev.position; rect = Rect2(p, Size2(0, rect_prev.size.y)); rect.expand_to(new_pos); apply_rect(rect); } break; case 4: { - Vector2 p = rect_prev.pos; + Vector2 p = rect_prev.position; rect = Rect2(p, Size2()); rect.expand_to(new_pos); apply_rect(rect); } break; case 5: { - Vector2 p = rect_prev.pos; + Vector2 p = rect_prev.position; rect = Rect2(p, Size2(rect_prev.size.x, 0)); rect.expand_to(new_pos); apply_rect(rect); } break; case 6: { - Vector2 p = rect_prev.pos + Vector2(rect_prev.size.x, 0); + Vector2 p = rect_prev.position + Vector2(rect_prev.size.x, 0); rect = Rect2(p, Size2()); rect.expand_to(new_pos); apply_rect(rect); } break; case 7: { - Vector2 p = rect_prev.pos + Vector2(rect_prev.size.x, 0); + Vector2 p = rect_prev.position + Vector2(rect_prev.size.x, 0); rect = Rect2(p, Size2(0, rect_prev.size.y)); rect.expand_to(new_pos); apply_rect(rect); @@ -693,7 +693,7 @@ void TextureRegionEditor::_edit_region() { if (grown.has_point(Point2(x, y))) { E->get().expand_to(Point2(x, y)); E->get().expand_to(Point2(x + 1, y + 1)); - x = E->get().pos.x + E->get().size.x - 1; + x = E->get().position.x + E->get().size.x - 1; bool merged = true; while (merged) { merged = false; @@ -706,8 +706,8 @@ void TextureRegionEditor::_edit_region() { if (F == E) continue; if (E->get().grow(1).intersects(F->get())) { - E->get().expand_to(F->get().pos); - E->get().expand_to(F->get().pos + F->get().size); + E->get().expand_to(F->get().position); + E->get().expand_to(F->get().position + F->get().size); if (F->prev()) { F = F->prev(); autoslice_cache.erase(F->next()); diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp index 9f7a41b8b6..d12b979121 100644 --- a/editor/plugins/tile_map_editor_plugin.cpp +++ b/editor/plugins/tile_map_editor_plugin.cpp @@ -98,8 +98,8 @@ void TileMapEditor::_menu_option(int p_option) { return; undo_redo->create_action("Erase Selection"); - for (int i = rectangle.pos.y; i <= rectangle.pos.y + rectangle.size.y; i++) { - for (int j = rectangle.pos.x; j <= rectangle.pos.x + rectangle.size.x; j++) { + for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { + for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { _set_cell(Point2i(j, i), TileMap::INVALID_CELL, false, false, false, true); } @@ -333,7 +333,7 @@ PoolVector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool era } Rect2i r = node->get_item_rect(); - r.pos = r.pos / node->get_cell_size(); + r.position = r.position / node->get_cell_size(); r.size = r.size / node->get_cell_size(); int area = r.get_area(); @@ -349,7 +349,7 @@ PoolVector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool era invalidate_cache = true; } // Tile ID changed or position wasn't visited by the previous fill - int loc = (p_start.x - r.get_pos().x) + (p_start.y - r.get_pos().y) * r.get_size().x; + int loc = (p_start.x - r.position.x) + (p_start.y - r.position.y) * r.get_size().x; if (prev_id != bucket_cache_tile || !bucket_cache_visited[loc]) { invalidate_cache = true; } @@ -380,7 +380,7 @@ PoolVector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool era if (node->get_cell(n.x, n.y) == prev_id) { if (preview) { - int loc = (n.x - r.get_pos().x) + (n.y - r.get_pos().y) * r.get_size().x; + int loc = (n.x - r.position.x) + (n.y - r.position.y) * r.get_size().x; if (bucket_cache_visited[loc]) continue; bucket_cache_visited[loc] = true; @@ -441,7 +441,7 @@ void TileMapEditor::_select(const Point2i &p_from, const Point2i &p_to) { SWAP(begin.y, end.y); } - rectangle.pos = begin; + rectangle.position = begin; rectangle.size = end - begin; canvas_item_editor->update(); @@ -460,7 +460,7 @@ void TileMapEditor::_draw_cell(int p_cell, const Point2i &p_point, bool p_flip_h Size2 sc = p_xform.get_scale(); Rect2 rect = Rect2(); - rect.pos = node->map_to_world(p_point) + node->get_cell_draw_offset(); + rect.position = node->map_to_world(p_point) + node->get_cell_draw_offset(); if (r.has_no_area()) { rect.size = t->get_size(); @@ -490,42 +490,42 @@ void TileMapEditor::_draw_cell(int p_cell, const Point2i &p_point, bool p_flip_h if (node->get_tile_origin() == TileMap::TILE_ORIGIN_TOP_LEFT) { - rect.pos += tile_ofs; + rect.position += tile_ofs; } else if (node->get_tile_origin() == TileMap::TILE_ORIGIN_BOTTOM_LEFT) { Size2 cell_size = node->get_cell_size(); - rect.pos += tile_ofs; + rect.position += tile_ofs; if (p_transpose) { if (p_flip_h) - rect.pos.x -= cell_size.x; + rect.position.x -= cell_size.x; else - rect.pos.x += cell_size.x; + rect.position.x += cell_size.x; } else { if (p_flip_v) - rect.pos.y -= cell_size.y; + rect.position.y -= cell_size.y; else - rect.pos.y += cell_size.y; + rect.position.y += cell_size.y; } } else if (node->get_tile_origin() == TileMap::TILE_ORIGIN_CENTER) { - rect.pos += node->get_cell_size() / 2; + rect.position += node->get_cell_size() / 2; Vector2 s = r.size; Vector2 center = (s / 2) - tile_ofs; if (p_flip_h) - rect.pos.x -= s.x - center.x; + rect.position.x -= s.x - center.x; else - rect.pos.x -= center.x; + rect.position.x -= center.x; if (p_flip_v) - rect.pos.y -= s.y - center.y; + rect.position.y -= s.y - center.y; else - rect.pos.y -= center.y; + rect.position.y -= center.y; } - rect.pos = p_xform.xform(rect.pos); + rect.position = p_xform.xform(rect.position); rect.size *= sc; if (r.has_no_area()) @@ -560,9 +560,9 @@ void TileMapEditor::_update_copydata() { if (!selection_active) return; - for (int i = rectangle.pos.y; i <= rectangle.pos.y + rectangle.size.y; i++) { + for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { - for (int j = rectangle.pos.x; j <= rectangle.pos.x + rectangle.size.x; j++) { + for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { TileData tcd; @@ -737,8 +737,8 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { if (id != TileMap::INVALID_CELL) { undo_redo->create_action("Rectangle Paint"); - for (int i = rectangle.pos.y; i <= rectangle.pos.y + rectangle.size.y; i++) { - for (int j = rectangle.pos.x; j <= rectangle.pos.x + rectangle.size.x; j++) { + for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { + for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { _set_cell(Point2i(j, i), id, flip_h, flip_v, transpose, true); } @@ -749,7 +749,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } } else if (tool == TOOL_DUPLICATING) { - Point2 ofs = over_tile - rectangle.pos; + Point2 ofs = over_tile - rectangle.position; undo_redo->create_action(TTR("Duplicate")); for (List<TileData>::Element *E = copydata.front(); E; E = E->next()) { @@ -826,7 +826,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { paint_undo.clear(); - Point2 local = node->world_to_map(xform_inv.xform(mb->get_pos())); + Point2 local = node->world_to_map(xform_inv.xform(mb->get_position())); if (mb->get_shift()) { @@ -900,7 +900,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { if (mm.is_valid()) { - Point2i new_over_tile = node->world_to_map(xform_inv.xform(mm->get_pos())); + Point2i new_over_tile = node->world_to_map(xform_inv.xform(mm->get_position())); if (new_over_tile != over_tile) { @@ -985,8 +985,8 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { paint_undo.clear(); - for (int i = rectangle.pos.y; i <= rectangle.pos.y + rectangle.size.y; i++) { - for (int j = rectangle.pos.x; j <= rectangle.pos.x + rectangle.size.x; j++) { + for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { + for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { Point2i tile = Point2i(j, i); paint_undo[tile] = _get_op_from_cell(tile); @@ -1103,7 +1103,7 @@ void TileMapEditor::_canvas_draw() { Size2 screen_size = canvas_item_editor->get_size(); { Rect2 aabb; - aabb.pos = node->world_to_map(xform_inv.xform(Vector2())); + aabb.position = node->world_to_map(xform_inv.xform(Vector2())); aabb.expand_to(node->world_to_map(xform_inv.xform(Vector2(0, screen_size.height)))); aabb.expand_to(node->world_to_map(xform_inv.xform(Vector2(screen_size.width, 0)))); aabb.expand_to(node->world_to_map(xform_inv.xform(screen_size))); @@ -1113,10 +1113,10 @@ void TileMapEditor::_canvas_draw() { int max_lines = 2000; //avoid crash if size too smal - for (int i = (si.pos.x) - 1; i <= (si.pos.x + si.size.x); i++) { + for (int i = (si.position.x) - 1; i <= (si.position.x + si.size.x); i++) { - Vector2 from = xform.xform(node->map_to_world(Vector2(i, si.pos.y))); - Vector2 to = xform.xform(node->map_to_world(Vector2(i, si.pos.y + si.size.y + 1))); + Vector2 from = xform.xform(node->map_to_world(Vector2(i, si.position.y))); + Vector2 to = xform.xform(node->map_to_world(Vector2(i, si.position.y + si.size.y + 1))); Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2); canvas_item_editor->draw_line(from, to, col, 1); @@ -1127,9 +1127,9 @@ void TileMapEditor::_canvas_draw() { int max_lines = 10000; //avoid crash if size too smal - for (int i = (si.pos.x) - 1; i <= (si.pos.x + si.size.x); i++) { + for (int i = (si.position.x) - 1; i <= (si.position.x + si.size.x); i++) { - for (int j = (si.pos.y) - 1; j <= (si.pos.y + si.size.y); j++) { + for (int j = (si.position.y) - 1; j <= (si.position.y + si.size.y); j++) { Vector2 ofs; if (ABS(j) & 1) { @@ -1151,10 +1151,10 @@ void TileMapEditor::_canvas_draw() { if (node->get_half_offset() != TileMap::HALF_OFFSET_Y) { - for (int i = (si.pos.y) - 1; i <= (si.pos.y + si.size.y); i++) { + for (int i = (si.position.y) - 1; i <= (si.position.y + si.size.y); i++) { - Vector2 from = xform.xform(node->map_to_world(Vector2(si.pos.x, i))); - Vector2 to = xform.xform(node->map_to_world(Vector2(si.pos.x + si.size.x + 1, i))); + Vector2 from = xform.xform(node->map_to_world(Vector2(si.position.x, i))); + Vector2 to = xform.xform(node->map_to_world(Vector2(si.position.x + si.size.x + 1, i))); Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2); canvas_item_editor->draw_line(from, to, col, 1); @@ -1164,9 +1164,9 @@ void TileMapEditor::_canvas_draw() { } } else { - for (int i = (si.pos.y) - 1; i <= (si.pos.y + si.size.y); i++) { + for (int i = (si.position.y) - 1; i <= (si.position.y + si.size.y); i++) { - for (int j = (si.pos.x) - 1; j <= (si.pos.x + si.size.x); j++) { + for (int j = (si.position.x) - 1; j <= (si.position.x + si.size.x); j++) { Vector2 ofs; if (ABS(j) & 1) { @@ -1188,10 +1188,10 @@ void TileMapEditor::_canvas_draw() { if (selection_active) { Vector<Vector2> points; - points.push_back(xform.xform(node->map_to_world((rectangle.pos)))); - points.push_back(xform.xform(node->map_to_world((rectangle.pos + Point2(rectangle.size.x + 1, 0))))); - points.push_back(xform.xform(node->map_to_world((rectangle.pos + Point2(rectangle.size.x + 1, rectangle.size.y + 1))))); - points.push_back(xform.xform(node->map_to_world((rectangle.pos + Point2(0, rectangle.size.y + 1))))); + points.push_back(xform.xform(node->map_to_world((rectangle.position)))); + points.push_back(xform.xform(node->map_to_world((rectangle.position + Point2(rectangle.size.x + 1, 0))))); + points.push_back(xform.xform(node->map_to_world((rectangle.position + Point2(rectangle.size.x + 1, rectangle.size.y + 1))))); + points.push_back(xform.xform(node->map_to_world((rectangle.position + Point2(0, rectangle.size.y + 1))))); canvas_item_editor->draw_colored_polygon(points, Color(0.2, 0.8, 1, 0.4)); } @@ -1248,8 +1248,8 @@ void TileMapEditor::_canvas_draw() { if (id == TileMap::INVALID_CELL) return; - for (int i = rectangle.pos.y; i <= rectangle.pos.y + rectangle.size.y; i++) { - for (int j = rectangle.pos.x; j <= rectangle.pos.x + rectangle.size.x; j++) { + for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { + for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { _draw_cell(id, Point2i(j, i), flip_h, flip_v, transpose, xform); } @@ -1264,7 +1264,7 @@ void TileMapEditor::_canvas_draw() { if (ts.is_null()) return; - Point2 ofs = over_tile - rectangle.pos; + Point2 ofs = over_tile - rectangle.position; for (List<TileData>::Element *E = copydata.front(); E; E = E->next()) { @@ -1277,13 +1277,13 @@ void TileMapEditor::_canvas_draw() { } Rect2i duplicate = rectangle; - duplicate.pos = over_tile; + duplicate.position = over_tile; Vector<Vector2> points; - points.push_back(xform.xform(node->map_to_world(duplicate.pos))); - points.push_back(xform.xform(node->map_to_world((duplicate.pos + Point2(duplicate.size.x + 1, 0))))); - points.push_back(xform.xform(node->map_to_world((duplicate.pos + Point2(duplicate.size.x + 1, duplicate.size.y + 1))))); - points.push_back(xform.xform(node->map_to_world((duplicate.pos + Point2(0, duplicate.size.y + 1))))); + points.push_back(xform.xform(node->map_to_world(duplicate.position))); + points.push_back(xform.xform(node->map_to_world((duplicate.position + Point2(duplicate.size.x + 1, 0))))); + points.push_back(xform.xform(node->map_to_world((duplicate.position + Point2(duplicate.size.x + 1, duplicate.size.y + 1))))); + points.push_back(xform.xform(node->map_to_world((duplicate.position + Point2(0, duplicate.size.y + 1))))); canvas_item_editor->draw_colored_polygon(points, Color(0.2, 1.0, 0.8, 0.2)); diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index a4e8ef70ce..a3d3d42110 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -914,8 +914,9 @@ void ProjectManager::_on_project_created(const String &dir) { _update_scroll_pos(dir); } else { _load_recent_projects(); - scroll->connect("draw", this, "_update_scroll_pos", varray(dir), CONNECT_ONESHOT); + _update_scroll_pos(dir); } + _open_project(); } void ProjectManager::_update_scroll_pos(const String &dir) { @@ -1469,7 +1470,7 @@ ProjectListFilter::ProjectListFilter() { _current_filter = FILTER_NAME; filter_option = memnew(OptionButton); - filter_option->set_custom_minimum_size(Size2(80, 10)); + filter_option->set_custom_minimum_size(Size2(80 * EDSCALE, 10 * EDSCALE)); filter_option->set_clip_text(true); filter_option->connect("item_selected", this, "_filter_option_selected"); add_child(filter_option); diff --git a/editor/project_settings.cpp b/editor/project_settings.cpp index 1c4ca3cb58..8ef7bd427f 100644 --- a/editor/project_settings.cpp +++ b/editor/project_settings.cpp @@ -430,8 +430,8 @@ void ProjectSettings::_action_button_pressed(Object *p_obj, int p_column, int p_ if (p_id == 1) { Point2 ofs = input_editor->get_global_position(); Rect2 ir = input_editor->get_item_rect(ti); - ir.pos.y -= input_editor->get_scroll().y; - ofs += ir.pos + ir.size; + ir.position.y -= input_editor->get_scroll().y; + ofs += ir.position + ir.size; ofs.x -= 100; popup_add->set_position(ofs); popup_add->popup(); diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index 1c8a1c0ee0..d1b79ea7aa 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -678,8 +678,8 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: field_names.push_back("h"); config_value_editors(4, 4, 10, field_names); Rect2 r = v; - value_editor[0]->set_text(String::num(r.pos.x)); - value_editor[1]->set_text(String::num(r.pos.y)); + value_editor[0]->set_text(String::num(r.position.x)); + value_editor[1]->set_text(String::num(r.position.y)); value_editor[2]->set_text(String::num(r.size.x)); value_editor[3]->set_text(String::num(r.size.y)); } break; @@ -1539,13 +1539,13 @@ void CustomPropertyEditor::_modified(String p_string) { Rect2 r2; if (evaluator) { - r2.pos.x = evaluator->eval(value_editor[0]->get_text()); - r2.pos.y = evaluator->eval(value_editor[1]->get_text()); + r2.position.x = evaluator->eval(value_editor[0]->get_text()); + r2.position.y = evaluator->eval(value_editor[1]->get_text()); r2.size.x = evaluator->eval(value_editor[2]->get_text()); r2.size.y = evaluator->eval(value_editor[3]->get_text()); } else { - r2.pos.x = value_editor[0]->get_text().to_double(); - r2.pos.y = value_editor[1]->get_text().to_double(); + r2.position.x = value_editor[0]->get_text().to_double(); + r2.position.y = value_editor[1]->get_text().to_double(); r2.size.x = value_editor[2]->get_text().to_double(); r2.size.y = value_editor[3]->get_text().to_double(); } @@ -2310,6 +2310,7 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String &p if (obj->get(p_name).get_type() == Variant::NIL || obj->get(p_name).operator RefPtr().is_null()) { p_item->set_text(1, "<null>"); p_item->set_icon(1, Ref<Texture>()); + p_item->set_custom_as_button(1, false); Dictionary d = p_item->get_metadata(0); int hint = d.has("hint") ? d["hint"].operator int() : -1; @@ -2319,6 +2320,7 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String &p } } else { + p_item->set_custom_as_button(1, true); RES res = obj->get(p_name).operator RefPtr(); if (res->is_class("Texture")) { int tw = EditorSettings::get_singleton()->get("docks/property_editor/texture_preview_width"); @@ -3540,17 +3542,21 @@ void PropertyEditor::update_tree() { item->set_cell_mode(1, TreeItem::CELL_MODE_CUSTOM); item->set_editable(1, !read_only); - item->add_button(1, get_icon("EditResource", "EditorIcons")); + //item->add_button(1, get_icon("EditResource", "EditorIcons")); String type; if (p.hint == PROPERTY_HINT_RESOURCE_TYPE) type = p.hint_string; - if (obj->get(p.name).get_type() == Variant::NIL || obj->get(p.name).operator RefPtr().is_null()) { + RES res = obj->get(p.name).operator RefPtr(); + + if (obj->get(p.name).get_type() == Variant::NIL || res.is_null()) { item->set_text(1, "<null>"); item->set_icon(1, Ref<Texture>()); + item->set_custom_as_button(1, false); - } else { - RES res = obj->get(p.name).operator RefPtr(); + } else if (res.is_valid()) { + + item->set_custom_as_button(1, true); if (res->is_class("Texture")) { int tw = EditorSettings::get_singleton()->get("docks/property_editor/texture_preview_width"); @@ -3668,7 +3674,7 @@ void PropertyEditor::_draw_transparency(Object *t, const Rect2 &p_rect) { // make a little space between consecutive color fields Rect2 area = p_rect; - area.pos.y += 1; + area.position.y += 1; area.size.height -= 2; area.size.width -= arrow->get_size().width + 5; tree->draw_texture_rect(get_icon("Transparent", "EditorIcons"), area, true); @@ -3854,6 +3860,16 @@ void PropertyEditor::_item_edited() { _edit_set(name, NodePath(item->get_text(1)), refresh_all); } break; + case Variant::OBJECT: { + if (!item->is_custom_set_as_button(1)) + break; + + RES res = obj->get(name); + if (res.is_valid()) { + emit_signal("resource_selected", res.get_ref_ptr(), name); + } + + } break; case Variant::DICTIONARY: { @@ -3926,7 +3942,7 @@ void PropertyEditor::_custom_editor_request(bool p_arrow) { int hint = d.has("hint") ? d["hint"].operator int() : -1; String hint_text = d.has("hint_text") ? d["hint_text"] : ""; Rect2 where = tree->get_custom_popup_rect(); - custom_editor->set_position(where.pos); + custom_editor->set_position(where.position); if (custom_editor->edit(obj, name, type, v, hint, hint_text)) { custom_editor->popup(); @@ -4033,9 +4049,9 @@ void PropertyEditor::_edit_button(Object *p_item, int p_column, int p_button) { Variant v = obj->get(n); custom_editor->edit(obj, n, (Variant::Type)t, v, h, ht); Rect2 where = tree->get_item_rect(ti, 1); - where.pos -= tree->get_scroll(); - where.pos += tree->get_global_position(); - custom_editor->set_position(where.pos); + where.position -= tree->get_scroll(); + where.position += tree->get_global_position(); + custom_editor->set_position(where.position); custom_editor->popup(); } else if (t == Variant::STRING) { @@ -4046,9 +4062,9 @@ void PropertyEditor::_edit_button(Object *p_item, int p_column, int p_button) { if (h == PROPERTY_HINT_FILE || h == PROPERTY_HINT_DIR || h == PROPERTY_HINT_GLOBAL_DIR || h == PROPERTY_HINT_GLOBAL_FILE) { Rect2 where = tree->get_item_rect(ti, 1); - where.pos -= tree->get_scroll(); - where.pos += tree->get_global_position(); - custom_editor->set_position(where.pos); + where.position -= tree->get_scroll(); + where.position += tree->get_global_position(); + custom_editor->set_position(where.position); custom_editor->popup(); } else { custom_editor->popup_centered_ratio(); @@ -4124,7 +4140,7 @@ void PropertyEditor::_draw_flags(Object *t, const Rect2 &p_rect) { if (i == 1) ofs.y += bsize + 1; - ofs += p_rect.pos; + ofs += p_rect.position; for (int j = 0; j < 10; j++) { Point2 o = ofs + Point2(j * (bsize + 1), 0); diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 0f05cc79ff..da2d22b900 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -658,6 +658,21 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } } } break; + + default: { + + if (p_tool >= EDIT_SUBRESOURCE_BASE) { + + int idx = p_tool - EDIT_SUBRESOURCE_BASE; + + ERR_FAIL_INDEX(idx, subresources.size()); + + Object *obj = ObjectDB::get_instance(subresources[idx]); + ERR_FAIL_COND(!obj); + + editor->push_item(obj); + } + } } } @@ -1662,6 +1677,47 @@ void SceneTreeDock::_nodes_dragged(Array p_nodes, NodePath p_to, int p_type) { _do_reparent(to_node, to_pos, nodes, true); } +void SceneTreeDock::_add_children_to_popup(Object *p_obj, int p_depth) { + + if (p_depth > 8) + return; + + List<PropertyInfo> pinfo; + p_obj->get_property_list(&pinfo); + for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { + + if (!(E->get().usage & PROPERTY_USAGE_EDITOR)) + continue; + if (E->get().hint != PROPERTY_HINT_RESOURCE_TYPE) + continue; + + Variant value = p_obj->get(E->get().name); + if (value.get_type() != Variant::OBJECT) + continue; + Object *obj = value; + if (!obj) + continue; + + Ref<Texture> icon; + + if (has_icon(obj->get_class(), "EditorIcons")) + icon = get_icon(obj->get_class(), "EditorIcons"); + else + icon = get_icon("Object", "EditorIcons"); + + if (menu->get_item_count() == 0) { + menu->add_item(TTR("Sub-Resources:")); + menu->set_item_disabled(0, true); + } + int index = menu->get_item_count(); + menu->add_icon_item(icon, E->get().name.capitalize(), EDIT_SUBRESOURCE_BASE + subresources.size()); + menu->set_item_h_offset(index, p_depth * 10 * EDSCALE); + subresources.push_back(obj->get_instance_ID()); + + _add_children_to_popup(obj, p_depth + 1); + } +} + void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { if (!EditorNode::get_singleton()->get_edited_scene()) { @@ -1683,6 +1739,12 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { menu->clear(); if (selection.size() == 1) { + + subresources.clear(); + _add_children_to_popup(selection.front()->get(), 0); + if (menu->get_item_count() > 0) + menu->add_separator(); + menu->add_icon_shortcut(get_icon("Add", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW); menu->add_icon_shortcut(get_icon("Instance", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANCE); menu->add_separator(); diff --git a/editor/scene_tree_dock.h b/editor/scene_tree_dock.h index f190025dd6..79e01e7571 100644 --- a/editor/scene_tree_dock.h +++ b/editor/scene_tree_dock.h @@ -73,6 +73,12 @@ class SceneTreeDock : public VBoxContainer { TOOL_BUTTON_MAX }; + enum { + EDIT_SUBRESOURCE_BASE = 100 + }; + + Vector<ObjectID> subresources; + bool restore_script_editor_on_drag; int current_option; @@ -114,6 +120,8 @@ class SceneTreeDock : public VBoxContainer { Node *edited_scene; EditorNode *editor; + void _add_children_to_popup(Object *p_obj, int p_depth); + Node *_duplicate(Node *p_node, Map<Node *, Node *> &duplimap); void _node_reparent(NodePath p_path, bool p_keep_global_xform); void _do_reparent(Node *p_new_parent, int p_position_in_parent, Vector<Node *> p_nodes, bool p_keep_global_xform); diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp index 2945abbd8c..d4e5714c0d 100644 --- a/editor/scene_tree_editor.cpp +++ b/editor/scene_tree_editor.cpp @@ -161,17 +161,17 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i if (p_id == BUTTON_SUBSCENE) { //open scene request Rect2 item_rect = tree->get_item_rect(item, 0); - item_rect.pos.y -= tree->get_scroll().y; - item_rect.pos += tree->get_global_position(); + item_rect.position.y -= tree->get_scroll().y; + item_rect.position += tree->get_global_position(); if (n == get_scene_node()) { - inheritance_menu->set_position(item_rect.pos + Vector2(0, item_rect.size.y)); + inheritance_menu->set_position(item_rect.position + Vector2(0, item_rect.size.y)); inheritance_menu->set_size(Vector2(item_rect.size.x, 0)); inheritance_menu->popup(); instance_node = n->get_instance_ID(); } else { - instance_menu->set_position(item_rect.pos + Vector2(0, item_rect.size.y)); + instance_menu->set_position(item_rect.position + Vector2(0, item_rect.size.y)); instance_menu->set_size(Vector2(item_rect.size.x, 0)); if (EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(n)) instance_menu->set_item_checked(0, true); diff --git a/editor/script_editor_debugger.cpp b/editor/script_editor_debugger.cpp index a2bb3a0879..7f1e6023bf 100644 --- a/editor/script_editor_debugger.cpp +++ b/editor/script_editor_debugger.cpp @@ -790,19 +790,19 @@ void ScriptEditorDebugger::_performance_draw() { Point2i p(i % cols, i / cols); Rect2i r(p * s, s); - r.pos += Point2(margin, margin); + r.position += Point2(margin, margin); r.size -= Point2(margin, margin) * 2.0; perf_draw->draw_style_box(graph_sb, r); - r.pos += graph_sb->get_offset(); + r.position += graph_sb->get_offset(); r.size -= graph_sb->get_minimum_size(); int pi = which[i]; Color c = Color(0.7, 0.9, 0.5); c.set_hsv(Math::fmod(c.get_h() + pi * 0.7654, 1), c.get_s(), c.get_v()); c.a = 0.8; - perf_draw->draw_string(graph_font, r.pos + Point2(0, graph_font->get_ascent()), perf_items[pi]->get_text(0), c, r.size.x); + perf_draw->draw_string(graph_font, r.position + Point2(0, graph_font->get_ascent()), perf_items[pi]->get_text(0), c, r.size.x); c.a = 0.6; - perf_draw->draw_string(graph_font, r.pos + Point2(graph_font->get_char_size('X').width, graph_font->get_ascent() + graph_font->get_height()), perf_items[pi]->get_text(1), c, r.size.y); + perf_draw->draw_string(graph_font, r.position + Point2(graph_font->get_char_size('X').width, graph_font->get_ascent() + graph_font->get_height()), perf_items[pi]->get_text(1), c, r.size.y); float spacing = point_sep / float(cols); float from = r.size.width; @@ -819,7 +819,7 @@ void ScriptEditorDebugger::_performance_draw() { c.a = 0.7; if (E != perf_history.front()) - perf_draw->draw_line(r.pos + Point2(from, h), r.pos + Point2(from + spacing, prev), c, 2.0); + perf_draw->draw_line(r.position + Point2(from, h), r.position + Point2(from + spacing, prev), c, 2.0); prev = h; E = E->next(); from -= spacing; diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp index 4781bb6a3b..149b06e50a 100644 --- a/editor/spatial_editor_gizmos.cpp +++ b/editor/spatial_editor_gizmos.cpp @@ -79,7 +79,7 @@ void EditorSpatialGizmo::Instance::create_instance(Spatial *p_base) { VS::get_singleton()->instance_set_layer_mask(instance, 1 << SpatialEditorViewport::GIZMO_EDIT_LAYER); //gizmos are 26 } -void EditorSpatialGizmo::add_mesh(const Ref<Mesh> &p_mesh, bool p_billboard, const RID &p_skeleton) { +void EditorSpatialGizmo::add_mesh(const Ref<ArrayMesh> &p_mesh, bool p_billboard, const RID &p_skeleton) { ERR_FAIL_COND(!spatial_node); Instance ins; @@ -100,7 +100,7 @@ void EditorSpatialGizmo::add_lines(const Vector<Vector3> &p_lines, const Ref<Mat ERR_FAIL_COND(!spatial_node); Instance ins; - Ref<Mesh> mesh = memnew(Mesh); + Ref<ArrayMesh> mesh = memnew(ArrayMesh); Array a; a.resize(Mesh::ARRAY_MAX); @@ -162,7 +162,7 @@ void EditorSpatialGizmo::add_unscaled_billboard(const Ref<Material> &p_material, uv.push_back(Vector2(0, 1)); uv.push_back(Vector2(1, 1)); - Ref<Mesh> mesh = memnew(Mesh); + Ref<ArrayMesh> mesh = memnew(ArrayMesh); Array a; a.resize(Mesh::ARRAY_MAX); a[Mesh::ARRAY_VERTEX] = vs; @@ -219,7 +219,7 @@ void EditorSpatialGizmo::add_handles(const Vector<Vector3> &p_handles, bool p_bi ERR_FAIL_COND(!spatial_node); Instance ins; - Ref<Mesh> mesh = memnew(Mesh); + Ref<ArrayMesh> mesh = memnew(ArrayMesh); #if 1 Array a; @@ -1029,7 +1029,7 @@ CameraSpatialGizmo::CameraSpatialGizmo(Camera *p_camera) { void MeshInstanceSpatialGizmo::redraw() { - Ref<Mesh> m = mesh->get_mesh(); + Ref<ArrayMesh> m = mesh->get_mesh(); if (!m.is_valid()) return; //none @@ -1248,7 +1248,7 @@ void SkeletonSpatialGizmo::redraw() { */ } - Ref<Mesh> m = surface_tool->commit(); + Ref<ArrayMesh> m = surface_tool->commit(); add_mesh(m, false, skel->get_skeleton()); } @@ -2511,7 +2511,7 @@ void NavigationMeshSpatialGizmo::redraw() { if (lines.size()) add_lines(lines, navmesh->is_enabled() ? SpatialEditorGizmos::singleton->navmesh_edge_material : SpatialEditorGizmos::singleton->navmesh_edge_material_disabled); add_collision_triangles(tmesh); - Ref<Mesh> m = memnew(Mesh); + Ref<ArrayMesh> m = memnew(ArrayMesh); Array a; a.resize(Mesh::ARRAY_MAX); a[0] = tmeshfaces; @@ -3213,7 +3213,7 @@ SpatialEditorGizmos::SpatialEditorGizmos() { //position 3D Shared mesh - pos3d_mesh = Ref<Mesh>(memnew(Mesh)); + pos3d_mesh = Ref<ArrayMesh>(memnew(ArrayMesh)); { PoolVector<Vector3> cursor_points; @@ -3246,7 +3246,7 @@ SpatialEditorGizmos::SpatialEditorGizmos() { pos3d_mesh->surface_set_material(0, mat); } - listener_line_mesh = Ref<Mesh>(memnew(Mesh)); + listener_line_mesh = Ref<ArrayMesh>(memnew(ArrayMesh)); { PoolVector<Vector3> cursor_points; diff --git a/editor/spatial_editor_gizmos.h b/editor/spatial_editor_gizmos.h index 095586ab91..6a77e91425 100644 --- a/editor/spatial_editor_gizmos.h +++ b/editor/spatial_editor_gizmos.h @@ -59,7 +59,7 @@ class EditorSpatialGizmo : public SpatialEditorGizmo { struct Instance { RID instance; - Ref<Mesh> mesh; + Ref<ArrayMesh> mesh; RID skeleton; bool billboard; bool unscaled; @@ -97,7 +97,7 @@ class EditorSpatialGizmo : public SpatialEditorGizmo { protected: void add_lines(const Vector<Vector3> &p_lines, const Ref<Material> &p_material, bool p_billboard = false); - void add_mesh(const Ref<Mesh> &p_mesh, bool p_billboard = false, const RID &p_skeleton = RID()); + void add_mesh(const Ref<ArrayMesh> &p_mesh, bool p_billboard = false, const RID &p_skeleton = RID()); void add_collision_segments(const Vector<Vector3> &p_lines); void add_collision_triangles(const Ref<TriangleMesh> &p_tmesh); void add_unscaled_billboard(const Ref<Material> &p_material, float p_scale = 1); @@ -454,8 +454,8 @@ public: Ref<SpatialMaterial> shape_material; Ref<Texture> handle_t; - Ref<Mesh> pos3d_mesh; - Ref<Mesh> listener_line_mesh; + Ref<ArrayMesh> pos3d_mesh; + Ref<ArrayMesh> listener_line_mesh; static SpatialEditorGizmos *singleton; Ref<TriangleMesh> test_cube_tm; diff --git a/main/input_default.cpp b/main/input_default.cpp index 0de30e5e9e..e488438059 100644 --- a/main/input_default.cpp +++ b/main/input_default.cpp @@ -325,11 +325,11 @@ void InputDefault::parse_input_event(const Ref<InputEvent> &p_event) { Ref<InputEventScreenTouch> touch_event; touch_event.instance(); touch_event->set_pressed(mb->is_pressed()); - touch_event->set_pos(mb->get_pos()); + touch_event->set_position(mb->get_position()); main_loop->input_event(touch_event); } - Point2 pos = mb->get_global_pos(); + Point2 pos = mb->get_global_position(); if (mouse_pos != pos) { set_mouse_position(pos); } @@ -343,7 +343,7 @@ void InputDefault::parse_input_event(const Ref<InputEvent> &p_event) { Ref<InputEventScreenDrag> drag_event; drag_event.instance(); - drag_event->set_pos(mm->get_pos()); + drag_event->set_position(mm->get_position()); drag_event->set_relative(mm->get_relative()); drag_event->set_speed(mm->get_speed()); @@ -493,10 +493,10 @@ Point2i InputDefault::warp_mouse_motion(const Ref<InputEventMouseMotion> &p_moti Math::fmod(p_motion->get_relative().x + rel_sgn.x * warp_margin.x, p_rect.size.x) - rel_sgn.x * warp_margin.x, Math::fmod(p_motion->get_relative().y + rel_sgn.y * warp_margin.y, p_rect.size.y) - rel_sgn.y * warp_margin.y); - const Point2i pos_local = p_motion->get_global_pos() - p_rect.pos; + const Point2i pos_local = p_motion->get_global_position() - p_rect.position; const Point2i pos_warped(Math::fposmod(pos_local.x, p_rect.size.x), Math::fposmod(pos_local.y, p_rect.size.y)); if (pos_warped != pos_local) { - OS::get_singleton()->warp_mouse_pos(pos_warped + p_rect.pos); + OS::get_singleton()->warp_mouse_pos(pos_warped + p_rect.position); } return rel_warped; diff --git a/main/tests/test_physics_2d.cpp b/main/tests/test_physics_2d.cpp index 5f57275503..2c9b51aadb 100644 --- a/main/tests/test_physics_2d.cpp +++ b/main/tests/test_physics_2d.cpp @@ -216,7 +216,7 @@ protected: if (mb->is_pressed()) { - Point2 p(mb->get_pos().x, mb->get_pos().y); + Point2 p(mb->get_position().x, mb->get_position().y); if (mb->get_button_index() == 1) { ray_to = p; @@ -232,7 +232,7 @@ protected: if (mm.is_valid()) { - Point2 p = mm->get_pos(); + Point2 p = mm->get_position(); if (mm->get_button_mask() & BUTTON_MASK_LEFT) { ray_to = p; diff --git a/modules/dds/texture_loader_dds.cpp b/modules/dds/texture_loader_dds.cpp index da895a6d69..71593ebfa9 100644 --- a/modules/dds/texture_loader_dds.cpp +++ b/modules/dds/texture_loader_dds.cpp @@ -76,8 +76,6 @@ static const DDSFormatInfo dds_format_info[DDS_MAX] = { { "DXT1", true, false, 4, 8, Image::FORMAT_DXT1 }, { "DXT3", true, false, 4, 16, Image::FORMAT_DXT3 }, { "DXT5", true, false, 4, 16, Image::FORMAT_DXT5 }, - { "ATI1", true, false, 4, 8, Image::FORMAT_LATC_L }, - { "ATI2", true, false, 4, 16, Image::FORMAT_LATC_LA }, { "BGRA8", false, false, 1, 4, Image::FORMAT_RGBA8 }, { "BGR8", false, false, 1, 3, Image::FORMAT_RGB8 }, { "RGBA8", false, false, 1, 4, Image::FORMAT_RGBA8 }, diff --git a/modules/gdnative/godot/godot_array.cpp b/modules/gdnative/godot/godot_array.cpp index bf2ef35972..8cf6d1b8ef 100644 --- a/modules/gdnative/godot/godot_array.cpp +++ b/modules/gdnative/godot/godot_array.cpp @@ -49,6 +49,12 @@ void GDAPI godot_array_new(godot_array *p_arr) { memnew_placement(a, Array); } +void GDAPI godot_array_new_copy(godot_array *p_dest, const godot_array *p_src) { + Array *dest = (Array *)p_dest; + const Array *src = (const Array *)p_src; + memnew_placement(dest, Array(*src)); +} + void GDAPI godot_array_new_pool_color_array(godot_array *p_arr, const godot_pool_color_array *p_pca) { Array *a = (Array *)p_arr; PoolVector<Color> *pca = (PoolVector<Color> *)p_pca; diff --git a/modules/gdnative/godot/godot_array.h b/modules/gdnative/godot/godot_array.h index f7150950fc..5db0031b8c 100644 --- a/modules/gdnative/godot/godot_array.h +++ b/modules/gdnative/godot/godot_array.h @@ -49,6 +49,7 @@ typedef struct godot_array { #include "../godot.h" void GDAPI godot_array_new(godot_array *p_arr); +void GDAPI godot_array_new_copy(godot_array *p_dest, const godot_array *p_src); void GDAPI godot_array_new_pool_color_array(godot_array *p_arr, const godot_pool_color_array *p_pca); void GDAPI godot_array_new_pool_vector3_array(godot_array *p_arr, const godot_pool_vector3_array *p_pv3a); void GDAPI godot_array_new_pool_vector2_array(godot_array *p_arr, const godot_pool_vector2_array *p_pv2a); diff --git a/modules/gdnative/godot/godot_dictionary.cpp b/modules/gdnative/godot/godot_dictionary.cpp index b98ee5b5c9..deec5f8ffb 100644 --- a/modules/gdnative/godot/godot_dictionary.cpp +++ b/modules/gdnative/godot/godot_dictionary.cpp @@ -44,6 +44,12 @@ void GDAPI godot_dictionary_new(godot_dictionary *r_dest) { memnew_placement(dest, Dictionary); } +void GDAPI godot_dictionary_new_copy(godot_dictionary *r_dest, const godot_dictionary *r_src) { + Dictionary *dest = (Dictionary *)r_dest; + const Dictionary *src = (const Dictionary *)r_src; + memnew_placement(dest, Dictionary(*src)); +} + void GDAPI godot_dictionary_destroy(godot_dictionary *p_self) { Dictionary *self = (Dictionary *)p_self; self->~Dictionary(); diff --git a/modules/gdnative/godot/godot_dictionary.h b/modules/gdnative/godot/godot_dictionary.h index 42f7f872a1..a89bd4bba1 100644 --- a/modules/gdnative/godot/godot_dictionary.h +++ b/modules/gdnative/godot/godot_dictionary.h @@ -48,6 +48,7 @@ typedef struct godot_dictionary { #include "godot_variant.h" void GDAPI godot_dictionary_new(godot_dictionary *r_dest); +void GDAPI godot_dictionary_new_copy(godot_dictionary *r_dest, const godot_dictionary *r_src); void GDAPI godot_dictionary_destroy(godot_dictionary *p_self); godot_int GDAPI godot_dictionary_size(const godot_dictionary *p_self); diff --git a/modules/gdnative/godot/godot_pool_arrays.cpp b/modules/gdnative/godot/godot_pool_arrays.cpp index 10d5d6d939..ff4586ebe7 100644 --- a/modules/gdnative/godot/godot_pool_arrays.cpp +++ b/modules/gdnative/godot/godot_pool_arrays.cpp @@ -49,6 +49,12 @@ void GDAPI godot_pool_byte_array_new(godot_pool_byte_array *p_pba) { memnew_placement(pba, PoolVector<uint8_t>); } +void GDAPI godot_pool_byte_array_new_copy(godot_pool_byte_array *p_dest, const godot_pool_byte_array *p_src) { + PoolVector<uint8_t> *dest = (PoolVector<uint8_t> *)p_dest; + const PoolVector<uint8_t> *src = (const PoolVector<uint8_t> *)p_src; + memnew_placement(dest, PoolVector<uint8_t>(*src)); +} + void GDAPI godot_pool_byte_array_new_with_array(godot_pool_byte_array *p_pba, const godot_array *p_a) { PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; Array *a = (Array *)p_a; @@ -118,14 +124,20 @@ void GDAPI godot_pool_byte_array_destroy(godot_pool_byte_array *p_pba) { // int void GDAPI godot_pool_int_array_new(godot_pool_int_array *p_pba) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; - memnew_placement(pba, PoolVector<uint8_t>); + PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; + memnew_placement(pba, PoolVector<godot_int>); +} + +void GDAPI godot_pool_int_array_new_copy(godot_pool_int_array *p_dest, const godot_pool_int_array *p_src) { + PoolVector<godot_int> *dest = (PoolVector<godot_int> *)p_dest; + const PoolVector<godot_int> *src = (const PoolVector<godot_int> *)p_src; + memnew_placement(dest, PoolVector<godot_int>(*src)); } void GDAPI godot_pool_int_array_new_with_array(godot_pool_int_array *p_pba, const godot_array *p_a) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; Array *a = (Array *)p_a; - memnew_placement(pba, PoolVector<uint8_t>); + memnew_placement(pba, PoolVector<godot_int>); pba->resize(a->size()); for (size_t i = 0; i < a->size(); i++) { @@ -191,14 +203,20 @@ void GDAPI godot_pool_int_array_destroy(godot_pool_int_array *p_pba) { // real void GDAPI godot_pool_real_array_new(godot_pool_real_array *p_pba) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; - memnew_placement(pba, PoolVector<uint8_t>); + PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; + memnew_placement(pba, PoolVector<godot_real>); +} + +void GDAPI godot_pool_real_array_new_copy(godot_pool_real_array *p_dest, const godot_pool_real_array *p_src) { + PoolVector<godot_real> *dest = (PoolVector<godot_real> *)p_dest; + const PoolVector<godot_real> *src = (const PoolVector<godot_real> *)p_src; + memnew_placement(dest, PoolVector<godot_real>(*src)); } void GDAPI godot_pool_real_array_new_with_array(godot_pool_real_array *p_pba, const godot_array *p_a) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; + PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; Array *a = (Array *)p_a; - memnew_placement(pba, PoolVector<uint8_t>); + memnew_placement(pba, PoolVector<godot_real>); pba->resize(a->size()); for (size_t i = 0; i < a->size(); i++) { @@ -268,6 +286,12 @@ void GDAPI godot_pool_string_array_new(godot_pool_string_array *p_pba) { memnew_placement(pba, PoolVector<String>); } +void GDAPI godot_pool_string_array_new_copy(godot_pool_string_array *p_dest, const godot_pool_string_array *p_src) { + PoolVector<String> *dest = (PoolVector<String> *)p_dest; + const PoolVector<String> *src = (const PoolVector<String> *)p_src; + memnew_placement(dest, PoolVector<String>(*src)); +} + void GDAPI godot_pool_string_array_new_with_array(godot_pool_string_array *p_pba, const godot_array *p_a) { PoolVector<String> *pba = (PoolVector<String> *)p_pba; Array *a = (Array *)p_a; @@ -349,6 +373,12 @@ void GDAPI godot_pool_vector2_array_new(godot_pool_vector2_array *p_pba) { memnew_placement(pba, PoolVector<Vector2>); } +void GDAPI godot_pool_vector2_array_new_copy(godot_pool_vector2_array *p_dest, const godot_pool_vector2_array *p_src) { + PoolVector<Vector2> *dest = (PoolVector<Vector2> *)p_dest; + const PoolVector<Vector2> *src = (const PoolVector<Vector2> *)p_src; + memnew_placement(dest, PoolVector<Vector2>(*src)); +} + void GDAPI godot_pool_vector2_array_new_with_array(godot_pool_vector2_array *p_pba, const godot_array *p_a) { PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; Array *a = (Array *)p_a; @@ -429,6 +459,12 @@ void GDAPI godot_pool_vector3_array_new(godot_pool_vector3_array *p_pba) { memnew_placement(pba, PoolVector<Vector3>); } +void GDAPI godot_pool_vector3_array_new_copy(godot_pool_vector3_array *p_dest, const godot_pool_vector3_array *p_src) { + PoolVector<Vector3> *dest = (PoolVector<Vector3> *)p_dest; + const PoolVector<Vector3> *src = (const PoolVector<Vector3> *)p_src; + memnew_placement(dest, PoolVector<Vector3>(*src)); +} + void GDAPI godot_pool_vector3_array_new_with_array(godot_pool_vector3_array *p_pba, const godot_array *p_a) { PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; Array *a = (Array *)p_a; @@ -509,6 +545,12 @@ void GDAPI godot_pool_color_array_new(godot_pool_color_array *p_pba) { memnew_placement(pba, PoolVector<Color>); } +void GDAPI godot_pool_color_array_new_copy(godot_pool_color_array *p_dest, const godot_pool_color_array *p_src) { + PoolVector<Color> *dest = (PoolVector<Color> *)p_dest; + const PoolVector<Color> *src = (const PoolVector<Color> *)p_src; + memnew_placement(dest, PoolVector<Color>(*src)); +} + void GDAPI godot_pool_color_array_new_with_array(godot_pool_color_array *p_pba, const godot_array *p_a) { PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; Array *a = (Array *)p_a; diff --git a/modules/gdnative/godot/godot_pool_arrays.h b/modules/gdnative/godot/godot_pool_arrays.h index 015be65c3e..8b0d0137fd 100644 --- a/modules/gdnative/godot/godot_pool_arrays.h +++ b/modules/gdnative/godot/godot_pool_arrays.h @@ -102,6 +102,7 @@ typedef struct godot_pool_color_array { // byte void GDAPI godot_pool_byte_array_new(godot_pool_byte_array *p_pba); +void GDAPI godot_pool_byte_array_new_copy(godot_pool_byte_array *p_dest, const godot_pool_byte_array *p_src); void GDAPI godot_pool_byte_array_new_with_array(godot_pool_byte_array *p_pba, const godot_array *p_a); void GDAPI godot_pool_byte_array_append(godot_pool_byte_array *p_pba, const uint8_t p_data); @@ -128,6 +129,7 @@ void GDAPI godot_pool_byte_array_destroy(godot_pool_byte_array *p_pba); // int void GDAPI godot_pool_int_array_new(godot_pool_int_array *p_pia); +void GDAPI godot_pool_int_array_new_copy(godot_pool_int_array *p_dest, const godot_pool_int_array *p_src); void GDAPI godot_pool_int_array_new_with_array(godot_pool_int_array *p_pia, const godot_array *p_a); void GDAPI godot_pool_int_array_append(godot_pool_int_array *p_pia, const godot_int p_data); @@ -154,6 +156,7 @@ void GDAPI godot_pool_int_array_destroy(godot_pool_int_array *p_pia); // real void GDAPI godot_pool_real_array_new(godot_pool_real_array *p_pra); +void GDAPI godot_pool_real_array_new_copy(godot_pool_real_array *p_dest, const godot_pool_real_array *p_src); void GDAPI godot_pool_real_array_new_with_array(godot_pool_real_array *p_pra, const godot_array *p_a); void GDAPI godot_pool_real_array_append(godot_pool_real_array *p_pra, const godot_real p_data); @@ -180,6 +183,7 @@ void GDAPI godot_pool_real_array_destroy(godot_pool_real_array *p_pra); // string void GDAPI godot_pool_string_array_new(godot_pool_string_array *p_psa); +void GDAPI godot_pool_string_array_new_copy(godot_pool_string_array *p_dest, const godot_pool_string_array *p_src); void GDAPI godot_pool_string_array_new_with_array(godot_pool_string_array *p_psa, const godot_array *p_a); void GDAPI godot_pool_string_array_append(godot_pool_string_array *p_psa, const godot_string *p_data); @@ -206,6 +210,7 @@ void GDAPI godot_pool_string_array_destroy(godot_pool_string_array *p_psa); // vector2 void GDAPI godot_pool_vector2_array_new(godot_pool_vector2_array *p_pv2a); +void GDAPI godot_pool_vector2_array_new_copy(godot_pool_vector2_array *p_dest, const godot_pool_vector2_array *p_src); void GDAPI godot_pool_vector2_array_new_with_array(godot_pool_vector2_array *p_pv2a, const godot_array *p_a); void GDAPI godot_pool_vector2_array_append(godot_pool_vector2_array *p_pv2a, const godot_vector2 *p_data); @@ -232,6 +237,7 @@ void GDAPI godot_pool_vector2_array_destroy(godot_pool_vector2_array *p_pv2a); // vector3 void GDAPI godot_pool_vector3_array_new(godot_pool_vector3_array *p_pv3a); +void GDAPI godot_pool_vector3_array_new_copy(godot_pool_vector3_array *p_dest, const godot_pool_vector3_array *p_src); void GDAPI godot_pool_vector3_array_new_with_array(godot_pool_vector3_array *p_pv3a, const godot_array *p_a); void GDAPI godot_pool_vector3_array_append(godot_pool_vector3_array *p_pv3a, const godot_vector3 *p_data); @@ -258,6 +264,7 @@ void GDAPI godot_pool_vector3_array_destroy(godot_pool_vector3_array *p_pv3a); // color void GDAPI godot_pool_color_array_new(godot_pool_color_array *p_pca); +void GDAPI godot_pool_color_array_new_copy(godot_pool_color_array *p_dest, const godot_pool_color_array *p_src); void GDAPI godot_pool_color_array_new_with_array(godot_pool_color_array *p_pca, const godot_array *p_a); void GDAPI godot_pool_color_array_append(godot_pool_color_array *p_pca, const godot_color *p_data); diff --git a/modules/gdnative/godot/godot_rect2.cpp b/modules/gdnative/godot/godot_rect2.cpp index eea95ca6fe..0e456ea3ba 100644 --- a/modules/gdnative/godot/godot_rect2.cpp +++ b/modules/gdnative/godot/godot_rect2.cpp @@ -38,11 +38,11 @@ extern "C" { void _rect2_api_anchor() {} -void GDAPI godot_rect2_new_with_pos_and_size(godot_rect2 *r_dest, const godot_vector2 *p_pos, const godot_vector2 *p_size) { - const Vector2 *pos = (const Vector2 *)p_pos; +void GDAPI godot_rect2_new_with_position_and_size(godot_rect2 *r_dest, const godot_vector2 *p_pos, const godot_vector2 *p_size) { + const Vector2 *position = (const Vector2 *)p_pos; const Vector2 *size = (const Vector2 *)p_size; Rect2 *dest = (Rect2 *)r_dest; - *dest = Rect2(*pos, *size); + *dest = Rect2(*position, *size); } void GDAPI godot_rect2_new(godot_rect2 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_width, const godot_real p_height) { @@ -124,11 +124,11 @@ godot_bool GDAPI godot_rect2_operator_equal(const godot_rect2 *p_self, const god return *self == *b; } -godot_vector2 GDAPI godot_rect2_get_pos(const godot_rect2 *p_self) { +godot_vector2 GDAPI godot_rect2_get_position(const godot_rect2 *p_self) { godot_vector2 dest; Vector2 *d = (Vector2 *)&dest; const Rect2 *self = (const Rect2 *)p_self; - *d = self->get_pos(); + *d = self->get_position(); return dest; } @@ -140,10 +140,10 @@ godot_vector2 GDAPI godot_rect2_get_size(const godot_rect2 *p_self) { return dest; } -void GDAPI godot_rect2_set_pos(godot_rect2 *p_self, const godot_vector2 *p_pos) { +void GDAPI godot_rect2_set_position(godot_rect2 *p_self, const godot_vector2 *p_pos) { Rect2 *self = (Rect2 *)p_self; - const Vector2 *pos = (const Vector2 *)p_pos; - self->set_pos(*pos); + const Vector2 *position = (const Vector2 *)p_pos; + self->set_position(*position); } void GDAPI godot_rect2_set_size(godot_rect2 *p_self, const godot_vector2 *p_size) { diff --git a/modules/gdnative/godot/godot_rect2.h b/modules/gdnative/godot/godot_rect2.h index 9743321a3b..488a1204f7 100644 --- a/modules/gdnative/godot/godot_rect2.h +++ b/modules/gdnative/godot/godot_rect2.h @@ -46,7 +46,7 @@ typedef struct godot_rect2 { #include "../godot.h" #include "godot_vector2.h" -void GDAPI godot_rect2_new_with_pos_and_size(godot_rect2 *r_dest, const godot_vector2 *p_pos, const godot_vector2 *p_size); +void GDAPI godot_rect2_new_with_position_and_size(godot_rect2 *r_dest, const godot_vector2 *p_pos, const godot_vector2 *p_size); void GDAPI godot_rect2_new(godot_rect2 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_width, const godot_real p_height); godot_string GDAPI godot_rect2_as_string(const godot_rect2 *p_self); @@ -71,11 +71,11 @@ godot_rect2 GDAPI godot_rect2_expand(const godot_rect2 *p_self, const godot_vect godot_bool GDAPI godot_rect2_operator_equal(const godot_rect2 *p_self, const godot_rect2 *p_b); -godot_vector2 GDAPI godot_rect2_get_pos(const godot_rect2 *p_self); +godot_vector2 GDAPI godot_rect2_get_position(const godot_rect2 *p_self); godot_vector2 GDAPI godot_rect2_get_size(const godot_rect2 *p_self); -void GDAPI godot_rect2_set_pos(godot_rect2 *p_self, const godot_vector2 *p_pos); +void GDAPI godot_rect2_set_position(godot_rect2 *p_self, const godot_vector2 *p_pos); void GDAPI godot_rect2_set_size(godot_rect2 *p_self, const godot_vector2 *p_size); diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index e567e08c79..121b403f64 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -560,7 +560,7 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu else return false; - return do_input_action(p_camera, Point2(mb->get_pos().x, mb->get_pos().y), true); + return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true); } else { if ( @@ -604,7 +604,7 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu if (mm.is_valid()) { - return do_input_action(p_camera, mm->get_pos(), false); + return do_input_action(p_camera, mm->get_position(), false); } } else if (edit_mode->get_selected() == 1) { @@ -616,7 +616,7 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) { - Point2 point = mb->get_pos(); + Point2 point = mb->get_position(); Camera *camera = p_camera; Vector3 from = camera->project_ray_origin(point); diff --git a/modules/hdr/image_loader_hdr.cpp b/modules/hdr/image_loader_hdr.cpp index 85819104cf..19df27b962 100644 --- a/modules/hdr/image_loader_hdr.cpp +++ b/modules/hdr/image_loader_hdr.cpp @@ -131,7 +131,7 @@ Error ImageLoaderHDR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force //convert for (int i = 0; i < width * height; i++) { - float exp = pow(2, ptr[3] - 128); + float exp = pow(2.0f, ptr[3] - 128.0f); Color c( ptr[0] * exp / 255.0, diff --git a/modules/hdr/image_loader_hdr.h b/modules/hdr/image_loader_hdr.h index 9bc1fadd13..127833ebd0 100644 --- a/modules/hdr/image_loader_hdr.h +++ b/modules/hdr/image_loader_hdr.h @@ -27,8 +27,8 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef IMAGE_LOADER_TINYEXR_H -#define IMAGE_LOADER_TINYEXR_H +#ifndef IMAGE_LOADER_HDR_H +#define IMAGE_LOADER_HDR_H #include "io/image_loader.h" diff --git a/modules/squish/image_compress_squish.cpp b/modules/squish/image_compress_squish.cpp index 2427dac8a7..e927f1ceaa 100644 --- a/modules/squish/image_compress_squish.cpp +++ b/modules/squish/image_compress_squish.cpp @@ -59,9 +59,9 @@ void image_decompress_squish(Image *p_image) { squish_flags = squish::kDxt3; } else if (p_image->get_format() == Image::FORMAT_DXT5) { squish_flags = squish::kDxt5; - } else if (p_image->get_format() == Image::FORMAT_LATC_L || p_image->get_format() == Image::FORMAT_RGTC_R) { + } else if (p_image->get_format() == Image::FORMAT_RGTC_R) { squish_flags = squish::kBc4; - } else if (p_image->get_format() == Image::FORMAT_LATC_LA || p_image->get_format() == Image::FORMAT_RGTC_RG) { + } else if (p_image->get_format() == Image::FORMAT_RGTC_RG) { squish_flags = squish::kBc5; } else { ERR_FAIL_COND(true); @@ -79,7 +79,7 @@ void image_decompress_squish(Image *p_image) { p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data); } -void image_compress_squish(Image *p_image) { +void image_compress_squish(Image *p_image, bool p_srgb) { if (p_image->get_format() >= Image::FORMAT_DXT1) return; //do not compress, already compressed @@ -96,16 +96,21 @@ void image_compress_squish(Image *p_image) { p_image->convert(Image::FORMAT_RGBA8); //still uses RGBA to convert + if (p_srgb && (dc == Image::DETECTED_R || dc == Image::DETECTED_RG)) { + //R and RG do not support SRGB + dc = Image::DETECTED_RGB; + } + switch (dc) { case Image::DETECTED_L: { - target_format = Image::FORMAT_LATC_L; - squish_comp |= squish::kBc4; + target_format = Image::FORMAT_DXT1; + squish_comp |= squish::kDxt1; } break; case Image::DETECTED_LA: { - target_format = Image::FORMAT_LATC_LA; - squish_comp |= squish::kBc5; + target_format = Image::FORMAT_DXT5; + squish_comp |= squish::kDxt5; } break; case Image::DETECTED_R: { @@ -148,8 +153,8 @@ void image_compress_squish(Image *p_image) { int bh = h % 4 != 0 ? h + (4 - h % 4) : h; int src_ofs = p_image->get_mipmap_offset(i); - squish::CompressImage(&rb[src_ofs], bw, bh, &wb[dst_ofs], squish_comp); - dst_ofs += (MAX(4, w) * MAX(4, h)) >> shift; + squish::CompressImage(&rb[src_ofs], w, h, &wb[dst_ofs], squish_comp); + dst_ofs += (MAX(4, bw) * MAX(4, bh)) >> shift; w >>= 1; h >>= 1; } diff --git a/modules/squish/image_compress_squish.h b/modules/squish/image_compress_squish.h index 519e3537ef..8d859b8e0b 100644 --- a/modules/squish/image_compress_squish.h +++ b/modules/squish/image_compress_squish.h @@ -32,7 +32,7 @@ #include "image.h" -void image_compress_squish(Image *p_image); +void image_compress_squish(Image *p_image, bool p_srgb); void image_decompress_squish(Image *p_image); #endif // IMAGE_COMPRESS_SQUISH_H diff --git a/modules/tga/SCsub b/modules/tga/SCsub new file mode 100644 index 0000000000..7e405f405c --- /dev/null +++ b/modules/tga/SCsub @@ -0,0 +1,9 @@ +#!/usr/bin/env python + +Import('env') +Import('env_modules') + +env_tga = env_modules.Clone() + +# Godot's own source files +env_tga.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/tga/config.py b/modules/tga/config.py new file mode 100644 index 0000000000..fb920482f5 --- /dev/null +++ b/modules/tga/config.py @@ -0,0 +1,7 @@ + +def can_build(platform): + return True + + +def configure(env): + pass diff --git a/modules/tga/image_loader_tga.cpp b/modules/tga/image_loader_tga.cpp new file mode 100644 index 0000000000..5b8610b975 --- /dev/null +++ b/modules/tga/image_loader_tga.cpp @@ -0,0 +1,314 @@ +/*************************************************************************/ +/* image_loader_jpegd.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "image_loader_tga.h" + +#include "os/os.h" +#include "print_string.h" + +Error ImageLoaderTGA::decode_tga_rle(const uint8_t *p_compressed_buffer, size_t p_pixel_size, uint8_t *p_uncompressed_buffer, size_t p_output_size) { + Error error; + + PoolVector<uint8_t> pixels; + error = pixels.resize(p_pixel_size); + if (error != OK) + return error; + + PoolVector<uint8_t>::Write pixels_w = pixels.write(); + + size_t compressed_pos = 0; + size_t output_pos = 0; + size_t c = 0; + size_t count = 0; + + while (output_pos < p_output_size) { + c = p_compressed_buffer[compressed_pos]; + compressed_pos += 1; + count = (c & 0x7f) + 1; + + if (c & 0x80) { + for (int i = 0; i < p_pixel_size; i++) { + pixels_w.ptr()[i] = p_compressed_buffer[compressed_pos]; + compressed_pos += 1; + } + for (int i = 0; i < count; i++) { + for (int j = 0; j < p_pixel_size; j++) { + p_uncompressed_buffer[output_pos + j] = pixels_w.ptr()[j]; + } + output_pos += p_pixel_size; + } + } else { + count *= p_pixel_size; + for (int i = 0; i < count; i++) { + p_uncompressed_buffer[output_pos] = p_compressed_buffer[compressed_pos]; + compressed_pos += 1; + output_pos += 1; + } + } + } + return OK; +} + +Error ImageLoaderTGA::convert_to_image(Ref<Image> p_image, const uint8_t *p_buffer, const tga_header_s &p_header, const uint8_t *p_palette, const bool p_is_monochrome) { + +#define TGA_PUT_PIXEL(r, g, b, a) \ + int image_data_ofs = ((y * width) + x); \ + image_data_w[image_data_ofs * 4 + 0] = r; \ + image_data_w[image_data_ofs * 4 + 1] = g; \ + image_data_w[image_data_ofs * 4 + 2] = b; \ + image_data_w[image_data_ofs * 4 + 3] = a; + + uint32_t width = p_header.image_width; + uint32_t height = p_header.image_height; + tga_origin_e origin = static_cast<tga_origin_e>((p_header.image_descriptor & TGA_ORIGIN_MASK) >> TGA_ORIGIN_SHIFT); + + uint32_t x_start; + int32_t x_step; + uint32_t x_end; + uint32_t y_start; + int32_t y_step; + uint32_t y_end; + + if (origin == TGA_ORIGIN_TOP_LEFT || origin == TGA_ORIGIN_TOP_RIGHT) { + y_start = 0; + y_step = 1; + y_end = height; + } else { + y_start = height - 1; + y_step = -1; + y_end = -1; + } + + if (origin == TGA_ORIGIN_TOP_LEFT || origin == TGA_ORIGIN_BOTTOM_LEFT) { + x_start = 0; + x_step = 1; + x_end = width; + } else { + x_start = width - 1; + x_step = -1; + x_end = -1; + } + + PoolVector<uint8_t> image_data; + image_data.resize(width * height * sizeof(uint32_t)); + PoolVector<uint8_t>::Write image_data_w = image_data.write(); + + size_t i = 0; + uint32_t x = x_start; + uint32_t y = y_start; + + if (p_header.pixel_depth == 8) { + if (p_is_monochrome) { + while (y != y_end) { + while (x != x_end) { + uint8_t shade = p_buffer[i]; + + TGA_PUT_PIXEL(shade, shade, shade, 0xff) + + x += x_step; + i += 1; + } + x = x_start; + y += y_step; + } + } else { + while (y != y_end) { + while (x != x_end) { + uint8_t index = p_buffer[i]; + uint8_t r = 0x00; + uint8_t g = 0x00; + uint8_t b = 0x00; + uint8_t a = 0xff; + + if (p_header.color_map_depth == 24) { + r = (p_palette[(index * 3) + 0]); + g = (p_palette[(index * 3) + 1]); + b = (p_palette[(index * 3) + 2]); + } else { + return ERR_INVALID_DATA; + } + + TGA_PUT_PIXEL(r, g, b, a) + + x += x_step; + i += 1; + } + x = x_start; + y += y_step; + } + } + } else if (p_header.pixel_depth == 24) { + while (y != y_end) { + while (x != x_end) { + uint8_t r = p_buffer[i + 2]; + uint8_t g = p_buffer[i + 1]; + uint8_t b = p_buffer[i + 0]; + + TGA_PUT_PIXEL(r, g, b, 0xff) + + x += x_step; + i += 3; + } + x = x_start; + y += y_step; + } + } else if (p_header.pixel_depth == 32) { + while (y != y_end) { + while (x != x_end) { + uint8_t a = p_buffer[i + 3]; + uint8_t r = p_buffer[i + 2]; + uint8_t g = p_buffer[i + 1]; + uint8_t b = p_buffer[i + 0]; + + TGA_PUT_PIXEL(r, g, b, a) + + x += x_step; + i += 4; + } + x = x_start; + y += y_step; + } + } + + image_data_w = PoolVector<uint8_t>::Write(); + + p_image->create(width, height, 0, Image::FORMAT_RGBA8, image_data); + + return OK; +} + +Error ImageLoaderTGA::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) { + + PoolVector<uint8_t> src_image; + int src_image_len = f->get_len(); + ERR_FAIL_COND_V(src_image_len == 0, ERR_FILE_CORRUPT); + ERR_FAIL_COND_V(src_image_len < sizeof(tga_header_s), ERR_FILE_CORRUPT); + src_image.resize(src_image_len); + + Error err = OK; + + tga_header_s tga_header; + tga_header.id_length = f->get_8(); + tga_header.color_map_type = f->get_8(); + tga_header.image_type = static_cast<tga_type_e>(f->get_8()); + + tga_header.first_color_entry = f->get_16(); + tga_header.color_map_length = f->get_16(); + tga_header.color_map_depth = f->get_8(); + + tga_header.x_origin = f->get_16(); + tga_header.y_origin = f->get_16(); + tga_header.image_width = f->get_16(); + tga_header.image_height = f->get_16(); + tga_header.pixel_depth = f->get_8(); + tga_header.image_descriptor = f->get_8(); + + bool is_encoded = (tga_header.image_type == TGA_TYPE_RLE_INDEXED || tga_header.image_type == TGA_TYPE_RLE_RGB || tga_header.image_type == TGA_TYPE_RLE_MONOCHROME); + bool has_color_map = (tga_header.image_type == TGA_TYPE_RLE_INDEXED || tga_header.image_type == TGA_TYPE_INDEXED); + bool is_monochrome = (tga_header.image_type == TGA_TYPE_RLE_MONOCHROME || tga_header.image_type == TGA_TYPE_MONOCHROME); + + if (tga_header.image_type == TGA_TYPE_NO_DATA) + err = FAILED; + + if (has_color_map) { + if (tga_header.color_map_length > 256 || (tga_header.color_map_depth != 24) || tga_header.color_map_type != 1) { + err = FAILED; + } + } else { + if (tga_header.color_map_type) { + err = FAILED; + } + } + + if (tga_header.image_width <= 0 || tga_header.image_height <= 0) + err = FAILED; + + if (tga_header.pixel_depth != 8 && tga_header.pixel_depth != 24 && tga_header.pixel_depth != 32) + err = FAILED; + + if (err == OK) { + f->seek(f->get_pos() + tga_header.id_length); + + PoolVector<uint8_t> palette; + + if (has_color_map) { + size_t color_map_size = tga_header.color_map_length * (tga_header.color_map_depth >> 3); + err = palette.resize(color_map_size); + if (err == OK) { + PoolVector<uint8_t>::Write palette_w = palette.write(); + f->get_buffer(&palette_w[0], color_map_size); + } else { + return OK; + } + } + + PoolVector<uint8_t>::Write src_image_w = src_image.write(); + f->get_buffer(&src_image_w[0], src_image_len - f->get_pos()); + + PoolVector<uint8_t>::Read src_image_r = src_image.read(); + + const size_t pixel_size = tga_header.pixel_depth >> 3; + const size_t buffer_size = (tga_header.image_width * tga_header.image_height) * pixel_size; + + PoolVector<uint8_t> uncompressed_buffer; + uncompressed_buffer.resize(buffer_size); + PoolVector<uint8_t>::Write uncompressed_buffer_w = uncompressed_buffer.write(); + PoolVector<uint8_t>::Read uncompressed_buffer_r; + + const uint8_t *buffer = NULL; + + if (is_encoded) { + + err = decode_tga_rle(src_image_r.ptr(), pixel_size, uncompressed_buffer_w.ptr(), buffer_size); + + if (err == OK) { + uncompressed_buffer_r = uncompressed_buffer.read(); + buffer = uncompressed_buffer_r.ptr(); + } + } else { + buffer = src_image_r.ptr(); + }; + + if (err == OK) { + PoolVector<uint8_t>::Read palette_r = palette.read(); + err = convert_to_image(p_image, buffer, tga_header, palette_r.ptr(), is_monochrome); + } + } + + f->close(); + return err; +} + +void ImageLoaderTGA::get_recognized_extensions(List<String> *p_extensions) const { + + p_extensions->push_back("tga"); +} + +ImageLoaderTGA::ImageLoaderTGA() { +} diff --git a/modules/tga/image_loader_tga.h b/modules/tga/image_loader_tga.h new file mode 100644 index 0000000000..11329ec68a --- /dev/null +++ b/modules/tga/image_loader_tga.h @@ -0,0 +1,83 @@ +/*************************************************************************/ +/* image_loader_jpegd.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef IMAGE_LOADER_TGA_H +#define IMAGE_LOADER_TGA_H + +#include "io/image_loader.h" + +/** + @author SaracenOne +*/ +class ImageLoaderTGA : public ImageFormatLoader { + enum tga_type_e { + TGA_TYPE_NO_DATA = 0, + TGA_TYPE_INDEXED = 1, + TGA_TYPE_RGB = 2, + TGA_TYPE_MONOCHROME = 3, + TGA_TYPE_RLE_INDEXED = 9, + TGA_TYPE_RLE_RGB = 10, + TGA_TYPE_RLE_MONOCHROME = 11 + }; + + enum tga_origin_e { + TGA_ORIGIN_BOTTOM_LEFT = 0x00, + TGA_ORIGIN_BOTTOM_RIGHT = 0x01, + TGA_ORIGIN_TOP_LEFT = 0x02, + TGA_ORIGIN_TOP_RIGHT = 0x03, + TGA_ORIGIN_SHIFT = 0x04, + TGA_ORIGIN_MASK = 0x30 + }; + + struct tga_header_s { + uint8_t id_length; + uint8_t color_map_type; + tga_type_e image_type; + + uint16_t first_color_entry; + uint16_t color_map_length; + uint8_t color_map_depth; + + uint16_t x_origin; + uint16_t y_origin; + uint16_t image_width; + uint16_t image_height; + uint8_t pixel_depth; + uint8_t image_descriptor; + }; + static Error decode_tga_rle(const uint8_t *p_compressed_buffer, size_t p_pixel_size, uint8_t *p_uncompressed_buffer, size_t p_output_size); + static Error convert_to_image(Ref<Image> p_image, const uint8_t *p_buffer, const tga_header_s &p_header, const uint8_t *p_palette, const bool p_is_monochrome); + +public: + virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear); + virtual void get_recognized_extensions(List<String> *p_extensions) const; + ImageLoaderTGA(); +}; + +#endif diff --git a/modules/tga/register_types.cpp b/modules/tga/register_types.cpp new file mode 100644 index 0000000000..6e120fa3bf --- /dev/null +++ b/modules/tga/register_types.cpp @@ -0,0 +1,45 @@ +/*************************************************************************/ +/* register_types.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "register_types.h" + +#include "image_loader_tga.h" + +static ImageLoaderTGA *image_loader_tga = NULL; + +void register_tga_types() { + + image_loader_tga = memnew(ImageLoaderTGA); + ImageLoader::add_image_format_loader(image_loader_tga); +} + +void unregister_tga_types() { + + memdelete(image_loader_tga); +} diff --git a/modules/tga/register_types.h b/modules/tga/register_types.h new file mode 100644 index 0000000000..079b7bf291 --- /dev/null +++ b/modules/tga/register_types.h @@ -0,0 +1,31 @@ +/*************************************************************************/ +/* register_types.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +void register_tga_types(); +void unregister_tga_types(); diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 5839bc9243..941668d474 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -1011,7 +1011,7 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt } Rect2 pos = members->get_item_rect(ti); - new_function_menu->set_position(members->get_global_position() + pos.pos + Vector2(0, pos.size.y)); + new_function_menu->set_position(members->get_global_position() + pos.position + Vector2(0, pos.size.y)); new_function_menu->popup(); return; } else if (p_button == 0) { @@ -2240,6 +2240,10 @@ void VisualScriptEditor::add_callback(const String &p_function, PoolStringArray //undo_redo->clear_history(); } +bool VisualScriptEditor::show_members_overview() { + return false; +} + void VisualScriptEditor::update_settings() { _update_graph(); diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index bb832431a0..92f31f20da 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -248,6 +248,7 @@ public: virtual void get_breakpoints(List<int> *p_breakpoints); virtual void add_callback(const String &p_function, PoolStringArray p_args); virtual void update_settings(); + virtual bool show_members_overview(); virtual void set_debugger_active(bool p_active); virtual void set_tooltip_request_func(String p_method, Object *p_obj); virtual Control *get_edit_menu(); diff --git a/platform/android/detect.py b/platform/android/detect.py index 8d2ed59f17..ce44ffbf74 100644 --- a/platform/android/detect.py +++ b/platform/android/detect.py @@ -232,7 +232,7 @@ def configure(env): elif (env["target"] == "debug"): env.Append(LINKFLAGS=['-O0']) env.Append(CPPFLAGS=['-O0', '-D_DEBUG', '-UNDEBUG', '-DDEBUG_ENABLED', - '-DDEBUG_MEMORY_ALLOC', '-g', '-fno-limit-debug-info']) + '-DDEBUG_MEMORY_ENABLED', '-g', '-fno-limit-debug-info']) env.Append(CPPFLAGS=['-DANDROID_ENABLED', '-DUNIX_ENABLED', '-DNO_FCNTL', '-DMPC_FIXED_POINT']) diff --git a/platform/android/java_glue.cpp b/platform/android/java_glue.cpp index 37f53a2478..d4bd443689 100644 --- a/platform/android/java_glue.cpp +++ b/platform/android/java_glue.cpp @@ -1367,7 +1367,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env jevent.device = p_device; jevent.type = OS_Android::JOY_EVENT_BUTTON; jevent.index = p_button; - jevent->is_pressed() = p_pressed; + jevent.pressed = p_pressed; input_mutex->lock(); joy_events.push_back(jevent); diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index 1c721c645c..9010b9e7da 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -344,7 +344,7 @@ void OS_Android::process_joy_event(OS_Android::JoypadEvent p_event) { switch (p_event.type) { case JOY_EVENT_BUTTON: - input->joy_button(p_event.device, p_event.index, p_event->is_pressed()); + input->joy_button(p_event.device, p_event.index, p_event.pressed); break; case JOY_EVENT_AXIS: InputDefault::JoyAxis value; @@ -380,8 +380,8 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos> ev->set_button_index(BUTTON_LEFT); ev->set_button_mask(BUTTON_MASK_LEFT); ev->set_pressed(false); - ev->set_pos(touch[0].pos); - ev->set_global_pos(touch[0].pos); + ev->set_position(touch[0].pos); + ev->set_global_position(touch[0].pos); input->parse_input_event(ev); } @@ -391,7 +391,7 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos> ev.instance(); ev->set_index(touch[i].id); ev->set_pressed(false); - ev->set_pos(touch[i].pos); + ev->set_position(touch[i].pos); input->parse_input_event(ev); } } @@ -406,12 +406,12 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos> //send mouse Ref<InputEventMouseButton> ev; ev.instance(); - ev.type = Ref<InputEvent>::MOUSE_BUTTON; + // ev.type = Ref<InputEvent>::MOUSE_BUTTON; ev->set_button_index(BUTTON_LEFT); ev->set_button_mask(BUTTON_MASK_LEFT); ev->set_pressed(true); - ev->set_pos(touch[0].pos); - ev->set_global_pos(touch[0].pos); + ev->set_position(touch[0].pos); + ev->set_global_position(touch[0].pos); input->set_mouse_position(Point2(touch[0].pos.x, touch[0].pos.y)); last_mouse = touch[0].pos; input->parse_input_event(ev); @@ -424,7 +424,7 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos> ev.instance(); ev->set_index(touch[i].id); ev->set_pressed(true); - ev->set_pos(touch[i].pos.x); + ev->set_position(touch[i].pos); input->parse_input_event(ev); } @@ -436,8 +436,8 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos> Ref<InputEventMouseMotion> ev; ev.instance(); ev->set_button_mask(BUTTON_MASK_LEFT); - ev->set_pos(p_points[0].pos.x); - input->set_mouse_position(Point2(ev.mouse_motion.x, ev.mouse_motion.y)); + ev->set_position(p_points[0].pos); + input->set_mouse_position(Point2(ev->get_position().x, ev->get_position().y)); ev->set_speed(input->get_last_mouse_speed()); ev->set_relative(p_points[0].pos - last_mouse); last_mouse = p_points[0].pos; @@ -465,7 +465,7 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos> Ref<InputEventScreenDrag> ev; ev.instance(); ev->set_index(touch[i].id); - ev->set_pos(p_points[idx].pos.x); + ev->set_position(p_points[idx].pos); ev->set_relative(p_points[idx].pos - touch[i].pos); input->parse_input_event(ev); touch[i].pos = p_points[idx].pos; @@ -481,8 +481,8 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos> ev->set_button_index(BUTTON_LEFT); ev->set_button_mask(BUTTON_MASK_LEFT); ev->set_pressed(false); - ev->set_pos(touch[0].pos.x); - ev->set_global_pos(touch[0].pos.x); + ev->set_position(touch[0].pos); + ev->set_global_position(touch[0].pos); input->set_mouse_position(Point2(touch[0].pos.x, touch[0].pos.y)); input->parse_input_event(ev); @@ -492,7 +492,7 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos> ev.instance(); ev->set_index(touch[i].id); ev->set_pressed(false); - ev->set_pos(touch[i].pos); + ev->set_position(touch[i].pos); input->parse_input_event(ev); } touch.clear(); @@ -511,7 +511,7 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos> ev->set_index(tp.id); ev->set_pressed(true); - ev->set_pos(tp.pos); + ev->set_position(tp.pos); input->parse_input_event(ev); } break; @@ -524,7 +524,7 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos> ev.instance(); ev->set_index(touch[i].id); ev->set_pressed(false); - ev->set_pos(touch[i].pos); + ev->set_position(touch[i].pos); input->parse_input_event(ev); touch.remove(i); i--; diff --git a/platform/iphone/detect.py b/platform/iphone/detect.py index 2dcd6dd7e5..c20d8e90f4 100644 --- a/platform/iphone/detect.py +++ b/platform/iphone/detect.py @@ -58,15 +58,15 @@ def configure(env): if (env["ios_sim"] == "yes" or env["arch"] == "x86"): # i386, simulator env["arch"] = "x86" env["bits"] = "32" - env.Append(CCFLAGS=string.split('-arch i386 -fobjc-abi-version=2 -fobjc-legacy-dispatch -fmessage-length=0 -fpascal-strings -fasm-blocks -D__IPHONE_OS_VERSION_MIN_REQUIRED=40100 -isysroot $IPHONESDK -mios-simulator-version-min=4.3 -DCUSTOM_MATRIX_TRANSFORM_H=\\\"build/iphone/matrix4_iphone.h\\\" -DCUSTOM_VECTOR3_TRANSFORM_H=\\\"build/iphone/vector3_iphone.h\\\"')) + env.Append(CCFLAGS=string.split('-arch i386 -fobjc-abi-version=2 -fobjc-legacy-dispatch -fmessage-length=0 -fpascal-strings -fblocks -fasm-blocks -D__IPHONE_OS_VERSION_MIN_REQUIRED=40100 -isysroot $IPHONESDK -mios-simulator-version-min=4.3 -DCUSTOM_MATRIX_TRANSFORM_H=\\\"build/iphone/matrix4_iphone.h\\\" -DCUSTOM_VECTOR3_TRANSFORM_H=\\\"build/iphone/vector3_iphone.h\\\"')) elif (env["arch"] == "arm" or env["arch"] == "arm32" or env["arch"] == "armv7" or env["bits"] == "32"): # arm env["arch"] = "arm" env["bits"] = "32" - env.Append(CCFLAGS=string.split('-fno-objc-arc -arch armv7 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -fpascal-strings -isysroot $IPHONESDK -fvisibility=hidden -mthumb "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -miphoneos-version-min=9.0 -MMD -MT dependencies -isysroot $IPHONESDK')) + env.Append(CCFLAGS=string.split('-fno-objc-arc -arch armv7 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -fpascal-strings -fblocks -isysroot $IPHONESDK -fvisibility=hidden -mthumb "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -miphoneos-version-min=9.0 -MMD -MT dependencies')) else: # armv64 env["arch"] = "arm64" env["bits"] = "64" - env.Append(CCFLAGS=string.split('-fno-objc-arc -arch arm64 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -fpascal-strings -fvisibility=hidden -MMD -MT dependencies -miphoneos-version-min=9.0 -isysroot $IPHONESDK')) + env.Append(CCFLAGS=string.split('-fno-objc-arc -arch arm64 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -fpascal-strings -fblocks -fvisibility=hidden -MMD -MT dependencies -miphoneos-version-min=9.0 -isysroot $IPHONESDK')) env.Append(CPPFLAGS=['-DNEED_LONG_INT']) env.Append(CPPFLAGS=['-DLIBYUV_DISABLE_NEON']) @@ -91,6 +91,7 @@ def configure(env): '-framework', 'OpenGLES', '-framework', 'QuartzCore', '-framework', 'SystemConfiguration', + '-framework', 'GameController', '-F$IPHONESDK', ]) elif (env["arch"] == "arm64"): @@ -111,6 +112,7 @@ def configure(env): '-framework', 'AVFoundation', '-framework', 'CoreMedia', '-framework', 'CoreMotion', + '-framework', 'GameController', ]) else: env.Append(LINKFLAGS=['-arch', 'armv7', '-Wl,-dead_strip', '-miphoneos-version-min=9.0', @@ -129,10 +131,11 @@ def configure(env): '-framework', 'AVFoundation', '-framework', 'CoreMedia', '-framework', 'CoreMotion', + '-framework', 'GameController', ]) if env['game_center'] == 'yes': - env.Append(CPPFLAGS=['-fblocks', '-DGAME_CENTER_ENABLED']) + env.Append(CPPFLAGS=['-DGAME_CENTER_ENABLED']) env.Append(LINKFLAGS=['-framework', 'GameKit']) if env['store_kit'] == 'yes': @@ -144,26 +147,20 @@ def configure(env): env.Append(CPPPATH=['$IPHONESDK/usr/include', '$IPHONESDK/System/Library/Frameworks/OpenGLES.framework/Headers', '$IPHONESDK/System/Library/Frameworks/AudioUnit.framework/Headers']) - if (env["target"] == "release"): + if (env["target"].startswith("release")): - env.Append(CCFLAGS=['-O3', '-DNS_BLOCK_ASSERTIONS=1', '-gdwarf-2']) # removed -ffast-math - env.Append(LINKFLAGS=['-O3']) + env.Append(CPPFLAGS=['-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1']) + env.Append(CPPFLAGS=['-O2', '-flto', '-ftree-vectorize', '-fomit-frame-pointer', '-ffast-math', '-funsafe-math-optimizations']) + env.Append(LINKFLAGS=['-O2', '-flto']) - elif env["target"] == "release_debug": - env.Append(CCFLAGS=['-Os', '-DNS_BLOCK_ASSERTIONS=1', '-DDEBUG_ENABLED']) - env.Append(LINKFLAGS=['-Os']) - env.Append(CPPFLAGS=['-DDEBUG_MEMORY_ENABLED']) + if env["target"] == "release_debug": + env.Append(CPPFLAGS=['-DDEBUG_ENABLED']) elif (env["target"] == "debug"): - env.Append(CCFLAGS=['-D_DEBUG', '-DDEBUG=1', '-gdwarf-2', '-O0', '-DDEBUG_ENABLED']) + env.Append(CPPFLAGS=['-D_DEBUG', '-DDEBUG=1', '-gdwarf-2', '-O0', '-DDEBUG_ENABLED']) env.Append(CPPFLAGS=['-DDEBUG_MEMORY_ENABLED']) - elif (env["target"] == "profile"): - - env.Append(CCFLAGS=['-g', '-pg', '-Os']) - env.Append(LINKFLAGS=['-pg']) - if (env["ios_sim"] == "yes"): # TODO: Check if needed? env['ENV']['MACOSX_DEPLOYMENT_TARGET'] = '10.6' env['ENV']['CODESIGN_ALLOCATE'] = '/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate' diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp index 0d7913446e..b244edbff6 100644 --- a/platform/iphone/os_iphone.cpp +++ b/platform/iphone/os_iphone.cpp @@ -212,7 +212,7 @@ void OSIPhone::mouse_button(int p_idx, int p_x, int p_y, bool p_pressed, bool p_ ev->set_index(p_idx); ev->set_pressed(p_pressed); - ev->set_pos(Vector2(p_x, p_y)); + ev->set_position(Vector2(p_x, p_y)); queue_event(ev); }; @@ -225,12 +225,12 @@ void OSIPhone::mouse_button(int p_idx, int p_x, int p_y, bool p_pressed, bool p_ // swaped it for tilted screen //ev->get_pos().x = ev.mouse_button.global_x = video_mode.height - p_y; //ev->get_pos().y = ev.mouse_button.global_y = p_x; - ev->set_pos(Vector2(video_mode.height - p_y, p_x)); - ev->set_global_pos(Vector2(video_mode.height - p_y, p_x)); + ev->set_position(Vector2(video_mode.height - p_y, p_x)); + ev->set_global_position(Vector2(video_mode.height - p_y, p_x)); //mouse_list.pressed[p_idx] = p_pressed; - input->set_mouse_position(ev->get_pos()); + input->set_mouse_position(ev->get_position()); ev->set_button_index(BUTTON_LEFT); ev->set_doubleclick(p_doubleclick); ev->set_pressed(p_pressed); @@ -246,7 +246,7 @@ void OSIPhone::mouse_move(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_ Ref<InputEventScreenDrag> ev; ev.instance(); ev->set_index(p_idx); - ev->set_pos(Vector2(p_x, p_y)); + ev->set_position(Vector2(p_x, p_y)); ev->set_relative(Vector2(p_x - p_prev_x, p_y - p_prev_y)); queue_event(ev); }; @@ -255,11 +255,11 @@ void OSIPhone::mouse_move(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_ Ref<InputEventMouseMotion> ev; ev.instance(); - ev->set_pos(Vector2(p_x, p_y)); - ev->set_global_pos(Vector2(p_x, p_y)); + ev->set_position(Vector2(p_x, p_y)); + ev->set_global_position(Vector2(p_x, p_y)); ev->set_relative(Vector2(p_x - p_prev_x, p_y - p_prev_y)); - input->set_mouse_position(ev->get_pos()); + input->set_mouse_position(ev->get_position()); ev->set_speed(input->get_last_mouse_speed()); ev->set_button_mask(BUTTON_LEFT); // pressed diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 13bc2226f4..54b1802250 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -291,8 +291,8 @@ static int button_mask = 0; get_key_modifier_state([event modifierFlags], mb); mb->set_button_index(BUTTON_LEFT); mb->set_pressed(true); - mb->set_pos(Vector2(mouse_x, mouse_y)); - mb->set_global_pos(Vector2(mouse_x, mouse_y)); + mb->set_position(Vector2(mouse_x, mouse_y)); + mb->set_global_position(Vector2(mouse_x, mouse_y)); mb->set_button_mask(button_mask); mb->set_doubleclick([event clickCount] == 2); OS_OSX::singleton->push_input(mb); @@ -311,8 +311,8 @@ static int button_mask = 0; get_key_modifier_state([event modifierFlags], mb); mb->set_button_index(BUTTON_LEFT); mb->set_pressed(false); - mb->set_pos(Vector2(mouse_x, mouse_y)); - mb->set_global_pos(Vector2(mouse_x, mouse_y)); + mb->set_position(Vector2(mouse_x, mouse_y)); + mb->set_global_position(Vector2(mouse_x, mouse_y)); mb->set_button_mask(button_mask); mb->set_doubleclick([event clickCount] == 2); OS_OSX::singleton->push_input(mb); @@ -330,8 +330,8 @@ static int button_mask = 0; const NSPoint p = [event locationInWindow]; mouse_x = p.x * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); mouse_y = (contentRect.size.height - p.y) * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); - mm->set_pos(Vector2(mouse_x, mouse_y)); - mm->set_global_pos(Vector2(mouse_x, mouse_y)); + mm->set_position(Vector2(mouse_x, mouse_y)); + mm->set_global_position(Vector2(mouse_x, mouse_y)); Vector2 relativeMotion = Vector2(); relativeMotion.x = [event deltaX] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); relativeMotion.y = [event deltaY] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); @@ -352,8 +352,8 @@ static int button_mask = 0; get_key_modifier_state([event modifierFlags], mb); mb->set_button_index(BUTTON_RIGHT); mb->set_pressed(true); - mb->set_pos(Vector2(mouse_x, mouse_y)); - mb->set_global_pos(Vector2(mouse_x, mouse_y)); + mb->set_position(Vector2(mouse_x, mouse_y)); + mb->set_global_position(Vector2(mouse_x, mouse_y)); mb->set_button_mask(button_mask); mb->set_doubleclick([event clickCount] == 2); OS_OSX::singleton->push_input(mb); @@ -365,7 +365,7 @@ static int button_mask = 0; - (void)rightMouseUp:(NSEvent *)event { - button_mask |= BUTTON_MASK_RIGHT; + button_mask &= ~BUTTON_MASK_RIGHT; Ref<InputEventMouseButton> mb; mb.instance(); @@ -373,8 +373,8 @@ static int button_mask = 0; get_key_modifier_state([event modifierFlags], mb); mb->set_button_index(BUTTON_RIGHT); mb->set_pressed(false); - mb->set_pos(Vector2(mouse_x, mouse_y)); - mb->set_global_pos(Vector2(mouse_x, mouse_y)); + mb->set_position(Vector2(mouse_x, mouse_y)); + mb->set_global_position(Vector2(mouse_x, mouse_y)); mb->set_button_mask(button_mask); mb->set_doubleclick([event clickCount] == 2); OS_OSX::singleton->push_input(mb); @@ -393,8 +393,8 @@ static int button_mask = 0; get_key_modifier_state([event modifierFlags], mb); mb->set_button_index(BUTTON_MIDDLE); mb->set_pressed(true); - mb->set_pos(Vector2(mouse_x, mouse_y)); - mb->set_global_pos(Vector2(mouse_x, mouse_y)); + mb->set_position(Vector2(mouse_x, mouse_y)); + mb->set_global_position(Vector2(mouse_x, mouse_y)); mb->set_button_mask(button_mask); mb->set_doubleclick([event clickCount] == 2); OS_OSX::singleton->push_input(mb); @@ -417,8 +417,8 @@ static int button_mask = 0; get_key_modifier_state([event modifierFlags], mb); mb->set_button_index(BUTTON_MIDDLE); mb->set_pressed(true); - mb->set_pos(Vector2(mouse_x, mouse_y)); - mb->set_global_pos(Vector2(mouse_x, mouse_y)); + mb->set_position(Vector2(mouse_x, mouse_y)); + mb->set_global_position(Vector2(mouse_x, mouse_y)); mb->set_button_mask(button_mask); mb->set_doubleclick([event clickCount] == 2); OS_OSX::singleton->push_input(mb); @@ -701,8 +701,8 @@ inline void sendScrollEvent(int button, double factor, int modifierFlags) { sc->set_factor(factor); sc->set_pressed(true); Vector2 mouse_pos = Vector2(mouse_x, mouse_y); - sc->set_pos(mouse_pos); - sc->set_global_pos(mouse_pos); + sc->set_position(mouse_pos); + sc->set_global_position(mouse_pos); sc->set_button_mask(button_mask); OS_OSX::singleton->push_input(sc); sc->set_pressed(false); @@ -974,7 +974,7 @@ void OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_au NSRect nsrect = [[screenArray objectAtIndex:i] visibleFrame]; Rect2 rect = Rect2(nsrect.origin.x, nsrect.origin.y, nsrect.size.width, nsrect.size.height); - rect.pos *= displayScale; + rect.position *= displayScale; rect.size *= displayScale; screens.push_back(rect); @@ -1275,7 +1275,7 @@ void OS_OSX::set_current_screen(int p_screen) { Point2 OS_OSX::get_screen_position(int p_screen) const { ERR_FAIL_INDEX_V(p_screen, screens.size(), Point2()); - return screens[p_screen].pos; + return screens[p_screen].position; }; int OS_OSX::get_screen_dpi(int p_screen) const { @@ -1384,7 +1384,7 @@ void OS_OSX::set_window_maximized(bool p_enabled) { [window_object setFrame:[[[NSScreen screens] objectAtIndex:current_screen] visibleFrame] display:YES]; } else { set_window_size(restore_rect.size); - set_window_position(restore_rect.pos); + set_window_position(restore_rect.position); }; maximized = p_enabled; }; diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 830aae5515..a9fcf70b55 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -219,7 +219,7 @@ void OS_Windows::_touch_event(bool p_pressed, int p_x, int p_y, int idx) { event.instance(); event->set_index(idx); event->set_pressed(p_pressed); - event->set_pos(Vector2(p_x, p_y)); + event->set_position(Vector2(p_x, p_y)); if (main_loop) { input->parse_input_event(event); @@ -231,7 +231,7 @@ void OS_Windows::_drag_event(int p_x, int p_y, int idx) { Ref<InputEventScreenDrag> event; event.instance(); event->set_index(idx); - event->set_pos(Vector2(p_x, p_y)); + event->set_position(Vector2(p_x, p_y)); if (main_loop) input->parse_input_event(event); @@ -378,7 +378,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) last_button_state = mm->get_button_mask(); /*mm->get_button_mask()|=(wParam&MK_XBUTTON1)?(1<<5):0; mm->get_button_mask()|=(wParam&MK_XBUTTON2)?(1<<6):0;*/ - mm->set_pos(Vector2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); + mm->set_position(Vector2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); if (mouse_mode == MOUSE_MODE_CAPTURED) { @@ -386,31 +386,31 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) old_x = c.x; old_y = c.y; - if (mm->get_pos() == c) { + if (mm->get_position() == c) { center = c; return 0; } - Point2i ncenter = mm->get_pos(); + Point2i ncenter = mm->get_position(); center = ncenter; POINT pos = { (int)c.x, (int)c.y }; ClientToScreen(hWnd, &pos); SetCursorPos(pos.x, pos.y); } - input->set_mouse_position(mm->get_pos()); + input->set_mouse_position(mm->get_position()); mm->set_speed(input->get_last_mouse_speed()); if (old_invalid) { - old_x = mm->get_pos().x; - old_y = mm->get_pos().y; + old_x = mm->get_position().x; + old_y = mm->get_position().y; old_invalid = false; } - mm->set_relative(Vector2(mm->get_pos() - Vector2(old_x, old_y))); - old_x = mm->get_pos().x; - old_y = mm->get_pos().y; + mm->set_relative(Vector2(mm->get_position() - Vector2(old_x, old_y))); + old_x = mm->get_position().x; + old_y = mm->get_position().y; if (window_has_focus && main_loop) input->parse_input_event(mm); @@ -536,14 +536,14 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) /* mb->get_button_mask()|=(wParam&MK_XBUTTON1)?(1<<5):0; mb->get_button_mask()|=(wParam&MK_XBUTTON2)?(1<<6):0;*/ - mb->set_pos(Vector2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); + mb->set_position(Vector2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); if (mouse_mode == MOUSE_MODE_CAPTURED) { - mb->set_pos(Vector2(old_x, old_y)); + mb->set_position(Vector2(old_x, old_y)); } - mb->set_global_pos(mb->get_pos()); + mb->set_global_position(mb->get_position()); if (uMsg != WM_MOUSEWHEEL) { if (mb->is_pressed()) { @@ -560,12 +560,12 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) } else if (mouse_mode != MOUSE_MODE_CAPTURED) { // for reasons unknown to mankind, wheel comes in screen cordinates POINT coords; - coords.x = mb->get_pos().x; - coords.y = mb->get_pos().y; + coords.x = mb->get_position().x; + coords.y = mb->get_position().y; ScreenToClient(hWnd, &coords); - mb->set_pos(Vector2(coords.x, coords.y)); + mb->set_position(Vector2(coords.x, coords.y)); } if (main_loop) { @@ -889,8 +889,8 @@ BOOL CALLBACK OS_Windows::MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPR MonitorInfo minfo; minfo.hMonitor = hMonitor; minfo.hdcMonitor = hdcMonitor; - minfo.rect.pos.x = lprcMonitor->left; - minfo.rect.pos.y = lprcMonitor->top; + minfo.rect.position.x = lprcMonitor->left; + minfo.rect.position.y = lprcMonitor->top; minfo.rect.size.x = lprcMonitor->right - lprcMonitor->left; minfo.rect.size.y = lprcMonitor->bottom - lprcMonitor->top; @@ -1370,7 +1370,7 @@ void OS_Windows::set_current_screen(int p_screen) { Point2 OS_Windows::get_screen_position(int p_screen) const { ERR_FAIL_INDEX_V(p_screen, monitor_info.size(), Point2()); - return Vector2(monitor_info[p_screen].rect.pos); + return Vector2(monitor_info[p_screen].rect.position); } Size2 OS_Windows::get_screen_size(int p_screen) const { diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 2a912a7ba2..8ac37c965b 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -1334,8 +1334,8 @@ void OS_X11::process_xevents() { get_key_modifier_state(event.xbutton.state, mb); mb->set_button_mask(get_mouse_button_state(event.xbutton.state)); - mb->set_pos(Vector2(event.xbutton.x, event.xbutton.y)); - mb->set_global_pos(mb->get_pos()); + mb->set_position(Vector2(event.xbutton.x, event.xbutton.y)); + mb->set_global_position(mb->get_position()); mb->set_button_index(event.xbutton.button); if (mb->get_button_index() == 2) mb->set_button_index(3); @@ -1443,8 +1443,8 @@ void OS_X11::process_xevents() { get_key_modifier_state(event.xmotion.state, mm); mm->set_button_mask(get_mouse_button_state(event.xmotion.state)); - mm->set_pos(pos); - mm->set_global_pos(pos); + mm->set_position(pos); + mm->set_global_position(pos); input->set_mouse_position(pos); mm->set_speed(input->get_last_mouse_speed()); mm->set_relative(rel); diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index 71f651b0a4..9d8b5da366 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -120,20 +120,20 @@ Transform2D Camera2D::get_camera_transform() { Rect2 screen_rect(-screen_offset + camera_pos, screen_size * zoom); if (offset != Vector2()) - screen_rect.pos += offset; + screen_rect.position += offset; if (limit_smoothing_enabled) { - if (screen_rect.pos.x < limit[MARGIN_LEFT]) - camera_pos.x -= screen_rect.pos.x - limit[MARGIN_LEFT]; + if (screen_rect.position.x < limit[MARGIN_LEFT]) + camera_pos.x -= screen_rect.position.x - limit[MARGIN_LEFT]; - if (screen_rect.pos.x + screen_rect.size.x > limit[MARGIN_RIGHT]) - camera_pos.x -= screen_rect.pos.x + screen_rect.size.x - limit[MARGIN_RIGHT]; + if (screen_rect.position.x + screen_rect.size.x > limit[MARGIN_RIGHT]) + camera_pos.x -= screen_rect.position.x + screen_rect.size.x - limit[MARGIN_RIGHT]; - if (screen_rect.pos.y + screen_rect.size.y > limit[MARGIN_BOTTOM]) - camera_pos.y -= screen_rect.pos.y + screen_rect.size.y - limit[MARGIN_BOTTOM]; + if (screen_rect.position.y + screen_rect.size.y > limit[MARGIN_BOTTOM]) + camera_pos.y -= screen_rect.position.y + screen_rect.size.y - limit[MARGIN_BOTTOM]; - if (screen_rect.pos.y < limit[MARGIN_TOP]) - camera_pos.y -= screen_rect.pos.y - limit[MARGIN_TOP]; + if (screen_rect.position.y < limit[MARGIN_TOP]) + camera_pos.y -= screen_rect.position.y - limit[MARGIN_TOP]; } if (smoothing_enabled && !get_tree()->is_editor_hint()) { @@ -160,42 +160,42 @@ Transform2D Camera2D::get_camera_transform() { } Rect2 screen_rect(-screen_offset + ret_camera_pos, screen_size * zoom); - if (screen_rect.pos.x < limit[MARGIN_LEFT]) - screen_rect.pos.x = limit[MARGIN_LEFT]; + if (screen_rect.position.x < limit[MARGIN_LEFT]) + screen_rect.position.x = limit[MARGIN_LEFT]; - if (screen_rect.pos.x + screen_rect.size.x > limit[MARGIN_RIGHT]) - screen_rect.pos.x = limit[MARGIN_RIGHT] - screen_rect.size.x; + if (screen_rect.position.x + screen_rect.size.x > limit[MARGIN_RIGHT]) + screen_rect.position.x = limit[MARGIN_RIGHT] - screen_rect.size.x; - if (screen_rect.pos.y + screen_rect.size.y > limit[MARGIN_BOTTOM]) - screen_rect.pos.y = limit[MARGIN_BOTTOM] - screen_rect.size.y; + if (screen_rect.position.y + screen_rect.size.y > limit[MARGIN_BOTTOM]) + screen_rect.position.y = limit[MARGIN_BOTTOM] - screen_rect.size.y; - if (screen_rect.pos.y < limit[MARGIN_TOP]) - screen_rect.pos.y = limit[MARGIN_TOP]; + if (screen_rect.position.y < limit[MARGIN_TOP]) + screen_rect.position.y = limit[MARGIN_TOP]; if (offset != Vector2()) { - screen_rect.pos += offset; - if (screen_rect.pos.x + screen_rect.size.x > limit[MARGIN_RIGHT]) - screen_rect.pos.x = limit[MARGIN_RIGHT] - screen_rect.size.x; + screen_rect.position += offset; + if (screen_rect.position.x + screen_rect.size.x > limit[MARGIN_RIGHT]) + screen_rect.position.x = limit[MARGIN_RIGHT] - screen_rect.size.x; - if (screen_rect.pos.y + screen_rect.size.y > limit[MARGIN_BOTTOM]) - screen_rect.pos.y = limit[MARGIN_BOTTOM] - screen_rect.size.y; + if (screen_rect.position.y + screen_rect.size.y > limit[MARGIN_BOTTOM]) + screen_rect.position.y = limit[MARGIN_BOTTOM] - screen_rect.size.y; - if (screen_rect.pos.x < limit[MARGIN_LEFT]) - screen_rect.pos.x = limit[MARGIN_LEFT]; + if (screen_rect.position.x < limit[MARGIN_LEFT]) + screen_rect.position.x = limit[MARGIN_LEFT]; - if (screen_rect.pos.y < limit[MARGIN_TOP]) - screen_rect.pos.y = limit[MARGIN_TOP]; + if (screen_rect.position.y < limit[MARGIN_TOP]) + screen_rect.position.y = limit[MARGIN_TOP]; } - camera_screen_center = screen_rect.pos + screen_rect.size * 0.5; + camera_screen_center = screen_rect.position + screen_rect.size * 0.5; Transform2D xform; if (rotating) { xform.set_rotation(angle); } xform.scale_basis(zoom); - xform.set_origin(screen_rect.pos /*.floor()*/); + xform.set_origin(screen_rect.position /*.floor()*/); /* if (0) { diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp index 39eef89274..6b603c6473 100644 --- a/scene/2d/collision_polygon_2d.cpp +++ b/scene/2d/collision_polygon_2d.cpp @@ -233,7 +233,7 @@ void CollisionPolygon2D::set_polygon(const Vector<Point2> &p_polygon) { aabb = Rect2(-10, -10, 20, 20); } else { - aabb.pos -= aabb.size * 0.3; + aabb.position -= aabb.size * 0.3; aabb.size += aabb.size * 0.6; } _update_parent(); diff --git a/scene/2d/line_builder.cpp b/scene/2d/line_builder.cpp index add476ae0f..ea059d133d 100644 --- a/scene/2d/line_builder.cpp +++ b/scene/2d/line_builder.cpp @@ -83,8 +83,8 @@ static inline Vector2 rotate90(const Vector2 &v) { static inline Vector2 interpolate(const Rect2 &r, const Vector2 &v) { return Vector2( - Math::lerp(r.get_pos().x, r.get_pos().x + r.get_size().x, v.x), - Math::lerp(r.get_pos().y, r.get_pos().y + r.get_size().y, v.y)); + Math::lerp(r.position.x, r.position.x + r.get_size().x, v.x), + Math::lerp(r.position.y, r.position.y + r.get_size().y, v.y)); } //---------------------------------------------------------------------------- diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index ec286b1d54..6fe1dd73fe 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -76,9 +76,9 @@ void Node2D::edit_set_rect(const Rect2 &p_edit_rect) { Vector2 zero_offset; if (r.size.x != 0) - zero_offset.x = -r.pos.x / r.size.x; + zero_offset.x = -r.position.x / r.size.x; if (r.size.y != 0) - zero_offset.y = -r.pos.y / r.size.y; + zero_offset.y = -r.position.y / r.size.y; Size2 new_scale(1, 1); @@ -87,7 +87,7 @@ void Node2D::edit_set_rect(const Rect2 &p_edit_rect) { if (r.size.y != 0) new_scale.y = p_edit_rect.size.y / r.size.y; - Point2 new_pos = p_edit_rect.pos + p_edit_rect.size * zero_offset; //p_edit_rect.pos - r.pos; + Point2 new_pos = p_edit_rect.position + p_edit_rect.size * zero_offset; //p_edit_rect.pos - r.pos; Transform2D postxf; postxf.set_rotation_and_scale(angle, _scale); diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp index 951861256e..27d0d07c0f 100644 --- a/scene/2d/particles_2d.cpp +++ b/scene/2d/particles_2d.cpp @@ -568,8 +568,8 @@ void Particles2D::_notification(int p_what) { if (total_frames > 1) { int frame = Math::fast_ftoi(Math::floor(p.frame * total_frames)) % total_frames; - src_rect.pos.x = size.x * (frame % h_frames); - src_rect.pos.y = size.y * (frame / h_frames); + src_rect.position.x = size.x * (frame % h_frames); + src_rect.position.y = size.y * (frame / h_frames); } Rect2 dst_rect(Point2(), size); if (flip_h) diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp index cb3e67f895..5c1c953a37 100644 --- a/scene/2d/polygon_2d.cpp +++ b/scene/2d/polygon_2d.cpp @@ -38,7 +38,7 @@ Rect2 Polygon2D::get_item_rect() const { for (int i = 0; i < l; i++) { Vector2 pos = r[i] + offset; if (i == 0) - item_rect.pos = pos; + item_rect.position = pos; else item_rect.expand_to(pos); } @@ -95,7 +95,7 @@ void Polygon2D::_notification(int p_what) { for (int i = 0; i < len; i++) { if (i == 0) - bounds.pos = points[i]; + bounds.position = points[i]; else bounds.expand_to(points[i]); if (points[i].y > highest_y) { @@ -110,10 +110,10 @@ void Polygon2D::_notification(int p_what) { Vector2 ep[7] = { Vector2(points[highest_idx].x, points[highest_idx].y + invert_border), - Vector2(bounds.pos + bounds.size), - Vector2(bounds.pos + Vector2(bounds.size.x, 0)), - Vector2(bounds.pos), - Vector2(bounds.pos + Vector2(0, bounds.size.y)), + Vector2(bounds.position + bounds.size), + Vector2(bounds.position + Vector2(bounds.size.x, 0)), + Vector2(bounds.position), + Vector2(bounds.position + Vector2(0, bounds.size.y)), Vector2(points[highest_idx].x - CMP_EPSILON, points[highest_idx].y + invert_border), Vector2(points[highest_idx].x - CMP_EPSILON, points[highest_idx].y), }; diff --git a/scene/2d/screen_button.cpp b/scene/2d/screen_button.cpp index f503a66208..ea68a111af 100644 --- a/scene/2d/screen_button.cpp +++ b/scene/2d/screen_button.cpp @@ -207,7 +207,7 @@ void TouchScreenButton::_input(const Ref<InputEvent> &p_event) { if ((st.is_valid() && st->is_pressed()) || sd.is_valid()) { int index = st.is_valid() ? st->get_index() : sd->get_index(); - Vector2 coord = st.is_valid() ? st->get_pos() : sd->get_pos(); + Vector2 coord = st.is_valid() ? st->get_position() : sd->get_position(); if (finger_pressed == -1 || index == finger_pressed) { @@ -254,7 +254,7 @@ void TouchScreenButton::_input(const Ref<InputEvent> &p_event) { if (!can_press) return; //already fingering - Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(st->get_pos()); + Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(st->get_position()); Rect2 item_rect = get_item_rect(); bool touched = false; diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp index 1735bf3b91..c1eb90e52a 100644 --- a/scene/2d/sprite.cpp +++ b/scene/2d/sprite.cpp @@ -75,8 +75,8 @@ void Sprite::_notification(int p_what) { s = s / Size2(hframes, vframes); src_rect.size = s; - src_rect.pos.x += float(frame % hframes) * s.x; - src_rect.pos.y += float(frame / hframes) * s.y; + src_rect.position.x += float(frame % hframes) * s.x; + src_rect.position.y += float(frame / hframes) * s.y; } Point2 ofs = offset; diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 080276eb25..eebf0efd1e 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -370,14 +370,14 @@ void TileMap::_update_dirty_quadrants() { s = tex->get_size(); else { s = r.size; - r.pos.x += fp_adjust; - r.pos.y += fp_adjust; + r.position.x += fp_adjust; + r.position.y += fp_adjust; r.size.x -= fp_adjust * 2.0; r.size.y -= fp_adjust * 2.0; } Rect2 rect; - rect.pos = offset.floor(); + rect.position = offset.floor(); rect.size = s; if (rect.size.y > rect.size.x) { @@ -406,39 +406,39 @@ void TileMap::_update_dirty_quadrants() { Vector2 center_ofs; if (tile_origin == TILE_ORIGIN_TOP_LEFT) { - rect.pos += tile_ofs; + rect.position += tile_ofs; } else if (tile_origin == TILE_ORIGIN_BOTTOM_LEFT) { - rect.pos += tile_ofs; + rect.position += tile_ofs; if (c.transpose) { if (c.flip_h) - rect.pos.x -= cell_size.x; + rect.position.x -= cell_size.x; else - rect.pos.x += cell_size.x; + rect.position.x += cell_size.x; } else { if (c.flip_v) - rect.pos.y -= cell_size.y; + rect.position.y -= cell_size.y; else - rect.pos.y += cell_size.y; + rect.position.y += cell_size.y; } } else if (tile_origin == TILE_ORIGIN_CENTER) { - rect.pos += tcenter; + rect.position += tcenter; Vector2 center = (s / 2) - tile_ofs; center_ofs = tcenter - (s / 2); if (c.flip_h) - rect.pos.x -= s.x - center.x; + rect.position.x -= s.x - center.x; else - rect.pos.x -= center.x; + rect.position.x -= center.x; if (c.flip_v) - rect.pos.y -= s.y - center.y; + rect.position.y -= s.y - center.y; else - rect.pos.y -= center.y; + rect.position.y -= center.y; } Color modulate = tile_set->tile_get_modulate(c.id); @@ -549,7 +549,7 @@ void TileMap::_recompute_rect_cache() { for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { Rect2 r; - r.pos = _map_to_world(E->key().x * _get_quadrant_size(), E->key().y * _get_quadrant_size()); + r.position = _map_to_world(E->key().x * _get_quadrant_size(), E->key().y * _get_quadrant_size()); r.expand_to(_map_to_world(E->key().x * _get_quadrant_size() + _get_quadrant_size(), E->key().y * _get_quadrant_size())); r.expand_to(_map_to_world(E->key().x * _get_quadrant_size() + _get_quadrant_size(), E->key().y * _get_quadrant_size() + _get_quadrant_size())); r.expand_to(_map_to_world(E->key().x * _get_quadrant_size(), E->key().y * _get_quadrant_size() + _get_quadrant_size())); diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp index 96311236ef..ec3e059249 100644 --- a/scene/3d/gi_probe.cpp +++ b/scene/3d/gi_probe.cpp @@ -885,7 +885,7 @@ Vector<Color> GIProbe::_get_bake_texture(Ref<Image> p_image, const Color &p_colo Vector<Color> ret; - if (p_image.is_null()) { + if (p_image.is_null() || p_image->empty()) { ret.resize(bake_texture_size * bake_texture_size); for (int i = 0; i < bake_texture_size * bake_texture_size; i++) { @@ -894,9 +894,11 @@ Vector<Color> GIProbe::_get_bake_texture(Ref<Image> p_image, const Color &p_colo return ret; } + p_image = p_image->duplicate(); if (p_image->is_compressed()) { print_line("DECOMPRESSING!!!!"); + p_image->decompress(); } p_image->convert(Image::FORMAT_RGBA8); @@ -907,10 +909,11 @@ Vector<Color> GIProbe::_get_bake_texture(Ref<Image> p_image, const Color &p_colo for (int i = 0; i < bake_texture_size * bake_texture_size; i++) { Color c; - c.r = r[i * 4 + 0] / 255.0; - c.g = r[i * 4 + 1] / 255.0; - c.b = r[i * 4 + 2] / 255.0; + c.r = (r[i * 4 + 0] / 255.0) * p_color.r; + c.g = (r[i * 4 + 1] / 255.0) * p_color.g; + c.b = (r[i * 4 + 2] / 255.0) * p_color.b; c.a = r[i * 4 + 3] / 255.0; + ret[i] = c; } @@ -970,7 +973,7 @@ GIProbe::Baker::MaterialCache GIProbe::_get_material_cache(Ref<Material> p_mater return mc; } -void GIProbe::_plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, Baker *p_baker, const Vector<Ref<Material> > &p_materials, const Ref<Material> &p_override_material) { +void GIProbe::_plot_mesh(const Transform &p_xform, Ref<ArrayMesh> &p_mesh, Baker *p_baker, const Vector<Ref<Material> > &p_materials, const Ref<Material> &p_override_material) { for (int i = 0; i < p_mesh->get_surface_count(); i++) { @@ -1064,7 +1067,7 @@ void GIProbe::_find_meshes(Node *p_at_node, Baker *p_baker) { MeshInstance *mi = p_at_node->cast_to<MeshInstance>(); if (mi && mi->get_flag(GeometryInstance::FLAG_USE_BAKED_LIGHT)) { - Ref<Mesh> mesh = mi->get_mesh(); + Ref<ArrayMesh> mesh = mi->get_mesh(); if (mesh.is_valid()) { Rect3 aabb = mesh->get_aabb(); @@ -1091,7 +1094,7 @@ void GIProbe::_find_meshes(Node *p_at_node, Baker *p_baker) { for (int i = 0; i < meshes.size(); i += 2) { Transform mxf = meshes[i]; - Ref<Mesh> mesh = meshes[i + 1]; + Ref<ArrayMesh> mesh = meshes[i + 1]; if (!mesh.is_valid()) continue; @@ -1277,6 +1280,7 @@ void GIProbe::_debug_mesh(int p_idx, int p_level, const Rect3 &p_aabb, Ref<Multi xform.basis.scale(p_aabb.size * 0.5); p_multimesh->set_instance_transform(idx, xform); Color col = Color(p_baker->bake_cells[p_idx].albedo[0], p_baker->bake_cells[p_idx].albedo[1], p_baker->bake_cells[p_idx].albedo[2]); + //Color col = Color(p_baker->bake_cells[p_idx].emission[0], p_baker->bake_cells[p_idx].emission[1], p_baker->bake_cells[p_idx].emission[2]); p_multimesh->set_instance_color(idx, col); idx++; @@ -1313,7 +1317,7 @@ void GIProbe::_create_debug_mesh(Baker *p_baker) { print_line("leaf voxels: " + itos(p_baker->leaf_voxel_count)); mm->set_instance_count(p_baker->leaf_voxel_count); - Ref<Mesh> mesh; + Ref<ArrayMesh> mesh; mesh.instance(); { @@ -1464,7 +1468,7 @@ GIProbe::GIProbe() { subdiv = SUBDIV_128; dynamic_range = 4; energy = 1.0; - bias = 0.4; + bias = 1.8; propagation = 1.0; extents = Vector3(10, 10, 10); color_scan_cell_width = 4; diff --git a/scene/3d/gi_probe.h b/scene/3d/gi_probe.h index 3b05d9952b..b5ee86455e 100644 --- a/scene/3d/gi_probe.h +++ b/scene/3d/gi_probe.h @@ -145,7 +145,7 @@ private: struct PlotMesh { Ref<Material> override_material; Vector<Ref<Material> > instance_materials; - Ref<Mesh> mesh; + Ref<ArrayMesh> mesh; Transform local_xform; }; @@ -173,7 +173,7 @@ private: Vector<Color> _get_bake_texture(Ref<Image> p_image, const Color &p_color); Baker::MaterialCache _get_material_cache(Ref<Material> p_material, Baker *p_baker); void _plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, const Vector3 *p_vtx, const Vector2 *p_uv, const Baker::MaterialCache &p_material, const Rect3 &p_aabb, Baker *p_baker); - void _plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, Baker *p_baker, const Vector<Ref<Material> > &p_materials, const Ref<Material> &p_override_material); + void _plot_mesh(const Transform &p_xform, Ref<ArrayMesh> &p_mesh, Baker *p_baker, const Vector<Ref<Material> > &p_materials, const Ref<Material> &p_override_material); void _find_meshes(Node *p_at_node, Baker *p_baker); void _fixup_plot(int p_idx, int p_level, int p_x, int p_y, int p_z, Baker *p_baker); diff --git a/scene/3d/listener.cpp b/scene/3d/listener.cpp index 148afbffa2..c7d3bac2f8 100644 --- a/scene/3d/listener.cpp +++ b/scene/3d/listener.cpp @@ -152,7 +152,7 @@ bool Listener::_can_gizmo_scale() const { } RES Listener::_get_gizmo_geometry() const { - Ref<Mesh> mesh = memnew(Mesh); + Ref<ArrayMesh> mesh = memnew(ArrayMesh); return mesh; } diff --git a/scene/3d/navigation_mesh.cpp b/scene/3d/navigation_mesh.cpp index 13fd852fe7..82f6f665db 100644 --- a/scene/3d/navigation_mesh.cpp +++ b/scene/3d/navigation_mesh.cpp @@ -187,7 +187,7 @@ Ref<Mesh> NavigationMesh::get_debug_mesh() { } } - debug_mesh = Ref<Mesh>(memnew(Mesh)); + debug_mesh = Ref<ArrayMesh>(memnew(ArrayMesh)); Array arr; arr.resize(Mesh::ARRAY_MAX); diff --git a/scene/3d/navigation_mesh.h b/scene/3d/navigation_mesh.h index c8f6d936aa..e5a3dc7b43 100644 --- a/scene/3d/navigation_mesh.h +++ b/scene/3d/navigation_mesh.h @@ -44,7 +44,7 @@ class NavigationMesh : public Resource { Vector<int> indices; }; Vector<Polygon> polygons; - Ref<Mesh> debug_mesh; + Ref<ArrayMesh> debug_mesh; struct _EdgeKey { diff --git a/scene/3d/ray_cast.cpp b/scene/3d/ray_cast.cpp index d24aa6ae2a..345afd3edf 100644 --- a/scene/3d/ray_cast.cpp +++ b/scene/3d/ray_cast.cpp @@ -266,7 +266,7 @@ void RayCast::_create_debug_shape() { line_material->set_albedo(Color(1.0, 0.8, 0.6)); } - Ref<Mesh> mesh = memnew(Mesh); + Ref<ArrayMesh> mesh = memnew(ArrayMesh); MeshInstance *mi = memnew(MeshInstance); mi->set_mesh(mesh); @@ -287,7 +287,7 @@ void RayCast::_update_debug_shape() { if (!mi->get_mesh().is_valid()) return; - Ref<Mesh> mesh = mi->get_mesh(); + Ref<ArrayMesh> mesh = mi->get_mesh(); if (mesh->get_surface_count() > 0) mesh->surface_remove(0); diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp index e97b22f9e0..43487505c2 100644 --- a/scene/3d/sprite_3d.cpp +++ b/scene/3d/sprite_3d.cpp @@ -335,8 +335,8 @@ void Sprite3D::_draw() { s = s / Size2i(hframes, vframes); src_rect.size = s; - src_rect.pos.x += (frame % hframes) * s.x; - src_rect.pos.y += (frame / hframes) * s.y; + src_rect.position.x += (frame % hframes) * s.x; + src_rect.position.y += (frame / hframes) * s.y; } Point2i ofs = get_offset(); @@ -360,17 +360,17 @@ void Sprite3D::_draw() { Vector2 vertices[4] = { - (final_rect.pos + Vector2(0, final_rect.size.y)) * pixel_size, - (final_rect.pos + final_rect.size) * pixel_size, - (final_rect.pos + Vector2(final_rect.size.x, 0)) * pixel_size, - final_rect.pos * pixel_size, + (final_rect.position + Vector2(0, final_rect.size.y)) * pixel_size, + (final_rect.position + final_rect.size) * pixel_size, + (final_rect.position + Vector2(final_rect.size.x, 0)) * pixel_size, + final_rect.position * pixel_size, }; Vector2 uvs[4] = { - final_src_rect.pos / tsize, - (final_src_rect.pos + Vector2(final_src_rect.size.x, 0)) / tsize, - (final_src_rect.pos + final_src_rect.size) / tsize, - (final_src_rect.pos + Vector2(0, final_src_rect.size.y)) / tsize, + final_src_rect.position / tsize, + (final_src_rect.position + Vector2(final_src_rect.size.x, 0)) / tsize, + (final_src_rect.position + final_src_rect.size) / tsize, + (final_src_rect.position + Vector2(0, final_src_rect.size.y)) / tsize, }; if (is_flipped_h()) { @@ -861,17 +861,17 @@ void AnimatedSprite3D::_draw() { Vector2 vertices[4] = { - (final_rect.pos + Vector2(0, final_rect.size.y)) * pixel_size, - (final_rect.pos + final_rect.size) * pixel_size, - (final_rect.pos + Vector2(final_rect.size.x, 0)) * pixel_size, - final_rect.pos * pixel_size, + (final_rect.position + Vector2(0, final_rect.size.y)) * pixel_size, + (final_rect.position + final_rect.size) * pixel_size, + (final_rect.position + Vector2(final_rect.size.x, 0)) * pixel_size, + final_rect.position * pixel_size, }; Vector2 uvs[4] = { - final_src_rect.pos / tsize, - (final_src_rect.pos + Vector2(final_src_rect.size.x, 0)) / tsize, - (final_src_rect.pos + final_src_rect.size) / tsize, - (final_src_rect.pos + Vector2(0, final_src_rect.size.y)) / tsize, + final_src_rect.position / tsize, + (final_src_rect.position + Vector2(final_src_rect.size.x, 0)) / tsize, + (final_src_rect.position + final_src_rect.size) / tsize, + (final_src_rect.position + Vector2(0, final_src_rect.size.y)) / tsize, }; if (is_flipped_h()) { diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index c4ea42d461..543b64bd15 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -202,6 +202,7 @@ void AnimationPlayer::_notification(int p_what) { if (!get_tree()->is_editor_hint() && animation_set.has(autoplay)) { play(autoplay); set_autoplay(""); //this line is the fix for autoplay issues with animatio + _animation_process(0); } } break; case NOTIFICATION_INTERNAL_PROCESS: { diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 318db8458b..c1dbc82f3c 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -162,7 +162,7 @@ void BaseButton::_gui_input(Ref<InputEvent> p_event) { if (mm.is_valid()) { if (status.press_attempt && status.pressing_button == 0) { bool last_press_inside = status.pressing_inside; - status.pressing_inside = has_point(mm->get_pos()); + status.pressing_inside = has_point(mm->get_position()); if (last_press_inside != status.pressing_inside) update(); } diff --git a/scene/gui/button_array.cpp b/scene/gui/button_array.cpp index 0d518059c8..1616272e66 100644 --- a/scene/gui/button_array.cpp +++ b/scene/gui/button_array.cpp @@ -236,8 +236,8 @@ void ButtonArray::_notification(int p_what) { } Rect2 r; - r.pos[orientation] = ofs; - r.pos[!orientation] = 0; + r.position[orientation] = ofs; + r.position[!orientation] = 0; r.size[orientation] = s; r.size[!orientation] = op_size; @@ -272,10 +272,10 @@ void ButtonArray::_notification(int p_what) { Point2 text_ofs = ((r.size - ssize - sbsize) / 2.0 + Point2(0, f->get_ascent())).floor() + sbofs; if (buttons[i].icon.is_valid()) { - draw_texture(buttons[i].icon, r.pos + Point2(text_ofs.x, Math::floor((r.size.height - buttons[i].icon->get_height()) / 2.0))); + draw_texture(buttons[i].icon, r.position + Point2(text_ofs.x, Math::floor((r.size.height - buttons[i].icon->get_height()) / 2.0))); text_ofs.x += buttons[i].icon->get_width() + icon_sep; } - draw_string(f, text_ofs + r.pos, buttons[i].xl_text, c); + draw_string(f, text_ofs + r.position, buttons[i].xl_text, c); buttons[i]._pos_cache = ofs; buttons[i]._size_cache = s; @@ -313,7 +313,7 @@ void ButtonArray::_gui_input(const Ref<InputEvent> &p_event) { if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { - int ofs = orientation == HORIZONTAL ? mb->get_pos().x : mb->get_pos().y; + int ofs = orientation == HORIZONTAL ? mb->get_position().x : mb->get_position().y; for (int i = 0; i < buttons.size(); i++) { @@ -330,7 +330,7 @@ void ButtonArray::_gui_input(const Ref<InputEvent> &p_event) { if (mm.is_valid()) { - int ofs = orientation == HORIZONTAL ? mm->get_pos().x : mm->get_pos().y; + int ofs = orientation == HORIZONTAL ? mm->get_position().x : mm->get_position().y; int new_hover = -1; for (int i = 0; i < buttons.size(); i++) { diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 662ce63946..f0e486aa50 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -304,8 +304,8 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &ev) { if (bev.is_valid()) { if (bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT) { changing_color = true; - float x = CLAMP((float)bev->get_pos().x, 0, 256); - float y = CLAMP((float)bev->get_pos().y, 0, 256); + float x = CLAMP((float)bev->get_position().x, 0, 256); + float y = CLAMP((float)bev->get_position().y, 0, 256); s = x / 256; v = 1.0 - y / 256.0; color.set_hsv(h, s, v, color.a); @@ -323,8 +323,8 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &ev) { if (mev.is_valid()) { if (!changing_color) return; - float x = CLAMP((float)mev->get_pos().x, 0, 256); - float y = CLAMP((float)mev->get_pos().y, 0, 256); + float x = CLAMP((float)mev->get_position().x, 0, 256); + float y = CLAMP((float)mev->get_position().y, 0, 256); s = x / 256; v = 1.0 - y / 256.0; color.set_hsv(h, s, v, color.a); @@ -343,7 +343,7 @@ void ColorPicker::_w_input(const Ref<InputEvent> &ev) { if (bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT) { changing_color = true; - h = 1 - ((float)bev->get_pos().y) / 256.0; + h = 1 - ((float)bev->get_position().y) / 256.0; } else { changing_color = false; @@ -361,7 +361,7 @@ void ColorPicker::_w_input(const Ref<InputEvent> &ev) { if (!changing_color) return; - float y = CLAMP((float)mev->get_pos().y, 0, 256); + float y = CLAMP((float)mev->get_position().y, 0, 256); h = 1.0 - y / 256.0; color.set_hsv(h, s, v, color.a); last_hsv = color; @@ -378,10 +378,10 @@ void ColorPicker::_preset_input(const Ref<InputEvent> &ev) { if (bev.is_valid()) { if (bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT) { - int index = bev->get_pos().x / (preset->get_size().x / presets.size()); + int index = bev->get_position().x / (preset->get_size().x / presets.size()); set_pick_color(presets[index]); } else if (bev->is_pressed() && bev->get_button_index() == BUTTON_RIGHT) { - int index = bev->get_pos().x / (preset->get_size().x / presets.size()); + int index = bev->get_position().x / (preset->get_size().x / presets.size()); presets.erase(presets[index]); _update_presets(); bt_add_preset->show(); @@ -394,7 +394,7 @@ void ColorPicker::_preset_input(const Ref<InputEvent> &ev) { if (mev.is_valid()) { - int index = mev->get_pos().x * presets.size(); + int index = mev->get_position().x * presets.size(); if (preset->get_size().x != 0) { index /= preset->get_size().x; } @@ -422,7 +422,7 @@ void ColorPicker::_screen_input(const Ref<InputEvent> &ev) { if (mev.is_valid()) { Viewport *r = get_tree()->get_root(); - if (!r->get_visible_rect().has_point(Point2(mev->get_global_pos().x, mev->get_global_pos().y))) + if (!r->get_visible_rect().has_point(Point2(mev->get_global_position().x, mev->get_global_position().y))) return; Ref<Image> img = r->get_screen_capture(); if (!img.is_null()) { @@ -431,7 +431,7 @@ void ColorPicker::_screen_input(const Ref<InputEvent> &ev) { } if (last_capture.is_valid() && !last_capture->empty()) { int pw = last_capture->get_format() == Image::FORMAT_RGBA8 ? 4 : 3; - int ofs = (mev->get_global_pos().y * last_capture->get_width() + mev->get_global_pos().x) * pw; + int ofs = (mev->get_global_position().y * last_capture->get_width() + mev->get_global_position().x) * pw; PoolVector<uint8_t>::Read r = last_capture->get_data().read(); diff --git a/scene/gui/color_ramp_edit.cpp b/scene/gui/color_ramp_edit.cpp index 8c47f8559a..33e4ce0403 100644 --- a/scene/gui/color_ramp_edit.cpp +++ b/scene/gui/color_ramp_edit.cpp @@ -88,14 +88,14 @@ void ColorRampEdit::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> mb = p_event; //Show color picker on double click. if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_doubleclick() && mb->is_pressed()) { - grabbed = _get_point_from_pos(mb->get_pos().x); + grabbed = _get_point_from_pos(mb->get_position().x); _show_color_picker(); accept_event(); } //Delete point on right click if (mb.is_valid() && mb->get_button_index() == 2 && mb->is_pressed()) { - grabbed = _get_point_from_pos(mb->get_pos().x); + grabbed = _get_point_from_pos(mb->get_position().x); if (grabbed != -1) { points.remove(grabbed); grabbed = -1; @@ -109,7 +109,7 @@ void ColorRampEdit::_gui_input(const Ref<InputEvent> &p_event) { //Hold alt key to duplicate selected color if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed() && mb->get_alt()) { - int x = mb->get_pos().x; + int x = mb->get_position().x; grabbed = _get_point_from_pos(x); if (grabbed != -1) { @@ -134,7 +134,7 @@ void ColorRampEdit::_gui_input(const Ref<InputEvent> &p_event) { if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) { update(); - int x = mb->get_pos().x; + int x = mb->get_position().x; int total_w = get_size().width - get_size().height - 3; //Check if color selector was clicked. @@ -214,7 +214,7 @@ void ColorRampEdit::_gui_input(const Ref<InputEvent> &p_event) { int total_w = get_size().width - get_size().height - 3; - int x = mm->get_pos().x; + int x = mm->get_position().x; float newofs = CLAMP(x / float(total_w), 0, 1); diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp index c428d524a4..92bb5d43a7 100644 --- a/scene/gui/container.cpp +++ b/scene/gui/container.cpp @@ -96,18 +96,18 @@ void Container::fit_child_in_rect(Control *p_child, const Rect2 &p_rect) { if (!(p_child->get_h_size_flags() & SIZE_FILL)) { r.size.x = minsize.x; - r.pos.x += Math::floor((p_rect.size.x - minsize.x) / 2); + r.position.x += Math::floor((p_rect.size.x - minsize.x) / 2); } if (!(p_child->get_v_size_flags() & SIZE_FILL)) { r.size.y = minsize.y; - r.pos.y += Math::floor((p_rect.size.y - minsize.y) / 2); + r.position.y += Math::floor((p_rect.size.y - minsize.y) / 2); } for (int i = 0; i < 4; i++) p_child->set_anchor(Margin(i), ANCHOR_BEGIN); - p_child->set_position(r.pos); + p_child->set_position(r.position); p_child->set_size(r.size); p_child->set_rotation(0); p_child->set_scale(Vector2(1, 1)); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 83fa20bee5..ae30acf52e 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -58,7 +58,7 @@ void Control::edit_set_state(const Variant &p_state) { Dictionary s = p_state; Rect2 state = s["rect"]; - set_position(state.pos); + set_position(state.position); set_size(state.size); set_rotation(s["rot"]); set_scale(s["scale"]); @@ -94,15 +94,15 @@ void Control::edit_set_rect(const Rect2 &p_edit_rect) { Transform2D postxf; postxf.set_rotation_and_scale(data.rotation, data.scale); - Vector2 new_pos = postxf.xform(p_edit_rect.pos); + Vector2 new_pos = postxf.xform(p_edit_rect.position); Vector2 pos = get_position() + new_pos; Rect2 new_rect = get_rect(); - new_rect.pos = pos.snapped(Vector2(1, 1)); + new_rect.position = pos.snapped(Vector2(1, 1)); new_rect.size = p_edit_rect.size.snapped(Vector2(1, 1)); - set_position(new_rect.pos); + set_position(new_rect.position); set_size(new_rect.size); } @@ -1477,7 +1477,7 @@ Rect2 Control::get_global_rect() const { Rect2 Control::get_window_rect() const { ERR_FAIL_COND_V(!is_inside_tree(), Rect2()); Rect2 gr = get_global_rect(); - gr.pos += get_viewport()->get_visible_rect().pos; + gr.position += get_viewport()->get_visible_rect().position; return gr; } @@ -1949,10 +1949,10 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) { Transform2D xform = get_global_transform(); Rect2 rect = get_item_rect(); - points[0] = xform.xform(rect.pos); - points[1] = xform.xform(rect.pos + Point2(rect.size.x, 0)); - points[2] = xform.xform(rect.pos + rect.size); - points[3] = xform.xform(rect.pos + Point2(0, rect.size.y)); + points[0] = xform.xform(rect.position); + points[1] = xform.xform(rect.position + Point2(rect.size.x, 0)); + points[2] = xform.xform(rect.position + rect.size); + points[3] = xform.xform(rect.position + Point2(0, rect.size.y)); const Vector2 dir[4] = { Vector2(-1, 0), @@ -2008,10 +2008,10 @@ void Control::_window_find_focus_neighbour(const Vector2 &p_dir, Node *p_at, con Transform2D xform = c->get_global_transform(); Rect2 rect = c->get_item_rect(); - points[0] = xform.xform(rect.pos); - points[1] = xform.xform(rect.pos + Point2(rect.size.x, 0)); - points[2] = xform.xform(rect.pos + rect.size); - points[3] = xform.xform(rect.pos + Point2(0, rect.size.y)); + points[0] = xform.xform(rect.position); + points[1] = xform.xform(rect.position + Point2(rect.size.x, 0)); + points[2] = xform.xform(rect.position + rect.size); + points[3] = xform.xform(rect.position + Point2(0, rect.size.y)); float min = 1e7; diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 627bc96fb1..60d1350405 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -90,15 +90,15 @@ bool WindowDialog::has_point(const Point2 &p_point) const { // Enlarge upwards for title bar. int title_height = get_constant("title_height", "WindowDialog"); - r.pos.y -= title_height; + r.position.y -= title_height; r.size.y += title_height; // Inflate by the resizable border thickness. if (resizable) { int scaleborder_size = get_constant("scaleborder_size", "WindowDialog"); - r.pos.x -= scaleborder_size; + r.position.x -= scaleborder_size; r.size.width += scaleborder_size * 2; - r.pos.y -= scaleborder_size; + r.position.y -= scaleborder_size; r.size.height += scaleborder_size * 2; } @@ -113,7 +113,7 @@ void WindowDialog::_gui_input(const Ref<InputEvent> &p_event) { if (mb->is_pressed()) { // Begin a possible dragging operation. - drag_type = _drag_hit_test(Point2(mb->get_pos().x, mb->get_pos().y)); + drag_type = _drag_hit_test(Point2(mb->get_position().x, mb->get_position().y)); if (drag_type != DRAG_NONE) drag_offset = get_global_mouse_position() - get_position(); drag_offset_far = get_position() + get_size() - get_global_mouse_position(); @@ -131,7 +131,7 @@ void WindowDialog::_gui_input(const Ref<InputEvent> &p_event) { // Update the cursor while moving along the borders. CursorShape cursor = CURSOR_ARROW; if (resizable) { - int preview_drag_type = _drag_hit_test(Point2(mm->get_pos().x, mm->get_pos().y)); + int preview_drag_type = _drag_hit_test(Point2(mm->get_position().x, mm->get_position().y)); switch (preview_drag_type) { case DRAG_RESIZE_TOP: case DRAG_RESIZE_BOTTOM: @@ -162,28 +162,28 @@ void WindowDialog::_gui_input(const Ref<InputEvent> &p_event) { Size2 min_size = get_minimum_size(); if (drag_type == DRAG_MOVE) { - rect.pos = global_pos - drag_offset; + rect.position = global_pos - drag_offset; } else { if (drag_type & DRAG_RESIZE_TOP) { - int bottom = rect.pos.y + rect.size.height; + int bottom = rect.position.y + rect.size.height; int max_y = bottom - min_size.height; - rect.pos.y = MIN(global_pos.y - drag_offset.y, max_y); - rect.size.height = bottom - rect.pos.y; + rect.position.y = MIN(global_pos.y - drag_offset.y, max_y); + rect.size.height = bottom - rect.position.y; } else if (drag_type & DRAG_RESIZE_BOTTOM) { - rect.size.height = global_pos.y - rect.pos.y + drag_offset_far.y; + rect.size.height = global_pos.y - rect.position.y + drag_offset_far.y; } if (drag_type & DRAG_RESIZE_LEFT) { - int right = rect.pos.x + rect.size.width; + int right = rect.position.x + rect.size.width; int max_x = right - min_size.width; - rect.pos.x = MIN(global_pos.x - drag_offset.x, max_x); - rect.size.width = right - rect.pos.x; + rect.position.x = MIN(global_pos.x - drag_offset.x, max_x); + rect.size.width = right - rect.position.x; } else if (drag_type & DRAG_RESIZE_RIGHT) { - rect.size.width = global_pos.x - rect.pos.x + drag_offset_far.x; + rect.size.width = global_pos.x - rect.position.x + drag_offset_far.x; } } set_size(rect.size); - set_position(rect.pos); + set_position(rect.position); } } } diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index c52cdd9325..8d085d5399 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -168,24 +168,24 @@ void GraphEdit::_update_scroll() { continue; Rect2 r; - r.pos = gn->get_offset() * zoom; + r.position = gn->get_offset() * zoom; r.size = gn->get_size() * zoom; screen = screen.merge(r); } - screen.pos -= get_size(); + screen.position -= get_size(); screen.size += get_size() * 2.0; - h_scroll->set_min(screen.pos.x); - h_scroll->set_max(screen.pos.x + screen.size.x); + h_scroll->set_min(screen.position.x); + h_scroll->set_max(screen.position.x + screen.size.x); h_scroll->set_page(get_size().x); if (h_scroll->get_max() - h_scroll->get_min() <= h_scroll->get_page()) h_scroll->hide(); else h_scroll->show(); - v_scroll->set_min(screen.pos.y); - v_scroll->set_max(screen.pos.y + screen.size.y); + v_scroll->set_min(screen.position.y); + v_scroll->set_max(screen.position.y + screen.size.y); v_scroll->set_page(get_size().y); if (v_scroll->get_max() - v_scroll->get_min() <= v_scroll->get_page()) @@ -374,7 +374,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) { Ref<Texture> port = get_icon("port", "GraphNode"); - Vector2 mpos(mb->get_pos().x, mb->get_pos().y); + Vector2 mpos(mb->get_position().x, mb->get_position().y); float grab_r = port->get_width() * 0.5 * grab_r_extend; for (int i = get_child_count() - 1; i >= 0; i--) { @@ -483,12 +483,12 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { Ref<InputEventMouseMotion> mm = p_ev; if (mm.is_valid() && connecting) { - connecting_to = mm->get_pos(); + connecting_to = mm->get_position(); connecting_target = false; top_layer->update(); Ref<Texture> port = get_icon("port", "GraphNode"); - Vector2 mpos = mm->get_pos(); + Vector2 mpos = mm->get_position(); float grab_r = port->get_width() * 0.5 * grab_r_extend; for (int i = get_child_count() - 1; i >= 0; i--) { @@ -546,7 +546,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { } else if (!just_disconected) { String from = connecting_from; int from_slot = connecting_index; - Vector2 ofs = Vector2(mb->get_pos().x, mb->get_pos().y); + Vector2 ofs = Vector2(mb->get_position().x, mb->get_position().y); emit_signal("connection_to_empty", from, from_slot, ofs); } connecting = false; @@ -817,7 +817,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { connecting = false; top_layer->update(); } else { - emit_signal("popup_request", b->get_global_pos()); + emit_signal("popup_request", b->get_global_position()); } } } @@ -880,7 +880,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { if (gn) { - if (_filter_input(b->get_pos())) + if (_filter_input(b->get_position())) return; dragging = true; @@ -905,7 +905,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { } } else { - if (_filter_input(b->get_pos())) + if (_filter_input(b->get_position())) return; if (Input::get_singleton()->is_key_pressed(KEY_SPACE)) return; diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index fb0ff4f320..95f65f31d6 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -239,7 +239,7 @@ void GraphNode::_notification(int p_what) { if (show_close) { Vector2 cpos = Point2(w + sb->get_margin(MARGIN_LEFT), -close->get_height() + close_offset); draw_texture(close, cpos); - close_rect.pos = cpos; + close_rect.position = cpos; close_rect.size = close->get_size(); } else { close_rect = Rect2(); @@ -582,11 +582,9 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) { ERR_EXPLAIN("GraphNode must be the child of a GraphEdit node."); ERR_FAIL_COND(get_parent_control() == NULL); - print_line("INPUT EVENT BUTTON"); - if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { - Vector2 mpos = Vector2(mb->get_pos().x, mb->get_pos().y); + Vector2 mpos = Vector2(mb->get_position().x, mb->get_position().y); if (close_rect.size != Size2() && close_rect.has_point(mpos)) { emit_signal("close_request"); accept_event(); @@ -616,7 +614,7 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) { Ref<InputEventMouseMotion> mm = p_ev; if (resizing && mm.is_valid()) { - Vector2 mpos = mm->get_pos(); + Vector2 mpos = mm->get_position(); Vector2 diff = mpos - resizing_from; diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index a9f063280b..2f0c7b9aaf 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -431,7 +431,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { if (mb.is_valid() && (mb->get_button_index() == BUTTON_LEFT || (allow_rmb_select && mb->get_button_index() == BUTTON_RIGHT)) && mb->is_pressed()) { search_string = ""; //any mousepress cancels - Vector2 pos(mb->get_pos().x, mb->get_pos().y); + Vector2 pos(mb->get_position().x, mb->get_position().y); Ref<StyleBox> bg = get_stylebox("bg"); pos -= bg->get_offset(); pos.y += scroll_bar->get_value(); @@ -475,7 +475,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { if (mb->get_button_index() == BUTTON_RIGHT) { - emit_signal("item_rmb_selected", i, Vector2(mb->get_pos().x, mb->get_pos().y)); + emit_signal("item_rmb_selected", i, Vector2(mb->get_position().x, mb->get_position().y)); } } else { @@ -486,7 +486,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { if (items[i].selected && mb->get_button_index() == BUTTON_RIGHT) { - emit_signal("item_rmb_selected", i, Vector2(mb->get_pos().x, mb->get_pos().y)); + emit_signal("item_rmb_selected", i, Vector2(mb->get_position().x, mb->get_position().y)); } else { bool selected = !items[i].selected; @@ -501,7 +501,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { if (mb->get_button_index() == BUTTON_RIGHT) { - emit_signal("item_rmb_selected", i, Vector2(mb->get_pos().x, mb->get_pos().y)); + emit_signal("item_rmb_selected", i, Vector2(mb->get_position().x, mb->get_position().y)); } else if (/*select_mode==SELECT_SINGLE &&*/ mb->is_doubleclick()) { emit_signal("item_activated", i); @@ -857,7 +857,7 @@ void ItemList::_notification(int p_what) { items[i].rect_cache = items[i].min_rect_cache; if (same_column_width) items[i].rect_cache.size.x = max_column_width; - items[i].rect_cache.pos = ofs; + items[i].rect_cache.position = ofs; max_h = MAX(max_h, items[i].rect_cache.size.y); ofs.x += items[i].rect_cache.size.x + hseparation; //print_line("item "+itos(i)+" ofs "+rtos(items[i].rect_cache.size.x)); @@ -906,10 +906,10 @@ void ItemList::_notification(int p_what) { int from = scroll_bar->get_value(); int to = from + scroll_bar->get_page(); - if (r.pos.y < from) { - scroll_bar->set_value(r.pos.y); - } else if (r.pos.y + r.size.y > to) { - scroll_bar->set_value(r.pos.y + r.size.y - (to - from)); + if (r.position.y < from) { + scroll_bar->set_value(r.position.y); + } else if (r.position.y + r.size.y > to) { + scroll_bar->set_value(r.position.y + r.size.y - (to - from)); } } @@ -928,26 +928,29 @@ void ItemList::_notification(int p_what) { continue; if (current_columns == 1) { - rcache.size.width = width - rcache.pos.x; + rcache.size.width = width - rcache.position.x; } - Rect2 r = rcache; - r.pos += base_ofs; - - // Use stylebox to dimension potential bg color, even if not selected - r.pos.x -= sbsel->get_margin(MARGIN_LEFT); - r.size.x += sbsel->get_margin(MARGIN_LEFT) + sbsel->get_margin(MARGIN_RIGHT); - r.pos.y -= sbsel->get_margin(MARGIN_TOP); - r.size.y += sbsel->get_margin(MARGIN_TOP) + sbsel->get_margin(MARGIN_BOTTOM); - if (items[i].selected) { + Rect2 r = rcache; + r.position += base_ofs; + + // Use stylebox to dimension potential bg color + r.position.x -= sbsel->get_margin(MARGIN_LEFT); + r.size.x += sbsel->get_margin(MARGIN_LEFT) + sbsel->get_margin(MARGIN_RIGHT); + r.position.y -= sbsel->get_margin(MARGIN_TOP); + r.size.y += sbsel->get_margin(MARGIN_TOP) + sbsel->get_margin(MARGIN_BOTTOM); draw_style_box(sbsel, r); } + if (items[i].custom_bg.a > 0.001) { - r.pos.x += 2; - r.size.x -= 4; - r.pos.y += 2; - r.size.y -= 4; + + Rect2 r = rcache; + r.position += base_ofs; + + // Size rect to make the align the temperature colors + r.position.y -= vseparation / 2; + r.size.y += vseparation; draw_rect(r, items[i].custom_bg); } @@ -965,7 +968,7 @@ void ItemList::_notification(int p_what) { Vector2 icon_ofs; - Point2 pos = items[i].rect_cache.pos + icon_ofs + base_ofs; + Point2 pos = items[i].rect_cache.position + icon_ofs + base_ofs; if (icon_mode == ICON_MODE_TOP) { @@ -985,7 +988,7 @@ void ItemList::_notification(int p_what) { if (fixed_icon_size.x > 0 && fixed_icon_size.y > 0) { Rect2 adj = _adjust_to_max_size(items[i].get_icon_size() * icon_scale, icon_size); - draw_rect.pos += adj.pos; + draw_rect.position += adj.position; draw_rect.size = adj.size; } @@ -1001,7 +1004,7 @@ void ItemList::_notification(int p_what) { if (items[i].tag_icon.is_valid()) { - draw_texture(items[i].tag_icon, items[i].rect_cache.pos + base_ofs); + draw_texture(items[i].tag_icon, items[i].rect_cache.position + base_ofs); } if (items[i].text != "") { @@ -1046,7 +1049,7 @@ void ItemList::_notification(int p_what) { text_ofs.y += font->get_ascent(); text_ofs = text_ofs.floor(); text_ofs += base_ofs; - text_ofs += items[i].rect_cache.pos; + text_ofs += items[i].rect_cache.position; for (int j = 0; j < ss; j++) { @@ -1074,7 +1077,7 @@ void ItemList::_notification(int p_what) { text_ofs.y += font->get_ascent(); text_ofs = text_ofs.floor(); text_ofs += base_ofs; - text_ofs += items[i].rect_cache.pos; + text_ofs += items[i].rect_cache.position; draw_string(font, text_ofs, items[i].text, modulate, max_len + 1); } @@ -1083,7 +1086,7 @@ void ItemList::_notification(int p_what) { if (select_mode == SELECT_MULTI && i == current) { Rect2 r = rcache; - r.pos += base_ofs; + r.position += base_ofs; draw_style_box(cursor, r); } } @@ -1141,7 +1144,7 @@ bool ItemList::is_pos_at_end_of_items(const Point2 &p_pos) const { pos.y += scroll_bar->get_value(); Rect2 endrect = items[items.size() - 1].rect_cache; - return (pos.y > endrect.pos.y + endrect.size.y); + return (pos.y > endrect.position.y + endrect.size.y); } String ItemList::get_tooltip(const Point2 &p_pos) const { diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 38debe8a77..bc579020bd 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -64,7 +64,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { shift_selection_check_pre(b->get_shift()); - set_cursor_at_pixel_pos(b->get_pos().x); + set_cursor_at_pixel_pos(b->get_position().x); if (b->get_shift()) { @@ -118,7 +118,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { if (m->get_button_mask() & BUTTON_LEFT) { if (selection.creating) { - set_cursor_at_pixel_pos(m->get_pos().x); + set_cursor_at_pixel_pos(m->get_position().x); selection_fill_at_cursor(); } } diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index 655d8ed6f6..8979e0f111 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -170,8 +170,8 @@ void Popup::popup_centered(const Size2 &p_size) { Rect2 rect; rect.size = p_size == Size2() ? get_size() : p_size; - rect.pos = ((window_size - rect.size) / 2.0).floor(); - set_position(rect.pos); + rect.position = ((window_size - rect.size) / 2.0).floor(); + set_position(rect.position); set_size(rect.size); show_modal(exclusive); @@ -193,8 +193,8 @@ void Popup::popup_centered_ratio(float p_screen_ratio) { Rect2 rect; Point2 window_size = get_viewport_rect().size; rect.size = (window_size * p_screen_ratio).floor(); - rect.pos = ((window_size - rect.size) / 2.0).floor(); - set_position(rect.pos); + rect.position = ((window_size - rect.size) / 2.0).floor(); + set_position(rect.position); set_size(rect.size); show_modal(exclusive); @@ -216,7 +216,7 @@ void Popup::popup(const Rect2 &bounds) { // Fit the popup into the optionally provided bounds. if (!bounds.has_no_area()) { - set_position(bounds.pos); + set_position(bounds.position); set_size(bounds.size); } _fix_size(); diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 985d9addc9..c4991700aa 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -190,12 +190,12 @@ void PopupMenu::_activate_submenu(int over) { PopupMenu *pum = pm->cast_to<PopupMenu>(); if (pum) { - pr.pos -= pum->get_global_position(); + pr.position -= pum->get_global_position(); pum->clear_autohide_areas(); - pum->add_autohide_area(Rect2(pr.pos.x, pr.pos.y, pr.size.x, items[over]._ofs_cache)); + pum->add_autohide_area(Rect2(pr.position.x, pr.position.y, pr.size.x, items[over]._ofs_cache)); if (over < items.size() - 1) { int from = items[over + 1]._ofs_cache; - pum->add_autohide_area(Rect2(pr.pos.x, pr.pos.y + from, pr.size.x, pr.size.y - from)); + pum->add_autohide_area(Rect2(pr.position.x, pr.position.y + from, pr.size.x, pr.size.y - from)); } } } @@ -284,7 +284,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { //update hover Ref<InputEventMouseMotion> ie; ie.instance(); - ie->set_pos(b->get_pos() + Vector2(0, s)); + ie->set_position(b->get_position() + Vector2(0, s)); _gui_input(ie); } } break; @@ -303,13 +303,13 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { //update hover Ref<InputEventMouseMotion> ie; ie.instance(); - ie->set_pos(b->get_pos() - Vector2(0, s)); + ie->set_position(b->get_position() - Vector2(0, s)); _gui_input(ie); } } break; case BUTTON_LEFT: { - int over = _get_mouse_over(b->get_pos()); + int over = _get_mouse_over(b->get_position()); if (invalidated_click) { invalidated_click = false; @@ -348,13 +348,13 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { for (List<Rect2>::Element *E = autohide_areas.front(); E; E = E->next()) { - if (!Rect2(Point2(), get_size()).has_point(m->get_pos()) && E->get().has_point(m->get_pos())) { + if (!Rect2(Point2(), get_size()).has_point(m->get_position()) && E->get().has_point(m->get_position())) { call_deferred("hide"); return; } } - int over = _get_mouse_over(m->get_pos()); + int over = _get_mouse_over(m->get_position()); int id = (over < 0 || items[over].separator || items[over].disabled) ? -1 : (items[over].ID >= 0 ? items[over].ID : over); if (id < 0) { diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index a618810c11..0b8595de42 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -264,7 +264,7 @@ void RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int cw = tab_size * font->get_char_size(' ').width; } - if (end > 0 && w + cw + wofs > p_width) { + if (end > 0 && w + cw + begin > p_width) { break; //don't allow lines longer than assigned width } @@ -751,7 +751,7 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { Item *item = NULL; bool outside; - _find_click(main, b->get_pos(), &item, &line, &outside); + _find_click(main, b->get_position(), &item, &line, &outside); if (item) { @@ -852,7 +852,7 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { int line = 0; Item *item = NULL; - _find_click(main, m->get_pos(), &item, &line); + _find_click(main, m->get_position(), &item, &line); if (!item) return; // do not update diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index 27a16ccc33..bd66cd2745 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -72,7 +72,7 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { if (b->is_pressed()) { - double ofs = orientation == VERTICAL ? b->get_pos().y : b->get_pos().x; + double ofs = orientation == VERTICAL ? b->get_position().y : b->get_position().x; Ref<Texture> decr = get_icon("decrement"); Ref<Texture> incr = get_icon("increment"); @@ -130,7 +130,7 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { if (drag.active) { - double ofs = orientation == VERTICAL ? m->get_pos().y : m->get_pos().x; + double ofs = orientation == VERTICAL ? m->get_position().y : m->get_position().x; Ref<Texture> decr = get_icon("decrement"); double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width(); @@ -141,7 +141,7 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { set_as_ratio(drag.value_at_click + diff); } else { - double ofs = orientation == VERTICAL ? m->get_pos().y : m->get_pos().x; + double ofs = orientation == VERTICAL ? m->get_position().y : m->get_position().x; Ref<Texture> decr = get_icon("decrement"); Ref<Texture> incr = get_icon("increment"); @@ -267,14 +267,14 @@ void ScrollBar::_notification(int p_what) { grabber_rect.size.width = get_grabber_size(); grabber_rect.size.height = get_size().height; - grabber_rect.pos.y = 0; - grabber_rect.pos.x = get_grabber_offset() + decr->get_width() + bg->get_margin(MARGIN_LEFT); + grabber_rect.position.y = 0; + grabber_rect.position.x = get_grabber_offset() + decr->get_width() + bg->get_margin(MARGIN_LEFT); } else { grabber_rect.size.width = get_size().width; grabber_rect.size.height = get_grabber_size(); - grabber_rect.pos.y = get_grabber_offset() + decr->get_height() + bg->get_margin(MARGIN_TOP); - grabber_rect.pos.x = 0; + grabber_rect.position.y = get_grabber_offset() + decr->get_height() + bg->get_margin(MARGIN_TOP); + grabber_rect.position.x = 0; } grabber->draw(ci, grabber_rect); diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp index 70b4ac47f8..cc1a637d2b 100644 --- a/scene/gui/scroll_container.cpp +++ b/scene/gui/scroll_container.cpp @@ -233,14 +233,14 @@ void ScrollContainer::_notification(int p_what) { Rect2 r = Rect2(-scroll, minsize); if (!scroll_h || (!h_scroll->is_visible_in_tree() && c->get_h_size_flags() & SIZE_EXPAND)) { - r.pos.x = 0; + r.position.x = 0; if (c->get_h_size_flags() & SIZE_EXPAND) r.size.width = MAX(size.width, minsize.width); else r.size.width = minsize.width; } if (!scroll_v || (!v_scroll->is_visible_in_tree() && c->get_v_size_flags() & SIZE_EXPAND)) { - r.pos.y = 0; + r.position.y = 0; r.size.height = size.height; if (c->get_v_size_flags() & SIZE_EXPAND) r.size.height = MAX(size.height, minsize.height); diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp index ae2bf0999e..d0e708bf73 100644 --- a/scene/gui/slider.cpp +++ b/scene/gui/slider.cpp @@ -46,7 +46,7 @@ void Slider::_gui_input(Ref<InputEvent> p_event) { if (mb->is_pressed()) { Ref<Texture> grabber = get_icon(mouse_inside || has_focus() ? "grabber_highlight" : "grabber"); - grab.pos = orientation == VERTICAL ? mb->get_pos().y : mb->get_pos().x; + grab.pos = orientation == VERTICAL ? mb->get_position().y : mb->get_position().x; double grab_width = (double)grabber->get_size().width; double grab_height = (double)grabber->get_size().height; @@ -75,7 +75,7 @@ void Slider::_gui_input(Ref<InputEvent> p_event) { Size2i size = get_size(); Ref<Texture> grabber = get_icon("grabber"); - float motion = (orientation == VERTICAL ? mm->get_pos().y : mm->get_pos().x) - grab.pos; + float motion = (orientation == VERTICAL ? mm->get_position().y : mm->get_position().x) - grab.pos; if (orientation == VERTICAL) motion = -motion; float areasize = orientation == VERTICAL ? size.height - grabber->get_size().height : size.width - grabber->get_size().width; diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 2eb2028391..c5b9df15b9 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -96,7 +96,7 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) { if (mb.is_valid() && mb->is_pressed()) { - bool up = mb->get_pos().y < (get_size().height / 2); + bool up = mb->get_position().y < (get_size().height / 2); switch (mb->get_button_index()) { @@ -135,7 +135,7 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) { if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == 1) { //set_default_cursor_shape(CURSOR_VSIZE); - Vector2 cpos = Vector2(mb->get_pos().x, mb->get_pos().y); + Vector2 cpos = Vector2(mb->get_position().x, mb->get_position().y); drag.mouse_pos = cpos; } @@ -155,7 +155,7 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) { if (mm.is_valid() && mm->get_button_mask() & 1) { - Vector2 cpos = mm->get_pos(); + Vector2 cpos = mm->get_position(); if (drag.enabled) { diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp index 91fd18e2ed..31236fa277 100644 --- a/scene/gui/split_container.cpp +++ b/scene/gui/split_container.cpp @@ -286,16 +286,16 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) { if (vertical) { - if (mb->get_pos().y > middle_sep && mb->get_pos().y < middle_sep + sep) { + if (mb->get_position().y > middle_sep && mb->get_position().y < middle_sep + sep) { dragging = true; - drag_from = mb->get_pos().y; + drag_from = mb->get_position().y; drag_ofs = expand_ofs; } } else { - if (mb->get_pos().x > middle_sep && mb->get_pos().x < middle_sep + sep) { + if (mb->get_position().x > middle_sep && mb->get_position().x < middle_sep + sep) { dragging = true; - drag_from = mb->get_pos().x; + drag_from = mb->get_position().x; drag_ofs = expand_ofs; } } @@ -312,7 +312,7 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) { if (dragging) { - expand_ofs = drag_ofs + ((vertical ? mm->get_pos().y : mm->get_pos().x) - drag_from); + expand_ofs = drag_ofs + ((vertical ? mm->get_position().y : mm->get_position().x) - drag_from); queue_sort(); emit_signal("dragged", get_split_offset()); } diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 6bbfa1aeb0..5ebcef3e8d 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -69,7 +69,7 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) { if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { - Point2 pos(mb->get_pos().x, mb->get_pos().y); + Point2 pos(mb->get_position().x, mb->get_position().y); Size2 size = get_size(); // Click must be on tabs in the tab header area. @@ -233,7 +233,7 @@ void TabContainer::_notification(int p_what) { Control *control = tabs[i + first_tab_cache]->cast_to<Control>(); String text = control->has_meta("_tab_name") ? String(XL_MESSAGE(String(control->get_meta("_tab_name")))) : String(control->get_name()); - int x_content = tab_rect.pos.x + tab_style->get_margin(MARGIN_LEFT); + int x_content = tab_rect.position.x + tab_style->get_margin(MARGIN_LEFT); int top_margin = tab_style->get_margin(MARGIN_TOP); int y_center = top_margin + (tab_rect.size.y - tab_style->get_minimum_size().y) / 2; diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index d94c33e408..cdb7965444 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -85,7 +85,7 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) { if (mm.is_valid()) { - Point2 pos = mm->get_pos(); + Point2 pos = mm->get_position(); highlight_arrow = -1; if (buttons_visible) { @@ -165,7 +165,7 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) { mb->get_button_index() == BUTTON_LEFT) { // clicks - Point2 pos(mb->get_pos().x, mb->get_pos().y); + Point2 pos(mb->get_position().x, mb->get_position().y); if (buttons_visible) { @@ -340,8 +340,8 @@ void Tabs::_notification(int p_what) { Rect2 rb_rect; rb_rect.size = style->get_minimum_size() + rb->get_size(); - rb_rect.pos.x = w; - rb_rect.pos.y = sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - (rb_rect.size.y)) / 2; + rb_rect.position.x = w; + rb_rect.position.y = sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - (rb_rect.size.y)) / 2; if (rb_hover == i) { if (rb_pressing) @@ -350,7 +350,7 @@ void Tabs::_notification(int p_what) { style->draw(ci, rb_rect); } - rb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), rb_rect.pos.y + style->get_margin(MARGIN_TOP))); + rb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), rb_rect.position.y + style->get_margin(MARGIN_TOP))); w += rb->get_width(); tabs[i].rb_rect = rb_rect; } @@ -364,8 +364,8 @@ void Tabs::_notification(int p_what) { Rect2 cb_rect; cb_rect.size = style->get_minimum_size() + cb->get_size(); - cb_rect.pos.x = w; - cb_rect.pos.y = sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - (cb_rect.size.y)) / 2; + cb_rect.position.x = w; + cb_rect.position.y = sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - (cb_rect.size.y)) / 2; if (!tabs[i].disabled && cb_hover == i) { if (cb_pressing) @@ -374,7 +374,7 @@ void Tabs::_notification(int p_what) { style->draw(ci, cb_rect); } - cb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), cb_rect.pos.y + style->get_margin(MARGIN_TOP))); + cb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), cb_rect.position.y + style->get_margin(MARGIN_TOP))); w += cb->get_width(); tabs[i].cb_rect = cb_rect; } diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 4989a3d863..936a9b77f8 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1069,16 +1069,16 @@ void TextEdit::_notification(int p_what) { int th = h + csb->get_minimum_size().y; if (cursor_pos.y + get_row_height() + th > get_size().height) { - completion_rect.pos.y = cursor_pos.y - th; + completion_rect.position.y = cursor_pos.y - th; } else { - completion_rect.pos.y = cursor_pos.y + get_row_height() + csb->get_offset().y; + completion_rect.position.y = cursor_pos.y + get_row_height() + csb->get_offset().y; completion_below = true; } if (cursor_pos.x - nofs + w + scrollw > get_size().width) { - completion_rect.pos.x = get_size().width - w - scrollw; + completion_rect.position.x = get_size().width - w - scrollw; } else { - completion_rect.pos.x = cursor_pos.x - nofs; + completion_rect.position.x = cursor_pos.x - nofs; } completion_rect.size.width = w + 2; @@ -1086,14 +1086,14 @@ void TextEdit::_notification(int p_what) { if (completion_options.size() <= maxlines) scrollw = 0; - draw_style_box(csb, Rect2(completion_rect.pos - csb->get_offset(), completion_rect.size + csb->get_minimum_size() + Size2(scrollw, 0))); + draw_style_box(csb, Rect2(completion_rect.position - csb->get_offset(), completion_rect.size + csb->get_minimum_size() + Size2(scrollw, 0))); if (cache.completion_background_color.a > 0.01) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(completion_rect.pos, completion_rect.size + Size2(scrollw, 0)), cache.completion_background_color); + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(completion_rect.position, completion_rect.size + Size2(scrollw, 0)), cache.completion_background_color); } int line_from = CLAMP(completion_index - lines / 2, 0, completion_options.size() - lines); - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(completion_rect.pos.x, completion_rect.pos.y + (completion_index - line_from) * get_row_height()), Size2(completion_rect.size.width, get_row_height())), cache.completion_selected_color); - draw_rect(Rect2(completion_rect.pos, Size2(nofs, completion_rect.size.height)), cache.completion_existing_color); + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(completion_rect.position.x, completion_rect.position.y + (completion_index - line_from) * get_row_height()), Size2(completion_rect.size.width, get_row_height())), cache.completion_selected_color); + draw_rect(Rect2(completion_rect.position, Size2(nofs, completion_rect.size.height)), cache.completion_existing_color); for (int i = 0; i < lines; i++) { @@ -1105,14 +1105,14 @@ void TextEdit::_notification(int p_what) { text_color = color_regions[j].color; } } - draw_string(cache.font, Point2(completion_rect.pos.x, completion_rect.pos.y + i * get_row_height() + cache.font->get_ascent()), completion_options[l], text_color, completion_rect.size.width); + draw_string(cache.font, Point2(completion_rect.position.x, completion_rect.position.y + i * get_row_height() + cache.font->get_ascent()), completion_options[l], text_color, completion_rect.size.width); } if (scrollw) { //draw a small scroll rectangle to show a position in the options float r = maxlines / (float)completion_options.size(); float o = line_from / (float)completion_options.size(); - draw_rect(Rect2(completion_rect.pos.x + completion_rect.size.width, completion_rect.pos.y + o * completion_rect.size.y, scrollw, completion_rect.size.y * r), scrollc); + draw_rect(Rect2(completion_rect.position.x + completion_rect.size.width, completion_rect.position.y + o * completion_rect.size.y, scrollw, completion_rect.size.y * r), scrollc); } completion_line_ofs = line_from; @@ -1445,7 +1445,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { Ref<InputEventMouseButton> mb = p_gui_input; if (mb.is_valid()) { - if (completion_active && completion_rect.has_point(mb->get_pos())) { + if (completion_active && completion_rect.has_point(mb->get_position())) { if (!mb->is_pressed()) return; @@ -1468,7 +1468,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (mb->get_button_index() == BUTTON_LEFT) { - completion_index = CLAMP(completion_line_ofs + (mb->get_pos().y - completion_rect.pos.y) / get_row_height(), 0, completion_options.size() - 1); + completion_index = CLAMP(completion_line_ofs + (mb->get_position().y - completion_rect.position.y) / get_row_height(), 0, completion_options.size() - 1); completion_current = completion_options[completion_index]; update(); @@ -1500,7 +1500,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { _reset_caret_blink_timer(); int row, col; - _get_mouse_pos(Point2i(mb->get_pos().x, mb->get_pos().y), row, col); + _get_mouse_pos(Point2i(mb->get_position().x, mb->get_position().y), row, col); if (mb->get_command() && highlighted_word != String()) { @@ -1511,7 +1511,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { // toggle breakpoint on gutter click if (draw_breakpoint_gutter) { int gutter = cache.style_normal->get_margin(MARGIN_LEFT); - if (mb->get_pos().x > gutter && mb->get_pos().x <= gutter + cache.breakpoint_gutter_width + 3) { + if (mb->get_position().x > gutter && mb->get_position().x <= gutter + cache.breakpoint_gutter_width + 3) { set_line_as_breakpoint(row, !is_line_set_as_breakpoint(row)); emit_signal("breakpoint_toggled", row); return; @@ -1646,7 +1646,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (select_identifiers_enabled) { if (mm->get_command() && mm->get_button_mask() == 0) { - String new_word = get_word_at_pos(mm->get_pos()); + String new_word = get_word_at_pos(mm->get_position()); if (new_word != highlighted_word) { highlighted_word = new_word; update(); @@ -1666,7 +1666,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { _reset_caret_blink_timer(); int row, col; - _get_mouse_pos(mm->get_pos(), row, col); + _get_mouse_pos(mm->get_position(), row, col); select(selection.selecting_line, selection.selecting_column, row, col); diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index b17192fe4f..d864d9fce7 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -610,6 +610,18 @@ Color TreeItem::get_custom_bg_color(int p_column) const { return cells[p_column].bg_color; } +void TreeItem::set_custom_as_button(int p_column, bool p_button) { + + ERR_FAIL_INDEX(p_column, cells.size()); + cells[p_column].custom_button = p_button; +} + +bool TreeItem::is_custom_set_as_button(int p_column) const { + + ERR_FAIL_INDEX_V(p_column, cells.size(), false); + return cells[p_column].custom_button; +} + void TreeItem::_bind_methods() { ClassDB::bind_method(D_METHOD("set_cell_mode", "column", "mode"), &TreeItem::set_cell_mode); @@ -670,6 +682,9 @@ void TreeItem::_bind_methods() { ClassDB::bind_method(D_METHOD("clear_custom_bg_color", "column"), &TreeItem::clear_custom_bg_color); ClassDB::bind_method(D_METHOD("get_custom_bg_color", "column"), &TreeItem::get_custom_bg_color); + ClassDB::bind_method(D_METHOD("set_custom_as_button", "column", "enable"), &TreeItem::set_custom_as_button); + ClassDB::bind_method(D_METHOD("is_custom_set_as_button", "column"), &TreeItem::is_custom_set_as_button); + ClassDB::bind_method(D_METHOD("add_button", "column", "button:Texture", "button_idx", "disabled", "tooltip"), &TreeItem::add_button, DEFVAL(-1), DEFVAL(false), DEFVAL("")); ClassDB::bind_method(D_METHOD("get_button_count", "column"), &TreeItem::get_button_count); ClassDB::bind_method(D_METHOD("get_button:Texture", "column", "button_idx"), &TreeItem::get_button); @@ -732,6 +747,10 @@ TreeItem::~TreeItem() { tree->pressing_for_editor = false; } + if (tree && tree->cache.hover_item == this) { + tree->cache.hover_item = NULL; + } + if (tree && tree->selected_item == this) tree->selected_item = NULL; @@ -772,6 +791,11 @@ void Tree::update_cache() { cache.select_arrow = get_icon("select_arrow"); cache.updown = get_icon("updown"); + cache.custom_button = get_stylebox("custom_button"); + cache.custom_button_hover = get_stylebox("custom_button_hover"); + cache.custom_button_pressed = get_stylebox("custom_button_pressed"); + cache.custom_button_font_highlight = get_color("custom_button_font_highlight"); + cache.font_color = get_color("font_color"); cache.font_color_selected = get_color("font_color_selected"); cache.guide_color = get_color("guide_color"); @@ -833,6 +857,9 @@ int Tree::compute_item_height(TreeItem *p_item) const { if (s.height > height) height = s.height; } + if (p_item->cells[i].mode == TreeItem::CELL_MODE_CUSTOM && p_item->cells[i].custom_button) { + height += cache.custom_button->get_minimum_size().height; + } } break; default: {} @@ -877,8 +904,8 @@ void Tree::draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, co bmsize.width = p_cell.icon_max_w; } - p_cell.draw_icon(ci, rect.pos + Size2i(0, Math::floor((real_t)(rect.size.y - bmsize.y) / 2)), bmsize); - rect.pos.x += bmsize.x + cache.hseparation; + p_cell.draw_icon(ci, rect.position + Size2i(0, Math::floor((real_t)(rect.size.y - bmsize.y) / 2)), bmsize); + rect.position.x += bmsize.x + cache.hseparation; rect.size.x -= bmsize.x + cache.hseparation; } @@ -893,8 +920,8 @@ void Tree::draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, co if (p_cell.suffix != String()) text += " " + p_cell.suffix; - rect.pos.y += Math::floor((rect.size.y - font->get_height()) / 2.0) + font->get_ascent(); - font->draw(ci, rect.pos, text, p_color, rect.size.x); + rect.position.y += Math::floor((rect.size.y - font->get_height()) / 2.0) + font->get_ascent(); + font->draw(ci, rect.position, text, p_color, rect.size.x); } #if 0 @@ -1007,16 +1034,16 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 Rect2i item_rect = Rect2i(Point2i(ofs, p_pos.y) - cache.offset + p_draw_ofs, Size2i(w, label_h)); Rect2i cell_rect = item_rect; if (i != 0) { - cell_rect.pos.x -= cache.hseparation; + cell_rect.position.x -= cache.hseparation; cell_rect.size.x += cache.hseparation; } - VisualServer::get_singleton()->canvas_item_add_line(ci, Point2i(cell_rect.pos.x, cell_rect.pos.y + cell_rect.size.height), cell_rect.pos + cell_rect.size, cache.guide_color, 1); + VisualServer::get_singleton()->canvas_item_add_line(ci, Point2i(cell_rect.position.x, cell_rect.position.y + cell_rect.size.height), cell_rect.position + cell_rect.size, cache.guide_color, 1); if (i == 0) { if (p_item->cells[0].selected && select_mode == SELECT_ROW) { - Rect2i row_rect = Rect2i(Point2i(cache.bg->get_margin(MARGIN_LEFT), item_rect.pos.y), Size2i(get_size().width - cache.bg->get_minimum_size().width, item_rect.size.y)); + Rect2i row_rect = Rect2i(Point2i(cache.bg->get_margin(MARGIN_LEFT), item_rect.position.y), Size2i(get_size().width - cache.bg->get_minimum_size().width, item_rect.size.y)); //Rect2 r = Rect2i(row_rect.pos,row_rect.size); //r.grow(cache.selected->get_margin(MARGIN_LEFT)); if (has_focus()) @@ -1028,34 +1055,34 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 if (p_item->cells[i].selected && select_mode != SELECT_ROW) { - Rect2i r(item_rect.pos, item_rect.size); + Rect2i r(item_rect.position, item_rect.size); if (p_item->cells[i].text.size() > 0) { float icon_width = p_item->cells[i].get_icon_size().width; - r.pos.x += icon_width; + r.position.x += icon_width; r.size.x -= icon_width; } //r.grow(cache.selected->get_margin(MARGIN_LEFT)); if (has_focus()) { cache.selected_focus->draw(ci, r); - p_item->set_meta("__focus_rect", Rect2(r.pos, r.size)); + p_item->set_meta("__focus_rect", Rect2(r.position, r.size)); } else { cache.selected->draw(ci, r); } if (text_editor->is_visible_in_tree()) { - text_editor->set_position(get_global_position() + r.pos); + text_editor->set_position(get_global_position() + r.position); } } if (p_item->cells[i].custom_bg_color) { Rect2 r = cell_rect; - r.pos.x -= cache.hseparation; + r.position.x -= cache.hseparation; r.size.x += cache.hseparation; if (p_item->cells[i].custom_bg_outline) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.pos.x, r.pos.y, r.size.x, 1), p_item->cells[i].bg_color); - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.pos.x, r.pos.y + r.size.y - 1, r.size.x, 1), p_item->cells[i].bg_color); - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.pos.x, r.pos.y, 1, r.size.y), p_item->cells[i].bg_color); - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.pos.x + r.size.x - 1, r.pos.y, 1, r.size.y), p_item->cells[i].bg_color); + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, r.size.x, 1), p_item->cells[i].bg_color); + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y + r.size.y - 1, r.size.x, 1), p_item->cells[i].bg_color); + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, 1, r.size.y), p_item->cells[i].bg_color); + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x + r.size.x - 1, r.position.y, 1, r.size.y), p_item->cells[i].bg_color); } else { VisualServer::get_singleton()->canvas_item_add_rect(ci, r, p_item->cells[i].bg_color); } @@ -1066,22 +1093,22 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 Rect2 r = cell_rect; if (drop_mode_section == -1 || drop_mode_section == 0) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.pos.x, r.pos.y, r.size.x, 1), cache.drop_position_color); + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, r.size.x, 1), cache.drop_position_color); } if (drop_mode_section == 0) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.pos.x, r.pos.y, 1, r.size.y), cache.drop_position_color); - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.pos.x + r.size.x - 1, r.pos.y, 1, r.size.y), cache.drop_position_color); + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, 1, r.size.y), cache.drop_position_color); + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x + r.size.x - 1, r.position.y, 1, r.size.y), cache.drop_position_color); } if (drop_mode_section == 1 || drop_mode_section == 0) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.pos.x, r.pos.y + r.size.y, r.size.x, 1), cache.drop_position_color); + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y + r.size.y, r.size.x, 1), cache.drop_position_color); } } Color col = p_item->cells[i].custom_color ? p_item->cells[i].color : get_color(p_item->cells[i].selected ? "font_color_selected" : "font_color"); - Point2i text_pos = item_rect.pos; + Point2i text_pos = item_rect.position; text_pos.y += Math::floor((item_rect.size.y - font->get_height()) / 2) + font_ascent; switch (p_item->cells[i].mode) { @@ -1094,7 +1121,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 Ref<Texture> checked = cache.checked; Ref<Texture> unchecked = cache.unchecked; - Point2i check_ofs = item_rect.pos; + Point2i check_ofs = item_rect.position; check_ofs.y += Math::floor((real_t)(item_rect.size.y - checked->get_height()) / 2); if (p_item->cells[i].checked) { @@ -1109,7 +1136,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 text_pos.x += check_w; item_rect.size.x -= check_w; - item_rect.pos.x += check_w; + item_rect.position.x += check_w; draw_item_rect(p_item->cells[i], item_rect, col); @@ -1137,7 +1164,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 font->draw(ci, text_pos, s, col, item_rect.size.x - downarrow->get_width()); //? - Point2i arrow_pos = item_rect.pos; + Point2i arrow_pos = item_rect.position; arrow_pos.x += item_rect.size.x - downarrow->get_width(); arrow_pos.y += Math::floor(((item_rect.size.y - downarrow->get_height())) / 2.0); @@ -1157,7 +1184,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 if (!p_item->cells[i].editable) break; - Point2i updown_pos = item_rect.pos; + Point2i updown_pos = item_rect.position; updown_pos.x += item_rect.size.x - updown->get_width(); updown_pos.y += Math::floor(((item_rect.size.y - updown->get_height())) / 2.0); @@ -1176,7 +1203,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 } Point2i icon_ofs = (item_rect.size - icon_size) / 2; - icon_ofs += item_rect.pos; + icon_ofs += item_rect.position; draw_texture_rect(p_item->cells[i].icon, Rect2(icon_ofs, icon_size)); //p_item->cells[i].icon->draw(ci, icon_ofs); @@ -1202,12 +1229,28 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 Ref<Texture> downarrow = cache.select_arrow; Rect2i ir = item_rect; - ir.size.width -= downarrow->get_width(); - draw_item_rect(p_item->cells[i], ir, col); - Point2i arrow_pos = item_rect.pos; + Point2i arrow_pos = item_rect.position; arrow_pos.x += item_rect.size.x - downarrow->get_width(); arrow_pos.y += Math::floor(((item_rect.size.y - downarrow->get_height())) / 2.0); + ir.size.width -= downarrow->get_width(); + + if (p_item->cells[i].custom_button) { + if (cache.hover_item == p_item && cache.hover_cell == i) { + if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { + draw_style_box(cache.custom_button_pressed, ir); + } else { + draw_style_box(cache.custom_button_hover, ir); + col = cache.custom_button_font_highlight; + } + } else { + draw_style_box(cache.custom_button, ir); + } + ir.size -= cache.custom_button->get_minimum_size(); + ir.position += cache.custom_button->get_offset(); + } + + draw_item_rect(p_item->cells[i], ir, col); downarrow->draw(ci, arrow_pos); @@ -1697,11 +1740,18 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool case TreeItem::CELL_MODE_CUSTOM: { edited_item = p_item; edited_col = col; - custom_popup_rect = Rect2i(get_global_position() + Point2i(col_ofs, _get_title_button_height() + y_ofs + item_h - cache.offset.y), Size2(get_column_width(col), item_h)); - emit_signal("custom_popup_edited", ((bool)(x >= (col_width - item_h / 2)))); + bool on_arrow = x > col_width - cache.select_arrow->get_width(); bring_up_editor = false; - item_edited(col, p_item); + + if (on_arrow || !p_item->cells[col].custom_button) { + custom_popup_rect = Rect2i(get_global_position() + Point2i(col_ofs, _get_title_button_height() + y_ofs + item_h - cache.offset.y), Size2(get_column_width(col), item_h)); + emit_signal("custom_popup_edited", ((bool)(x >= (col_width - item_h / 2)))); + } + + if (!p_item->cells[col].custom_button || !on_arrow) { + item_edited(col, p_item); + } click_handled = true; return -1; } break; @@ -2122,7 +2172,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { Ref<StyleBox> bg = cache.bg; - Point2 pos = mm->get_pos() - bg->get_offset(); + Point2 pos = mm->get_position() - bg->get_offset(); Cache::ClickType old_hover = cache.hover_type; int old_index = cache.hover_index; @@ -2148,9 +2198,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { } } - if (drop_mode_flags && root) { + if (root) { - Point2 mpos = mm->get_pos(); + Point2 mpos = mm->get_position(); mpos -= cache.bg->get_offset(); mpos.y -= _get_title_button_height(); if (mpos.y >= 0) { @@ -2163,11 +2213,17 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { int col, h, section; TreeItem *it = _find_item_at_pos(root, mpos, col, h, section); - if (it != drop_mode_over || section != drop_mode_section) { + if (drop_mode_flags && it != drop_mode_over || section != drop_mode_section) { drop_mode_over = it; drop_mode_section = section; update(); } + + if (it != cache.hover_item || col != cache.hover_cell) { + cache.hover_item = it; + cache.hover_cell = col; + update(); + } } } @@ -2180,7 +2236,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { if (!range_drag_enabled) { - Vector2 cpos = mm->get_pos(); + Vector2 cpos = mm->get_position(); if (cpos.distance_to(pressing_pos) > 2) { range_drag_enabled = true; range_drag_capture_pos = cpos; @@ -2217,7 +2273,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { if (b->get_button_index() == BUTTON_LEFT) { - Point2 pos = b->get_pos() - cache.bg->get_offset(); + Point2 pos = b->get_position() - cache.bg->get_offset(); if (show_column_titles) { pos.y -= _get_title_button_height(); @@ -2251,7 +2307,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { warp_mouse(range_drag_capture_pos); } else { Rect2 rect = get_selected()->get_meta("__focus_rect"); - if (rect.has_point(Point2(b->get_pos().x, b->get_pos().y))) { + if (rect.has_point(Point2(b->get_position().x, b->get_position().y))) { edit_selected(); } else { emit_signal("item_double_clicked"); @@ -2295,7 +2351,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { case BUTTON_LEFT: { Ref<StyleBox> bg = cache.bg; - Point2 pos = b->get_pos() - bg->get_offset(); + Point2 pos = b->get_position() - bg->get_offset(); cache.click_type = Cache::CLICK_NONE; if (show_column_titles && b->get_button_index() == BUTTON_LEFT) { pos.y -= _get_title_button_height(); @@ -2333,7 +2389,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { blocked--; if (pressing_for_editor) { - pressing_pos = b->get_pos(); + pressing_pos = b->get_position(); } if (b->get_button_index() == BUTTON_RIGHT) @@ -2401,7 +2457,7 @@ bool Tree::edit_selected() { edited_item = s; edited_col = col; - custom_popup_rect = Rect2i(get_global_position() + rect.pos, rect.size); + custom_popup_rect = Rect2i(get_global_position() + rect.position, rect.size); emit_signal("custom_popup_edited", false); item_edited(col, s); @@ -2416,7 +2472,7 @@ bool Tree::edit_selected() { } popup_menu->set_size(Size2(rect.size.width, 0)); - popup_menu->set_position(get_global_position() + rect.pos + Point2i(0, rect.size.height)); + popup_menu->set_position(get_global_position() + rect.position + Point2i(0, rect.size.height)); popup_menu->popup(); popup_edited_item = s; popup_edited_item_col = col; @@ -2424,7 +2480,7 @@ bool Tree::edit_selected() { } else if (c.mode == TreeItem::CELL_MODE_STRING || c.mode == TreeItem::CELL_MODE_RANGE || c.mode == TreeItem::CELL_MODE_RANGE_EXPRESSION) { - Point2i textedpos = get_global_position() + rect.pos; + Point2i textedpos = get_global_position() + rect.position; text_editor->set_position(textedpos); text_editor->set_size(rect.size); text_editor->clear(); @@ -2671,7 +2727,7 @@ void Tree::_notification(int p_what) { ofs += tbrect.size.width; //text int clip_w = tbrect.size.width - sb->get_minimum_size().width; - f->draw_halign(ci, tbrect.pos + Point2i(sb->get_offset().x, (tbrect.size.height - f->get_height()) / 2 + f->get_ascent()), HALIGN_CENTER, clip_w, columns[i].title, cache.title_button_color); + f->draw_halign(ci, tbrect.position + Point2i(sb->get_offset().x, (tbrect.size.height - f->get_height()) / 2 + f->get_ascent()), HALIGN_CENTER, clip_w, columns[i].title, cache.title_button_color); } } } @@ -3053,11 +3109,11 @@ Rect2 Tree::get_item_rect(TreeItem *p_item, int p_column) const { int ofs = get_item_offset(p_item); int height = compute_item_height(p_item); Rect2 r; - r.pos.y = ofs; + r.position.y = ofs; r.size.height = height; if (p_column == -1) { - r.pos.x = 0; + r.position.x = 0; r.size.x = get_size().width; } else { @@ -3065,7 +3121,7 @@ Rect2 Tree::get_item_rect(TreeItem *p_item, int p_column) const { for (int i = 0; i < p_column; i++) { accum += get_column_width(i); } - r.pos.x = accum; + r.position.x = accum; r.size.x = get_column_width(p_column); } @@ -3469,6 +3525,7 @@ void Tree::_bind_methods() { ADD_SIGNAL(MethodInfo("item_rmb_selected", PropertyInfo(Variant::VECTOR2, "pos"))); ADD_SIGNAL(MethodInfo("empty_tree_rmb_selected", PropertyInfo(Variant::VECTOR2, "pos"))); ADD_SIGNAL(MethodInfo("item_edited")); + ADD_SIGNAL(MethodInfo("item_custom_button_pressed")); ADD_SIGNAL(MethodInfo("item_double_clicked")); ADD_SIGNAL(MethodInfo("item_collapsed", PropertyInfo(Variant::OBJECT, "item"))); //ADD_SIGNAL( MethodInfo("item_doubleclicked" ) ); @@ -3575,6 +3632,9 @@ Tree::Tree() { force_edit_checkbox_only_on_checkbox = false; set_clip_contents(true); + + cache.hover_item = NULL; + cache.hover_cell = -1; } Tree::~Tree() { diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 0c07109e7d..097e0110e8 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -81,6 +81,7 @@ private: bool custom_bg_color; bool custom_bg_outline; Color bg_color; + bool custom_button; Variant meta; String tooltip; @@ -107,6 +108,7 @@ private: Cell() { custom_draw_obj = 0; + custom_button = false; mode = TreeItem::CELL_MODE_STRING; min = 0; max = 100; @@ -238,6 +240,9 @@ public: void clear_custom_bg_color(int p_column); Color get_custom_bg_color(int p_column) const; + void set_custom_as_button(int p_column, bool p_button); + bool is_custom_set_as_button(int p_column) const; + void set_tooltip(int p_column, const String &p_tooltip); String get_tooltip(int p_column) const; @@ -369,6 +374,10 @@ private: Ref<StyleBox> title_button; Ref<StyleBox> title_button_hover; Ref<StyleBox> title_button_pressed; + Ref<StyleBox> custom_button; + Ref<StyleBox> custom_button_hover; + Ref<StyleBox> custom_button_pressed; + Color title_button_color; Ref<Texture> checked; @@ -383,6 +392,7 @@ private: Color guide_color; Color drop_position_color; Color relationship_line_color; + Color custom_button_font_highlight; int hseparation; int vseparation; @@ -410,6 +420,9 @@ private: int hover_index; Point2 click_pos; + TreeItem *hover_item; + int hover_cell; + } cache; int _get_title_button_height() const; diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp index 96a3519840..f7a255cd33 100644 --- a/scene/main/scene_main_loop.cpp +++ b/scene/main/scene_main_loop.cpp @@ -839,12 +839,12 @@ Ref<Material> SceneTree::get_debug_collision_material() { return collision_material; } -Ref<Mesh> SceneTree::get_debug_contact_mesh() { +Ref<ArrayMesh> SceneTree::get_debug_contact_mesh() { if (debug_contact_mesh.is_valid()) return debug_contact_mesh; - debug_contact_mesh = Ref<Mesh>(memnew(Mesh)); + debug_contact_mesh = Ref<ArrayMesh>(memnew(ArrayMesh)); Ref<SpatialMaterial> mat = memnew(SpatialMaterial); /*mat->set_flag(Material::FLAG_UNSHADED,true); diff --git a/scene/main/scene_main_loop.h b/scene/main/scene_main_loop.h index 5d42c66652..2ea79bf945 100644 --- a/scene/main/scene_main_loop.h +++ b/scene/main/scene_main_loop.h @@ -33,6 +33,7 @@ #include "io/networked_multiplayer_peer.h" #include "os/main_loop.h" #include "os/thread_safe.h" +#include "scene/resources/mesh.h" #include "scene/resources/world.h" #include "scene/resources/world_2d.h" #include "self_list.h" @@ -169,7 +170,7 @@ private: Color debug_collision_contact_color; Color debug_navigation_color; Color debug_navigation_disabled_color; - Ref<Mesh> debug_contact_mesh; + Ref<ArrayMesh> debug_contact_mesh; Ref<Material> navigation_material; Ref<Material> navigation_disabled_material; Ref<Material> collision_material; @@ -406,7 +407,7 @@ public: Ref<Material> get_debug_navigation_material(); Ref<Material> get_debug_navigation_disabled_material(); Ref<Material> get_debug_collision_material(); - Ref<Mesh> get_debug_contact_mesh(); + Ref<ArrayMesh> get_debug_contact_mesh(); int get_collision_debug_contact_count() { return collision_debug_contacts; } diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index f62cebe042..ec36cf48bc 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -512,7 +512,7 @@ void Viewport::_notification(int p_what) { if (mm.is_valid()) { - pos = mm->get_pos(); + pos = mm->get_position(); motion_tested = true; physics_last_mousepos = pos; } @@ -520,19 +520,19 @@ void Viewport::_notification(int p_what) { Ref<InputEventMouseButton> mb = ev; if (mb.is_valid()) { - pos = mb->get_pos(); + pos = mb->get_position(); } Ref<InputEventScreenDrag> sd = ev; if (sd.is_valid()) { - pos = sd->get_pos(); + pos = sd->get_position(); } Ref<InputEventScreenTouch> st = ev; if (st.is_valid()) { - pos = st->get_pos(); + pos = st->get_position(); } if (ss2d) { @@ -1310,7 +1310,7 @@ Transform2D Viewport::_get_input_pre_xform() const { if (to_screen_rect != Rect2()) { - pre_xf.elements[2] = -to_screen_rect.pos; + pre_xf.elements[2] = -to_screen_rect.position; pre_xf.scale(size / to_screen_rect.size); } @@ -1473,17 +1473,17 @@ void Viewport::_gui_show_tooltip() { gui.tooltip_label->set_text(tooltip); Rect2 r(gui.tooltip_pos + Point2(10, 10), gui.tooltip_label->get_combined_minimum_size() + ttp->get_minimum_size()); Rect2 vr = gui.tooltip_label->get_viewport_rect(); - if (r.size.x + r.pos.x > vr.size.x) - r.pos.x = vr.size.x - r.size.x; - else if (r.pos.x < 0) - r.pos.x = 0; + if (r.size.x + r.position.x > vr.size.x) + r.position.x = vr.size.x - r.size.x; + else if (r.position.x < 0) + r.position.x = 0; - if (r.size.y + r.pos.y > vr.size.y) - r.pos.y = vr.size.y - r.size.y; - else if (r.pos.y < 0) - r.pos.y = 0; + if (r.size.y + r.position.y > vr.size.y) + r.position.y = vr.size.y - r.size.y; + else if (r.position.y < 0) + r.position.y = 0; - gui.tooltip_popup->set_global_position(r.pos); + gui.tooltip_popup->set_global_position(r.position); gui.tooltip_popup->set_size(r.size); gui.tooltip_popup->raise(); @@ -1685,7 +1685,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { gui.key_event_accepted = false; - Point2 mpos = mb->get_pos(); + Point2 mpos = mb->get_position(); if (mb->is_pressed()) { Size2 pos = mpos; @@ -1740,11 +1740,11 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { mb = mb->xformed_by(Transform2D()); // make a copy of the event - mb->set_global_pos(pos); + mb->set_global_position(pos); pos = gui.focus_inv_xform.xform(pos); - mb->set_pos(pos); + mb->set_position(pos); #ifdef DEBUG_ENABLED if (ScriptDebugger::get_singleton()) { @@ -1841,9 +1841,9 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { Size2 pos = mpos; mb = mb->xformed_by(Transform2D()); //make a copy - mb->set_global_pos(pos); + mb->set_global_position(pos); pos = gui.focus_inv_xform.xform(pos); - mb->set_pos(pos); + mb->set_position(pos); if (gui.mouse_focus->can_process()) { _gui_call_input(gui.mouse_focus, mb); @@ -1869,7 +1869,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { if (mm.is_valid()) { gui.key_event_accepted = false; - Point2 mpos = mm->get_pos(); + Point2 mpos = mm->get_position(); gui.last_mouse_pos = mpos; @@ -1961,7 +1961,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { mm = mm->xformed_by(Transform2D()); //make a copy - mm->set_global_pos(mpos); + mm->set_global_position(mpos); mm->set_speed(speed); mm->set_relative(rel); @@ -1999,7 +1999,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { //pos = gui.focus_inv_xform.xform(pos); - mm->set_pos(pos); + mm->set_position(pos); Control::CursorShape cursor_shape = over->get_cursor_shape(pos); OS::get_singleton()->set_cursor_shape((OS::CursorShape)cursor_shape); @@ -2318,7 +2318,7 @@ void Viewport::_gui_grab_click_focus(Control *p_control) { //send unclic Point2 click = gui.mouse_focus->get_global_transform_with_canvas().affine_inverse().xform(gui.last_mouse_pos); - mb->set_pos(click); + mb->set_position(click); mb->set_button_index(gui.mouse_focus_button); mb->set_pressed(false); gui.mouse_focus->call_deferred(SceneStringNames::get_singleton()->_gui_input, mb); @@ -2326,7 +2326,7 @@ void Viewport::_gui_grab_click_focus(Control *p_control) { gui.mouse_focus = p_control; gui.focus_inv_xform = gui.mouse_focus->get_global_transform_with_canvas().affine_inverse(); click = gui.mouse_focus->get_global_transform_with_canvas().affine_inverse().xform(gui.last_mouse_pos); - mb->set_pos(click); + mb->set_position(click); mb->set_button_index(gui.mouse_focus_button); mb->set_pressed(true); gui.mouse_focus->call_deferred(SceneStringNames::get_singleton()->_gui_input, mb); diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 0a3f64eacd..9f078072d7 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -523,11 +523,12 @@ void register_scene_types() { ClassDB::register_virtual_class<Shader>(); #ifndef _3D_DISABLED - ClassDB::register_class<Mesh>(); - ClassDB::register_class<QuadMesh>(); + ClassDB::register_virtual_class<Mesh>(); + ClassDB::register_class<ArrayMesh>(); ClassDB::register_virtual_class<Material>(); ClassDB::register_class<SpatialMaterial>(); ClassDB::add_compatibility_class("FixedSpatialMaterial", "SpatialMaterial"); + ClassDB::add_compatibility_class("Mesh", "ArrayMesh"); SceneTree::add_idle_callback(SpatialMaterial::flush_changes); SpatialMaterial::init_shaders(); diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 545c700354..fe5e6e775a 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -1133,7 +1133,7 @@ Variant Animation::_cubic_interpolate(const Variant &p_pre_a, const Variant &p_a Rect2 pb = p_post_b; return Rect2( - a.pos.cubic_interpolate(b.pos, pa.pos, pb.pos, p_c), + a.position.cubic_interpolate(b.position, pa.position, pb.position, p_c), a.size.cubic_interpolate(b.size, pa.size, pb.size, p_c)); } break; diff --git a/scene/resources/bit_mask.cpp b/scene/resources/bit_mask.cpp index e512f8a968..a473067937 100644 --- a/scene/resources/bit_mask.cpp +++ b/scene/resources/bit_mask.cpp @@ -67,9 +67,9 @@ void BitMap::set_bit_rect(const Rect2 &p_rect, bool p_value) { Rect2i current = Rect2i(0, 0, width, height).clip(p_rect); uint8_t *data = bitmask.ptr(); - for (int i = current.pos.x; i < current.pos.x + current.size.x; i++) { + for (int i = current.position.x; i < current.position.x + current.size.x; i++) { - for (int j = current.pos.y; j < current.pos.y + current.size.y; j++) { + for (int j = current.position.y; j < current.position.y + current.size.y; j++) { int ofs = width * j + i; int bbyte = ofs / 8; diff --git a/scene/resources/capsule_shape_2d.cpp b/scene/resources/capsule_shape_2d.cpp index 3f41526bcb..20177692a1 100644 --- a/scene/resources/capsule_shape_2d.cpp +++ b/scene/resources/capsule_shape_2d.cpp @@ -80,7 +80,7 @@ Rect2 CapsuleShape2D::get_rect() const { Vector2 he = Point2(get_radius(), get_radius() + get_height() * 0.5); Rect2 rect; - rect.pos = -he; + rect.position = -he; rect.size = he * 2.0; return rect; } diff --git a/scene/resources/circle_shape_2d.cpp b/scene/resources/circle_shape_2d.cpp index 4512e1c4a9..1b7e09ddfb 100644 --- a/scene/resources/circle_shape_2d.cpp +++ b/scene/resources/circle_shape_2d.cpp @@ -58,7 +58,7 @@ void CircleShape2D::_bind_methods() { Rect2 CircleShape2D::get_rect() const { Rect2 rect; - rect.pos = -Point2(get_radius(), get_radius()); + rect.position = -Point2(get_radius(), get_radius()); rect.size = Point2(get_radius(), get_radius()) * 2.0; return rect; } diff --git a/scene/resources/concave_polygon_shape_2d.cpp b/scene/resources/concave_polygon_shape_2d.cpp index 653540a663..b8c931421e 100644 --- a/scene/resources/concave_polygon_shape_2d.cpp +++ b/scene/resources/concave_polygon_shape_2d.cpp @@ -68,7 +68,7 @@ Rect2 ConcavePolygonShape2D::get_rect() const { PoolVector<Vector2>::Read r = s.read(); for (int i = 0; i < len; i++) { if (i == 0) - rect.pos = r[i]; + rect.position = r[i]; else rect.expand_to(r[i]); } diff --git a/scene/resources/convex_polygon_shape_2d.cpp b/scene/resources/convex_polygon_shape_2d.cpp index fcbf66c8cd..e13f7faf70 100644 --- a/scene/resources/convex_polygon_shape_2d.cpp +++ b/scene/resources/convex_polygon_shape_2d.cpp @@ -78,7 +78,7 @@ Rect2 ConvexPolygonShape2D::get_rect() const { Rect2 rect; for (int i = 0; i < points.size(); i++) { if (i == 0) - rect.pos = points[i]; + rect.position = points[i]; else rect.expand_to(points[i]); } diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 7e5065a03b..668a8ff66f 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -138,8 +138,8 @@ static Ref<BitmapFont> make_font(int p_height, int p_ascent, int p_valign, int p int chr = c[0]; Rect2 frect; - frect.pos.x = c[1]; - frect.pos.y = c[2]; + frect.position.x = c[1]; + frect.position.y = c[2]; frect.size.x = c[3]; frect.size.y = c[4]; Point2 align(c[5], c[6] + p_valign); @@ -170,8 +170,8 @@ static Ref<BitmapFont> make_font2(int p_height, int p_ascent, int p_charcount, c int chr = c[0]; Rect2 frect; - frect.pos.x = c[1]; - frect.pos.y = c[2]; + frect.position.x = c[1]; + frect.position.y = c[2]; frect.size.x = c[3]; frect.size.y = c[4]; Point2 align(c[6], c[5]); @@ -626,6 +626,9 @@ void fill_default_theme(Ref<Theme> &t, const Ref<Font> &default_font, const Ref< t->set_stylebox("title_button_normal", "Tree", make_stylebox(tree_title_png, 4, 4, 4, 4)); t->set_stylebox("title_button_pressed", "Tree", make_stylebox(tree_title_pressed_png, 4, 4, 4, 4)); t->set_stylebox("title_button_hover", "Tree", make_stylebox(tree_title_png, 4, 4, 4, 4)); + t->set_stylebox("custom_button", "Tree", sb_button_normal); + t->set_stylebox("custom_button_pressed", "Tree", sb_button_pressed); + t->set_stylebox("custom_button_hover", "Tree", sb_button_hover); t->set_icon("checked", "Tree", make_icon(checked_png)); t->set_icon("unchecked", "Tree", make_icon(unchecked_png)); @@ -645,6 +648,7 @@ void fill_default_theme(Ref<Theme> &t, const Ref<Font> &default_font, const Ref< t->set_color("guide_color", "Tree", Color(0, 0, 0, 0.1)); t->set_color("drop_position_color", "Tree", Color(1, 0.3, 0.2)); t->set_color("relationship_line_color", "Tree", Color::html("464646")); + t->set_color("custom_button_font_highlight", "Tree", control_font_color_hover); t->set_constant("hseparation", "Tree", 4 * scale); t->set_constant("vseparation", "Tree", 4 * scale); diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index 66f913f347..e40fc0d4be 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -217,6 +217,7 @@ void Environment::set_adjustment_enable(bool p_enable) { adjustment_enabled = p_enable; VS::get_singleton()->environment_set_adjustment(environment, adjustment_enabled, adjustment_brightness, adjustment_contrast, adjustment_saturation, adjustment_color_correction.is_valid() ? adjustment_color_correction->get_rid() : RID()); + _change_notify(); } bool Environment::is_adjustment_enabled() const { @@ -283,12 +284,39 @@ void Environment::_validate_property(PropertyInfo &property) const { property.usage = PROPERTY_USAGE_NOEDITOR; } } + + static const char *hide_prefixes[] = { + "fog_", + "auto_exposure_", + "ss_reflections_", + "ssao_", + "dof_blur_far_", + "dof_blur_near_", + "glow_", + "adjustment_", + NULL + + }; + + const char **prefixes = hide_prefixes; + while (*prefixes) { + String prefix = String(*prefixes); + + String enabled = prefix + "enabled"; + if (property.name.begins_with(prefix) && property.name != enabled && !bool(get(enabled))) { + property.usage = PROPERTY_USAGE_NOEDITOR; + return; + } + + prefixes++; + } } void Environment::set_ssr_enabled(bool p_enable) { ssr_enabled = p_enable; VS::get_singleton()->environment_set_ssr(environment, ssr_enabled, ssr_max_steps, ssr_accel, ssr_fade, ssr_depth_tolerance, ssr_smooth, ssr_roughness); + _change_notify(); } bool Environment::is_ssr_enabled() const { @@ -360,6 +388,7 @@ void Environment::set_ssao_enabled(bool p_enable) { ssao_enabled = p_enable; VS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_radius2, ssao_intensity2, ssao_bias, ssao_direct_light_affect, ssao_color, ssao_blur); + _change_notify(); } bool Environment::is_ssao_enabled() const { @@ -453,6 +482,7 @@ void Environment::set_glow_enabled(bool p_enabled) { glow_enabled = p_enabled; VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_treshold, glow_hdr_bleed_treshold, glow_bicubic_upscale); + _change_notify(); } bool Environment::is_glow_enabled() const { @@ -558,6 +588,7 @@ void Environment::set_dof_blur_far_enabled(bool p_enable) { dof_blur_far_enabled = p_enable; VS::get_singleton()->environment_set_dof_blur_far(environment, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_far_amount, VS::EnvironmentDOFBlurQuality(dof_blur_far_quality)); + _change_notify(); } bool Environment::is_dof_blur_far_enabled() const { @@ -610,6 +641,7 @@ void Environment::set_dof_blur_near_enabled(bool p_enable) { dof_blur_near_enabled = p_enable; VS::get_singleton()->environment_set_dof_blur_near(environment, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_near_amount, VS::EnvironmentDOFBlurQuality(dof_blur_near_quality)); + _change_notify(); } bool Environment::is_dof_blur_near_enabled() const { @@ -661,6 +693,138 @@ Environment::DOFBlurQuality Environment::get_dof_blur_near_quality() const { return dof_blur_near_quality; } +void Environment::set_fog_enabled(bool p_enabled) { + + fog_enabled = p_enabled; + VS::get_singleton()->environment_set_fog(environment, fog_enabled, fog_color, fog_sun_color, fog_sun_amount); + _change_notify(); +} + +bool Environment::is_fog_enabled() const { + + return fog_enabled; +} + +void Environment::set_fog_color(const Color &p_color) { + + fog_color = p_color; + VS::get_singleton()->environment_set_fog(environment, fog_enabled, fog_color, fog_sun_color, fog_sun_amount); +} +Color Environment::get_fog_color() const { + + return fog_color; +} + +void Environment::set_fog_sun_color(const Color &p_color) { + + fog_sun_color = p_color; + VS::get_singleton()->environment_set_fog(environment, fog_enabled, fog_color, fog_sun_color, fog_sun_amount); +} +Color Environment::get_fog_sun_color() const { + + return fog_sun_color; +} + +void Environment::set_fog_sun_amount(float p_amount) { + + fog_sun_amount = p_amount; + VS::get_singleton()->environment_set_fog(environment, fog_enabled, fog_color, fog_sun_color, fog_sun_amount); +} +float Environment::get_fog_sun_amount() const { + + return fog_sun_amount; +} + +void Environment::set_fog_depth_enabled(bool p_enabled) { + + fog_depth_enabled = p_enabled; + VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); +} +bool Environment::is_fog_depth_enabled() const { + + return fog_depth_enabled; +} + +void Environment::set_fog_depth_begin(float p_distance) { + + fog_depth_begin = p_distance; + VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); +} +float Environment::get_fog_depth_begin() const { + + return fog_depth_begin; +} + +void Environment::set_fog_depth_curve(float p_curve) { + + fog_depth_curve = p_curve; + VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); +} +float Environment::get_fog_depth_curve() const { + + return fog_depth_curve; +} + +void Environment::set_fog_transmit_enabled(bool p_enabled) { + + fog_transmit_enabled = p_enabled; + VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); +} +bool Environment::is_fog_transmit_enabled() const { + + return fog_transmit_enabled; +} + +void Environment::set_fog_transmit_curve(float p_curve) { + + fog_transmit_curve = p_curve; + VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); +} +float Environment::get_fog_transmit_curve() const { + + return fog_transmit_curve; +} + +void Environment::set_fog_height_enabled(bool p_enabled) { + + fog_height_enabled = p_enabled; + VS::get_singleton()->environment_set_fog_height(environment, fog_height_enabled, fog_height_min, fog_height_max, fog_height_curve); +} +bool Environment::is_fog_height_enabled() const { + + return fog_height_enabled; +} + +void Environment::set_fog_height_min(float p_distance) { + + fog_height_min = p_distance; + VS::get_singleton()->environment_set_fog_height(environment, fog_height_enabled, fog_height_min, fog_height_max, fog_height_curve); +} +float Environment::get_fog_height_min() const { + + return fog_height_min; +} + +void Environment::set_fog_height_max(float p_distance) { + + fog_height_max = p_distance; + VS::get_singleton()->environment_set_fog_height(environment, fog_height_enabled, fog_height_min, fog_height_max, fog_height_curve); +} +float Environment::get_fog_height_max() const { + + return fog_height_max; +} + +void Environment::set_fog_height_curve(float p_distance) { + + fog_height_curve = p_distance; + VS::get_singleton()->environment_set_fog_height(environment, fog_height_enabled, fog_height_min, fog_height_max, fog_height_curve); +} +float Environment::get_fog_height_curve() const { + + return fog_height_curve; +} + void Environment::_bind_methods() { ClassDB::bind_method(D_METHOD("set_background", "mode"), &Environment::set_background); @@ -695,6 +859,60 @@ void Environment::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::REAL, "ambient_light_energy", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_ambient_light_energy", "get_ambient_light_energy"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "ambient_light_sky_contribution", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_ambient_light_sky_contribution", "get_ambient_light_sky_contribution"); + ClassDB::bind_method(D_METHOD("set_fog_enabled", "enabled"), &Environment::set_fog_enabled); + ClassDB::bind_method(D_METHOD("is_fog_enabled"), &Environment::is_fog_enabled); + + ClassDB::bind_method(D_METHOD("set_fog_color", "color"), &Environment::set_fog_color); + ClassDB::bind_method(D_METHOD("get_fog_color"), &Environment::get_fog_color); + + ClassDB::bind_method(D_METHOD("set_fog_sun_color", "color"), &Environment::set_fog_sun_color); + ClassDB::bind_method(D_METHOD("get_fog_sun_color"), &Environment::get_fog_sun_color); + + ClassDB::bind_method(D_METHOD("set_fog_sun_amount", "amount"), &Environment::set_fog_sun_amount); + ClassDB::bind_method(D_METHOD("get_fog_sun_amount"), &Environment::get_fog_sun_amount); + + ClassDB::bind_method(D_METHOD("set_fog_depth_enabled", "enabled"), &Environment::set_fog_depth_enabled); + ClassDB::bind_method(D_METHOD("is_fog_depth_enabled"), &Environment::is_fog_depth_enabled); + + ClassDB::bind_method(D_METHOD("set_fog_depth_begin", "distance"), &Environment::set_fog_depth_begin); + ClassDB::bind_method(D_METHOD("get_fog_depth_begin"), &Environment::get_fog_depth_begin); + + ClassDB::bind_method(D_METHOD("set_fog_depth_curve", "curve"), &Environment::set_fog_depth_curve); + ClassDB::bind_method(D_METHOD("get_fog_depth_curve"), &Environment::get_fog_depth_curve); + + ClassDB::bind_method(D_METHOD("set_fog_transmit_enabled", "enabled"), &Environment::set_fog_transmit_enabled); + ClassDB::bind_method(D_METHOD("is_fog_transmit_enabled"), &Environment::is_fog_transmit_enabled); + + ClassDB::bind_method(D_METHOD("set_fog_transmit_curve", "curve"), &Environment::set_fog_transmit_curve); + ClassDB::bind_method(D_METHOD("get_fog_transmit_curve"), &Environment::get_fog_transmit_curve); + + ClassDB::bind_method(D_METHOD("set_fog_height_enabled", "enabled"), &Environment::set_fog_height_enabled); + ClassDB::bind_method(D_METHOD("is_fog_height_enabled"), &Environment::is_fog_height_enabled); + + ClassDB::bind_method(D_METHOD("set_fog_height_min", "height"), &Environment::set_fog_height_min); + ClassDB::bind_method(D_METHOD("get_fog_height_min"), &Environment::get_fog_height_min); + + ClassDB::bind_method(D_METHOD("set_fog_height_max", "height"), &Environment::set_fog_height_max); + ClassDB::bind_method(D_METHOD("get_fog_height_max"), &Environment::get_fog_height_max); + + ClassDB::bind_method(D_METHOD("set_fog_height_curve", "curve"), &Environment::set_fog_height_curve); + ClassDB::bind_method(D_METHOD("get_fog_height_curve"), &Environment::get_fog_height_curve); + + ADD_GROUP("Fog", "fog_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fog_enabled"), "set_fog_enabled", "is_fog_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "fog_color"), "set_fog_color", "get_fog_color"); + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "fog_sun_color"), "set_fog_sun_color", "get_fog_sun_color"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "fog_sun_amount", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_fog_sun_amount", "get_fog_sun_amount"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fog_depth_enabled"), "set_fog_depth_enabled", "is_fog_depth_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "fog_depth_begin", PROPERTY_HINT_RANGE, "0,4000,0.1"), "set_fog_depth_begin", "get_fog_depth_begin"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "fog_depth_curve", PROPERTY_HINT_EXP_EASING), "set_fog_depth_curve", "get_fog_depth_curve"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fog_transmit_enabled"), "set_fog_transmit_enabled", "is_fog_transmit_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "fog_transmit_curve", PROPERTY_HINT_EXP_EASING), "set_fog_transmit_curve", "get_fog_transmit_curve"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fog_height_enabled"), "set_fog_height_enabled", "is_fog_height_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "fog_height_min", PROPERTY_HINT_RANGE, "-4000,4000,0.1"), "set_fog_height_min", "get_fog_height_min"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "fog_height_max", PROPERTY_HINT_RANGE, "-4000,4000,0.1"), "set_fog_height_max", "get_fog_height_max"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "fog_height_curve", PROPERTY_HINT_EXP_EASING), "set_fog_height_curve", "get_fog_height_curve"); + ClassDB::bind_method(D_METHOD("set_tonemapper", "mode"), &Environment::set_tonemapper); ClassDB::bind_method(D_METHOD("get_tonemapper"), &Environment::get_tonemapper); @@ -997,6 +1215,27 @@ Environment::Environment() { dof_blur_near_transition = 1; dof_blur_near_amount = 0.1; dof_blur_near_quality = DOF_BLUR_QUALITY_MEDIUM; + + fog_enabled = false; + fog_color = Color(0.5, 0.5, 0.5); + fog_sun_color = Color(0.8, 0.8, 0.0); + fog_sun_amount = 0; + + fog_depth_enabled = true; + + fog_depth_begin = 10; + fog_depth_curve = 1; + + fog_transmit_enabled = false; + fog_transmit_curve = 1; + + fog_height_enabled = false; + fog_height_min = 0; + fog_height_max = 100; + fog_height_curve = 1; + + set_fog_color(Color(0.5, 0.6, 0.7)); + set_fog_sun_color(Color(1.0, 0.9, 0.7)); } Environment::~Environment() { diff --git a/scene/resources/environment.h b/scene/resources/environment.h index d9141ccd9c..7df3458231 100644 --- a/scene/resources/environment.h +++ b/scene/resources/environment.h @@ -138,6 +138,23 @@ private: float dof_blur_near_amount; DOFBlurQuality dof_blur_near_quality; + bool fog_enabled; + Color fog_color; + Color fog_sun_color; + float fog_sun_amount; + + bool fog_depth_enabled; + float fog_depth_begin; + float fog_depth_curve; + + bool fog_transmit_enabled; + float fog_transmit_curve; + + bool fog_height_enabled; + float fog_height_min; + float fog_height_max; + float fog_height_curve; + protected: static void _bind_methods(); virtual void _validate_property(PropertyInfo &property) const; @@ -307,6 +324,45 @@ public: void set_dof_blur_near_quality(DOFBlurQuality p_quality); DOFBlurQuality get_dof_blur_near_quality() const; + void set_fog_enabled(bool p_enabled); + bool is_fog_enabled() const; + + void set_fog_color(const Color &p_color); + Color get_fog_color() const; + + void set_fog_sun_color(const Color &p_color); + Color get_fog_sun_color() const; + + void set_fog_sun_amount(float p_amount); + float get_fog_sun_amount() const; + + void set_fog_depth_enabled(bool p_enabled); + bool is_fog_depth_enabled() const; + + void set_fog_depth_begin(float p_distance); + float get_fog_depth_begin() const; + + void set_fog_depth_curve(float p_curve); + float get_fog_depth_curve() const; + + void set_fog_transmit_enabled(bool p_enabled); + bool is_fog_transmit_enabled() const; + + void set_fog_transmit_curve(float p_curve); + float get_fog_transmit_curve() const; + + void set_fog_height_enabled(bool p_enabled); + bool is_fog_height_enabled() const; + + void set_fog_height_min(float p_distance); + float get_fog_height_min() const; + + void set_fog_height_max(float p_distance); + float get_fog_height_max() const; + + void set_fog_height_curve(float p_distance); + float get_fog_height_curve() const; + virtual RID get_rid() const; Environment(); diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 692dc47677..225a42f651 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -120,8 +120,8 @@ PoolVector<int> BitmapFont::_get_chars() const { const Character *c = char_map.getptr(*key); chars.push_back(*key); chars.push_back(c->texture_idx); - chars.push_back(c->rect.pos.x); - chars.push_back(c->rect.pos.y); + chars.push_back(c->rect.position.x); + chars.push_back(c->rect.position.y); chars.push_back(c->rect.size.x); chars.push_back(c->rect.size.y); @@ -272,9 +272,9 @@ Error BitmapFont::create_from_fnt(const String &p_string) { Rect2 rect; if (keys.has("x")) - rect.pos.x = keys["x"].to_int(); + rect.position.x = keys["x"].to_int(); if (keys.has("y")) - rect.pos.y = keys["y"].to_int(); + rect.position.y = keys["y"].to_int(); if (keys.has("width")) rect.size.width = keys["width"].to_int(); if (keys.has("height")) diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index d1713eb15c..ce88325539 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -181,7 +181,7 @@ void SpatialMaterial::init_shaders() { shader_names->albedo = "albedo"; shader_names->specular = "specular"; shader_names->roughness = "roughness"; - shader_names->metalness = "metalness"; + shader_names->metallic = "metallic"; shader_names->emission = "emission"; shader_names->emission_energy = "emission_energy"; shader_names->normal_scale = "normal_scale"; @@ -190,10 +190,9 @@ void SpatialMaterial::init_shaders() { shader_names->clearcoat = "clearcoat"; shader_names->clearcoat_gloss = "clearcoat_gloss"; shader_names->anisotropy = "anisotropy_ratio"; - shader_names->height_scale = "height_scale"; + shader_names->depth_scale = "depth_scale"; shader_names->subsurface_scattering_strength = "subsurface_scattering_strength"; shader_names->refraction = "refraction"; - shader_names->refraction_roughness = "refraction_roughness"; shader_names->point_size = "point_size"; shader_names->uv1_scale = "uv1_scale"; shader_names->uv1_offset = "uv1_offset"; @@ -203,19 +202,21 @@ void SpatialMaterial::init_shaders() { shader_names->particle_h_frames = "particle_h_frames"; shader_names->particle_v_frames = "particle_v_frames"; shader_names->particles_anim_loop = "particles_anim_loop"; + shader_names->depth_min_layers = "depth_min_layers"; + shader_names->depth_max_layers = "depth_max_layers"; shader_names->texture_names[TEXTURE_ALBEDO] = "texture_albedo"; - shader_names->texture_names[TEXTURE_SPECULAR] = "texture_specular"; + shader_names->texture_names[TEXTURE_METALLIC] = "texture_metallic"; + shader_names->texture_names[TEXTURE_ROUGHNESS] = "texture_roughness"; shader_names->texture_names[TEXTURE_EMISSION] = "texture_emission"; shader_names->texture_names[TEXTURE_NORMAL] = "texture_normal"; shader_names->texture_names[TEXTURE_RIM] = "texture_rim"; shader_names->texture_names[TEXTURE_CLEARCOAT] = "texture_clearcoat"; shader_names->texture_names[TEXTURE_FLOWMAP] = "texture_flowmap"; shader_names->texture_names[TEXTURE_AMBIENT_OCCLUSION] = "texture_ambient_occlusion"; - shader_names->texture_names[TEXTURE_HEIGHT] = "texture_height"; + shader_names->texture_names[TEXTURE_DEPTH] = "texture_depth"; shader_names->texture_names[TEXTURE_SUBSURFACE_SCATTERING] = "texture_subsurface_scattering"; shader_names->texture_names[TEXTURE_REFRACTION] = "texture_refraction"; - shader_names->texture_names[TEXTURE_REFRACTION_ROUGHNESS] = "texture_refraction_roughness"; shader_names->texture_names[TEXTURE_DETAIL_MASK] = "texture_detail_mask"; shader_names->texture_names[TEXTURE_DETAIL_ALBEDO] = "texture_detail_albedo"; shader_names->texture_names[TEXTURE_DETAIL_NORMAL] = "texture_detail_normal"; @@ -266,7 +267,12 @@ void SpatialMaterial::_update_shader() { case BLEND_MODE_MUL: code += "blend_mul"; break; } - switch (depth_draw_mode) { + DepthDrawMode ddm = depth_draw_mode; + if (features[FEATURE_REFRACTION]) { + ddm = DEPTH_DRAW_ALWAYS; + } + + switch (ddm) { case DEPTH_DRAW_OPAQUE_ONLY: code += ",depth_draw_opaque"; break; case DEPTH_DRAW_ALWAYS: code += ",depth_draw_always"; break; case DEPTH_DRAW_DISABLED: code += ",depth_draw_never"; break; @@ -278,6 +284,12 @@ void SpatialMaterial::_update_shader() { case CULL_FRONT: code += ",cull_front"; break; case CULL_DISABLED: code += ",cull_disabled"; break; } + switch (diffuse_mode) { + case DIFFUSE_LAMBERT: code += ",diffuse_lambert"; break; + case DIFFUSE_HALF_LAMBERT: code += ",diffuse_half_lambert"; break; + case DIFFUSE_OREN_NAYAR: code += ",diffuse_oren_nayar"; break; + case DIFFUSE_BURLEY: code += ",diffuse_burley"; break; + } if (flags[FLAG_UNSHADED]) { code += ",unshaded"; @@ -290,15 +302,13 @@ void SpatialMaterial::_update_shader() { code += "uniform vec4 albedo : hint_color;\n"; code += "uniform sampler2D texture_albedo : hint_albedo;\n"; - if (specular_mode == SPECULAR_MODE_SPECULAR) { - code += "uniform vec4 specular : hint_color;\n"; - } else { - code += "uniform float metalness;\n"; - } + code += "uniform float specular;\n"; + code += "uniform float metallic;\n"; code += "uniform float roughness : hint_range(0,1);\n"; code += "uniform float point_size : hint_range(0,128);\n"; - code += "uniform sampler2D texture_specular : hint_white;\n"; + code += "uniform sampler2D texture_metallic : hint_white;\n"; + code += "uniform sampler2D texture_roughness : hint_white;\n"; code += "uniform vec2 uv1_scale;\n"; code += "uniform vec2 uv1_offset;\n"; code += "uniform vec2 uv2_scale;\n"; @@ -316,6 +326,11 @@ void SpatialMaterial::_update_shader() { code += "uniform float emission_energy;\n"; } + if (features[FEATURE_REFRACTION]) { + code += "uniform sampler2D texture_refraction;\n"; + code += "uniform float refraction : hint_range(-16,16);\n"; + } + if (features[FEATURE_NORMAL_MAPPING]) { code += "uniform sampler2D texture_normal : hint_normal;\n"; code += "uniform float normal_scale : hint_range(-16,16);\n"; @@ -350,6 +365,13 @@ void SpatialMaterial::_update_shader() { code += "uniform sampler2D texture_subsurface_scattering : hint_white;\n"; } + if (features[FEATURE_DEPTH_MAPPING]) { + code += "uniform sampler2D texture_depth : hint_black;\n"; + code += "uniform float depth_scale;\n"; + code += "uniform int depth_min_layers;\n"; + code += "uniform int depth_max_layers;\n"; + } + code += "\n\n"; code += "void vertex() {\n"; @@ -423,10 +445,52 @@ void SpatialMaterial::_update_shader() { code += "\n\n"; code += "void fragment() {\n"; + code += "\tvec2 base_uv = UV;\n"; + if (features[FEATURE_DETAIL] && detail_uv == DETAIL_UV_2) { + code += "\tvec2 base_uv2 = UV2;\n"; + } + + if (features[FEATURE_DEPTH_MAPPING]) { + code += "\t{\n"; + code += "\t\tvec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT,BINORMAL,NORMAL));\n"; + + if (deep_parallax) { + code += "\t\tfloat num_layers = mix(float(depth_max_layers),float(depth_min_layers), abs(dot(vec3(0.0, 0.0, 1.0), view_dir)));\n"; + code += "\t\tfloat layer_depth = 1.0 / num_layers;\n"; + code += "\t\tfloat current_layer_depth = 0.0;\n"; + code += "\t\tvec2 P = view_dir.xy * depth_scale;\n"; + code += "\t\tvec2 delta = P / num_layers;\n"; + code += "\t\tvec2 ofs = base_uv;\n"; + code += "\t\tfloat depth = texture(texture_depth, ofs).r;\n"; + code += "\t\tfloat current_depth = 0.0;\n"; + code += "\t\twhile(current_depth < depth) {\n"; + code += "\t\t\tofs -= delta;\n"; + code += "\t\t\tdepth = texture(texture_depth, ofs).r;\n"; + code += "\t\t\tcurrent_depth += layer_depth;\n"; + code += "\t\t}\n"; + code += "\t\tvec2 prev_ofs = ofs + delta;\n"; + code += "\t\tfloat after_depth = depth - current_depth;\n"; + code += "\t\tfloat before_depth = texture(texture_depth, prev_ofs).r - current_depth + layer_depth;\n"; + code += "\t\tfloat weight = after_depth / (after_depth - before_depth);\n"; + code += "\t\tofs = mix(ofs,prev_ofs,weight);\n"; + + } else { + code += "\t\tfloat depth = texture(texture_depth, base_uv).r;\n"; + code += "\t\tvec2 ofs = base_uv - view_dir.xy / view_dir.z * (depth * depth_scale);\n"; + } + + code += "\t\tbase_uv=ofs;\n"; + if (features[FEATURE_DETAIL] && detail_uv == DETAIL_UV_2) { + code += "\t\tbase_uv2-=ofs;\n"; + } + + code += "\t}\n"; + } + if (flags[FLAG_USE_POINT_SIZE]) { code += "\tvec4 albedo_tex = texture(texture_albedo,POINT_COORD);\n"; } else { - code += "\tvec4 albedo_tex = texture(texture_albedo,UV);\n"; + code += "\tvec4 albedo_tex = texture(texture_albedo,base_uv);\n"; } if (flags[FLAG_ALBEDO_FROM_VERTEX_COLOR]) { @@ -434,52 +498,72 @@ void SpatialMaterial::_update_shader() { } code += "\tALBEDO = albedo.rgb * albedo_tex.rgb;\n"; - if (features[FEATURE_TRANSPARENT]) { - code += "\tALPHA = albedo.a * albedo_tex.a;\n"; + code += "\tfloat metallic_tex = texture(texture_metallic,base_uv).r;\n"; + code += "\tMETALLIC = metallic_tex * metallic;\n"; + code += "\tfloat roughness_tex = texture(texture_roughness,base_uv).r;\n"; + code += "\tROUGHNESS = roughness_tex * roughness;\n"; + code += "\tSPECULAR = specular;\n"; + + if (features[FEATURE_NORMAL_MAPPING]) { + code += "\tNORMALMAP = texture(texture_normal,base_uv).rgb;\n"; + code += "\tNORMALMAP_DEPTH = normal_scale;\n"; } if (features[FEATURE_EMISSION]) { - code += "\tEMISSION = (emission.rgb+texture(texture_emission,UV).rgb)*emission_energy;\n"; + code += "\tEMISSION = (emission.rgb+texture(texture_emission,base_uv).rgb)*emission_energy;\n"; } - if (features[FEATURE_NORMAL_MAPPING]) { - code += "\tNORMALMAP = texture(texture_normal,UV).rgb;\n"; - code += "\tNORMALMAP_DEPTH = normal_scale;\n"; + if (features[FEATURE_REFRACTION]) { + + if (features[FEATURE_NORMAL_MAPPING]) { + code += "\tvec3 ref_normal = normalize( mix(NORMAL,TANGENT * NORMALMAP.x + BINORMAL * NORMALMAP.y + NORMAL * NORMALMAP.z,NORMALMAP_DEPTH) ) * SIDE;\n"; + } else { + code += "\tvec3 ref_normal = NORMAL;\n"; + } + + code += "\tvec2 ref_ofs = SCREEN_UV - ref_normal.xy * texture(texture_refraction,base_uv).r * refraction;\n"; + code += "\tfloat ref_amount = 1.0 - albedo.a * albedo_tex.a;\n"; + code += "\tEMISSION += textureLod(SCREEN_TEXTURE,ref_ofs,ROUGHNESS * 8.0).rgb * ref_amount;\n"; + code += "\tALBEDO *= 1.0 - ref_amount;\n"; + code += "\tALPHA = 1.0;\n"; + + } else if (features[FEATURE_TRANSPARENT]) { + code += "\tALPHA = albedo.a * albedo_tex.a;\n"; } if (features[FEATURE_RIM]) { - code += "\tvec2 rim_tex = texture(texture_rim,UV).xw;\n"; + code += "\tvec2 rim_tex = texture(texture_rim,base_uv).xw;\n"; code += "\tRIM = rim*rim_tex.x;"; code += "\tRIM_TINT = rim_tint*rim_tex.y;\n"; } if (features[FEATURE_CLEARCOAT]) { - code += "\tvec2 clearcoat_tex = texture(texture_clearcoat,UV).xw;\n"; + code += "\tvec2 clearcoat_tex = texture(texture_clearcoat,base_uv).xw;\n"; code += "\tCLEARCOAT = clearcoat*clearcoat_tex.x;"; code += "\tCLEARCOAT_GLOSS = clearcoat_gloss*clearcoat_tex.y;\n"; } if (features[FEATURE_ANISOTROPY]) { - code += "\tvec4 anisotropy_tex = texture(texture_flowmap,UV);\n"; + code += "\tvec4 anisotropy_tex = texture(texture_flowmap,base_uv);\n"; code += "\tANISOTROPY = anisotropy_ratio*anisotropy_tex.a;\n"; code += "\tANISOTROPY_FLOW = anisotropy_tex.rg*2.0-1.0;\n"; } if (features[FEATURE_AMBIENT_OCCLUSION]) { - code += "\tAO = texture(texture_ambient_occlusion,UV).r;\n"; + code += "\tAO = texture(texture_ambient_occlusion,base_uv).r;\n"; } if (features[FEATURE_SUBSURACE_SCATTERING]) { - code += "\tfloat sss_tex = texture(texture_subsurface_scattering,UV).r;\n"; + code += "\tfloat sss_tex = texture(texture_subsurface_scattering,base_uv).r;\n"; code += "\tSSS_STRENGTH=subsurface_scattering_strength*sss_tex;\n"; } if (features[FEATURE_DETAIL]) { - String det_uv = detail_uv == DETAIL_UV_1 ? "UV" : "UV2"; + String det_uv = detail_uv == DETAIL_UV_1 ? "base_uv" : "base_uv2"; code += "\tvec4 detail_tex = texture(texture_detail_albedo," + det_uv + ");\n"; code += "\tvec4 detail_norm_tex = texture(texture_detail_normal," + det_uv + ");\n"; - code += "\tvec4 detail_mask_tex = texture(texture_detail_mask,UV);\n"; + code += "\tvec4 detail_mask_tex = texture(texture_detail_mask,base_uv);\n"; switch (detail_blend_mode) { case BLEND_MODE_MIX: { @@ -502,17 +586,6 @@ void SpatialMaterial::_update_shader() { code += "\tALBEDO.rgb = mix(ALBEDO.rgb,detail,detail_mask_tex.r);\n"; } - if (specular_mode == SPECULAR_MODE_SPECULAR) { - - code += "\tvec4 specular_tex = texture(texture_specular,UV);\n"; - code += "\tSPECULAR = specular.rgb * specular_tex.rgb;\n"; - code += "\tROUGHNESS = specular_tex.a * roughness;\n"; - } else { - code += "\tvec4 specular_tex = texture(texture_specular,UV);\n"; - code += "\tSPECULAR = vec3(ALBEDO.rgb * metalness * specular_tex.r);\n"; - code += "\tROUGHNESS = specular_tex.g * roughness;\n"; - } - code += "}\n"; ShaderData shader_data; @@ -579,23 +652,13 @@ Color SpatialMaterial::get_albedo() const { return albedo; } -void SpatialMaterial::set_specular_mode(SpecularMode p_mode) { - specular_mode = p_mode; - _change_notify(); - _queue_shader_change(); -} - -SpatialMaterial::SpecularMode SpatialMaterial::get_specular_mode() const { - - return specular_mode; -} - -void SpatialMaterial::set_specular(const Color &p_specular) { +void SpatialMaterial::set_specular(float p_specular) { specular = p_specular; VS::get_singleton()->material_set_param(_get_material(), shader_names->specular, p_specular); } -Color SpatialMaterial::get_specular() const { + +float SpatialMaterial::get_specular() const { return specular; } @@ -611,15 +674,15 @@ float SpatialMaterial::get_roughness() const { return roughness; } -void SpatialMaterial::set_metalness(float p_metalness) { +void SpatialMaterial::set_metallic(float p_metallic) { - metalness = p_metalness; - VS::get_singleton()->material_set_param(_get_material(), shader_names->metalness, p_metalness); + metallic = p_metallic; + VS::get_singleton()->material_set_param(_get_material(), shader_names->metallic, p_metallic); } -float SpatialMaterial::get_metalness() const { +float SpatialMaterial::get_metallic() const { - return metalness; + return metallic; } void SpatialMaterial::set_emission(const Color &p_emission) { @@ -704,15 +767,15 @@ float SpatialMaterial::get_anisotropy() const { return anisotropy; } -void SpatialMaterial::set_height_scale(float p_height_scale) { +void SpatialMaterial::set_depth_scale(float p_depth_scale) { - height_scale = p_height_scale; - VS::get_singleton()->material_set_param(_get_material(), shader_names->height_scale, p_height_scale); + depth_scale = p_depth_scale; + VS::get_singleton()->material_set_param(_get_material(), shader_names->depth_scale, p_depth_scale); } -float SpatialMaterial::get_height_scale() const { +float SpatialMaterial::get_depth_scale() const { - return height_scale; + return depth_scale; } void SpatialMaterial::set_subsurface_scattering_strength(float p_subsurface_scattering_strength) { @@ -737,16 +800,6 @@ float SpatialMaterial::get_refraction() const { return refraction; } -void SpatialMaterial::set_refraction_roughness(float p_refraction_roughness) { - - refraction_roughness = p_refraction_roughness; - VS::get_singleton()->material_set_param(_get_material(), shader_names->refraction_roughness, refraction_roughness); -} -float SpatialMaterial::get_refraction_roughness() const { - - return refraction_roughness; -} - void SpatialMaterial::set_detail_uv(DetailUV p_detail_uv) { if (detail_uv == p_detail_uv) @@ -874,6 +927,9 @@ void SpatialMaterial::_validate_feature(const String &text, Feature feature, Pro if (property.name.begins_with(text) && property.name != text + "_enabled" && !features[feature]) { property.usage = 0; } + if ((property.name == "depth_min_layers" || property.name == "depth_max_layers") && !deep_parallax) { + property.usage = 0; + } } void SpatialMaterial::_validate_property(PropertyInfo &property) const { @@ -883,18 +939,11 @@ void SpatialMaterial::_validate_property(PropertyInfo &property) const { _validate_feature("clearcoat", FEATURE_CLEARCOAT, property); _validate_feature("anisotropy", FEATURE_ANISOTROPY, property); _validate_feature("ao", FEATURE_AMBIENT_OCCLUSION, property); - _validate_feature("height", FEATURE_HEIGHT_MAPPING, property); + _validate_feature("depth", FEATURE_DEPTH_MAPPING, property); _validate_feature("subsurf_scatter", FEATURE_SUBSURACE_SCATTERING, property); _validate_feature("refraction", FEATURE_REFRACTION, property); _validate_feature("detail", FEATURE_DETAIL, property); - if (property.name == "specular_color" && specular_mode == SPECULAR_MODE_METALLIC) { - property.usage = 0; - } - if (property.name == "specular_metalness" && specular_mode == SPECULAR_MODE_SPECULAR) { - property.usage = 0; - } - if (property.name.begins_with("particles_anim_") && billboard_mode != BILLBOARD_PARTICLES) { property.usage = 0; } @@ -1009,19 +1058,49 @@ int SpatialMaterial::get_particles_anim_loop() const { return particles_anim_loop; } +void SpatialMaterial::set_depth_deep_parallax(bool p_enable) { + + deep_parallax = p_enable; + _queue_shader_change(); + _change_notify(); + ; +} + +bool SpatialMaterial::is_depth_deep_parallax_enabled() const { + + return deep_parallax; +} + +void SpatialMaterial::set_depth_deep_parallax_min_layers(int p_layer) { + + deep_parallax_min_layers = p_layer; + VS::get_singleton()->material_set_param(_get_material(), shader_names->depth_min_layers, p_layer); +} +int SpatialMaterial::get_depth_deep_parallax_min_layers() const { + + return deep_parallax_min_layers; +} + +void SpatialMaterial::set_depth_deep_parallax_max_layers(int p_layer) { + + deep_parallax_max_layers = p_layer; + VS::get_singleton()->material_set_param(_get_material(), shader_names->depth_max_layers, p_layer); +} +int SpatialMaterial::get_depth_deep_parallax_max_layers() const { + + return deep_parallax_max_layers; +} + void SpatialMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_albedo", "albedo"), &SpatialMaterial::set_albedo); ClassDB::bind_method(D_METHOD("get_albedo"), &SpatialMaterial::get_albedo); - ClassDB::bind_method(D_METHOD("set_specular_mode", "specular_mode"), &SpatialMaterial::set_specular_mode); - ClassDB::bind_method(D_METHOD("get_specular_mode"), &SpatialMaterial::get_specular_mode); - ClassDB::bind_method(D_METHOD("set_specular", "specular"), &SpatialMaterial::set_specular); ClassDB::bind_method(D_METHOD("get_specular"), &SpatialMaterial::get_specular); - ClassDB::bind_method(D_METHOD("set_metalness", "metalness"), &SpatialMaterial::set_metalness); - ClassDB::bind_method(D_METHOD("get_metalness"), &SpatialMaterial::get_metalness); + ClassDB::bind_method(D_METHOD("set_metallic", "metallic"), &SpatialMaterial::set_metallic); + ClassDB::bind_method(D_METHOD("get_metallic"), &SpatialMaterial::get_metallic); ClassDB::bind_method(D_METHOD("set_roughness", "roughness"), &SpatialMaterial::set_roughness); ClassDB::bind_method(D_METHOD("get_roughness"), &SpatialMaterial::get_roughness); @@ -1050,8 +1129,8 @@ void SpatialMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_anisotropy", "anisotropy"), &SpatialMaterial::set_anisotropy); ClassDB::bind_method(D_METHOD("get_anisotropy"), &SpatialMaterial::get_anisotropy); - ClassDB::bind_method(D_METHOD("set_height_scale", "height_scale"), &SpatialMaterial::set_height_scale); - ClassDB::bind_method(D_METHOD("get_height_scale"), &SpatialMaterial::get_height_scale); + ClassDB::bind_method(D_METHOD("set_depth_scale", "depth_scale"), &SpatialMaterial::set_depth_scale); + ClassDB::bind_method(D_METHOD("get_depth_scale"), &SpatialMaterial::get_depth_scale); ClassDB::bind_method(D_METHOD("set_subsurface_scattering_strength", "strength"), &SpatialMaterial::set_subsurface_scattering_strength); ClassDB::bind_method(D_METHOD("get_subsurface_scattering_strength"), &SpatialMaterial::get_subsurface_scattering_strength); @@ -1059,9 +1138,6 @@ void SpatialMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_refraction", "refraction"), &SpatialMaterial::set_refraction); ClassDB::bind_method(D_METHOD("get_refraction"), &SpatialMaterial::get_refraction); - ClassDB::bind_method(D_METHOD("set_refraction_roughness", "refraction_roughness"), &SpatialMaterial::set_refraction_roughness); - ClassDB::bind_method(D_METHOD("get_refraction_roughness"), &SpatialMaterial::get_refraction_roughness); - ClassDB::bind_method(D_METHOD("set_line_width", "line_width"), &SpatialMaterial::set_line_width); ClassDB::bind_method(D_METHOD("get_line_width"), &SpatialMaterial::get_line_width); @@ -1119,6 +1195,15 @@ void SpatialMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_particles_anim_loop", "frames"), &SpatialMaterial::set_particles_anim_loop); ClassDB::bind_method(D_METHOD("get_particles_anim_loop"), &SpatialMaterial::get_particles_anim_loop); + ClassDB::bind_method(D_METHOD("set_depth_deep_parallax", "enable"), &SpatialMaterial::set_depth_deep_parallax); + ClassDB::bind_method(D_METHOD("is_depth_deep_parallax_enabled"), &SpatialMaterial::is_depth_deep_parallax_enabled); + + ClassDB::bind_method(D_METHOD("set_depth_deep_parallax_min_layers", "layer"), &SpatialMaterial::set_depth_deep_parallax_min_layers); + ClassDB::bind_method(D_METHOD("get_depth_deep_parallax_min_layers"), &SpatialMaterial::get_depth_deep_parallax_min_layers); + + ClassDB::bind_method(D_METHOD("set_depth_deep_parallax_max_layers", "layer"), &SpatialMaterial::set_depth_deep_parallax_max_layers); + ClassDB::bind_method(D_METHOD("get_depth_deep_parallax_max_layers"), &SpatialMaterial::get_depth_deep_parallax_max_layers); + ADD_GROUP("Flags", "flags_"); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_transparent"), "set_feature", "get_feature", FEATURE_TRANSPARENT); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_unshaded"), "set_flag", "get_flag", FLAG_UNSHADED); @@ -1146,12 +1231,14 @@ void SpatialMaterial::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::COLOR, "albedo_color"), "set_albedo", "get_albedo"); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "albedo_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_ALBEDO); - ADD_GROUP("Specular", "specular_"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "specular_mode", PROPERTY_HINT_ENUM, "Metallic,Specular"), "set_specular_mode", "get_specular_mode"); - ADD_PROPERTY(PropertyInfo(Variant::COLOR, "specular_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_specular", "get_specular"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "specular_metalness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_metalness", "get_metalness"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "specular_roughness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_roughness", "get_roughness"); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "specular_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_SPECULAR); + ADD_GROUP("Metallic", "metallic_"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "metallic_amount", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_metallic", "get_metallic"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "metallic_specular", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_specular", "get_specular"); + ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "metallic_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_METALLIC); + + ADD_GROUP("Roughness", "roughness_"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "roughness_amount", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_roughness", "get_roughness"); + ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "roughness_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_ROUGHNESS); ADD_GROUP("Emission", "emission_"); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "emission_enabled"), "set_feature", "get_feature", FEATURE_EMISSION); @@ -1185,10 +1272,13 @@ void SpatialMaterial::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "ao_enabled"), "set_feature", "get_feature", FEATURE_AMBIENT_OCCLUSION); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "ao_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_AMBIENT_OCCLUSION); - ADD_GROUP("Height", "height_"); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "height_enabled"), "set_feature", "get_feature", FEATURE_HEIGHT_MAPPING); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "height_scale", PROPERTY_HINT_RANGE, "-16,16,0.01"), "set_height_scale", "get_height_scale"); - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "height_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_HEIGHT); + ADD_GROUP("Depth", "depth_"); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "depth_enabled"), "set_feature", "get_feature", FEATURE_DEPTH_MAPPING); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "depth_scale", PROPERTY_HINT_RANGE, "-16,16,0.01"), "set_depth_scale", "get_depth_scale"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "depth_deep_parallax"), "set_depth_deep_parallax", "is_depth_deep_parallax_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "depth_min_layers", PROPERTY_HINT_RANGE, "1,32,1"), "set_depth_deep_parallax_min_layers", "get_depth_deep_parallax_min_layers"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "depth_max_layers", PROPERTY_HINT_RANGE, "1,32,1"), "set_depth_deep_parallax_max_layers", "get_depth_deep_parallax_max_layers"); + ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "depth_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_DEPTH); ADD_GROUP("Subsurf Scatter", "subsurf_scatter_"); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "subsurf_scatter_enabled"), "set_feature", "get_feature", FEATURE_SUBSURACE_SCATTERING); @@ -1197,8 +1287,7 @@ void SpatialMaterial::_bind_methods() { ADD_GROUP("Refraction", "refraction_"); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "refraction_enabled"), "set_feature", "get_feature", FEATURE_REFRACTION); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "refraction_displacement", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_refraction", "get_refraction"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "refraction_roughness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_refraction_roughness", "get_refraction_roughness"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "refraction_scale", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_refraction", "get_refraction"); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "refraction_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_REFRACTION); ADD_GROUP("Detail", "detail_"); @@ -1218,17 +1307,17 @@ void SpatialMaterial::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "uv2_offset"), "set_uv2_offset", "get_uv2_offset"); BIND_CONSTANT(TEXTURE_ALBEDO); - BIND_CONSTANT(TEXTURE_SPECULAR); + BIND_CONSTANT(TEXTURE_METALLIC); + BIND_CONSTANT(TEXTURE_ROUGHNESS); BIND_CONSTANT(TEXTURE_EMISSION); BIND_CONSTANT(TEXTURE_NORMAL); BIND_CONSTANT(TEXTURE_RIM); BIND_CONSTANT(TEXTURE_CLEARCOAT); BIND_CONSTANT(TEXTURE_FLOWMAP); BIND_CONSTANT(TEXTURE_AMBIENT_OCCLUSION); - BIND_CONSTANT(TEXTURE_HEIGHT); + BIND_CONSTANT(TEXTURE_DEPTH); BIND_CONSTANT(TEXTURE_SUBSURFACE_SCATTERING); BIND_CONSTANT(TEXTURE_REFRACTION); - BIND_CONSTANT(TEXTURE_REFRACTION_ROUGHNESS); BIND_CONSTANT(TEXTURE_DETAIL_MASK); BIND_CONSTANT(TEXTURE_DETAIL_ALBEDO); BIND_CONSTANT(TEXTURE_DETAIL_NORMAL); @@ -1244,7 +1333,7 @@ void SpatialMaterial::_bind_methods() { BIND_CONSTANT(FEATURE_CLEARCOAT); BIND_CONSTANT(FEATURE_ANISOTROPY); BIND_CONSTANT(FEATURE_AMBIENT_OCCLUSION); - BIND_CONSTANT(FEATURE_HEIGHT_MAPPING); + BIND_CONSTANT(FEATURE_DEPTH_MAPPING); BIND_CONSTANT(FEATURE_SUBSURACE_SCATTERING); BIND_CONSTANT(FEATURE_REFRACTION); BIND_CONSTANT(FEATURE_DETAIL); @@ -1273,13 +1362,10 @@ void SpatialMaterial::_bind_methods() { BIND_CONSTANT(FLAG_MAX); BIND_CONSTANT(DIFFUSE_LAMBERT); - BIND_CONSTANT(DIFFUSE_LAMBERT_WRAP); + BIND_CONSTANT(DIFFUSE_HALF_LAMBERT); BIND_CONSTANT(DIFFUSE_OREN_NAYAR); BIND_CONSTANT(DIFFUSE_BURLEY); - BIND_CONSTANT(SPECULAR_MODE_METALLIC); - BIND_CONSTANT(SPECULAR_MODE_SPECULAR); - BIND_CONSTANT(BILLBOARD_DISABLED); BIND_CONSTANT(BILLBOARD_ENABLED); BIND_CONSTANT(BILLBOARD_FIXED_Y); @@ -1290,11 +1376,10 @@ SpatialMaterial::SpatialMaterial() : element(this) { //initialize to right values - specular_mode = SPECULAR_MODE_METALLIC; set_albedo(Color(0.7, 0.7, 0.7, 1.0)); - set_specular(Color(0.1, 0.1, 0.1)); + set_specular(0.5); set_roughness(0.0); - set_metalness(0.1); + set_metallic(0.1); set_emission(Color(0, 0, 0)); set_emission_energy(1.0); set_normal_scale(1); @@ -1303,10 +1388,9 @@ SpatialMaterial::SpatialMaterial() set_clearcoat(1); set_clearcoat_gloss(0.5); set_anisotropy(0); - set_height_scale(1); + set_depth_scale(0.05); set_subsurface_scattering_strength(0); - set_refraction(0); - set_refraction_roughness(0); + set_refraction(0.05); set_line_width(1); set_point_size(1); set_uv1_offset(Vector2(0, 0)); @@ -1318,6 +1402,10 @@ SpatialMaterial::SpatialMaterial() set_particles_anim_v_frames(1); set_particles_anim_loop(false); + deep_parallax = false; + set_depth_deep_parallax_min_layers(8); + set_depth_deep_parallax_max_layers(32); + detail_uv = DETAIL_UV_1; blend_mode = BLEND_MODE_MIX; detail_blend_mode = BLEND_MODE_MIX; diff --git a/scene/resources/material.h b/scene/resources/material.h index 408815d756..b6e85c8332 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -89,17 +89,17 @@ class SpatialMaterial : public Material { public: enum TextureParam { TEXTURE_ALBEDO, - TEXTURE_SPECULAR, + TEXTURE_METALLIC, + TEXTURE_ROUGHNESS, TEXTURE_EMISSION, TEXTURE_NORMAL, TEXTURE_RIM, TEXTURE_CLEARCOAT, TEXTURE_FLOWMAP, TEXTURE_AMBIENT_OCCLUSION, - TEXTURE_HEIGHT, + TEXTURE_DEPTH, TEXTURE_SUBSURFACE_SCATTERING, TEXTURE_REFRACTION, - TEXTURE_REFRACTION_ROUGHNESS, TEXTURE_DETAIL_MASK, TEXTURE_DETAIL_ALBEDO, TEXTURE_DETAIL_NORMAL, @@ -120,7 +120,7 @@ public: FEATURE_CLEARCOAT, FEATURE_ANISOTROPY, FEATURE_AMBIENT_OCCLUSION, - FEATURE_HEIGHT_MAPPING, + FEATURE_DEPTH_MAPPING, FEATURE_SUBSURACE_SCATTERING, FEATURE_REFRACTION, FEATURE_DETAIL, @@ -160,16 +160,11 @@ public: enum DiffuseMode { DIFFUSE_LAMBERT, - DIFFUSE_LAMBERT_WRAP, + DIFFUSE_HALF_LAMBERT, DIFFUSE_OREN_NAYAR, DIFFUSE_BURLEY, }; - enum SpecularMode { - SPECULAR_MODE_METALLIC, - SPECULAR_MODE_SPECULAR, - }; - enum BillboardMode { BILLBOARD_DISABLED, BILLBOARD_ENABLED, @@ -190,7 +185,7 @@ private: uint32_t detail_blend_mode : 2; uint32_t diffuse_mode : 2; uint32_t invalid_key : 1; - uint32_t specular_mode : 1; + uint32_t deep_parallax : 1; uint32_t billboard_mode : 2; }; @@ -230,8 +225,9 @@ private: } mk.detail_blend_mode = detail_blend_mode; mk.diffuse_mode = diffuse_mode; - mk.specular_mode = specular_mode; mk.billboard_mode = billboard_mode; + mk.deep_parallax = deep_parallax ? 1 : 0; + ; return mk; } @@ -239,7 +235,7 @@ private: struct ShaderNames { StringName albedo; StringName specular; - StringName metalness; + StringName metallic; StringName roughness; StringName emission; StringName emission_energy; @@ -249,10 +245,9 @@ private: StringName clearcoat; StringName clearcoat_gloss; StringName anisotropy; - StringName height_scale; + StringName depth_scale; StringName subsurface_scattering_strength; StringName refraction; - StringName refraction_roughness; StringName point_size; StringName uv1_scale; StringName uv1_offset; @@ -261,6 +256,9 @@ private: StringName particle_h_frames; StringName particle_v_frames; StringName particles_anim_loop; + StringName depth_min_layers; + StringName depth_max_layers; + StringName texture_names[TEXTURE_MAX]; }; @@ -275,8 +273,8 @@ private: _FORCE_INLINE_ bool _is_shader_dirty() const; Color albedo; - Color specular; - float metalness; + float specular; + float metallic; float roughness; Color emission; float emission_energy; @@ -286,10 +284,9 @@ private: float clearcoat; float clearcoat_gloss; float anisotropy; - float height_scale; + float depth_scale; float subsurface_scattering_strength; float refraction; - float refraction_roughness; float line_width; float point_size; int particles_anim_h_frames; @@ -304,13 +301,16 @@ private: DetailUV detail_uv; + bool deep_parallax; + int deep_parallax_min_layers; + int deep_parallax_max_layers; + BlendMode blend_mode; BlendMode detail_blend_mode; DepthDrawMode depth_draw_mode; CullMode cull_mode; bool flags[FLAG_MAX]; DiffuseMode diffuse_mode; - SpecularMode specular_mode; BillboardMode billboard_mode; bool features[FEATURE_MAX]; @@ -327,14 +327,11 @@ public: void set_albedo(const Color &p_albedo); Color get_albedo() const; - void set_specular_mode(SpecularMode p_mode); - SpecularMode get_specular_mode() const; - - void set_specular(const Color &p_specular); - Color get_specular() const; + void set_specular(float p_specular); + float get_specular() const; - void set_metalness(float p_metalness); - float get_metalness() const; + void set_metallic(float p_metallic); + float get_metallic() const; void set_roughness(float p_roughness); float get_roughness() const; @@ -363,8 +360,17 @@ public: void set_anisotropy(float p_anisotropy); float get_anisotropy() const; - void set_height_scale(float p_height_scale); - float get_height_scale() const; + void set_depth_scale(float p_depth_scale); + float get_depth_scale() const; + + void set_depth_deep_parallax(bool p_enable); + bool is_depth_deep_parallax_enabled() const; + + void set_depth_deep_parallax_min_layers(int p_layer); + int get_depth_deep_parallax_min_layers() const; + + void set_depth_deep_parallax_max_layers(int p_layer); + int get_depth_deep_parallax_max_layers() const; void set_subsurface_scattering_strength(float p_strength); float get_subsurface_scattering_strength() const; @@ -372,9 +378,6 @@ public: void set_refraction(float p_refraction); float get_refraction() const; - void set_refraction_roughness(float p_refraction_roughness); - float get_refraction_roughness() const; - void set_line_width(float p_line_width); float get_line_width() const; @@ -447,7 +450,6 @@ VARIANT_ENUM_CAST(SpatialMaterial::DepthDrawMode) VARIANT_ENUM_CAST(SpatialMaterial::CullMode) VARIANT_ENUM_CAST(SpatialMaterial::Flags) VARIANT_ENUM_CAST(SpatialMaterial::DiffuseMode) -VARIANT_ENUM_CAST(SpatialMaterial::SpecularMode) VARIANT_ENUM_CAST(SpatialMaterial::BillboardMode) ////////////////////// diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 4846d84b33..e2ede41290 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -32,6 +32,390 @@ #include "scene/resources/convex_polygon_shape.h" #include "surface_tool.h" +void Mesh::_clear_triangle_mesh() { + + triangle_mesh.unref(); + ; +} + +Ref<TriangleMesh> Mesh::generate_triangle_mesh() const { + + if (triangle_mesh.is_valid()) + return triangle_mesh; + + int facecount = 0; + + for (int i = 0; i < get_surface_count(); i++) { + + if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES) + continue; + + if (surface_get_format(i) & ARRAY_FORMAT_INDEX) { + + facecount += surface_get_array_index_len(i); + } else { + + facecount += surface_get_array_len(i); + } + } + + if (facecount == 0 || (facecount % 3) != 0) + return triangle_mesh; + + PoolVector<Vector3> faces; + faces.resize(facecount); + PoolVector<Vector3>::Write facesw = faces.write(); + + int widx = 0; + + for (int i = 0; i < get_surface_count(); i++) { + + if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES) + continue; + + Array a = surface_get_arrays(i); + + int vc = surface_get_array_len(i); + PoolVector<Vector3> vertices = a[ARRAY_VERTEX]; + PoolVector<Vector3>::Read vr = vertices.read(); + + if (surface_get_format(i) & ARRAY_FORMAT_INDEX) { + + int ic = surface_get_array_index_len(i); + PoolVector<int> indices = a[ARRAY_INDEX]; + PoolVector<int>::Read ir = indices.read(); + + for (int i = 0; i < ic; i++) { + int index = ir[i]; + facesw[widx++] = vr[index]; + } + + } else { + + for (int i = 0; i < vc; i++) + facesw[widx++] = vr[i]; + } + } + + facesw = PoolVector<Vector3>::Write(); + + triangle_mesh = Ref<TriangleMesh>(memnew(TriangleMesh)); + triangle_mesh->create(faces); + + return triangle_mesh; +} + +PoolVector<Face3> Mesh::get_faces() const { + + Ref<TriangleMesh> tm = generate_triangle_mesh(); + if (tm.is_valid()) + return tm->get_faces(); + return PoolVector<Face3>(); + /* + for (int i=0;i<surfaces.size();i++) { + + if (VisualServer::get_singleton()->mesh_surface_get_primitive_type( mesh, i ) != VisualServer::PRIMITIVE_TRIANGLES ) + continue; + + PoolVector<int> indices; + PoolVector<Vector3> vertices; + + vertices=VisualServer::get_singleton()->mesh_surface_get_array(mesh, i,VisualServer::ARRAY_VERTEX); + + int len=VisualServer::get_singleton()->mesh_surface_get_array_index_len(mesh, i); + bool has_indices; + + if (len>0) { + + indices=VisualServer::get_singleton()->mesh_surface_get_array(mesh, i,VisualServer::ARRAY_INDEX); + has_indices=true; + + } else { + + len=vertices.size(); + has_indices=false; + } + + if (len<=0) + continue; + + PoolVector<int>::Read indicesr = indices.read(); + const int *indicesptr = indicesr.ptr(); + + PoolVector<Vector3>::Read verticesr = vertices.read(); + const Vector3 *verticesptr = verticesr.ptr(); + + int old_faces=faces.size(); + int new_faces=old_faces+(len/3); + + faces.resize(new_faces); + + PoolVector<Face3>::Write facesw = faces.write(); + Face3 *facesptr=facesw.ptr(); + + + for (int i=0;i<len/3;i++) { + + Face3 face; + + for (int j=0;j<3;j++) { + + int idx=i*3+j; + face.vertex[j] = has_indices ? verticesptr[ indicesptr[ idx ] ] : verticesptr[idx]; + } + + facesptr[i+old_faces]=face; + } + + } +*/ +} + +Ref<Shape> Mesh::create_convex_shape() const { + + PoolVector<Vector3> vertices; + + for (int i = 0; i < get_surface_count(); i++) { + + Array a = surface_get_arrays(i); + PoolVector<Vector3> v = a[ARRAY_VERTEX]; + vertices.append_array(v); + } + + Ref<ConvexPolygonShape> shape = memnew(ConvexPolygonShape); + shape->set_points(vertices); + return shape; +} + +Ref<Shape> Mesh::create_trimesh_shape() const { + + PoolVector<Face3> faces = get_faces(); + if (faces.size() == 0) + return Ref<Shape>(); + + PoolVector<Vector3> face_points; + face_points.resize(faces.size() * 3); + + for (int i = 0; i < face_points.size(); i++) { + + Face3 f = faces.get(i / 3); + face_points.set(i, f.vertex[i % 3]); + } + + Ref<ConcavePolygonShape> shape = memnew(ConcavePolygonShape); + shape->set_faces(face_points); + return shape; +} + +Ref<Mesh> Mesh::create_outline(float p_margin) const { + + Array arrays; + int index_accum = 0; + for (int i = 0; i < get_surface_count(); i++) { + + if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES) + continue; + + Array a = surface_get_arrays(i); + int vcount = 0; + + if (i == 0) { + arrays = a; + PoolVector<Vector3> v = a[ARRAY_VERTEX]; + index_accum += v.size(); + } else { + + for (int j = 0; j < arrays.size(); j++) { + + if (arrays[j].get_type() == Variant::NIL || a[j].get_type() == Variant::NIL) { + //mismatch, do not use + arrays[j] = Variant(); + continue; + } + + switch (j) { + + case ARRAY_VERTEX: + case ARRAY_NORMAL: { + + PoolVector<Vector3> dst = arrays[j]; + PoolVector<Vector3> src = a[j]; + if (j == ARRAY_VERTEX) + vcount = src.size(); + if (dst.size() == 0 || src.size() == 0) { + arrays[j] = Variant(); + continue; + } + dst.append_array(src); + arrays[j] = dst; + } break; + case ARRAY_TANGENT: + case ARRAY_BONES: + case ARRAY_WEIGHTS: { + + PoolVector<real_t> dst = arrays[j]; + PoolVector<real_t> src = a[j]; + if (dst.size() == 0 || src.size() == 0) { + arrays[j] = Variant(); + continue; + } + dst.append_array(src); + arrays[j] = dst; + + } break; + case ARRAY_COLOR: { + PoolVector<Color> dst = arrays[j]; + PoolVector<Color> src = a[j]; + if (dst.size() == 0 || src.size() == 0) { + arrays[j] = Variant(); + continue; + } + dst.append_array(src); + arrays[j] = dst; + + } break; + case ARRAY_TEX_UV: + case ARRAY_TEX_UV2: { + PoolVector<Vector2> dst = arrays[j]; + PoolVector<Vector2> src = a[j]; + if (dst.size() == 0 || src.size() == 0) { + arrays[j] = Variant(); + continue; + } + dst.append_array(src); + arrays[j] = dst; + + } break; + case ARRAY_INDEX: { + PoolVector<int> dst = arrays[j]; + PoolVector<int> src = a[j]; + if (dst.size() == 0 || src.size() == 0) { + arrays[j] = Variant(); + continue; + } + { + int ss = src.size(); + PoolVector<int>::Write w = src.write(); + for (int k = 0; k < ss; k++) { + w[k] += index_accum; + } + } + dst.append_array(src); + arrays[j] = dst; + index_accum += vcount; + + } break; + } + } + } + } + + { + PoolVector<int>::Write ir; + PoolVector<int> indices = arrays[ARRAY_INDEX]; + bool has_indices = false; + PoolVector<Vector3> vertices = arrays[ARRAY_VERTEX]; + int vc = vertices.size(); + ERR_FAIL_COND_V(!vc, Ref<ArrayMesh>()); + PoolVector<Vector3>::Write r = vertices.write(); + + if (indices.size()) { + vc = indices.size(); + ir = indices.write(); + has_indices = true; + } + + Map<Vector3, Vector3> normal_accum; + + //fill normals with triangle normals + for (int i = 0; i < vc; i += 3) { + + Vector3 t[3]; + + if (has_indices) { + t[0] = r[ir[i + 0]]; + t[1] = r[ir[i + 1]]; + t[2] = r[ir[i + 2]]; + } else { + t[0] = r[i + 0]; + t[1] = r[i + 1]; + t[2] = r[i + 2]; + } + + Vector3 n = Plane(t[0], t[1], t[2]).normal; + + for (int j = 0; j < 3; j++) { + + Map<Vector3, Vector3>::Element *E = normal_accum.find(t[j]); + if (!E) { + normal_accum[t[j]] = n; + } else { + float d = n.dot(E->get()); + if (d < 1.0) + E->get() += n * (1.0 - d); + //E->get()+=n; + } + } + } + + //normalize + + for (Map<Vector3, Vector3>::Element *E = normal_accum.front(); E; E = E->next()) { + E->get().normalize(); + } + + //displace normals + int vc2 = vertices.size(); + + for (int i = 0; i < vc2; i++) { + + Vector3 t = r[i]; + + Map<Vector3, Vector3>::Element *E = normal_accum.find(t); + ERR_CONTINUE(!E); + + t += E->get() * p_margin; + r[i] = t; + } + + r = PoolVector<Vector3>::Write(); + arrays[ARRAY_VERTEX] = vertices; + + if (!has_indices) { + + PoolVector<int> new_indices; + new_indices.resize(vertices.size()); + PoolVector<int>::Write iw = new_indices.write(); + + for (int j = 0; j < vc2; j += 3) { + + iw[j] = j; + iw[j + 1] = j + 2; + iw[j + 2] = j + 1; + } + + iw = PoolVector<int>::Write(); + arrays[ARRAY_INDEX] = new_indices; + + } else { + + for (int j = 0; j < vc; j += 3) { + + SWAP(ir[j + 1], ir[j + 2]); + } + ir = PoolVector<int>::Write(); + arrays[ARRAY_INDEX] = indices; + } + } + + Ref<ArrayMesh> newmesh = memnew(ArrayMesh); + newmesh->add_surface_from_arrays(PRIMITIVE_TRIANGLES, arrays); + return newmesh; +} + +Mesh::Mesh() { +} + static const char *_array_name[] = { "vertex_array", "normal_array", @@ -45,34 +429,34 @@ static const char *_array_name[] = { NULL }; -static const Mesh::ArrayType _array_types[] = { - - Mesh::ARRAY_VERTEX, - Mesh::ARRAY_NORMAL, - Mesh::ARRAY_TANGENT, - Mesh::ARRAY_COLOR, - Mesh::ARRAY_TEX_UV, - Mesh::ARRAY_TEX_UV2, - Mesh::ARRAY_BONES, - Mesh::ARRAY_WEIGHTS, - Mesh::ARRAY_INDEX +static const ArrayMesh::ArrayType _array_types[] = { + + ArrayMesh::ARRAY_VERTEX, + ArrayMesh::ARRAY_NORMAL, + ArrayMesh::ARRAY_TANGENT, + ArrayMesh::ARRAY_COLOR, + ArrayMesh::ARRAY_TEX_UV, + ArrayMesh::ARRAY_TEX_UV2, + ArrayMesh::ARRAY_BONES, + ArrayMesh::ARRAY_WEIGHTS, + ArrayMesh::ARRAY_INDEX }; /* compatibility */ static const int _format_translate[] = { - Mesh::ARRAY_FORMAT_VERTEX, - Mesh::ARRAY_FORMAT_NORMAL, - Mesh::ARRAY_FORMAT_TANGENT, - Mesh::ARRAY_FORMAT_COLOR, - Mesh::ARRAY_FORMAT_TEX_UV, - Mesh::ARRAY_FORMAT_TEX_UV2, - Mesh::ARRAY_FORMAT_BONES, - Mesh::ARRAY_FORMAT_WEIGHTS, - Mesh::ARRAY_FORMAT_INDEX, + ArrayMesh::ARRAY_FORMAT_VERTEX, + ArrayMesh::ARRAY_FORMAT_NORMAL, + ArrayMesh::ARRAY_FORMAT_TANGENT, + ArrayMesh::ARRAY_FORMAT_COLOR, + ArrayMesh::ARRAY_FORMAT_TEX_UV, + ArrayMesh::ARRAY_FORMAT_TEX_UV2, + ArrayMesh::ARRAY_FORMAT_BONES, + ArrayMesh::ARRAY_FORMAT_WEIGHTS, + ArrayMesh::ARRAY_FORMAT_INDEX, }; -bool Mesh::_set(const StringName &p_name, const Variant &p_value) { +bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { String sname = p_name; @@ -191,7 +575,7 @@ bool Mesh::_set(const StringName &p_name, const Variant &p_value) { return false; } -bool Mesh::_get(const StringName &p_name, Variant &r_ret) const { +bool ArrayMesh::_get(const StringName &p_name, Variant &r_ret) const { if (_is_generated()) return false; @@ -270,7 +654,7 @@ bool Mesh::_get(const StringName &p_name, Variant &r_ret) const { return true; } -void Mesh::_get_property_list(List<PropertyInfo> *p_list) const { +void ArrayMesh::_get_property_list(List<PropertyInfo> *p_list) const { if (_is_generated()) return; @@ -290,7 +674,7 @@ void Mesh::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::RECT3, "custom_aabb/custom_aabb")); } -void Mesh::_recompute_aabb() { +void ArrayMesh::_recompute_aabb() { // regenerate AABB aabb = Rect3(); @@ -304,7 +688,7 @@ void Mesh::_recompute_aabb() { } } -void Mesh::add_surface(uint32_t p_format, PrimitiveType p_primitive, const PoolVector<uint8_t> &p_array, int p_vertex_count, const PoolVector<uint8_t> &p_index_array, int p_index_count, const Rect3 &p_aabb, const Vector<PoolVector<uint8_t> > &p_blend_shapes, const Vector<Rect3> &p_bone_aabbs) { +void ArrayMesh::add_surface(uint32_t p_format, PrimitiveType p_primitive, const PoolVector<uint8_t> &p_array, int p_vertex_count, const PoolVector<uint8_t> &p_index_array, int p_index_count, const Rect3 &p_aabb, const Vector<PoolVector<uint8_t> > &p_blend_shapes, const Vector<Rect3> &p_bone_aabbs) { Surface s; s.aabb = p_aabb; @@ -313,7 +697,7 @@ void Mesh::add_surface(uint32_t p_format, PrimitiveType p_primitive, const PoolV VisualServer::get_singleton()->mesh_add_surface(mesh, p_format, (VS::PrimitiveType)p_primitive, p_array, p_vertex_count, p_index_array, p_index_count, p_aabb, p_blend_shapes, p_bone_aabbs); } -void Mesh::add_surface_from_arrays(PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes, uint32_t p_flags) { +void ArrayMesh::add_surface_from_arrays(PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes, uint32_t p_flags) { ERR_FAIL_COND(p_arrays.size() != ARRAY_MAX); @@ -345,28 +729,28 @@ void Mesh::add_surface_from_arrays(PrimitiveType p_primitive, const Array &p_arr _recompute_aabb(); } - triangle_mesh = Ref<TriangleMesh>(); + _clear_triangle_mesh(); _change_notify(); emit_changed(); } -Array Mesh::surface_get_arrays(int p_surface) const { +Array ArrayMesh::surface_get_arrays(int p_surface) const { ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Array()); return VisualServer::get_singleton()->mesh_surface_get_arrays(mesh, p_surface); } -Array Mesh::surface_get_blend_shape_arrays(int p_surface) const { +Array ArrayMesh::surface_get_blend_shape_arrays(int p_surface) const { ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Array()); return Array(); } -int Mesh::get_surface_count() const { +int ArrayMesh::get_surface_count() const { return surfaces.size(); } -void Mesh::add_blend_shape(const StringName &p_name) { +void ArrayMesh::add_blend_shape(const StringName &p_name) { if (surfaces.size()) { ERR_EXPLAIN("Can't add a shape key count if surfaces are already created."); @@ -389,15 +773,15 @@ void Mesh::add_blend_shape(const StringName &p_name) { VS::get_singleton()->mesh_set_blend_shape_count(mesh, blend_shapes.size()); } -int Mesh::get_blend_shape_count() const { +int ArrayMesh::get_blend_shape_count() const { return blend_shapes.size(); } -StringName Mesh::get_blend_shape_name(int p_index) const { +StringName ArrayMesh::get_blend_shape_name(int p_index) const { ERR_FAIL_INDEX_V(p_index, blend_shapes.size(), StringName()); return blend_shapes[p_index]; } -void Mesh::clear_blend_shapes() { +void ArrayMesh::clear_blend_shapes() { if (surfaces.size()) { ERR_EXPLAIN("Can't set shape key count if surfaces are already created."); @@ -407,54 +791,54 @@ void Mesh::clear_blend_shapes() { blend_shapes.clear(); } -void Mesh::set_blend_shape_mode(BlendShapeMode p_mode) { +void ArrayMesh::set_blend_shape_mode(BlendShapeMode p_mode) { blend_shape_mode = p_mode; VS::get_singleton()->mesh_set_blend_shape_mode(mesh, (VS::BlendShapeMode)p_mode); } -Mesh::BlendShapeMode Mesh::get_blend_shape_mode() const { +ArrayMesh::BlendShapeMode ArrayMesh::get_blend_shape_mode() const { return blend_shape_mode; } -void Mesh::surface_remove(int p_idx) { +void ArrayMesh::surface_remove(int p_idx) { ERR_FAIL_INDEX(p_idx, surfaces.size()); VisualServer::get_singleton()->mesh_remove_surface(mesh, p_idx); surfaces.remove(p_idx); - triangle_mesh = Ref<TriangleMesh>(); + _clear_triangle_mesh(); _recompute_aabb(); _change_notify(); emit_changed(); } -int Mesh::surface_get_array_len(int p_idx) const { +int ArrayMesh::surface_get_array_len(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, surfaces.size(), -1); return VisualServer::get_singleton()->mesh_surface_get_array_len(mesh, p_idx); } -int Mesh::surface_get_array_index_len(int p_idx) const { +int ArrayMesh::surface_get_array_index_len(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, surfaces.size(), -1); return VisualServer::get_singleton()->mesh_surface_get_array_index_len(mesh, p_idx); } -uint32_t Mesh::surface_get_format(int p_idx) const { +uint32_t ArrayMesh::surface_get_format(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, surfaces.size(), 0); return VisualServer::get_singleton()->mesh_surface_get_format(mesh, p_idx); } -Mesh::PrimitiveType Mesh::surface_get_primitive_type(int p_idx) const { +ArrayMesh::PrimitiveType ArrayMesh::surface_get_primitive_type(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, surfaces.size(), PRIMITIVE_LINES); return (PrimitiveType)VisualServer::get_singleton()->mesh_surface_get_primitive_type(mesh, p_idx); } -void Mesh::surface_set_material(int p_idx, const Ref<Material> &p_material) { +void ArrayMesh::surface_set_material(int p_idx, const Ref<Material> &p_material) { ERR_FAIL_INDEX(p_idx, surfaces.size()); if (surfaces[p_idx].material == p_material) @@ -465,33 +849,33 @@ void Mesh::surface_set_material(int p_idx, const Ref<Material> &p_material) { _change_notify("material"); } -void Mesh::surface_set_name(int p_idx, const String &p_name) { +void ArrayMesh::surface_set_name(int p_idx, const String &p_name) { ERR_FAIL_INDEX(p_idx, surfaces.size()); surfaces[p_idx].name = p_name; } -String Mesh::surface_get_name(int p_idx) const { +String ArrayMesh::surface_get_name(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, surfaces.size(), String()); return surfaces[p_idx].name; } -void Mesh::surface_set_custom_aabb(int p_idx, const Rect3 &p_aabb) { +void ArrayMesh::surface_set_custom_aabb(int p_idx, const Rect3 &p_aabb) { ERR_FAIL_INDEX(p_idx, surfaces.size()); surfaces[p_idx].aabb = p_aabb; // set custom aabb too? } -Ref<Material> Mesh::surface_get_material(int p_idx) const { +Ref<Material> ArrayMesh::surface_get_material(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, surfaces.size(), Ref<Material>()); return surfaces[p_idx].material; } -void Mesh::add_surface_from_mesh_data(const Geometry::MeshData &p_mesh_data) { +void ArrayMesh::add_surface_from_mesh_data(const Geometry::MeshData &p_mesh_data) { VisualServer::get_singleton()->mesh_add_surface_from_mesh_data(mesh, p_mesh_data); Rect3 aabb; @@ -510,7 +894,7 @@ void Mesh::add_surface_from_mesh_data(const Geometry::MeshData &p_mesh_data) { else aabb.merge_with(s.aabb); - triangle_mesh = Ref<TriangleMesh>(); + _clear_triangle_mesh(); surfaces.push_back(s); _change_notify(); @@ -518,129 +902,27 @@ void Mesh::add_surface_from_mesh_data(const Geometry::MeshData &p_mesh_data) { emit_changed(); } -RID Mesh::get_rid() const { +RID ArrayMesh::get_rid() const { return mesh; } -Rect3 Mesh::get_aabb() const { +Rect3 ArrayMesh::get_aabb() const { return aabb; } -void Mesh::set_custom_aabb(const Rect3 &p_custom) { +void ArrayMesh::set_custom_aabb(const Rect3 &p_custom) { custom_aabb = p_custom; VS::get_singleton()->mesh_set_custom_aabb(mesh, custom_aabb); } -Rect3 Mesh::get_custom_aabb() const { +Rect3 ArrayMesh::get_custom_aabb() const { return custom_aabb; } -PoolVector<Face3> Mesh::get_faces() const { - - Ref<TriangleMesh> tm = generate_triangle_mesh(); - if (tm.is_valid()) - return tm->get_faces(); - return PoolVector<Face3>(); - /* - for (int i=0;i<surfaces.size();i++) { - - if (VisualServer::get_singleton()->mesh_surface_get_primitive_type( mesh, i ) != VisualServer::PRIMITIVE_TRIANGLES ) - continue; - - PoolVector<int> indices; - PoolVector<Vector3> vertices; - - vertices=VisualServer::get_singleton()->mesh_surface_get_array(mesh, i,VisualServer::ARRAY_VERTEX); - - int len=VisualServer::get_singleton()->mesh_surface_get_array_index_len(mesh, i); - bool has_indices; - - if (len>0) { - - indices=VisualServer::get_singleton()->mesh_surface_get_array(mesh, i,VisualServer::ARRAY_INDEX); - has_indices=true; - - } else { - - len=vertices.size(); - has_indices=false; - } - - if (len<=0) - continue; - - PoolVector<int>::Read indicesr = indices.read(); - const int *indicesptr = indicesr.ptr(); - - PoolVector<Vector3>::Read verticesr = vertices.read(); - const Vector3 *verticesptr = verticesr.ptr(); - - int old_faces=faces.size(); - int new_faces=old_faces+(len/3); - - faces.resize(new_faces); - - PoolVector<Face3>::Write facesw = faces.write(); - Face3 *facesptr=facesw.ptr(); - - - for (int i=0;i<len/3;i++) { - - Face3 face; - - for (int j=0;j<3;j++) { - - int idx=i*3+j; - face.vertex[j] = has_indices ? verticesptr[ indicesptr[ idx ] ] : verticesptr[idx]; - } - - facesptr[i+old_faces]=face; - } - - } -*/ -} - -Ref<Shape> Mesh::create_convex_shape() const { - - PoolVector<Vector3> vertices; - - for (int i = 0; i < get_surface_count(); i++) { - - Array a = surface_get_arrays(i); - PoolVector<Vector3> v = a[ARRAY_VERTEX]; - vertices.append_array(v); - } - - Ref<ConvexPolygonShape> shape = memnew(ConvexPolygonShape); - shape->set_points(vertices); - return shape; -} - -Ref<Shape> Mesh::create_trimesh_shape() const { - - PoolVector<Face3> faces = get_faces(); - if (faces.size() == 0) - return Ref<Shape>(); - - PoolVector<Vector3> face_points; - face_points.resize(faces.size() * 3); - - for (int i = 0; i < face_points.size(); i++) { - - Face3 f = faces.get(i / 3); - face_points.set(i, f.vertex[i % 3]); - } - - Ref<ConcavePolygonShape> shape = memnew(ConcavePolygonShape); - shape->set_faces(face_points); - return shape; -} - -void Mesh::center_geometry() { +void ArrayMesh::center_geometry() { /* Vector3 ofs = aabb.pos+aabb.size*0.5; @@ -668,13 +950,13 @@ void Mesh::center_geometry() { */ } -void Mesh::regen_normalmaps() { +void ArrayMesh::regen_normalmaps() { Vector<Ref<SurfaceTool> > surfs; for (int i = 0; i < get_surface_count(); i++) { Ref<SurfaceTool> st = memnew(SurfaceTool); - st->create_from(Ref<Mesh>(this), i); + st->create_from(Ref<ArrayMesh>(this), i); surfs.push_back(st); } @@ -685,315 +967,42 @@ void Mesh::regen_normalmaps() { for (int i = 0; i < surfs.size(); i++) { surfs[i]->generate_tangents(); - surfs[i]->commit(Ref<Mesh>(this)); - } -} - -Ref<TriangleMesh> Mesh::generate_triangle_mesh() const { - - if (triangle_mesh.is_valid()) - return triangle_mesh; - - int facecount = 0; - - for (int i = 0; i < get_surface_count(); i++) { - - if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES) - continue; - - if (surface_get_format(i) & ARRAY_FORMAT_INDEX) { - - facecount += surface_get_array_index_len(i); - } else { - - facecount += surface_get_array_len(i); - } - } - - if (facecount == 0 || (facecount % 3) != 0) - return triangle_mesh; - - PoolVector<Vector3> faces; - faces.resize(facecount); - PoolVector<Vector3>::Write facesw = faces.write(); - - int widx = 0; - - for (int i = 0; i < get_surface_count(); i++) { - - if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES) - continue; - - Array a = surface_get_arrays(i); - - int vc = surface_get_array_len(i); - PoolVector<Vector3> vertices = a[ARRAY_VERTEX]; - PoolVector<Vector3>::Read vr = vertices.read(); - - if (surface_get_format(i) & ARRAY_FORMAT_INDEX) { - - int ic = surface_get_array_index_len(i); - PoolVector<int> indices = a[ARRAY_INDEX]; - PoolVector<int>::Read ir = indices.read(); - - for (int i = 0; i < ic; i++) { - int index = ir[i]; - facesw[widx++] = vr[index]; - } - - } else { - - for (int i = 0; i < vc; i++) - facesw[widx++] = vr[i]; - } + surfs[i]->commit(Ref<ArrayMesh>(this)); } - - facesw = PoolVector<Vector3>::Write(); - - triangle_mesh = Ref<TriangleMesh>(memnew(TriangleMesh)); - triangle_mesh->create(faces); - - return triangle_mesh; } -Ref<Mesh> Mesh::create_outline(float p_margin) const { - - Array arrays; - int index_accum = 0; - for (int i = 0; i < get_surface_count(); i++) { - - if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES) - continue; - - Array a = surface_get_arrays(i); - int vcount = 0; - - if (i == 0) { - arrays = a; - PoolVector<Vector3> v = a[ARRAY_VERTEX]; - index_accum += v.size(); - } else { - - for (int j = 0; j < arrays.size(); j++) { - - if (arrays[j].get_type() == Variant::NIL || a[j].get_type() == Variant::NIL) { - //mismatch, do not use - arrays[j] = Variant(); - continue; - } - - switch (j) { - - case ARRAY_VERTEX: - case ARRAY_NORMAL: { - - PoolVector<Vector3> dst = arrays[j]; - PoolVector<Vector3> src = a[j]; - if (j == ARRAY_VERTEX) - vcount = src.size(); - if (dst.size() == 0 || src.size() == 0) { - arrays[j] = Variant(); - continue; - } - dst.append_array(src); - arrays[j] = dst; - } break; - case ARRAY_TANGENT: - case ARRAY_BONES: - case ARRAY_WEIGHTS: { - - PoolVector<real_t> dst = arrays[j]; - PoolVector<real_t> src = a[j]; - if (dst.size() == 0 || src.size() == 0) { - arrays[j] = Variant(); - continue; - } - dst.append_array(src); - arrays[j] = dst; - - } break; - case ARRAY_COLOR: { - PoolVector<Color> dst = arrays[j]; - PoolVector<Color> src = a[j]; - if (dst.size() == 0 || src.size() == 0) { - arrays[j] = Variant(); - continue; - } - dst.append_array(src); - arrays[j] = dst; - - } break; - case ARRAY_TEX_UV: - case ARRAY_TEX_UV2: { - PoolVector<Vector2> dst = arrays[j]; - PoolVector<Vector2> src = a[j]; - if (dst.size() == 0 || src.size() == 0) { - arrays[j] = Variant(); - continue; - } - dst.append_array(src); - arrays[j] = dst; - - } break; - case ARRAY_INDEX: { - PoolVector<int> dst = arrays[j]; - PoolVector<int> src = a[j]; - if (dst.size() == 0 || src.size() == 0) { - arrays[j] = Variant(); - continue; - } - { - int ss = src.size(); - PoolVector<int>::Write w = src.write(); - for (int k = 0; k < ss; k++) { - w[k] += index_accum; - } - } - dst.append_array(src); - arrays[j] = dst; - index_accum += vcount; - - } break; - } - } - } - } - - { - PoolVector<int>::Write ir; - PoolVector<int> indices = arrays[ARRAY_INDEX]; - bool has_indices = false; - PoolVector<Vector3> vertices = arrays[ARRAY_VERTEX]; - int vc = vertices.size(); - ERR_FAIL_COND_V(!vc, Ref<Mesh>()); - PoolVector<Vector3>::Write r = vertices.write(); - - if (indices.size()) { - vc = indices.size(); - ir = indices.write(); - has_indices = true; - } - - Map<Vector3, Vector3> normal_accum; - - //fill normals with triangle normals - for (int i = 0; i < vc; i += 3) { - - Vector3 t[3]; - - if (has_indices) { - t[0] = r[ir[i + 0]]; - t[1] = r[ir[i + 1]]; - t[2] = r[ir[i + 2]]; - } else { - t[0] = r[i + 0]; - t[1] = r[i + 1]; - t[2] = r[i + 2]; - } - - Vector3 n = Plane(t[0], t[1], t[2]).normal; - - for (int j = 0; j < 3; j++) { - - Map<Vector3, Vector3>::Element *E = normal_accum.find(t[j]); - if (!E) { - normal_accum[t[j]] = n; - } else { - float d = n.dot(E->get()); - if (d < 1.0) - E->get() += n * (1.0 - d); - //E->get()+=n; - } - } - } - - //normalize - - for (Map<Vector3, Vector3>::Element *E = normal_accum.front(); E; E = E->next()) { - E->get().normalize(); - } - - //displace normals - int vc2 = vertices.size(); - - for (int i = 0; i < vc2; i++) { - - Vector3 t = r[i]; - - Map<Vector3, Vector3>::Element *E = normal_accum.find(t); - ERR_CONTINUE(!E); - - t += E->get() * p_margin; - r[i] = t; - } - - r = PoolVector<Vector3>::Write(); - arrays[ARRAY_VERTEX] = vertices; - - if (!has_indices) { - - PoolVector<int> new_indices; - new_indices.resize(vertices.size()); - PoolVector<int>::Write iw = new_indices.write(); - - for (int j = 0; j < vc2; j += 3) { - - iw[j] = j; - iw[j + 1] = j + 2; - iw[j + 2] = j + 1; - } - - iw = PoolVector<int>::Write(); - arrays[ARRAY_INDEX] = new_indices; - - } else { - - for (int j = 0; j < vc; j += 3) { - - SWAP(ir[j + 1], ir[j + 2]); - } - ir = PoolVector<int>::Write(); - arrays[ARRAY_INDEX] = indices; - } - } - - Ref<Mesh> newmesh = memnew(Mesh); - newmesh->add_surface_from_arrays(PRIMITIVE_TRIANGLES, arrays); - return newmesh; -} - -void Mesh::_bind_methods() { - - ClassDB::bind_method(D_METHOD("add_blend_shape", "name"), &Mesh::add_blend_shape); - ClassDB::bind_method(D_METHOD("get_blend_shape_count"), &Mesh::get_blend_shape_count); - ClassDB::bind_method(D_METHOD("get_blend_shape_name", "index"), &Mesh::get_blend_shape_name); - ClassDB::bind_method(D_METHOD("clear_blend_shapes"), &Mesh::clear_blend_shapes); - ClassDB::bind_method(D_METHOD("set_blend_shape_mode", "mode"), &Mesh::set_blend_shape_mode); - ClassDB::bind_method(D_METHOD("get_blend_shape_mode"), &Mesh::get_blend_shape_mode); - - ClassDB::bind_method(D_METHOD("add_surface_from_arrays", "primitive", "arrays", "blend_shapes", "compress_flags"), &Mesh::add_surface_from_arrays, DEFVAL(Array()), DEFVAL(ARRAY_COMPRESS_DEFAULT)); - ClassDB::bind_method(D_METHOD("get_surface_count"), &Mesh::get_surface_count); - ClassDB::bind_method(D_METHOD("surface_remove", "surf_idx"), &Mesh::surface_remove); - ClassDB::bind_method(D_METHOD("surface_get_array_len", "surf_idx"), &Mesh::surface_get_array_len); - ClassDB::bind_method(D_METHOD("surface_get_array_index_len", "surf_idx"), &Mesh::surface_get_array_index_len); - ClassDB::bind_method(D_METHOD("surface_get_format", "surf_idx"), &Mesh::surface_get_format); - ClassDB::bind_method(D_METHOD("surface_get_primitive_type", "surf_idx"), &Mesh::surface_get_primitive_type); - ClassDB::bind_method(D_METHOD("surface_set_material", "surf_idx", "material:Material"), &Mesh::surface_set_material); - ClassDB::bind_method(D_METHOD("surface_get_material:Material", "surf_idx"), &Mesh::surface_get_material); - ClassDB::bind_method(D_METHOD("surface_set_name", "surf_idx", "name"), &Mesh::surface_set_name); - ClassDB::bind_method(D_METHOD("surface_get_name", "surf_idx"), &Mesh::surface_get_name); - ClassDB::bind_method(D_METHOD("create_trimesh_shape:Shape"), &Mesh::create_trimesh_shape); - ClassDB::bind_method(D_METHOD("create_convex_shape:Shape"), &Mesh::create_convex_shape); - ClassDB::bind_method(D_METHOD("create_outline:Mesh", "margin"), &Mesh::create_outline); - ClassDB::bind_method(D_METHOD("center_geometry"), &Mesh::center_geometry); +void ArrayMesh::_bind_methods() { + + ClassDB::bind_method(D_METHOD("add_blend_shape", "name"), &ArrayMesh::add_blend_shape); + ClassDB::bind_method(D_METHOD("get_blend_shape_count"), &ArrayMesh::get_blend_shape_count); + ClassDB::bind_method(D_METHOD("get_blend_shape_name", "index"), &ArrayMesh::get_blend_shape_name); + ClassDB::bind_method(D_METHOD("clear_blend_shapes"), &ArrayMesh::clear_blend_shapes); + ClassDB::bind_method(D_METHOD("set_blend_shape_mode", "mode"), &ArrayMesh::set_blend_shape_mode); + ClassDB::bind_method(D_METHOD("get_blend_shape_mode"), &ArrayMesh::get_blend_shape_mode); + + ClassDB::bind_method(D_METHOD("add_surface_from_arrays", "primitive", "arrays", "blend_shapes", "compress_flags"), &ArrayMesh::add_surface_from_arrays, DEFVAL(Array()), DEFVAL(ARRAY_COMPRESS_DEFAULT)); + ClassDB::bind_method(D_METHOD("get_surface_count"), &ArrayMesh::get_surface_count); + ClassDB::bind_method(D_METHOD("surface_remove", "surf_idx"), &ArrayMesh::surface_remove); + ClassDB::bind_method(D_METHOD("surface_get_array_len", "surf_idx"), &ArrayMesh::surface_get_array_len); + ClassDB::bind_method(D_METHOD("surface_get_array_index_len", "surf_idx"), &ArrayMesh::surface_get_array_index_len); + ClassDB::bind_method(D_METHOD("surface_get_format", "surf_idx"), &ArrayMesh::surface_get_format); + ClassDB::bind_method(D_METHOD("surface_get_primitive_type", "surf_idx"), &ArrayMesh::surface_get_primitive_type); + ClassDB::bind_method(D_METHOD("surface_set_material", "surf_idx", "material:Material"), &ArrayMesh::surface_set_material); + ClassDB::bind_method(D_METHOD("surface_get_material:Material", "surf_idx"), &ArrayMesh::surface_get_material); + ClassDB::bind_method(D_METHOD("surface_set_name", "surf_idx", "name"), &ArrayMesh::surface_set_name); + ClassDB::bind_method(D_METHOD("surface_get_name", "surf_idx"), &ArrayMesh::surface_get_name); + ClassDB::bind_method(D_METHOD("create_trimesh_shape:Shape"), &ArrayMesh::create_trimesh_shape); + ClassDB::bind_method(D_METHOD("create_convex_shape:Shape"), &ArrayMesh::create_convex_shape); + ClassDB::bind_method(D_METHOD("create_outline:ArrayMesh", "margin"), &ArrayMesh::create_outline); + ClassDB::bind_method(D_METHOD("center_geometry"), &ArrayMesh::center_geometry); ClassDB::set_method_flags(get_class_static(), _scs_create("center_geometry"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR); - ClassDB::bind_method(D_METHOD("regen_normalmaps"), &Mesh::regen_normalmaps); + ClassDB::bind_method(D_METHOD("regen_normalmaps"), &ArrayMesh::regen_normalmaps); ClassDB::set_method_flags(get_class_static(), _scs_create("regen_normalmaps"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR); - ClassDB::bind_method(D_METHOD("get_faces"), &Mesh::get_faces); - ClassDB::bind_method(D_METHOD("generate_triangle_mesh:TriangleMesh"), &Mesh::generate_triangle_mesh); + ClassDB::bind_method(D_METHOD("get_faces"), &ArrayMesh::get_faces); + ClassDB::bind_method(D_METHOD("generate_triangle_mesh:TriangleMesh"), &ArrayMesh::generate_triangle_mesh); - ClassDB::bind_method(D_METHOD("set_custom_aabb", "aabb"), &Mesh::set_custom_aabb); - ClassDB::bind_method(D_METHOD("get_custom_aabb"), &Mesh::get_custom_aabb); + ClassDB::bind_method(D_METHOD("set_custom_aabb", "aabb"), &ArrayMesh::set_custom_aabb); + ClassDB::bind_method(D_METHOD("get_custom_aabb"), &ArrayMesh::get_custom_aabb); BIND_CONSTANT(NO_INDEX_ARRAY); BIND_CONSTANT(ARRAY_WEIGHTS_SIZE); @@ -1027,19 +1036,19 @@ void Mesh::_bind_methods() { BIND_CONSTANT(PRIMITIVE_TRIANGLE_FAN); } -Mesh::Mesh() { +ArrayMesh::ArrayMesh() { mesh = VisualServer::get_singleton()->mesh_create(); blend_shape_mode = BLEND_SHAPE_MODE_RELATIVE; } -Mesh::~Mesh() { +ArrayMesh::~ArrayMesh() { VisualServer::get_singleton()->free(mesh); } //////////////////////// - +#if 0 void QuadMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("set_material", "material:Material"), &QuadMesh::set_material); @@ -1105,3 +1114,4 @@ QuadMesh::QuadMesh() { add_surface_from_arrays(PRIMITIVE_TRIANGLE_FAN, arr); } +#endif diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h index e441b4924a..7804a84f81 100644 --- a/scene/resources/mesh.h +++ b/scene/resources/mesh.h @@ -38,10 +38,13 @@ /** @author Juan Linietsky <reduzio@gmail.com> */ -class Mesh : public Resource { +class Mesh : public Resource { GDCLASS(Mesh, Resource); - RES_BASE_EXTENSION("msh"); + + mutable Ref<TriangleMesh> triangle_mesh; //cached +protected: + void _clear_triangle_mesh(); public: enum { @@ -111,6 +114,34 @@ public: BLEND_SHAPE_MODE_RELATIVE = VS::BLEND_SHAPE_MODE_RELATIVE, }; + virtual int get_surface_count() const = 0; + virtual int surface_get_array_len(int p_idx) const = 0; + virtual int surface_get_array_index_len(int p_idx) const = 0; + virtual Array surface_get_arrays(int p_surface) const = 0; + virtual uint32_t surface_get_format(int p_idx) const = 0; + virtual PrimitiveType surface_get_primitive_type(int p_idx) const = 0; + virtual Ref<Material> surface_get_material(int p_idx) const = 0; + virtual int get_blend_shape_count() const = 0; + virtual StringName get_blend_shape_name(int p_index) const = 0; + + PoolVector<Face3> get_faces() const; + Ref<TriangleMesh> generate_triangle_mesh() const; + + Ref<Shape> create_trimesh_shape() const; + Ref<Shape> create_convex_shape() const; + + Ref<Mesh> create_outline(float p_margin) const; + + virtual Rect3 get_aabb() const = 0; + + Mesh(); +}; + +class ArrayMesh : public Mesh { + + GDCLASS(ArrayMesh, Mesh); + RES_BASE_EXTENSION("msh"); + private: struct Surface { String name; @@ -124,8 +155,6 @@ private: Vector<StringName> blend_shapes; Rect3 custom_aabb; - mutable Ref<TriangleMesh> triangle_mesh; - void _recompute_aabb(); protected: @@ -177,21 +206,15 @@ public: Rect3 get_aabb() const; virtual RID get_rid() const; - Ref<Shape> create_trimesh_shape() const; - Ref<Shape> create_convex_shape() const; - - Ref<Mesh> create_outline(float p_margin) const; - void center_geometry(); void regen_normalmaps(); - PoolVector<Face3> get_faces() const; - Ref<TriangleMesh> generate_triangle_mesh() const; - Mesh(); + ArrayMesh(); - ~Mesh(); + ~ArrayMesh(); }; +#if 0 class QuadMesh : public Mesh { GDCLASS(QuadMesh, Mesh) @@ -206,6 +229,8 @@ public: QuadMesh(); }; +#endif + VARIANT_ENUM_CAST(Mesh::ArrayType); VARIANT_ENUM_CAST(Mesh::PrimitiveType); VARIANT_ENUM_CAST(Mesh::BlendShapeMode); diff --git a/scene/resources/mesh_data_tool.cpp b/scene/resources/mesh_data_tool.cpp index b6b47bf443..dc3713fb57 100644 --- a/scene/resources/mesh_data_tool.cpp +++ b/scene/resources/mesh_data_tool.cpp @@ -38,7 +38,7 @@ void MeshDataTool::clear() { format = 0; } -Error MeshDataTool::create_from_surface(const Ref<Mesh> &p_mesh, int p_surface) { +Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surface) { ERR_FAIL_COND_V(p_mesh.is_null(), ERR_INVALID_PARAMETER); @@ -179,7 +179,7 @@ Error MeshDataTool::create_from_surface(const Ref<Mesh> &p_mesh, int p_surface) return OK; } -Error MeshDataTool::commit_to_surface(const Ref<Mesh> &p_mesh) { +Error MeshDataTool::commit_to_surface(const Ref<ArrayMesh> &p_mesh) { ERR_FAIL_COND_V(p_mesh.is_null(), ERR_INVALID_PARAMETER); Array arr; @@ -309,7 +309,7 @@ Error MeshDataTool::commit_to_surface(const Ref<Mesh> &p_mesh) { if (w.size()) arr[Mesh::ARRAY_WEIGHTS] = w; - Ref<Mesh> ncmesh = p_mesh; + Ref<ArrayMesh> ncmesh = p_mesh; int sc = ncmesh->get_surface_count(); ncmesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, arr); ncmesh->surface_set_material(sc, material); diff --git a/scene/resources/mesh_data_tool.h b/scene/resources/mesh_data_tool.h index f6797d3e5e..ad771edbd1 100644 --- a/scene/resources/mesh_data_tool.h +++ b/scene/resources/mesh_data_tool.h @@ -78,8 +78,8 @@ protected: public: void clear(); - Error create_from_surface(const Ref<Mesh> &p_mesh, int p_surface); - Error commit_to_surface(const Ref<Mesh> &p_mesh); + Error create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surface); + Error commit_to_surface(const Ref<ArrayMesh> &p_mesh); int get_format() const; diff --git a/scene/resources/polygon_path_finder.cpp b/scene/resources/polygon_path_finder.cpp index 472031366f..80b413630a 100644 --- a/scene/resources/polygon_path_finder.cpp +++ b/scene/resources/polygon_path_finder.cpp @@ -71,7 +71,7 @@ void PolygonPathFinder::setup(const Vector<Vector2> &p_points, const Vector<int> outside_point.y = i == 0 ? p_points[0].y : (MAX(p_points[i].y, outside_point.y)); if (i == 0) { - bounds.pos = points[i].pos; + bounds.position = points[i].pos; } else { bounds.expand_to(points[i].pos); } diff --git a/scene/resources/segment_shape_2d.cpp b/scene/resources/segment_shape_2d.cpp index 145374ff05..99062d693b 100644 --- a/scene/resources/segment_shape_2d.cpp +++ b/scene/resources/segment_shape_2d.cpp @@ -35,7 +35,7 @@ void SegmentShape2D::_update_shape() { Rect2 r; - r.pos = a; + r.position = a; r.size = b; Physics2DServer::get_singleton()->shape_set_data(get_rid(), r); emit_changed(); @@ -69,7 +69,7 @@ void SegmentShape2D::draw(const RID &p_to_rid, const Color &p_color) { Rect2 SegmentShape2D::get_rect() const { Rect2 rect; - rect.pos = a; + rect.position = a; rect.expand_to(b); return rect; } @@ -121,7 +121,7 @@ void RayShape2D::draw(const RID &p_to_rid, const Color &p_color) { Rect2 RayShape2D::get_rect() const { Rect2 rect; - rect.pos = Vector2(); + rect.position = Vector2(); rect.expand_to(Vector2(0, length)); rect = rect.grow(0.707 * 4); return rect; diff --git a/scene/resources/shape.cpp b/scene/resources/shape.cpp index b449932b17..77f2096d9b 100644 --- a/scene/resources/shape.cpp +++ b/scene/resources/shape.cpp @@ -49,14 +49,14 @@ void Shape::add_vertices_to_array(PoolVector<Vector3> &array, const Transform &p } } -Ref<Mesh> Shape::get_debug_mesh() { +Ref<ArrayMesh> Shape::get_debug_mesh() { if (debug_mesh_cache.is_valid()) return debug_mesh_cache; Vector<Vector3> lines = _gen_debug_mesh_lines(); - debug_mesh_cache = Ref<Mesh>(memnew(Mesh)); + debug_mesh_cache = Ref<ArrayMesh>(memnew(ArrayMesh)); if (!lines.empty()) { //make mesh diff --git a/scene/resources/shape.h b/scene/resources/shape.h index 01b8db650e..ea3ba9ab0a 100644 --- a/scene/resources/shape.h +++ b/scene/resources/shape.h @@ -31,7 +31,7 @@ #define SHAPE_H #include "resource.h" -class Mesh; +class ArrayMesh; class Shape : public Resource { @@ -40,7 +40,7 @@ class Shape : public Resource { RES_BASE_EXTENSION("shp"); RID shape; - Ref<Mesh> debug_mesh_cache; + Ref<ArrayMesh> debug_mesh_cache; protected: _FORCE_INLINE_ RID get_shape() const { return shape; } @@ -50,7 +50,7 @@ protected: public: virtual RID get_rid() const { return shape; } - Ref<Mesh> get_debug_mesh(); + Ref<ArrayMesh> get_debug_mesh(); void add_vertices_to_array(PoolVector<Vector3> &array, const Transform &p_xform); diff --git a/scene/resources/shape_line_2d.cpp b/scene/resources/shape_line_2d.cpp index 89c1cea252..c38ae04eff 100644 --- a/scene/resources/shape_line_2d.cpp +++ b/scene/resources/shape_line_2d.cpp @@ -76,7 +76,7 @@ Rect2 LineShape2D::get_rect() const { Vector2 l1[2] = { point - get_normal().tangent() * 100, point + get_normal().tangent() * 100 }; Vector2 l2[2] = { point, point + get_normal() * 30 }; Rect2 rect; - rect.pos = l1[0]; + rect.position = l1[0]; rect.expand_to(l1[1]); rect.expand_to(l2[0]); rect.expand_to(l2[1]); diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index b665de2de1..8874cbc102 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -138,8 +138,8 @@ void StyleBoxTexture::draw(RID p_canvas_item, const Rect2 &p_rect) const { texture->get_rect_region(rect, src_rect, rect, src_rect); - rect.pos.x -= expand_margin[MARGIN_LEFT]; - rect.pos.y -= expand_margin[MARGIN_TOP]; + rect.position.x -= expand_margin[MARGIN_LEFT]; + rect.position.y -= expand_margin[MARGIN_TOP]; rect.size.x += expand_margin[MARGIN_LEFT] + expand_margin[MARGIN_RIGHT]; rect.size.y += expand_margin[MARGIN_TOP] + expand_margin[MARGIN_BOTTOM]; @@ -352,26 +352,26 @@ void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const { color_downright.b = (border_size - i) * color_downright.b / border_size + i * bg_color.b / border_size; } - vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r.pos.x, r.pos.y + r.size.y - 1), Size2(r.size.x, 1)), color_downright); - vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r.pos.x + r.size.x - 1, r.pos.y), Size2(1, r.size.y)), color_downright); + vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r.position.x, r.position.y + r.size.y - 1), Size2(r.size.x, 1)), color_downright); + vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r.position.x + r.size.x - 1, r.position.y), Size2(1, r.size.y)), color_downright); - vs->canvas_item_add_rect(p_canvas_item, Rect2(r.pos, Size2(r.size.x, 1)), color_upleft); - vs->canvas_item_add_rect(p_canvas_item, Rect2(r.pos, Size2(1, r.size.y)), color_upleft); + vs->canvas_item_add_rect(p_canvas_item, Rect2(r.position, Size2(r.size.x, 1)), color_upleft); + vs->canvas_item_add_rect(p_canvas_item, Rect2(r.position, Size2(1, r.size.y)), color_upleft); - r.pos.x++; - r.pos.y++; + r.position.x++; + r.position.y++; r.size.x -= 2; r.size.y -= 2; } if (draw_center) - vs->canvas_item_add_rect(p_canvas_item, Rect2(r.pos, r.size), bg_color); + vs->canvas_item_add_rect(p_canvas_item, Rect2(r.position, r.size), bg_color); Rect2i r_add = p_rect; - vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r_add.pos.x - additional_border_size[MARGIN_LEFT], r_add.pos.y - additional_border_size[MARGIN_TOP]), Size2(r_add.size.width + additional_border_size[MARGIN_LEFT] + additional_border_size[MARGIN_RIGHT], additional_border_size[MARGIN_TOP])), light_color); - vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r_add.pos.x - additional_border_size[MARGIN_LEFT], r_add.pos.y), Size2(additional_border_size[MARGIN_LEFT], r_add.size.height)), light_color); - vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r_add.pos.x + r_add.size.width, r_add.pos.y), Size2(additional_border_size[MARGIN_RIGHT], r_add.size.height)), dark_color); - vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r_add.pos.x - additional_border_size[MARGIN_LEFT], r_add.pos.y + r_add.size.height), Size2(r_add.size.width + additional_border_size[MARGIN_LEFT] + additional_border_size[MARGIN_RIGHT], additional_border_size[MARGIN_BOTTOM])), dark_color); + vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r_add.position.x - additional_border_size[MARGIN_LEFT], r_add.position.y - additional_border_size[MARGIN_TOP]), Size2(r_add.size.width + additional_border_size[MARGIN_LEFT] + additional_border_size[MARGIN_RIGHT], additional_border_size[MARGIN_TOP])), light_color); + vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r_add.position.x - additional_border_size[MARGIN_LEFT], r_add.position.y), Size2(additional_border_size[MARGIN_LEFT], r_add.size.height)), light_color); + vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r_add.position.x + r_add.size.width, r_add.position.y), Size2(additional_border_size[MARGIN_RIGHT], r_add.size.height)), dark_color); + vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r_add.position.x - additional_border_size[MARGIN_LEFT], r_add.position.y + r_add.size.height), Size2(r_add.size.width + additional_border_size[MARGIN_LEFT] + additional_border_size[MARGIN_RIGHT], additional_border_size[MARGIN_BOTTOM])), dark_color); } float StyleBoxFlat::get_style_margin(Margin p_margin) const { diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp index 4c36d79a7a..60fb97c792 100644 --- a/scene/resources/surface_tool.cpp +++ b/scene/resources/surface_tool.cpp @@ -224,13 +224,13 @@ void SurfaceTool::add_index(int p_index) { index_array.push_back(p_index); } -Ref<Mesh> SurfaceTool::commit(const Ref<Mesh> &p_existing) { +Ref<ArrayMesh> SurfaceTool::commit(const Ref<ArrayMesh> &p_existing) { - Ref<Mesh> mesh; + Ref<ArrayMesh> mesh; if (p_existing.is_valid()) mesh = p_existing; else - mesh = Ref<Mesh>(memnew(Mesh)); + mesh.instance(); int varr_len = vertex_array.size(); diff --git a/scene/resources/surface_tool.h b/scene/resources/surface_tool.h index b143086e11..753c3626b8 100644 --- a/scene/resources/surface_tool.h +++ b/scene/resources/surface_tool.h @@ -125,7 +125,7 @@ public: void create_from(const Ref<Mesh> &p_existing, int p_surface); void append_from(const Ref<Mesh> &p_existing, int p_surface, const Transform &p_xform); - Ref<Mesh> commit(const Ref<Mesh> &p_existing = Ref<Mesh>()); + Ref<ArrayMesh> commit(const Ref<ArrayMesh> &p_existing = Ref<ArrayMesh>()); SurfaceTool(); }; diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index bc8deb501e..a1e0c95dd9 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -494,9 +494,9 @@ Error StreamTexture::_load_data(const String &p_path, int &tw, int &th, int &fla img = Image::lossy_unpacker(pv); } - if (img.is_null()) { + if (img.is_null() || img->empty()) { memdelete(f); - ERR_FAIL_COND_V(img->empty(), ERR_FILE_CORRUPT); + ERR_FAIL_COND_V(img.is_null() || img->empty(), ERR_FILE_CORRUPT); } total_size += img->get_data().size(); @@ -860,7 +860,7 @@ void AtlasTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_m rc.size.height = atlas->get_height(); } - VS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(p_pos + margin.pos, rc.size), atlas->get_rid(), rc, p_modulate, p_transpose); + VS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(p_pos + margin.position, rc.size), atlas->get_rid(), rc, p_modulate, p_transpose); } void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose) const { @@ -879,7 +879,7 @@ void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile } Vector2 scale = p_rect.size / (region.size + margin.size); - Rect2 dr(p_rect.pos + margin.pos * scale, rc.size * scale); + Rect2 dr(p_rect.position + margin.position * scale, rc.size * scale); VS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, dr, atlas->get_rid(), rc, p_modulate, p_transpose); } @@ -892,24 +892,24 @@ void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, cons return; Rect2 src = p_src_rect; - src.pos += (rc.pos - margin.pos); + src.position += (rc.position - margin.position); Rect2 src_c = rc.clip(src); if (src_c.size == Size2()) return; - Vector2 ofs = (src_c.pos - src.pos); + Vector2 ofs = (src_c.position - src.position); Vector2 scale = p_rect.size / p_src_rect.size; if (scale.x < 0) { - float mx = (margin.size.width - margin.pos.x); - mx -= margin.pos.x; + float mx = (margin.size.width - margin.position.x); + mx -= margin.position.x; ofs.x = -(ofs.x + mx); } if (scale.y < 0) { - float my = margin.size.height - margin.pos.y; - my -= margin.pos.y; + float my = margin.size.height - margin.position.y; + my -= margin.position.y; ofs.y = -(ofs.y + my); } - Rect2 dr(p_rect.pos + ofs * scale, src_c.size * scale); + Rect2 dr(p_rect.position + ofs * scale, src_c.size * scale); VS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, dr, atlas->get_rid(), src_c, p_modulate, p_transpose); } @@ -922,24 +922,24 @@ bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, return false; Rect2 src = p_src_rect; - src.pos += (rc.pos - margin.pos); + src.position += (rc.position - margin.position); Rect2 src_c = rc.clip(src); if (src_c.size == Size2()) return false; - Vector2 ofs = (src_c.pos - src.pos); + Vector2 ofs = (src_c.position - src.position); Vector2 scale = p_rect.size / p_src_rect.size; if (scale.x < 0) { - float mx = (margin.size.width - margin.pos.x); - mx -= margin.pos.x; + float mx = (margin.size.width - margin.position.x); + mx -= margin.position.x; ofs.x = -(ofs.x + mx); } if (scale.y < 0) { - float my = margin.size.height - margin.pos.y; - my -= margin.pos.y; + float my = margin.size.height - margin.position.y; + my -= margin.position.y; ofs.y = -(ofs.y + my); } - Rect2 dr(p_rect.pos + ofs * scale, src_c.size * scale); + Rect2 dr(p_rect.position + ofs * scale, src_c.size * scale); r_rect = dr; r_src_rect = src_c; @@ -1096,7 +1096,7 @@ void LargeTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile for (int i = 0; i < pieces.size(); i++) { // TODO - pieces[i].texture->draw_rect(p_canvas_item, Rect2(pieces[i].offset * scale + p_rect.pos, pieces[i].texture->get_size() * scale), false, p_modulate, p_transpose); + pieces[i].texture->draw_rect(p_canvas_item, Rect2(pieces[i].offset * scale + p_rect.position, pieces[i].texture->get_size() * scale), false, p_modulate, p_transpose); } } void LargeTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose) const { @@ -1116,8 +1116,8 @@ void LargeTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, cons Rect2 local = p_src_rect.clip(rect); Rect2 target = local; target.size *= scale; - target.pos = p_rect.pos + (p_src_rect.pos + rect.pos) * scale; - local.pos -= rect.pos; + target.position = p_rect.position + (p_src_rect.position + rect.position) * scale; + local.position -= rect.position; pieces[i].texture->draw_rect_region(p_canvas_item, target, local, p_modulate, p_transpose); } } diff --git a/scene/resources/world_2d.cpp b/scene/resources/world_2d.cpp index db72ccd03c..ec9ec96e50 100644 --- a/scene/resources/world_2d.cpp +++ b/scene/resources/world_2d.cpp @@ -97,9 +97,9 @@ struct SpatialIndexer2D { void _notifier_update_cells(VisibilityNotifier2D *p_notifier, const Rect2 &p_rect, bool p_add) { - Point2i begin = p_rect.pos; + Point2i begin = p_rect.position; begin /= cell_size; - Point2i end = p_rect.pos + p_rect.size; + Point2i end = p_rect.position + p_rect.size; end /= cell_size; for (int i = begin.x; i <= end.x; i++) { @@ -220,9 +220,9 @@ struct SpatialIndexer2D { for (Map<Viewport *, ViewportData>::Element *E = viewports.front(); E; E = E->next()) { - Point2i begin = E->get().rect.pos; + Point2i begin = E->get().rect.position; begin /= cell_size; - Point2i end = E->get().rect.pos + E->get().rect.size; + Point2i end = E->get().rect.position + E->get().rect.size; end /= cell_size; pass++; List<VisibilityNotifier2D *> added; diff --git a/servers/physics_2d/broad_phase_2d_hash_grid.cpp b/servers/physics_2d/broad_phase_2d_hash_grid.cpp index e39a5b6df1..438cd416f6 100644 --- a/servers/physics_2d/broad_phase_2d_hash_grid.cpp +++ b/servers/physics_2d/broad_phase_2d_hash_grid.cpp @@ -116,8 +116,8 @@ void BroadPhase2DHashGrid::_enter_grid(Element *p_elem, const Rect2 &p_rect, boo return; } - Point2i from = (p_rect.pos / cell_size).floor(); - Point2i to = ((p_rect.pos + p_rect.size) / cell_size).floor(); + Point2i from = (p_rect.position / cell_size).floor(); + Point2i to = ((p_rect.position + p_rect.size) / cell_size).floor(); for (int i = from.x; i <= to.x; i++) { @@ -214,8 +214,8 @@ void BroadPhase2DHashGrid::_exit_grid(Element *p_elem, const Rect2 &p_rect, bool return; } - Point2i from = (p_rect.pos / cell_size).floor(); - Point2i to = ((p_rect.pos + p_rect.size) / cell_size).floor(); + Point2i from = (p_rect.position / cell_size).floor(); + Point2i to = ((p_rect.position + p_rect.size) / cell_size).floor(); for (int i = from.x; i <= to.x; i++) { @@ -574,8 +574,8 @@ int BroadPhase2DHashGrid::cull_aabb(const Rect2 &p_aabb, CollisionObject2DSW **p pass++; - Point2i from = (p_aabb.pos / cell_size).floor(); - Point2i to = ((p_aabb.pos + p_aabb.size) / cell_size).floor(); + Point2i from = (p_aabb.position / cell_size).floor(); + Point2i to = ((p_aabb.position + p_aabb.size) / cell_size).floor(); int cullcount = 0; for (int i = from.x; i <= to.x; i++) { diff --git a/servers/physics_2d/collision_object_2d_sw.cpp b/servers/physics_2d/collision_object_2d_sw.cpp index 265b5bb836..b6c1d145df 100644 --- a/servers/physics_2d/collision_object_2d_sw.cpp +++ b/servers/physics_2d/collision_object_2d_sw.cpp @@ -169,7 +169,7 @@ void CollisionObject2DSW::_update_shapes_with_motion(const Vector2 &p_motion) { Rect2 shape_aabb = s.shape->get_aabb(); Transform2D xform = transform * s.xform; shape_aabb = xform.xform(shape_aabb); - shape_aabb = shape_aabb.merge(Rect2(shape_aabb.pos + p_motion, shape_aabb.size)); //use motion + shape_aabb = shape_aabb.merge(Rect2(shape_aabb.position + p_motion, shape_aabb.size)); //use motion s.aabb_cache = shape_aabb; space->get_broadphase()->move(s.bpid, shape_aabb); diff --git a/servers/physics_2d/collision_solver_2d_sw.cpp b/servers/physics_2d/collision_solver_2d_sw.cpp index e57d1b7044..b482f826c2 100644 --- a/servers/physics_2d/collision_solver_2d_sw.cpp +++ b/servers/physics_2d/collision_solver_2d_sw.cpp @@ -203,7 +203,7 @@ bool CollisionSolver2DSW::solve_concave(const Shape2DSW *p_shape_A, const Transf smin *= axis_scale; smax *= axis_scale; - local_aabb.pos[i] = smin; + local_aabb.position[i] = smin; local_aabb.size[i] = smax - smin; } diff --git a/servers/physics_2d/shape_2d_sw.cpp b/servers/physics_2d/shape_2d_sw.cpp index 203a1052b2..245b4e15bc 100644 --- a/servers/physics_2d/shape_2d_sw.cpp +++ b/servers/physics_2d/shape_2d_sw.cpp @@ -246,12 +246,12 @@ void SegmentShape2DSW::set_data(const Variant &p_data) { ERR_FAIL_COND(p_data.get_type() != Variant::RECT2); Rect2 r = p_data; - a = r.pos; + a = r.position; b = r.size; n = (b - a).tangent(); Rect2 aabb; - aabb.pos = a; + aabb.position = a; aabb.expand_to(b); if (aabb.size.x == 0) aabb.size.x = 0.001; @@ -263,7 +263,7 @@ void SegmentShape2DSW::set_data(const Variant &p_data) { Variant SegmentShape2DSW::get_data() const { Rect2 r; - r.pos = a; + r.position = a; r.size = b; return r; } @@ -621,13 +621,13 @@ bool ConvexPolygonShape2DSW::intersect_segment(const Vector2 &p_begin, const Vec real_t ConvexPolygonShape2DSW::get_moment_of_inertia(real_t p_mass, const Size2 &p_scale) const { Rect2 aabb; - aabb.pos = points[0].pos * p_scale; + aabb.position = points[0].pos * p_scale; for (int i = 0; i < point_count; i++) { aabb.expand_to(points[i].pos * p_scale); } - return p_mass * aabb.size.dot(aabb.size) / 12.0 + p_mass * (aabb.pos + aabb.size * 0.5).length_squared(); + return p_mass * aabb.size.dot(aabb.size) / 12.0 + p_mass * (aabb.position + aabb.size * 0.5).length_squared(); } void ConvexPolygonShape2DSW::set_data(const Variant &p_data) { @@ -677,7 +677,7 @@ void ConvexPolygonShape2DSW::set_data(const Variant &p_data) { ERR_FAIL_COND(point_count == 0); Rect2 aabb; - aabb.pos = points[0].pos; + aabb.position = points[0].pos; for (int i = 1; i < point_count; i++) aabb.expand_to(points[i].pos); @@ -942,7 +942,7 @@ void ConcavePolygonShape2DSW::set_data(const Variant &p_data) { } points.resize(pointmap.size()); - aabb.pos = pointmap.front()->key(); + aabb.position = pointmap.front()->key(); for (Map<Point2, int>::Element *E = pointmap.front(); E; E = E->next()) { aabb.expand_to(E->key()); @@ -953,7 +953,7 @@ void ConcavePolygonShape2DSW::set_data(const Variant &p_data) { main_vbh.resize(segments.size()); for (int i = 0; i < main_vbh.size(); i++) { - main_vbh[i].aabb.pos = points[segments[i].points[0]]; + main_vbh[i].aabb.position = points[segments[i].points[0]]; main_vbh[i].aabb.expand_to(points[segments[i].points[1]]); main_vbh[i].left = -1; main_vbh[i].right = i; diff --git a/servers/physics_2d/shape_2d_sw.h b/servers/physics_2d/shape_2d_sw.h index 547ecdcd11..4cc98b7f1e 100644 --- a/servers/physics_2d/shape_2d_sw.h +++ b/servers/physics_2d/shape_2d_sw.h @@ -513,7 +513,7 @@ class ConcavePolygonShape2DSW : public ConcaveShape2DSW { _FORCE_INLINE_ bool operator()(const BVH &a, const BVH &b) const { - return (a.aabb.pos.x + a.aabb.size.x * 0.5) < (b.aabb.pos.x + b.aabb.size.x * 0.5); + return (a.aabb.position.x + a.aabb.size.x * 0.5) < (b.aabb.position.x + b.aabb.size.x * 0.5); } }; @@ -521,7 +521,7 @@ class ConcavePolygonShape2DSW : public ConcaveShape2DSW { _FORCE_INLINE_ bool operator()(const BVH &a, const BVH &b) const { - return (a.aabb.pos.y + a.aabb.size.y * 0.5) < (b.aabb.pos.y + b.aabb.size.y * 0.5); + return (a.aabb.position.y + a.aabb.size.y * 0.5) < (b.aabb.position.y + b.aabb.size.y * 0.5); } }; diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index ac479aab7a..78b1e84734 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -50,7 +50,7 @@ int Physics2DDirectSpaceStateSW::intersect_point(const Vector2 &p_point, ShapeRe return 0; Rect2 aabb; - aabb.pos = p_point - Vector2(0.00001, 0.00001); + aabb.position = p_point - Vector2(0.00001, 0.00001); aabb.size = Vector2(0.00002, 0.00002); int amount = space->broadphase->cull_aabb(aabb, space->intersection_query_results, Space2DSW::INTERSECTION_QUERY_MAX, space->intersection_query_subindex_results); @@ -223,7 +223,7 @@ bool Physics2DDirectSpaceStateSW::cast_motion(const RID &p_shape, const Transfor ERR_FAIL_COND_V(!shape, false); Rect2 aabb = p_xform.xform(shape->get_aabb()); - aabb = aabb.merge(Rect2(aabb.pos + p_motion, aabb.size)); //motion + aabb = aabb.merge(Rect2(aabb.position + p_motion, aabb.size)); //motion aabb = aabb.grow(p_margin); /* @@ -339,7 +339,7 @@ bool Physics2DDirectSpaceStateSW::collide_shape(RID p_shape, const Transform2D & ERR_FAIL_COND_V(!shape, 0); Rect2 aabb = p_shape_xform.xform(shape->get_aabb()); - aabb = aabb.merge(Rect2(aabb.pos + p_motion, aabb.size)); //motion + aabb = aabb.merge(Rect2(aabb.position + p_motion, aabb.size)); //motion aabb = aabb.grow(p_margin); int amount = space->broadphase->cull_aabb(aabb, space->intersection_query_results, Space2DSW::INTERSECTION_QUERY_MAX, space->intersection_query_subindex_results); @@ -434,7 +434,7 @@ bool Physics2DDirectSpaceStateSW::rest_info(RID p_shape, const Transform2D &p_sh ERR_FAIL_COND_V(!shape, 0); Rect2 aabb = p_shape_xform.xform(shape->get_aabb()); - aabb = aabb.merge(Rect2(aabb.pos + p_motion, aabb.size)); //motion + aabb = aabb.merge(Rect2(aabb.position + p_motion, aabb.size)); //motion aabb = aabb.grow(p_margin); int amount = space->broadphase->cull_aabb(aabb, space->intersection_query_results, Space2DSW::INTERSECTION_QUERY_MAX, space->intersection_query_subindex_results); @@ -656,7 +656,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co } body_transform.elements[2] += recover_motion; - body_aabb.pos += recover_motion; + body_aabb.position += recover_motion; recover_attempts--; @@ -671,7 +671,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co // STEP 2 ATTEMPT MOTION Rect2 motion_aabb = body_aabb; - motion_aabb.pos += p_motion; + motion_aabb.position += p_motion; motion_aabb = motion_aabb.merge(body_aabb); int amount = _cull_aabb_for_body(p_body, motion_aabb); @@ -807,7 +807,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co Transform2D body_shape_xform = ugt * p_body->get_shape_transform(best_shape); Shape2DSW *body_shape = p_body->get_shape(best_shape); - body_aabb.pos += p_motion * unsafe; + body_aabb.position += p_motion * unsafe; int amount = _cull_aabb_for_body(p_body, body_aabb); diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index 4b274acd9e..9dfb0b2e71 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -71,6 +71,10 @@ public: virtual void environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, RID p_ramp) = 0; + virtual void environment_set_fog(RID p_env, bool p_enable, const Color &p_color, const Color &p_sun_color, float p_sun_amount) = 0; + virtual void environment_set_fog_depth(RID p_env, bool p_enable, float p_depth_begin, float p_depth_curve, bool p_transmit, float p_transmit_curve) = 0; + virtual void environment_set_fog_height(RID p_env, bool p_enable, float p_min_height, float p_max_height, float p_height_curve) = 0; + struct InstanceBase : RID_Data { VS::InstanceType base_type; @@ -769,7 +773,7 @@ public: case Item::Command::TYPE_LINE: { const Item::CommandLine *line = static_cast<const Item::CommandLine *>(c); - r.pos = line->from; + r.position = line->from; r.expand_to(line->to); } break; case Item::Command::TYPE_RECT: { @@ -786,7 +790,7 @@ public: case Item::Command::TYPE_PRIMITIVE: { const Item::CommandPrimitive *primitive = static_cast<const Item::CommandPrimitive *>(c); - r.pos = primitive->points[0]; + r.position = primitive->points[0]; for (int i = 1; i < primitive->points.size(); i++) { r.expand_to(primitive->points[i]); @@ -797,7 +801,7 @@ public: const Item::CommandPolygon *polygon = static_cast<const Item::CommandPolygon *>(c); int l = polygon->points.size(); const Point2 *pp = &polygon->points[0]; - r.pos = pp[0]; + r.position = pp[0]; for (int i = 1; i < l; i++) { r.expand_to(pp[i]); @@ -822,7 +826,7 @@ public: case Item::Command::TYPE_CIRCLE: { const Item::CommandCircle *circle = static_cast<const Item::CommandCircle *>(c); - r.pos = Point2(-circle->radius, -circle->radius) + circle->pos; + r.position = Point2(-circle->radius, -circle->radius) + circle->pos; r.size = Point2(circle->radius * 2.0, circle->radius * 2.0); } break; case Item::Command::TYPE_TRANSFORM: { diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index 9fe92f0fec..319351f8ec 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -3185,7 +3185,7 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Dat tk = _get_token(); if (tk.type != TK_PARENTHESIS_CLOSE) { - _set_error("Expected '(' after expression"); + _set_error("Expected ')' after expression"); return ERR_PARSE_ERROR; } @@ -3196,6 +3196,8 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Dat p_block->statements.push_back(cf); Error err = _parse_block(block, p_builtin_types, true, p_can_break, p_can_continue); + if (err) + return err; pos = _get_tkpos(); tk = _get_token(); @@ -3209,6 +3211,35 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Dat } else { _set_tkpos(pos); //rollback } + } else if (tk.type == TK_CF_WHILE) { + //if () {} + tk = _get_token(); + if (tk.type != TK_PARENTHESIS_OPEN) { + _set_error("Expected '(' after if"); + return ERR_PARSE_ERROR; + } + + ControlFlowNode *cf = alloc_node<ControlFlowNode>(); + cf->flow_op = FLOW_OP_WHILE; + Node *n = _parse_and_reduce_expression(p_block, p_builtin_types); + if (!n) + return ERR_PARSE_ERROR; + + tk = _get_token(); + if (tk.type != TK_PARENTHESIS_CLOSE) { + _set_error("Expected ')' after expression"); + return ERR_PARSE_ERROR; + } + + BlockNode *block = alloc_node<BlockNode>(); + block->parent_block = p_block; + cf->expressions.push_back(n); + cf->blocks.push_back(block); + p_block->statements.push_back(cf); + + Error err = _parse_block(block, p_builtin_types, true, p_can_break, p_can_continue); + if (err) + return err; } else if (tk.type == TK_CF_RETURN) { diff --git a/servers/visual/shader_types.cpp b/servers/visual/shader_types.cpp index 8d72ee3f34..e0201420fe 100644 --- a/servers/visual/shader_types.cpp +++ b/servers/visual/shader_types.cpp @@ -52,7 +52,6 @@ ShaderTypes::ShaderTypes() { shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["SRC_VERTEX"] = ShaderLanguage::TYPE_VEC3; shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["SRC_NORMAL"] = ShaderLanguage::TYPE_VEC3; - shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["SRC_TANGENT"] = ShaderLanguage::TYPE_VEC4; shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["SRC_BONES"] = ShaderLanguage::TYPE_IVEC4; shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["SRC_WEIGHTS"] = ShaderLanguage::TYPE_VEC4; @@ -91,7 +90,8 @@ ShaderTypes::ShaderTypes() { shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["NORMAL"] = ShaderLanguage::TYPE_VEC3; shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["ALBEDO"] = ShaderLanguage::TYPE_VEC3; shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["ALPHA"] = ShaderLanguage::TYPE_FLOAT; - shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["SPECULAR"] = ShaderLanguage::TYPE_VEC3; + shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["METALLIC"] = ShaderLanguage::TYPE_FLOAT; + shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["SPECULAR"] = ShaderLanguage::TYPE_FLOAT; shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["ROUGHNESS"] = ShaderLanguage::TYPE_FLOAT; shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["RIM"] = ShaderLanguage::TYPE_FLOAT; shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["RIM_TINT"] = ShaderLanguage::TYPE_FLOAT; @@ -104,8 +104,11 @@ ShaderTypes::ShaderTypes() { shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["EMISSION"] = ShaderLanguage::TYPE_VEC3; shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["SPECIAL"] = ShaderLanguage::TYPE_FLOAT; shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["DISCARD"] = ShaderLanguage::TYPE_BOOL; + shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["SCREEN_TEXTURE"] = ShaderLanguage::TYPE_SAMPLER2D; + shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["DEPTH_TEXTURE"] = ShaderLanguage::TYPE_SAMPLER2D; shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["SCREEN_UV"] = ShaderLanguage::TYPE_VEC2; shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["POINT_COORD"] = ShaderLanguage::TYPE_VEC2; + shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["SIDE"] = ShaderLanguage::TYPE_FLOAT; shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["WORLD_MATRIX"] = ShaderLanguage::TYPE_MAT4; shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["INV_CAMERA_MATRIX"] = ShaderLanguage::TYPE_MAT4; @@ -130,6 +133,11 @@ ShaderTypes::ShaderTypes() { shader_modes[VS::SHADER_SPATIAL].modes.insert("unshaded"); shader_modes[VS::SHADER_SPATIAL].modes.insert("ontop"); + shader_modes[VS::SHADER_SPATIAL].modes.insert("diffuse_lambert"); + shader_modes[VS::SHADER_SPATIAL].modes.insert("diffuse_half_lambert"); + shader_modes[VS::SHADER_SPATIAL].modes.insert("diffuse_oren_nayar"); + shader_modes[VS::SHADER_SPATIAL].modes.insert("diffuse_burley"); + shader_modes[VS::SHADER_SPATIAL].modes.insert("skip_default_transform"); /************ CANVAS ITEM **************************/ @@ -165,8 +173,6 @@ ShaderTypes::ShaderTypes() { shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"]["COLOR"] = ShaderLanguage::TYPE_VEC4; shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"]["TEXTURE"] = ShaderLanguage::TYPE_SAMPLER2D; shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"]["TEXTURE_PIXEL_SIZE"] = ShaderLanguage::TYPE_VEC2; - shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"]["VAR1"] = ShaderLanguage::TYPE_VEC4; - shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"]["VAR2"] = ShaderLanguage::TYPE_VEC4; shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"]["SCREEN_UV"] = ShaderLanguage::TYPE_VEC2; shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"]["LIGHT_VEC"] = ShaderLanguage::TYPE_VEC2; shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"]["LIGHT_HEIGHT"] = ShaderLanguage::TYPE_FLOAT; diff --git a/servers/visual/visual_server_canvas.cpp b/servers/visual/visual_server_canvas.cpp index 3a83ba887d..14a7af3e6e 100644 --- a/servers/visual/visual_server_canvas.cpp +++ b/servers/visual/visual_server_canvas.cpp @@ -61,7 +61,7 @@ void VisualServerCanvas::_render_canvas_item(Item *p_canvas_item, const Transfor Rect2 rect = ci->get_rect(); Transform2D xform = p_transform * ci->xform; Rect2 global_rect = xform.xform(rect); - global_rect.pos += p_clip_rect.pos; + global_rect.position += p_clip_rect.position; if (ci->use_parent_material && p_material_owner) ci->material_owner = p_material_owner; @@ -119,7 +119,7 @@ void VisualServerCanvas::_render_canvas_item(Item *p_canvas_item, const Transfor ci->final_transform = xform; ci->final_modulate = Color(modulate.r * ci->self_modulate.r, modulate.g * ci->self_modulate.g, modulate.b * ci->self_modulate.b, modulate.a * ci->self_modulate.a); ci->global_rect_cache = global_rect; - ci->global_rect_cache.pos -= p_clip_rect.pos; + ci->global_rect_cache.position -= p_clip_rect.position; ci->light_masked = false; int zidx = p_z - VS::CANVAS_ITEM_Z_MIN; @@ -233,7 +233,6 @@ void VisualServerCanvas::render_canvas(Canvas *p_canvas, const Transform2D &p_tr } VSG::canvas_render->canvas_end(); - } RID VisualServerCanvas::canvas_create() { @@ -1041,7 +1040,7 @@ void VisualServerCanvas::canvas_occluder_polygon_set_shape_as_lines(RID p_occlud PoolVector<Vector2>::Read r = p_shape.read(); for (int i = 0; i < lc; i++) { if (i == 0) - occluder_poly->aabb.pos = r[i]; + occluder_poly->aabb.position = r[i]; else occluder_poly->aabb.expand_to(r[i]); } diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 957af7b9dd..8c311300ad 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -950,6 +950,10 @@ public: BIND6(environment_set_adjustment, RID, bool, float, float, float, RID) + BIND5(environment_set_fog, RID, bool, const Color &, const Color &, float) + BIND6(environment_set_fog_depth, RID, bool, float, float, bool, float) + BIND5(environment_set_fog_height, RID, bool, float, float, float) + /* SCENARIO API */ #undef BINDBASE diff --git a/servers/visual/visual_server_viewport.cpp b/servers/visual/visual_server_viewport.cpp index 63ed0ac7c4..c1f1922255 100644 --- a/servers/visual/visual_server_viewport.cpp +++ b/servers/visual/visual_server_viewport.cpp @@ -133,7 +133,7 @@ void VisualServerViewport::_draw_viewport(Viewport *p_viewport) { cl->texture_cache = NULL; Transform2D scale; scale.scale(cl->rect_cache.size); - scale.elements[2] = cl->rect_cache.pos; + scale.elements[2] = cl->rect_cache.position; cl->light_shader_xform = (cl->xform_cache * scale).affine_inverse(); cl->light_shader_pos = cl->xform_cache[2]; if (cl->shadow_buffer.is_valid()) { diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index 5df1ca456b..498b7dcc43 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -399,7 +399,7 @@ Error VisualServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint32_ } } - r_aabb = Rect3(Vector3(aabb.pos.x, aabb.pos.y, 0), Vector3(aabb.size.x, aabb.size.y, 0)); + r_aabb = Rect3(Vector3(aabb.position.x, aabb.position.y, 0), Vector3(aabb.size.x, aabb.size.y, 0)); } else { PoolVector<Vector3> array = p_arrays[ai]; diff --git a/servers/visual_server.h b/servers/visual_server.h index aa98d47455..3d5ca9d99a 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -638,6 +638,10 @@ public: virtual void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_accel, float p_fade, float p_depth_tolerance, bool p_smooth, bool p_roughness) = 0; virtual void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_radius2, float p_intensity2, float p_bias, float p_light_affect, const Color &p_color, bool p_blur) = 0; + virtual void environment_set_fog(RID p_env, bool p_enable, const Color &p_color, const Color &p_sun_color, float p_sun_amount) = 0; + virtual void environment_set_fog_depth(RID p_env, bool p_enable, float p_depth_begin, float p_depth_curve, bool p_transmit, float p_transmit_curve) = 0; + virtual void environment_set_fog_height(RID p_env, bool p_enable, float p_min_height, float p_max_height, float p_height_curve) = 0; + /* SCENARIO API */ virtual RID scenario_create() = 0; |