コード例 #1
0
        private static void addJointsToRig(ColladaRigData rig, XmlNode xmlNode, ColladaJointData parentJoint)
        {
            // Find the next child joint node.
            foreach (XmlNode node in xmlNode.ChildNodes)
            {
                bool   isJoint = false;
                string id      = string.Empty;

                // Look at the attributes to check if this node is a joint
                foreach (XmlAttribute attribute in node.Attributes)
                {
                    if (attribute.Name == id_label)
                    {
                        id = attribute.Value;
                    }
                    if (attribute.Name == type && attribute.Value == JOINT)
                    {
                        isJoint = true;
                    }
                }

                if (isJoint) // found a child joint. Create the data, get the parent, add it to the rig
                {
                    ColladaJointData jointData = getColladaJointFromNode(node, id);

                    Quaternion lhsRotation = QuaternionHelper.RHStoLHS(jointData.RotationVector);
                    jointData.LHSTransformationMatrix =
                        Matrix4x4.TRS(new Vector3(-jointData.Translation.x, jointData.Translation.y, jointData.Translation.z),
                                      lhsRotation, Vector3.one);

                    // Get parent joint
                    if (parentJoint != null)
                    {
                        jointData.LHSWorldTransformationMatrix = parentJoint.LHSWorldTransformationMatrix * jointData.LHSTransformationMatrix;

                        rig.Add(id, parentJoint.Id, jointData);
                    }
                    else
                    {
                        rig.Add(id, jointData);
                    }

                    //  look for children joints.
                    addJointsToRig(rig, node, jointData);
                }
            }
        }
コード例 #2
0
        private static ColladaJointData getColladaJointFromNode(XmlNode xmlNode, string id)
        {
            ColladaJointData jointData = new ColladaJointData(id);

            Vector3 translation = Vector3.zero;
            float   xRotation   = 0f;
            float   yRotation   = 0f;
            float   zRotation   = 0f;

            foreach (XmlNode child in xmlNode.ChildNodes)
            {
                foreach (XmlAttribute attribute in child.Attributes)
                {
                    if (attribute.Name == "sid" && attribute.Value == "translate")
                    {
                        string[] values = child.InnerText.Split(' ');
                        for (int i = 0; i < values.Length; i++)
                        {
                            translation[i] = float.Parse(values[i], NumberStyles.Any, CultureInfo.InvariantCulture);
                        }
                    }
                    else if (attribute.Name == "sid" && (attribute.Value == "rotateZ" || attribute.Value == "jointOrientZ"))
                    {
                        string[] values = child.InnerText.Split(' ');
                        zRotation = float.Parse(values[3], NumberStyles.Any, CultureInfo.InvariantCulture);
                    }
                    else if (attribute.Name == "sid" && (attribute.Value == "rotateY" || attribute.Value == "jointOrientY"))
                    {
                        string[] values = child.InnerText.Split(' ');
                        yRotation = float.Parse(values[3], NumberStyles.Any, CultureInfo.InvariantCulture);
                    }
                    else if (attribute.Name == "sid" && (attribute.Value == "rotateX" || attribute.Value == "jointOrientX"))
                    {
                        string[] values = child.InnerText.Split(' ');
                        xRotation = float.Parse(values[3], NumberStyles.Any, CultureInfo.InvariantCulture);
                    }
                }
            }
            jointData.Translation    = translation;
            jointData.RotationVector = new Vector3(xRotation, yRotation, zRotation);
            jointData.Rotation       = Quaternion.Euler(jointData.RotationVector);

            return(jointData);
        }
コード例 #3
0
 /// <summary>
 /// Add a child node to the rig and specify the parent id.
 /// </summary>
 /// <param name="id"></param>
 /// <param name="parentId"></param>
 /// <param name="joint"></param>
 public void Add(string id, string parentId, ColladaJointData joint)
 {
     jointData.Add(id, joint);
     jointHierarchy.Add(id, parentId);
 }
コード例 #4
0
 /// <summary>
 /// Add a joint to the rig. This should be used to add the root node.
 /// </summary>
 /// <param name="id"></param>
 /// <param name="joint"></param>
 public void Add(string id, ColladaJointData joint)
 {
     jointData.Add(id, joint);
 }