Пример #1
0
        public bool SetAnimation(uint animation)
        {
            if (mAnimations.Length == 0 && mAnimationLookup.Length == 0)
            {
                return(false);
            }

            if (Array.IndexOf(mAnimationLookup, (short)animation) >= 0)
            {
                mAnimationId  = mAnimationLookup[animation];
                mAnimation    = mAnimations[mAnimationId];
                mHasAnimation = true;
                ResetAnimationTimes();
                return(true);
            }
            else if (Array.IndexOf(mAnimationIds, (ushort)animation) >= 0)
            {
                var anim = mAnimations.First(x => x.animationID == animation);
                mAnimationId  = anim.animationID;
                mAnimation    = anim;
                mHasAnimation = true;
                ResetAnimationTimes();
                return(true);
            }
            else
            {
                Log.Warning("Animation not found in model. Skipping");
                return(false);
            }
        }
Пример #2
0
 public M2File(string fileName) : base(fileName)
 {
     Bones           = new M2AnimationBone[0];
     UvAnimations    = new M2UVAnimation[0];
     ColorAnimations = new M2TexColorAnimation[0];
     Transparencies  = new M2AlphaAnimation[0];
     GlobalSequences = new uint[0];
     Animations      = new AnimationEntry[0];
     AnimationLookup = new short[0];
     mModelName      = string.Empty;
     mFileName       = fileName;
     mDirectoryParts = Path.GetDirectoryName(fileName).Split(Path.DirectorySeparatorChar);
 }
Пример #3
0
        public void SetAnimationByIndex(uint index)
        {
            if(index >= mAnimations.Length)
            {
                Log.Warning("Tried to access animation by index outside of valid animation range. Ignoring animation");
                return;
            }

            mAnimation = mAnimations[index];
            mAnimationId = (int) index;
            mHasAnimation = true;
            ResetAnimationTimes();
        }
Пример #4
0
        public void SetAnimationByIndex(uint index)
        {
            if (index >= mAnimations.Length)
            {
                Log.Warning("Tried to access animation by index outside of valid animation range. Ignoring animation");
                return;
            }

            mAnimation    = mAnimations[index];
            mAnimationId  = (int)index;
            mHasAnimation = true;
            ResetAnimationTimes();
        }
Пример #5
0
 public M2File(string fileName)
 {
     Bones           = new M2AnimationBone[0];
     UvAnimations    = new M2UVAnimation[0];
     ColorAnimations = new M2TexColorAnimation[0];
     Transparencies  = new M2AlphaAnimation[0];
     GlobalSequences = new uint[0];
     Animations      = new AnimationEntry[0];
     AnimLookup      = new short[0];
     mModelName      = string.Empty;
     mFileName       = fileName;
     mRootPath       = Path.GetDirectoryName(mFileName);
 }
Пример #6
0
        public void SetAnimation(uint animation)
        {
            if(animation >= mAnimationLookup.Length)
            {
                Log.Warning("Tried to access animation by id outside of the lookup array. Ignoring animation");
                return;
            }

            if(mAnimationLookup[animation] < 0)
            {
                Log.Warning("Animation not found in model. Skipping");
                return;
            }

            mAnimationId = mAnimationLookup[animation];
            mAnimation = mAnimations[mAnimationId];
            mHasAnimation = true;
            ResetAnimationTimes();
        }
Пример #7
0
        public void SetAnimation(uint animation)
        {
            if (animation >= mAnimationLookup.Length)
            {
                Log.Warning("Tried to access animation by id outside of the lookup array. Ignoring animation");
                return;
            }

            if (mAnimationLookup[animation] < 0)
            {
                Log.Warning("Animation not found in model. Skipping");
                return;
            }

            mAnimationId  = mAnimationLookup[animation];
            mAnimation    = mAnimations[mAnimationId];
            mHasAnimation = true;
            ResetAnimationTimes();
        }
Пример #8
0
        public void Update()
        {
            if (mHasAnimation == false)
                return;

            var now = Environment.TickCount;

            var time = (uint)(now - mBoneStart);
            if (time >= mAnimation.length && ((mAnimation.flags & 0x20) == 0 || mAnimation.nextAnimation >= 0))
            {
                if (mIsFinished)
                {
                    if (mAnimation.nextAnimation < 0 || mAnimation.nextAnimation >= mAnimations.Length) return;

                    mIsFinished = false;
                    mBoneStart = now;
                    mAnimationId = mAnimation.nextAnimation;
                    mAnimation = mAnimations[mAnimationId];
                    return;
                }

                time = mAnimation.length;
                mIsFinished = true;
            }
            else
            {
                if (mAnimation.length > 0)
                    time %= mAnimation.length;
            }

            for (var i = 0; i < mBoneCalculated.Length; ++i)
                mBoneCalculated[i] = false;

            lock(mBones)
            {
                for (var i = 0; i < mBones.Length; ++i)
                {
                    if (mBoneCalculated[i])
                        continue;

                    mBones[i].UpdateMatrix(time, mAnimationId, out BoneMatrices[i], this);
                    mBoneCalculated[i] = true;
                }
            }

            time = (uint)(now - mUvStart);
            lock(mUvAnimations)
            {
                for (var i = 0; i < mUvAnimations.Length; ++i)
                    mUvAnimations[i].UpdateMatrix(mAnimationId, time, out UvMatrices[i]);
            }

            time = (uint)(now - mTexColorStart);
            lock(mTexColorAnimations)
            {
                for (var i = 0; i < mTexColorAnimations.Length; ++i)
                    mTexColorAnimations[i].UpdateValue(mAnimationId, time, out Colors[i]);
            }

            time = (uint)(now - mAlphaStart);
            lock(mAlphaAnimations)
            {
                for (var i = 0; i < mAlphaAnimations.Length; ++i)
                    mAlphaAnimations[i].UpdateValue(mAnimationId, time, out Transparencies[i]);
            }

            mIsDirty = true;
        }
Пример #9
0
        public void Update(BillboardParameters billboard)
        {
            if (mHasAnimation == false)
            {
                return;
            }

            var now = Environment.TickCount;

            var time = (uint)(now - mBoneStart);

            if (time >= mAnimation.length && ((mAnimation.flags & 0x20) == 0 || mAnimation.nextAnimation >= 0))
            {
                if (mIsFinished)
                {
                    if (mAnimation.nextAnimation < 0 || mAnimation.nextAnimation >= mAnimations.Length)
                    {
                        return;
                    }

                    mIsFinished  = false;
                    mBoneStart   = now;
                    mAnimationId = mAnimation.nextAnimation;
                    mAnimation   = mAnimations[mAnimationId];
                    return;
                }

                time        = mAnimation.length;
                mIsFinished = true;
            }
            else
            {
                if (mAnimation.length > 0)
                {
                    time %= mAnimation.length;
                }
            }

            for (var i = 0; i < mBoneCalculated.Length; ++i)
            {
                mBoneCalculated[i] = false;
            }

            lock (mBones)
            {
                for (var i = 0; i < mBones.Length; ++i)
                {
                    if (mBoneCalculated[i])
                    {
                        continue;
                    }

                    mBones[i].UpdateMatrix(time, mAnimationId, out BoneMatrices[i], this, billboard);
                    mBoneCalculated[i] = true;
                }
            }

            time = (uint)(now - mUvStart);
            lock (mUvAnimations)
            {
                for (var i = 0; i < mUvAnimations.Length; ++i)
                {
                    mUvAnimations[i].UpdateMatrix(0, time, out UvMatrices[i]);
                }
            }

            time = (uint)(now - mTexColorStart);
            lock (mTexColorAnimations)
            {
                for (var i = 0; i < mTexColorAnimations.Length; ++i)
                {
                    mTexColorAnimations[i].UpdateValue(0, time, out Colors[i]);
                }
            }

            time = (uint)(now - mAlphaStart);
            lock (mAlphaAnimations)
            {
                for (var i = 0; i < mAlphaAnimations.Length; ++i)
                {
                    mAlphaAnimations[i].UpdateValue(0, time, out Transparencies[i]);
                }
            }

            mIsDirty = true;
        }