Пример #1
0
        private void MaxFramesBox_ValueChanged(object sender, EventArgs e)
        {
            animLength = (int)MaxFramesBox.Value;
            CurrentFrameSelect.Maximum = MaxFramesBox.Value - 1;
            currentFrame = (int)CurrentFrameSelect.Value;

            BoneNode node = (BoneNode)(BoneTreeView.SelectedNode);

            if (node != null)
            {
                if (node.Images != null)
                {
                    if (currentFrame < node.Images.Count)
                    {
                        ImageIndBox.Value = node.Images[(int)currentFrame];
                    }
                }
                if (node.Rotations != null)
                {
                    if (currentFrame < node.Rotations.Count)
                    {
                        RotationBox.Value = (decimal)(node.Rotations[(int)currentFrame]);
                    }
                }
            }
        }
Пример #2
0
        public BoneNode GetChild(string name)
        {
            BoneNode childBone = null;

            if (Nodes.Count > 0)
            {
                foreach (BoneNode b in Nodes)
                {
                    if (childBone == null)
                    {
                        if (b.Name == name)
                        {
                            childBone = b;
                            Console.WriteLine("found child");
                        }
                        else
                        {
                            Console.WriteLine("child was not the one; " + Name);
                            childBone = b.GetChild(name);
                        }
                    }
                }
            }

            return(childBone);
        }
Пример #3
0
        protected override void Draw()
        {
            base.Draw();

            GraphicsDevice.Clear(Color.CornflowerBlue);

            if (Loaded == false)
            {
                Load();
                Loaded = true;
                Console.WriteLine("loaded textures");
            }

            Transformation rootTrans = Transformation.Identity;

            rootTrans.Scale = new Vector2(scale, scale);

            float frame = (form.currentFrame);
            int   maxF  = (form.animLength);

            if (form.BoneTreeView.Nodes.Count > 0)
            {
                BoneNode rootNode = ((BoneNode)form.BoneTreeView.Nodes[0]);

                BoneDrawingHack(rootNode, rootTrans, frame, maxF);
            }
        }
Пример #4
0
        private BoneNode LoadBone(BoneNode currentNode, XElement parent)
        {
            System.Globalization.CultureInfo ci = (System.Globalization.CultureInfo)System.Globalization.CultureInfo.CurrentCulture.Clone();
            ci.NumberFormat.CurrencyDecimalSeparator = ".";

            string name = parent.Attribute("name").Value;

            Vector3 Position = new Vector3(
                float.Parse(parent.Attribute("posx").Value, System.Globalization.NumberStyles.Any, ci),
                float.Parse(parent.Attribute("posy").Value, System.Globalization.NumberStyles.Any, ci),
                float.Parse(parent.Attribute("posz").Value, System.Globalization.NumberStyles.Any, ci));

            Vector2 Size = new Vector2(
                float.Parse(parent.Attribute("sizex").Value, System.Globalization.NumberStyles.Any, ci),
                float.Parse(parent.Attribute("sizey").Value, System.Globalization.NumberStyles.Any, ci));

            Vector2 Origin = new Vector2(
                float.Parse(parent.Attribute("origx").Value, System.Globalization.NumberStyles.Any, ci),
                float.Parse(parent.Attribute("origy").Value, System.Globalization.NumberStyles.Any, ci));

            string tex = parent.Attribute("texture").Value;

            BoneNode newNode = new BoneNode(name, Size, Origin, tex, Position);

            foreach (XElement b in parent.Elements("Bone"))
            {
                newNode.Nodes.Add(LoadBone(newNode, b));
            }

            return(newNode);
        }
Пример #5
0
        private void BoneSizeXBox_ValueChanged(object sender, EventArgs e)
        {
            BoneNode node = (BoneNode)(BoneTreeView.SelectedNode);

            if (node != null)
            {
                node.Size = new Vector2((float)(BoneSizeXBox.Value), node.Size.Y);
            }
        }
Пример #6
0
        private void BoneOrigYBox_ValueChanged(object sender, EventArgs e)
        {
            BoneNode node = (BoneNode)(BoneTreeView.SelectedNode);

            if (node != null)
            {
                node.Origin = new Vector2(node.Origin.X, (float)(BoneOrigYBox.Value));
            }
        }
Пример #7
0
        private void BonePosZBox_ValueChanged(object sender, EventArgs e)
        {
            BoneNode node = (BoneNode)(BoneTreeView.SelectedNode);

            if (node != null)
            {
                node.Position = new Vector3(node.Position.X, node.Position.Y, (float)(BonePosZBox.Value));
            }
        }
Пример #8
0
 private void AddChildButton_Click(object sender, EventArgs e)
 {
     if (BoneTreeView.SelectedNode != null)
     {
         BoneNode newNode = new BoneNode("newbone", new Vector2(0, 0), new Vector2(0, 0), "", new Vector3(0, 0, 0));
         BoneTreeView.SelectedNode.Nodes.Add(newNode);
         BoneTreeView.SelectedNode.Expand();
     }
 }
Пример #9
0
        private void BoneTexBox_TextChanged(object sender, EventArgs e)
        {
            BoneNode node = (BoneNode)(BoneTreeView.SelectedNode);

            if (node != null)
            {
                node.Texture = BoneTexBox.Text;
            }
        }
Пример #10
0
        private void BoneDrawingHack(BoneNode b, Transformation parentTransformation, float frame, int maxFrames)
        {
            Transformation localTransformation = Transformation.Identity;

            localTransformation.Position = new Vector2(b.Position.X, b.Position.Z);

            if (b.Rotations != null)
            {
                if (frame >= b.Rotations.Count)
                {
                    localTransformation.Rotation = 0;
                }
                else
                {
                    int   currentFrame = (int)frame;
                    int   nextFrame    = (int)(frame + 1) % maxFrames;
                    float lerpAmount   = frame % 1;

                    float r = Lerp(b.Rotations[currentFrame], b.Rotations[nextFrame], lerpAmount);

                    localTransformation.Rotation = r;
                }
            }
            else
            {
                localTransformation.Rotation = 0f;
            }

            Transformation worldTrans = Transformation.Compose(parentTransformation, localTransformation);

            int imageInd = 0;

            if (b.Images != null && frame <= b.Images.Count)
            {
                imageInd = b.Images[(int)frame];
            }

            Color highlight = Color.White;

            if (form.BoneTreeView.SelectedNode == b)
            {
                highlight = Color.Red;
            }

            DrawBone(b.Texture, b.Size, imageInd, b.Origin, worldTrans, highlight);

            if (b.Nodes.Count > 0)
            {
                foreach (BoneNode e in b.Nodes)
                {
                    BoneDrawingHack(e, worldTrans, frame, maxFrames);
                }
            }
        }
Пример #11
0
        private void SaveAnimationBone(BoneNode b, List <BoneNode> boneList)
        {
            boneList.Add(b);

            if (b.Nodes.Count > 0)
            {
                foreach (BoneNode e in b.Nodes)
                {
                    SaveAnimationBone(e, boneList);
                }
            }
        }
Пример #12
0
        private void LoadBoneTree(Stream strm)
        {
            //string animData = "player_test.ske";

            //cAnimationPreview1.Load();

            XDocument file;

            byte[] buffer = new byte[strm.Length];
            strm.Read(buffer, 0, buffer.Length);
            string xmlText = Encoding.ASCII.GetString(buffer);

            file = XDocument.Parse(xmlText);

            //Console.WriteLine(xmlText);

            BoneTreeView.Nodes.Clear();

            foreach (XElement e in file.Root.Elements("Bone"))
            {
                System.Globalization.CultureInfo ci = (System.Globalization.CultureInfo)System.Globalization.CultureInfo.CurrentCulture.Clone();
                ci.NumberFormat.CurrencyDecimalSeparator = ".";

                string name = e.Attribute("name").Value;

                Vector3 Position = new Vector3(
                    float.Parse(e.Attribute("posx").Value, System.Globalization.NumberStyles.Any, ci),
                    float.Parse(e.Attribute("posy").Value, System.Globalization.NumberStyles.Any, ci),
                    float.Parse(e.Attribute("posz").Value, System.Globalization.NumberStyles.Any, ci));

                Vector2 Size = new Vector2(
                    float.Parse(e.Attribute("sizex").Value, System.Globalization.NumberStyles.Any, ci),
                    float.Parse(e.Attribute("sizey").Value, System.Globalization.NumberStyles.Any, ci));

                Vector2 Origin = new Vector2(
                    float.Parse(e.Attribute("origx").Value, System.Globalization.NumberStyles.Any, ci),
                    float.Parse(e.Attribute("origy").Value, System.Globalization.NumberStyles.Any, ci));

                string tex = e.Attribute("texture").Value;

                BoneNode rootNode = new BoneNode(name, Size, Origin, tex, Position);

                BoneTreeView.Nodes.Add(rootNode);

                Console.WriteLine("created rootbone " + name);

                foreach (XElement b in e.Elements("Bone"))
                {
                    rootNode.Nodes.Add(LoadBone(rootNode, b));
                }
            }
        }
Пример #13
0
        private void ImageIndBox_ValueChanged(object sender, EventArgs e)
        {
            BoneNode node = (BoneNode)(BoneTreeView.SelectedNode);

            if (node != null)
            {
                if (node.Images != null)
                {
                    if (currentFrame < node.Images.Count)
                    {
                        node.Images[(int)currentFrame] = (int)(ImageIndBox.Value);
                    }
                }
            }
        }
Пример #14
0
        private void RotationBox_ValueChanged(object sender, EventArgs e)
        {
            BoneNode node = (BoneNode)(BoneTreeView.SelectedNode);

            if (node != null)
            {
                if (node.Rotations != null)
                {
                    if (currentFrame < node.Rotations.Count)
                    {
                        node.Rotations[(int)currentFrame] = (float)(RotationBox.Value);
                    }
                }
            }
        }
Пример #15
0
        public BoneNode GetBone(string name)
        {
            BoneNode bone = null;

            BoneNode rootNode = ((BoneNode)BoneTreeView.Nodes[0]);

            if (BoneTreeView.Nodes[0].Name != name)
            {
                Console.WriteLine("bone was not root, traversing");
                bone = rootNode.GetChild(name);
            }
            else
            {
                bone = rootNode;
            }

            return(bone);
        }
Пример #16
0
        private void BoneTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (BoneTreeView.SelectedNode != null)
            {
                BoneNode node = (BoneNode)BoneTreeView.SelectedNode;

                BoneNameBox.Text   = node.Text;
                BoneSizeXBox.Value = (decimal)node.Size.X;
                BoneSizeYBox.Value = (decimal)node.Size.Y;
                BoneOrigXBox.Value = (decimal)node.Origin.X;
                BoneOrigYBox.Value = (decimal)node.Origin.Y;
                BonePosXBox.Value  = (decimal)node.Position.X;
                BonePosYBox.Value  = (decimal)node.Position.Y;
                BonePosZBox.Value  = (decimal)node.Position.Z;
                BoneTexBox.Text    = node.Texture;
                if (node.Images != null)
                {
                    if (currentFrame < node.Images.Count)
                    {
                        ImageIndBox.Value = node.Images[(int)currentFrame];
                    }
                }
                if (node.Rotations != null)
                {
                    if (currentFrame < node.Rotations.Count)
                    {
                        RotationBox.Value = (decimal)(node.Rotations[(int)currentFrame]);
                    }
                }
            }
            else
            {
                BoneNameBox.Text   = "";
                BoneSizeXBox.Value = 0;
                BoneSizeYBox.Value = 0;
                BoneOrigXBox.Value = 0;
                BoneOrigYBox.Value = 0;
                BonePosXBox.Value  = 0;
                BonePosYBox.Value  = 0;
                BonePosZBox.Value  = 0;
                BoneTexBox.Text    = "";
            }
        }
Пример #17
0
        private string SaveAnimation()
        {
            List <BoneNode> nodes = new List <BoneNode>();

            if (BoneTreeView.Nodes.Count > 0)
            {
                {
                    BoneNode rootNode = ((BoneNode)BoneTreeView.Nodes[0]);

                    SaveAnimationBone(rootNode, nodes);
                }
            }

            string xmlText = "<SkeletalAnimation></SkeletalAnimation>";

            XDocument file = XDocument.Parse(xmlText);

            file.Root.Add(new XAttribute("frames", animLength));

            //Console.WriteLine(xmlText);


            foreach (BoneNode e in nodes)
            {
                XElement element = new XElement("Bone");
                element.Add(new XAttribute("name", e.Name));

                if (e.Rotations != null && e.Images != null)
                {
                    for (int i = 0; i < e.Rotations.Count; i++)
                    {
                        XElement frame = new XElement("Frame");
                        frame.Add(new XAttribute("txind", e.Images[i]));
                        frame.SetValue(e.Rotations[i]);
                        element.Add(frame);
                    }
                }

                file.Root.Add(element);
            }

            return(file.ToString());;
        }
Пример #18
0
        private XElement SaveBone(BoneNode bone, XDocument file)
        {
            XElement element = new XElement("Bone");

            element.Add(new XAttribute("name", bone.Name));
            element.Add(new XAttribute("sizex", bone.Size.X));
            element.Add(new XAttribute("sizey", bone.Size.Y));
            element.Add(new XAttribute("origx", bone.Origin.X));
            element.Add(new XAttribute("origy", bone.Origin.Y));
            element.Add(new XAttribute("texture", bone.Texture));
            element.Add(new XAttribute("posx", bone.Position.X));
            element.Add(new XAttribute("posy", bone.Position.Y));
            element.Add(new XAttribute("posz", bone.Position.Z));

            foreach (BoneNode b in bone.Nodes)
            {
                XElement nextBone = SaveBone(b, file);
                element.Add(nextBone);
            }

            return(element);
        }
Пример #19
0
        public void UpdateFrame()
        {
            CurrentFrameSelect.Value = (decimal)currentFrame;

            BoneNode node = (BoneNode)(BoneTreeView.SelectedNode);

            if (node != null)
            {
                if (node.Images != null)
                {
                    if (currentFrame < node.Images.Count)
                    {
                        ImageIndBox.Value = node.Images[(int)currentFrame];
                    }
                }
                if (node.Rotations != null)
                {
                    if (currentFrame < node.Rotations.Count)
                    {
                        RotationBox.Value = (decimal)(node.Rotations[(int)currentFrame]);
                    }
                }
            }
        }
Пример #20
0
        private void CurrentFrameSelect_ValueChanged(object sender, EventArgs e)
        {
            currentFrame = (float)(CurrentFrameSelect.Value);

            BoneNode node = (BoneNode)(BoneTreeView.SelectedNode);

            if (node != null)
            {
                if (node.Images != null)
                {
                    if (currentFrame < node.Images.Count)
                    {
                        ImageIndBox.Value = node.Images[(int)currentFrame];
                    }
                }
                if (node.Rotations != null)
                {
                    if (currentFrame < node.Rotations.Count)
                    {
                        RotationBox.Value = (decimal)(node.Rotations[(int)currentFrame]);
                    }
                }
            }
        }