diff options
Diffstat (limited to 'scene/3d/mesh_instance_3d.cpp')
-rw-r--r-- | scene/3d/mesh_instance_3d.cpp | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/scene/3d/mesh_instance_3d.cpp b/scene/3d/mesh_instance_3d.cpp index d4f60503c2..10f3ab5c79 100644 --- a/scene/3d/mesh_instance_3d.cpp +++ b/scene/3d/mesh_instance_3d.cpp @@ -33,6 +33,8 @@ #include "collision_shape_3d.h" #include "core/core_string_names.h" #include "physics_body_3d.h" +#include "scene/resources/concave_polygon_shape_3d.h" +#include "scene/resources/convex_polygon_shape_3d.h" bool MeshInstance3D::_set(const StringName &p_name, const Variant &p_value) { //this is not _too_ bad performance wise, really. it only arrives here if the property was not set anywhere else. @@ -50,11 +52,22 @@ bool MeshInstance3D::_set(const StringName &p_name, const Variant &p_value) { if (p_name.operator String().begins_with("surface_material_override/")) { int idx = p_name.operator String().get_slicec('/', 1).to_int(); - if (idx >= surface_override_materials.size() || idx < 0) { + + // This is a bit of a hack to ensure compatibility with older material + // overrides that start indexing at 0. + // We assume that idx 0 is always read first, if its not, this won't work. + if (idx == 0) { + old_surface_index = true; + } + if (old_surface_index) { + idx++; + } + + if (idx > surface_override_materials.size() || idx < 0) { return false; } - set_surface_override_material(idx, p_value); + set_surface_override_material(idx - 1, p_value); return true; } @@ -73,7 +86,7 @@ bool MeshInstance3D::_get(const StringName &p_name, Variant &r_ret) const { } if (p_name.operator String().begins_with("surface_material_override/")) { - int idx = p_name.operator String().get_slicec('/', 1).to_int(); + int idx = p_name.operator String().get_slicec('/', 1).to_int() - 1; if (idx >= surface_override_materials.size() || idx < 0) { return false; } @@ -96,7 +109,7 @@ void MeshInstance3D::_get_property_list(List<PropertyInfo> *p_list) const { } if (mesh.is_valid()) { - for (int i = 0; i < mesh->get_surface_count(); i++) { + for (int i = 1; i <= mesh->get_surface_count(); i++) { p_list->push_back(PropertyInfo(Variant::OBJECT, vformat("%s/%d", PNAME("surface_material_override"), i), PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DEFERRED_SET_RESOURCE)); } } @@ -224,7 +237,7 @@ Node *MeshInstance3D::create_trimesh_collision_node() { return nullptr; } - Ref<Shape3D> shape = mesh->create_trimesh_shape(); + Ref<ConcavePolygonShape3D> shape = mesh->create_trimesh_shape(); if (shape.is_null()) { return nullptr; } @@ -254,7 +267,7 @@ Node *MeshInstance3D::create_convex_collision_node(bool p_clean, bool p_simplify return nullptr; } - Ref<Shape3D> shape = mesh->create_convex_shape(p_clean, p_simplify); + Ref<ConvexPolygonShape3D> shape = mesh->create_convex_shape(p_clean, p_simplify); if (shape.is_null()) { return nullptr; } @@ -320,6 +333,11 @@ void MeshInstance3D::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { _resolve_skeleton_path(); } break; + case NOTIFICATION_TRANSLATION_CHANGED: { + if (mesh.is_valid()) { + mesh->notification(NOTIFICATION_TRANSLATION_CHANGED); + } + } break; } } |