Esempio n. 1
0
 public void ComplementaryAdd(Pose pose)
 {
     foreach (PoseNode poseNode in pose.PoseNodes)
     {
         PoseNode ownNode = this.GetNode(poseNode.Node);
         if (ownNode == null)
         {
             PoseNode newNode = new PoseNode(poseNode.Node);
             foreach (string property in poseNode.Properties.Keys)
             {
                 newNode.SetProperty(property, poseNode.Properties[property]);
             }
             this.PoseNodes.Add(newNode);
         }
         else
         {
             foreach (string property in poseNode.Properties.Keys)
             {
                 if (!ownNode.Properties.ContainsKey(property))
                 {
                     ownNode.SetProperty(property, poseNode.Properties[property]);
                 }
             }
         }
     }
 }
Esempio n. 2
0
        public void Create(TextureNode root, string[] properties, Pose basePose = null)
        {
            this.ClearPoseNodes();
            this.DifferentPropertiesCount = 0;
            List <TextureNode> nodes = new List <TextureNode>();

            nodes.Add(root);
            int baseIndex = 0;

            while (nodes.Count > 0)
            {
                PoseNode pnv = new PoseNode(nodes[0]);
                foreach (string property in properties)
                {
                    if (basePose == null)
                    {
                        pnv.SetProperty(property, nodes[0].GetProperty(property));
                    }
                    else
                    {
                        if (basePose.PoseNodes.Count > baseIndex && basePose.PoseNodes[baseIndex].Properties.ContainsKey(property))
                        {
                            float val1 = (float)nodes[0].GetProperty(property);
                            float val2 = (float)basePose.PoseNodes[baseIndex].Properties[property];
                            if (val1 != val2)
                            {
                                pnv.SetProperty(property, val1);
                            }
                        }
                        else
                        {
                            throw new IndexOutOfRangeException("base pose is not correct initialized");
                        }
                    }
                }
                if (pnv.Properties.Count > 0)
                {
                    this.PoseNodes.Add(pnv);
                    this.DifferentPropertiesCount += pnv.Properties.Count;
                }
                else
                {
                    pnv.Clear();
                }
                baseIndex++;
                foreach (TreeNode n in nodes[0].Nodes)
                {
                    nodes.Add(n as TextureNode);
                }
                nodes.RemoveAt(0);
            }
        }
Esempio n. 3
0
        private static Pose ReadPose(XmlTextReader reader, TextureNode root)
        {
            Pose pose = new Pose(reader.GetAttribute(0));

            pose.Mode = reader.GetAttribute(1).Equals(PoseMode.Collection.ToString()) ? PoseMode.Collection : PoseMode.Pose;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.Name == "Pose")
                    {
                        return(pose);
                    }
                }

                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == "PoseNode")
                    {
                        string[] path = reader.GetAttribute(1).Split('.');
                        TreeNode node = root;
                        node = root;
                        for (int index = 0; index < path.Length; index++)
                        {
                            if (path.Length > 0)
                            {
                                int i = 0;
                                if (int.TryParse(path[index], out i))
                                {
                                    node = node.Nodes[i];
                                }
                            }
                        }
                        PoseNode poseNode = new PoseNode(node as TextureNode);

                        ReadProperty(reader, poseNode);
                        pose.MergeAdd(poseNode);
                    }

                    if (reader.Name == "Pose")      // if Pose is collection
                    {
                        Pose pose2 = ReadPose(reader, root);
                        pose.Nodes.Add(pose2);
                    }
                }
            }

            return(pose);
        }
Esempio n. 4
0
        public List <string> GetKeysOfDifferentValues(PoseNode poseNode)
        {
            List <string> keys = new List <string>();

            if (this.Node == poseNode.Node)
            {
                foreach (string property in this.Properties.Keys)
                {
                    if (poseNode.Properties.ContainsKey(property))
                    {
                        if ((float)this.Properties[property] != (float)poseNode.Properties[property])
                        {
                            keys.Add(property);
                        }
                    }
                }
            }

            return(keys);
        }
Esempio n. 5
0
        private static void writePose(XmlTextWriter writer, Pose pose, Pose basePose, TextureNode root)
        {
            if (basePose != pose)     // exclude BasePose
            {
                PoseMode poseMode = pose.Mode;
                WriteElement(writer, "Pose", new string[] { "name", "type" }, new string[] { pose.Text, poseMode.ToString() });

                if (pose.PoseNodes.Count > 0 && poseMode == PoseMode.Pose)
                {
                    foreach (PoseNode poseNode in pose.PoseNodes)
                    {
                        PoseNode baseNode = basePose.GetNode(poseNode.Node);    // check null ?

                        string[] values = { poseNode.Node.Text, poseNode.Node.GetIndexPath() };
                        WriteElement(writer, "PoseNode", new string[] { "name", "path" }, values);

                        foreach (string property in poseNode.Properties.Keys)
                        {
                            string[] pValues = new string[] { property, poseNode.Properties[property].ToString() };
                            WriteElement(writer, "Property", new string[] { "name", "value" }, pValues, true);
                        }

                        writer.WriteEndElement();
                    }
                }
                else
                {
                    WriteElement(writer, "Equals", new string[] { "Pose" }, new String[] { basePose.Text }, true);
                }

                foreach (TreeNode subPose in pose.Nodes)
                {
                    writePose(writer, subPose as Pose, basePose, root);
                }

                writer.WriteEndElement();
            }
        }
Esempio n. 6
0
        public void CreatePartialRoot()
        {
            ClearPoseNodes();
            int counter = 0;

            if (this.TreeView != null && this.TreeView.Nodes.Count > 0)
            {
                Pose basePose = (this.TreeView.Nodes[0]) as Pose;

                foreach (TreeNode child in this.Nodes)
                {
                    foreach (PoseNode childNode in (child as Pose).PoseNodes)
                    {
                        this.MergeAdd(childNode, true);
                    }
                }

                foreach (PoseNode poseNode in this.PoseNodes)
                {
                    PoseNode baseNode = basePose.GetNode(poseNode.Node);
                    if (baseNode != null)
                    {
                        List <string> keys = new List <string>(poseNode.Properties.Keys);

                        foreach (string property in keys)
                        {
                            poseNode.Properties[property] = baseNode.Properties[property];
                            counter++;
                        }
                    }
                }

                foreach (TreeNode child in this.Nodes)
                {
                    (child as Pose).ComplementaryAdd(this);
                }
            }
        }
Esempio n. 7
0
        private static void ReadProperty(XmlTextReader reader, PoseNode poseNode)
        {
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.Name == "PoseNode")
                    {
                        break;
                    }
                }

                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == "Property")
                    {
                        string pName  = reader.GetAttribute(0);
                        float  pValue = float.Parse(reader.GetAttribute(1));
                        poseNode.SetProperty(pName, pValue);
                    }
                }
            }
        }
Esempio n. 8
0
        public void MergeAdd(PoseNode poseNode, bool deepCopy = false)
        {
            PoseNode target = poseNode;

            foreach (PoseNode node in this.PoseNodes)
            {
                if (node.Node == poseNode.Node)
                {
                    target = node;
                    break;
                }
            }

            if (target == poseNode)
            {
                if (deepCopy)
                {
                    PoseNode newNode = new PoseNode(poseNode.Node);
                    foreach (string property in poseNode.Properties.Keys)
                    {
                        newNode.SetProperty(property, poseNode.Properties[property]);
                    }
                    this.PoseNodes.Add(newNode);
                }
                else
                {
                    this.PoseNodes.Add(poseNode);
                }
            }
            else
            {
                foreach (string property in poseNode.Properties.Keys)
                {
                    target.SetProperty(property, poseNode.Properties[property]);
                }
            }
        }