Ejemplo n.º 1
0
 public static void  CheckForAddKeyFromCurveEditor(SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams, SubstanceFlickerParams flickerValues)
 {
     for (int i = 0; i <= animationParams.substanceCurveBackup.keys.Count() - 1; i++)
     {
         if (i <= animationParams.substanceCurve.keys.Count() - 1 && animationParams.substanceCurve.keys[i].time != animationParams.substanceCurveBackup.keys[i].time) // find keyframe that has just been created or deleted in the curve editor
         {
             if (animationParams.substanceCurve.keys.Count() > animationParams.substanceCurveBackup.keys.Count())
             {
                 animationParams.substanceCurve.MoveKey(i, new Keyframe(animationParams.substanceCurve.keys[i].time, animationParams.substanceCurve.keys[i].time)); // lerp does not work correctly if the keyframe value is different than the time. i cant edit the key so i delete then add a new one
                 float tempKeyframeTime = animationParams.substanceCurve.keys[i].time;
                 SubstanceTweenSetParameterUtility.SetProceduralMaterialBasedOnAnimationTime(ref tempKeyframeTime, substanceMaterialParams, animationParams, substanceToolParams, flickerValues);
                 SubstanceTweenKeyframeUtility.InsertKeyframe(i, substanceMaterialParams, animationParams, substanceToolParams);
                 SubstanceTweenKeyframeUtility.SelectKeyframe(i, substanceMaterialParams, animationParams, substanceToolParams);
                 animationParams.currentAnimationTime      = 0;
                 animationParams.substanceCurveBackup.keys = animationParams.substanceCurve.keys;
                 SubstanceTweenAnimationUtility.CalculateAnimationLength(substanceMaterialParams, animationParams);
                 return;
             }
         }
     }
 }
Ejemplo n.º 2
0
    public static void CheckForRemoveOrEditFromCurveEditor(SubstanceMaterialParams substanceMaterialParams, SubstanceAnimationParams animationParams, SubstanceToolParams substanceToolParams, SubstanceFlickerParams flickerValues)
    {
        bool         inEditKeysMode                     = false;
        int          keyframesModifiedSoFar             = 0;                                                                                               //number of keyframes deleted edited so far
        int          curvePointsCountDifference         = animationParams.substanceCurveBackup.keys.Count() - animationParams.substanceCurve.keys.Count(); // difference between number of points before the change compared to the number of points after the change
        List <float> BackupKeyframePointTimes           = new List <float>();                                                                              // points on curve before change
        List <float> CurrentKeyframePointTimes          = new List <float>();                                                                              // points on curve after change
        Keyframe     firstEditedKeyframeBeforeEdit      = new Keyframe(-1, -1);                                                                            //the first keyframe in the list that has been edited ore deleted
        int          firstEditedKeyframeIndexBeforeEdit = -1;                                                                                              // index of the first edited keyframe

        if (animationParams.substanceCurve.keys[0].time != 0)
        {
            animationParams.substanceCurve.keys[0].time = 0;
        }
        for (int i = 0; i <= animationParams.substanceCurveBackup.keys.Count() - 1; i++)
        {
            BackupKeyframePointTimes.Add(animationParams.substanceCurveBackup.keys[i].time);
        }
        for (int i = 0; i <= animationParams.substanceCurve.keys.Count() - 1; i++)
        {
            CurrentKeyframePointTimes.Add(animationParams.substanceCurve.keys[i].time);
        }

        for (int i = 0; i <= BackupKeyframePointTimes.Count() - 2; i++)
        {
            if (!CurrentKeyframePointTimes.Contains(BackupKeyframePointTimes[i]))
            { // find index of the first key that has ben edited using context menu
                firstEditedKeyframeBeforeEdit = animationParams.substanceCurveBackup.keys[i];
                float tempKeyframeTime = firstEditedKeyframeBeforeEdit.time;
                firstEditedKeyframeIndexBeforeEdit = i;
                SubstanceTweenSetParameterUtility.SetProceduralMaterialBasedOnAnimationTime(ref tempKeyframeTime, substanceMaterialParams, animationParams, substanceToolParams, flickerValues);
                break;
            }
        }

        for (int i = 0; i <= CurrentKeyframePointTimes.Count() - 2; i++)
        {
            if (!BackupKeyframePointTimes.Contains(CurrentKeyframePointTimes[i]))
            {// if  i use the context menu to edit multiple keyframes to a value that is not already on the graph i can find that new keyframe here.
             // I can tell when i have EDITED a keyframe to a new value because when deleting keyframes, every new point's time should also exist in the backup
                inEditKeysMode = true;
                float tempKeyframeTime = firstEditedKeyframeBeforeEdit.time;
                SubstanceTweenSetParameterUtility.SetProceduralMaterialBasedOnAnimationTime(ref tempKeyframeTime, substanceMaterialParams, animationParams, substanceToolParams, flickerValues); // find/set material based on first edited keyframe
                if (firstEditedKeyframeIndexBeforeEdit != -1)                                                                                                                                    // if multiple keyframes has been edited using context menu
                {
                    SubstanceTweenKeyframeUtility.OverWriteKeyframe(firstEditedKeyframeIndexBeforeEdit, substanceMaterialParams, animationParams, substanceToolParams);                          // overwrite new keyframe with material of the first edited keyframe
                }
            }
        }

        for (int i = BackupKeyframePointTimes.Count() - 1; i > 0; i--)            // Go through every key in the backup list(Before the keys got deleted)
        {
            if (!CurrentKeyframePointTimes.Contains(BackupKeyframePointTimes[i])) // if the current list of curve points does not contain this value(it was deleted in the curve editor)
            {                                                                     //Find the index of the value and delete any information that has not already been deleted in the curve editor
               // get the index of the deleted point and delete the Dictionary/List associated with that index
                keyframesModifiedSoFar++;
                animationParams.keyFrameTimes.RemoveAt(BackupKeyframePointTimes.IndexOf(BackupKeyframePointTimes[i]));
                substanceMaterialParams.MaterialVariableKeyframeList.RemoveAt(BackupKeyframePointTimes.IndexOf(BackupKeyframePointTimes[i]));
                substanceMaterialParams.MaterialVariableKeyframeDictionaryList.RemoveAt(BackupKeyframePointTimes.IndexOf(BackupKeyframePointTimes[i]));
                if (animationParams.keyFrames > 0)
                {
                    animationParams.keyFrames--;
                }
            }
            if (inEditKeysMode && i == 1 && keyframesModifiedSoFar > 0)
            { // if i edited multiple keyframes at the same time using the context menu I insert a keyframe when i reach the end of the for loop
                SubstanceTweenKeyframeUtility.InsertKeyframe(i, substanceMaterialParams, animationParams, substanceToolParams);
            }
        }
        for (int i = 0; i <= animationParams.substanceCurve.keys.Count() - 2; i++)
        {                                                                                                                                     // rebuild/refresh animation times
            animationParams.keyFrameTimes[i] = animationParams.substanceCurve.keys[i + 1].time - animationParams.substanceCurve.keys[i].time; // this keyframe time = (next keyframe time - This keyframe time)
            substanceMaterialParams.MaterialVariableKeyframeList[i].animationTime = animationParams.substanceCurve.keys[i + 1].time - animationParams.substanceCurve.keys[i].time;
        }

        if (curvePointsCountDifference != keyframesModifiedSoFar)
        { // Because curvePoint EditDifference != keyframes Edited/changed, I know that keyframes have been changed with 'Edit Keys..' and not 'Delete'
          // when editing multipule keyframes to a new singular time that is not already on the list,
          // there should always be more edited keyframes then the difference between current curve points and backup curve points.
            if (animationParams.substanceCurve.keys[animationParams.substanceCurve.keys.Count() - 1].time > animationParams.substanceCurveBackup.keys[animationParams.substanceCurveBackup.keys.Count() - 1].time)
            {// Edited multiple keyframes to a new time that is more than the length of the backup curve
                SubstanceTweenKeyframeUtility.CreateKeyframe(substanceMaterialParams, animationParams, substanceToolParams);
            }
        }
        animationParams.substanceCurveBackup.keys = animationParams.substanceCurve.keys;
        SubstanceTweenAnimationUtility.CalculateAnimationLength(substanceMaterialParams, animationParams);
        inEditKeysMode = false;
    }