예제 #1
0
        private void ProcessConstant(Clip clip, AnimationClipBindingConstant bindings, IReadOnlyDictionary <uint, string> tos, int frameCount)
        {
            DenseClip    dense       = clip.DenseClip;
            ConstantClip constant    = clip.ConstantClip;
            int          streamCount = clip.StreamedClip.CurveCount;
            int          denseCount  = clip.DenseClip.CurveCount;

            // only first and last frames
            for (int frameIndex = 0; frameIndex < frameCount; frameIndex += (frameCount > 1 ? frameCount - 1 : 1))
            {
                float time = frameIndex / dense.SampleRate;
                for (int curveIndex = 0; curveIndex < constant.Constants.Count;)
                {
                    int index = streamCount + denseCount + curveIndex;
                    if (!GetGenericBinding(bindings, index, out GenericBinding binding))
                    {
                        curveIndex++;
                        continue;
                    }

                    string path = GetCurvePath(tos, binding.Path);
                    AddComplexCurve(time, binding.BindingType, constant.Constants, curveIndex, path);
                    curveIndex += binding.BindingType.GetDimension();
                }
            }
        }
예제 #2
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;
                    if (!GetGenericBinding(bindings, index, out GenericBinding binding))
                    {
                        curveIndex++;
                        continue;
                    }

                    string path = GetCurvePath(tos, binding.Path);
                    AddComplexCurve(time, binding.BindingType, dense.SampleArray, slopeValues, slopeValues, frameOffset + curveIndex, path);
                    curveIndex += binding.BindingType.GetDimension();
                }
            }
        }
예제 #3
0
        private void ProcessStreams(IReadOnlyList <StreamedFrame> streamFrames, AnimationClipBindingConstant bindings, IReadOnlyDictionary <uint, string> tos)
        {
            float[] curveValues = new float[4];
            for (int frameIndex = 1; frameIndex < streamFrames.Count - 2; frameIndex++)
            {
                StreamedFrame frame = streamFrames[frameIndex];
                for (int curveIndex = 0; curveIndex < frame.Curves.Count;)
                {
                    StreamedCurveKey curve = frame.Curves[curveIndex];
                    if (!GetGenericBinding(bindings, curve.Index, out GenericBinding binding))
                    {
                        curveIndex++;
                        continue;
                    }

                    string path      = GetCurvePath(tos, binding.Path);
                    int    dimension = binding.BindingType.GetDimension();
                    for (int key = 0; key < dimension; key++)
                    {
                        curveValues[key] = frame.Curves[curveIndex + key].Value;
                    }

                    AddComplexCurve(frame.Time, binding.BindingType, curveValues, 0, path);
                    curveIndex += dimension;
                }
            }
        }
예제 #4
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;
                    if (!GetGenericBinding(bindings, index, out GenericBinding binding))
                    {
                        curveIndex++;
                        continue;
                    }

                    string path = GetCurvePath(tos, binding.Path);
                    AddComplexCurve(time, binding.BindingType, constant.Constants, slopeValues, slopeValues, curveIndex, path);
                    curveIndex += binding.BindingType.GetDimension();
                }
            }
        }
예제 #5
0
        public void Process(Clip clip, AnimationClipBindingConstant bindings, IReadOnlyDictionary <uint, string> tos)
        {
            IReadOnlyList <StreamedFrame> streamedFrames = clip.StreamedClip.GenerateFrames(m_version, m_platform);
            int frameCount = Math.Max(clip.DenseClip.FrameCount - 1, streamedFrames.Count - 2);

            ProcessStreams(streamedFrames, bindings, tos);
            ProcessDenses(clip, bindings, tos);
            ProcessConstant(clip, bindings, tos, frameCount);
        }
예제 #6
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);
        }
        public void Process(Clip clip, AnimationClipBindingConstant bindings, IReadOnlyDictionary <uint, string> tos)
        {
            IReadOnlyList <StreamedFrame> streamedFrames = clip.StreamedClip.GenerateFrames(m_version, m_platform, m_flags);
            float lastDenseFrame  = clip.DenseClip.FrameCount / clip.DenseClip.SampleRate;
            float lastSampleFrame = streamedFrames.Count > 1 ? streamedFrames[streamedFrames.Count - 2].Time : 0.0f;
            float lastFrame       = Math.Max(lastDenseFrame, lastSampleFrame);

            Clear();
            ProcessStreams(streamedFrames, bindings, tos);
            ProcessDenses(clip, bindings, tos);
            ProcessConstant(clip, bindings, tos, lastFrame);
        }
예제 #8
0
        private void ProcessStreams(IReadOnlyList <StreamedFrame> streamFrames, AnimationClipBindingConstant bindings, IReadOnlyDictionary <uint, string> tos)
        {
            float[] curveValues    = new float[4];
            float[] inSlopeValues  = new float[4];
            float[] outSlopeValues = new float[4];

            // 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];
                    if (!GetGenericBinding(bindings, curve.Index, out GenericBinding binding))
                    {
                        curveIndex++;
                        continue;
                    }

                    //FindPreviousCurve(streamFrames, curve.Index, frameIndex, out int prevFrameIndex, out int prevCurveIndex);
                    //FindNextCurve(streamFrames, curve.Index, frameIndex, out int nextFrameIndex, out int nextCurveIndex);

                    string path      = GetCurvePath(tos, binding.Path);
                    int    dimension = binding.BindingType.GetDimension();
                    for (int key = 0; key < dimension; key++)
                    {
                        StreamedCurveKey keyCurve = frame.Curves[curveIndex + key];
                        //StreamedFrame prevFrame = streamFrames[prevFrameIndex];
                        //StreamedFrame nextFrame = streamFrames[nextFrameIndex];
                        //StreamedCurveKey prevKeyCurve = prevFrame.Curves[prevCurveIndex + key];
                        //StreamedCurveKey nextKeyCurve = nextFrame.Curves[nextCurveIndex + key];
                        curveValues[key] = keyCurve.Value;
#warning TODO: TCB to in/out slope
                        //inSlopeValues[key] = prevKeyCurve.CalculateNextInTangent(keyCurve.Value, nextKeyCurve.Value);
                        //outSlopeValues[key] = keyCurve.CalculateOutTangent(prevKeyCurve.Value, nextKeyCurve.Value);
                    }

                    AddComplexCurve(frame.Time, binding.BindingType, curveValues, inSlopeValues, outSlopeValues, 0, path);
                    curveIndex += dimension;
                }
            }
        }