Пример #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="fileName"></param>
        public void DumpContents(string fileName)
        {
            FileStream fs = File.Open(fileName, FileMode.Create);
            StreamWriter writer = new StreamWriter(fs);
            writer.AutoFlush = true;

            writer.WriteLine("-= Debug output of skeleton  {0} =-", this.name);
            writer.WriteLine("");
            writer.WriteLine("== Bones ==");
            writer.WriteLine("Number of bones: {0}", boneList.Count);

            Quaternion q = new Quaternion();
            float angle = 0;
            Vector3 axis = new Vector3();

            // write each bone out
            foreach (Bone bone in boneList.Values) {
                writer.WriteLine("-- Bone {0} --", bone.Handle);
                writer.Write("Position: {0}", bone.Position);
                q = bone.Orientation;
                writer.Write("Rotation: {0}", q);
                q.ToAngleAxis(ref angle, ref axis);
                writer.Write(" = {0} radians around axis {1}", angle, axis);
                writer.WriteLine(""); writer.WriteLine("");
            }

            writer.WriteLine("== Animations ==");
            writer.WriteLine("Number of animations: {0}", animationList.Count);

            // animations
            foreach(Animation anim in animationList) {
                writer.WriteLine("-- Animation '{0}' (length {1}) --", anim.Name, anim.Length);
                writer.WriteLine("Number of tracks: {0}", anim.NodeTracks.Count);

                // tracks
                foreach(NodeAnimationTrack track in anim.NodeTracks.Values) {
                    writer.WriteLine("  -- AnimationTrack {0} --", track.Handle);
                    writer.WriteLine("  Affects bone: {0}", ((Bone)track.TargetNode).Handle);
                    writer.WriteLine("  Number of keyframes: {0}", track.KeyFrames.Count);

                    // key frames
                    int kf = 0;
                    for(ushort i=0; i<track.KeyFrames.Count; i++) {
                        TransformKeyFrame keyFrame = track.GetNodeKeyFrame(i);
                        writer.WriteLine("    -- KeyFrame {0} --", kf++);
                        writer.Write("    Time index: {0}", keyFrame.Time);
                        writer.WriteLine("    Translation: {0}", keyFrame.Translate);
                        q = keyFrame.Rotation;
                        writer.Write("    Rotation: {0}", q);
                        q.ToAngleAxis(ref angle, ref axis);
                        writer.WriteLine(" = {0} radians around axis {1}", angle, axis);
                    }
                }
            }

            writer.Close();
            fs.Close();
        }
 protected XmlElement WriteQuaternion(string elementName, Quaternion rot)
 {
     Vector3 axis = new Vector3();
     float angle = 0;
     rot.ToAngleAxis(ref angle, ref axis);
     XmlElement node = document.CreateElement(elementName);
     XmlAttribute attr;
     attr = document.CreateAttribute("angle");
     if (angle >= Math.PI &&
         2 * (float)Math.PI - angle < (float)Math.PI)
     {
         angle = 2 * (float)Math.PI - angle;
         axis = -1 * axis;
         Debug.Assert(angle < Math.PI);
     }
     Debug.Assert(angle < Math.PI + .0001);
     attr.Value = angle.ToString();
     node.Attributes.Append(attr);
     XmlElement childNode = WriteAxis(axis);
     node.AppendChild(childNode);
     return node;
 }
 public XmlNode WriteRotate(Quaternion rot, XmlDocument document)
 {
     XmlNode node = document.CreateElement("rotate");
     float angle = 0;
     Vector3 axis = Vector3.Zero;
     rot.ToAngleAxis(ref angle, ref axis);
     float degrees = MathUtil.RadiansToDegrees(angle);
     node.InnerText = string.Format("{0} {1} {2} {3}", axis.x, axis.y, axis.z, degrees);
     return node;
 }