Example #1
0
        public static Keyframe Interpolate(int frameNumber, Keyframe key1, int key1FrameNumber, Keyframe key2, int key2FrameNumber)
        {
            Keyframe keyframe = new Keyframe(frameNumber);
            keyframe.FlipVertically = key1.FlipVertically;
            keyframe.FlipHorizontally = key1.FlipHorizontally;

            float t = (frameNumber - key1FrameNumber) / (float)(key2FrameNumber - key1FrameNumber);

            for (int boneIndex = 0; boneIndex < key1.Bones.Count; boneIndex++)
            {
                Bone bone = new Bone(key1.Bones[boneIndex].Name, key1.Bones[boneIndex].TextureIndex, key1.Bones[boneIndex].ParentIndex);
                bone.Position = Vector2.Lerp(key1.Bones[boneIndex].Position, key2.Bones[boneIndex].Position, t);
                bone.Scale = Vector2.Lerp(key1.Bones[boneIndex].Scale, key2.Bones[boneIndex].Scale, t);
                bone.Rotation = MathHelper.Lerp(key1.Bones[boneIndex].Rotation, key2.Bones[boneIndex].Rotation, t);
                bone.TextureFlipHorizontal = key1.Bones[boneIndex].TextureFlipHorizontal;
                bone.TextureFlipVertical = key1.Bones[boneIndex].TextureFlipVertical;
                bone.Hidden = key1.Bones[boneIndex].Hidden;

                keyframe.AddBone(bone);
            }

            keyframe.SortBones();
            keyframe.UpdateBones();
            return keyframe;
        }
Example #2
0
        public Keyframe(Keyframe keyframe)
        {
            FrameNumber = keyframe.FrameNumber;
            Trigger = keyframe.Trigger;
            FlipVertically = keyframe.FlipVertically;
            FlipHorizontally = keyframe.FlipHorizontally;

            Bones = new List<Bone>();
            updateOrderBones = new List<Bone>();

            foreach (Bone b in keyframe.Bones)
                Bones.Add(new Bone(b));

            updateOrderBones.AddRange(Bones);
            SortBones();

            UpdateBones();
        }
Example #3
0
        private void pasteKeyframeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!atExistingKeyframe && copiedKeyframe != null)
            {
                AddUndo();
                ClearRedo();

                Keyframe key = new Keyframe(copiedKeyframe);
                key.FrameNumber = currentKeyframe;
                keyframes.Add(key);
                keyframes.Sort((k1, k2) => k1.FrameNumber.CompareTo(k2.FrameNumber));

                atExistingKeyframe = true;
                existingKeyframe = key;

                interpolatedKeyframe = null;
            }
        }
Example #4
0
        void OpenAnimation(string animationFile)
        {
            ClearUndo();
            ClearRedo();

            savePath = animationFile;

            NewAnimation();
            keyframes.Clear();

            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.Load(animationFile);

            frameRate = Int32.Parse(xmlDocument.SelectSingleNode("/Animation/FrameRate").InnerText);
            frameRateComboBox.SelectedItem = frameRate.ToString();

            loopFrame = Int32.Parse(xmlDocument.SelectSingleNode("/Animation/LoopFrame").InnerText);

            XmlNodeList nodeList = xmlDocument.SelectNodes("/Animation/Texture");
            foreach (XmlNode node in nodeList)
            {
                LoadTexture(node.InnerText, animationFile);
            }

            nodeList = xmlDocument.SelectNodes("/Animation/Keyframe");
            foreach (XmlNode node in nodeList)
            {
                Keyframe keyframe = new Keyframe(Int32.Parse(node.Attributes["frame"].Value));
                if (node.Attributes["trigger"] != null)
                    keyframe.Trigger = node.Attributes["trigger"].Value;
                else
                    keyframe.Trigger = "";

                if (node.Attributes["vflip"] != null)
                    keyframe.FlipVertically = bool.Parse(node.Attributes["vflip"].Value);
                else
                    keyframe.FlipVertically = false;

                if (node.Attributes["hflip"] != null)
                    keyframe.FlipHorizontally = bool.Parse(node.Attributes["hflip"].Value);
                else
                    keyframe.FlipHorizontally = false;

                XmlNodeList boneList = node.SelectNodes("Bone");
                foreach (XmlNode boneNode in boneList)
                {
                    Bone bone = new Bone(boneNode.Attributes["name"].Value,
                        Int32.Parse(boneNode.SelectSingleNode("TextureIndex").InnerText),
                        Int32.Parse(boneNode.SelectSingleNode("ParentIndex").InnerText));

                    bone.Hidden = bool.Parse(boneNode.SelectSingleNode("Hidden").InnerText);

                    XmlNode tempNode = boneNode.SelectSingleNode("TextureFlipHorizontal");
                    if (tempNode != null)
                        bone.TextureFlipHorizontal = bool.Parse(tempNode.InnerText);
                    tempNode = boneNode.SelectSingleNode("TextureFlipVertical");
                    if (tempNode != null)
                        bone.TextureFlipVertical = bool.Parse(tempNode.InnerText);

                    bone.Position = new Vector2(float.Parse(boneNode.SelectSingleNode("Position/X").InnerText, CultureInfo.InvariantCulture),
                        float.Parse(boneNode.SelectSingleNode("Position/Y").InnerText, CultureInfo.InvariantCulture));
                    bone.Rotation = float.Parse(boneNode.SelectSingleNode("Rotation").InnerText, CultureInfo.InvariantCulture);
                    bone.Scale = new Vector2(float.Parse(boneNode.SelectSingleNode("Scale/X").InnerText, CultureInfo.InvariantCulture),
                        float.Parse(boneNode.SelectSingleNode("Scale/Y").InnerText, CultureInfo.InvariantCulture));

                    keyframe.AddBone(bone);
                }
                keyframe.SortBones();
                keyframe.UpdateBones();

                keyframes.Add(keyframe);
            }

            if (keyframes[0].Bones.Count != 0)
            {
                currentBoneIndex = 0;
                currentKeyframe = 0;
                atExistingKeyframe = true;
                existingKeyframe = keyframes[0];
            }
        }
Example #5
0
        void NewAnimation()
        {
            keyframes = new List<Keyframe>();
            keyframes.Add(new Keyframe(0));

            boneTextures = new List<Texture2D>();
            boneTextureFileNames = new List<string>();
            boneTexturePixels = new List<Color[]>();

            currentKeyframe = 0;
            currentBoneIndex = -1;

            loopFrame = -1;

            atExistingKeyframe = true;
            existingKeyframe = keyframes[0];

            copiedKeyframe = null;

            previouslySelectedBones.Clear();
        }
Example #6
0
 private void copyKeyframeToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (atExistingKeyframe && existingKeyframe != null)
     {
         copiedKeyframe = new Keyframe(existingKeyframe);
     }
     else if (interpolatedKeyframe != null)
     {
         copiedKeyframe = new Keyframe(interpolatedKeyframe);
     }
 }
Example #7
0
        private void addKeyframeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!atExistingKeyframe && interpolatedKeyframe != null)
            {
                AddUndo();
                ClearRedo();

                keyframes.Add(interpolatedKeyframe);

                keyframes.Sort((k1, k2) => k1.FrameNumber.CompareTo(k2.FrameNumber));

                atExistingKeyframe = true;
                existingKeyframe = interpolatedKeyframe;

                UpdateCurrentKeyframe(interpolatedKeyframe.FrameNumber);

                interpolatedKeyframe = null;
            }
        }
Example #8
0
        void UpdateCurrentKeyframe(int frame)
        {
            previouslySelectedBones.Clear();

            currentKeyframe = frame;

            int foundIndex = keyframes.FindIndex(key => key.FrameNumber == currentKeyframe);
            if (foundIndex != -1)
            {
                atExistingKeyframe = true;
                existingKeyframe = keyframes[foundIndex];
                currentKeyframeIndex = foundIndex;

                if (currentBoneIndex >= existingKeyframe.Bones.Count)
                    currentBoneIndex = -1;
            }
            else
            {
                atExistingKeyframe = false;
                existingKeyframe = null;

                for (int keyIndex = 0; keyIndex < keyframes.Count; keyIndex++)
                {
                    if (keyframes[keyIndex].FrameNumber < currentKeyframe)
                    {
                        // at last key
                        //		loop point is after current position
                        //		no loop
                        // between keys
                        //		next key is before loop point (or no loop)
                        //		next key is after loop point

                        if (keyIndex == keyframes.Count - 1)
                        {
                            if (loopFrame > currentKeyframe)
                            {
                                existingKeyframe = null;
                                interpolatedKeyframe = Keyframe.Interpolate(currentKeyframe, keyframes[keyIndex], keyframes[keyIndex].FrameNumber, keyframes[0], loopFrame);
                            }
                            else
                            {
                                existingKeyframe = null;
                                interpolatedKeyframe = new Keyframe(keyframes[keyIndex]);
                                interpolatedKeyframe.FrameNumber = currentKeyframe;
                            }
                            break;
                        }
                        else if (keyframes[keyIndex + 1].FrameNumber > currentKeyframe)
                        {
                            if (loopFrame > currentKeyframe && loopFrame < keyframes[keyIndex + 1].FrameNumber)
                            {
                                existingKeyframe = null;
                                interpolatedKeyframe = Keyframe.Interpolate(currentKeyframe, keyframes[keyIndex], keyframes[keyIndex].FrameNumber, keyframes[0], loopFrame);
                            }
                            else
                            {
                                existingKeyframe = null;
                                interpolatedKeyframe = Keyframe.Interpolate(currentKeyframe, keyframes[keyIndex], keyframes[keyIndex + 1]);
                            }
                            break;
                        }
                    }
                }
            }
        }
Example #9
0
 public static Keyframe Interpolate(int frameNumber, Keyframe key1, Keyframe key2)
 {
     return Interpolate(frameNumber, key1, key1.FrameNumber, key2, key2.FrameNumber);
 }