示例#1
0
        static Preferences()
        {
            m_BakeToConstraintCurveFilterOptions = new CurveFilterOptions()
            {
                unrollRotation    = EditorPrefs.GetBool(k_BakeToConstraintPrefix + k_UnrollRotation, true),
                keyframeReduction = EditorPrefs.GetBool(k_BakeToConstraintPrefix + k_KeyReduceSuffix, true),
                positionError     = EditorPrefs.GetFloat(k_BakeToConstraintPrefix + k_KeyReducePositionErrorSuffix, 0.5f),
                rotationError     = EditorPrefs.GetFloat(k_BakeToConstraintPrefix + k_KeyReduceRotationErrorSuffix, 0.5f),
                scaleError        = EditorPrefs.GetFloat(k_BakeToConstraintPrefix + k_KeyReduceScaleErrorSuffix, 0.5f),
                floatError        = EditorPrefs.GetFloat(k_BakeToConstraintPrefix + k_KeyReduceFloatErrorSuffix, 0.5f)
            };

            m_BakeToSkeletonCurveFilterOptions = new CurveFilterOptions()
            {
                unrollRotation    = EditorPrefs.GetBool(k_BakeToSkeletonPrefix + k_UnrollRotation, true),
                keyframeReduction = EditorPrefs.GetBool(k_BakeToSkeletonPrefix + k_KeyReduceSuffix, true),
                positionError     = EditorPrefs.GetFloat(k_BakeToSkeletonPrefix + k_KeyReducePositionErrorSuffix, 0.5f),
                rotationError     = EditorPrefs.GetFloat(k_BakeToSkeletonPrefix + k_KeyReduceRotationErrorSuffix, 0.5f),
                scaleError        = EditorPrefs.GetFloat(k_BakeToSkeletonPrefix + k_KeyReduceScaleErrorSuffix, 0.5f),
                floatError        = EditorPrefs.GetFloat(k_BakeToSkeletonPrefix + k_KeyReduceFloatErrorSuffix, 0.5f)
            };

            m_BakeToConstraintAndRemoveCurves = EditorPrefs.GetBool(k_BakeToConstraintPrefix + k_RemoveCurvesSuffix, false);
            m_BakeToSkeletonAndRemoveCurves   = EditorPrefs.GetBool(k_BakeToSkeletonPrefix + k_RemoveCurvesSuffix, false);

            m_ForceConstraintWeightOnBake = EditorPrefs.GetBool(k_Prefix + k_ForceWeightSuffix, true);
        }
示例#2
0
        public static void SetDefaultValues()
        {
            var defaultOptions = new CurveFilterOptions()
            {
                unrollRotation    = true,
                keyframeReduction = true,
                positionError     = .5f,
                rotationError     = .5f,
                scaleError        = .5f,
                floatError        = .5f
            };

            bakeToConstraintCurveFilterOptions = defaultOptions;
            bakeToSkeletonCurveFilterOptions   = defaultOptions;

            bakeToConstraintAndRemoveCurves = false;
            bakeToSkeletonAndRemoveCurves   = false;

            forceConstraintWeightOnBake = true;
        }
示例#3
0
        private static void BakeCurvesToClip(AnimationClip clip, IEnumerable <EditorCurveBinding> bindings, RigBuilder rigBuilder, IEvaluationGraph graph, CurveFilterOptions filterOptions)
        {
            if (rigBuilder == null)
            {
                throw new ArgumentNullException("It is not possible to bake curves without an RigBuilder.");
            }

            if (clip == null)
            {
                throw new ArgumentNullException("It is not possible to bake curves to a clip that is null.");
            }

            if (!AnimationMode.InAnimationMode())
            {
                throw new ArgumentException("AnimationMode must be active during bake operation.");
            }

            var animator = rigBuilder.GetComponent <Animator>();

            var recorder = new GameObjectRecorder(animator.gameObject);

            foreach (var binding in bindings)
            {
                recorder.Bind(binding);
            }

            var   frameCount = (int)(clip.length * clip.frameRate);
            float dt         = 1f / clip.frameRate;
            float time       = 0f;

            graph?.Evaluate(0f);
            recorder.TakeSnapshot(0f);

            for (int frame = 1; frame <= frameCount; ++frame)
            {
                time = frame / clip.frameRate;
                graph?.Evaluate(time);
                recorder.TakeSnapshot(dt);
            }

            var tempClip = new AnimationClip();

            recorder.SaveToClip(tempClip, clip.frameRate, filterOptions);
            CopyCurvesToClip(tempClip, clip);
        }
示例#4
0
        private static void BakeToConstraint(RigBuilder rigBuilder, IRigConstraint constraint, AnimationClip clip, AnimationClip defaultPoseClip, IEnumerable <EditorCurveBinding> bindings, CurveFilterOptions filterOptions)
        {
            // Make sure the base constraint is valid
            if (constraint == null || !constraint.IsValid())
            {
                throw new InvalidOperationException(
                          string.Format("The rig constraint {0} is not a valid constraint.",
                                        constraint != null ? constraint.ToString() : ""));
            }

            // Check if the constraint is inverse solvable
            var inverseConstraint = FindInverseRigConstraint(constraint);

            if (inverseConstraint == null)
            {
                throw new InvalidOperationException(
                          string.Format("No inverse rig constraint could be found for {0}.",
                                        constraint.ToString()));
            }
            else if (!inverseConstraint.IsValid())
            {
                throw new InvalidOperationException(
                          string.Format("The inverse rig constrain {1} for {0} is not a valid constraint.",
                                        constraint.ToString(),
                                        inverseConstraint.ToString()));
            }

            var overrides = new Dictionary <IRigConstraint, IRigConstraint>();

            overrides.Add(constraint, inverseConstraint);

            using (var graph = new EvaluationGraph(rigBuilder, clip, defaultPoseClip, overrides, constraint))
            {
                BakeCurvesToClip(clip, bindings, rigBuilder, graph, filterOptions);
            }
        }
示例#5
0
        internal static void BakeToConstraint <T>(T constraint, AnimationClip clip, AnimationClip defaultPoseClip, IEnumerable <EditorCurveBinding> bindings, CurveFilterOptions filterOptions)
            where T : MonoBehaviour, IRigConstraint
        {
            // Make sure we have a rigbuilder (which guarantees an animator).
            var rigBuilder = constraint.GetComponentInParent <RigBuilder>();

            if (rigBuilder == null)
            {
                throw new InvalidOperationException(
                          "No rigbuilder was found in the hierarchy. " +
                          "A RigBuilder and Animator are required to construct valid bindings.");
            }

            BakeToConstraint(rigBuilder, constraint, clip, defaultPoseClip, bindings, filterOptions);
        }
示例#6
0
        private static void BakeToSkeleton(RigBuilder rigBuilder, IRigConstraint constraint, AnimationClip clip, AnimationClip defaultPoseClip, IEnumerable <EditorCurveBinding> bindings, CurveFilterOptions filterOptions)
        {
            // Make sure the base constraint is valid
            if (constraint == null || !constraint.IsValid())
            {
                throw new InvalidOperationException(
                          string.Format("The rig constraint {0} is not a valid constraint.",
                                        constraint != null ? constraint.ToString() : ""));
            }

            var overrides = new Dictionary <IRigConstraint, IRigConstraint>();

            using (var graph = new EvaluationGraph(rigBuilder, clip, defaultPoseClip, overrides, constraint))
            {
                BakeCurvesToClip(clip, bindings, rigBuilder, graph, filterOptions);
            }
        }