KhronosGroup / KhronosGroup/UnityGLTF

Export object with blendshape and multiple frame in it cause incorrect result

Open
#899 1 comment 0 reactions 1 assignee Claimed by @robertdorn83 View on GitHub
bug
Dominant language
C#
Stars
2.2k
Forks
536
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug 💬

Hello,

Thank you for this great tool!

When exporting my scene, i saw that some of my objects has incorrect render.
After investigating, i manage to find that object with skinmeshrenderer, with blendshape and multiple frame are impacted.
I have done some research, and in ExporterMeshes.cs i saw the comment that say gltf support only one frame in ExportBlendShapes function :
```
// As described above, a blend shape can have multiple frames. Given that glTF only supports a single frame
// per blend shape, we'll always use the final frame (the one that would be for when 100% weight is applied).
int frameIndex = meshObj.GetBlendShapeFrameCount(blendShapeIndex) - 1;
```
But when getting the weight index, 0 is used in GetBlendShapeWeights function
```
var frameWeight = meshObj.GetBlendShapeFrameWeight(blendShapeIndex, 0);
weights.Add(smr.GetBlendShapeWeight(blendShapeIndex) / frameWeight);
```

I think, and in my case it works, that the code should be as the following, and getting the last frame
```
var frameCount = meshObj.GetBlendShapeFrameCount(blendShapeIndex);
var frameWeight = meshObj.GetBlendShapeFrameWeight(blendShapeIndex, frameCount - 1);
weights.Add(smr.GetBlendShapeWeight(blendShapeIndex) / frameWeight);
```
or simply
`weights.Add(smr.GetBlendShapeWeight(blendShapeIndex) / 100);`
but i don't really know if the last weight can be different than 100

To giving some more details, in my test with the current code, frameWeight = 16.666
smr.GetBlendShapeWeight(blendShapeIndex) = 55.5555
And the result smr.GetBlendShapeWeight(blendShapeIndex) / frameWeight = 3.3333
I don't think weight should be higher than 1. After importing the glb in another tool, it looks like it is because result is 333% so it have done more than expected in weight

### Steps to reproduce 🔢

I attach an exemple prefab in unitypackage in zip file to reproduce and see difference between unity en glb export when changing the blendshape value
- Import the unity package
- Modify the blendshape value more than 50%
- Export as glb
- See difference unity viewer and glb viewer

### Files to reproduce the issue ♻

[coussin.zip](https://github.com/user-attachments/files/25446963/coussin.zip)

### Editor Version 🎲

2022.3

### Render Pipeline and version

URP

### UnityGLTF Version

2.18.7

### Operating System 👩‍💻

iOS, Windows, Android

### When does this problem happen?

- [ ] Editor Import
- [ ] Runtime Import
- [ ] Editor Export
- [x] Runtime Export

### Additional Info 📜

_No response_

### Validations 🩹

- [x] I have [searched existing issues](https://github.com/KhronosGroup/UnityGLTF/issues): no issue already exist that reports the same problem.
- [x] I follow the [Code of Conduct](https://www.khronos.org/about/code-of-conduct)
- [x] I provided a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example), including files when necessary.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.