Skip to content

Sort bone weights descending before Resize(4) truncation#22

Merged
ousnius merged 2 commits intoousnius:mainfrom
MANOLOV02:fix/updateskinpartitions-sort-desc
Apr 25, 2026
Merged

Sort bone weights descending before Resize(4) truncation#22
ousnius merged 2 commits intoousnius:mainfrom
MANOLOV02:fix/updateskinpartitions-sort-desc

Conversation

@MANOLOV02
Copy link
Copy Markdown
Contributor

UpdateSkinPartitions sorts per-vertex bone weights with lhs.CompareTo(rhs) (ascending) and then calls Resize(4), which discards the heaviest weights instead of the lightest. Vertices with more than 4 influences end up keeping their weakest bones.

C++ reference: nifly/include/NifFile.hpp:50BoneWeightsSort::operator() returns rhs.weight < lhs.weight, i.e. descending.

Fix: change the comparator to rhs.CompareTo(lhs).

Maps to issue #15 item B5.

MANOLOV02 and others added 2 commits April 25, 2026 17:46
Sort order was ascending (`lhs.Weight.CompareTo(rhs.Weight)`), so when
the subsequent `Resize(4)` limited each vertex to at most four
influences, it discarded the LARGEST weights and kept the smallest.
Skinning of vertices with more than four bone influences produced
visibly broken deformation after this code path ran.

Matches C++ nifly NifFile.hpp:50 `BoneWeightsSort` operator which
returns `rhs.weight < lhs.weight` (descending).
@ousnius ousnius merged commit 65b4823 into ousnius:main Apr 25, 2026
1 check passed
@MANOLOV02 MANOLOV02 deleted the fix/updateskinpartitions-sort-desc branch April 25, 2026 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants