Exemple #1
0
        static private void DiscardRotationModification(RotationModification rotationModification, ref List <UndoPropertyModification> discardedModifications)
        {
            if (rotationModification.x.currentValue != null)
            {
                discardedModifications.Add(rotationModification.x);
            }
            if (rotationModification.y.currentValue != null)
            {
                discardedModifications.Add(rotationModification.y);
            }
            if (rotationModification.z.currentValue != null)
            {
                discardedModifications.Add(rotationModification.z);
            }
            if (rotationModification.w.currentValue != null)
            {
                discardedModifications.Add(rotationModification.w);
            }

            if (rotationModification.eulerX.currentValue != null)
            {
                discardedModifications.Add(rotationModification.eulerX);
            }
            if (rotationModification.eulerY.currentValue != null)
            {
                discardedModifications.Add(rotationModification.eulerY);
            }
            if (rotationModification.eulerZ.currentValue != null)
            {
                discardedModifications.Add(rotationModification.eulerZ);
            }
        }
Exemple #2
0
        static private UndoPropertyModification[] FilterRotationModifications(IAnimationRecordingState state, ref Dictionary <object, RotationModification> rotationModifications)
        {
            GameObject rootGameObject = state.activeRootGameObject;

            List <object> itemsToRemove = new List <object>();

            List <UndoPropertyModification> discardedModifications = new List <UndoPropertyModification>();

            foreach (KeyValuePair <object, RotationModification> item in rotationModifications)
            {
                RotationModification m = item.Value;

                if (state.DiscardModification(m.lastQuatModification.currentValue))
                {
                    DiscardRotationModification(m, ref discardedModifications);
                    itemsToRemove.Add(item.Key);
                    continue;
                }

                EditorCurveBinding binding = new EditorCurveBinding();
                Type type = AnimationUtility.PropertyModificationToEditorCurveBinding(m.lastQuatModification.currentValue, rootGameObject, out binding);
                if (type == null)
                {
                    DiscardRotationModification(m, ref discardedModifications);
                    itemsToRemove.Add(item.Key);
                }
            }

            foreach (var key in itemsToRemove)
            {
                rotationModifications.Remove(key);
            }

            return(discardedModifications.ToArray());
        }
Exemple #3
0
        static private void CollectRotationModifications(IAnimationRecordingState state, ref UndoPropertyModification[] modifications,
                                                         ref System.Collections.Generic.Dictionary <object, RotationModification> rotationModifications)
        {
            List <UndoPropertyModification> outModifs = new List <UndoPropertyModification>();

            foreach (var modification in modifications)
            {
                PropertyModification prop = modification.previousValue;
                if (!(prop.target is Transform))
                {
                    outModifs.Add(modification);
                    continue;
                }

                EditorCurveBinding binding = new EditorCurveBinding();
                AnimationUtility.PropertyModificationToEditorCurveBinding(prop, state.activeRootGameObject, out binding);
                if (binding.propertyName.StartsWith(kLocalRotation))
                {
                    RotationModification rotationModification;

                    if (!rotationModifications.TryGetValue(prop.target, out rotationModification))
                    {
                        rotationModification = new RotationModification();
                        rotationModifications[prop.target] = rotationModification;
                    }

                    if (binding.propertyName.EndsWith("x"))
                    {
                        rotationModification.x = modification;
                    }
                    else if (binding.propertyName.EndsWith("y"))
                    {
                        rotationModification.y = modification;
                    }
                    else if (binding.propertyName.EndsWith("z"))
                    {
                        rotationModification.z = modification;
                    }
                    else if (binding.propertyName.EndsWith("w"))
                    {
                        rotationModification.w = modification;
                    }

                    rotationModification.lastQuatModification = modification;
                }
                else if (prop.propertyPath.StartsWith(kLocalEulerAnglesHint))
                {
                    RotationModification rotationModification;

                    if (!rotationModifications.TryGetValue(prop.target, out rotationModification))
                    {
                        rotationModification = new RotationModification();
                        rotationModifications[prop.target] = rotationModification;
                    }

                    rotationModification.useEuler = true;

                    if (prop.propertyPath.EndsWith("x"))
                    {
                        rotationModification.eulerX = modification;
                    }
                    else if (prop.propertyPath.EndsWith("y"))
                    {
                        rotationModification.eulerY = modification;
                    }
                    else if (prop.propertyPath.EndsWith("z"))
                    {
                        rotationModification.eulerZ = modification;
                    }
                }
                else
                {
                    outModifs.Add(modification);
                }
            }

            if (rotationModifications.Count > 0)
            {
                modifications = outModifs.ToArray();
            }
        }
Exemple #4
0
        static private void ProcessAnimatorModifications(IAnimationRecordingState state,
                                                         ref System.Collections.Generic.Dictionary <object, Vector3Modification> positionModifications,
                                                         ref System.Collections.Generic.Dictionary <object, RotationModification> rotationModifications,
                                                         ref System.Collections.Generic.Dictionary <object, Vector3Modification> scaleModifications)
        {
            System.Collections.Generic.Dictionary <object, RootMotionModification> rootMotionModifications = new Dictionary <object, RootMotionModification>();

            AnimationClip clip     = state.activeAnimationClip;
            GameObject    root     = state.activeRootGameObject;
            Animator      animator = root.GetComponent <Animator>();

            bool isHuman         = animator != null ? animator.isHuman : false;
            bool hasRootMotion   = animator != null ? animator.hasRootMotion : false;
            bool applyRootMotion = animator != null ? animator.applyRootMotion : false;

            // process animator positions
            List <object> discardListPos = new List <object>();

            foreach (KeyValuePair <object, Vector3Modification> item in positionModifications)
            {
                Vector3Modification m      = item.Value;
                Transform           target = item.Key as Transform;

                if (target == null)
                {
                    continue;
                }

                EditorCurveBinding binding = new EditorCurveBinding();
                Type type = AnimationUtility.PropertyModificationToEditorCurveBinding(m.last.currentValue, state.activeRootGameObject, out binding);
                if (type == null)
                {
                    continue;
                }

                bool isRootTransform = root.transform == target;
                bool isRootMotion    = (isHuman || hasRootMotion || applyRootMotion) && isRootTransform;
                bool isHumanBone     = isHuman && !isRootTransform && animator.IsBoneTransform(target);

                if (isHumanBone)
                {
                    Debug.LogWarning("Keyframing translation on humanoid rig is not supported!", target as Transform);
                    discardListPos.Add(item.Key);
                }
                else if (isRootMotion)
                {
                    RootMotionModification rootMotionModification;

                    if (!rootMotionModifications.TryGetValue(target, out rootMotionModification))
                    {
                        rootMotionModification          = new RootMotionModification();
                        rootMotionModifications[target] = rootMotionModification;
                    }

                    rootMotionModification.lastP = m.last;
                    rootMotionModification.px    = m.x;
                    rootMotionModification.py    = m.y;
                    rootMotionModification.pz    = m.z;

                    discardListPos.Add(item.Key);
                }
            }

            foreach (object key in discardListPos)
            {
                positionModifications.Remove(key);
            }

            // process animator rotation
            List <object> discardListRot = new List <object>();

            foreach (KeyValuePair <object, RotationModification> item in rotationModifications)
            {
                RotationModification m      = item.Value;
                Transform            target = item.Key as Transform;

                if (target == null)
                {
                    continue;
                }

                EditorCurveBinding binding = new EditorCurveBinding();
                Type type = AnimationUtility.PropertyModificationToEditorCurveBinding(m.lastQuatModification.currentValue, state.activeRootGameObject, out binding);
                if (type == null)
                {
                    continue;
                }

                bool isRootTransform = root.transform == target;
                bool isRootMotion    = (isHuman || hasRootMotion || applyRootMotion) && isRootTransform;
                bool isHumanBone     = isHuman && !isRootTransform && animator.IsBoneTransform(target);

                if (isHumanBone)
                {
                    Debug.LogWarning("Keyframing rotation on humanoid rig is not supported!", target as Transform);
                    discardListRot.Add(item.Key);
                }
                else if (isRootMotion)
                {
                    RootMotionModification rootMotionModification;

                    if (!rootMotionModifications.TryGetValue(target, out rootMotionModification))
                    {
                        rootMotionModification          = new RootMotionModification();
                        rootMotionModifications[target] = rootMotionModification;
                    }

                    rootMotionModification.lastR = m.lastQuatModification;
                    rootMotionModification.rx    = m.x;
                    rootMotionModification.ry    = m.y;
                    rootMotionModification.rz    = m.z;
                    rootMotionModification.rw    = m.w;

                    discardListRot.Add(item.Key);
                }
            }

            foreach (object key in discardListRot)
            {
                rotationModifications.Remove(key);
            }

            // process animator scales
            List <object> discardListScale = new List <object>();

            foreach (KeyValuePair <object, Vector3Modification> item in scaleModifications)
            {
                Vector3Modification m      = item.Value;
                Transform           target = item.Key as Transform;

                if (target == null)
                {
                    continue;
                }

                EditorCurveBinding binding = new EditorCurveBinding();
                Type type = AnimationUtility.PropertyModificationToEditorCurveBinding(m.last.currentValue, state.activeRootGameObject, out binding);
                if (type == null)
                {
                    continue;
                }

                bool isRootTransform = root.transform == target;
                bool isHumanBone     = isHuman && !isRootTransform && animator.IsBoneTransform(target);
                if (isHumanBone)
                {
                    Debug.LogWarning("Keyframing scale on humanoid rig is not supported!", target as Transform);
                    discardListScale.Add(item.Key);
                }
            }

            foreach (object key in discardListScale)
            {
                scaleModifications.Remove(key);
            }

            ProcessRootMotionModifications(state, ref rootMotionModifications);
        }
Exemple #5
0
        static private void ProcessRotationModifications(IAnimationRecordingState state, ref System.Collections.Generic.Dictionary <object, RotationModification> rotationModifications)
        {
            AnimationClip clip = state.activeAnimationClip;
            GameObject    root = state.activeRootGameObject;

            foreach (KeyValuePair <object, RotationModification> item in rotationModifications)
            {
                RotationModification m      = item.Value;
                Transform            target = item.Key as Transform;

                if (target == null)
                {
                    continue;
                }

                EditorCurveBinding binding = new EditorCurveBinding();
                Type type = AnimationUtility.PropertyModificationToEditorCurveBinding(m.lastQuatModification.currentValue, state.activeRootGameObject, out binding);
                if (type == null)
                {
                    continue;
                }

                AddRotationPropertyModification(state, binding, m.x);
                AddRotationPropertyModification(state, binding, m.y);
                AddRotationPropertyModification(state, binding, m.z);
                AddRotationPropertyModification(state, binding, m.w);

                Quaternion previousValue = target.localRotation;
                Quaternion currentValue  = target.localRotation;

                object x, y, z, w;
                if (ValueFromPropertyModification(m.x.previousValue, binding, out x))
                {
                    previousValue.x = (float)x;
                }
                if (ValueFromPropertyModification(m.y.previousValue, binding, out y))
                {
                    previousValue.y = (float)y;
                }
                if (ValueFromPropertyModification(m.z.previousValue, binding, out z))
                {
                    previousValue.z = (float)z;
                }
                if (ValueFromPropertyModification(m.w.previousValue, binding, out w))
                {
                    previousValue.w = (float)w;
                }

                if (ValueFromPropertyModification(m.x.currentValue, binding, out x))
                {
                    currentValue.x = (float)x;
                }
                if (ValueFromPropertyModification(m.y.currentValue, binding, out y))
                {
                    currentValue.y = (float)y;
                }
                if (ValueFromPropertyModification(m.z.currentValue, binding, out z))
                {
                    currentValue.z = (float)z;
                }
                if (ValueFromPropertyModification(m.w.currentValue, binding, out w))
                {
                    currentValue.w = (float)w;
                }

                // Favour euler hints if one or more exist on any axis.
                if (m.useEuler)
                {
                    AddRotationPropertyModification(state, binding, m.eulerX);
                    AddRotationPropertyModification(state, binding, m.eulerY);
                    AddRotationPropertyModification(state, binding, m.eulerZ);

                    Vector3 previousEulerAngles = target.GetLocalEulerAngles(RotationOrder.OrderZXY);
                    Vector3 currentEulerAngles  = previousEulerAngles;

                    object eulerX, eulerY, eulerZ;
                    if (ValueFromPropertyModification(m.eulerX.previousValue, binding, out eulerX))
                    {
                        previousEulerAngles.x = (float)eulerX;
                    }
                    if (ValueFromPropertyModification(m.eulerY.previousValue, binding, out eulerY))
                    {
                        previousEulerAngles.y = (float)eulerY;
                    }
                    if (ValueFromPropertyModification(m.eulerZ.previousValue, binding, out eulerZ))
                    {
                        previousEulerAngles.z = (float)eulerZ;
                    }

                    if (ValueFromPropertyModification(m.eulerX.currentValue, binding, out eulerX))
                    {
                        currentEulerAngles.x = (float)eulerX;
                    }
                    if (ValueFromPropertyModification(m.eulerY.currentValue, binding, out eulerY))
                    {
                        currentEulerAngles.y = (float)eulerY;
                    }
                    if (ValueFromPropertyModification(m.eulerZ.currentValue, binding, out eulerZ))
                    {
                        currentEulerAngles.z = (float)eulerZ;
                    }

                    // Fallback to quaternion euler values if euler hint and quaternion are out of sync.
                    previousEulerAngles = AnimationUtility.GetClosestEuler(previousValue, previousEulerAngles, RotationOrder.OrderZXY);
                    currentEulerAngles  = AnimationUtility.GetClosestEuler(currentValue, currentEulerAngles, RotationOrder.OrderZXY);

                    AddRotationKey(state, binding, type, previousEulerAngles, currentEulerAngles);
                }
                else
                {
                    Vector3 eulerAngles = target.GetLocalEulerAngles(RotationOrder.OrderZXY);

                    Vector3 previousEulerAngles = AnimationUtility.GetClosestEuler(previousValue, eulerAngles, RotationOrder.OrderZXY);
                    Vector3 currentEulerAngles  = AnimationUtility.GetClosestEuler(currentValue, eulerAngles, RotationOrder.OrderZXY);

                    AddRotationKey(state, binding, type, previousEulerAngles, currentEulerAngles);
                }
            }
        }
Exemple #6
0
        private static void CollectRotationModifications(IAnimationRecordingState state, ref UndoPropertyModification[] modifications, ref Dictionary <object, RotationModification> rotationModifications)
        {
            List <UndoPropertyModification> list = new List <UndoPropertyModification>();

            foreach (UndoPropertyModification modification in modifications)
            {
                EditorCurveBinding   binding       = new EditorCurveBinding();
                PropertyModification previousValue = modification.previousValue;
                AnimationUtility.PropertyModificationToEditorCurveBinding(previousValue, state.activeRootGameObject, out binding);
                if (binding.propertyName.StartsWith("m_LocalRotation"))
                {
                    RotationModification modification3;
                    if (!rotationModifications.TryGetValue(previousValue.target, out modification3))
                    {
                        modification3 = new RotationModification();
                        rotationModifications[previousValue.target] = modification3;
                    }
                    if (binding.propertyName.EndsWith("x"))
                    {
                        modification3.x = modification;
                    }
                    else if (binding.propertyName.EndsWith("y"))
                    {
                        modification3.y = modification;
                    }
                    else if (binding.propertyName.EndsWith("z"))
                    {
                        modification3.z = modification;
                    }
                    else if (binding.propertyName.EndsWith("w"))
                    {
                        modification3.w = modification;
                    }
                    modification3.lastQuatModification = modification;
                }
                else if (previousValue.propertyPath.StartsWith("m_LocalEulerAnglesHint"))
                {
                    RotationModification modification4;
                    if (!rotationModifications.TryGetValue(previousValue.target, out modification4))
                    {
                        modification4 = new RotationModification();
                        rotationModifications[previousValue.target] = modification4;
                    }
                    modification4.useEuler = true;
                    if (previousValue.propertyPath.EndsWith("x"))
                    {
                        modification4.eulerX = modification;
                    }
                    else if (previousValue.propertyPath.EndsWith("y"))
                    {
                        modification4.eulerY = modification;
                    }
                    else if (previousValue.propertyPath.EndsWith("z"))
                    {
                        modification4.eulerZ = modification;
                    }
                }
                else
                {
                    list.Add(modification);
                }
            }
            if (rotationModifications.Count > 0)
            {
                modifications = list.ToArray();
            }
        }
Exemple #7
0
        private static void ProcessRotationModifications(IAnimationRecordingState state, ref UndoPropertyModification[] modifications)
        {
            Dictionary <object, RotationModification> rotationModifications = new Dictionary <object, RotationModification>();

            CollectRotationModifications(state, ref modifications, ref rotationModifications);
            foreach (KeyValuePair <object, RotationModification> pair in rotationModifications)
            {
                RotationModification modification = pair.Value;
                Transform            key          = pair.Key as Transform;
                if (key != null)
                {
                    EditorCurveBinding binding = new EditorCurveBinding();
                    System.Type        type    = AnimationUtility.PropertyModificationToEditorCurveBinding(modification.lastQuatModification.currentValue, state.activeRootGameObject, out binding);
                    if (type != null)
                    {
                        AddRotationPropertyModification(state, binding, modification.x);
                        AddRotationPropertyModification(state, binding, modification.y);
                        AddRotationPropertyModification(state, binding, modification.z);
                        AddRotationPropertyModification(state, binding, modification.w);
                        if (modification.useEuler)
                        {
                            object obj2;
                            object obj3;
                            object obj4;
                            AddRotationPropertyModification(state, binding, modification.eulerX);
                            AddRotationPropertyModification(state, binding, modification.eulerY);
                            AddRotationPropertyModification(state, binding, modification.eulerZ);
                            Vector3 localEulerAngles   = key.GetLocalEulerAngles(RotationOrder.OrderZXY);
                            Vector3 currentEulerAngles = key.GetLocalEulerAngles(RotationOrder.OrderZXY);
                            if (ValueFromPropertyModification(modification.eulerX.previousValue, binding, out obj2))
                            {
                                localEulerAngles.x = (float)obj2;
                            }
                            if (ValueFromPropertyModification(modification.eulerY.previousValue, binding, out obj3))
                            {
                                localEulerAngles.y = (float)obj3;
                            }
                            if (ValueFromPropertyModification(modification.eulerZ.previousValue, binding, out obj4))
                            {
                                localEulerAngles.z = (float)obj4;
                            }
                            if (ValueFromPropertyModification(modification.eulerX.currentValue, binding, out obj2))
                            {
                                currentEulerAngles.x = (float)obj2;
                            }
                            if (ValueFromPropertyModification(modification.eulerY.currentValue, binding, out obj3))
                            {
                                currentEulerAngles.y = (float)obj3;
                            }
                            if (ValueFromPropertyModification(modification.eulerZ.currentValue, binding, out obj4))
                            {
                                currentEulerAngles.z = (float)obj4;
                            }
                            AddRotationKey(state, binding, type, localEulerAngles, currentEulerAngles);
                        }
                        else
                        {
                            object     obj5;
                            object     obj6;
                            object     obj7;
                            object     obj8;
                            Quaternion localRotation = key.localRotation;
                            Quaternion quaternion2   = key.localRotation;
                            if (ValueFromPropertyModification(modification.x.previousValue, binding, out obj5))
                            {
                                localRotation.x = (float)obj5;
                            }
                            if (ValueFromPropertyModification(modification.y.previousValue, binding, out obj6))
                            {
                                localRotation.y = (float)obj6;
                            }
                            if (ValueFromPropertyModification(modification.z.previousValue, binding, out obj7))
                            {
                                localRotation.z = (float)obj7;
                            }
                            if (ValueFromPropertyModification(modification.w.previousValue, binding, out obj8))
                            {
                                localRotation.w = (float)obj8;
                            }
                            if (ValueFromPropertyModification(modification.x.currentValue, binding, out obj5))
                            {
                                quaternion2.x = (float)obj5;
                            }
                            if (ValueFromPropertyModification(modification.y.currentValue, binding, out obj6))
                            {
                                quaternion2.y = (float)obj6;
                            }
                            if (ValueFromPropertyModification(modification.z.currentValue, binding, out obj7))
                            {
                                quaternion2.z = (float)obj7;
                            }
                            if (ValueFromPropertyModification(modification.w.currentValue, binding, out obj8))
                            {
                                quaternion2.w = (float)obj8;
                            }
                            AddRotationKey(state, binding, type, localRotation.eulerAngles, quaternion2.eulerAngles);
                        }
                    }
                }
            }
        }
 private static void CollectRotationModifications(IAnimationRecordingState state, ref UndoPropertyModification[] modifications, ref Dictionary<object, RotationModification> rotationModifications)
 {
     List<UndoPropertyModification> list = new List<UndoPropertyModification>();
     foreach (UndoPropertyModification modification in modifications)
     {
         EditorCurveBinding binding = new EditorCurveBinding();
         PropertyModification previousValue = modification.previousValue;
         AnimationUtility.PropertyModificationToEditorCurveBinding(previousValue, state.activeRootGameObject, out binding);
         if (binding.propertyName.StartsWith("m_LocalRotation"))
         {
             RotationModification modification3;
             if (!rotationModifications.TryGetValue(previousValue.target, out modification3))
             {
                 modification3 = new RotationModification();
                 rotationModifications[previousValue.target] = modification3;
             }
             if (binding.propertyName.EndsWith("x"))
             {
                 modification3.x = modification;
             }
             else if (binding.propertyName.EndsWith("y"))
             {
                 modification3.y = modification;
             }
             else if (binding.propertyName.EndsWith("z"))
             {
                 modification3.z = modification;
             }
             else if (binding.propertyName.EndsWith("w"))
             {
                 modification3.w = modification;
             }
             modification3.lastQuatModification = modification;
         }
         else if (previousValue.propertyPath.StartsWith("m_LocalEulerAnglesHint"))
         {
             RotationModification modification4;
             if (!rotationModifications.TryGetValue(previousValue.target, out modification4))
             {
                 modification4 = new RotationModification();
                 rotationModifications[previousValue.target] = modification4;
             }
             modification4.useEuler = true;
             if (previousValue.propertyPath.EndsWith("x"))
             {
                 modification4.eulerX = modification;
             }
             else if (previousValue.propertyPath.EndsWith("y"))
             {
                 modification4.eulerY = modification;
             }
             else if (previousValue.propertyPath.EndsWith("z"))
             {
                 modification4.eulerZ = modification;
             }
         }
         else
         {
             list.Add(modification);
         }
     }
     if (rotationModifications.Count > 0)
     {
         modifications = list.ToArray();
     }
 }