From 941cff4157b2655f3971cf688a7e45d7008ac193 Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Mon, 27 Sep 2021 11:56:58 -0700 Subject: [PATCH] Update mesh AABB when software skinning is used Not updating the mesh properly can cause rendering issues in some cases, like shadows not updating properly. --- scene/3d/mesh_instance.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scene/3d/mesh_instance.cpp b/scene/3d/mesh_instance.cpp index 56fa6de72fb6..4b727b398475 100644 --- a/scene/3d/mesh_instance.cpp +++ b/scene/3d/mesh_instance.cpp @@ -390,6 +390,9 @@ void MeshInstance::_update_skinning() { RID skeleton = skin_ref->get_skeleton(); ERR_FAIL_COND(!skeleton.is_valid()); + AABB aabb; + bool first_vertex = true; + VisualServer *visual_server = VisualServer::get_singleton(); // Prepare bone transforms. @@ -499,11 +502,20 @@ void MeshInstance::_update_skinning() { tangent = transform.basis.xform(tangent_read); } } + + if (first_vertex) { + aabb.position = vertex; + first_vertex = false; + } else { + aabb.expand_to(vertex); + } } visual_server->mesh_surface_update_region(mesh_rid, surface_index, 0, buffer); } + visual_server->mesh_set_custom_aabb(mesh_rid, aabb); + software_skinning_flags |= SoftwareSkinning::FLAG_BONES_READY; }