Beispiel #1
0
 private void CreateOrReplaceLipsyncOverrideView(AnimationClip emptyClip, List <ManifestBinding> manifestBindings)
 {
     if (_activityStageName != null)
     {
         SharedLayerUtils.CreateParamIfNotExists(_animatorController, _activityStageName, AnimatorControllerParameterType.Int);
     }
     if (Feature(FeatureToggles.ExposeIsLipsyncLimited))
     {
         SharedLayerUtils.CreateParamIfNotExists(_animatorController, SharedLayerUtils.HaiGestureComboIsLipsyncLimitedParamName, AnimatorControllerParameterType.Int);
     }
     if (Feature(FeatureToggles.ExposeDisableLipsyncOverride))
     {
         SharedLayerUtils.CreateParamIfNotExists(_animatorController, SharedLayerUtils.HaiGestureComboDisableLipsyncOverrideParamName, AnimatorControllerParameterType.Int);
     }
     SharedLayerUtils.CreateParamIfNotExists(_animatorController, "Viseme", AnimatorControllerParameterType.Int);
     SharedLayerUtils.CreateParamIfNotExists(_animatorController, "_Hai_GestureAnimLSWide", AnimatorControllerParameterType.Float);
     new LayerForLipsyncOverrideView(_analogBlinkingUpperThreshold,
                                     _logicalAvatarMask,
                                     _animatorGenerator,
                                     _avatarDescriptor,
                                     _limitedLipsync,
                                     _assetContainer,
                                     emptyClip,
                                     manifestBindings,
                                     _conflictPrevention.ShouldWriteDefaults).Create();
 }
Beispiel #2
0
 private static void CreateOrReplaceSmoothing(AvatarMask weightCorrectionAvatarMask, AnimatorGenerator animatorGenerator, AnimatorController animatorController, ConflictPrevention conflictPrevention)
 {
     SharedLayerUtils.CreateParamIfNotExists(animatorController, SharedLayerUtils.HaiGestureComboLeftWeightSmoothing, AnimatorControllerParameterType.Float);
     SharedLayerUtils.CreateParamIfNotExists(animatorController, SharedLayerUtils.HaiGestureComboRightWeightSmoothing, AnimatorControllerParameterType.Float);
     SharedLayerUtils.CreateParamIfNotExists(animatorController, SharedLayerUtils.HaiGestureComboSmoothingFactor, AnimatorControllerParameterType.Float);
     new LayerForAnalogFistSmoothing(animatorGenerator, weightCorrectionAvatarMask, conflictPrevention.ShouldWriteDefaults, animatorController).Create();
 }
Beispiel #3
0
        private void InitializeMachineFor(AnimatorStateMachine machine, string proxyParam, string liveParam, string handParam, string clipPath)
        {
            var waiting = machine.AddState("Waiting", SharedLayerUtils.GridPosition(1, 1));

            waiting.timeParameter       = proxyParam;
            waiting.timeParameterActive = true;
            waiting.motion             = AssetDatabase.LoadAssetAtPath <AnimationClip>(clipPath);
            waiting.speed              = 1;
            waiting.writeDefaultValues = _writeDefaultsForAnimatedAnimatorParameterStates;

            var listening = machine.AddState("Listening", SharedLayerUtils.GridPosition(1, 2));

            listening.timeParameter       = liveParam;
            listening.timeParameterActive = true;
            listening.motion             = AssetDatabase.LoadAssetAtPath <AnimationClip>(clipPath);
            listening.speed              = 1;
            listening.writeDefaultValues = _writeDefaultsForAnimatedAnimatorParameterStates;

            var toListening = waiting.AddTransition(listening);

            SetupTransition(toListening);
            toListening.AddCondition(AnimatorConditionMode.Equals, 1, handParam);

            var toWaiting = listening.AddTransition(waiting);

            SetupTransition(toWaiting);
            toWaiting.AddCondition(AnimatorConditionMode.NotEqual, 1, handParam);
        }
Beispiel #4
0
        private void CreateOrReplaceExpressionsView(AnimationClip emptyClip, List <ManifestBinding> manifestBindings)
        {
            CreateExpressionsViewParameters(_animatorController, _activityStageName);
            SharedLayerUtils.CreateParamIfNotExists(_animatorController, "_Hai_GestureAnimBlink", AnimatorControllerParameterType.Float);
            SharedLayerUtils.CreateParamIfNotExists(_animatorController, "_Hai_GestureAnimLSWide", AnimatorControllerParameterType.Float);

            var avatarFallbacks = new CgeAvatarSnapshot(_avatarDescriptor, _compilerFallbackParamList).CaptureFallbacks();

            new LayerForExpressionsView(
                _featuresToggles,
                _animatorGenerator,
                _expressionsAvatarMask,
                emptyClip,
                _activityStageName,
                _conflictPrevention,
                _assetContainer,
                _compilerConflictFxLayerMode,
                _compilerIgnoreParamList,
                avatarFallbacks,
                new List <CurveKey>(),
                _animatorController,
                _comboLayers,
                _useGestureWeightCorrection,
                _useSmoothing,
                manifestBindings,
                ""
                ).Create();
        }
Beispiel #5
0
        private AnimatorState CreateSuspendState(AnimatorStateMachine machine, AnimationClip emptyClip)
        {
            var enableBlinking = machine.AddState("SuspendBlinking", SharedLayerUtils.GridPosition(1, 1));

            enableBlinking.motion             = emptyClip;
            enableBlinking.writeDefaultValues = _writeDefaultsForLogicalStates;
            return(enableBlinking);
        }
Beispiel #6
0
 private static void CreateOrReplaceWeightCorrection(AvatarMask weightCorrectionAvatarMask, AnimatorGenerator animatorGenerator, AnimatorController animatorController, ConflictPrevention conflictPrevention)
 {
     SharedLayerUtils.CreateParamIfNotExists(animatorController, "GestureLeft", AnimatorControllerParameterType.Int);
     SharedLayerUtils.CreateParamIfNotExists(animatorController, "GestureRight", AnimatorControllerParameterType.Int);
     SharedLayerUtils.CreateParamIfNotExists(animatorController, "GestureLeftWeight", AnimatorControllerParameterType.Float);
     SharedLayerUtils.CreateParamIfNotExists(animatorController, "GestureRightWeight", AnimatorControllerParameterType.Float);
     SharedLayerUtils.CreateParamIfNotExists(animatorController, SharedLayerUtils.HaiGestureComboLeftWeightProxy, AnimatorControllerParameterType.Float);
     SharedLayerUtils.CreateParamIfNotExists(animatorController, SharedLayerUtils.HaiGestureComboRightWeightProxy, AnimatorControllerParameterType.Float);
     new LayerForWeightCorrection(animatorGenerator, weightCorrectionAvatarMask, conflictPrevention.ShouldWriteDefaults).Create();
 }
Beispiel #7
0
 private List <ManifestBinding> CreateManifestBindings(AnimationClip emptyClip)
 {
     return(_comboLayers
            .Select((mapper, layerOrdinal) => new ManifestBinding(
                        ToParameterGeneration(mapper),
                        SharedLayerUtils.FromMapper(mapper, emptyClip),
                        layerOrdinal
                        ))
            .ToList());
 }
        public void Create()
        {
            EditorUtility.DisplayProgressBar("GestureCombo", "Clearing lipsync override layer", 0f);
            var machine = ReinitializeLayer();

            if (!_manifestBindings.Any(manifest => manifest.Manifest.RequiresLimitedLipsync()))
            {
                return;
            }

            var none = machine.AddState("None", SharedLayerUtils.GridPosition(0, 0));

            none.motion             = _emptyClip;
            none.writeDefaultValues = false;

            var noneTransition = machine.AddAnyStateTransition(none);

            SetupLipsyncTransition(noneTransition);
            noneTransition.canTransitionToSelf = false;
            noneTransition.duration            = _limitedLipsync.transitionDuration;
            noneTransition.AddCondition(AnimatorConditionMode.Less, _analogBlinkingUpperThreshold, "_Hai_GestureAnimLSWide");

            _assetContainer.RemoveAssetsStartingWith("zAutogeneratedLipsync_", typeof(AnimationClip));
            var regularVisemeClips = CreateRegularClips();
            var wideVisemeClips    = CreateWideClips();

            AssetContainer.GlobalSave();
            for (var visemeNumber = 0; visemeNumber < wideVisemeClips.Count; visemeNumber++)
            {
                var state = machine.AddState("Wide " + visemeNumber, SharedLayerUtils.GridPosition(4, 2 + visemeNumber));
                state.motion             = wideVisemeClips[visemeNumber];
                state.writeDefaultValues = _writeDefaultsForLipsyncBlendshapes;

                var transition = machine.AddAnyStateTransition(state);
                SetupLipsyncTransition(transition);
                transition.canTransitionToSelf = false;
                transition.duration            = _limitedLipsync.transitionDuration * FindVisemeTransitionTweak(visemeNumber);
                transition.AddCondition(AnimatorConditionMode.Equals, visemeNumber, "Viseme");
                transition.AddCondition(AnimatorConditionMode.Greater, _analogBlinkingUpperThreshold, "_Hai_GestureAnimLSWide");
            }
            for (var visemeNumber = 0; visemeNumber < regularVisemeClips.Count; visemeNumber++)
            {
                var state = machine.AddState("Regular " + visemeNumber, SharedLayerUtils.GridPosition(-4, 2 + visemeNumber));
                state.motion             = regularVisemeClips[visemeNumber];
                state.writeDefaultValues = _writeDefaultsForLipsyncBlendshapes;

                var transition = machine.AddAnyStateTransition(state);
                SetupLipsyncTransition(transition);
                transition.canTransitionToSelf = false;
                transition.duration            = _limitedLipsync.transitionDuration * FindVisemeTransitionTweak(visemeNumber);
                transition.AddCondition(AnimatorConditionMode.Equals, visemeNumber, "Viseme");
                transition.AddCondition(AnimatorConditionMode.Less, _analogBlinkingUpperThreshold, "_Hai_GestureAnimLSWide");
            }
        }
        public void Create()
        {
            EditorUtility.DisplayProgressBar("GestureCombo", "Clearing expressions layer", 0f);
            var machine = ReinitializeLayer();

            var defaultState = machine.AddState("Default", SharedLayerUtils.GridPosition(-1, -1));

            defaultState.motion             = _emptyClip;
            defaultState.writeDefaultValues = _conflictPrevention.ShouldWriteDefaults;

            if (_activityStageName != null)
            {
                CreateTransitionWhenActivityIsOutOfBounds(machine, defaultState);
            }

            var activityManifests = _manifestBindings;

            EditorUtility.DisplayProgressBar("GestureCombo", "Generating animations", 0f);
            _assetContainer.RemoveAssetsStartingWith("zAutogeneratedExp" + _animInfix + "_", typeof(AnimationClip));
            _assetContainer.RemoveAssetsStartingWith("zAutogeneratedPup" + _animInfix + "_", typeof(BlendTree));
            activityManifests = new AnimationNeutralizer(
                activityManifests,
                _compilerConflictFxLayerMode,
                _compilerIgnoreParamList,
                _compilerFallbackParamList,
                _blinkBlendshapes,
                _assetContainer,
                _conflictPrevention.ShouldGenerateExhaustiveAnimations,
                _emptyClip,
                Feature(FeatureToggles.DoNotFixSingleKeyframes)
                ).NeutralizeManifestAnimations();

            // The blend tree auto weight corrector assumes that all of the Manifests' blend trees have been autogenerated.
            // This remains true as long as the Animation Neutralizer is executed before this.
            activityManifests = new CgeBlendTreeAutoWeightCorrector(activityManifests, _useGestureWeightCorrection, _useSmoothing, _assetContainer)
                                .MutateAndCorrectExistingBlendTrees();

            foreach (var parameter in AllParametersUsedByManifests(activityManifests))
            {
                SharedLayerUtils.CreateParamIfNotExists(_animatorController, parameter, AnimatorControllerParameterType.Float);
            }

            var combinator = new IntermediateCombinator(activityManifests);

            new GestureCExpressionCombiner(
                _animatorController,
                machine,
                combinator.IntermediateToTransition,
                _activityStageName,
                _conflictPrevention.ShouldWriteDefaults,
                _useGestureWeightCorrection,
                _useSmoothing
                ).Populate();
        }
        private void CreateTransitionWhenActivityIsOutOfBounds(AnimatorStateMachine machine, AnimatorState defaultState)
        {
            var transition = machine.AddAnyStateTransition(defaultState);

            SharedLayerUtils.SetupDefaultTransition(transition);

            foreach (var layer in _comboLayers)
            {
                transition.AddCondition(AnimatorConditionMode.NotEqual, layer.stageValue, _activityStageName);
            }
        }
Beispiel #11
0
        private void CreateOrReplaceBooleansToVirtualActivityMenu()
        {
            foreach (var mapper in _comboLayers)
            {
                if (!string.IsNullOrEmpty(mapper.booleanParameterName))
                {
                    SharedLayerUtils.CreateParamIfNotExists(_animatorController, mapper.booleanParameterName, AnimatorControllerParameterType.Bool);
                }
            }

            new LayerForBooleansToVirtualActivity(_animatorGenerator, _logicalAvatarMask, _conflictPrevention.ShouldWriteDefaults, _comboLayers).Create();
        }
Beispiel #12
0
        private static void CreateExpressionsViewParameters(AnimatorController animatorController, string activityStageName)
        {
            if (activityStageName != null)
            {
                SharedLayerUtils.CreateParamIfNotExists(animatorController, activityStageName, AnimatorControllerParameterType.Int);
            }

            SharedLayerUtils.CreateParamIfNotExists(animatorController, "GestureLeft", AnimatorControllerParameterType.Int);
            SharedLayerUtils.CreateParamIfNotExists(animatorController, "GestureRight", AnimatorControllerParameterType.Int);
            SharedLayerUtils.CreateParamIfNotExists(animatorController, "GestureLeftWeight", AnimatorControllerParameterType.Float);
            SharedLayerUtils.CreateParamIfNotExists(animatorController, "GestureRightWeight", AnimatorControllerParameterType.Float);
        }
Beispiel #13
0
        private static void ReapAnimator(AnimatorController animatorController)
        {
            if (AssetDatabase.GetAssetPath(animatorController) == "")
            {
                return;
            }

            var allSubAssets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(animatorController));

            var reachableMotions = SharedLayerUtils.FindAllReachableClipsAndBlendTrees(animatorController)
                                   .ToList <Object>();

            Reap(allSubAssets, typeof(BlendTree), reachableMotions, o => o.name.StartsWith("autoBT_"));
        }
Beispiel #14
0
 private List <string> FindPotentiallyAnimatedPaths()
 {
     return(SharedLayerUtils.FindAllReachableClipsAndBlendTrees(_fxController)
            .OfType <AnimationClip>()
            .SelectMany(clip =>
     {
         var materialSwaps = AnimationUtility.GetObjectReferenceCurveBindings(clip);
         var transforms = AnimationUtility.GetCurveBindings(clip)
                          .Where(binding => binding.type == typeof(Transform));
         return transforms.Concat(materialSwaps)
         .Select(binding => binding.path);
     })
            .Distinct()
            .ToList());
 }
Beispiel #15
0
 private void CreateOrReplaceBlinkingOverrideView(AnimationClip emptyClip, List <ManifestBinding> manifestBindings)
 {
     if (_activityStageName != null)
     {
         SharedLayerUtils.CreateParamIfNotExists(_animatorController, _activityStageName, AnimatorControllerParameterType.Int);
     }
     SharedLayerUtils.CreateParamIfNotExists(_animatorController, "_Hai_GestureAnimBlink", AnimatorControllerParameterType.Float);
     new LayerForBlinkingOverrideView(
         _activityStageName,
         _comboLayers,
         _analogBlinkingUpperThreshold,
         _logicalAvatarMask,
         _animatorGenerator,
         emptyClip,
         manifestBindings,
         _conflictPrevention.ShouldWriteDefaults).Create();
 }
Beispiel #16
0
        public void Create()
        {
            EditorUtility.DisplayProgressBar("GestureCombo", "Clearing eyes blinking override layer", 0f);
            var machine = ReinitializeLayer();

            if (!_manifestBindings.Any(manifest => manifest.Manifest.RequiresBlinking()))
            {
                return;
            }

            var enableBlinking  = CreateBlinkingState(machine, VRC_AnimatorTrackingControl.TrackingType.Tracking, _emptyClip);
            var disableBlinking = CreateBlinkingState(machine, VRC_AnimatorTrackingControl.TrackingType.Animation, _emptyClip);

            var requireSuspension = _activityStageName != null;

            if (requireSuspension)
            {
                var suspend = CreateSuspendState(machine, _emptyClip);

                if (_activityStageName != null)
                {
                    CreateTransitionWhenActivityIsOutOfBounds(enableBlinking, suspend);
                    CreateTransitionWhenActivityIsOutOfBounds(disableBlinking, suspend);
                }

                foreach (var layer in _comboLayers)
                {
                    var transition = suspend.AddTransition(enableBlinking);
                    SharedLayerUtils.SetupDefaultTransition(transition);
                    if (_activityStageName != null)
                    {
                        transition.AddCondition(AnimatorConditionMode.Equals, layer.stageValue, _activityStageName);
                    }
                }
            }

            var toDisable = enableBlinking.AddTransition(disableBlinking);

            SetupBlinkingTransition(toDisable);
            toDisable.AddCondition(AnimatorConditionMode.Greater, _analogBlinkingUpperThreshold, "_Hai_GestureAnimBlink");

            var toEnable = disableBlinking.AddTransition(enableBlinking);

            SetupBlinkingTransition(toEnable);
            toEnable.AddCondition(AnimatorConditionMode.Less, _analogBlinkingUpperThreshold, "_Hai_GestureAnimBlink");
        }
Beispiel #17
0
        public List <BlendShapeKey> FindLipsync()
        {
            if (_avatar == null)
            {
                return(new List <BlendShapeKey>());
            }

            if (_avatar.lipSync != VRC_AvatarDescriptor.LipSyncStyle.VisemeBlendShape ||
                _avatar.VisemeSkinnedMesh == null ||
                _avatar.VisemeSkinnedMesh.sharedMesh == null)
            {
                return(new List <BlendShapeKey>());
            }

            var relativePathToSkinnedMesh = SharedLayerUtils.ResolveRelativePath(_avatar.transform, _avatar.VisemeSkinnedMesh.transform);

            return(_avatar.VisemeBlendShapes
                   .Where(blendShapeName => blendShapeName != null)
                   .Select(blendShapeName => new BlendShapeKey(relativePathToSkinnedMesh, blendShapeName))
                   .ToList());
        }
Beispiel #18
0
        public void DoOverwriteAnimatorGesturePlayableLayer()
        {
            _animatorGenerator = new AnimatorGenerator(_gesturePlayableLayerController, new StatefulEmptyClipProvider(new ClipGenerator(_customEmptyClip, EmptyClipPath, "ComboGesture")));
            var emptyClip = GetOrCreateEmptyClip();

            if (_activityStageName != null)
            {
                SharedLayerUtils.CreateParamIfNotExists(_gesturePlayableLayerController, _activityStageName, AnimatorControllerParameterType.Int);
            }

            if (!Feature(FeatureToggles.DoNotGenerateWeightCorrectionLayer))
            {
                if (_useGestureWeightCorrection)
                {
                    CreateOrReplaceWeightCorrection(_gesturePlayableLayerTechnicalAvatarMask, _animatorGenerator, _gesturePlayableLayerController, _conflictPreventionTempGestureLayer);
                    if (_useSmoothing)
                    {
                        CreateOrReplaceSmoothing(_weightCorrectionAvatarMask, _animatorGenerator, _gesturePlayableLayerController, _conflictPreventionTempGestureLayer);
                    }
                    else
                    {
                        DeleteSmoothing();
                    }
                }
                else
                {
                    DeleteWeightCorrection();
                    DeleteSmoothing();
                }
            }

            var manifestBindings = CreateManifestBindings(emptyClip);

            CreateOrReplaceGesturePlayableLayerExpressionsView(emptyClip, manifestBindings);

            ReapAnimator(_gesturePlayableLayerController);

            AssetDatabase.Refresh();
            EditorUtility.ClearProgressBar();
        }
Beispiel #19
0
        public List <BlendShapeKey> FindBlink()
        {
            if (_avatar == null)
            {
                return(new List <BlendShapeKey>());
            }

            var eyeLook = _avatar.customEyeLookSettings;

            if (eyeLook.eyelidsSkinnedMesh == null || eyeLook.eyelidsSkinnedMesh.sharedMesh == null)
            {
                return(new List <BlendShapeKey>());
            }

            var relativePathToSkinnedMesh = SharedLayerUtils.ResolveRelativePath(_avatar.transform, eyeLook.eyelidsSkinnedMesh.transform);

            return(eyeLook.eyelidsBlendshapes
                   .Select(i => BlendShapeNameIfValid(i, eyeLook))
                   .Where(blendShapeName => blendShapeName != null)
                   .Select(blendShapeName => new BlendShapeKey(relativePathToSkinnedMesh, blendShapeName))
                   .ToList());
        }
 private void SetupLipsyncTransition(AnimatorStateTransition transition)
 {
     SharedLayerUtils.SetupDefaultTransition(transition);
     transition.exitTime    = 0f;
     transition.hasExitTime = true;
 }
Beispiel #21
0
        private AnimatorState CreateBlinkingState(AnimatorStateMachine machine, VRC_AnimatorTrackingControl.TrackingType type,
                                                  AnimationClip emptyClip)
        {
            var enableBlinking = machine.AddState(type == VRC_AnimatorTrackingControl.TrackingType.Tracking ? "EnableBlinking" : "DisableBlinking", SharedLayerUtils.GridPosition(type == VRC_AnimatorTrackingControl.TrackingType.Tracking ? 0 : 2, 3));

            enableBlinking.motion             = emptyClip;
            enableBlinking.writeDefaultValues = _writeDefaultsForLogicalStates;
            var tracking = enableBlinking.AddStateMachineBehaviour <VRCAnimatorTrackingControl>();

            tracking.trackingEyes = type;
            return(enableBlinking);
        }
Beispiel #22
0
        public void DoOverwriteAnimatorFxLayer()
        {
            _animatorGenerator = new AnimatorGenerator(_animatorController, new StatefulEmptyClipProvider(new ClipGenerator(_customEmptyClip, EmptyClipPath, "ComboGesture")));
            var emptyClip = GetOrCreateEmptyClip();

            if (_activityStageName != null)
            {
                SharedLayerUtils.CreateParamIfNotExists(_animatorController, _activityStageName, AnimatorControllerParameterType.Int);
            }

            DeleteDeprecatedControllerLayer();

            if (_parameterGeneration == ParameterGeneration.VirtualActivity)
            {
                CreateOrReplaceBooleansToVirtualActivityMenu();
            }
            else
            {
                DeleteBooleansToVirtualActivityMenu();
            }

            if (!Feature(FeatureToggles.DoNotGenerateWeightCorrectionLayer))
            {
                if (_useGestureWeightCorrection)
                {
                    CreateOrReplaceWeightCorrection(_weightCorrectionAvatarMask, _animatorGenerator, _animatorController, _conflictPrevention);
                    if (_useSmoothing)
                    {
                        CreateOrReplaceSmoothing(_weightCorrectionAvatarMask, _animatorGenerator, _animatorController, _conflictPrevention);
                    }
                    else
                    {
                        DeleteSmoothing();
                    }
                }
                else
                {
                    DeleteWeightCorrection();
                    DeleteSmoothing();
                }
            }

            var manifestBindings = CreateManifestBindings(emptyClip);

            CreateOrReplaceExpressionsView(emptyClip, manifestBindings);

            if (!Feature(FeatureToggles.DoNotGenerateBlinkingOverrideLayer))
            {
                CreateOrReplaceBlinkingOverrideView(emptyClip, manifestBindings);
            }

            if (!Feature(FeatureToggles.DoNotGenerateLipsyncOverrideLayer))
            {
                if (_integrateLimitedLipsync && _avatarDescriptor != null && _avatarDescriptor.VisemeSkinnedMesh != null)
                {
                    CreateOrReplaceLipsyncOverrideView(emptyClip, manifestBindings);
                }
                else
                {
                    DeleteLipsyncOverrideView();
                }
            }

            ReapAnimator(_animatorController);

            AssetDatabase.Refresh();
            EditorUtility.ClearProgressBar();
        }