Skip to content

Commit

Permalink
Merge pull request vrm-c#2137 from ousttrue/fix/mv_ILookAtEyeDirectio…
Browse files Browse the repository at this point in the history
…nProvider

ILookAtEyeDirectionProvider を LookAt フォルダーに移動
  • Loading branch information
ousttrue authored Aug 18, 2023
2 parents ad2ffae + 6883803 commit ce69a84
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Vrm10Runtime(Vrm10Instance target, bool useControlRig)
}
Constraints = target.GetComponentsInChildren<IVrm10Constraint>();
LookAt = new Vrm10RuntimeLookAt(target.Vrm.LookAt, target.Humanoid, ControlRig);
Expression = new Vrm10RuntimeExpression(target, LookAt, LookAt.EyeDirectionApplicable);
Expression = new Vrm10RuntimeExpression(target, LookAt.EyeDirectionApplicable);

var instance = target.GetComponent<RuntimeGltfInstance>();
if (instance != null)
Expand Down Expand Up @@ -232,7 +232,7 @@ public void Process()
LookAt.Process(m_target.LookAtTargetType, m_target.LookAtTarget);

// 5. Apply Expression
Expression.Process();
Expression.Process(LookAt.EyeDirection);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ public sealed class Vrm10RuntimeExpression
private Dictionary<ExpressionKey, float> _actualWeights = new Dictionary<ExpressionKey, float>();
private ExpressionMerger _merger;
private IExpressionValidator _validator;
private LookAtEyeDirection _inputEyeDirection;
private LookAtEyeDirection _actualEyeDirection;
private ILookAtEyeDirectionProvider _eyeDirectionProvider;
private ILookAtEyeDirectionApplicable _eyeDirectionApplicable;

public IReadOnlyList<ExpressionKey> ExpressionKeys => _keys;
Expand All @@ -26,7 +24,7 @@ public sealed class Vrm10RuntimeExpression

int m_debugCount;

internal Vrm10RuntimeExpression(Vrm10Instance target, ILookAtEyeDirectionProvider eyeDirectionProvider, ILookAtEyeDirectionApplicable eyeDirectionApplicable)
internal Vrm10RuntimeExpression(Vrm10Instance target, ILookAtEyeDirectionApplicable eyeDirectionApplicable)
{
Restore();

Expand All @@ -51,7 +49,6 @@ internal Vrm10RuntimeExpression(Vrm10Instance target, ILookAtEyeDirectionProvide
ExpressionKey.Comparer
);
_validator = ExpressionValidatorFactory.Create(target.Vrm.Expression);
_eyeDirectionProvider = eyeDirectionProvider;
_eyeDirectionApplicable = eyeDirectionApplicable;
}

Expand All @@ -64,9 +61,9 @@ internal void Restore()
_eyeDirectionApplicable = null;
}

internal void Process()
internal void Process(LookAtEyeDirection inputEyeDirection)
{
Apply();
Apply(inputEyeDirection);
}

public IDictionary<ExpressionKey, float> GetWeights()
Expand All @@ -84,11 +81,6 @@ public float GetWeight(ExpressionKey expressionKey)
return 0f;
}

public LookAtEyeDirection GetEyeDirection()
{
return _inputEyeDirection;
}

public void SetWeights(IEnumerable<KeyValuePair<ExpressionKey, float>> weights)
{
foreach (var (expressionKey, weight) in weights)
Expand Down Expand Up @@ -123,20 +115,17 @@ public void SetWeight(ExpressionKey expressionKey, float weight)
/// 入力 Weight を基に、Validation を行い実際にモデルに適用される Weights を計算し、Merger を介して適用する。
/// この際、LookAt の情報を pull してそれも適用する。
/// </summary>
private void Apply()
private void Apply(LookAtEyeDirection inputEyeDirection)
{
// 1. Get eye direction from provider.
_inputEyeDirection = _eyeDirectionProvider?.EyeDirection ?? default;

// 2. Validate user input, and Output as actual weights.
// 1. Validate user input, and Output as actual weights.
_validator.Validate(_inputWeights, _actualWeights,
_inputEyeDirection, out _actualEyeDirection,
inputEyeDirection, out _actualEyeDirection,
out var blink, out var lookAt, out var mouth);

// 3. Set eye direction expression weights or any other side-effects (ex. eye bone).
// 2. Set eye direction expression weights or any other side-effects (ex. eye bone).
_eyeDirectionApplicable?.Apply(_actualEyeDirection, _actualWeights);

// 4. Set actual weights to raw blendshapes.
// 3. Set actual weights to raw blendshapes.
_merger.SetValues(_actualWeights);

BlinkOverrideRate = blink;
Expand Down

0 comments on commit ce69a84

Please sign in to comment.