Пример #1
0
        private static void ApplyCommonSettingsToComponent(OneClickConfiguration configuration, Expression expression,
                                                           int currCmpnt, OneClickComponent oneClickComponent, int exp)
        {
            expression.components[currCmpnt].durationOn  = .08f;
            expression.components[currCmpnt].durationOff = .06f;
            expression.components[currCmpnt].easing      = LerpEasings.EasingType.CubicOut;
            expression.components[currCmpnt].inspFoldout = false;
            var label = String.IsNullOrEmpty(oneClickComponent.componentName)
                                            ? configuration.oneClickExpressions[exp].name
                                            : oneClickComponent.componentName;

            expression.components[currCmpnt].name = label + " cmpnt " + (currCmpnt);
        }
Пример #2
0
        private static bool FindSkinnedMeshRenderers(OneClickConfiguration configuration)
        {
            requiredSmrs.Clear();             // reset list of SMRs...

            if (configuration.smrSearches.Count > 0)
            {
                var allSmrs = selectedObject.GetComponentsInChildren <SkinnedMeshRenderer>();
                // quick test to see if this object has the necessary stuff
                if (allSmrs == null || allSmrs.Length == 0)
                {
                    Debug.LogError(
                        "This object does not have the required components. No Skinned Mesh Renderers found. Ensure this one-click script was applied to the root of the model prefab in the scene hierarchy.");
                    return(false);
                }

                // Find the necessary SMR's
                foreach (var smr in allSmrs)
                {
                    foreach (var smrSearch in configuration.smrSearches)
                    {
                        if (Regex.IsMatch(smr.name, smrSearch, RegexOptions.IgnoreCase))
                        {
                            requiredSmrs.Add(smr);
                        }
                    }
                }

                if (requiredSmrs.Count == 0)
                {
                    string smrsSearched = "";
                    foreach (var smrSearch in configuration.smrSearches)
                    {
                        smrsSearched += smrSearch + " ";
                    }
                    Debug.LogError(
                        "This object does not have the required components. Could not find the referenced SMRs. Ensure the appropriate one-click was used for your model type and generation. " +
                        smrsSearched);
                    return(false);
                }
            }

            return(true);
        }
Пример #3
0
        private static Expression InitializeExpressionType(OneClickConfiguration configuration, int exp)
        {
            Expression expressionData;

            // module-specific expression actions
            switch (configuration.type)
            {
            case OneClickConfiguration.ConfigType.Salsa:
                // create our salsa viseme for each oneClickExpression.
                salsa.visemes.Add(new LipsyncExpression(configuration.oneClickExpressions[exp].name,
                                                        new InspectorControllerHelperData(), 0f));
                var viseme = salsa.visemes[salsa.visemes.Count - 1];
                viseme.expData.inspFoldout = false;
                expressionData             = viseme.expData;
                break;

            case OneClickConfiguration.ConfigType.Emoter:
                // create our emoter emote for each oneClickExpression.
                emoter.emotes.Add(new EmoteExpression(configuration.oneClickExpressions[exp].name,
                                                      new InspectorControllerHelperData(), false, true, false, 0f));
                var emote = emoter.emotes[emoter.emotes.Count - 1];
                var oneClickEmoterExpression = (OneClickEmoterExpression)configuration.oneClickExpressions[exp];
                emote.expData.inspFoldout    = false;
                emote.isRandomEmote          = oneClickEmoterExpression.isRandom;
                emote.isLipsyncEmphasisEmote = oneClickEmoterExpression.isEmphasis;
                emote.isAlwaysEmphasisEmote  = oneClickEmoterExpression.isAlwaysEmphasis;
                emote.isRepeaterEmote        = oneClickEmoterExpression.isRepeater;
                emote.frac     = oneClickEmoterExpression.expressionDynamics;
                expressionData = emote.expData;
                break;

            default:
                expressionData = salsa.visemes[salsa.visemes.Count - 1].expData;
                break;
            }

            return(expressionData);
        }
Пример #4
0
        private static void ConfigureModule(OneClickConfiguration configuration)
        {
            // module-specific initialization::
            switch (configuration.type)
            {
            case OneClickConfiguration.ConfigType.Salsa:
                salsa.visemes.Clear();
                break;

            case OneClickConfiguration.ConfigType.Emoter:
                emoter.emotes.Clear();
                break;
            }

            for (int exp = 0; exp < configuration.oneClickExpressions.Count; exp++)
            {
                Expression expression = new Expression();
                // module-specific expression actions
                switch (configuration.type)
                {
                case OneClickConfiguration.ConfigType.Salsa:
                    // create our salsa viseme for each oneClickExpression.
                    salsa.visemes.Add(new LipsyncExpression(configuration.oneClickExpressions[exp].name, new InspectorControllerHelperData(), 0f));
                    var viseme = salsa.visemes[salsa.visemes.Count - 1];
                    viseme.expData.inspFoldout = false;
                    expression = viseme.expData;
                    break;

                case OneClickConfiguration.ConfigType.Emoter:
                    // create our emoter emote for each oneClickExpression.
                    emoter.emotes.Add(new EmoteExpression(configuration.oneClickExpressions[exp].name, new InspectorControllerHelperData(), false, true, false, 0f));
                    var emote = emoter.emotes[emoter.emotes.Count - 1];
                    emote.expData.inspFoldout    = false;
                    emote.isRandomEmote          = configuration.oneClickExpressions[exp].isRandom;
                    emote.isLipsyncEmphasisEmote = configuration.oneClickExpressions[exp].isEmphasis;
                    emote.isRepeaterEmote        = configuration.oneClickExpressions[exp].isRepeater;
                    emote.frac = configuration.oneClickExpressions[exp].expressionDynamics;
                    expression = emote.expData;
                    break;

                case OneClickConfiguration.ConfigType.Eyes:
                    // create our eyes eye for each oneClickExpression.


                    //expression = eyes.eyes[eyes.eyes.Count - 1].expData;
                    break;

                default:
                    expression = salsa.visemes[salsa.visemes.Count - 1].expData;
                    break;
                }

                var componentCount = 0;
                var currCmpnt      = 0;

                for (int j = 0; j < configuration.oneClickExpressions[exp].components.Count; j++)
                {
                    var oneClickComponent = configuration.oneClickExpressions[exp].components[j];
                    switch (oneClickComponent.type)
                    {
                    case OneClickComponent.ComponentType.Shape:
                        for (int i = 0; i < requiredSmrs.Count; i++)
                        {
                            int blendshapeIndex = -1;
                            // we need to confirm proposed blendshape names are viable...
                            foreach (var blendshapeName in oneClickComponent.blendshapeNames)
                            {
                                if (oneClickComponent.useRegex)
                                {
                                    blendshapeIndex = RegexFindBlendshapeName(requiredSmrs[i], blendshapeName);
                                }
                                else
                                {
                                    blendshapeIndex = requiredSmrs[i].sharedMesh.GetBlendShapeIndex(blendshapeName);
                                }

                                if (blendshapeIndex > -1)                                         // we found one!
                                {
                                    break;
                                }
                            }
                            if (blendshapeIndex == -1)                                     // we didn't find our blendshape...
                            {
                                continue;
                            }

                            // Create a new component if applicable.
                            CreateNewComponent(componentCount, expression);

                            currCmpnt = expression.components.Count - 1;
                            ApplyCommonSettingsToComponent(configuration, expression, currCmpnt, oneClickComponent, exp);

                            expression.controllerVars[currCmpnt].smr        = requiredSmrs[i];
                            expression.controllerVars[currCmpnt].blendIndex = blendshapeIndex;
                            expression.controllerVars[currCmpnt].minShape   = 0f;
                            expression.controllerVars[currCmpnt].maxShape   = oneClickComponent.maxAmount;
                            expression.components[currCmpnt].durationOn     = oneClickComponent.durOn;
                            expression.components[currCmpnt].durationHold   = oneClickComponent.durHold;
                            expression.components[currCmpnt].durationOff    = oneClickComponent.durOff;

                            componentCount++;
                        }
                        break;

                    case OneClickComponent.ComponentType.UMA:
                        // Create a new component if applicable.
                        CreateNewComponent(componentCount, expression);

                        currCmpnt = expression.components.Count - 1;
                        ApplyCommonSettingsToComponent(configuration, expression, currCmpnt, oneClickComponent, exp);

                        expression.components[currCmpnt].controlType     = ExpressionComponent.ControlType.UMA;
                        expression.controllerVars[currCmpnt].umaUepProxy = uepProxy;
                        expression.controllerVars[currCmpnt].blendIndex  = uepProxy.GetPoseIndex(oneClickComponent.poseName);
                        expression.controllerVars[currCmpnt].minShape    = 0f;
                        expression.controllerVars[currCmpnt].uepAmount   = oneClickComponent.maxAmount;
                        expression.components[currCmpnt].durationOn      = oneClickComponent.durOn;
                        expression.components[currCmpnt].durationHold    = oneClickComponent.durHold;
                        expression.components[currCmpnt].durationOff     = oneClickComponent.durOff;

                        componentCount++;
                        break;

                    case OneClickComponent.ComponentType.Bone:
                        // confirm bone is viable...
                        var bone = FindBone(oneClickComponent.boneSearch);
                        if (bone == null)
                        {
                            Debug.LogWarning("Could not find bone: " + oneClickComponent.boneSearch);
                            continue;
                        }

                        // Create a new component if applicable.
                        CreateNewComponent(componentCount, expression);

                        currCmpnt = expression.components.Count - 1;
                        ApplyCommonSettingsToComponent(configuration, expression, currCmpnt, oneClickComponent, exp);

                        expression.components[currCmpnt].controlType = ExpressionComponent.ControlType.Bone;
                        var controlHelper = expression.controllerVars[currCmpnt];
                        controlHelper.bone           = bone;
                        controlHelper.startTform     = ConvertBoneToTform(bone);
                        controlHelper.endTform       = oneClickComponent.max;
                        controlHelper.inspIsSetStart = true;
                        controlHelper.inspIsSetEnd   = true;
                        controlHelper.fracRot        = oneClickComponent.useRot;
                        controlHelper.fracPos        = oneClickComponent.usePos;
                        controlHelper.fracScl        = oneClickComponent.useScl;

                        controlHelper.StoreBoneBase();
                        controlHelper.StoreStartTform();

                        componentCount++;
                        break;
                    }
                }

                // if no component was created for this expression, remove it.
                if (componentCount == 0)
                {
                    Debug.Log("Removed expression " + expression.name + " This may be OK, but may indicate a change in the model generator. If this is a supported model, contact Crazy Minnow Studio via [email protected].");
                    switch (configuration.type)
                    {
                    case OneClickConfiguration.ConfigType.Salsa:
                        salsa.visemes.RemoveAt(salsa.visemes.Count - 1);
                        break;

                    case OneClickConfiguration.ConfigType.Emoter:
                        emoter.emotes.RemoveAt(emoter.emotes.Count - 1);
                        break;
                    }
                }

                // module-specific wrap-up
                switch (configuration.type)
                {
                case OneClickConfiguration.ConfigType.Salsa:
                    salsa.DistributeTriggers(LerpEasings.EasingType.SquaredIn);
                    break;
                }
            }
        }
Пример #5
0
        private static void ConfigureModuleExpressions(OneClickConfiguration configuration)
        {
            for (int exp = 0; exp < configuration.oneClickExpressions.Count; exp++)
            {
                Expression expression = InitializeExpressionType(configuration, exp);

                var componentCount = 0;              // keeps track of good component creation to prevent creating components when criteria are not met (i.e. search blendshape name not found).
                var currCmpntID    = 0;              // holds the index of the current component being configured.
                InspectorControllerHelperData controlHelper;
                ExpressionComponent           component = new ExpressionComponent();

                for (int j = 0; j < configuration.oneClickExpressions[exp].components.Count; j++)
                {
                    var oneClickComponent = configuration.oneClickExpressions[exp].components[j];

                    switch (oneClickComponent.type)
                    {
                    case OneClickComponent.ComponentType.Shape:
                        // create a component for each valid, required SMR.
                        for (int i = 0; i < requiredSmrs.Count; i++)
                        {
                            // cast the OneClickComponent...
                            var oneClickShapeComponent = (OneClickShapeComponent)oneClickComponent;

                            int blendshapeIndex = -1;
                            // we need to confirm proposed blendshape names are viable...
                            foreach (var blendshapeName in oneClickShapeComponent.blendshapeNames)
                            {
                                if (oneClickShapeComponent.useRegex)
                                {
                                    blendshapeIndex = RegexFindBlendshapeName(requiredSmrs[i], blendshapeName);
                                }
                                else
                                {
                                    blendshapeIndex = requiredSmrs[i].sharedMesh.GetBlendShapeIndex(blendshapeName);
                                }

                                if (blendshapeIndex > -1)                                         // we found one!
                                {
                                    break;
                                }
                            }
                            if (blendshapeIndex == -1)                                     // we didn't find our blendshape...
                            {
                                continue;
                            }

                            // Create a new component if applicable.
                            currCmpntID = CreateNewComponent(componentCount, expression);

                            controlHelper            = expression.controllerVars[currCmpntID];
                            controlHelper.smr        = requiredSmrs[i];
                            controlHelper.blendIndex = blendshapeIndex;
                            controlHelper.minShape   = 0f;
                            controlHelper.maxShape   = oneClickShapeComponent.maxAmount;

                            component             = expression.components[currCmpntID];
                            component.controlType = ExpressionComponent.ControlType.Shape;

                            ApplyCommonSettingsToComponent(component, oneClickComponent, currCmpntID);
                            componentCount++;                                     // good component created, update component count.
                        }

                        break;

                    case OneClickComponent.ComponentType.UMA:
                        var oneClickUepComponent = (OneClickUepComponent)oneClickComponent;

                        // Create a new component if applicable.
                        currCmpntID = CreateNewComponent(componentCount, expression);

                        controlHelper             = expression.controllerVars[currCmpntID];
                        controlHelper.umaUepProxy = uepProxy;
                        controlHelper.blendIndex  = uepProxy.GetPoseIndex(oneClickUepComponent.poseName);
                        controlHelper.minShape    = 0f;
                        controlHelper.uepAmount   = oneClickUepComponent.maxAmount;

                        component             = expression.components[currCmpntID];
                        component.controlType = ExpressionComponent.ControlType.UMA;

                        ApplyCommonSettingsToComponent(component, oneClickComponent, currCmpntID);
                        componentCount++;                                 // good component created, update component count.

                        break;

                    case OneClickComponent.ComponentType.Bone:
                        var oneClickBoneComponent = (OneClickBoneComponent)oneClickComponent;

                        // confirm bone is viable...
                        var bone = FindBone(oneClickBoneComponent.componentSearchName);
                        if (bone == null)
                        {
                            Debug.LogWarning("Could not find bone: " + oneClickBoneComponent.componentSearchName);
                            continue;
                        }

                        // Create a new component if applicable.
                        currCmpntID = CreateNewComponent(componentCount, expression);

                        controlHelper                = expression.controllerVars[currCmpntID];
                        controlHelper.bone           = bone;
                        controlHelper.startTform     = ConvertBoneToTform(bone);
                        controlHelper.endTform       = oneClickBoneComponent.max;
                        controlHelper.fracRot        = oneClickBoneComponent.useRot;
                        controlHelper.fracPos        = oneClickBoneComponent.usePos;
                        controlHelper.fracScl        = oneClickBoneComponent.useScl;
                        controlHelper.inspIsSetStart = true;
                        controlHelper.inspIsSetEnd   = true;

                        component             = expression.components[currCmpntID];
                        component.controlType = ExpressionComponent.ControlType.Bone;

                        controlHelper.StoreBoneBase();
                        controlHelper.StoreStartTform();

                        ApplyCommonSettingsToComponent(component, oneClickComponent, currCmpntID);
                        componentCount++;                                 // good component created, update component count.

                        break;

                    case OneClickComponent.ComponentType.Animator:
                        var oneClickAnimatorComponent = (OneClickAnimatorComponent)oneClickComponent;

                        var animator = FindAnimator(oneClickAnimatorComponent.componentSearchName);
                        if (animator == null)
                        {
                            Debug.LogWarning("Could not find Animator: " + oneClickAnimatorComponent.componentSearchName);
                            continue;
                        }

                        // Create a new component if applicable.
                        currCmpntID = CreateNewComponent(componentCount, expression);

                        controlHelper          = expression.controllerVars[currCmpntID];
                        controlHelper.animator = animator;
                        controlHelper.isTriggerParameterBiDirectional = oneClickAnimatorComponent.isTriggerParmBiDirectional;
                        controlHelper.blendIndex = oneClickAnimatorComponent.animationParmIndex;

                        component             = expression.components[currCmpntID];
                        component.controlType = ExpressionComponent.ControlType.Animator;

                        ApplyCommonSettingsToComponent(component, oneClickComponent, currCmpntID);
                        componentCount++;                                 // good component created, update component count.

                        break;
                    }
                }

                // if no component was created for this expression, remove it.
                if (componentCount == 0)
                {
                    Debug.Log("Removed expression " + expression.name + " This may be OK, but may indicate a change in the model generator. If this is a supported model, contact Crazy Minnow Studio via [email protected].");
                    switch (configuration.type)
                    {
                    case OneClickConfiguration.ConfigType.Salsa:
                        salsa.visemes.RemoveAt(salsa.visemes.Count - 1);
                        break;

                    case OneClickConfiguration.ConfigType.Emoter:
                        emoter.emotes.RemoveAt(emoter.emotes.Count - 1);
                        break;
                    }
                }

                // module-specific wrap-up
                switch (configuration.type)
                {
                case OneClickConfiguration.ConfigType.Salsa:
                    salsa.DistributeTriggers(LerpEasings.EasingType.SquaredIn);
                    break;
                }
            }
        }
Пример #6
0
 protected static void NewConfiguration(OneClickConfiguration.ConfigType configType)
 {
     oneClickConfigurations.Add(new OneClickConfiguration(configType));
     currentConfiguration = oneClickConfigurations[oneClickConfigurations.Count - 1];
 }