Representation of a joint of a skeleton. Sometimes also called "Bone".
Inheritance: IAddress
Esempio n. 1
0
        /// <summary>
        /// Imports all joint nodes referenced by &lt;skeleton&gt; nodes and their
        /// children. Stores the found joints in the given model's joint collection.
        /// </summary>
        /// <param name="xmlRoot">XML root node</param>
        /// <param name="model">model to store joints in</param>
        public void Import(XmlNode xmlRoot, ColladaModel model)
        {
            knownJoints.Clear();

            // Add root joint that can be used to transform the model alltogether
            Joint root = new Joint("__root")
                             {
                                 Parent = null,
                                 Transform = Matrix.Identity,
                                 Index = 0,
                                 ScopedID = "__root",
                                 GlobalID = "__root"
                             };

            ReadJoints(root, FindJointNodes(xmlRoot), model);

            // Last joint is the root
            model.Joints.Add(root);
            root.Index = model.Joints.Count - 1;
        }
Esempio n. 2
0
        /// <summary>
        /// Reads the given joints and all of their children recursively. Newly created joints
        /// are appended to the Children collection of the parent (if not null) and to the
        /// Joints collection of the given model.
        /// </summary>
        /// <param name="parent">Parent joint of joints to read</param>
        /// <param name="xmlNodes">XML joint nodes</param>
        /// <param name="model">Model instance with non-null joint collection</param>
        void ReadJoints(Joint parent, IEnumerable<XmlNode> xmlNodes, ColladaModel model)
        {
            bool jointWithoutId = false;

            foreach (XmlNode xmlNode in xmlNodes)
            {
                // Create joint from XML
                Joint joint = new Joint(GetNodeName(xmlNode))
                              {
                                  Parent = parent,
                                  Transform = CreateNodeTransform(xmlNode),
                                  GlobalID = xmlNode.GetAttributeString("id"),
                                  ScopedID = xmlNode.GetAttributeString("sid")
                              };

                // Check if this joint was already added, only possible if ID is set);
                if (!String.IsNullOrEmpty(joint.GlobalID))
                {
                    if (knownJoints.ContainsKey(joint.GlobalID)) continue;
                    knownJoints.Add(joint.GlobalID, true);
                }
                else
                {
                    // There was a joint without ID
                    jointWithoutId = true;
                }

                // Append this joint to parents' children collection
                if (parent != null)
                {
                    if (parent.Children == null)
                        parent.Children = new JointList { joint };
                    else
                        parent.Children.Add(joint);
                }

                // Add joint to model's joint collection
                joint.Index = model.Joints.Count;
                model.Joints.Add(joint);

                // Read child nodes of this joint
                XmlNodeList xmlChildren = xmlNode.SelectNodes("node");
                if (xmlChildren != null)
                {
                    ReadJoints(joint, xmlChildren.OfType<XmlNode>(), model);
                }
            }

            if (jointWithoutId)
            {
                // There were joints without IDs, these bones could be contained
                // in model's joint collection multiple times
                // TODO: Remove double joints in case of Joint without Id
            }
        }