forked from net-press/CC3-Rokoko-Unity-integration
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFaceCC3.cs
More file actions
157 lines (143 loc) · 10.2 KB
/
FaceCC3.cs
File metadata and controls
157 lines (143 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Rokoko.Inputs;
using Rokoko.Helper;
using Rokoko.Core;
public class FaceCC3 : Face {
[Header("Expression tuning")]
public float browEmphasis = 1;
public float eyesEmphasis = 1;
public float cheekEmphasis = 1;
public float noseEmphasis = 1;
public float mouthEmphasis = 1;
SkinnedMeshRenderer smr;
[Tooltip("If your characters have a beard or bushy eyebrows that can be animamated through blendshapes add a Face Script and link them here")]
[Header("Other settings")]
public Face[] secondaryFaces;
public enum CC3BlendShapeNames {
A01_Brow_Inner_Up,
A02_Brow_Down_Left,
A03_Brow_Down_Right,
A04_Brow_Outer_Up_Left,
A05_Brow_Outer_Up_Right,
A06_Eye_Look_Up_Left,
A07_Eye_Look_Up_Right,
A08_Eye_Look_Down_Left,
A09_Eye_Look_Down_Right,
A10_Eye_Look_Out_Left,
A11_Eye_Look_In_Left,
A12_Eye_Look_In_Right,
A13_Eye_Look_Out_Right,
A14_Eye_Blink_Left,
A15_Eye_Blink_Right,
A16_Eye_Squint_Left,
A17_Eye_Squint_Right,
A18_Eye_Wide_Left,
A19_Eye_Wide_Right,
A20_Cheek_Puff,
A21_Cheek_Squint_Left,
A22_Cheek_Squint_Right,
A23_Nose_Sneer_Left,
A24_Nose_Sneer_Right,
A25_Jaw_Open,
A26_Jaw_Forward,
A27_Jaw_Left,
A28_Jaw_Right,
A29_Mouth_Funnel,
A30_Mouth_Pucker,
A31_Mouth_Left,
A32_Mouth_Right,
A33_Mouth_Roll_Upper,
A34_Mouth_Roll_Lower,
A35_Mouth_Shrug_Upper,
A36_Mouth_Shrug_Lower,
A37_Mouth_Close,
A38_Mouth_Smile_Left,
A39_Mouth_Smile_Right,
A40_Mouth_Frown_Left,
A41_Mouth_Frown_Right,
A42_Mouth_Dimple_Left,
A43_Mouth_Dimple_Right,
A44_Mouth_Upper_Up_Left,
A45_Mouth_Upper_Up_Right,
A46_Mouth_Lower_Down_Left,
A47_Mouth_Lower_Down_Right,
A48_Mouth_Press_Left,
A49_Mouth_Press_Right,
A50_Mouth_Stretch_Left,
A51_Mouth_Stretch_Right,
A52_Tongue_Out,
Merged_Open_Mouth,
};
Dictionary<CC3BlendShapeNames, int> CC3BlendShapeNamesDict;
protected override void Start() {
smr = GetComponent<SkinnedMeshRenderer>();
if (smr == null) Debug.Log("Skinned Mesh Renderer component not found");
// Find the blendshape index for each given blendshape name
CC3BlendShapeNamesDict = new Dictionary<CC3BlendShapeNames, int>();
foreach(CC3BlendShapeNames bsn in System.Enum.GetValues(typeof(CC3BlendShapeNames))) {
CC3BlendShapeNamesDict.Add(bsn, smr.sharedMesh.GetBlendShapeIndex(bsn.ToString()));
}
}
public override void UpdateFace(FaceFrame faceFrame) {
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A01_Brow_Inner_Up], faceFrame.browInnerUp * browEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A02_Brow_Down_Left], faceFrame.browDownLeft * browEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A03_Brow_Down_Right], faceFrame.browDownRight * browEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A04_Brow_Outer_Up_Left], faceFrame.browOuterUpLeft * browEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A05_Brow_Outer_Up_Right], faceFrame.browOuterUpRight * browEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A06_Eye_Look_Up_Left], faceFrame.eyeLookUpLeft);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A07_Eye_Look_Up_Right], faceFrame.eyeLookUpRight);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A08_Eye_Look_Down_Left], faceFrame.eyeLookDownLeft);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A09_Eye_Look_Down_Right], faceFrame.eyeLookDownRight);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A10_Eye_Look_Out_Left], faceFrame.eyeLookOutLeft);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A11_Eye_Look_In_Left], faceFrame.eyeLookInLeft);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A12_Eye_Look_In_Right], faceFrame.eyeLookInRight);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A13_Eye_Look_Out_Right], faceFrame.eyeLookOutRight);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A14_Eye_Blink_Left], faceFrame.eyeBlinkLeft * eyesEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A15_Eye_Blink_Right], faceFrame.eyeBlinkRight * eyesEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A16_Eye_Squint_Left], faceFrame.eyeSquintLeft * eyesEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A17_Eye_Squint_Right], faceFrame.eyeSquintRight * eyesEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A18_Eye_Wide_Left], faceFrame.eyeWideLeft * eyesEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A19_Eye_Wide_Right], faceFrame.eyeWideRight * eyesEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A20_Cheek_Puff], faceFrame.cheekPuff * cheekEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A21_Cheek_Squint_Left], faceFrame.cheekSquintLeft * cheekEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A22_Cheek_Squint_Right], faceFrame.cheekSquintRight * cheekEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A23_Nose_Sneer_Left], faceFrame.noseSneerLeft * noseEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A24_Nose_Sneer_Right], faceFrame.noseSneerRight * noseEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A25_Jaw_Open], faceFrame.jawOpen);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A26_Jaw_Forward], faceFrame.jawForward);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A27_Jaw_Left], faceFrame.jawLeft * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A28_Jaw_Right], faceFrame.jawRight * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A29_Mouth_Funnel], faceFrame.mouthFunnel * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A30_Mouth_Pucker], faceFrame.mouthPucker * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A31_Mouth_Left], faceFrame.mouthLeft * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A32_Mouth_Right], faceFrame.mouthRight * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A33_Mouth_Roll_Upper], faceFrame.mouthRollUpper * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A34_Mouth_Roll_Lower], faceFrame.mouthRollLower * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A35_Mouth_Shrug_Upper], faceFrame.mouthShrugUpper * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A36_Mouth_Shrug_Lower], faceFrame.mouthShrugLower * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A37_Mouth_Close], faceFrame.mouthClose * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A38_Mouth_Smile_Left], faceFrame.mouthSmileLeft * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A39_Mouth_Smile_Right], faceFrame.mouthSmileRight * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A40_Mouth_Frown_Left], faceFrame.mouthFrownLeft * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A41_Mouth_Frown_Right], faceFrame.mouthFrownRight * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A42_Mouth_Dimple_Left], faceFrame.mouthDimpleLeft * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A43_Mouth_Dimple_Right], faceFrame.mouthDimpleRight * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A44_Mouth_Upper_Up_Left], faceFrame.mouthUpperUpLeft * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A45_Mouth_Upper_Up_Right], faceFrame.mouthUpperUpRight * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A46_Mouth_Lower_Down_Left], faceFrame.mouthLowerDownLeft * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A47_Mouth_Lower_Down_Right], faceFrame.mouthLowerDownRight * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A48_Mouth_Press_Left], faceFrame.mouthPressLeft * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A49_Mouth_Press_Right], faceFrame.mouthPressRight * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A50_Mouth_Stretch_Left], faceFrame.mouthStretchLeft * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A51_Mouth_Stretch_Right], faceFrame.mouthStretchRight * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.A52_Tongue_Out], faceFrame.tongueOut * mouthEmphasis);
smr.SetBlendShapeWeight(CC3BlendShapeNamesDict[CC3BlendShapeNames.Merged_Open_Mouth], faceFrame.jawOpen * mouthEmphasis);
if (secondaryFaces.Length > 0) {
foreach (Face face in secondaryFaces) {
face.UpdateFace(faceFrame);
}
}
}
}