Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GLTF, DAE and FBX importers enforcement for blend shape mask array #59489

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions editor/import/editor_import_collada.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,13 +994,12 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &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);
}

Expand Down
11 changes: 11 additions & 0 deletions modules/fbx/data/fbx_mesh_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions modules/gltf/gltf_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2907,6 +2907,13 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> 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);
}
}
Expand Down