From ff27b994cd1dfd9fc67c4c07befac94d0d6bbcfe Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Wed, 6 Oct 2021 23:25:14 +0800 Subject: [PATCH] Re-prepare VisualServer if SoftBody mesh changed --- scene/3d/soft_body.cpp | 5 +++-- scene/3d/soft_body.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/scene/3d/soft_body.cpp b/scene/3d/soft_body.cpp index becd3f2f32f..61947076a8e 100644 --- a/scene/3d/soft_body.cpp +++ b/scene/3d/soft_body.cpp @@ -437,8 +437,9 @@ void SoftBody::_draw_soft_mesh() { return; } - if (!visual_server_handler.is_ready()) { - visual_server_handler.prepare(get_mesh()->get_rid(), 0); + const RID mesh_rid = get_mesh()->get_rid(); + if (!visual_server_handler.is_ready(mesh_rid)) { + visual_server_handler.prepare(mesh_rid, 0); /// Necessary in order to render the mesh correctly (Soft body nodes are in global space) simulation_started = true; diff --git a/scene/3d/soft_body.h b/scene/3d/soft_body.h index 437889b8c60..001f4ef62b0 100644 --- a/scene/3d/soft_body.h +++ b/scene/3d/soft_body.h @@ -49,7 +49,7 @@ class SoftBodyVisualServerHandler { private: SoftBodyVisualServerHandler(); - bool is_ready() { return mesh.is_valid(); } + bool is_ready(RID p_mesh_rid) const { return mesh.is_valid() && mesh == p_mesh_rid; } void prepare(RID p_mesh_rid, int p_surface); void clear(); void open();