Skip to content

Commit

Permalink
Improve skinned mesh eyelid morpher for both sample
Browse files Browse the repository at this point in the history
  • Loading branch information
mochi-neko committed Aug 9, 2023
1 parent 08dec55 commit 4fd496b
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,38 @@ public sealed class SkinnedMeshEyelidMorpher : IEyelidMorpher
{
private readonly SkinnedMeshRenderer skinnedMeshRenderer;
private readonly IReadOnlyDictionary<Eyelid, int> indexMap;
private readonly bool separateBoth;

/// <summary>
/// Creates a new instance of <see cref="SkinnedMeshEyelidMorpher"/>.
/// </summary>
/// <param name="skinnedMeshRenderer">Target renderer.</param>
/// <param name="indexMap">Map of eyelid and blend shape index.</param>
/// <param name="separateBoth">Whether separate both eyelids blend shape.</param>
public SkinnedMeshEyelidMorpher(
SkinnedMeshRenderer skinnedMeshRenderer,
IReadOnlyDictionary<Eyelid, int> indexMap)
IReadOnlyDictionary<Eyelid, int> indexMap,
bool separateBoth = false)
{
this.skinnedMeshRenderer = skinnedMeshRenderer;
this.indexMap = indexMap;
this.separateBoth = separateBoth;
}

public void MorphInto(EyelidSample sample)
{
if (indexMap.TryGetValue(sample.eyelid, out var index))
if (separateBoth && sample.eyelid == Eyelid.Both)
{
if (indexMap.TryGetValue(Eyelid.Left, out var rightIndex))
{
skinnedMeshRenderer.SetBlendShapeWeight(rightIndex, sample.weight * 100f);
}
if (indexMap.TryGetValue(Eyelid.Right, out var leftIndex))
{
skinnedMeshRenderer.SetBlendShapeWeight(leftIndex, sample.weight * 100f);
}
}
else if (indexMap.TryGetValue(sample.eyelid, out var index))
{
skinnedMeshRenderer.SetBlendShapeWeight(index, sample.weight * 100f);
}
Expand Down

0 comments on commit 4fd496b

Please sign in to comment.