diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/3d/ray_cast.cpp | 3 | ||||
-rw-r--r-- | scene/3d/soft_body.cpp | 11 | ||||
-rw-r--r-- | scene/main/scene_tree.cpp | 6 | ||||
-rw-r--r-- | scene/main/viewport.cpp | 86 | ||||
-rw-r--r-- | scene/main/viewport.h | 30 | ||||
-rw-r--r-- | scene/resources/mesh.cpp | 397 | ||||
-rw-r--r-- | scene/resources/mesh.h | 30 | ||||
-rw-r--r-- | scene/resources/primitive_meshes.cpp | 27 | ||||
-rw-r--r-- | scene/resources/primitive_meshes.h | 4 | ||||
-rw-r--r-- | scene/resources/surface_tool.cpp | 2 |
10 files changed, 311 insertions, 285 deletions
diff --git a/scene/3d/ray_cast.cpp b/scene/3d/ray_cast.cpp index 7f764a737a..616ab7cf40 100644 --- a/scene/3d/ray_cast.cpp +++ b/scene/3d/ray_cast.cpp @@ -362,8 +362,7 @@ void RayCast::_update_debug_shape() { return; Ref<ArrayMesh> mesh = mi->get_mesh(); - if (mesh->get_surface_count() > 0) - mesh->surface_remove(0); + mesh->clear_surfaces(); Array a; a.resize(Mesh::ARRAY_MAX); diff --git a/scene/3d/soft_body.cpp b/scene/3d/soft_body.cpp index 435bef7247..931e786455 100644 --- a/scene/3d/soft_body.cpp +++ b/scene/3d/soft_body.cpp @@ -47,7 +47,10 @@ void SoftBodyVisualServerHandler::prepare(RID p_mesh, int p_surface) { mesh = p_mesh; surface = p_surface; - +#ifndef _MSC_VER +#warning Softbody is not working, needs to be redone considering that these functions no longer exist +#endif +#if 0 const uint32_t surface_format = VS::get_singleton()->mesh_surface_get_format(mesh, surface); const int surface_vertex_len = VS::get_singleton()->mesh_surface_get_array_len(mesh, p_surface); const int surface_index_len = VS::get_singleton()->mesh_surface_get_array_index_len(mesh, p_surface); @@ -57,6 +60,7 @@ void SoftBodyVisualServerHandler::prepare(RID p_mesh, int p_surface) { stride = VS::get_singleton()->mesh_surface_make_offsets_from_format(surface_format, surface_vertex_len, surface_index_len, surface_offsets); offset_vertices = surface_offsets[VS::ARRAY_VERTEX]; offset_normal = surface_offsets[VS::ARRAY_NORMAL]; +#endif } void SoftBodyVisualServerHandler::clear() { @@ -485,14 +489,15 @@ void SoftBody::become_mesh_owner() { // Get current mesh array and create new mesh array with necessary flag for softbody Array surface_arrays = mesh->surface_get_arrays(0); Array surface_blend_arrays = mesh->surface_get_blend_shape_arrays(0); + Dictionary surface_lods = mesh->surface_get_lods(0); uint32_t surface_format = mesh->surface_get_format(0); - surface_format &= ~(Mesh::ARRAY_COMPRESS_VERTEX | Mesh::ARRAY_COMPRESS_NORMAL); + surface_format &= ~(Mesh::ARRAY_COMPRESS_NORMAL); surface_format |= Mesh::ARRAY_FLAG_USE_DYNAMIC_UPDATE; Ref<ArrayMesh> soft_mesh; soft_mesh.instance(); - soft_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, surface_arrays, surface_blend_arrays, surface_format); + soft_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, surface_arrays, surface_blend_arrays, surface_lods, surface_format); soft_mesh->surface_set_material(0, mesh->surface_get_material(0)); set_mesh(soft_mesh); diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 15d21859ea..67a39a6b22 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -2081,12 +2081,6 @@ SceneTree::SceneTree() { ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/filters/msaa", PropertyInfo(Variant::INT, "rendering/quality/filters/msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x,AndroidVR 2x,AndroidVR 4x")); root->set_msaa(Viewport::MSAA(msaa_mode)); - GLOBAL_DEF("rendering/quality/depth/hdr", true); - GLOBAL_DEF("rendering/quality/depth/hdr.mobile", false); - - bool hdr = GLOBAL_GET("rendering/quality/depth/hdr"); - root->set_hdr(hdr); - VS::get_singleton()->scenario_set_reflection_atlas_size(root->get_world()->get_scenario(), ref_atlas_size, ref_atlas_subdiv); { //load default fallback environment diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index e4343d3982..976c66ad0c 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1330,17 +1330,6 @@ Ref<ViewportTexture> Viewport::get_texture() const { return default_texture; } -void Viewport::set_vflip(bool p_enable) { - - vflip = p_enable; - VisualServer::get_singleton()->viewport_set_vflip(viewport, p_enable); -} - -bool Viewport::get_vflip() const { - - return vflip; -} - void Viewport::set_clear_mode(ClearMode p_mode) { clear_mode = p_mode; @@ -2948,26 +2937,6 @@ bool Viewport::is_input_disabled() const { return disable_input; } -void Viewport::set_disable_3d(bool p_disable) { - disable_3d = p_disable; - VS::get_singleton()->viewport_set_disable_3d(viewport, p_disable); -} - -bool Viewport::is_3d_disabled() const { - - return disable_3d; -} - -void Viewport::set_keep_3d_linear(bool p_keep_3d_linear) { - keep_3d_linear = p_keep_3d_linear; - VS::get_singleton()->viewport_set_keep_3d_linear(viewport, keep_3d_linear); -} - -bool Viewport::get_keep_3d_linear() const { - - return keep_3d_linear; -} - Variant Viewport::gui_get_drag_data() const { return gui.drag_data; } @@ -3008,30 +2977,6 @@ Viewport::MSAA Viewport::get_msaa() const { return msaa; } -void Viewport::set_hdr(bool p_hdr) { - - if (hdr == p_hdr) - return; - - hdr = p_hdr; - VS::get_singleton()->viewport_set_hdr(viewport, p_hdr); -} - -bool Viewport::get_hdr() const { - - return hdr; -} - -void Viewport::set_usage(Usage p_usage) { - - usage = p_usage; - VS::get_singleton()->viewport_set_usage(viewport, VS::ViewportUsage(p_usage)); -} - -Viewport::Usage Viewport::get_usage() const { - return usage; -} - void Viewport::set_debug_draw(DebugDraw p_debug_draw) { debug_draw = p_debug_draw; @@ -3090,10 +3035,6 @@ bool Viewport::is_handling_input_locally() const { } void Viewport::_validate_property(PropertyInfo &property) const { - - if (VisualServer::get_singleton()->is_low_end() && property.name == "hdr") { - property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL; - } } void Viewport::set_default_canvas_item_texture_filter(DefaultCanvasItemTextureFilter p_filter) { @@ -3176,9 +3117,6 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_size_override_stretch", "enabled"), &Viewport::set_size_override_stretch); ClassDB::bind_method(D_METHOD("is_size_override_stretch_enabled"), &Viewport::is_size_override_stretch_enabled); - ClassDB::bind_method(D_METHOD("set_vflip", "enable"), &Viewport::set_vflip); - ClassDB::bind_method(D_METHOD("get_vflip"), &Viewport::get_vflip); - ClassDB::bind_method(D_METHOD("set_clear_mode", "mode"), &Viewport::set_clear_mode); ClassDB::bind_method(D_METHOD("get_clear_mode"), &Viewport::get_clear_mode); @@ -3188,12 +3126,6 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_msaa", "msaa"), &Viewport::set_msaa); ClassDB::bind_method(D_METHOD("get_msaa"), &Viewport::get_msaa); - ClassDB::bind_method(D_METHOD("set_hdr", "enable"), &Viewport::set_hdr); - ClassDB::bind_method(D_METHOD("get_hdr"), &Viewport::get_hdr); - - ClassDB::bind_method(D_METHOD("set_usage", "usage"), &Viewport::set_usage); - ClassDB::bind_method(D_METHOD("get_usage"), &Viewport::get_usage); - ClassDB::bind_method(D_METHOD("set_debug_draw", "debug_draw"), &Viewport::set_debug_draw); ClassDB::bind_method(D_METHOD("get_debug_draw"), &Viewport::get_debug_draw); @@ -3236,12 +3168,6 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_disable_input", "disable"), &Viewport::set_disable_input); ClassDB::bind_method(D_METHOD("is_input_disabled"), &Viewport::is_input_disabled); - ClassDB::bind_method(D_METHOD("set_disable_3d", "disable"), &Viewport::set_disable_3d); - ClassDB::bind_method(D_METHOD("is_3d_disabled"), &Viewport::is_3d_disabled); - - ClassDB::bind_method(D_METHOD("set_keep_3d_linear", "keep_3d_linear"), &Viewport::set_keep_3d_linear); - ClassDB::bind_method(D_METHOD("get_keep_3d_linear"), &Viewport::get_keep_3d_linear); - ClassDB::bind_method(D_METHOD("_gui_show_tooltip"), &Viewport::_gui_show_tooltip); ClassDB::bind_method(D_METHOD("_gui_remove_focus"), &Viewport::_gui_remove_focus); ClassDB::bind_method(D_METHOD("_post_gui_grab_click_focus"), &Viewport::_post_gui_grab_click_focus); @@ -3289,7 +3215,6 @@ void Viewport::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_direct_to_screen"), "set_use_render_direct_to_screen", "is_using_render_direct_to_screen"); ADD_PROPERTY(PropertyInfo(Variant::INT, "debug_draw", PROPERTY_HINT_ENUM, "Disabled,Unshaded,Overdraw,Wireframe"), "set_debug_draw", "get_debug_draw"); ADD_GROUP("Render Target", "render_target_"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_target_v_flip"), "set_vflip", "get_vflip"); ADD_PROPERTY(PropertyInfo(Variant::INT, "render_target_clear_mode", PROPERTY_HINT_ENUM, "Always,Never,Next Frame"), "set_clear_mode", "get_clear_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "render_target_update_mode", PROPERTY_HINT_ENUM, "Disabled,Once,When Visible,Always"), "set_update_mode", "get_update_mode"); ADD_GROUP("Canvas Items", "canvas_item_"); @@ -3348,11 +3273,6 @@ void Viewport::_bind_methods() { BIND_ENUM_CONSTANT(MSAA_8X); BIND_ENUM_CONSTANT(MSAA_16X); - BIND_ENUM_CONSTANT(USAGE_2D); - BIND_ENUM_CONSTANT(USAGE_2D_NO_SAMPLING); - BIND_ENUM_CONSTANT(USAGE_3D); - BIND_ENUM_CONSTANT(USAGE_3D_NO_EFFECTS); - BIND_ENUM_CONSTANT(CLEAR_MODE_ALWAYS); BIND_ENUM_CONSTANT(CLEAR_MODE_NEVER); BIND_ENUM_CONSTANT(CLEAR_MODE_ONLY_NEXT_FRAME); @@ -3406,8 +3326,6 @@ Viewport::Viewport() { size_override_size = Size2(1, 1); gen_mipmaps = false; - vflip = false; - //clear=true; update_mode = UPDATE_WHEN_VISIBLE; @@ -3433,8 +3351,6 @@ Viewport::Viewport() { unhandled_key_input_group = "_vp_unhandled_key_input" + id; disable_input = false; - disable_3d = false; - keep_3d_linear = false; //window tooltip gui.tooltip_timer = -1; @@ -3453,9 +3369,7 @@ Viewport::Viewport() { gui.last_mouse_focus = NULL; msaa = MSAA_DISABLED; - hdr = true; - usage = USAGE_3D; debug_draw = DEBUG_DRAW_DISABLED; clear_mode = CLEAR_MODE_ALWAYS; diff --git a/scene/main/viewport.h b/scene/main/viewport.h index a70d812eda..469665676c 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -115,13 +115,6 @@ public: MSAA_16X, }; - enum Usage { - USAGE_2D, - USAGE_2D_NO_SAMPLING, - USAGE_3D, - USAGE_3D_NO_EFFECTS, - }; - enum RenderInfo { RENDER_INFO_OBJECTS_IN_FRAME, @@ -226,7 +219,6 @@ private: Rect2 last_vp_rect; bool transparent_bg; - bool vflip; ClearMode clear_mode; bool filter; bool gen_mipmaps; @@ -278,21 +270,15 @@ private: void _update_stretch_transform(); void _update_global_transform(); - bool disable_3d; - bool keep_3d_linear; UpdateMode update_mode; RID texture_rid; DebugDraw debug_draw; - Usage usage; - int shadow_atlas_size; ShadowAtlasQuadrantSubdiv shadow_atlas_quadrant_subdiv[4]; MSAA msaa; - bool hdr; - Ref<ViewportTexture> default_texture; Set<ViewportTexture *> viewport_textures; @@ -491,9 +477,6 @@ public: void set_size_override_stretch(bool p_enable); bool is_size_override_stretch_enabled() const; - void set_vflip(bool p_enable); - bool get_vflip() const; - void set_clear_mode(ClearMode p_mode); ClearMode get_clear_mode() const; @@ -510,9 +493,6 @@ public: void set_msaa(MSAA p_msaa); MSAA get_msaa() const; - void set_hdr(bool p_hdr); - bool get_hdr() const; - Vector2 get_camera_coords(const Vector2 &p_viewport_coords) const; Vector2 get_camera_rect_size() const; @@ -525,12 +505,6 @@ public: void set_disable_input(bool p_disable); bool is_input_disabled() const; - void set_disable_3d(bool p_disable); - bool is_3d_disabled() const; - - void set_keep_3d_linear(bool p_keep_3d_linear); - bool get_keep_3d_linear() const; - void set_attach_to_screen_rect(const Rect2 &p_rect); Rect2 get_attach_to_screen_rect() const; @@ -553,9 +527,6 @@ public: virtual String get_configuration_warning() const; - void set_usage(Usage p_usage); - Usage get_usage() const; - void set_debug_draw(DebugDraw p_debug_draw); DebugDraw get_debug_draw() const; @@ -587,7 +558,6 @@ public: VARIANT_ENUM_CAST(Viewport::UpdateMode); VARIANT_ENUM_CAST(Viewport::ShadowAtlasQuadrantSubdiv); VARIANT_ENUM_CAST(Viewport::MSAA); -VARIANT_ENUM_CAST(Viewport::Usage); VARIANT_ENUM_CAST(Viewport::DebugDraw); VARIANT_ENUM_CAST(Viewport::ClearMode); VARIANT_ENUM_CAST(Viewport::RenderInfo); diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 8955838f62..96c609174f 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -159,7 +159,7 @@ void Mesh::generate_debug_mesh_indices(Vector<Vector3> &r_points) { bool Mesh::surface_is_softbody_friendly(int p_idx) const { const uint32_t surface_format = surface_get_format(p_idx); - return (surface_format & Mesh::ARRAY_FLAG_USE_DYNAMIC_UPDATE && (!(surface_format & Mesh::ARRAY_COMPRESS_VERTEX)) && (!(surface_format & Mesh::ARRAY_COMPRESS_NORMAL))); + return (surface_format & Mesh::ARRAY_FLAG_USE_DYNAMIC_UPDATE && (!(surface_format & Mesh::ARRAY_COMPRESS_NORMAL))); } PoolVector<Face3> Mesh::get_faces() const { @@ -499,7 +499,9 @@ void Mesh::_bind_methods() { BIND_ENUM_CONSTANT(PRIMITIVE_POINTS); BIND_ENUM_CONSTANT(PRIMITIVE_LINES); + BIND_ENUM_CONSTANT(PRIMITIVE_LINE_STRIP); BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLES); + BIND_ENUM_CONSTANT(PRIMITIVE_TRIANGLE_STRIP); BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_NORMALIZED); BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_RELATIVE); @@ -514,18 +516,14 @@ void Mesh::_bind_methods() { BIND_ENUM_CONSTANT(ARRAY_FORMAT_WEIGHTS); BIND_ENUM_CONSTANT(ARRAY_FORMAT_INDEX); - BIND_ENUM_CONSTANT(ARRAY_COMPRESS_VERTEX); BIND_ENUM_CONSTANT(ARRAY_COMPRESS_NORMAL); BIND_ENUM_CONSTANT(ARRAY_COMPRESS_TANGENT); BIND_ENUM_CONSTANT(ARRAY_COMPRESS_COLOR); BIND_ENUM_CONSTANT(ARRAY_COMPRESS_TEX_UV); BIND_ENUM_CONSTANT(ARRAY_COMPRESS_TEX_UV2); - BIND_ENUM_CONSTANT(ARRAY_COMPRESS_BONES); - BIND_ENUM_CONSTANT(ARRAY_COMPRESS_WEIGHTS); BIND_ENUM_CONSTANT(ARRAY_COMPRESS_INDEX); BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_2D_VERTICES); - BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_16_BIT_BONES); BIND_ENUM_CONSTANT(ARRAY_COMPRESS_DEFAULT); @@ -626,9 +624,12 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { return true; } +#ifdef ENABLE_DEPRECATED if (!sname.begins_with("surfaces")) return false; + WARN_DEPRECATED("Mesh uses old surface format, which is deprecated (and loads slower). Consider re-importing or re-saving the scene."); + int idx = sname.get_slicec('/', 1).to_int(); String what = sname.get_slicec('/', 2); @@ -654,6 +655,12 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { uint32_t format = d["format"]; uint32_t primitive = d["primitive"]; + if (primitive > PRIMITIVE_LINE_STRIP) { + primitive--; //line loop was deprecated, so it's not supported and indices go down by one + } + if (primitive > PRIMITIVE_TRIANGLE_STRIP) { + primitive = PRIMITIVE_TRIANGLE_STRIP; //fan is no longer supported + } ERR_FAIL_COND_V(!d.has("vertex_count"), false); int vertex_count = d["vertex_count"]; @@ -701,9 +708,191 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { return true; } +#endif + return false; } +Array ArrayMesh::_get_surfaces() const { + + if (mesh.is_null()) { + return Array(); + } + + Array ret; + for (int i = 0; i < surfaces.size(); i++) { + VisualServer::SurfaceData surface = VS::get_singleton()->mesh_get_surface(mesh, i); + Dictionary data; + data["format"] = surface.format; + data["primitive"] = surface.primitive; + data["vertex_data"] = surface.vertex_data; + data["vertex_count"] = surface.vertex_count; + data["aabb"] = surface.aabb; + if (surface.index_count) { + data["index_data"] = surface.index_data; + data["index_count"] = surface.index_count; + }; + + Array lods; + for (int j = 0; j < surface.lods.size(); j++) { + lods.push_back(surface.lods[j].edge_length); + lods.push_back(surface.lods[j].index_data); + } + + if (lods.size()) { + data["lods"] = lods; + } + + Array bone_aabbs; + for (int j = 0; j < surface.bone_aabbs.size(); j++) { + bone_aabbs.push_back(surface.bone_aabbs[j]); + } + if (bone_aabbs.size()) { + data["bone_aabbs"] = bone_aabbs; + } + + Array blend_shapes; + for (int j = 0; j < surface.blend_shapes.size(); j++) { + blend_shapes.push_back(surface.blend_shapes[j]); + } + + if (surfaces[i].material.is_valid()) { + data["material"] = surfaces[i].material; + } + + if (surfaces[i].name != String()) { + data["name"] = surfaces[i].name; + } + + if (surfaces[i].is_2d) { + data["2d"] = true; + } + + ret.push_back(data); + } + return ret; +} + +void ArrayMesh::_create_if_empty() const { + if (!mesh.is_valid()) { + mesh = VS::get_singleton()->mesh_create(); + } +} + +void ArrayMesh::_set_surfaces(const Array &p_surfaces) { + + Vector<VS::SurfaceData> surface_data; + Vector<Ref<Material> > surface_materials; + Vector<String> surface_names; + Vector<bool> surface_2d; + + for (int i = 0; i < p_surfaces.size(); i++) { + VS::SurfaceData surface; + Dictionary d = p_surfaces[i]; + ERR_FAIL_COND(!d.has("format")); + ERR_FAIL_COND(!d.has("primitive")); + ERR_FAIL_COND(!d.has("vertex_data")); + ERR_FAIL_COND(!d.has("vertex_count")); + ERR_FAIL_COND(!d.has("aabb")); + surface.format = d["format"]; + surface.primitive = VS::PrimitiveType(int(d["primitive"])); + surface.vertex_data = d["vertex_data"]; + surface.vertex_count = d["vertex_count"]; + surface.aabb = d["aabb"]; + + if (d.has("index_data")) { + ERR_FAIL_COND(!d.has("index_count")); + surface.index_data = d["index_data"]; + surface.index_count = d["index_count"]; + } + + if (d.has("lods")) { + Array lods = d["lods"]; + ERR_FAIL_COND(lods.size() & 1); //must be even + for (int j = 0; j < lods.size(); j += 2) { + VS::SurfaceData::LOD lod; + lod.edge_length = lods[j + 0]; + lod.index_data = lods[j + 1]; + surface.lods.push_back(lod); + } + } + + if (d.has("bone_aabbs")) { + Array bone_aabbs = d["bone_aabbs"]; + for (int j = 0; j < bone_aabbs.size(); j++) { + surface.bone_aabbs.push_back(bone_aabbs[j]); + } + } + + if (d.has("blend_shapes")) { + Array blend_shapes; + for (int j = 0; j < blend_shapes.size(); j++) { + surface.blend_shapes.push_back(blend_shapes[j]); + } + } + + Ref<Material> material; + if (d.has("material")) { + material = d["material"]; + if (material.is_valid()) { + surface.material = material->get_rid(); + } + } + + String name; + if (d.has("name")) { + name = d["name"]; + } + + bool _2d = false; + if (d.has("2d")) { + _2d = d["2d"]; + } + + surface_data.push_back(surface); + surface_materials.push_back(material); + surface_names.push_back(name); + surface_2d.push_back(_2d); + } + + if (mesh.is_valid()) { + //if mesh exists, it needs to be updated + VS::get_singleton()->mesh_clear(mesh); + for (int i = 0; i < surface_data.size(); i++) { + VS::get_singleton()->mesh_add_surface(mesh, surface_data[i]); + } + } else { + // if mesh does not exist (first time this is loaded, most likely), + // we can create it with a single call, which is a lot more efficient and thread friendly + mesh = VS::get_singleton()->mesh_create_from_surfaces(surface_data); + } + + surfaces.clear(); + + aabb = AABB(); + for (int i = 0; i < surface_data.size(); i++) { + Surface s; + s.aabb = surface_data[i].aabb; + if (i == 0) { + aabb = s.aabb; + blend_shapes.resize(surface_data[i].blend_shapes.size()); + } else { + aabb.merge_with(s.aabb); + } + + s.material = surface_materials[i]; + s.is_2d = surface_2d[i]; + s.name = surface_names[i]; + + s.format = surface_data[i].format; + s.primitive = PrimitiveType(surface_data[i].primitive); + s.array_length = surface_data[i].vertex_count; + s.index_array_length = surface_data[i].index_count; + + surfaces.push_back(s); + } +} + bool ArrayMesh::_get(const StringName &p_name, Variant &r_ret) const { if (_is_generated()) @@ -734,47 +923,7 @@ bool ArrayMesh::_get(const StringName &p_name, Variant &r_ret) const { else if (what == "name") r_ret = surface_get_name(idx); return true; - } else if (!sname.begins_with("surfaces")) - return false; - - int idx = sname.get_slicec('/', 1).to_int(); - ERR_FAIL_INDEX_V(idx, surfaces.size(), false); - - Dictionary d; - - d["array_data"] = VS::get_singleton()->mesh_surface_get_array(mesh, idx); - d["vertex_count"] = VS::get_singleton()->mesh_surface_get_array_len(mesh, idx); - d["array_index_data"] = VS::get_singleton()->mesh_surface_get_index_array(mesh, idx); - d["index_count"] = VS::get_singleton()->mesh_surface_get_array_index_len(mesh, idx); - d["primitive"] = VS::get_singleton()->mesh_surface_get_primitive_type(mesh, idx); - d["format"] = VS::get_singleton()->mesh_surface_get_format(mesh, idx); - d["aabb"] = VS::get_singleton()->mesh_surface_get_aabb(mesh, idx); - - Vector<AABB> skel_aabb = VS::get_singleton()->mesh_surface_get_skeleton_aabb(mesh, idx); - Array arr; - arr.resize(skel_aabb.size()); - for (int i = 0; i < skel_aabb.size(); i++) { - arr[i] = skel_aabb[i]; } - d["skeleton_aabb"] = arr; - - Vector<PoolVector<uint8_t> > blend_shape_data = VS::get_singleton()->mesh_surface_get_blend_shapes(mesh, idx); - - Array md; - for (int i = 0; i < blend_shape_data.size(); i++) { - md.push_back(blend_shape_data[i]); - } - - d["blend_shape_data"] = md; - - Ref<Material> m = surface_get_material(idx); - if (m.is_valid()) - d["material"] = m; - String n = surface_get_name(idx); - if (n != "") - d["name"] = n; - - r_ret = d; return true; } @@ -791,7 +940,6 @@ void ArrayMesh::_get_property_list(List<PropertyInfo> *p_list) const { for (int i = 0; i < surfaces.size(); i++) { - p_list->push_back(PropertyInfo(Variant::DICTIONARY, "surfaces/" + itos(i), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); p_list->push_back(PropertyInfo(Variant::STRING, "surface_" + itos(i + 1) + "/name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); if (surfaces[i].is_2d) { p_list->push_back(PropertyInfo(Variant::OBJECT, "surface_" + itos(i + 1) + "/material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,CanvasItemMaterial", PROPERTY_USAGE_EDITOR)); @@ -814,55 +962,53 @@ void ArrayMesh::_recompute_aabb() { aabb.merge_with(surfaces[i].aabb); } } +#ifndef _MSC_VER +#warning need to add binding to add_surface using future MeshSurfaceData object +#endif +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 AABB &p_aabb, const Vector<PoolVector<uint8_t> > &p_blend_shapes, const Vector<AABB> &p_bone_aabb, const Vector<VS::SurfaceData::LOD> &p_lods) { -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 AABB &p_aabb, const Vector<PoolVector<uint8_t> > &p_blend_shapes, const Vector<AABB> &p_bone_aabbs) { + _create_if_empty(); Surface s; s.aabb = p_aabb; s.is_2d = p_format & ARRAY_FLAG_USE_2D_VERTICES; + s.primitive = p_primitive; + s.array_length = p_vertex_count; + s.index_array_length = p_index_count; + s.format = p_format; + surfaces.push_back(s); _recompute_aabb(); - 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 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); - - Surface s; - - VisualServer::get_singleton()->mesh_add_surface_from_arrays(mesh, (VisualServer::PrimitiveType)p_primitive, p_arrays, p_blend_shapes, p_flags); + VS::SurfaceData sd; + sd.format = p_format; + sd.primitive = VS::PrimitiveType(p_primitive); + sd.aabb = p_aabb; + sd.vertex_count = p_vertex_count; + sd.vertex_data = p_array; + sd.index_count = p_index_count; + sd.index_data = p_index_array; + sd.blend_shapes = p_blend_shapes; + sd.bone_aabbs = p_bone_aabb; + sd.lods = p_lods; - /* make aABB? */ { + VisualServer::get_singleton()->mesh_add_surface(mesh, sd); - Variant arr = p_arrays[ARRAY_VERTEX]; - PoolVector<Vector3> vertices = arr; - int len = vertices.size(); - ERR_FAIL_COND(len == 0); - PoolVector<Vector3>::Read r = vertices.read(); - const Vector3 *vtx = r.ptr(); + clear_cache(); + _change_notify(); + emit_changed(); +} - // check AABB - AABB aabb; - for (int i = 0; i < len; i++) { +void ArrayMesh::add_surface_from_arrays(PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes, const Dictionary &p_lods, uint32_t p_flags) { - if (i == 0) - aabb.position = vtx[i]; - else - aabb.expand_to(vtx[i]); - } + ERR_FAIL_COND(p_arrays.size() != ARRAY_MAX); - s.aabb = aabb; - s.is_2d = arr.get_type() == Variant::POOL_VECTOR2_ARRAY; - surfaces.push_back(s); + VS::SurfaceData surface; - _recompute_aabb(); - } + Error err = VS::get_singleton()->mesh_create_surface_data_from_arrays(&surface, (VisualServer::PrimitiveType)p_primitive, p_arrays, p_blend_shapes, p_lods, p_flags); + ERR_FAIL_COND(err != OK); - clear_cache(); - _change_notify(); - emit_changed(); + add_surface(surface.format, PrimitiveType(surface.primitive), surface.vertex_data, surface.vertex_count, surface.index_data, surface.index_count, surface.aabb, surface.blend_shapes, surface.bone_aabbs, surface.lods); } Array ArrayMesh::surface_get_arrays(int p_surface) const { @@ -875,6 +1021,10 @@ Array ArrayMesh::surface_get_blend_shape_arrays(int p_surface) const { ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Array()); return VisualServer::get_singleton()->mesh_surface_get_blend_shape_arrays(mesh, p_surface); } +Dictionary ArrayMesh::surface_get_lods(int p_surface) const { + ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Dictionary()); + return VisualServer::get_singleton()->mesh_surface_get_lods(mesh, p_surface); +} int ArrayMesh::get_surface_count() const { @@ -898,7 +1048,7 @@ void ArrayMesh::add_blend_shape(const StringName &p_name) { } blend_shapes.push_back(name); - VS::get_singleton()->mesh_set_blend_shape_count(mesh, blend_shapes.size()); + //VS::get_singleton()->mesh_set_blend_shape_count(mesh, blend_shapes.size()); } int ArrayMesh::get_blend_shape_count() const { @@ -927,40 +1077,28 @@ ArrayMesh::BlendShapeMode ArrayMesh::get_blend_shape_mode() const { return blend_shape_mode; } -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); - - clear_cache(); - _recompute_aabb(); - _change_notify(); - emit_changed(); -} - 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); + return surfaces[p_idx].array_length; } 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); + return surfaces[p_idx].index_array_length; } 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); + return surfaces[p_idx].format; } 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); + return surfaces[p_idx].primitive; } void ArrayMesh::surface_set_material(int p_idx, const Ref<Material> &p_material) { @@ -981,7 +1119,6 @@ int ArrayMesh::surface_find_by_name(const String &p_name) const { return i; } } - return -1; } @@ -1020,35 +1157,9 @@ Ref<Material> ArrayMesh::surface_get_material(int p_idx) const { return surfaces[p_idx].material; } -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); - AABB aabb; - for (int i = 0; i < p_mesh_data.vertices.size(); i++) { - - if (i == 0) - aabb.position = p_mesh_data.vertices[i]; - else - aabb.expand_to(p_mesh_data.vertices[i]); - } - - Surface s; - s.aabb = aabb; - if (surfaces.size() == 0) - aabb = s.aabb; - else - aabb.merge_with(s.aabb); - - clear_cache(); - - surfaces.push_back(s); - _change_notify(); - - emit_changed(); -} - RID ArrayMesh::get_rid() const { + _create_if_empty(); return mesh; } AABB ArrayMesh::get_aabb() const { @@ -1056,8 +1167,18 @@ AABB ArrayMesh::get_aabb() const { return aabb; } +void ArrayMesh::clear_surfaces() { + if (!mesh.is_valid()) { + return; + } + VS::get_singleton()->mesh_clear(mesh); + surfaces.clear(); + aabb = AABB(); +} + void ArrayMesh::set_custom_aabb(const AABB &p_custom) { + _create_if_empty(); custom_aabb = p_custom; VS::get_singleton()->mesh_set_custom_aabb(mesh, custom_aabb); emit_changed(); @@ -1070,6 +1191,9 @@ AABB ArrayMesh::get_custom_aabb() const { void ArrayMesh::regen_normalmaps() { + if (surfaces.size() == 0) { + return; + } Vector<Ref<SurfaceTool> > surfs; for (int i = 0; i < get_surface_count(); i++) { @@ -1078,9 +1202,7 @@ void ArrayMesh::regen_normalmaps() { surfs.push_back(st); } - while (get_surface_count()) { - surface_remove(0); - } + clear_surfaces(); for (int i = 0; i < surfs.size(); i++) { @@ -1200,9 +1322,7 @@ Error ArrayMesh::lightmap_unwrap(const Transform &p_base_transform, float p_texe } //remove surfaces - while (get_surface_count()) { - surface_remove(0); - } + clear_surfaces(); //create surfacetools for each surface.. Vector<Ref<SurfaceTool> > surfaces_tools; @@ -1286,8 +1406,8 @@ void ArrayMesh::_bind_methods() { 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("surface_remove", "surf_idx"), &ArrayMesh::surface_remove); + ClassDB::bind_method(D_METHOD("add_surface_from_arrays", "primitive", "arrays", "blend_shapes", "lods", "compress_flags"), &ArrayMesh::add_surface_from_arrays, DEFVAL(Array()), DEFVAL(Dictionary()), DEFVAL(ARRAY_COMPRESS_DEFAULT)); + ClassDB::bind_method(D_METHOD("clear_surfaces"), &ArrayMesh::clear_surfaces); ClassDB::bind_method(D_METHOD("surface_update_region", "surf_idx", "offset", "data"), &ArrayMesh::surface_update_region); 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); @@ -1309,6 +1429,10 @@ void ArrayMesh::_bind_methods() { 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); + ClassDB::bind_method(D_METHOD("_set_surfaces", "surfaces"), &ArrayMesh::_set_surfaces); + ClassDB::bind_method(D_METHOD("_get_surfaces"), &ArrayMesh::_get_surfaces); + + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_surfaces", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_INTERNAL), "_set_surfaces", "_get_surfaces"); ADD_PROPERTY(PropertyInfo(Variant::INT, "blend_shape_mode", PROPERTY_HINT_ENUM, "Normalized,Relative", PROPERTY_USAGE_NOEDITOR), "set_blend_shape_mode", "get_blend_shape_mode"); ADD_PROPERTY(PropertyInfo(Variant::AABB, "custom_aabb", PROPERTY_HINT_NONE, ""), "set_custom_aabb", "get_custom_aabb"); @@ -1350,11 +1474,14 @@ void ArrayMesh::reload_from_file() { ArrayMesh::ArrayMesh() { - mesh = VisualServer::get_singleton()->mesh_create(); + //mesh is now created on demand + //mesh = VisualServer::get_singleton()->mesh_create(); blend_shape_mode = BLEND_SHAPE_MODE_RELATIVE; } ArrayMesh::~ArrayMesh() { - VisualServer::get_singleton()->free(mesh); + if (mesh.is_valid()) { + VisualServer::get_singleton()->free(mesh); + } } diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h index 6ead37a7bb..b8f3702bbe 100644 --- a/scene/resources/mesh.h +++ b/scene/resources/mesh.h @@ -83,28 +83,26 @@ public: ARRAY_FORMAT_INDEX = 1 << ARRAY_INDEX, ARRAY_COMPRESS_BASE = (ARRAY_INDEX + 1), - ARRAY_COMPRESS_VERTEX = 1 << (ARRAY_VERTEX + ARRAY_COMPRESS_BASE), // mandatory ARRAY_COMPRESS_NORMAL = 1 << (ARRAY_NORMAL + ARRAY_COMPRESS_BASE), ARRAY_COMPRESS_TANGENT = 1 << (ARRAY_TANGENT + ARRAY_COMPRESS_BASE), ARRAY_COMPRESS_COLOR = 1 << (ARRAY_COLOR + ARRAY_COMPRESS_BASE), ARRAY_COMPRESS_TEX_UV = 1 << (ARRAY_TEX_UV + ARRAY_COMPRESS_BASE), ARRAY_COMPRESS_TEX_UV2 = 1 << (ARRAY_TEX_UV2 + ARRAY_COMPRESS_BASE), - ARRAY_COMPRESS_BONES = 1 << (ARRAY_BONES + ARRAY_COMPRESS_BASE), - ARRAY_COMPRESS_WEIGHTS = 1 << (ARRAY_WEIGHTS + ARRAY_COMPRESS_BASE), ARRAY_COMPRESS_INDEX = 1 << (ARRAY_INDEX + ARRAY_COMPRESS_BASE), ARRAY_FLAG_USE_2D_VERTICES = ARRAY_COMPRESS_INDEX << 1, - ARRAY_FLAG_USE_16_BIT_BONES = ARRAY_COMPRESS_INDEX << 2, ARRAY_FLAG_USE_DYNAMIC_UPDATE = ARRAY_COMPRESS_INDEX << 3, - ARRAY_COMPRESS_DEFAULT = ARRAY_COMPRESS_NORMAL | ARRAY_COMPRESS_TANGENT | ARRAY_COMPRESS_COLOR | ARRAY_COMPRESS_TEX_UV | ARRAY_COMPRESS_TEX_UV2 | ARRAY_COMPRESS_WEIGHTS + ARRAY_COMPRESS_DEFAULT = ARRAY_COMPRESS_NORMAL | ARRAY_COMPRESS_TANGENT | ARRAY_COMPRESS_COLOR | ARRAY_COMPRESS_TEX_UV | ARRAY_COMPRESS_TEX_UV2 }; enum PrimitiveType { PRIMITIVE_POINTS = VisualServer::PRIMITIVE_POINTS, PRIMITIVE_LINES = VisualServer::PRIMITIVE_LINES, + PRIMITIVE_LINE_STRIP = VisualServer::PRIMITIVE_LINE_STRIP, PRIMITIVE_TRIANGLES = VisualServer::PRIMITIVE_TRIANGLES, + PRIMITIVE_TRIANGLE_STRIP = VisualServer::PRIMITIVE_TRIANGLE_STRIP, PRIMITIVE_MAX = VisualServer::PRIMITIVE_MAX, }; @@ -120,6 +118,7 @@ public: virtual bool surface_is_softbody_friendly(int p_idx) const; virtual Array surface_get_arrays(int p_surface) const = 0; virtual Array surface_get_blend_shape_arrays(int p_surface) const = 0; + virtual Dictionary surface_get_lods(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 void surface_set_material(int p_idx, const Ref<Material> &p_material) = 0; @@ -157,20 +156,29 @@ class ArrayMesh : public Mesh { GDCLASS(ArrayMesh, Mesh); RES_BASE_EXTENSION("mesh"); + Array _get_surfaces() const; + void _set_surfaces(const Array &p_data); + private: struct Surface { + uint32_t format; + int array_length; + int index_array_length; + PrimitiveType primitive; + String name; AABB aabb; Ref<Material> material; bool is_2d; }; Vector<Surface> surfaces; - RID mesh; + mutable RID mesh; AABB aabb; BlendShapeMode blend_shape_mode; Vector<StringName> blend_shapes; AABB custom_aabb; + _FORCE_INLINE_ void _create_if_empty() const; void _recompute_aabb(); protected: @@ -183,11 +191,13 @@ protected: static void _bind_methods(); public: - void add_surface_from_arrays(PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes = Array(), uint32_t p_flags = ARRAY_COMPRESS_DEFAULT); - void 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 AABB &p_aabb, const Vector<PoolVector<uint8_t> > &p_blend_shapes = Vector<PoolVector<uint8_t> >(), const Vector<AABB> &p_bone_aabbs = Vector<AABB>()); + void add_surface_from_arrays(PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes = Array(), const Dictionary &p_lods = Dictionary(), uint32_t p_flags = ARRAY_COMPRESS_DEFAULT); + + void 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 AABB &p_aabb, const Vector<PoolVector<uint8_t> > &p_blend_shapes = Vector<PoolVector<uint8_t> >(), const Vector<AABB> &p_bone_aabbs = Vector<AABB>(), const Vector<VS::SurfaceData::LOD> &p_lods = Vector<VS::SurfaceData::LOD>()); Array surface_get_arrays(int p_surface) const; Array surface_get_blend_shape_arrays(int p_surface) const; + Dictionary surface_get_lods(int p_surface) const; void add_blend_shape(const StringName &p_name); int get_blend_shape_count() const; @@ -202,6 +212,8 @@ public: int get_surface_count() const; void surface_remove(int p_idx); + void clear_surfaces(); + void surface_set_custom_aabb(int p_idx, const AABB &p_aabb); //only recognized by driver int surface_get_array_len(int p_idx) const; @@ -217,8 +229,6 @@ public: void surface_set_name(int p_idx, const String &p_name); String surface_get_name(int p_idx) const; - void add_surface_from_mesh_data(const Geometry::MeshData &p_mesh_data); - void set_custom_aabb(const AABB &p_custom); AABB get_custom_aabb() const; diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp index 74df72619a..79d030b8ab 100644 --- a/scene/resources/primitive_meshes.cpp +++ b/scene/resources/primitive_meshes.cpp @@ -57,9 +57,11 @@ void PrimitiveMesh::_update() const { } } + PoolVector<int> indices = arr[VS::ARRAY_INDEX]; + if (flip_faces) { PoolVector<Vector3> normals = arr[VS::ARRAY_NORMAL]; - PoolVector<int> indices = arr[VS::ARRAY_INDEX]; + if (normals.size() && indices.size()) { { @@ -82,6 +84,8 @@ void PrimitiveMesh::_update() const { } } + array_len = pc; + index_array_len = indices.size(); // in with the new VisualServer::get_singleton()->mesh_clear(mesh); VisualServer::get_singleton()->mesh_add_surface_from_arrays(mesh, (VisualServer::PrimitiveType)primitive_type, arr); @@ -114,7 +118,7 @@ int PrimitiveMesh::surface_get_array_len(int p_idx) const { _update(); } - return VisualServer::get_singleton()->mesh_surface_get_array_len(mesh, 0); + return array_len; } int PrimitiveMesh::surface_get_array_index_len(int p_idx) const { @@ -123,7 +127,7 @@ int PrimitiveMesh::surface_get_array_index_len(int p_idx) const { _update(); } - return VisualServer::get_singleton()->mesh_surface_get_array_index_len(mesh, 0); + return index_array_len; } Array PrimitiveMesh::surface_get_arrays(int p_surface) const { @@ -135,22 +139,18 @@ Array PrimitiveMesh::surface_get_arrays(int p_surface) const { return VisualServer::get_singleton()->mesh_surface_get_arrays(mesh, 0); } +Dictionary PrimitiveMesh::surface_get_lods(int p_surface) const { + return Dictionary(); //not really supported +} Array PrimitiveMesh::surface_get_blend_shape_arrays(int p_surface) const { - ERR_FAIL_INDEX_V(p_surface, 1, Array()); - if (pending_request) { - _update(); - } - return Array(); + return Array(); //not really supported } 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); + return VS::ARRAY_COMPRESS_DEFAULT; } Mesh::PrimitiveType PrimitiveMesh::surface_get_primitive_type(int p_idx) const { @@ -261,6 +261,9 @@ PrimitiveMesh::PrimitiveMesh() { // make sure we do an update after we've finished constructing our object pending_request = true; + + array_len = 0; + index_array_len = 0; } PrimitiveMesh::~PrimitiveMesh() { diff --git a/scene/resources/primitive_meshes.h b/scene/resources/primitive_meshes.h index 47126f1862..5f17680c9e 100644 --- a/scene/resources/primitive_meshes.h +++ b/scene/resources/primitive_meshes.h @@ -50,6 +50,9 @@ private: mutable AABB aabb; AABB custom_aabb; + mutable int array_len; + mutable int index_array_len; + Ref<Material> material; bool flip_faces; @@ -70,6 +73,7 @@ public: virtual int surface_get_array_index_len(int p_idx) const; virtual Array surface_get_arrays(int p_surface) const; virtual Array surface_get_blend_shape_arrays(int p_surface) const; + virtual Dictionary surface_get_lods(int p_surface) const; virtual uint32_t surface_get_format(int p_idx) const; virtual Mesh::PrimitiveType surface_get_primitive_type(int p_idx) const; virtual void surface_set_material(int p_idx, const Ref<Material> &p_material); diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp index f921a9695c..a1e6430255 100644 --- a/scene/resources/surface_tool.cpp +++ b/scene/resources/surface_tool.cpp @@ -466,7 +466,7 @@ Ref<ArrayMesh> SurfaceTool::commit(const Ref<ArrayMesh> &p_existing, uint32_t p_ Array a = commit_to_arrays(); - mesh->add_surface_from_arrays(primitive, a, Array(), p_flags); + mesh->add_surface_from_arrays(primitive, a, Array(), Dictionary(), p_flags); if (material.is_valid()) mesh->surface_set_material(surface, material); |