Exemple #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;
        }
Exemple #2
0
        protected void BoneSortAdd(Bone b)
        {
            if (UpdateOrderBones.Contains(b))
                return;

            if (b.ParentIndex != -1)
                BoneSortAdd(Bones[b.ParentIndex]);

            UpdateOrderBones.Add(b);
            b.UpdateIndex = UpdateOrderBones.Count - 1;
        }
Exemple #3
0
        public Bone(Bone bone)
        {
            Name = bone.Name;

            TextureIndex = bone.TextureIndex;
            ParentIndex = bone.ParentIndex;

            Position = bone.Position;
            Scale = bone.Scale;
            Rotation = bone.Rotation;

            Hidden = bone.Hidden;

            TextureFlipHorizontal = bone.TextureFlipHorizontal;
            TextureFlipVertical = bone.TextureFlipVertical;

            Transform = bone.Transform;
        }
Exemple #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];
            }
        }
Exemple #5
0
        private void newAnimationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dirtyFlag)
            {
                DialogResult dialogResult = MessageBox.Show("Unsaved changes will be lost. Do you want to save?",
                    "Save changes?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                switch (dialogResult)
                {
                    case DialogResult.Cancel:
                        return;
                    case DialogResult.No:
                        break;
                    case DialogResult.Yes:
                        if (string.IsNullOrEmpty(savePath))
                            saveAsToolStripMenuItem_Click(sender, e);
                        else
                            Save(savePath);
                        break;
                }
            }

            dirtyFlag = false;

            ClearUndo();
            ClearRedo();

            savePath = "";
            NewAnimation();

            if (openBoneDialog.ShowDialog() == DialogResult.OK)
            {
                xmlPath = openBoneDialog.FileName;

                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(openBoneDialog.FileName);

                XmlNodeList boneList = xmlDocument.SelectNodes("/Bones/Bone");
                List<string> boneNames = new List<string>();

                foreach (XmlNode boneNode in boneList)
                {
                    boneNames.Add(boneNode.Attributes["name"].Value);
                }

                foreach (XmlNode boneNode in boneList)
                {
                    string name = boneNode.Attributes["name"].Value;
                    string textureFile = boneNode.Attributes["texture"].Value;
                    string parentName = boneNode.Attributes["parent"].Value;
                    int parentIndex = boneNames.FindIndex(s => s == parentName);

                    if (!Path.IsPathRooted(textureFile))
                    {
                        textureFile = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(openBoneDialog.FileName), textureFile));
                    }

                    int textureIndex = boneTextureFileNames.FindIndex(s => s == textureFile);
                    if (textureIndex == -1)
                    {
                        Texture2D texture;
                        Color[] pixels;

                        LoadPremultipledAlphaTexture(textureFile, out texture, out pixels);

                        boneTextures.Add(texture);
                        boneTextureFileNames.Add(textureFile);
                        boneTexturePixels.Add(pixels);

                        textureIndex = boneTextures.Count - 1;
                    }

                    Bone bone = new Bone(name, textureIndex, parentIndex);
                    keyframes[0].AddBone(bone);
                }

                XmlNodeList textureList = xmlDocument.SelectNodes("/Bones/Texture");

                foreach (XmlNode textureNode in textureList)
                {
                    string textureFile = textureNode.Attributes["texture"].Value;

                    if (!Path.IsPathRooted(textureFile))
                    {
                        textureFile = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(openBoneDialog.FileName), textureFile));
                    }

                    int textureIndex = boneTextureFileNames.FindIndex(s => s == textureFile);
                    if (textureIndex == -1)
                    {
                        Texture2D texture;
                        Color[] pixels;

                        LoadPremultipledAlphaTexture(textureFile, out texture, out pixels);

                        boneTextures.Add(texture);
                        boneTextureFileNames.Add(textureFile);
                        boneTexturePixels.Add(pixels);
                    }
                }

                keyframes[0].SortBones();
                keyframes[0].UpdateBones();
                currentBoneIndex = keyframes[0].Bones.Count - 1;
            }
        }
Exemple #6
0
        private void addBoneToolStripMenuItem_Click(object sender, EventArgs e)
        {
            boneInfoForm.nameTextBox.Text = "";
            boneInfoForm.parentTextBox.Text = "";
            boneInfoForm.insertTextBox.Text = "";
            boneInfoForm.texturePathTextBox.Text = "";
            boneInfoForm.browseButton.Enabled = true;

            if (atExistingKeyframe && existingKeyframe != null && currentBoneIndex != -1)
            {
                boneInfoForm.parentTextBox.Text = existingKeyframe.Bones[currentBoneIndex].Name;
                boneInfoForm.insertTextBox.Text = existingKeyframe.Bones[currentBoneIndex].Name;
            }

            if (keyframes[0].Bones.Count == 0)
            {
                boneInfoForm.parentTextBox.ReadOnly = true;
                boneInfoForm.insertTextBox.ReadOnly = true;
            }
            else
            {
                boneInfoForm.parentTextBox.ReadOnly = false;
                boneInfoForm.insertTextBox.ReadOnly = false;
            }

            if (boneInfoForm.ShowDialog() == DialogResult.OK)
            {
                AddUndo();
                ClearRedo();

                int insertIndex = -1;
                int parentIndex = -1;

                for (int boneIndex = 0; boneIndex < keyframes[0].Bones.Count; boneIndex++)
                {
                    if (keyframes[0].Bones[boneIndex].Name == boneInfoForm.parentTextBox.Text)
                        parentIndex = boneIndex;
                    if (keyframes[0].Bones[boneIndex].Name == boneInfoForm.insertTextBox.Text)
                    {
                        if (boneInfoForm.beforeRadioButton.Checked)
                            insertIndex = boneIndex;
                        else
                            insertIndex = boneIndex + 1;
                    }
                }

                if ((insertIndex == -1 && keyframes[0].Bones.Count != 0) || (parentIndex == -1 && boneInfoForm.parentTextBox.Text != ""))
                {
                    MessageBox.Show("Error occured while adding bone. Please check parent and insert names and try again");
                    return;
                }

                insertIndex = Math.Max(0, insertIndex);

                int textureIndex = LoadTexture(boneInfoForm.texturePathTextBox.Text);
                Bone bone = new Bone(boneInfoForm.nameTextBox.Text, textureIndex, parentIndex);

                foreach (Keyframe kf in keyframes)
                {
                    kf.Bones.Insert(insertIndex, new Bone(bone));

                    foreach (Bone b in kf.Bones)
                    {
                        if (b.ParentIndex >= insertIndex)
                            b.ParentIndex++;
                    }

                    kf.SortBones();
                    kf.UpdateBones();
                }

                currentBoneIndex = insertIndex;
            }
        }
Exemple #7
0
        protected void BoneSortAdd(Bone b)
        {
            if (updateOrderBones.Contains(b))
                return;

            if (b.ParentIndex != -1)
                BoneSortAdd(Bones[b.ParentIndex]);

            updateOrderBones.Add(b);
        }
Exemple #8
0
 public void AddBone(Bone bone)
 {
     Bones.Add(bone);
     updateOrderBones.Add(bone);
 }