public ColladaAnimationData(ColladaRigData rig)
 {
     foreach (KeyValuePair <string, ColladaJointData> jointData in rig.JointData)
     {
         this.joints.Add(jointData.Key);
         this.jointTranslateX.Add(jointData.Key, string.Empty);
         this.jointTranslateY.Add(jointData.Key, string.Empty);
         this.jointTranslateZ.Add(jointData.Key, string.Empty);
         this.jointRotateX.Add(jointData.Key, string.Empty);
         this.jointRotateY.Add(jointData.Key, string.Empty);
         this.jointRotateZ.Add(jointData.Key, string.Empty);
         this.jointValues.Add(jointData.Key, string.Empty);
     }
 }
Пример #2
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);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Provides rig data associated with a given COLLADA file.
        /// </summary>
        /// <param name="FilePath">The filepath of the COLLADA to be opened.</param>
        /// <returns>The ColladaRigData</returns>
        public static ColladaRigData ReadRigData(string FilePath)
        {
            ColladaRigData rigData = new ColladaRigData();

            XmlDocument colladaDocument = new XmlDocument();

            colladaDocument.Load(FilePath);

            XmlNodeList visualSceneNodes = colladaDocument.GetElementsByTagName("visual_scene");

            if (visualSceneNodes.Count > 0)
            {
                // We will just use the first one we find.
                XmlNode visualScene = visualSceneNodes.Item(0);

                // Add nodes to the rig recursively.
                addJointsToRig(rigData, visualScene, null);
            }

            return(rigData);
        }