Skip to content

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

@BTT-AG

Description

@BTT-AG

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

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
  • Runtime Export

Additional Info 📜

No response

Validations 🩹

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions