Skip to content

Commit

Permalink
fix: blend shape keys weren't imported
Browse files Browse the repository at this point in the history
  • Loading branch information
hybridherbst committed Sep 27, 2022
1 parent c5f4744 commit 1ddccb3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ public static void BuildAnimationSamplers(ref Dictionary<string, List<AttributeA
case "rotation":
attributeAccessor.AccessorId.Value.AsVector4Array(ref resultArray, bufferViewCache, offset);
break;
case "weights":
attributeAccessor.AccessorId.Value.AsFloatArray(ref resultArray, bufferViewCache, offset);
break;
}

attributeAccessor.AccessorContent = resultArray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,16 +301,24 @@ protected async Task<AnimationClip> ConstructClip(Transform root, int animationI
case GLTFAnimationChannelPath.weights:
// TODO: add support for blend shapes/morph targets

// var primitives = channel.Target.Node.Value.Mesh.Value.Primitives;
// var targetCount = primitives[0].Targets.Count;
// for (int primitiveIndex = 0; primitiveIndex < primitives.Count; primitiveIndex++)
// {
// for (int targetIndex = 0; targetIndex < targetCount; targetIndex++)
// {
//
// //clip.SetCurve(primitiveObjPath, typeof(SkinnedMeshRenderer), "blendShape." + targetIndex, curves[targetIndex]);
// }
// }
var primitives = channel.Target.Node.Value.Mesh.Value.Primitives;
var targetCount = primitives[0].Targets.Count;
for (int primitiveIndex = 0; primitiveIndex < primitives.Count; primitiveIndex++)
{
// see SceneImporter:156
// blend shapes are always called "Morphtarget" and always have frame weight 100 on import

propertyNames = new string[targetCount];
for (var i = 0; i < targetCount; i++)
propertyNames[i] = "blendShape.Morphtarget" + i;
SetAnimationCurve(clip, relativePath, propertyNames, input, output,
samplerCache.Interpolation, typeof(SkinnedMeshRenderer),
(data, frame) =>
{
var scale = data.AsFloats[frame];
return new float[] { scale * 100.0f };
});
}
break;

default:
Expand Down

0 comments on commit 1ddccb3

Please sign in to comment.