diff options
author | Trevor Davenport <trevor.davenport@gmail.com> | 2024-10-03 08:14:19 -0600 |
---|---|---|
committer | Trevor Davenport <trevor.davenport@gmail.com> | 2024-10-03 18:08:49 -0600 |
commit | 47f75547ce976988fd067c66ae6345d57771616b (patch) | |
tree | fc84ef85578e69fd44f8137c3e8599ba775f786d | |
parent | 2e144928793f17ebd70e1475bb7a7f4fd1095484 (diff) | |
download | redot-engine-47f75547ce976988fd067c66ae6345d57771616b.tar.gz |
Fix immediate mesh modifications that don't call set_mesh
Mesh_instance_2d has no way to know when the mesh had been modified
unless you called set_mesh. This meant that you could modify the
underlying mesh without it knowing which could result in incorrect
result.
Modified mesh_instance_2d to be more similar to mesh_instance_3d which
connects to the changed signal of the mesh and reacts occordingly.
-rw-r--r-- | scene/2d/mesh_instance_2d.cpp | 13 | ||||
-rw-r--r-- | scene/resources/immediate_mesh.cpp | 2 |
2 files changed, 15 insertions, 0 deletions
diff --git a/scene/2d/mesh_instance_2d.cpp b/scene/2d/mesh_instance_2d.cpp index ae45d431fe..1031a67343 100644 --- a/scene/2d/mesh_instance_2d.cpp +++ b/scene/2d/mesh_instance_2d.cpp @@ -54,7 +54,20 @@ void MeshInstance2D::_bind_methods() { } void MeshInstance2D::set_mesh(const Ref<Mesh> &p_mesh) { + if (mesh == p_mesh) { + return; + } + + if (mesh.is_valid()) { + mesh->disconnect_changed(callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw)); + } + mesh = p_mesh; + + if (mesh.is_valid()) { + mesh->connect_changed(callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw)); + } + queue_redraw(); } diff --git a/scene/resources/immediate_mesh.cpp b/scene/resources/immediate_mesh.cpp index 907c0ab4ca..072542f0ad 100644 --- a/scene/resources/immediate_mesh.cpp +++ b/scene/resources/immediate_mesh.cpp @@ -312,6 +312,8 @@ void ImmediateMesh::surface_end() { uses_uv2s = false; surface_active = false; + + emit_changed(); } void ImmediateMesh::clear_surfaces() { |