public void TestAnimationClip()
        {
            var clip = new AnimationClip
            {
                Duration = TimeSpan.FromSeconds(2.0f),
                RepeatMode = AnimationRepeatMode.LoopInfinite
            };

            var testCurve = new AnimationCurve<float>();
            clip.AddCurve("posx[TestNode]", testCurve);
            testCurve.InterpolationType = AnimationCurveInterpolationType.Linear;

            var time = CompressedTimeSpan.FromSeconds(0.0f);
            var value = 0.0f;
            var frame0 = new KeyFrameData<float>(time, value);
            testCurve.KeyFrames.Add(frame0);

            time = CompressedTimeSpan.FromSeconds(1.0f);
            value = 1.0f;
            var frame1 = new KeyFrameData<float>(time, value);
            testCurve.KeyFrames.Add(frame1);

            clip.Optimize();

            var optimizedCurvesFloat = (AnimationData<float>)clip.OptimizedAnimationDatas.First();

            //we should have 3 frames at this point. the last one will be added by the optimization process...
            Assert.That(optimizedCurvesFloat.AnimationSortedValueCount, Is.EqualTo(1));
            //And 2 initial frames            
            Assert.That(optimizedCurvesFloat.AnimationInitialValues[0].Value1, Is.EqualTo(frame0));
            Assert.That(optimizedCurvesFloat.AnimationInitialValues[0].Value2, Is.EqualTo(frame1));
            Assert.That(optimizedCurvesFloat.AnimationSortedValues.Length, Is.EqualTo(1));
            Assert.That(optimizedCurvesFloat.AnimationSortedValues[0].Length, Is.EqualTo(1));
            Assert.That(optimizedCurvesFloat.AnimationSortedValues[0][0].Value, Is.EqualTo(frame1));
        }
Example #2
0
 public KeyFrameData GetKeyFrames(KeyFrameData obj, int j)
 {
     int o = __offset(8); return o != 0 ? obj.__init(__indirect(__vector(o) + j * 4), bb) : null;
 }
Example #3
0
    static KeyFrameData CalculateAnimationKeyFrameData(int animid, Parser.Tr2Level leveldata)
    {
        //Note: animid is a index to tranim list.

        KeyFrameData tr2framedata = new KeyFrameData();
        if(animid == leveldata.NumAnimations)
        {
            //endofanimation
            tr2framedata.endofanimation = true;
            return tr2framedata;
        }

        if(animid == 0)
        {
            tr2framedata.bplayer = true;
        }

        Parser.Tr2Animation tr2animation = leveldata.Animations[animid];
        //create  s16 offset list of frames for this animation;
        //determine short stating offset to frames chunk of this animclip
        //calculate index into tr2frames[] and how large the frame is
        //tr2animation.FrameOffset is byte offset into Frame, make it short offset
        //tr2animation.FrameSize = (byte)((tr2frames[fo + 9] * 2) + 10);

        tr2framedata.data = leveldata.Frames;
        tr2framedata.startoffset = (int) tr2animation.FrameOffset / 2;
        tr2framedata.framesize = (int) tr2animation.FrameSize;  // num shorts of this frame step
        tr2framedata.framerate= 1.0f/((7.0f - tr2animation.FrameRate) * 4.0f) ;

        if(animid < (int)leveldata.NumAnimations - 1)
        {
            Parser.Tr2Animation nexttr2animation = leveldata.Animations[animid + 1];
            int nextoffset = (int)(nexttr2animation.FrameOffset / 2);
            tr2framedata.numshorts = nextoffset - tr2framedata.startoffset ;
        }
        else
        {
            tr2framedata.numshorts = (int)(leveldata.NumFrames  - (uint)tr2framedata.startoffset);
        }

        if(tr2framedata.framesize!=0)
        {
            tr2framedata.numkeyframe = tr2framedata.numshorts / tr2framedata.framesize;
        }
        else
        {
            tr2framedata.numkeyframe = 0;
        }

        //if(tr2framedata.numkeyframe > 15)
        //Debug.Log("numkeyframe: " + tr2framedata.numkeyframe + " NextAnimation:" + tr2animation.NextAnimation);

        return tr2framedata;
    }