VRMBlendShapeProxy.cs
6.05 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
using System;
using System.Collections.Generic;
using UnityEngine;
namespace VRM
{
[DisallowMultipleComponent]
public class VRMBlendShapeProxy : MonoBehaviour, IVRMComponent
{
[SerializeField]
public BlendShapeAvatar BlendShapeAvatar;
public void OnImported(VRMImporterContext context)
{
throw new NotImplementedException();
}
BlendShapeMerger m_merger;
private void OnDestroy()
{
if (m_merger != null)
{
m_merger.RestoreMaterialInitialValues(BlendShapeAvatar.Clips);
}
}
private void Start()
{
if (BlendShapeAvatar != null)
{
if (m_merger == null)
{
m_merger = new BlendShapeMerger(BlendShapeAvatar.Clips, transform);
}
}
}
/// <summary>
/// Immediately SetValue
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
public void ImmediatelySetValue(BlendShapeKey key, float value)
{
if (m_merger != null)
{
m_merger.ImmediatelySetValue(key, value);
}
}
/// <summary>
/// AccumulateValue. After, Should call Apply
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
public void AccumulateValue(BlendShapeKey key, float value)
{
if (m_merger != null)
{
m_merger.AccumulateValue(key, value);
}
}
/// <summary>
/// Get a blendShape value
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public float GetValue(BlendShapeKey key)
{
if (m_merger == null)
{
return 0;
}
return m_merger.GetValue(key);
}
public IEnumerable<KeyValuePair<BlendShapeKey, float>> GetValues()
{
if (m_merger != null && BlendShapeAvatar != null)
{
foreach (var clip in BlendShapeAvatar.Clips)
{
var key = BlendShapeKey.CreateFrom(clip);
yield return new KeyValuePair<BlendShapeKey, float>(key, m_merger.GetValue(key));
}
}
}
/// <summary>
/// Set blendShape values immediate.
/// </summary>
/// <param name="values"></param>
public void SetValues(IEnumerable<KeyValuePair<BlendShapeKey, float>> values)
{
if (m_merger != null)
{
m_merger.SetValues(values);
}
}
/// <summary>
/// Apply blendShape values that use SetValue apply=false
/// </summary>
public void Apply()
{
if (m_merger != null)
{
m_merger.Apply();
}
}
}
public static class VRMBlendShapeProxyExtensions
{
public static float GetValue(this VRMBlendShapeProxy proxy, BlendShapePreset key)
{
return proxy.GetValue(new BlendShapeKey(key));
}
public static float GetValue(this VRMBlendShapeProxy proxy, String key)
{
return proxy.GetValue(new BlendShapeKey(key));
}
[Obsolete("Use ImmediatelySetValue")]
public static void SetValue(this VRMBlendShapeProxy proxy, BlendShapePreset key, float value)
{
proxy.ImmediatelySetValue(new BlendShapeKey(key), value);
}
public static void ImmediatelySetValue(this VRMBlendShapeProxy proxy, BlendShapePreset key, float value)
{
proxy.ImmediatelySetValue(new BlendShapeKey(key), value);
}
public static void AccumulateValue(this VRMBlendShapeProxy proxy, BlendShapePreset key, float value)
{
proxy.AccumulateValue(new BlendShapeKey(key), value);
}
[Obsolete("Use ImmediatelySetValue")]
public static void SetValue(this VRMBlendShapeProxy proxy, String key, float value)
{
proxy.ImmediatelySetValue(new BlendShapeKey(key), value);
}
public static void ImmediatelySetValue(this VRMBlendShapeProxy proxy, String key, float value)
{
proxy.ImmediatelySetValue(new BlendShapeKey(key), value);
}
public static void AccumulateValue(this VRMBlendShapeProxy proxy, String key, float value)
{
proxy.AccumulateValue(new BlendShapeKey(key), value);
}
[Obsolete("Use ImmediatelySetValue")]
public static void SetValue(this VRMBlendShapeProxy proxy, BlendShapeKey key, float value)
{
proxy.ImmediatelySetValue(key, value);
}
[Obsolete("Use ImmediatelySetValue or AccumulateValue")]
public static void SetValue(this VRMBlendShapeProxy proxy, BlendShapePreset key, float value, bool apply)
{
if (apply)
{
proxy.ImmediatelySetValue(new BlendShapeKey(key), value);
}
else
{
proxy.AccumulateValue(new BlendShapeKey(key), value);
}
}
[Obsolete("Use ImmediatelySetValue or AccumulateValue")]
public static void SetValue(this VRMBlendShapeProxy proxy, String key, float value, bool apply)
{
if (apply)
{
proxy.ImmediatelySetValue(new BlendShapeKey(key), value);
}
else
{
proxy.AccumulateValue(new BlendShapeKey(key), value);
}
}
[Obsolete("Use ImmediatelySetValue or AccumulateValue")]
public static void SetValue(this VRMBlendShapeProxy proxy, BlendShapeKey key, float value, bool apply)
{
if (apply)
{
proxy.ImmediatelySetValue(key, value);
}
else
{
proxy.AccumulateValue(key, value);
}
}
}
}