Exemple #1
0
        void Interpolate(AnimationFrame[] frames, int index, int blid, short maxtime)
        {
            int last = index - 1;
            int next = index + 1;

            while (last >= 0)
            {
                if (frames[last].Blocks[blid] != null)
                {
                    break;
                }
                last--;
            }

            while (next < frames.Length)
            {
                if (frames[next].Blocks[blid] != null)
                {
                    break;
                }
                next++;
            }

            AnimationAxisTransform lb = new AnimationAxisTransform(null, -1);

            lb.TimeCode = Math.Min((short)0, frames[index].TimeCode);
            lb.Linear   = frames[index].Linear;

            //if (last<0 && next<frames.Length) last=next; //if the first Frame is missing, use the Position of the next Frame
            if (last >= 0)
            {
                lb.TimeCode  = frames[last].TimeCode;
                lb.Parameter = frames[last].Blocks[blid].Parameter;
                if (frames[last].Blocks[blid].Parent != null)
                {
                    if (lb.TimeCode == 0 && frames[last].Blocks[blid].Parent.Locked)
                    {
                        lb.Parameter = 0;
                    }
                }
            }



            AnimationAxisTransform nb = new AnimationAxisTransform(null, -1);

            nb.TimeCode  = Math.Max(maxtime, frames[index].TimeCode);
            nb.Parameter = lb.Parameter;
            nb.Linear    = frames[index].Linear;


            if (next < frames.Length)
            {
                nb.TimeCode  = frames[next].TimeCode;
                nb.Parameter = frames[next].Blocks[blid].Parameter;
            }


            frames[index].Blocks[blid] = InterpolateFrame(lb, nb, frames[index].TimeCode);
        }
Exemple #2
0
        public AnimationAxisTransform InterpolateFrame(AnimationAxisTransform first, AnimationAxisTransform last, short timecode)
        {
            AnimationAxisTransform b = new AnimationAxisTransform(null, -1);

            b.TimeCode = timecode;
            b.Linear   = first.Linear || last.Linear;

            if (first.TimeCode == last.TimeCode)
            {
                b.Parameter = first.Parameter;
            }
            else
            {
                //swap first and last?
                if (first.TimeCode > last.TimeCode)
                {
                    AnimationAxisTransform d = first;
                    first = last;
                    last  = d;
                }

                float pos = (float)(b.TimeCode - first.TimeCode) / (float)(last.TimeCode - first.TimeCode);
                short val = (short)(((last.Parameter - first.Parameter) * pos) + first.Parameter);

                b.Parameter = val;
            }

            if (this.AxisCount > 0)
            {
                b.SetParent(this.AxisSet[0]);
            }


            return(b);
        }
Exemple #3
0
 /// <summary>
 /// Add a new <see cref="AnimationAxisTransform"/> based on a Cloned Object
 /// </summary>
 /// <param name="aat">The Item you want to Add</param>
 /// <exception cref="AxisTransformException">
 /// Thrown, if the Item you triy to add, is a Child of another <see cref="AnimationAxisTransformBlock"/>,
 /// or is already included in the current Listing. Before add a Frame, you have to create a Clone!
 /// </exception>
 public void Add(AnimationAxisTransform aat)
 {
     if ((aat.Parent != this && aat.Parent != null) || aat.Index != -1)
     {
         throw new AxisTransformException("Can't add the passed AnimationAxisTransform!");
     }
     aat.SetIndex(items.Count);
     aat.SetParent(this);
     items.Add(aat);
 }
Exemple #4
0
        AnimationAxisTransform GetFrameAddonData(int part)
        {
            AnimationAxisTransform b = GetBlock((byte)(part % 3));

            if (b == null)
            {
                return(new AnimationAxisTransform(null, -1));
            }
            return(b);
        }
Exemple #5
0
        /// <summary>
        /// Insert a new <see cref="AnimationAxisTransform"/> based on a Cloned Object
        /// </summary>
        /// <param name="index">The index within the List</param>
        /// <param name="aat">The Item you want to Add</param>
        /// <exception cref="AxisTransformException">
        /// Thrown, if the Item you triy to add, is a Child of another <see cref="AnimationAxisTransformBlock"/>,
        /// or is already included in the current Listing. Before add a Frame, you have to create a Clone!
        /// </exception>
        public void Insert(int index, AnimationAxisTransform aat)
        {
            if ((aat.Parent != this && aat.Parent != null) || aat.Index != -1)
            {
                throw new AxisTransformException("Can't add the passed AnimationAxisTransform!");
            }

            aat.SetIndex(index);
            aat.SetParent(this);
            items.Insert(index, aat);
            ReIndex(index + 1);
        }
Exemple #6
0
        /// <summary>
        /// Add a new <see cref="AnimationAxisTransform"/> Item
        /// </summary>
        /// <param name="timecode"></param>
        /// <param name="param"></param>
        /// <param name="u1"></param>
        /// <param name="u2"></param>
        /// <param name="islinear"></param>
        /// <remarks>The Data does not get added when the timecode already exists, null will be returned in that case</remarks>
        public AnimationAxisTransform Add(short timecode, short param, short u1, short u2, bool islinear)
        {
            AnimationAxisTransform aat = BuildAnimationAxisTransform(timecode, param, u1, u2, islinear, items.Count);

            if (ContainsTimeCode(timecode))
            {
                return(null);
            }

            items.Add(aat);
            return(aat);
        }
Exemple #7
0
        public AnimationAxisTransform BuildAnimationAxisTransform(short timecode, short param, short u1, short u2, bool islinear, int index)
        {
            AnimationAxisTransform aat = new AnimationAxisTransform(this, index);

            aat.TimeCode  = timecode;
            aat.Linear    = islinear;
            aat.Parameter = param;
            aat.Unknown1  = u1;
            aat.Unknown2  = u2;

            return(aat);
        }
Exemple #8
0
        /// <summary>
        /// Unserializes a BinaryStream into the Attributes of this Instance
        /// </summary>
        /// <param name="reader">The Stream that contains the FileData</param>
        internal void UnserializeAddonData(System.IO.BinaryReader reader)
        {
            int ct = GetCount() / this.TokenSize;


            for (int i = 0; i < ct; i++)
            {
                AnimationAxisTransform aat = new AnimationAxisTransform(this, i);
                aat.UnserializeData(reader);
                items.Add(aat);
            }
        }
Exemple #9
0
        public AnimationAxisTransform CloneBase()
        {
            AnimationAxisTransform aat = new AnimationAxisTransform(null, -1);

            aat.Linear    = this.Linear;
            aat.TimeCode  = this.TimeCode;
            aat.Parameter = this.Parameter;
            aat.Unknown1  = this.Unknown1;
            aat.Unknown2  = this.Unknown2;

            return(aat);
        }
Exemple #10
0
        /// <summary>
        /// This Operation will remove all Frames, that are not needed to perform the Animation
        /// </summary>
        /// <remarks>
        /// Unneeded Frames are ones, that can be interpolated by
        /// the previous and following Frame
        /// </remarks>
        public void RemoveUnneededFrames()
        {
            const float DELTA = float.Epsilon * 10;

            for (int blid = this.AxisSet.Length - 1; blid >= 0; blid--)
            {
                IntArrayList remlist = new IntArrayList();
                for (int nr = 1; nr < this.AxisSet[blid].Count - 1; nr++)
                {
                    AnimationAxisTransform iframe = null;

                    /*if (nr==0) iframe = this.AxisSet[blid][nr+1];
                     * else if (nr==this.AxisSet[blid].Count-1) iframe = this.AxisSet[blid][nr+1];
                     * else*/iframe = InterpolateFrame(this.AxisSet[blid][nr - 1], this.AxisSet[blid][nr + 1], this.AxisSet[blid][nr].TimeCode);

                    if (Math.Abs(iframe.Parameter - this.AxisSet[blid][nr].Parameter) < DELTA)
                    {
                        remlist.Add(nr);
                    }
                }


                //sort the List and remove the marked Transformations
                remlist.Sort();
                for (int i = remlist.Count - 1; i >= 0; i--)
                {
                    AxisSet[blid].Remove(AxisSet[blid][remlist[i]]);
                }

                //two or more remaining Frames, where the last two have the same Parameter ==> delete the last one
                if (AxisSet[blid].Count >= 2)
                {
                    if (AxisSet[blid][AxisSet[blid].Count - 2].Parameter == AxisSet[blid][AxisSet[blid].Count - 1].Parameter)
                    {
                        AxisSet[blid].Remove(AxisSet[blid][AxisSet[blid].Count - 1]);
                    }
                }

                //Now set the suggested Type that should be used
                if (AxisSet[blid].Count == 1)
                {
                    if (AxisSet[blid].FirstTimeCode == 0)
                    {
                        AxisSet[blid].Type = AnimationTokenType.TwoByte;
                    }
                }
                else if (AxisSet[blid].Count == 0)
                {
                    ab3 = (AnimationAxisTransformBlock[])Helper.Delete(ab3, AxisSet[blid]);
                }
            }
        }
Exemple #11
0
        /// <summary>
        /// Remove the passed Item from the Parent
        /// </summary>
        /// <param name="aat"></param>
        public void Remove(AnimationAxisTransform aat)
        {
            int ct = items.Count;

            items.Remove(aat);
            ReIndex();


            if (ct != items.Count)
            {
                aat.SetParent(null);
                aat.SetIndex(-1);
            }
        }
Exemple #12
0
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }
            if (!(obj is AnimationAxisTransform))
            {
                return(-1);
            }

            AnimationAxisTransform aat = (AnimationAxisTransform)obj;

            return(this.TimeCode.CompareTo(aat.TimeCode));
        }
Exemple #13
0
        public AnimationFrame AddFrame(short tc, short x, short y, short z, bool linear)
        {
            AnimationFrame af = new AnimationFrame(tc, TransformationType);

            //af.Blocks = new AnimationAxisTransform[AxisCount];
            for (int i = 0; i < AxisCount; i++)
            {
                AnimationAxisTransformBlock b   = AxisSet[i];
                AnimationAxisTransform      aat = b.Add(tc, GetAxisValue(i, x, y, z), 0, 0, linear);

                if (i < 4)
                {
                    af.Blocks[i] = aat;
                }
            }

            return(af);
        }