コード例 #1
0
        private void ProcessDenses(Clip clip, AnimationClipBindingConstant bindings, IReadOnlyDictionary <uint, string> tos)
        {
            DenseClip dense       = clip.DenseClip;
            int       streamCount = clip.StreamedClip.CurveCount;

            float[] slopeValues = new float[4];             // no slopes - 0 values
            for (int frameIndex = 0; frameIndex < dense.FrameCount; frameIndex++)
            {
                float time        = frameIndex / dense.SampleRate;
                int   frameOffset = frameIndex * dense.CurveCount;
                for (int curveIndex = 0; curveIndex < dense.CurveCount;)
                {
                    int            index         = streamCount + curveIndex;
                    GenericBinding binding       = bindings.FindBinding(index);
                    string         path          = GetCurvePath(tos, binding.Path);
                    int            framePosition = frameOffset + curveIndex;
                    if (binding.IsTransform)
                    {
                        AddTransformCurve(time, binding.TransformType, dense.SampleArray, slopeValues, slopeValues, framePosition, path);
                        curveIndex += binding.TransformType.GetDimension();
                    }
                    else if (binding.CustomType == BindingCustomType.None)
                    {
                        AddDefaultCurve(binding, path, time, dense.SampleArray[framePosition]);
                        curveIndex++;
                    }
                    else
                    {
                        AddCustomCurve(bindings, binding, path, time, dense.SampleArray[framePosition]);
                        curveIndex++;
                    }
                }
            }
        }
コード例 #2
0
 private void AddGameObjectCurve(GenericBinding binding, string path, float time, float value)
 {
     if (binding.Attribute == CRC.CalculateDigestAscii(GameObject.IsActiveName))
     {
         FloatCurve curve = new FloatCurve(path, GameObject.IsActiveName, ClassIDType.GameObject, default);
         AddFloatKeyframe(curve, time, value);
         return;
     }
     throw new Exception($"Unsupported attribute {binding.Attribute} for {nameof(GameObject)}");
 }
コード例 #3
0
        private void ProcessStreams(IReadOnlyList <StreamedFrame> streamFrames, AnimationClipBindingConstant bindings, IReadOnlyDictionary <uint, string> tos, float sampleRate)
        {
            float[] curveValues    = new float[4];
            float[] inSlopeValues  = new float[4];
            float[] outSlopeValues = new float[4];
            float   interval       = 1.0f / sampleRate;

            // first (index [0]) stream frame is for slope calculation for the first real frame (index [1])
            // last one (index [count - 1]) is +Infinity
            // it is made for slope processing, but we don't need them
            for (int frameIndex = 1; frameIndex < streamFrames.Count - 1; frameIndex++)
            {
                StreamedFrame frame = streamFrames[frameIndex];
                for (int curveIndex = 0; curveIndex < frame.Curves.Count;)
                {
                    StreamedCurveKey curve   = frame.Curves[curveIndex];
                    GenericBinding   binding = bindings.FindBinding(curve.Index);
                    GetPreviousFrame(streamFrames, curve.Index, frameIndex, out int prevFrameIndex, out int prevCurveIndex);

                    string path = GetCurvePath(tos, binding.Path);
                    if (binding.IsTransform)
                    {
                        int dimension = binding.TransformType.GetDimension();
                        for (int key = 0; key < dimension; key++)
                        {
                            StreamedCurveKey keyCurve     = frame.Curves[curveIndex];
                            StreamedFrame    prevFrame    = streamFrames[prevFrameIndex];
                            StreamedCurveKey prevKeyCurve = prevFrame.Curves[prevCurveIndex + key];
                            float            deltaTime    = frame.Time - prevFrame.Time;
                            curveValues[key]    = keyCurve.Value;
                            inSlopeValues[key]  = prevKeyCurve.CalculateNextInSlope(deltaTime, keyCurve.Value);
                            outSlopeValues[key] = keyCurve.OutSlope;
                            curveIndex          = GetNextCurve(frame, curveIndex);
                        }

                        AddTransformCurve(frame.Time, binding.TransformType, curveValues, inSlopeValues, outSlopeValues, 0, path);
                    }
                    else if (binding.CustomType == BindingCustomType.None)
                    {
                        AddDefaultCurve(binding, path, frame.Time, frame.Curves[curveIndex].Value);
                        curveIndex = GetNextCurve(frame, curveIndex);
                    }
                    else
                    {
                        AddCustomCurve(bindings, binding, path, frame.Time, frame.Curves[curveIndex].Value);
                        curveIndex = GetNextCurve(frame, curveIndex);
                    }
                }
            }
        }
コード例 #4
0
 private void AddGameObjectCurve(GenericBinding binding, string path, float time, float value)
 {
     if (binding.Attribute == CRC.CalculateDigestAscii(GameObject.IsActiveName))
     {
         FloatCurve curve = new FloatCurve(path, GameObject.IsActiveName, ClassIDType.GameObject, default);
         AddFloatKeyframe(curve, time, value);
         return;
     }
     else
     {
         // that means that dev exported animation clip with missed component
         FloatCurve curve = new FloatCurve(path, MissedPropertyPrefix + binding.Attribute, ClassIDType.GameObject, default);
         AddFloatKeyframe(curve, time, value);
     }
 }
コード例 #5
0
        private void AddDefaultCurve(GenericBinding binding, string path, float time, float value)
        {
            switch (binding.ClassID)
            {
            case ClassIDType.GameObject:
            {
                AddGameObjectCurve(binding, path, time, value);
            }
            break;

            case ClassIDType.MonoBehaviour:
            {
                AddScriptCurve(binding, path, time, value);
            }
            break;

            default:
                AddEngineCurve(binding, path, time, value);
                break;
            }
        }
コード例 #6
0
        private void AddCustomCurve(AnimationClipBindingConstant bindings, GenericBinding binding, string path, float time, float value)
        {
            switch (binding.CustomType)
            {
            case BindingCustomType.AnimatorMuscle:
                AddAnimatorMuscleCurve(binding, path, time, value);
                break;

            default:
                string attribute = m_customCurveResolver.ToAttributeName(binding.CustomType, binding.Attribute, path);
                if (binding.IsPPtrCurve)
                {
                    PPtrCurve curve = new PPtrCurve(path, attribute, binding.ClassID, binding.Script.CastTo <MonoScript>());
                    AddPPtrKeyframe(curve, bindings, time, (int)value);
                }
                else
                {
                    FloatCurve curve = new FloatCurve(path, attribute, binding.ClassID, binding.Script.CastTo <MonoScript>());
                    AddFloatKeyframe(curve, time, value);
                }
                break;
            }
        }
コード例 #7
0
        public GenericBinding FindBinding(int index)
        {
            int curves = 0;

            for (int i = 0; i < GenericBindings.Count; i++)
            {
                GenericBinding gb = GenericBindings[i];
                if (gb.ClassID == ClassIDType.Transform)
                {
                    curves += gb.TransformType.GetDimension();
                }
                else
                {
                    curves += 1;
                }

                if (curves > index)
                {
                    return(gb);
                }
            }
            throw new ArgumentException($"Binding with index {index} hasn't been found", nameof(index));
        }
コード例 #8
0
        private void ProcessConstant(Clip clip, AnimationClipBindingConstant bindings, IReadOnlyDictionary <uint, string> tos, float lastFrame)
        {
            ConstantClip constant    = clip.ConstantClip;
            int          streamCount = clip.StreamedClip.CurveCount;
            int          denseCount  = clip.DenseClip.CurveCount;

            float[] slopeValues = new float[4];             // no slopes - 0 values

            // only first and last frames
            float time = 0.0f;

            for (int i = 0; i < 2; i++, time += lastFrame)
            {
                for (int curveIndex = 0; curveIndex < constant.Constants.Count;)
                {
                    int            index   = streamCount + denseCount + curveIndex;
                    GenericBinding binding = bindings.FindBinding(index);
                    string         path    = GetCurvePath(tos, binding.Path);
                    if (binding.IsTransform)
                    {
                        AddTransformCurve(time, binding.TransformType, constant.Constants, slopeValues, slopeValues, curveIndex, path);
                        curveIndex += binding.TransformType.GetDimension();
                    }
                    else if (binding.CustomType == BindingCustomType.None)
                    {
                        AddDefaultCurve(binding, path, time, constant.Constants[curveIndex]);
                        curveIndex++;
                    }
                    else
                    {
                        AddCustomCurve(bindings, binding, path, time, constant.Constants[curveIndex]);
                        curveIndex++;
                    }
                }
            }
        }
コード例 #9
0
        private void AddAnimatorMuscleCurve(GenericBinding binding, string path, float time, float value)
        {
            FloatCurve curve = new FloatCurve(string.Empty, binding.GetHumanoidMuscle(Version).ToAttributeString(), ClassIDType.Animator, default);

            AddFloatKeyframe(curve, time, value);
        }
コード例 #10
0
        private void AddEngineCurve(GenericBinding binding, string path, float time, float value)
        {
#warning TODO:
            FloatCurve curve = new FloatCurve(path, TypeTreePropertyPrefix + binding.Attribute, binding.ClassID, default);
            AddFloatKeyframe(curve, time, value);
        }
コード例 #11
0
        private void AddScriptCurve(GenericBinding binding, string path, float time, float value)
        {
#warning TODO:
            FloatCurve curve = new FloatCurve(path, ScriptPropertyPrefix + binding.Attribute, ClassIDType.MonoBehaviour, binding.Script.CastTo <MonoScript>());
            AddFloatKeyframe(curve, time, value);
        }
コード例 #12
0
        private static bool GetGenericBinding(AnimationClipBindingConstant bindings, int index, out GenericBinding binding)
        {
            binding = bindings.FindBinding(index);
            if (binding.ClassID == ClassIDType.Transform)
            {
                return(true);
            }
#warning TODO: humanoid
            return(false);
        }
コード例 #13
0
 public AnimationClipBindingConstant(bool _)
 {
     m_genericBindings  = new GenericBinding[0];
     m_pptrCurveMapping = new PPtr <Object> [0];
 }