-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathVRCFTGenerator.cs
1051 lines (846 loc) · 52.9 KB
/
VRCFTGenerator.cs
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.Linq;
using VRCFTGenerator.AnimatorAsCode.V0;
using UnityEngine;
using VRC.SDK3.Avatars.Components;
using VRC.SDK3.Avatars.ScriptableObjects;
using UnityEditor;
using UnityEditor.Animations;
namespace Raz.VRCFTGenerator
{
[Serializable]
public class ParamSpecifier
{
public VRCFTValues.ParamMode mode;
public VRCFTValues.ParameterName VRCFTParameter;
}
public class VRCFTGenerator : MonoBehaviour
{
public VRCAvatarDescriptor avatar;
public AnimatorController assetContainer;
public string assetKey;
[Header("This will change how the controller is generated. Recommended to keep on, regardless of rest of controller.")]
public bool writeDefaults = true;
[Header("[Experimental] Instead of using an explicit cast state, implicitly cast expression Bool -> Animator Float")]
public bool useImplicitParameterCasting = false;
[Header("[Experimental] Generate in a single layer")]
public bool singleLayer = false;
public bool removeAnimatorParams = true;
public bool manageExpressionParameters = true;
public SkinnedMeshRenderer[] blendshapeTargetMeshRenderers = new SkinnedMeshRenderer[1];
public float remoteSmoothingTimeConstant = 0.7f;
[Header("Use VRCFT name of params in synced params - ex. Face/Combined/General/TongueX => TongueX")]
[Space(25)]
public ParamSpecifier[] paramsToAnimate;
}
[CustomEditor(typeof(VRCFTGenerator), true)]
public class VRCFTGeneratorEditor : Editor
{
private const string SystemName = "FT";
private VRCFTGenerator generator;
private AacFlBase aac;
private void InitializeAAC()
{
generator = (VRCFTGenerator) target;
var wd = generator.writeDefaults ? AACTemplate.Options().WriteDefaultsOn() : AACTemplate.Options().WriteDefaultsOff();
aac = AACTemplate.AnimatorAsCode(SystemName, generator.avatar, generator.assetContainer, generator.assetKey, wd);
}
// // // // // // // // // // // // // // // // // // // // // // // // // // //
public static void DrawUILine(Color color, int thickness = 2, int padding = 8)
{
Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding+thickness));
r.height = thickness;
r.y+=padding/2;
r.x-=2;
EditorGUI.DrawRect(r, color);
}
public static void DrawUILine(int thickness = 2, int padding = 8) => DrawUILine(darkgray, thickness, padding);
static Color darkgray = new Color(0.184f, 0.184f, 0.184f, 1.0f);
private bool paramListFoldout = false;
private bool paramCoverageFoldout = false;
private bool AnalyzeSetupGui()
{
bool hasDuplicates = false;
paramListFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(paramListFoldout, "Shapes in use");
HashSet<string> shapesInUse = new HashSet<string>();
int paramCost = 1; // One base for global FT toggle
foreach(var parameterSpec in generator.paramsToAnimate)
{
paramCost += (int)parameterSpec.mode;
string paramName = parameterSpec.VRCFTParameter.ToString();
List<string> shapeParams = new List<string>();
if(VRCFTValues.CombinedMapping.ContainsKey(paramName))
{
if(parameterSpec.mode != VRCFTValues.ParamMode.floatParam) paramCost++;
foreach(string constituentParam in VRCFTValues.CombinedMapping[paramName])
{
if(VRCFTValues.AveragedMapping.ContainsKey(constituentParam))
{
shapeParams.AddRange(VRCFTValues.AveragedMapping[constituentParam]);
}
else
{
shapeParams.Add(constituentParam);
}
}
}
else if(VRCFTValues.AveragedMapping.ContainsKey(paramName))
{
if(parameterSpec.mode != VRCFTValues.ParamMode.floatParam) paramCost++;
shapeParams.AddRange(VRCFTValues.AveragedMapping[paramName]);
}
else
{
shapeParams.Add(paramName);
}
foreach(var shape in shapeParams)
{
using(new EditorGUILayout.HorizontalScope())
{
bool isDuplicate = !shapesInUse.Add(shape);
if(isDuplicate)
hasDuplicates = true;
if(paramListFoldout)
{
Texture icon = isDuplicate ? EditorGUIUtility.IconContent("Error").image : (Texture)null;
var label = new GUIContent($" {shape}", icon);
EditorGUILayout.LabelField(label);
if(shapeParams.Count > 1)
EditorGUILayout.LabelField($"({paramName})", EditorStyles.centeredGreyMiniLabel);
}
}
}
}
int usedShapes = shapesInUse.Count;
int availableShapes = VRCFTValues.BlendshapeMapping.Keys.Count;
float coveragePercent = ((float)usedShapes)/((float)availableShapes) * 100f;
if(paramListFoldout)
{
paramCoverageFoldout = EditorGUILayout.Foldout(paramCoverageFoldout, "Unused Blendshapes");
if(paramCoverageFoldout)
{
foreach(string shape in VRCFTValues.BlendshapeMapping.Keys)
{
if(!shapesInUse.Contains(shape))
{
EditorGUILayout.LabelField(shape);
}
}
}
}
EditorGUILayout.EndFoldoutHeaderGroup();
DrawUILine();
EditorGUILayout.LabelField($"Shapes used: {usedShapes}/{availableShapes} ({coveragePercent.ToString("0")}%)");
EditorGUILayout.LabelField($"Parameter Cost: {paramCost} bits");
return hasDuplicates;
}
public override void OnInspectorGUI()
{
generator = (VRCFTGenerator) target;
serializedObject.Update();
// Unity GUI Magic?
var prop = serializedObject.FindProperty("assetKey");
if (prop.stringValue.Trim() == "")
{
prop.stringValue = GUID.Generate().ToString();
serializedObject.ApplyModifiedProperties();
}
this.DrawDefaultInspector();
DrawUILine();
bool hasDuplicates = AnalyzeSetupGui();
bool noAvatar = generator.avatar == null;
bool noContainer = generator.assetContainer == null;
bool noFX = false;
if(!noAvatar)
noFX = generator.avatar.baseAnimationLayers.First(it => it.type == VRCAvatarDescriptor.AnimLayerType.FX).animatorController == null;
DrawUILine();
if(noAvatar)
EditorGUILayout.HelpBox("No avatar descriptor specified. Please provide an avatar descriptor.", MessageType.Error);
if(noContainer)
EditorGUILayout.HelpBox("No asset container. Please create a new, blank animator controller to contain system assets.", MessageType.Error);
if(hasDuplicates)
EditorGUILayout.HelpBox("Duplicate Parameters in setup. Please ensure there are no duplicates.", MessageType.Error);
if(noFX)
EditorGUILayout.HelpBox("No FX Layer. Please add an FX layer", MessageType.Error);
using(new EditorGUI.DisabledScope(noAvatar || noContainer || hasDuplicates || noFX))
{
if (GUILayout.Button("Add Selected Features")){ AddFeatures(); }
}
if (GUILayout.Button("Remove FT System")){ RemoveFeatures(); }
serializedObject.ApplyModifiedProperties();
}
// // //
internal string SystemPrefix
{
get => SystemName + "/";
private set {}
}
const string FaceTrackingToggleParameter = "FaceTracking";
private void AddFeatures()
{
InitializeAAC();
if(EditorUtility.DisplayDialog("VRCFTGenerator: Add","Generate Face Tracking?", "OK", "Cancel"))
{
CreateFTBlendshapeController();
AssetDatabase.SaveAssets();
}
}
private void RemoveFeatures()
{
InitializeAAC();
if (EditorUtility.DisplayDialog("VRCFTGenerator: Remove", "Remove Face Tracking from Animator (and items selected for deletion)?", "OK", "Cancel"))
{
RemoveFTBlendshapeController();
AssetDatabase.SaveAssets();
}
}
private void RemoveFTBlendshapeController()
{
// Find FX Layer
AnimatorController fxLayer = (AnimatorController) generator.avatar.baseAnimationLayers.First(it => it.type == VRCAvatarDescriptor.AnimLayerType.FX).animatorController;
aac.RemoveAllMainLayers();
foreach(var layer in fxLayer.layers)
{
string layerName = layer.name;
string supportingLayerName = layerName.Replace(SystemName + "__", "");
if(layerName.StartsWith(SystemName))
{
aac.RemoveAllSupportingLayers(supportingLayerName);
}
}
List<string> parameterNames = VRCFTValues.CombinedMapping.Keys.ToList();
parameterNames = parameterNames.Concat(VRCFTValues.BlendshapeMapping.Keys.ToList())
.Concat(VRCFTValues.AveragedMapping.Keys.ToList())
.ToList();
AnimatorControllerParameter[] fxParameters = fxLayer.parameters;
if (generator.manageExpressionParameters)
{
VRCExpressionParameters.Parameter[] expressionParameters = generator.avatar.expressionParameters.parameters;
foreach (VRCExpressionParameters.Parameter expressionParameter in expressionParameters)
{
if (expressionParameter.name.Contains(SystemPrefix) || expressionParameter.name == FaceTrackingToggleParameter)
{
VRCFTGenerator_ParameterUtility.RemoveParameter(expressionParameter.name, generator.avatar);
}
foreach (string p in parameterNames)
{
if (expressionParameter.name.Contains(p))
{
VRCFTGenerator_ParameterUtility.RemoveParameter(expressionParameter.name, generator.avatar);
}
}
}
}
if(generator.removeAnimatorParams)
{
int i = 0;
foreach (AnimatorControllerParameter animatorParameter in fxParameters)
{
if (animatorParameter.name.Contains(SystemPrefix) || animatorParameter.name == FaceTrackingToggleParameter)
{
fxLayer.RemoveParameter(fxParameters[i]);
} else {
foreach (string name in parameterNames)
{
if (animatorParameter.name.Contains(name))
{
fxLayer.RemoveParameter(fxParameters[i]);
}
}
}
i++;
}
}
}
private void CreateFTBlendshapeController()
{
var fx = aac.CreateMainFxLayer();
Dictionary<string, VRCFTValues.ParamMode> SelectedParameters = new Dictionary<string, VRCFTValues.ParamMode>();
List<string> selectedBinaryDecodeParams = new List<string>();
List<string> selectedFloatDecodeParams = new List<string>();
List<string> decodeParams = new List<string>();
List<string> smoothingParams = new List<string>();
List<string> directFloatParamsNoPrefix = new List<string>();
int parameterMemoryCost = 1; // 1 for Face Tracking toggle
var faceTrackingToggle = fx.BoolParameter(FaceTrackingToggleParameter);
foreach (ParamSpecifier specification in generator.paramsToAnimate)
{
SelectedParameters.Add(Enum.GetName(typeof(VRCFTValues.ParameterName), specification.VRCFTParameter), specification.mode);
}
// Pre-Parse Selected Parameters
foreach (string param in SelectedParameters.Keys.ToArray())
{
VRCFTValues.ParamMode mode = SelectedParameters[param];
bool isParamFloat = mode == VRCFTValues.ParamMode.floatParam;
bool isParamCombined = VRCFTValues.CombinedMapping.ContainsKey(param);
int paramBits = (int)SelectedParameters[param];
parameterMemoryCost += paramBits;
if(isParamFloat)
{
fx.FloatParameter(param);
if(isParamCombined)
{
selectedFloatDecodeParams.Add(param);
}
else
{
directFloatParamsNoPrefix.Add(param);
}
} else {
for (int j = 0; j < paramBits; j++)
{
int binarySuffix = (int)Mathf.Pow(2, j);
if(generator.useImplicitParameterCasting)
fx.FloatParameter(param + binarySuffix.ToString());
else
fx.BoolParameter(param + binarySuffix.ToString());
}
if(isParamCombined)
{
// Extra bit for negative flag bool
parameterMemoryCost++;
if(generator.useImplicitParameterCasting)
fx.FloatParameter(param + "Negative");
else
fx.BoolParameter(param + "Negative");
}
selectedBinaryDecodeParams.Add(param);
}
if (isParamCombined)
{
smoothingParams.Add(VRCFTValues.CombinedMapping[param][0]);
smoothingParams.Add(VRCFTValues.CombinedMapping[param][1]);
} else {
smoothingParams.Add(param);
}
}
var parameterConstant1 = fx.FloatParameter(SystemPrefix + "Constant_1");
fx.OverrideValue(parameterConstant1, 1f);
decodeParams = selectedFloatDecodeParams.Concat(selectedBinaryDecodeParams).ToList();
BlendTree combinedBlendTree = aac.NewBlendTreeAsRaw();
BlendTree decodeBlendTreeToCombine = aac.NewBlendTreeAsRaw();
BlendTree smoothingBlendTreeToCombine = aac.NewBlendTreeAsRaw();
var combinedDisabledClip = aac.NewClip("FT_Off");
var decodeDisabledClip = aac.NewClip("FT_Off_Decode");
var smoothingDisabledClip = aac.NewClip("FT_Off_Smoothing");
// Create Binary Cast/Decode Layers (only if needed)
int decodeBlendtreeChildren = decodeParams.Count;
if (decodeBlendtreeChildren > 0)
{
var binaryCastLayer = aac.CreateSupportingFxLayer("BinaryCast");
var binaryCastState = binaryCastLayer.NewState("Cast");
binaryCastState.TransitionsTo(binaryCastState).AfterAnimationIsAtLeastAtPercent(0f).WithTransitionToSelf().When(faceTrackingToggle.IsTrue()); // re-evaluate every frame
var decodeLayer = aac.CreateSupportingFxLayer("Decode");
var offState = decodeLayer.NewState("FaceTracking_Off").WithAnimation(decodeDisabledClip);
var decodeState = decodeLayer.NewState("Decode");
offState.TransitionsTo(decodeState).When(faceTrackingToggle.IsTrue());
decodeState.TransitionsTo(offState).When(faceTrackingToggle.IsFalse());
AacFlFloatParameter binarySumTopLevelNormalizerParam;
if(generator.writeDefaults)
{
binarySumTopLevelNormalizerParam = parameterConstant1;
}
else
{
binarySumTopLevelNormalizerParam = fx.FloatParameter(SystemPrefix + "DecodeBlendTreeNormalizer");
fx.OverrideValue(binarySumTopLevelNormalizerParam, 1f/(float)decodeBlendtreeChildren);
}
List<ChildMotion> binarySumTopLevelChildMotions = new List<ChildMotion>();
foreach (string param in selectedBinaryDecodeParams)
{
int paramBits = (int)SelectedParameters[param];
bool isCombinedParam = VRCFTValues.CombinedMapping.ContainsKey(param);
string paramPositiveName = isCombinedParam ? VRCFTValues.CombinedMapping[param][0] : param;
var paramPositive = fx.FloatParameter(SystemPrefix + paramPositiveName);
AacFlClip[] zeroClips = new AacFlClip[paramBits];
AacFlClip[] oneClipsParam1 = new AacFlClip[paramBits];
AacFlClip[] oneClipsParam2 = new AacFlClip[paramBits];
BlendTree[] binarySumChildBlendTreesPositive = new BlendTree[paramBits];
BlendTree[] binarySumChildBlendTreesNegative = new BlendTree[paramBits];
AacFlFloatParameter[] binarySumChildBlendTreesBlendParams = new AacFlFloatParameter[paramBits];
for (int j = 0; j < paramBits; j++)
{
int binarySuffix = (int)Mathf.Pow(2, j);
float binaryContribution = 0.5f * Mathf.Pow(2, j+1) * 1f/(Mathf.Pow(2, (float)paramBits) - 1f);
string p = param + binarySuffix.ToString();
foreach(string keyframeParam in decodeParams)
{
var paramToAnimate = fx.FloatParameter(SystemPrefix + keyframeParam);
if(generator.writeDefaults && keyframeParam != param)
continue;
float oneClipVal = keyframeParam == param ? binaryContribution : 0f;
oneClipVal *= (generator.writeDefaults ? 1f : 1f*(float)decodeBlendtreeChildren);
bool keyframeParamIsCombined = VRCFTValues.CombinedMapping.ContainsKey(keyframeParam);
var keyframePositiveName = keyframeParamIsCombined ? VRCFTValues.CombinedMapping[keyframeParam][0] : keyframeParam;
var keyframeNegativeName = keyframeParamIsCombined ? VRCFTValues.CombinedMapping[keyframeParam][1] : keyframeParam;
var keyframePositive = fx.FloatParameter(SystemPrefix + keyframePositiveName);
var keyframeNegative = fx.FloatParameter(SystemPrefix + keyframeNegativeName);
var zeroClip = aac.NewClip(param + "_0_b" + binarySuffix);
var plusClip = aac.NewClip(param + "_1_b" + binarySuffix);
var minusClip = aac.NewClip(param + "_-1_b" + binarySuffix);
// TongueSteps neutral is -1, not 0
if(keyframeParam == "TongueSteps")
{
zeroClip.Animating(clip => clip.AnimatesAnimator(keyframePositive).WithOneFrame(oneClipVal));
plusClip.Animating(clip => clip.AnimatesAnimator(keyframePositive).WithOneFrame(oneClipVal));
minusClip.Animating(clip => clip.AnimatesAnimator(keyframePositive).WithOneFrame(0f));
plusClip.Animating(clip => clip.AnimatesAnimator(keyframeNegative).WithOneFrame(oneClipVal));
zeroClip.Animating(clip => clip.AnimatesAnimator(keyframeNegative).WithOneFrame(0f));
minusClip.Animating(clip => clip.AnimatesAnimator(keyframeNegative).WithOneFrame(0f));
decodeDisabledClip.Animating(clip => clip.AnimatesAnimator(keyframePositive).WithOneFrame(0f));
combinedDisabledClip.Animating(clip => clip.AnimatesAnimator(keyframePositive).WithOneFrame(0f));
decodeDisabledClip.Animating(clip => clip.AnimatesAnimator(keyframeNegative).WithOneFrame(0f));
combinedDisabledClip.Animating(clip => clip.AnimatesAnimator(keyframeNegative).WithOneFrame(0f));
}
else
{
zeroClip.Animating(clip => clip.AnimatesAnimator(keyframePositive).WithOneFrame(0f));
plusClip.Animating(clip => clip.AnimatesAnimator(keyframePositive).WithOneFrame(oneClipVal));
minusClip.Animating(clip => clip.AnimatesAnimator(keyframePositive).WithOneFrame(0f));
decodeDisabledClip.Animating(clip => clip.AnimatesAnimator(keyframePositive).WithOneFrame(0f));
combinedDisabledClip.Animating(clip => clip.AnimatesAnimator(keyframePositive).WithOneFrame(0f));
if(keyframeParamIsCombined)
{
zeroClip.Animating(clip => clip.AnimatesAnimator(keyframeNegative).WithOneFrame(0f));
plusClip.Animating(clip => clip.AnimatesAnimator(keyframeNegative).WithOneFrame(0f));
minusClip.Animating(clip => clip.AnimatesAnimator(keyframeNegative).WithOneFrame(oneClipVal));
decodeDisabledClip.Animating(clip => clip.AnimatesAnimator(keyframeNegative).WithOneFrame(0f));
combinedDisabledClip.Animating(clip => clip.AnimatesAnimator(keyframeNegative).WithOneFrame(0f));
}
}
zeroClips[j] = zeroClip;
oneClipsParam1[j] = plusClip;
oneClipsParam2[j] = minusClip;
}
string boolParamAsFloatName = generator.useImplicitParameterCasting ? param + binarySuffix.ToString() : SystemPrefix + param + binarySuffix.ToString() + "_Float";
var boolParamAsFloat = fx.FloatParameter(boolParamAsFloatName);
if(!generator.useImplicitParameterCasting)
{
var boolParam = fx.BoolParameter(param + binarySuffix.ToString());
binaryCastState.DrivingCasts(boolParam, 0f, 1f, boolParamAsFloat, 0f, 1f);
}
var positiveTree = CreateProxyTree(boolParamAsFloat, zeroClips[j], oneClipsParam1[j], param + $"_b{binarySuffix.ToString()}_Positive");
var negativeTree = CreateProxyTree(boolParamAsFloat, zeroClips[j], oneClipsParam2[j], param + $"_b{binarySuffix.ToString()}_Negative");
binarySumChildBlendTreesPositive[j] = positiveTree;
binarySumChildBlendTreesNegative[j] = negativeTree;
binarySumChildBlendTreesBlendParams[j] = parameterConstant1;
}
BlendTree childMotion;
BlendTree parameterDirectBlendTreePositive = CreateDirectTree(decodeLayer, parameterConstant1, binarySumChildBlendTreesBlendParams, binarySumChildBlendTreesPositive, param + "_Binary_Positive");
BlendTree parameterDirectBlendTreeNegative = CreateDirectTree(decodeLayer, parameterConstant1, binarySumChildBlendTreesBlendParams, binarySumChildBlendTreesNegative, param + "_Binary_Negative");
if (isCombinedParam)
{
string boolParamNegativeAsFloatName = generator.useImplicitParameterCasting ? param : SystemPrefix + param + "_Float";
var boolParamNegativeAsFloat = fx.FloatParameter(boolParamNegativeAsFloatName + "Negative");
if(!generator.useImplicitParameterCasting)
{
var boolParamNegative = fx.BoolParameter(param + "Negative");
binaryCastState.DrivingCasts(boolParamNegative, 0f, 1f, boolParamNegativeAsFloat, 0f, 1f);
}
var combinedTree = CreateFactorTree(boolParamNegativeAsFloat, parameterDirectBlendTreePositive, parameterDirectBlendTreeNegative, param + "_Combined");
childMotion = combinedTree;
} else {
childMotion = parameterDirectBlendTreePositive;
}
binarySumTopLevelChildMotions.Add(new ChildMotion {motion = childMotion, directBlendParameter = binarySumTopLevelNormalizerParam.Name, timeScale = 1.0f, threshold = 0.0f});
}
foreach (string param in selectedFloatDecodeParams)
{
var zeroClip = aac.NewClip(param + "_0");
var oneClip = aac.NewClip(param + "_1");
var minusClip = aac.NewClip(param + "_-1");
foreach(string keyframeParam in decodeParams)
{
var paramToAnimate = fx.FloatParameter(SystemPrefix + keyframeParam);
if(generator.writeDefaults && keyframeParam != param)
continue;
float oneClipVal = keyframeParam == param ? (generator.writeDefaults ? 1f : 1f*(float)decodeBlendtreeChildren) : 0f;
bool keyframeParamIsCombined = VRCFTValues.CombinedMapping.ContainsKey(keyframeParam);
var keyframePositiveName = keyframeParamIsCombined ? VRCFTValues.CombinedMapping[keyframeParam][0] : keyframeParam;
var keyframeNegativeName = keyframeParamIsCombined ? VRCFTValues.CombinedMapping[keyframeParam][1] : keyframeParam;
var keyframePositive = fx.FloatParameter(SystemPrefix + keyframePositiveName);
var keyframeNegative = fx.FloatParameter(SystemPrefix + keyframeNegativeName);
// TongueSteps neutral is -1, not 0
if(keyframeParam == "TongueSteps")
{
zeroClip.Animating(clip => clip.AnimatesAnimator(keyframePositive).WithOneFrame(oneClipVal));
oneClip.Animating(clip => clip.AnimatesAnimator(keyframePositive).WithOneFrame(oneClipVal));
minusClip.Animating(clip => clip.AnimatesAnimator(keyframePositive).WithOneFrame(0f));
oneClip.Animating(clip => clip.AnimatesAnimator(keyframeNegative).WithOneFrame(oneClipVal));
zeroClip.Animating(clip => clip.AnimatesAnimator(keyframeNegative).WithOneFrame(0f));
minusClip.Animating(clip => clip.AnimatesAnimator(keyframeNegative).WithOneFrame(0f));
decodeDisabledClip.Animating(clip => clip.AnimatesAnimator(keyframePositive).WithOneFrame(0f));
combinedDisabledClip.Animating(clip => clip.AnimatesAnimator(keyframePositive).WithOneFrame(0f));
decodeDisabledClip.Animating(clip => clip.AnimatesAnimator(keyframeNegative).WithOneFrame(0f));
combinedDisabledClip.Animating(clip => clip.AnimatesAnimator(keyframeNegative).WithOneFrame(0f));
}
else
{
zeroClip.Animating(clip => clip.AnimatesAnimator(keyframePositive).WithOneFrame(0f));
oneClip.Animating(clip => clip.AnimatesAnimator(keyframePositive).WithOneFrame(oneClipVal));
minusClip.Animating(clip => clip.AnimatesAnimator(keyframeNegative).WithOneFrame(oneClipVal));
decodeDisabledClip.Animating(clip => clip.AnimatesAnimator(keyframePositive).WithOneFrame(0f));
decodeDisabledClip.Animating(clip => clip.AnimatesAnimator(keyframeNegative).WithOneFrame(0f));
combinedDisabledClip.Animating(clip => clip.AnimatesAnimator(keyframePositive).WithOneFrame(0f));
combinedDisabledClip.Animating(clip => clip.AnimatesAnimator(keyframeNegative).WithOneFrame(0f));
}
}
BlendTree childMotion = CreateCombinedTree(fx.FloatParameter(param), minusClip, zeroClip, oneClip, param + "_Combined");
binarySumTopLevelChildMotions.Add(new ChildMotion {motion = childMotion, directBlendParameter = binarySumTopLevelNormalizerParam.Name, timeScale = 1.0f, threshold = 0.0f});
}
var binarySumTopLevelDirectBlendTree = CreateDirectTree(decodeLayer, binarySumTopLevelNormalizerParam, binarySumTopLevelChildMotions.ToArray(), "DecodeBlendTree");
decodeState.WithAnimation(binarySumTopLevelDirectBlendTree);
decodeBlendTreeToCombine = binarySumTopLevelDirectBlendTree;
if(generator.useImplicitParameterCasting)
{
aac.RemoveAllSupportingLayers("BinaryCast");
}
}
// Smoothing/Driving Layer
if(smoothingParams.Count > 0)
{
var smoothingLayer = aac.CreateSupportingFxLayer("SmoothAndDrive"); // Adds or Overwrites
var smoothingFactorParameter = fx.FloatParameter(SystemPrefix + "SmoothingAlpha");
fx.OverrideValue(smoothingFactorParameter, generator.remoteSmoothingTimeConstant);
fx.OverrideValue(faceTrackingToggle, true);
int numDirectStates = smoothingParams.Count;
AacFlFloatParameter directNormalizer;
if(generator.writeDefaults)
{
directNormalizer = parameterConstant1;
}
else
{
directNormalizer = fx.FloatParameter(SystemPrefix + "SmoothingDrivingTreeNormalizer");
float directNormalizerValue = generator.writeDefaults ? 1f : 1f/(float)numDirectStates;
fx.OverrideValue(directNormalizer, directNormalizerValue);
}
List<ChildMotion> smoothingChildMotions = new List<ChildMotion>();
foreach (string parameterToSmooth in smoothingParams)
{
string parameterNameToSmooth = parameterToSmooth;
if(!directFloatParamsNoPrefix.Contains(parameterToSmooth))
{
parameterNameToSmooth = SystemPrefix + parameterNameToSmooth;
}
var parameter = fx.FloatParameter(parameterNameToSmooth);
var smoothedParameter = fx.FloatParameter(SystemPrefix + parameterToSmooth + "_Smoothed");
var zeroClip = aac.NewClip(parameterToSmooth + "param_0_scaled");
var oneClip = aac.NewClip(parameterToSmooth + "param_1_scaled");
foreach(string paramName in smoothingParams)
{
var paramNameSmoothed = fx.FloatParameter(SystemPrefix + paramName + "_Smoothed");
if(generator.writeDefaults && paramName != parameterToSmooth)
continue;
float driveVal = paramName == parameterToSmooth ? (generator.writeDefaults ? 1 : 1f*(float)numDirectStates) : 0f;
zeroClip.Animating(clip => clip.AnimatesAnimator(paramNameSmoothed).WithOneFrame(0f));
oneClip.Animating(clip => clip.AnimatesAnimator(paramNameSmoothed).WithOneFrame(driveVal));
foreach (var target in generator.blendshapeTargetMeshRenderers)
{
if(VRCFTValues.AveragedMapping.ContainsKey(paramName))
{
string blendshapeName1 = VRCFTValues.BlendshapeMapping[VRCFTValues.AveragedMapping[paramName][0]];
string blendshapeName2 = VRCFTValues.BlendshapeMapping[VRCFTValues.AveragedMapping[paramName][1]];
zeroClip.Animating(clip => {clip.Animates(target, "blendShape." + blendshapeName1).WithOneFrame(0f);});
zeroClip.Animating(clip => {clip.Animates(target, "blendShape." + blendshapeName2).WithOneFrame(0f);});
oneClip.Animating(clip => {clip.Animates(target, "blendShape." + blendshapeName1).WithOneFrame(driveVal*100f);});
oneClip.Animating(clip => {clip.Animates(target, "blendShape." + blendshapeName2).WithOneFrame(driveVal*100f);});
} else {
string blendshapeName = VRCFTValues.BlendshapeMapping[paramName];
zeroClip.Animating(clip => {clip.Animates(target, "blendShape." + blendshapeName).WithOneFrame(0f);});
oneClip.Animating(clip => {clip.Animates(target, "blendShape." + blendshapeName).WithOneFrame(driveVal*100f);});
}
}
}
var factorTree = CreateFactorTree(smoothingFactorParameter, CreateProxyTree(parameter, zeroClip, oneClip, parameter.Name + "_SmoothingA"), CreateSmoothingTree(smoothedParameter, zeroClip, oneClip, parameter.Name + "_SmoothingB"), parameter.Name + "_Smoothing");
smoothingChildMotions.Add(new ChildMotion {motion = factorTree, directBlendParameter = directNormalizer.Name, timeScale = 1.0f, threshold = 0.0f});
}
var smoothingDirectBlendTree = CreateDirectTree(smoothingLayer, directNormalizer, smoothingChildMotions.ToArray(), "Smoothing");
var offState = smoothingLayer.NewState("FaceTracking_Off").WithAnimation(smoothingDisabledClip);
var smoothingState = smoothingLayer.NewState("Smoothing").WithAnimation(smoothingDirectBlendTree);
offState.TransitionsTo(smoothingState).When(faceTrackingToggle.IsTrue());
smoothingState.TransitionsTo(offState).When(faceTrackingToggle.IsFalse());
foreach (string paramName in smoothingParams)
{
var smoothedParameter = fx.FloatParameter(SystemPrefix + paramName + "_Smoothed");
smoothingDisabledClip.Animating(clip => clip.AnimatesAnimator(smoothedParameter).WithOneFrame(0f));
foreach (var target in generator.blendshapeTargetMeshRenderers)
{
if(VRCFTValues.AveragedMapping.ContainsKey(paramName))
{
string blendshapeName1 = VRCFTValues.BlendshapeMapping[VRCFTValues.AveragedMapping[paramName][0]];
string blendshapeName2 = VRCFTValues.BlendshapeMapping[VRCFTValues.AveragedMapping[paramName][1]];
smoothingDisabledClip.Animating(clip => {clip.Animates(target, "blendShape." + blendshapeName1).WithOneFrame(0f);});
smoothingDisabledClip.Animating(clip => {clip.Animates(target, "blendShape." + blendshapeName2).WithOneFrame(0f);});
combinedDisabledClip.Animating(clip => {clip.Animates(target, "blendShape." + blendshapeName1).WithOneFrame(0f);});
combinedDisabledClip.Animating(clip => {clip.Animates(target, "blendShape." + blendshapeName2).WithOneFrame(0f);});
} else {
smoothingDisabledClip.Animating(clip => {clip.Animates(target, "blendShape." + VRCFTValues.BlendshapeMapping[paramName]).WithOneFrame(0f);});
combinedDisabledClip.Animating(clip => {clip.Animates(target, "blendShape." + VRCFTValues.BlendshapeMapping[paramName]).WithOneFrame(0f);});
}
}
}
smoothingBlendTreeToCombine = smoothingDirectBlendTree;
}
if(generator.writeDefaults
&& generator.singleLayer
&& decodeBlendTreeToCombine != (BlendTree)null
&& smoothingBlendTreeToCombine != (BlendTree)null)
{
var ftCombinedLayer = aac.CreateSupportingFxLayer("CombinedFaceTracking");
AacFlFloatParameter[] blendParameters = {parameterConstant1, parameterConstant1};
BlendTree[] combinedChildren = {decodeBlendTreeToCombine, smoothingBlendTreeToCombine};
combinedBlendTree = CreateDirectTree(ftCombinedLayer, parameterConstant1, blendParameters, combinedChildren, "CombinedFaceTracking");
var disabledState = ftCombinedLayer.NewState("Disabled").WithAnimation(combinedDisabledClip);
var enabledState = ftCombinedLayer.NewState("Enabled").WithAnimation(combinedBlendTree);
disabledState.TransitionsTo(enabledState).When(faceTrackingToggle.IsTrue());
enabledState.TransitionsTo(disabledState).When(faceTrackingToggle.IsFalse());
aac.RemoveAllSupportingLayers("Decode");
aac.RemoveAllSupportingLayers("SmoothAndDrive");
}
aac.RemoveAllMainLayers();
if (generator.manageExpressionParameters)
{
AddParametersToAvatar(generator.avatar, SelectedParameters);
}
}
// // // // // // // // // // // // // // // // // // // // // // // // // // //
private void AddParametersToAvatar(VRCAvatarDescriptor avatar, Dictionary<string, VRCFTValues.ParamMode> parameters)
{
VRCFTGenerator_ParameterUtility.AddParameter(FaceTrackingToggleParameter, VRCExpressionParameters.ValueType.Bool, true, true, avatar);
foreach (var param in parameters)
{
if (param.Value == VRCFTValues.ParamMode.floatParam)
{
if(!VRCFTGenerator_ParameterUtility.ParameterExists(param.Key, avatar))
{
VRCFTGenerator_ParameterUtility.AddParameter(param.Key, VRCExpressionParameters.ValueType.Float, 0f, false, avatar);
}
}
else
{
int paramBits = (int) param.Value;
bool isCombinedParam = VRCFTValues.CombinedMapping.ContainsKey(param.Key);
if (isCombinedParam && !VRCFTGenerator_ParameterUtility.ParameterExists(param.Key, avatar))
{
VRCFTGenerator_ParameterUtility.AddParameter(param.Key + "Negative", VRCExpressionParameters.ValueType.Bool, false, false, avatar);
}
for (int j = 0; j < paramBits; j++)
{
int binarySuffix = (int) Mathf.Pow(2, j);
string p = param.Key + binarySuffix.ToString();
if (!VRCFTGenerator_ParameterUtility.ParameterExists(param.Key, avatar))
{
VRCFTGenerator_ParameterUtility.AddParameter(p, VRCExpressionParameters.ValueType.Bool, false, false, avatar);
}
}
}
}
}
private AacFlFloatParameter CreateFramerateMeasurementSystem()
{
// Framerate Measurement System (from llealoo's implementation)
var layer_frameTimeCaptureA = aac.CreateSupportingFxLayer("FramerateInvariance_CaptureA");
// Declare our stuff here
var frameTimeTriggerA = layer_frameTimeCaptureA.BoolParameter ("FrameTimeTriggerA");
var frameTimeCaptureA = layer_frameTimeCaptureA.FloatParameter("FrameTimeCaptureA");
var frameTimeTriggerB = layer_frameTimeCaptureA.BoolParameter ("FrameTimeTriggerB");
var frameTimeCaptureB = layer_frameTimeCaptureA.FloatParameter("FrameTimeCaptureB");
var frameTimeMeasured = layer_frameTimeCaptureA.FloatParameter("FrameTimeMeasured");
// Need 2 different layers to properly measure
// Frame Capture Layer A
var clip_frameTimeCaptureA = aac.NewClip("FrameTimeA")
.Animating(clip => clip.AnimatesAnimator(frameTimeCaptureA)
.WithSecondsUnit(keyframes => keyframes.Linear(0, 0f).Linear(1, 1f)));
var state_frameTimeFlipperA = layer_frameTimeCaptureA.NewState("CaptureA")
.WithAnimation(clip_frameTimeCaptureA);
state_frameTimeFlipperA.TransitionsTo(state_frameTimeFlipperA).WithTransitionToSelf().When(frameTimeTriggerB.IsTrue());
// Frame Capture Layer B
var layer_frameTimeCaptureB = aac.CreateSupportingFxLayer("FramerateInvariance_CaptureB");
var clip_frameTimeCaptureB = aac.NewClip("FrameTimeB")
.Animating(clip => clip.AnimatesAnimator(frameTimeCaptureB)
.WithSecondsUnit(keyframes => keyframes.Linear(0, 0f).Linear(1, 1f)));
var state_frameTimeFlipperB = layer_frameTimeCaptureB.NewState("CaptureB")
.WithAnimation(clip_frameTimeCaptureB);
state_frameTimeFlipperB.TransitionsTo(state_frameTimeFlipperB).WithTransitionToSelf().When(frameTimeTriggerA.IsTrue());
// Grab from correct capture layer
var layer_frameTimeMeasurement = aac.CreateSupportingFxLayer("FramerateInvariance_Frametime");
var clip_frameTimeMeasured = aac.NewClip("FrameTimeMeasured")
.Animating(clip => clip.AnimatesAnimator(frameTimeMeasured)
.WithSecondsUnit(keyframes => keyframes.Linear(0, 0f).Linear(1, 1f)));
var state_frameTimeCaptureA = layer_frameTimeMeasurement.NewState("ReadCaptureA")
.WithAnimation(clip_frameTimeMeasured)
.MotionTime(frameTimeCaptureA)
.Drives(frameTimeTriggerA, true)
.Drives(frameTimeTriggerB, false);
var state_frameTimeCaptureB = layer_frameTimeMeasurement.NewState("ReadCaptureB")
.WithAnimation(clip_frameTimeMeasured)
.MotionTime(frameTimeCaptureB)
.Drives(frameTimeTriggerA, false)
.Drives(frameTimeTriggerB, true);
state_frameTimeCaptureA.TransitionsTo(state_frameTimeCaptureB).When(frameTimeTriggerA.IsTrue());
state_frameTimeCaptureB.TransitionsTo(state_frameTimeCaptureA).When(frameTimeTriggerB.IsTrue());
return frameTimeMeasured;
}
private AacFlFloatParameter CreateLocalRemoteSmoothingLayer(AacFlFloatParameter frameTimeMeasured)
{
AacFlLayer smoothingFactorParameterLayer = aac.CreateSupportingFxLayer("SmoothingParameter");
AacFlFloatParameter smoothingFactorParameter = smoothingFactorParameterLayer.FloatParameter("FT_SmoothingAlpha");
var IsLocal = smoothingFactorParameterLayer.BoolParameter("IsLocal"); // Only adds if not already present
smoothingFactorParameterLayer.OverrideValue(smoothingFactorParameter, generator.remoteSmoothingTimeConstant); // Forces the value to init at remote value
var smoothingParameterNameRemote = "FT_SmoothingAlpha_Remote";
var smoothingParameterNameLocal = "FT_SmoothingAlpha_Local";
var smoothingFactorParameterRemote = smoothingFactorParameterLayer.FloatParameter(smoothingParameterNameRemote);
var smoothingFactorParameterLocal = smoothingFactorParameterLayer.FloatParameter(smoothingParameterNameLocal);
float tauRemote = generator.remoteSmoothingTimeConstant;
float tauLocal = generator.remoteSmoothingTimeConstant;// my.localSmoothingTimeConstant;
float keyframeTime = 0f;
Keyframe[] smoothingParamKeyframesRemote = new Keyframe[61];
Keyframe[] smoothingParamKeyframesLocal = new Keyframe[61];
var smoothingParamCurveRemote = new AnimationCurve();
var smoothingParamCurveLocal = new AnimationCurve();
float sRemote;
float dsRemote;
float sLocal;
float dsLocal;
for(int j = 0; j < 61; j++)
{
keyframeTime = (float)j * 1f/60f;
sRemote = Mathf.Clamp(Mathf.Exp(-keyframeTime / tauRemote), 0.01f, 0.9f);
sLocal = Mathf.Clamp(Mathf.Exp(-keyframeTime / tauLocal), 0.01f, 0.9f);
dsRemote = sRemote <= 0.01f ? 0 : -Mathf.Exp(-keyframeTime / tauRemote)/tauRemote;
dsLocal = sLocal <= 0.01f ? 0 : -Mathf.Exp(-keyframeTime / tauLocal)/tauLocal;
smoothingParamKeyframesRemote[j] = new Keyframe(keyframeTime, sRemote, dsRemote, dsRemote);
smoothingParamKeyframesLocal[j] = new Keyframe(keyframeTime, sLocal, dsLocal, dsLocal);
}
smoothingParamCurveRemote.keys = smoothingParamKeyframesRemote;
smoothingParamCurveLocal.keys = smoothingParamKeyframesLocal;
var clip_remoteSmoothing = aac.NewClip("SmoothingAlphaRemote");
var clip_localSmoothing = aac.NewClip("SmoothingAlphaLocal");
clip_remoteSmoothing.Clip.SetCurve("", typeof(Animator), smoothingFactorParameter.Name, smoothingParamCurveRemote);
clip_localSmoothing.Clip.SetCurve("", typeof(Animator), smoothingFactorParameter.Name, smoothingParamCurveLocal);
var remoteSmoothingState = smoothingFactorParameterLayer.NewState("Remote Smoothing")//.Drives(smoothingFactorParameter, my.remoteSmoothingAlpha);
.WithAnimation(clip_remoteSmoothing).MotionTime(frameTimeMeasured);
var localSmoothingState = smoothingFactorParameterLayer.NewState("Local Smoothing")//.Drives(smoothingFactorParameter, my.localSmoothingAlpha);
.WithAnimation(clip_localSmoothing).MotionTime(frameTimeMeasured);
// Transition between local and remote smoothing
localSmoothingState.TransitionsTo(remoteSmoothingState).When(IsLocal.IsFalse());
remoteSmoothingState.TransitionsTo(localSmoothingState).When(IsLocal.IsTrue());
return smoothingFactorParameter;
}
// // //
string AssetName(string name)
{
return $"zAutogenerated__{generator.assetKey}__{name}";
}
private BlendTree CreateCombinedTree(AacFlFloatParameter manualControlParameter, AacFlClip minusClip, AacFlClip zeroClip, AacFlClip oneClip, string name = "")
{
var proxyTree = aac.NewBlendTreeAsRaw();
proxyTree.blendParameter = manualControlParameter.Name;
proxyTree.blendType = BlendTreeType.Simple1D;
proxyTree.minThreshold = -1;
proxyTree.maxThreshold = 1;
proxyTree.useAutomaticThresholds = true;
proxyTree.children = new[]
{
new ChildMotion {motion = minusClip.Clip, timeScale = 1, threshold = -1},
new ChildMotion {motion = zeroClip.Clip, timeScale = 1, threshold = 0},
new ChildMotion {motion = oneClip.Clip, timeScale = 1, threshold = 1}
};
if(name != "")
proxyTree.name = AssetName(name);
return proxyTree;
}
private BlendTree CreateProxyTree(AacFlFloatParameter manualControlParameter, AacFlClip zeroClip, AacFlClip oneClip, string name = "")
{
var proxyTree = aac.NewBlendTreeAsRaw();
proxyTree.blendParameter = manualControlParameter.Name;
proxyTree.blendType = BlendTreeType.Simple1D;
proxyTree.minThreshold = 0;
proxyTree.maxThreshold = 1;
proxyTree.useAutomaticThresholds = true;
proxyTree.children = new[]
{
new ChildMotion {motion = zeroClip.Clip, timeScale = 1, threshold = 0},
new ChildMotion {motion = oneClip.Clip, timeScale = 1, threshold = 1}
};
if(name != "")
proxyTree.name = AssetName(name);
return proxyTree;
}
private BlendTree CreateFactorTree(AacFlFloatParameter smoothingFactorParameter, BlendTree proxyTree, BlendTree smoothingTree, string name = "")
{
var factorTree = aac.NewBlendTreeAsRaw();
{
factorTree.blendParameter = smoothingFactorParameter.Name;
factorTree.blendType = BlendTreeType.Simple1D;
factorTree.minThreshold = 0;
factorTree.maxThreshold = 1;
factorTree.useAutomaticThresholds = true;
factorTree.children = new[]
{
new ChildMotion {motion = proxyTree, timeScale = 1, threshold = 0},
new ChildMotion {motion = smoothingTree, timeScale = 1, threshold = 1}
};
if(name != "")
proxyTree.name = AssetName(name);
}
return factorTree;
}
private BlendTree CreateSmoothingTree(AacFlFloatParameter smoothedParameter, AacFlClip zeroClip, AacFlClip oneClip, string name = "")
{
var smoothingTree = aac.NewBlendTreeAsRaw();
smoothingTree.blendParameter = smoothedParameter.Name;
smoothingTree.blendType = BlendTreeType.Simple1D;
smoothingTree.minThreshold = 0;
smoothingTree.maxThreshold = 1;
smoothingTree.useAutomaticThresholds = true;
smoothingTree.children = new[]
{
new ChildMotion {motion = zeroClip.Clip, timeScale = 1, threshold = 0},
new ChildMotion {motion = oneClip.Clip, timeScale = 1, threshold = 1}
};
if(name != "")
smoothingTree.name = AssetName(name);