From 4fd496b759458cd6f52ef62eb718cf91e028712f Mon Sep 17 00:00:00 2001 From: mochi-neko Date: Wed, 9 Aug 2023 17:46:04 +0900 Subject: [PATCH] Improve skinned mesh eyelid morpher for both sample --- .../Blink/SkinnedMeshEyelidMorpher.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Assets/Mochineko/FacialExpressions/Blink/SkinnedMeshEyelidMorpher.cs b/Assets/Mochineko/FacialExpressions/Blink/SkinnedMeshEyelidMorpher.cs index 3680712..7917f5a 100644 --- a/Assets/Mochineko/FacialExpressions/Blink/SkinnedMeshEyelidMorpher.cs +++ b/Assets/Mochineko/FacialExpressions/Blink/SkinnedMeshEyelidMorpher.cs @@ -11,23 +11,38 @@ public sealed class SkinnedMeshEyelidMorpher : IEyelidMorpher { private readonly SkinnedMeshRenderer skinnedMeshRenderer; private readonly IReadOnlyDictionary indexMap; + private readonly bool separateBoth; /// /// Creates a new instance of . /// /// Target renderer. /// Map of eyelid and blend shape index. + /// Whether separate both eyelids blend shape. public SkinnedMeshEyelidMorpher( SkinnedMeshRenderer skinnedMeshRenderer, - IReadOnlyDictionary indexMap) + IReadOnlyDictionary 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); }