Fix handling missing skins using ufbx importer

Previously, _asset_parse_skins() would mess with the order of skin indices.
However, the rest of the code expected these to match to ufbx skin indices.
To fix this, retain the original skin indices in FBXState::original_skin_indices.
This commit is contained in:
bqqbarbhg 2024-05-03 20:46:26 +03:00
parent 03e6fbb010
commit b9ab0e46e2
2 changed files with 5 additions and 6 deletions

View File

@ -693,10 +693,7 @@ Error FBXDocument::_parse_meshes(Ref<FBXState> p_state) {
// Find the first imported skin deformer // Find the first imported skin deformer
for (ufbx_skin_deformer *fbx_skin : fbx_mesh->skin_deformers) { for (ufbx_skin_deformer *fbx_skin : fbx_mesh->skin_deformers) {
if (!p_state->skin_indices.has(fbx_skin->typed_id)) { GLTFSkinIndex skin_i = p_state->original_skin_indices[fbx_skin->typed_id];
continue;
}
GLTFSkinIndex skin_i = p_state->skin_indices[fbx_skin->typed_id];
if (skin_i < 0) { if (skin_i < 0) {
continue; continue;
} }
@ -2341,7 +2338,7 @@ Error FBXDocument::_parse_skins(Ref<FBXState> p_state) {
HashMap<GLTFNodeIndex, bool> joint_mapping; HashMap<GLTFNodeIndex, bool> joint_mapping;
for (const ufbx_skin_deformer *fbx_skin : fbx_scene->skin_deformers) { for (const ufbx_skin_deformer *fbx_skin : fbx_scene->skin_deformers) {
if (fbx_skin->clusters.count == 0) { if (fbx_skin->clusters.count == 0 || fbx_skin->weights.count == 0) {
p_state->skin_indices.push_back(-1); p_state->skin_indices.push_back(-1);
continue; continue;
} }
@ -2387,8 +2384,9 @@ Error FBXDocument::_parse_skins(Ref<FBXState> p_state) {
} }
} }
} }
p_state->original_skin_indices = p_state->skin_indices.duplicate();
Error err = SkinTool::_asset_parse_skins( Error err = SkinTool::_asset_parse_skins(
p_state->skin_indices.duplicate(), p_state->original_skin_indices,
p_state->skins.duplicate(), p_state->skins.duplicate(),
p_state->nodes.duplicate(), p_state->nodes.duplicate(),
p_state->skin_indices, p_state->skin_indices,

View File

@ -53,6 +53,7 @@ class FBXState : public GLTFState {
HashMap<Pair<uint64_t, uint64_t>, GLTFTextureIndex, PairHash<uint64_t, uint64_t>> albedo_transparency_textures; HashMap<Pair<uint64_t, uint64_t>, GLTFTextureIndex, PairHash<uint64_t, uint64_t>> albedo_transparency_textures;
Vector<GLTFSkinIndex> skin_indices; Vector<GLTFSkinIndex> skin_indices;
Vector<GLTFSkinIndex> original_skin_indices;
HashMap<ObjectID, GLTFSkeletonIndex> skeleton3d_to_fbx_skeleton; HashMap<ObjectID, GLTFSkeletonIndex> skeleton3d_to_fbx_skeleton;
HashMap<ObjectID, HashMap<ObjectID, GLTFSkinIndex>> skin_and_skeleton3d_to_fbx_skin; HashMap<ObjectID, HashMap<ObjectID, GLTFSkinIndex>> skin_and_skeleton3d_to_fbx_skin;
HashSet<String> unique_mesh_names; // Not in GLTFState because GLTFState prefixes mesh names with the scene name (or _) HashSet<String> unique_mesh_names; // Not in GLTFState because GLTFState prefixes mesh names with the scene name (or _)