Skip to content

fix(assets): decode normalized glTF skin weights#654

Open
Changdw wants to merge 3 commits into
cocos:mainfrom
Changdw:fix/gltf-importer-normalized
Open

fix(assets): decode normalized glTF skin weights#654
Changdw wants to merge 3 commits into
cocos:mainfrom
Changdw:fix/gltf-importer-normalized

Conversation

@Changdw

@Changdw Changdw commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

修复 glTF importer 未正确处理 accessor.normalized 导致的 skin weights 导入问题。

问题场景:

  • UE5 glTF Exporter 会导出 WEIGHTS_0/WEIGHTS_1UNSIGNED_BYTE + normalized: true
  • 旧逻辑直接按原始整数读取权重,随后在 reduceJointInfluences() 中对 Uint8Array 做归一化,浮点结果被截断,导致权重损坏,蒙皮网格出现尖刺。
  • 这个问题在 cocos/engine-extensions 中同样存在,因为 cocos-cli 的这段 glTF importer 代码来源于 Creator 的 engine-extensions。

修复内容:

  • normalized: trueWEIGHTS_* accessor 在进入 joint influence reduction 前解码为 Float32Array
  • 保留旧资产兼容性:normalized: false 或未声明时不覆盖 PPGeometry 原有的 normalized 推断逻辑。
  • 复用原有整数归一化 helper,避免动画 sampler 和 mesh weights 使用两套转换逻辑。

@Changdw

Changdw commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Fixes glTF skin weight corruption caused by ignoring accessor.normalized.

Problem:

  • UE5's glTF Exporter can write WEIGHTS_0/WEIGHTS_1 as UNSIGNED_BYTE with normalized: true.
  • The previous importer read those weights as raw integers. When reduceJointInfluences() later normalized them inside a Uint8Array, fractional values were truncated and the skin weights were destroyed, causing spiked skinned meshes.
  • The same issue also exists in cocos/engine-extensions, since this glTF importer code in cocos-cli comes from Creator's engine-extensions.

Changes:

  • Decode normalized: true WEIGHTS_* accessors to Float32Array before joint influence reduction.
  • Preserve legacy asset compatibility: when normalized is false or omitted, the importer does not override PPGeometry's existing normalized inference.
  • Reuse the existing integer-to-float normalization helper instead of keeping a separate conversion path.

@Changdw

Changdw commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

#630

@Changdw Changdw closed this Jun 16, 2026
@Changdw Changdw reopened this Jun 16, 2026
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