From 634aa4fc24dcc2ca5ebb284a0deb4664d6f1266b Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 19 Nov 2018 10:42:27 -0300 Subject: [PATCH] Ensure bone AABBs are properly transformed to affect mesh AABB, fixes #19281 --- drivers/gles3/rasterizer_storage_gles3.cpp | 9 +++++++-- scene/resources/mesh.cpp | 1 + servers/visual_server.cpp | 2 +- servers/visual_server.h | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index 64e04eec71c..65543956faf 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -3787,12 +3787,14 @@ AABB RasterizerStorageGLES3::mesh_get_aabb(RID p_mesh, RID p_skeleton) const { Mesh *mesh = mesh_owner.get(p_mesh); ERR_FAIL_COND_V(!mesh, AABB()); - if (mesh->custom_aabb != AABB()) + if (mesh->custom_aabb != AABB()) { return mesh->custom_aabb; + } Skeleton *sk = NULL; - if (p_skeleton.is_valid()) + if (p_skeleton.is_valid()) { sk = skeleton_owner.get(p_skeleton); + } AABB aabb; @@ -3831,6 +3833,7 @@ AABB RasterizerStorageGLES3::mesh_get_aabb(RID p_mesh, RID p_skeleton) const { mtx.origin.y = texture[base_ofs + 3]; AABB baabb = mtx.xform(skbones[j]); + if (first) { laabb = baabb; first = false; @@ -3863,6 +3866,8 @@ AABB RasterizerStorageGLES3::mesh_get_aabb(RID p_mesh, RID p_skeleton) const { mtx.basis[2].z = texture[base_ofs + 2]; mtx.origin.z = texture[base_ofs + 3]; + print_line("surface " + itos(i) + " bone " + itos(j) + " aabb: " + skbones[j]); + AABB baabb = mtx.xform(skbones[j]); if (first) { laabb = baabb; diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 838d73edb3d..80191367ce9 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -706,6 +706,7 @@ bool ArrayMesh::_get(const StringName &p_name, Variant &r_ret) const { Vector skel_aabb = VS::get_singleton()->mesh_surface_get_skeleton_aabb(mesh, idx); Array arr; + arr.resize(skel_aabb.size()); for (int i = 0; i < skel_aabb.size(); i++) { arr[i] = skel_aabb[i]; } diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index ca5271190c0..e1db123f58d 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -343,7 +343,7 @@ RID VisualServer::get_white_texture() { #define SMALL_VEC2 Vector2(0.00001, 0.00001) #define SMALL_VEC3 Vector3(0.00001, 0.00001, 0.00001) -Error VisualServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint32_t *p_offsets, uint32_t p_stride, PoolVector &r_vertex_array, int p_vertex_array_len, PoolVector &r_index_array, int p_index_array_len, AABB &r_aabb, Vector r_bone_aabb) { +Error VisualServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint32_t *p_offsets, uint32_t p_stride, PoolVector &r_vertex_array, int p_vertex_array_len, PoolVector &r_index_array, int p_index_array_len, AABB &r_aabb, Vector &r_bone_aabb) { PoolVector::Write vw = r_vertex_array.write(); diff --git a/servers/visual_server.h b/servers/visual_server.h index 59eb43da97f..743e0100343 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -61,7 +61,7 @@ protected: RID white_texture; RID test_material; - Error _surface_set_data(Array p_arrays, uint32_t p_format, uint32_t *p_offsets, uint32_t p_stride, PoolVector &r_vertex_array, int p_vertex_array_len, PoolVector &r_index_array, int p_index_array_len, AABB &r_aabb, Vector r_bone_aabb); + Error _surface_set_data(Array p_arrays, uint32_t p_format, uint32_t *p_offsets, uint32_t p_stride, PoolVector &r_vertex_array, int p_vertex_array_len, PoolVector &r_index_array, int p_index_array_len, AABB &r_aabb, Vector &r_bone_aabb); static VisualServer *(*create_func)(); static void _bind_methods();