Skip to content

fix(MeshHelper): compressed mesh bone weights and UV sets - #390

Open
nichinichisou0609 wants to merge 2 commits into
K0lb3:masterfrom
nichinichisou0609:fix/compressed-mesh
Open

nichinichisou0609 wants to merge 2 commits into
K0lb3:masterfrom
nichinichisou0609:fix/compressed-mesh

Conversation

@nichinichisou0609

@nichinichisou0609 nichinichisou0609 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Meshes imported with Mesh Compression store their vertex data in m_CompressedMesh. Two values decoded from it are wrong; one commit each.

  • Implied fourth bone weight. A compressed mesh stores up to three 5-bit weights per vertex and implies the fourth when they don't add up to 31. Since MeshHandler: Fix weightsData dequantization error #338 the running sum counts 5-bit units, but the implied weight was still computed as 1 - sum, so weights 10, 10, 5 gave a fourth weight of -24. It is now (31 - sum) / 31, and the four weights of a vertex add up to 1.
  • Third and later UV sets. With m_UVInfo set, the UV sets are stored back to back in m_UV. The read offset was assigned the size of the current set instead of advancing by it, so every set after the second was read from the second set's position and came back as a copy of it. The offset now accumulates.

Compressed meshes store up to three 5-bit weights per vertex and imply
the fourth one when they do not add up to 31. The running sum counts
5-bit units since K0lb3#338, but the implied weight was still computed as
1 - sum, which gives a negative weight (-24 for weights 10, 10, 5).
It is now (31 - sum) / 31, so the four weights of a vertex add up to 1.
With m_UVInfo set, a compressed mesh stores its texture coordinate sets
back to back in m_UV. The read offset was assigned the size of the
current set instead of advancing by it, so every set after the second
one was read from the position of the second set and came back as a
copy of it. The offset now accumulates, as the sets are stored.
@nichinichisou0609

nichinichisou0609 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Same as in #384/#391: removed the test file and rebased on master. The two fixes are unchanged.

I attached a tiny AssetBundle with one compressed skinned mesh (three UV sets), built from an empty Unity 2022.3 project, with the build script. Its README shows the weights and UVs before and after.

unitypy-390-samples.zip

This branch has not been deployed

No deployments
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.

1 participant