diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/2d/sprite.cpp | 13 | ||||
-rw-r--r-- | scene/gui/dialogs.cpp | 4 | ||||
-rw-r--r-- | scene/gui/item_list.cpp | 34 | ||||
-rw-r--r-- | scene/gui/item_list.h | 8 | ||||
-rw-r--r-- | scene/gui/line_edit.cpp | 6 | ||||
-rw-r--r-- | scene/gui/range.cpp | 4 | ||||
-rw-r--r-- | scene/gui/tabs.cpp | 13 | ||||
-rw-r--r-- | scene/gui/tabs.h | 6 | ||||
-rw-r--r-- | scene/main/scene_tree.cpp | 14 | ||||
-rw-r--r-- | scene/main/scene_tree.h | 3 | ||||
-rw-r--r-- | scene/resources/dynamic_font.cpp | 4 | ||||
-rw-r--r-- | scene/resources/material.cpp | 10 | ||||
-rw-r--r-- | scene/resources/material.h | 1 | ||||
-rw-r--r-- | scene/resources/mesh.cpp | 2 | ||||
-rw-r--r-- | scene/resources/mesh.h | 2 | ||||
-rw-r--r-- | scene/resources/primitive_meshes.cpp | 148 | ||||
-rw-r--r-- | scene/resources/primitive_meshes.h | 27 | ||||
-rw-r--r-- | scene/resources/sky_box.cpp | 20 | ||||
-rw-r--r-- | scene/resources/sky_box.h | 5 |
19 files changed, 205 insertions, 119 deletions
diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp index 450f8e2474..b469013819 100644 --- a/scene/2d/sprite.cpp +++ b/scene/2d/sprite.cpp @@ -105,20 +105,7 @@ void Sprite::set_texture(const Ref<Texture> &p_texture) { if (p_texture == texture) return; -#ifdef DEBUG_ENABLED - if (texture.is_valid()) { - texture->disconnect(CoreStringNames::get_singleton()->changed, this, SceneStringNames::get_singleton()->update); - } -#endif texture = p_texture; - /* this should no longer be needed in 3.0 -#ifdef DEBUG_ENABLED - if (texture.is_valid()) { - texture->set_flags(texture->get_flags()); //remove repeat from texture, it looks bad in sprites - texture->connect(CoreStringNames::get_singleton()->changed, this, SceneStringNames::get_singleton()->update); - } -#endif -*/ update(); emit_signal("texture_changed"); item_rect_changed(); diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 8885bec03c..7d7c636bc2 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -584,6 +584,8 @@ Button *ConfirmationDialog::get_cancel() { ConfirmationDialog::ConfirmationDialog() { set_title(RTR("Please Confirm...")); - set_custom_minimum_size(Size2(200, 70)); +#ifdef TOOLS_ENABLED + set_custom_minimum_size(Size2(200, 70) * EDSCALE); +#endif cancel = add_cancel(); } diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index eff9d801b6..97f49da2be 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -28,8 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "item_list.h" -#include "project_settings.h" #include "os/os.h" +#include "project_settings.h" void ItemList::add_item(const String &p_item, const Ref<Texture> &p_texture, bool p_selectable) { @@ -743,12 +743,10 @@ void ItemList::_notification(int p_what) { Size2 size = get_size(); - float page = size.height - bg->get_minimum_size().height; int width = size.width - bg->get_minimum_size().width; if (scroll_bar->is_visible()) { width -= mw + bg->get_margin(MARGIN_RIGHT); } - scroll_bar->set_page(page); draw_style_box(bg, Rect2(Point2(), size)); @@ -883,8 +881,12 @@ void ItemList::_notification(int p_what) { } if (all_fit) { + float page = size.height - bg->get_minimum_size().height; float max = MAX(page, ofs.y + max_h); + if (auto_height) + auto_height_value = ofs.y + max_h + bg->get_minimum_size().height; scroll_bar->set_max(max); + scroll_bar->set_page(page); //print_line("max: "+rtos(max)+" page "+rtos(page)); if (max <= page) { scroll_bar->set_value(0); @@ -1253,6 +1255,26 @@ Array ItemList::_get_items() const { return items; } +Size2 ItemList::get_minimum_size() const { + + if (auto_height) { + return Size2(0, auto_height_value); + } + return Size2(); +} + +void ItemList::set_auto_height(bool p_enable) { + + auto_height = p_enable; + shape_changed = true; + update(); +} + +bool ItemList::has_auto_height() const { + + return auto_height; +} + void ItemList::_bind_methods() { ClassDB::bind_method(D_METHOD("add_item", "text", "icon:Texture", "selectable"), &ItemList::add_item, DEFVAL(Variant()), DEFVAL(true)); @@ -1323,6 +1345,9 @@ void ItemList::_bind_methods() { ClassDB::bind_method(D_METHOD("set_allow_rmb_select", "allow"), &ItemList::set_allow_rmb_select); ClassDB::bind_method(D_METHOD("get_allow_rmb_select"), &ItemList::get_allow_rmb_select); + ClassDB::bind_method(D_METHOD("set_auto_height", "enable"), &ItemList::set_auto_height); + ClassDB::bind_method(D_METHOD("has_auto_height"), &ItemList::has_auto_height); + ClassDB::bind_method(D_METHOD("get_item_at_pos", "pos", "exact"), &ItemList::get_item_at_pos, DEFVAL(false)); ClassDB::bind_method(D_METHOD("ensure_current_is_visible"), &ItemList::ensure_current_is_visible); @@ -1340,6 +1365,7 @@ void ItemList::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "select_mode", PROPERTY_HINT_ENUM, "Single,Multi"), "set_select_mode", "get_select_mode"); ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "allow_rmb_select"), "set_allow_rmb_select", "get_allow_rmb_select"); ADD_PROPERTYNO(PropertyInfo(Variant::INT, "max_text_lines"), "set_max_text_lines", "get_max_text_lines"); + ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "auto_height"), "set_auto_height", "has_auto_height"); ADD_GROUP("Columns", ""); ADD_PROPERTYNO(PropertyInfo(Variant::INT, "max_columns"), "set_max_columns", "get_max_columns"); ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "same_column_width"), "set_same_column_width", "is_same_column_width"); @@ -1372,6 +1398,8 @@ ItemList::ItemList() { same_column_width = false; max_text_lines = 1; max_columns = 1; + auto_height = false; + auto_height_value = 0.0f; scroll_bar = memnew(VScrollBar); add_child(scroll_bar); diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h index 9cb7016b60..137eff8885 100644 --- a/scene/gui/item_list.h +++ b/scene/gui/item_list.h @@ -78,6 +78,9 @@ private: bool ensure_selected_visible; bool same_column_width; + bool auto_height; + float auto_height_value; + Vector<Item> items; Vector<int> separators; @@ -198,6 +201,11 @@ public: void set_icon_scale(real_t p_scale); real_t get_icon_scale() const; + void set_auto_height(bool p_enable); + bool has_auto_height() const; + + Size2 get_minimum_size() const; + VScrollBar *get_v_scroll() { return scroll_bar; } ItemList(); diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index adcf86357d..f4dd3e92cd 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -628,6 +628,12 @@ void LineEdit::_notification(int p_what) { font_color.a *= placeholder_alpha; font_color.a *= disabled_alpha; + if (has_icon("right_icon")) { + Ref<Texture> r_icon = Control::get_icon("right_icon"); + ofs_max -= r_icon->get_width(); + r_icon->draw(ci, Point2(width - r_icon->get_width() - x_ofs, y_ofs), Color(1, 1, 1, disabled_alpha * .9)); + } + int caret_height = font->get_height() > y_area ? y_area : font->get_height(); while (true) { diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp index b57085923e..6bec365dcf 100644 --- a/scene/gui/range.cpp +++ b/scene/gui/range.cpp @@ -273,8 +273,8 @@ Range::Range() { shared = memnew(Shared); shared->min = 0; shared->max = 100; - shared->val = - shared->step = 1; + shared->val = 0; + shared->step = 1; shared->page = 0; shared->owners.insert(this); shared->exp_ratio = false; diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index ee0ae1fb41..c477a3156f 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -630,6 +630,7 @@ int Tabs::get_tab_idx_at_point(const Point2 &p_point) const { void Tabs::set_tab_align(TabAlign p_align) { + ERR_FAIL_INDEX(p_align, ALIGN_MAX); tab_align = p_align; update(); } @@ -764,10 +765,17 @@ Rect2 Tabs::get_tab_rect(int p_tab) const { } void Tabs::set_tab_close_display_policy(CloseButtonDisplayPolicy p_policy) { + + ERR_FAIL_INDEX(p_policy, CLOSE_BUTTON_MAX); cb_displaypolicy = p_policy; update(); } +Tabs::CloseButtonDisplayPolicy Tabs::get_tab_close_display_policy() const { + + return cb_displaypolicy; +} + void Tabs::set_min_width(int p_width) { min_width = p_width; } @@ -791,6 +799,8 @@ void Tabs::_bind_methods() { ClassDB::bind_method(D_METHOD("ensure_tab_visible", "idx"), &Tabs::ensure_tab_visible); ClassDB::bind_method(D_METHOD("get_tab_rect", "tab_idx"), &Tabs::get_tab_rect); ClassDB::bind_method(D_METHOD("move_tab", "from", "to"), &Tabs::move_tab); + ClassDB::bind_method(D_METHOD("set_tab_close_display_policy", "policy"), &Tabs::set_tab_close_display_policy); + ClassDB::bind_method(D_METHOD("get_tab_close_display_policy"), &Tabs::get_tab_close_display_policy); ADD_SIGNAL(MethodInfo("tab_changed", PropertyInfo(Variant::INT, "tab"))); ADD_SIGNAL(MethodInfo("right_button_pressed", PropertyInfo(Variant::INT, "tab"))); @@ -799,14 +809,17 @@ void Tabs::_bind_methods() { ADD_SIGNAL(MethodInfo("reposition_active_tab_request", PropertyInfo(Variant::INT, "idx_to"))); ADD_PROPERTY(PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE, "-1,4096,1", PROPERTY_USAGE_EDITOR), "set_current_tab", "get_current_tab"); + ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "tab_close_display_policy", PROPERTY_HINT_ENUM, "Show Never,Show Active Only,Show Always"), "set_tab_close_display_policy", "get_tab_close_display_policy"); BIND_CONSTANT(ALIGN_LEFT); BIND_CONSTANT(ALIGN_CENTER); BIND_CONSTANT(ALIGN_RIGHT); + BIND_CONSTANT(ALIGN_MAX); BIND_CONSTANT(CLOSE_BUTTON_SHOW_ACTIVE_ONLY); BIND_CONSTANT(CLOSE_BUTTON_SHOW_ALWAYS); BIND_CONSTANT(CLOSE_BUTTON_SHOW_NEVER); + BIND_CONSTANT(CLOSE_BUTTON_MAX); } Tabs::Tabs() { diff --git a/scene/gui/tabs.h b/scene/gui/tabs.h index a9dd6bddd7..86ad128dcd 100644 --- a/scene/gui/tabs.h +++ b/scene/gui/tabs.h @@ -41,7 +41,8 @@ public: ALIGN_LEFT, ALIGN_CENTER, - ALIGN_RIGHT + ALIGN_RIGHT, + ALIGN_MAX }; enum CloseButtonDisplayPolicy { @@ -49,6 +50,7 @@ public: CLOSE_BUTTON_SHOW_NEVER, CLOSE_BUTTON_SHOW_ACTIVE_ONLY, CLOSE_BUTTON_SHOW_ALWAYS, + CLOSE_BUTTON_MAX }; private: @@ -122,6 +124,7 @@ public: void move_tab(int from, int to); void set_tab_close_display_policy(CloseButtonDisplayPolicy p_policy); + CloseButtonDisplayPolicy get_tab_close_display_policy() const; int get_tab_count() const; void set_current_tab(int p_current); @@ -142,5 +145,6 @@ public: }; VARIANT_ENUM_CAST(Tabs::TabAlign); +VARIANT_ENUM_CAST(Tabs::CloseButtonDisplayPolicy); #endif // TABS_H diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 9783f3d4b8..48e6a44745 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -1153,7 +1153,7 @@ void SceneTree::_update_root_rect() { if (stretch_mode == STRETCH_MODE_DISABLED) { - root->set_size(last_screen_size); + root->set_size((last_screen_size / stretch_shrink).floor()); root->set_attach_to_screen_rect(Rect2(Point2(), last_screen_size)); root->set_size_override_stretch(false); root->set_size_override(false, Size2()); @@ -1231,15 +1231,15 @@ void SceneTree::_update_root_rect() { switch (stretch_mode) { case STRETCH_MODE_2D: { - root->set_size(screen_size); + root->set_size((screen_size / stretch_shrink).floor()); root->set_attach_to_screen_rect(Rect2(margin, screen_size)); root->set_size_override_stretch(true); - root->set_size_override(true, viewport_size); + root->set_size_override(true, (viewport_size / stretch_shrink).floor()); } break; case STRETCH_MODE_VIEWPORT: { - root->set_size(viewport_size); + root->set_size((viewport_size / stretch_shrink).floor()); root->set_attach_to_screen_rect(Rect2(margin, screen_size)); root->set_size_override_stretch(false); root->set_size_override(false, Size2()); @@ -1248,11 +1248,12 @@ void SceneTree::_update_root_rect() { } } -void SceneTree::set_screen_stretch(StretchMode p_mode, StretchAspect p_aspect, const Size2 p_minsize) { +void SceneTree::set_screen_stretch(StretchMode p_mode, StretchAspect p_aspect, const Size2 p_minsize, int p_shrink) { stretch_mode = p_mode; stretch_aspect = p_aspect; stretch_min = p_minsize; + stretch_shrink = p_shrink; _update_root_rect(); } @@ -2207,7 +2208,7 @@ void SceneTree::_bind_methods() { ClassDB::bind_method(D_METHOD("get_frame"), &SceneTree::get_frame); ClassDB::bind_method(D_METHOD("quit"), &SceneTree::quit); - ClassDB::bind_method(D_METHOD("set_screen_stretch", "mode", "aspect", "minsize"), &SceneTree::set_screen_stretch); + ClassDB::bind_method(D_METHOD("set_screen_stretch", "mode", "aspect", "minsize", "shrink"), &SceneTree::set_screen_stretch, DEFVAL(1)); ClassDB::bind_method(D_METHOD("queue_delete", "obj"), &SceneTree::queue_delete); @@ -2395,6 +2396,7 @@ SceneTree::SceneTree() { stretch_mode = STRETCH_MODE_DISABLED; stretch_aspect = STRETCH_ASPECT_IGNORE; + stretch_shrink = 1; last_screen_size = Size2(OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height); _update_root_rect(); diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h index 76a4becdbc..90d42ef01b 100644 --- a/scene/main/scene_tree.h +++ b/scene/main/scene_tree.h @@ -149,6 +149,7 @@ private: StretchMode stretch_mode; StretchAspect stretch_aspect; Size2i stretch_min; + int stretch_shrink; void _update_root_rect(); @@ -420,7 +421,7 @@ public: void get_nodes_in_group(const StringName &p_group, List<Node *> *p_list); bool has_group(const StringName &p_identifier) const; - void set_screen_stretch(StretchMode p_mode, StretchAspect p_aspect, const Size2 p_minsize); + void set_screen_stretch(StretchMode p_mode, StretchAspect p_aspect, const Size2 p_minsize, int p_shrink = 1); //void change_scene(const String& p_path); //Node *get_loaded_scene(); diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index d2848076a0..2fdc4c9e24 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -338,7 +338,7 @@ float DynamicFontAtSize::draw_char(RID p_canvas_item, const Point2 &p_pos, CharT cpos.y += ch->v_align; ERR_FAIL_COND_V(ch->texture_idx < -1 || ch->texture_idx >= fb->textures.size(), 0); if (ch->texture_idx != -1) - VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, ch->rect.size), fb->textures[ch->texture_idx].texture->get_rid(), ch->rect, p_modulate); + VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, ch->rect.size), fb->textures[ch->texture_idx].texture->get_rid(), ch->rect, p_modulate, false, RID(), false); advance = ch->advance; used_fallback = true; break; @@ -360,7 +360,7 @@ float DynamicFontAtSize::draw_char(RID p_canvas_item, const Point2 &p_pos, CharT cpos.y += c->v_align; ERR_FAIL_COND_V(c->texture_idx < -1 || c->texture_idx >= textures.size(), 0); if (c->texture_idx != -1) - VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, c->rect.size), textures[c->texture_idx].texture->get_rid(), c->rect, p_modulate); + VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, c->rect.size), textures[c->texture_idx].texture->get_rid(), c->rect, p_modulate, false, RID(), false); advance = c->advance; //textures[c->texture_idx].texture->draw(p_canvas_item,Vector2()); } diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index d7c3d26ebc..24ec39afe3 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -334,6 +334,9 @@ void SpatialMaterial::_update_shader() { if (flags[FLAG_ONTOP]) { code += ",ontop"; } + if (flags[FLAG_USE_VERTEX_LIGHTING]) { + code += ",vertex_lighting"; + } if (flags[FLAG_UV1_USE_TRIPLANAR] || flags[FLAG_UV2_USE_TRIPLANAR]) { code += ",world_vertex_coords"; @@ -444,6 +447,11 @@ void SpatialMaterial::_update_shader() { code += "\tPOINT_SIZE=point_size;\n"; } + if (flags[FLAG_USE_VERTEX_LIGHTING]) { + + code += "\tROUGHNESS=roughness;\n"; + } + if (!flags[FLAG_UV1_USE_TRIPLANAR]) { code += "\tUV=UV*uv1_scale.xy+uv1_offset.xy;\n"; } @@ -1450,6 +1458,7 @@ void SpatialMaterial::_bind_methods() { 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); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_vertex_lighting"), "set_flag", "get_flag", FLAG_USE_VERTEX_LIGHTING); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_on_top"), "set_flag", "get_flag", FLAG_ONTOP); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_use_point_size"), "set_flag", "get_flag", FLAG_USE_POINT_SIZE); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_fixed_size"), "set_flag", "get_flag", FLAG_FIXED_SIZE); @@ -1605,6 +1614,7 @@ void SpatialMaterial::_bind_methods() { BIND_CONSTANT(CULL_DISABLED); BIND_CONSTANT(FLAG_UNSHADED); + BIND_CONSTANT(FLAG_USE_VERTEX_LIGHTING); BIND_CONSTANT(FLAG_ONTOP); BIND_CONSTANT(FLAG_ALBEDO_FROM_VERTEX_COLOR); BIND_CONSTANT(FLAG_SRGB_VERTEX_COLOR) diff --git a/scene/resources/material.h b/scene/resources/material.h index 276064bce4..7587fc7927 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -155,6 +155,7 @@ public: enum Flags { FLAG_UNSHADED, + FLAG_USE_VERTEX_LIGHTING, FLAG_ONTOP, FLAG_ALBEDO_FROM_VERTEX_COLOR, FLAG_SRGB_VERTEX_COLOR, diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 414d0a6240..310ab5e371 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -32,7 +32,7 @@ #include "scene/resources/convex_polygon_shape.h" #include "surface_tool.h" -void Mesh::_clear_triangle_mesh() { +void Mesh::_clear_triangle_mesh() const { triangle_mesh.unref(); ; diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h index 4adb871e09..e40ef99237 100644 --- a/scene/resources/mesh.h +++ b/scene/resources/mesh.h @@ -44,7 +44,7 @@ class Mesh : public Resource { mutable Ref<TriangleMesh> triangle_mesh; //cached protected: - void _clear_triangle_mesh(); + void _clear_triangle_mesh() const; static void _bind_methods(); diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp index 81cfd0e5f0..327de2f6f3 100644 --- a/scene/resources/primitive_meshes.cpp +++ b/scene/resources/primitive_meshes.cpp @@ -34,42 +34,44 @@ /** PrimitiveMesh */ -void PrimitiveMesh::_update() { - if (!cache_is_dirty) - return; +void PrimitiveMesh::_update() const { Array arr; arr.resize(VS::ARRAY_MAX); _create_mesh_array(arr); + PoolVector<Vector3> points = arr[VS::ARRAY_VERTEX]; + + aabb = Rect3(); + + int pc = points.size(); + ERR_FAIL_COND(pc == 0); + { + + PoolVector<Vector3>::Read r = points.read(); + for (int i = 0; i < pc; i++) { + if (i == 0) + aabb.position = r[i]; + else + aabb.expand_to(r[i]); + } + } + // in with the new VisualServer::get_singleton()->mesh_clear(mesh); VisualServer::get_singleton()->mesh_add_surface_from_arrays(mesh, (VisualServer::PrimitiveType)primitive_type, arr); VisualServer::get_singleton()->mesh_surface_set_material(mesh, 0, material.is_null() ? RID() : material->get_rid()); - cache_is_dirty = false; + pending_request = false; _clear_triangle_mesh(); - emit_changed(); } -void PrimitiveMesh::_queue_update(bool p_first_mesh) { +void PrimitiveMesh::_request_update() { - if (first_mesh && p_first_mesh) { - first_mesh = false; - cache_is_dirty = true; - _update(); + if (pending_request) return; - } - - if (!cache_is_dirty) { - cache_is_dirty = true; - call_deferred("_update"); - } -} - -void PrimitiveMesh::set_aabb(Rect3 p_aabb) { - aabb = p_aabb; + _update(); } int PrimitiveMesh::get_surface_count() const { @@ -78,21 +80,37 @@ int PrimitiveMesh::get_surface_count() const { int PrimitiveMesh::surface_get_array_len(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, 1, -1); + if (pending_request) { + _update(); + } + return VisualServer::get_singleton()->mesh_surface_get_array_len(mesh, 0); } int PrimitiveMesh::surface_get_array_index_len(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, 1, -1); + if (pending_request) { + _update(); + } + return VisualServer::get_singleton()->mesh_surface_get_array_index_len(mesh, 0); } Array PrimitiveMesh::surface_get_arrays(int p_surface) const { ERR_FAIL_INDEX_V(p_surface, 1, Array()); + if (pending_request) { + _update(); + } + return VisualServer::get_singleton()->mesh_surface_get_arrays(mesh, 0); } uint32_t PrimitiveMesh::surface_get_format(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, 1, 0); + if (pending_request) { + _update(); + } + return VisualServer::get_singleton()->mesh_surface_get_format(mesh, 0); } @@ -113,10 +131,17 @@ StringName PrimitiveMesh::get_blend_shape_name(int p_index) const { } Rect3 PrimitiveMesh::get_aabb() const { + if (pending_request) { + _update(); + } + return aabb; } RID PrimitiveMesh::get_rid() const { + if (pending_request) { + _update(); + } return mesh; } @@ -131,10 +156,9 @@ void PrimitiveMesh::_bind_methods() { void PrimitiveMesh::set_material(const Ref<Material> &p_material) { material = p_material; - if (!cache_is_dirty) { + if (!pending_request) { // just apply it, else it'll happen when _update is called. VisualServer::get_singleton()->mesh_surface_set_material(mesh, 0, material.is_null() ? RID() : material->get_rid()); - _change_notify(); emit_changed(); }; @@ -152,9 +176,7 @@ PrimitiveMesh::PrimitiveMesh() { primitive_type = Mesh::PRIMITIVE_TRIANGLES; // make sure we do an update after we've finished constructing our object - cache_is_dirty = false; - first_mesh = true; - _queue_update(); + pending_request = true; } PrimitiveMesh::~PrimitiveMesh() { @@ -165,7 +187,7 @@ PrimitiveMesh::~PrimitiveMesh() { CapsuleMesh */ -void CapsuleMesh::_create_mesh_array(Array &p_arr) { +void CapsuleMesh::_create_mesh_array(Array &p_arr) const { int i, j, prevrow, thisrow, point; float x, y, z, u, v, w; float onethird = 1.0 / 3.0; @@ -173,8 +195,6 @@ void CapsuleMesh::_create_mesh_array(Array &p_arr) { // note, this has been aligned with our collision shape but I've left the descriptions as top/middle/bottom - set_aabb(Rect3(Vector3(-radius, -radius, (mid_height * -0.5) - radius), Vector3(radius * 2.0, radius * 2.0, mid_height + (2.0 * radius)))); - PoolVector<Vector3> points; PoolVector<Vector3> normals; PoolVector<float> tangents; @@ -334,7 +354,7 @@ void CapsuleMesh::_bind_methods() { void CapsuleMesh::set_radius(const float p_radius) { radius = p_radius; - _queue_update(); + _request_update(); } float CapsuleMesh::get_radius() const { @@ -343,7 +363,7 @@ float CapsuleMesh::get_radius() const { void CapsuleMesh::set_mid_height(const float p_mid_height) { mid_height = p_mid_height; - _queue_update(); + _request_update(); } float CapsuleMesh::get_mid_height() const { @@ -352,7 +372,7 @@ float CapsuleMesh::get_mid_height() const { void CapsuleMesh::set_radial_segments(const int p_segments) { radial_segments = p_segments > 4 ? p_segments : 4; - _queue_update(); + _request_update(); } int CapsuleMesh::get_radial_segments() const { @@ -361,7 +381,7 @@ int CapsuleMesh::get_radial_segments() const { void CapsuleMesh::set_rings(const int p_rings) { rings = p_rings > 1 ? p_rings : 1; - _queue_update(true); //last property set, force update mesh + _request_update(); } int CapsuleMesh::get_rings() const { @@ -380,7 +400,7 @@ CapsuleMesh::CapsuleMesh() { CubeMesh */ -void CubeMesh::_create_mesh_array(Array &p_arr) { +void CubeMesh::_create_mesh_array(Array &p_arr) const { int i, j, prevrow, thisrow, point; float x, y, z; float onethird = 1.0 / 3.0; @@ -389,7 +409,6 @@ void CubeMesh::_create_mesh_array(Array &p_arr) { Vector3 start_pos = size * -0.5; // set our bounding box - set_aabb(Rect3(start_pos, size)); PoolVector<Vector3> points; PoolVector<Vector3> normals; @@ -592,7 +611,7 @@ void CubeMesh::_bind_methods() { void CubeMesh::set_size(const Vector3 &p_size) { size = p_size; - _queue_update(); + _request_update(); } Vector3 CubeMesh::get_size() const { @@ -601,7 +620,7 @@ Vector3 CubeMesh::get_size() const { void CubeMesh::set_subdivide_width(const int p_subdivide) { subdivide_w = p_subdivide > 0 ? p_subdivide : 0; - _queue_update(); + _request_update(); } int CubeMesh::get_subdivide_width() const { @@ -610,7 +629,7 @@ int CubeMesh::get_subdivide_width() const { void CubeMesh::set_subdivide_height(const int p_subdivide) { subdivide_h = p_subdivide > 0 ? p_subdivide : 0; - _queue_update(); + _request_update(); } int CubeMesh::get_subdivide_height() const { @@ -619,7 +638,7 @@ int CubeMesh::get_subdivide_height() const { void CubeMesh::set_subdivide_depth(const int p_subdivide) { subdivide_d = p_subdivide > 0 ? p_subdivide : 0; - _queue_update(true); //last property set, force update mesh + _request_update(); } int CubeMesh::get_subdivide_depth() const { @@ -638,14 +657,12 @@ CubeMesh::CubeMesh() { CylinderMesh */ -void CylinderMesh::_create_mesh_array(Array &p_arr) { +void CylinderMesh::_create_mesh_array(Array &p_arr) const { int i, j, prevrow, thisrow, point; float x, y, z, u, v, radius; radius = bottom_radius > top_radius ? bottom_radius : top_radius; - set_aabb(Rect3(Vector3(-radius, height * -0.5, -radius), Vector3(radius * 2.0, height, radius * 2.0))); - PoolVector<Vector3> points; PoolVector<Vector3> normals; PoolVector<float> tangents; @@ -800,7 +817,7 @@ void CylinderMesh::_bind_methods() { void CylinderMesh::set_top_radius(const float p_radius) { top_radius = p_radius; - _queue_update(); + _request_update(); } float CylinderMesh::get_top_radius() const { @@ -809,7 +826,7 @@ float CylinderMesh::get_top_radius() const { void CylinderMesh::set_bottom_radius(const float p_radius) { bottom_radius = p_radius; - _queue_update(); + _request_update(); } float CylinderMesh::get_bottom_radius() const { @@ -818,7 +835,7 @@ float CylinderMesh::get_bottom_radius() const { void CylinderMesh::set_height(const float p_height) { height = p_height; - _queue_update(); + _request_update(); } float CylinderMesh::get_height() const { @@ -827,7 +844,7 @@ float CylinderMesh::get_height() const { void CylinderMesh::set_radial_segments(const int p_segments) { radial_segments = p_segments > 4 ? p_segments : 4; - _queue_update(); + _request_update(); } int CylinderMesh::get_radial_segments() const { @@ -836,7 +853,7 @@ int CylinderMesh::get_radial_segments() const { void CylinderMesh::set_rings(const int p_rings) { rings = p_rings > 0 ? p_rings : 0; - _queue_update(true); //last property set, force update mesh + _request_update(); } int CylinderMesh::get_rings() const { @@ -856,14 +873,12 @@ CylinderMesh::CylinderMesh() { PlaneMesh */ -void PlaneMesh::_create_mesh_array(Array &p_arr) { +void PlaneMesh::_create_mesh_array(Array &p_arr) const { int i, j, prevrow, thisrow, point; float x, z; Size2 start_pos = size * -0.5; - set_aabb(Rect3(Vector3(start_pos.x, 0.0, start_pos.y), Vector3(size.x, 0.0, size.y))); - PoolVector<Vector3> points; PoolVector<Vector3> normals; PoolVector<float> tangents; @@ -935,7 +950,7 @@ void PlaneMesh::_bind_methods() { void PlaneMesh::set_size(const Size2 &p_size) { size = p_size; - _queue_update(); + _request_update(); } Size2 PlaneMesh::get_size() const { @@ -944,7 +959,7 @@ Size2 PlaneMesh::get_size() const { void PlaneMesh::set_subdivide_width(const int p_subdivide) { subdivide_w = p_subdivide > 0 ? p_subdivide : 0; - _queue_update(); + _request_update(); } int PlaneMesh::get_subdivide_width() const { @@ -953,7 +968,7 @@ int PlaneMesh::get_subdivide_width() const { void PlaneMesh::set_subdivide_depth(const int p_subdivide) { subdivide_d = p_subdivide > 0 ? p_subdivide : 0; - _queue_update(true); //last property set, force update mesh + _request_update(); } int PlaneMesh::get_subdivide_depth() const { @@ -971,7 +986,7 @@ PlaneMesh::PlaneMesh() { PrismMesh */ -void PrismMesh::_create_mesh_array(Array &p_arr) { +void PrismMesh::_create_mesh_array(Array &p_arr) const { int i, j, prevrow, thisrow, point; float x, y, z; float onethird = 1.0 / 3.0; @@ -980,7 +995,6 @@ void PrismMesh::_create_mesh_array(Array &p_arr) { Vector3 start_pos = size * -0.5; // set our bounding box - set_aabb(Rect3(start_pos, size)); PoolVector<Vector3> points; PoolVector<Vector3> normals; @@ -1207,7 +1221,7 @@ void PrismMesh::_bind_methods() { void PrismMesh::set_left_to_right(const float p_left_to_right) { left_to_right = p_left_to_right; - _queue_update(); + _request_update(); } float PrismMesh::get_left_to_right() const { @@ -1216,7 +1230,7 @@ float PrismMesh::get_left_to_right() const { void PrismMesh::set_size(const Vector3 &p_size) { size = p_size; - _queue_update(); + _request_update(); } Vector3 PrismMesh::get_size() const { @@ -1225,7 +1239,7 @@ Vector3 PrismMesh::get_size() const { void PrismMesh::set_subdivide_width(const int p_divisions) { subdivide_w = p_divisions > 0 ? p_divisions : 0; - _queue_update(); + _request_update(); } int PrismMesh::get_subdivide_width() const { @@ -1234,7 +1248,7 @@ int PrismMesh::get_subdivide_width() const { void PrismMesh::set_subdivide_height(const int p_divisions) { subdivide_h = p_divisions > 0 ? p_divisions : 0; - _queue_update(); + _request_update(); } int PrismMesh::get_subdivide_height() const { @@ -1243,7 +1257,7 @@ int PrismMesh::get_subdivide_height() const { void PrismMesh::set_subdivide_depth(const int p_divisions) { subdivide_d = p_divisions > 0 ? p_divisions : 0; - _queue_update(true); //last property set, force update mesh + _request_update(); } int PrismMesh::get_subdivide_depth() const { @@ -1263,7 +1277,7 @@ PrismMesh::PrismMesh() { QuadMesh */ -void QuadMesh::_create_mesh_array(Array &p_arr) { +void QuadMesh::_create_mesh_array(Array &p_arr) const { PoolVector<Vector3> faces; PoolVector<Vector3> normals; PoolVector<float> tangents; @@ -1312,19 +1326,17 @@ void QuadMesh::_bind_methods() { QuadMesh::QuadMesh() { primitive_type = PRIMITIVE_TRIANGLE_FAN; - _queue_update(true); } /** SphereMesh */ -void SphereMesh::_create_mesh_array(Array &p_arr) { +void SphereMesh::_create_mesh_array(Array &p_arr) const { int i, j, prevrow, thisrow, point; float x, y, z; // set our bounding box - set_aabb(Rect3(Vector3(-radius, height * -0.5, -radius), Vector3(radius * 2.0, height, radius * 2.0))); PoolVector<Vector3> points; PoolVector<Vector3> normals; @@ -1413,7 +1425,7 @@ void SphereMesh::_bind_methods() { void SphereMesh::set_radius(const float p_radius) { radius = p_radius; - _queue_update(); + _request_update(); } float SphereMesh::get_radius() const { @@ -1422,7 +1434,7 @@ float SphereMesh::get_radius() const { void SphereMesh::set_height(const float p_height) { height = p_height; - _queue_update(); + _request_update(); } float SphereMesh::get_height() const { @@ -1431,7 +1443,7 @@ float SphereMesh::get_height() const { void SphereMesh::set_radial_segments(const int p_radial_segments) { radial_segments = p_radial_segments > 4 ? p_radial_segments : 4; - _queue_update(); + _request_update(); } int SphereMesh::get_radial_segments() const { @@ -1440,7 +1452,7 @@ int SphereMesh::get_radial_segments() const { void SphereMesh::set_rings(const int p_rings) { rings = p_rings > 1 ? p_rings : 1; - _queue_update(); + _request_update(); } int SphereMesh::get_rings() const { @@ -1449,7 +1461,7 @@ int SphereMesh::get_rings() const { void SphereMesh::set_is_hemisphere(const bool p_is_hemisphere) { is_hemisphere = p_is_hemisphere; - _queue_update(true); //last property set, force update mesh + _request_update(); } bool SphereMesh::get_is_hemisphere() const { diff --git a/scene/resources/primitive_meshes.h b/scene/resources/primitive_meshes.h index 5e1387e864..bcd5d30dd3 100644 --- a/scene/resources/primitive_meshes.h +++ b/scene/resources/primitive_meshes.h @@ -47,23 +47,20 @@ class PrimitiveMesh : public Mesh { private: RID mesh; - Rect3 aabb; + mutable Rect3 aabb; Ref<Material> material; - bool first_mesh; - bool cache_is_dirty; - void _update(); + mutable bool pending_request; + void _update() const; protected: Mesh::PrimitiveType primitive_type; static void _bind_methods(); - virtual void _create_mesh_array(Array &p_arr) = 0; - void _queue_update(bool p_first_mesh = false); //pretty bad hack to have the mesh built firt time parameters are set without delay - - void set_aabb(Rect3 p_aabb); + virtual void _create_mesh_array(Array &p_arr) const = 0; + void _request_update(); public: virtual int get_surface_count() const; @@ -99,7 +96,7 @@ private: protected: static void _bind_methods(); - virtual void _create_mesh_array(Array &p_arr); + virtual void _create_mesh_array(Array &p_arr) const; public: void set_radius(const float p_radius); @@ -132,7 +129,7 @@ private: protected: static void _bind_methods(); - virtual void _create_mesh_array(Array &p_arr); + virtual void _create_mesh_array(Array &p_arr) const; public: void set_size(const Vector3 &p_size); @@ -167,7 +164,7 @@ private: protected: static void _bind_methods(); - virtual void _create_mesh_array(Array &p_arr); + virtual void _create_mesh_array(Array &p_arr) const; public: void set_top_radius(const float p_radius); @@ -202,7 +199,7 @@ private: protected: static void _bind_methods(); - virtual void _create_mesh_array(Array &p_arr); + virtual void _create_mesh_array(Array &p_arr) const; public: void set_size(const Size2 &p_size); @@ -233,7 +230,7 @@ private: protected: static void _bind_methods(); - virtual void _create_mesh_array(Array &p_arr); + virtual void _create_mesh_array(Array &p_arr) const; public: void set_left_to_right(const float p_left_to_right); @@ -267,7 +264,7 @@ private: protected: static void _bind_methods(); - virtual void _create_mesh_array(Array &p_arr); + virtual void _create_mesh_array(Array &p_arr) const; public: QuadMesh(); @@ -289,7 +286,7 @@ private: protected: static void _bind_methods(); - virtual void _create_mesh_array(Array &p_arr); + virtual void _create_mesh_array(Array &p_arr) const; public: void set_radius(const float p_radius); diff --git a/scene/resources/sky_box.cpp b/scene/resources/sky_box.cpp index c373ad67ee..b1ca72571e 100644 --- a/scene/resources/sky_box.cpp +++ b/scene/resources/sky_box.cpp @@ -47,8 +47,11 @@ void Sky::_bind_methods() { ClassDB::bind_method(D_METHOD("set_radiance_size", "size"), &Sky::set_radiance_size); ClassDB::bind_method(D_METHOD("get_radiance_size"), &Sky::get_radiance_size); - ADD_PROPERTY(PropertyInfo(Variant::INT, "radiance_size", PROPERTY_HINT_ENUM, "256,512,1024,2048"), "set_radiance_size", "get_radiance_size"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "radiance_size", PROPERTY_HINT_ENUM, "32,64,128,256,512,1024,2048"), "set_radiance_size", "get_radiance_size"); + BIND_CONSTANT(RADIANCE_SIZE_32); + BIND_CONSTANT(RADIANCE_SIZE_64); + BIND_CONSTANT(RADIANCE_SIZE_128); BIND_CONSTANT(RADIANCE_SIZE_256); BIND_CONSTANT(RADIANCE_SIZE_512); BIND_CONSTANT(RADIANCE_SIZE_1024); @@ -66,7 +69,7 @@ void PanoramaSky::_radiance_changed() { if (panorama.is_valid()) { static const int size[RADIANCE_SIZE_MAX] = { - 256, 512, 1024, 2048 + 32, 64, 128, 256, 512, 1024, 2048 }; VS::get_singleton()->sky_set_texture(sky, panorama->get_rid(), size[get_radiance_size()]); } @@ -120,7 +123,7 @@ void ProceduralSky::_radiance_changed() { return; //do nothing yet static const int size[RADIANCE_SIZE_MAX] = { - 256, 512, 1024, 2048 + 32, 64, 128, 256, 512, 1024, 2048 }; VS::get_singleton()->sky_set_texture(sky, texture, size[get_radiance_size()]); } @@ -132,7 +135,7 @@ void ProceduralSky::_update_sky() { PoolVector<uint8_t> imgdata; static const int size[TEXTURE_SIZE_MAX] = { - 1024, 2048, 4096 + 256, 512, 1024, 2048, 4096 }; int w = size[texture_size]; @@ -465,7 +468,14 @@ void ProceduralSky::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::REAL, "sun_energy", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_sun_energy", "get_sun_energy"); ADD_GROUP("Texture", "texture_"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_size", PROPERTY_HINT_ENUM, "1024,2048,4096"), "set_texture_size", "get_texture_size"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_size", PROPERTY_HINT_ENUM, "256,512,1024,2048,4096"), "set_texture_size", "get_texture_size"); + + BIND_CONSTANT(TEXTURE_SIZE_256); + BIND_CONSTANT(TEXTURE_SIZE_512); + BIND_CONSTANT(TEXTURE_SIZE_1024); + BIND_CONSTANT(TEXTURE_SIZE_2048); + BIND_CONSTANT(TEXTURE_SIZE_4096); + BIND_CONSTANT(TEXTURE_SIZE_MAX); } ProceduralSky::ProceduralSky() { diff --git a/scene/resources/sky_box.h b/scene/resources/sky_box.h index 7b707af3a6..8298d1b3c0 100644 --- a/scene/resources/sky_box.h +++ b/scene/resources/sky_box.h @@ -37,6 +37,9 @@ class Sky : public Resource { public: enum RadianceSize { + RADIANCE_SIZE_32, + RADIANCE_SIZE_64, + RADIANCE_SIZE_128, RADIANCE_SIZE_256, RADIANCE_SIZE_512, RADIANCE_SIZE_1024, @@ -85,6 +88,8 @@ class ProceduralSky : public Sky { public: enum TextureSize { + TEXTURE_SIZE_256, + TEXTURE_SIZE_512, TEXTURE_SIZE_1024, TEXTURE_SIZE_2048, TEXTURE_SIZE_4096, |