Skip to content

Commit

Permalink
Merge pull request #44649 from lyuma/bone_aabb_blendshapes
Browse files Browse the repository at this point in the history
Fix blendshapes and calculation of bone_aabbs
  • Loading branch information
akien-mga authored Dec 24, 2020
2 parents 4d9b95f + d976003 commit ecda989
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions editor/import/scene_importer_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ void EditorSceneImporterMesh::add_surface(Mesh::PrimitiveType p_primitive, const
s.arrays = p_arrays;
s.name = p_name;

Vector<Vector3> vertex_array = p_arrays[Mesh::ARRAY_VERTEX];
int vertex_count = vertex_array.size();
ERR_FAIL_COND(vertex_count == 0);

for (int i = 0; i < blend_shapes.size(); i++) {
Array bsdata = p_blend_shapes[i];
ERR_FAIL_COND(bsdata.size() != Mesh::ARRAY_MAX);
Vector<Vector3> vertex_data = bsdata[Mesh::ARRAY_VERTEX];
ERR_FAIL_COND(vertex_data.size() != vertex_count);
Surface::BlendShape bs;
bs.arrays = bsdata;
s.blend_shape_data.push_back(bs);
Expand Down
8 changes: 5 additions & 3 deletions servers/rendering/renderer_rd/renderer_storage_rd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2408,9 +2408,6 @@ void RendererStorageRD::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_su
Mesh *mesh = mesh_owner.getornull(p_mesh);
ERR_FAIL_COND(!mesh);

//ensure blend shape consistency
ERR_FAIL_COND(mesh->blend_shape_count && p_surface.bone_aabbs.size() != mesh->bone_aabbs.size());

#ifdef DEBUG_ENABLED
//do a validation, to catch errors first
{
Expand Down Expand Up @@ -2576,6 +2573,11 @@ void RendererStorageRD::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_su
mesh->bone_aabbs = p_surface.bone_aabbs;
mesh->aabb = p_surface.aabb;
} else {
if (mesh->bone_aabbs.size() < p_surface.bone_aabbs.size()) {
// ArrayMesh::_surface_set_data only allocates bone_aabbs up to max_bone
// Each surface may affect different numbers of bones.
mesh->bone_aabbs.resize(p_surface.bone_aabbs.size());
}
for (int i = 0; i < p_surface.bone_aabbs.size(); i++) {
mesh->bone_aabbs.write[i].merge_with(p_surface.bone_aabbs[i]);
}
Expand Down

0 comments on commit ecda989

Please sign in to comment.