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

@ -223,11 +223,11 @@ public class OpenSeeVRMDriver : MonoBehaviour {
catsData.Add(OVRLipSync.Viseme.SS, new float[]{0f, 0.8f, 0f, 0f, 0f});
catsData.Add(OVRLipSync.Viseme.TH, new float[]{0.4f, 0f, 0f, 0f, 0.15f});
visemePresetMap = new BlendShapeKey[5] {
new BlendShapeKey(BlendShapePreset.A),
new BlendShapeKey(BlendShapePreset.I),
new BlendShapeKey(BlendShapePreset.U),
new BlendShapeKey(BlendShapePreset.E),
new BlendShapeKey(BlendShapePreset.O)
BlendShapeKey.CreateFromPreset(BlendShapePreset.A),
BlendShapeKey.CreateFromPreset(BlendShapePreset.I),
BlendShapeKey.CreateFromPreset(BlendShapePreset.U),
BlendShapeKey.CreateFromPreset(BlendShapePreset.E),
BlendShapeKey.CreateFromPreset(BlendShapePreset.O)
};
lastVisemeValues = new float[5] {0f, 0f, 0f, 0f, 0f};
}
@ -537,8 +537,8 @@ public class OpenSeeVRMDriver : MonoBehaviour {
}
if (foundClipUp != null && foundClipDown != null) {
browClips = new BlendShapeKey[2] {
new BlendShapeKey(foundClipUp),
new BlendShapeKey(foundClipDown)
BlendShapeKey.CreateUnknown(foundClipUp),
BlendShapeKey.CreateUnknown(foundClipDown)
};
return;
}
@ -733,9 +733,9 @@ public class OpenSeeVRMDriver : MonoBehaviour {
expression.reached = true;
openSeeExpression.weightMap.Add(expression.trigger, expression.errorWeight);
if (expression.customBlendShapeName != "")
expression.blendShapeKey = new BlendShapeKey(expression.customBlendShapeName);
expression.blendShapeKey = BlendShapeKey.CreateUnknown(expression.customBlendShapeName);
else
expression.blendShapeKey = new BlendShapeKey(expression.blendShapePreset);
expression.blendShapeKey = BlendShapeKey.CreateFromPreset(expression.blendShapePreset);
expressionMap.Add(expression.trigger, expression);
}
}
@ -981,21 +981,21 @@ public class OpenSeeVRMDriver : MonoBehaviour {
lookLeftRight = -lookLeftRight;
if (leftEye == null || rightEye == null) {
vrmBlendShapeProxy.AccumulateValue(new BlendShapeKey(BlendShapePreset.LookUp), 0f);
vrmBlendShapeProxy.AccumulateValue(new BlendShapeKey(BlendShapePreset.LookDown), 0f);
vrmBlendShapeProxy.AccumulateValue(new BlendShapeKey(BlendShapePreset.LookLeft), 0);
vrmBlendShapeProxy.AccumulateValue(new BlendShapeKey(BlendShapePreset.LookRight), 0f);
vrmBlendShapeProxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.LookUp), 0f);
vrmBlendShapeProxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.LookDown), 0f);
vrmBlendShapeProxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.LookLeft), 0);
vrmBlendShapeProxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.LookRight), 0f);
if (gazeTracking) {
if (lookUpDown > 0f) {
vrmBlendShapeProxy.AccumulateValue(new BlendShapeKey(BlendShapePreset.LookUp), gazeFactor.x * lookUpDown);
vrmBlendShapeProxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.LookUp), gazeFactor.x * lookUpDown);
} else {
vrmBlendShapeProxy.AccumulateValue(new BlendShapeKey(BlendShapePreset.LookDown), -gazeFactor.x * lookUpDown);
vrmBlendShapeProxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.LookDown), -gazeFactor.x * lookUpDown);
}
if (lookLeftRight > 0f) {
vrmBlendShapeProxy.AccumulateValue(new BlendShapeKey(BlendShapePreset.LookLeft), gazeFactor.y * lookLeftRight);
vrmBlendShapeProxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.LookLeft), gazeFactor.y * lookLeftRight);
} else {
vrmBlendShapeProxy.AccumulateValue(new BlendShapeKey(BlendShapePreset.LookRight), -gazeFactor.y * lookLeftRight);
vrmBlendShapeProxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.LookRight), -gazeFactor.y * lookLeftRight);
}
}
} else {
@ -1017,7 +1017,7 @@ public class OpenSeeVRMDriver : MonoBehaviour {
if (autoBlink) {
if (currentExpressionEnableBlinking) {
float blink = eyeBlinker.Blink();
vrmBlendShapeProxy.AccumulateValue(new BlendShapeKey(BlendShapePreset.Blink), blink);
vrmBlendShapeProxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Blink), blink);
}
} else if (openSeeExpression != null && openSeeExpression.openSee != null) {
if (!currentExpressionEnableBlinking)
@ -1087,10 +1087,10 @@ public class OpenSeeVRMDriver : MonoBehaviour {
if (linkBlinks) {
float v = Mathf.Max(left, right);
vrmBlendShapeProxy.AccumulateValue(new BlendShapeKey(BlendShapePreset.Blink), v);
vrmBlendShapeProxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Blink), v);
} else {
vrmBlendShapeProxy.AccumulateValue(new BlendShapeKey(BlendShapePreset.Blink_R), right);
vrmBlendShapeProxy.AccumulateValue(new BlendShapeKey(BlendShapePreset.Blink_L), left);
vrmBlendShapeProxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Blink_R), right);
vrmBlendShapeProxy.AccumulateValue(BlendShapeKey.CreateFromPreset(BlendShapePreset.Blink_L), left);
}
}
}

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);
}
}