From 5e6d4baa48b0104f1f0778d098aa145b8ce368a8 Mon Sep 17 00:00:00 2001 From: Adam Scott Date: Thu, 24 Mar 2022 17:15:23 -0400 Subject: [PATCH] Add GLTF, DAE and FBX importers enforcement for blend shape mask array --- editor/import/editor_import_collada.cpp | 11 +++++------ modules/fbx/data/fbx_mesh_data.cpp | 11 +++++++++++ modules/gltf/gltf_document.cpp | 7 +++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index 3b5a82b2c339..69fa64c24cc0 100644 --- a/editor/import/editor_import_collada.cpp +++ b/editor/import/editor_import_collada.cpp @@ -994,13 +994,12 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref &p Array a = p_morph_meshes[mi]->get_surface_arrays(surface); //add valid weight and bone arrays if they exist, TODO check if they are unique to shape (generally not) - if (has_weights) { - a[Mesh::ARRAY_WEIGHTS] = d[Mesh::ARRAY_WEIGHTS]; - a[Mesh::ARRAY_BONES] = d[Mesh::ARRAY_BONES]; + // Enforce blend shape mask array format + for (int mj = 0; mj < Mesh::ARRAY_MAX; mj++) { + if (!(Mesh::ARRAY_FORMAT_BLEND_SHAPE_MASK & (1 << mj))) { + a[mj] = Variant(); + } } - - a[Mesh::ARRAY_INDEX] = Variant(); - //a.resize(Mesh::ARRAY_MAX); //no need for index mr.push_back(a); } diff --git a/modules/fbx/data/fbx_mesh_data.cpp b/modules/fbx/data/fbx_mesh_data.cpp index 643a74f83e9c..1d5985177876 100644 --- a/modules/fbx/data/fbx_mesh_data.cpp +++ b/modules/fbx/data/fbx_mesh_data.cpp @@ -371,6 +371,17 @@ ImporterMeshInstance3D *FBXMeshData::create_fbx_mesh(const ImportState &state, c Array mesh_array = surface->surface_tool->commit_to_arrays(); Array blend_shapes = surface->morphs; + // Enforce blend shape mask array format + for (int i = 0; i < blend_shapes.size(); i++) { + Array bsdata = blend_shapes[i]; + + for (int j = 0; j < Mesh::ARRAY_MAX; j++) { + if (!(Mesh::ARRAY_FORMAT_BLEND_SHAPE_MASK & (1 << j))) { + bsdata[j] = Variant(); + } + } + } + if (surface->material.is_valid()) { mesh->add_surface(Mesh::PRIMITIVE_TRIANGLES, mesh_array, blend_shapes, Dictionary(), surface->material, surface->material->get_name()); } else { diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index c70081a62098..a8211569ebe7 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -2907,6 +2907,13 @@ Error GLTFDocument::_parse_meshes(Ref state) { } array_copy = blend_surface_tool->commit_to_arrays(); + // Enforce blend shape mask array format + for (int l = 0; l < Mesh::ARRAY_MAX; l++) { + if (!(Mesh::ARRAY_FORMAT_BLEND_SHAPE_MASK & (1 << l))) { + array_copy[l] = Variant(); + } + } + morphs.push_back(array_copy); } }