Updated VRM examples to UniVRM 0.56 API

This commit is contained in:
Emiliana 2020-07-06 14:51:16 +02:00
parent cac412b2af
commit 20c907ce21
2 changed files with 59 additions and 34 deletions

View file

@ -6,6 +6,7 @@ namespace OpenSee {
public class OpenSeeVRMExpression : MonoBehaviour
{
public OpenSee openSee;
public OpenSeeExpression openSeeExpression;
public VRMBlendShapeProxy vrmBlendShapeProxy;
public string expressionNeutral = "neutral";
@ -15,7 +16,6 @@ public class OpenSeeVRMExpression : MonoBehaviour
public string expressionJoy = "shocked";
private BlendShapeKey lastKey;
private string lastExpression = "";
void Start()
{
@ -26,27 +26,52 @@ public class OpenSeeVRMExpression : MonoBehaviour
if (openSeeExpression == null || vrmBlendShapeProxy == null) {
return;
}
vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Neutral), 0f);
vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Fun), 0f);
vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Sorrow), 0f);
vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Angry), 0f);
vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Joy), 0f);
vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Blink_R), 0f);
vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Blink_L), 0f);
float rightEyeOpen = 1f;
float leftEyeOpen = 1f;
if (openSee != null) {
var openSeeData = openSee.trackingData;
if (openSeeData == null || openSeeData.Length < 1)
return;
int idx = -1;
int i = 0;
foreach (var item in openSeeData) {
if (item.id == openSeeExpression.faceId)
idx = i;
i++;
}
if (idx > -1) {
rightEyeOpen = openSeeData[idx].rightEyeOpen;
leftEyeOpen = openSeeData[idx].leftEyeOpen;
}
}
vrmBlendShapeProxy.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Neutral), 0f);
vrmBlendShapeProxy.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Fun), 0f);
vrmBlendShapeProxy.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Sorrow), 0f);
vrmBlendShapeProxy.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Angry), 0f);
vrmBlendShapeProxy.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Joy), 0f);
vrmBlendShapeProxy.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Blink_R), 0f);
vrmBlendShapeProxy.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Blink_L), 0f);
if (openSeeExpression.expression == expressionFun) {
vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Fun), 1f);
vrmBlendShapeProxy.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Fun), 1f);
return;
} else if (openSeeExpression.expression == expressionSorrow) {
vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Sorrow), 1f);
vrmBlendShapeProxy.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Sorrow), 1f);
return;
} else if (openSeeExpression.expression == expressionAngry) {
vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Angry), 1f);
vrmBlendShapeProxy.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Angry), 1f);
return;
} else if (openSeeExpression.expression == expressionJoy) {
vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Joy), 1f);
vrmBlendShapeProxy.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Joy), 1f);
return;
} else {
/*if (rightEyeOpen < 0.05) {
vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Blink_R), 1f);
}
if (leftEyeOpen < 0.05) {
vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Blink_L), 1f);
}*/
}
vrmBlendShapeProxy.ImmediatelySetValue(new BlendShapeKey(BlendShapePreset.Neutral), 1f);
vrmBlendShapeProxy.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Neutral), 1f);
}
}