Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.0] Expression の override と binary の組み合わせの挙動を実装 #2464

Merged
merged 10 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,45 @@ public void Validate(IReadOnlyDictionary<ExpressionKey, float> inputWeights, IDi
{
if (key.IsBlink)
{
actualWeights[key] = actualWeights[key] * blinkMultiplier;
if (_expressions[key].IsBinary)
{
if (blinkMultiplier < 1.0f)
{
actualWeights[key] = 0.0f;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isBinaryが指定されている表情が他の表情からオーバーライドの影響を受ける場合、受けている影響が0.0より大きければ、完全に抑制されなければいけません(MUST)。

}
else
{
actualWeights[key] = actualWeights[key] * blinkMultiplier;
}
}
else if (key.IsLookAt)
{
actualWeights[key] = actualWeights[key] * lookAtMultiplier;
if (_expressions[key].IsBinary)
{
if (lookAtMultiplier < 1.0f)
{
actualWeights[key] = 0.0f;
}
}
else
{
actualWeights[key] = actualWeights[key] * lookAtMultiplier;
}
}
else if (key.IsMouth)
{
actualWeights[key] = actualWeights[key] * mouthMultiplier;
if (_expressions[key].IsBinary)
{
if (mouthMultiplier < 1.0f)
{
actualWeights[key] = 0.0f;
}
}
else
{
actualWeights[key] = actualWeights[key] * mouthMultiplier;
}
}
}

Expand Down
54 changes: 54 additions & 0 deletions Assets/VRM10_Samples/VRM10Viewer/FaceCameraTarget.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!86 &8600000
CustomRenderTexture:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: FaceCameraTarget
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
m_IsAlphaChannelOptional: 0
serializedVersion: 5
m_Width: 300
m_Height: 300
m_AntiAliasing: 1
m_MipCount: -1
m_DepthStencilFormat: 94
m_ColorFormat: 8
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_UseDynamicScale: 0
m_BindMS: 0
m_EnableCompatibleFormat: 1
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 0
m_MipBias: 0
m_WrapU: 1
m_WrapV: 1
m_WrapW: 1
m_Dimension: 2
m_VolumeDepth: 1
m_ShadowSamplingMode: 2
m_Material: {fileID: 0}
m_InitSource: 0
m_InitMaterial: {fileID: 0}
m_InitColor: {r: 1, g: 1, b: 1, a: 1}
m_InitTexture: {fileID: 0}
m_UpdateMode: 0
m_InitializationMode: 2
m_UpdateZoneSpace: 0
m_CurrentUpdateZoneSpace: 0
m_UpdateZones: []
m_UpdatePeriod: 0
m_ShaderPass: 0
m_CubemapFaceMask: 4294967295
m_DoubleBuffered: 0
m_WrapUpdateZones: 0
8 changes: 8 additions & 0 deletions Assets/VRM10_Samples/VRM10Viewer/FaceCameraTarget.asset.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 19 additions & 14 deletions Assets/VRM10_Samples/VRM10Viewer/VRM10AIUEO.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,51 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


namespace UniVRM10.VRM10Viewer
{
public class VRM10AIUEO : MonoBehaviour
{
[SerializeField]
public Vrm10Instance Controller;
private void Reset()
{
Controller = GetComponent<Vrm10Instance>();
}

Coroutine m_coroutine;

[SerializeField]
float m_wait = 0.5f;

private void Awake()
public float Aa = 0.0f;
public float Ih = 0.0f;
public float Ou = 0.0f;
public float Ee = 0.0f;
public float Oh = 0.0f;

void SetWeight(ExpressionPreset preset, float value)
{
if (Controller == null)
switch (preset)
{
Controller = GetComponent<Vrm10Instance>();
case ExpressionPreset.aa: Aa = value; break;
case ExpressionPreset.ih: Ih = value; break;
case ExpressionPreset.ou: Ou = value; break;
case ExpressionPreset.ee: Ee = value; break;
case ExpressionPreset.oh: Oh = value; break;
default: break;
}
}

IEnumerator RoutineNest(ExpressionPreset preset, float velocity, float wait)
{
for (var value = 0.0f; value <= 1.0f; value += velocity)
{
Controller.Runtime.Expression.SetWeight(ExpressionKey.CreateFromPreset(preset), value);
SetWeight(preset, value);
yield return null;
}
Controller.Runtime.Expression.SetWeight(ExpressionKey.CreateFromPreset(preset), 1.0f);
SetWeight(preset, 1.0f);
yield return new WaitForSeconds(wait);
for (var value = 1.0f; value >= 0; value -= velocity)
{
Controller.Runtime.Expression.SetWeight(ExpressionKey.CreateFromPreset(preset), value);
SetWeight(preset, value);
yield return null;
}
Controller.Runtime.Expression.SetWeight(ExpressionKey.CreateFromPreset(preset), 0);
SetWeight(preset, 0);
yield return new WaitForSeconds(wait * 2);
}

Expand Down
32 changes: 18 additions & 14 deletions Assets/VRM10_Samples/VRM10Viewer/VRM10AutoExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,45 @@ namespace UniVRM10.VRM10Viewer
/// </summary>
public class VRM10AutoExpression : MonoBehaviour
{
[SerializeField]
public Vrm10Instance Controller;
private void Reset()
{
Controller = GetComponent<Vrm10Instance>();
}

Coroutine m_coroutine;

[SerializeField]
float m_wait = 0.5f;

private void Awake()
public float Happy = 0.0f;
public float Angry = 0.0f;
public float Sad = 0.0f;
public float Relaxed = 0.0f;
public float Surprised = 0.0f;

void SetWeight(ExpressionPreset preset, float value)
{
if (Controller == null)
switch (preset)
{
Controller = GetComponent<Vrm10Instance>();
case ExpressionPreset.happy: Happy = value; break;
case ExpressionPreset.angry: Angry = value; break;
case ExpressionPreset.sad: Sad = value; break;
case ExpressionPreset.relaxed: Relaxed = value; break;
case ExpressionPreset.surprised: Surprised = value; break;
default: break;
}
}

IEnumerator RoutineNest(ExpressionPreset preset, float velocity, float wait)
{
for (var value = 0.0f; value <= 1.0f; value += velocity)
{
Controller.Runtime.Expression.SetWeight(ExpressionKey.CreateFromPreset(preset), value);
SetWeight(preset, value);
yield return null;
}
Controller.Runtime.Expression.SetWeight(ExpressionKey.CreateFromPreset(preset), 1.0f);
SetWeight(preset, 1.0f);
yield return new WaitForSeconds(wait);
for (var value = 1.0f; value >= 0; value -= velocity)
{
Controller.Runtime.Expression.SetWeight(ExpressionKey.CreateFromPreset(preset), value);
SetWeight(preset, value);
yield return null;
}
Controller.Runtime.Expression.SetWeight(ExpressionKey.CreateFromPreset(preset), 0);
SetWeight(preset, 0);
yield return new WaitForSeconds(wait * 2);
}

Expand Down
13 changes: 6 additions & 7 deletions Assets/VRM10_Samples/VRM10Viewer/VRM10Blinker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace UniVRM10.VRM10Viewer
/// </summary>
public class VRM10Blinker : MonoBehaviour
{
Vrm10Instance m_controller;

[FormerlySerializedAs("m_interVal")]
[SerializeField]
public float Interval = 5.0f;
Expand Down Expand Up @@ -46,6 +44,8 @@ public bool Request
}
}

public float BlinkValue = 0;

IEnumerator BlinkRoutine()
{
while (true)
Expand All @@ -72,10 +72,10 @@ IEnumerator BlinkRoutine()
break;
}

m_controller.Runtime.Expression.SetWeight(ExpressionKey.CreateFromPreset(ExpressionPreset.blink), value);
BlinkValue = value;
yield return null;
}
m_controller.Runtime.Expression.SetWeight(ExpressionKey.CreateFromPreset(ExpressionPreset.blink), 1.0f);
BlinkValue = 1.0f;

// wait...
yield return new WaitForSeconds(ClosingTime);
Expand All @@ -91,16 +91,15 @@ IEnumerator BlinkRoutine()
break;
}

m_controller.Runtime.Expression.SetWeight(ExpressionKey.CreateFromPreset(ExpressionPreset.blink), value);
BlinkValue = value;
yield return null;
}
m_controller.Runtime.Expression.SetWeight(ExpressionKey.CreateFromPreset(ExpressionPreset.blink), 0);
BlinkValue = 0;
}
}

private void OnEnable()
{
m_controller = GetComponent<Vrm10Instance>();
m_coroutine = StartCoroutine(BlinkRoutine());
}

Expand Down
73 changes: 10 additions & 63 deletions Assets/VRM10_Samples/VRM10Viewer/VRM10Loaded.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,73 +7,20 @@ namespace UniVRM10.VRM10Viewer
class Loaded : IDisposable
{
RuntimeGltfInstance m_instance;
Vrm10Instance m_controller;
public Vrm10Instance Instance => m_controller;
public Vrm10RuntimeControlRig ControlRig => m_controller.Runtime.ControlRig;
public Vrm10Runtime Runtime => m_controller.Runtime;
Vrm10Instance m_vrm;
public Vrm10Instance Instance => m_vrm;
public Vrm10RuntimeControlRig ControlRig => m_vrm.Runtime.ControlRig;
public Vrm10Runtime Runtime => m_vrm.Runtime;

VRM10AIUEO m_lipSync;
bool m_enableLipSyncValue;
public bool EnableLipSyncValue
{
set
{
if (m_enableLipSyncValue == value) return;
m_enableLipSyncValue = value;
if (m_lipSync != null)
{
m_lipSync.enabled = m_enableLipSyncValue;
}
}
}

VRM10AutoExpression m_autoExpression;
bool m_enableAutoExpressionValue;
public bool EnableAutoExpressionValue
{
set
{
if (m_enableAutoExpressionValue == value) return;
m_enableAutoExpressionValue = value;
if (m_autoExpression != null)
{
m_autoExpression.enabled = m_enableAutoExpressionValue;
}
}
}

VRM10Blinker m_blink;
bool m_enableBlinkValue;
public bool EnableBlinkValue
{
set
{
if (m_blink == value) return;
m_enableBlinkValue = value;
if (m_blink != null)
{
m_blink.enabled = m_enableBlinkValue;
}
}
}

public Loaded(RuntimeGltfInstance instance, Transform lookAtTarget)
public Loaded(RuntimeGltfInstance instance)
{
m_instance = instance;

m_controller = instance.GetComponent<Vrm10Instance>();
if (m_controller != null)
m_vrm = instance.GetComponent<Vrm10Instance>();
if (m_vrm != null)
{
// VRM
m_controller.UpdateType = Vrm10Instance.UpdateTypes.LateUpdate; // after HumanPoseTransfer's setPose
{
m_lipSync = instance.gameObject.AddComponent<VRM10AIUEO>();
m_blink = instance.gameObject.AddComponent<VRM10Blinker>();
m_autoExpression = instance.gameObject.AddComponent<VRM10AutoExpression>();

m_controller.LookAtTargetType = VRM10ObjectLookAt.LookAtTargetTypes.SpecifiedTransform;
m_controller.LookAtTarget = lookAtTarget;
}
m_vrm.UpdateType = Vrm10Instance.UpdateTypes.LateUpdate; // after HumanPoseTransfer's setPose
m_vrm.LookAtTargetType = VRM10ObjectLookAt.LookAtTargetTypes.YawPitchValue;
}

var animation = instance.GetComponent<Animation>();
Expand All @@ -90,4 +37,4 @@ public void Dispose()
GameObject.Destroy(m_instance.gameObject);
}
}
}
}
7 changes: 1 addition & 6 deletions Assets/VRM10_Samples/VRM10Viewer/VRM10RokuroCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct PosRot

class _Rokuro
{
public float Yaw;
public float Yaw = 180.0f;
public float Pitch;
public float ShiftX;
public float ShiftY;
Expand Down Expand Up @@ -71,11 +71,6 @@ public PosRot Calc()
private List<Coroutine> _activeCoroutines = new List<Coroutine>();
private void OnEnable()
{
// left mouse drag
_activeCoroutines.Add(StartCoroutine(MouseDragOperationCoroutine(0, diff =>
{
_currentCamera.Rotate(diff.x * RotateSpeed, diff.y * RotateSpeed);
})));
// right mouse drag
_activeCoroutines.Add(StartCoroutine(MouseDragOperationCoroutine(1, diff =>
{
Expand Down
Loading