Skip to content

fix: Assimp skeleton/animation importer for models with duplicate node names#2444

Merged
Eideren merged 1 commit into
stride3d:masterfrom
Basewq:assimp_anim_fix
Sep 15, 2024
Merged

fix: Assimp skeleton/animation importer for models with duplicate node names#2444
Eideren merged 1 commit into
stride3d:masterfrom
Basewq:assimp_anim_fix

Conversation

@Basewq

@Basewq Basewq commented Sep 12, 2024

Copy link
Copy Markdown
Contributor

PR Details

See model in #2406 (be aware the second animation seems to play strangely, but this is consistent with how it plays in Blender 3.6 - it didn't import properly in a higher version of Blender)

Assimp has a generic 'Node' hierarchy structure and a 'Bone' list (per mesh).
Each Bone has a corresponding 'Node', however the link between the two is only done by name.
Unfortunately, this is a problem when a model has duplicate names, eg. the model's armature and bone, and Stride will more than likely link the 'Bone' to the non-Bone node.
This fix attempts to make an educated guess whenever duplicated names occurs.
If it fails to properly detect what should be linked, then it'll output a warning/error telling the end-user to make the name unique.

While aiPostProcessSteps.aiProcess_PopulateArmatureData does exist on the importer which is supposed to link the bone to the node, it does not make any effort to correctly link a bone to the bone node if duplicate names exist (it just searches for the first matching name), so this is not used.

Related Issue

This is a fundamental flaw in Assimp, assimp/assimp#4064 may help if it gets resolved.

Fixes #2406

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have built and run the editor to try this change out.

@Eideren Eideren left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one nitpick

{
nodeIndices = new();
duplicateNodeNameToNodeIndices[originalNodeName] = nodeIndices;
//Logger.Warning($"Duplicate node name found: {originalNodeName}. Animations may not play correctly if this node is used in an animation.");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated commented out line afaict ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hesitant on whether to log a warning here, because technically the whole point of the other code is to actually try to resolve the duplicate nodes.
But now I just realized I can just output this at Info level.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Changed to output at Info level, and rebased the commit to the latest.

…ect node when a model has duplicate node names
@Eideren Eideren merged commit 37bbf0c into stride3d:master Sep 15, 2024
@Eideren

Eideren commented Sep 15, 2024

Copy link
Copy Markdown
Collaborator

Thanks !

@Eideren Eideren changed the title Fix Assimp skeleton/animation importer for models with duplicate node names fix: Assimp skeleton/animation importer for models with duplicate node names Sep 15, 2024
@Basewq Basewq deleted the assimp_anim_fix branch September 16, 2024 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

*.glb asset is imported with broken mesh

2 participants