瀏覽代碼

Merge pull request #65035 from nathanfranke/fix-aabb-mesh

Fix AABB errors on meshes with bones on multiple surfaces
Rémi Verschelde 2 年之前
父節點
當前提交
43e9ca40ff
共有 2 個文件被更改,包括 16 次插入2 次删除
  1. 8 1
      drivers/gles3/storage/mesh_storage.cpp
  2. 8 1
      servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp

+ 8 - 1
drivers/gles3/storage/mesh_storage.cpp

@@ -334,7 +334,14 @@ void MeshStorage::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface)
 		for (int i = 0; i < p_surface.bone_aabbs.size(); i++) {
 			const AABB &bone = p_surface.bone_aabbs[i];
 			if (bone.has_volume()) {
-				mesh->bone_aabbs.write[i].merge_with(bone);
+				AABB &mesh_bone = mesh->bone_aabbs.write[i];
+				if (mesh_bone != AABB()) {
+					// Already initialized, merge AABBs.
+					mesh_bone.merge_with(bone);
+				} else {
+					// Not yet initialized, copy the bone AABB.
+					mesh_bone = bone;
+				}
 			}
 		}
 		mesh->aabb.merge_with(p_surface.aabb);

+ 8 - 1
servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp

@@ -445,7 +445,14 @@ void MeshStorage::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface)
 		for (int i = 0; i < p_surface.bone_aabbs.size(); i++) {
 			const AABB &bone = p_surface.bone_aabbs[i];
 			if (bone.has_volume()) {
-				mesh->bone_aabbs.write[i].merge_with(bone);
+				AABB &mesh_bone = mesh->bone_aabbs.write[i];
+				if (mesh_bone != AABB()) {
+					// Already initialized, merge AABBs.
+					mesh_bone.merge_with(bone);
+				} else {
+					// Not yet initialized, copy the bone AABB.
+					mesh_bone = bone;
+				}
 			}
 		}
 		mesh->aabb.merge_with(p_surface.aabb);