예제 #1
0
        public static void TestAllAnimSize()
        {
            var support = 0;
            var correct = 0;

            var animationClipGuids     = AssetDatabase.FindAssets("t:AnimationClip");
            var animationClipGuidCount = animationClipGuids.Length;

            for (var i = 0; i < animationClipGuidCount; ++i)
            {
                var animationClipGuid = animationClipGuids[i];
                var animationClipPath = AssetDatabase.GUIDToAssetPath(animationClipGuid);
                var animationClip     =
                    AssetDatabase.LoadAssetAtPath(animationClipPath, typeof(AnimationClip)) as AnimationClip;
                var stats = AnimationClipStatsPublic.Get(animationClip);
                if (!IsSupport(stats))
                {
                    continue;
                }

                try
                {
                    EditorUtility.DisplayProgressBar("Process",
                                                     string.Format("[{0}/{1}] {2}\n", i, animationClipGuidCount, animationClip.name),
                                                     ((float)i) / animationClipGuidCount);

                    var builder = new AnimationClipBuilder(animationClip);
                    var mystats = builder.GetStats();

                    support++;
                    if (stats.size == mystats.size)
                    {
                        correct++;
                        continue;
                    }

                    Debug.Log(
                        string.Format("{0}\t{1}\t{2}\t{3}", animationClip.name, stats.size, mystats.size,
                                      stats.size - mystats.size), animationClip);
                }
                catch (Exception e)
                {
                    Debug.Log(string.Format("{0}, Exception:{1}", animationClip.name, e.Message), animationClip);
                }
            }

            Debug.LogFormat("Total: {0} Support: {1} Correct:{2}", animationClipGuidCount, support, correct);
            EditorUtility.ClearProgressBar();
        }
예제 #2
0
        private static bool IsSupport(AnimationClipStatsPublic stats)
        {
            if (stats.size == 0)
            {
                return(false);
            }

            if (stats.denseCurves != 0 || stats.constantCurves != 0)
            {
                return(false);
            }

            if (stats.totalCurves != (stats.positionCurves * 3 + stats.scaleCurves * 3 + stats.quaternionCurves * 4))
            {
                return(false);
            }
            return(true);
        }
예제 #3
0
        private void CalcStats(List <Curve> curves, int valueCount, ref AnimationClipStatsPublic stats,
                               ref CurveDetail curveDetail, List <BuildCurveKey> streamedKeys)
        {
            foreach (var curve in curves)
            {
                switch (curve.clipType)
                {
                case ClipOptType.StreamedClip:
                    stats.streamCurves += valueCount;

                    foreach (var key in curve.keys)
                    {
                        for (var i = 0; i < valueCount; i++)
                        {
                            if (i == 0 && key.time == float.MinValue)
                            {
                                continue;
                            }

                            var cache = new BuildCurveKey();
                            cache.time       = key.time;
                            cache.curveIndex = curveDetail.StreamedClipCurveIndex + i;
                            streamedKeys.Add(cache);
                        }
                    }

                    curveDetail.StreamedClipCurveIndex += valueCount;
                    break;

                case ClipOptType.DenseClip:
                    stats.denseCurves += valueCount;
                    curveDetail.DenseClipCurveIndex += valueCount;
                    break;

                case ClipOptType.ConstantClip:
                    stats.constantCurves           += valueCount;
                    curveDetail.ConstantCurveIndex += valueCount;
                    break;
                }
            }
        }
예제 #4
0
        public AnimationClipStatsPublic GetStats()
        {
            AnimationClipStatsPublic stats = new AnimationClipStatsPublic();

            stats.positionCurves   = PositionCurves.Count;
            stats.scaleCurves      = ScaleCurves.Count;
            stats.quaternionCurves = RotationCurves.Count;
            stats.totalCurves      = stats.positionCurves * 3 + stats.scaleCurves * 3 + stats.quaternionCurves * 4;

            var groupedCurves = GetGroupedCurves();

            var         streamedKeys = new List <BuildCurveKey>();
            CurveDetail curveDetail  = new CurveDetail();

            CalcStats(PositionCurves, 3, ref stats, ref curveDetail, streamedKeys);
            CalcStats(ScaleCurves, 3, ref stats, ref curveDetail, streamedKeys);
            CalcStats(RotationCurves, 4, ref stats, ref curveDetail, streamedKeys);

            var bindingSize =
                stats.positionCurves * 24 + stats.scaleCurves * 24 + stats.quaternionCurves * 24; // GenericBinding(24)
            var streamedSize = CalcStreamedClipSize(streamedKeys);
            var constantSize = sizeof(UInt32) + curveDetail.ConstantCurveIndex * sizeof(float);
            var densetSize   = 5 * sizeof(UInt32) + curveDetail.DenseClipCurveIndex * sizeof(float);

            var guessBase = 2168;

            var streamedClipCurves = groupedCurves[(int)ClipOptType.StreamedClip];
            var guessCurvesSize    = streamedClipCurves.PositionCurves.Count * 60 +
                                     streamedClipCurves.ScaleCurves.Count * 60 +
                                     streamedClipCurves.RotationCurves.Count * 88;

            stats.size = bindingSize + streamedSize + constantSize + densetSize + guessBase + guessCurvesSize;
            // var count = GetPathCount();
            // var guessPath = 8 * count * ( (curveDetail.ConstantCurveIndex > 0 ? 1 : 0) + (curveDetail.StreamedClipCurveIndex > 0 ? 1 : 0) - 1);
            // stats.size += guessPath;
            return(stats);
        }
예제 #5
0
        public static void TestAnimSize()
        {
            var animationClip = Selection.activeObject as AnimationClip;

            if (animationClip == null)
            {
                Debug.Log("AnimationClip not selected");
                return;
            }

            var stats = AnimationClipStatsPublic.Get(animationClip);

            if (!IsSupport(stats))
            {
                Debug.Log("Unsupported AnimationClip");
                return;
            }

            var builder = new AnimationClipBuilder(animationClip);
            var mystats = builder.GetStats();

            Debug.LogFormat("{0}\t{1}\t{2}\t{3}", animationClip.name, stats.size, mystats.size,
                            stats.size - mystats.size);
        }