/// <summary> /// Read a transformation matrix and attach to the current frame /// </summary> /// <param name="node"></param> /// <param name="depth"></param> /// <param name="thisFrame"></param> private static void LoadTransformationMatrix(XFileData node, int depth, JointFrame thisFrame) { try { // Debug.WriteLine(Depth(depth) + "Creating Matrix for "+thisFrame.Name); GraphicsStream stream = node.Lock(); // access the data stream thisFrame.TransformationMatrix = MatrixFromXFile(stream); // read in the matrix node.Unlock(); } catch (Exception e) { Debug.WriteLine("Error reading transformation matrix: "+e.ToString()); throw; } }
/// <summary> /// Read an AnimationKey node and load its transformation into the given frame /// </summary> /// <param name="node"></param> /// <param name="frame"></param> private static void LoadKeyframes(XFileData node, JointFrame frame) { int keyType = 0, keyFrames = 0; int keyTime = 0, keyValues = 0; Quaternion q = new Quaternion(); Vector3 v = new Vector3(); GraphicsStream stream = node.Lock(); // Lock the node and obtain a stream keyType = (int)stream.Read(keyType.GetType()); // get the keyframe type (rotation, etc.) keyFrames = (int)stream.Read(keyFrames.GetType()); // get the number of keyframes (should be 2) if (keyFrames>2) throw new Exception("XFile "+filespec+" should have only two keyframes per animation"); for (int i=0; i<keyFrames; i++) { keyTime = (int)stream.Read(keyTime.GetType()); // time of key (ignored) keyValues = (int)stream.Read(keyValues.GetType()); // number of values in key (ignored) switch (keyType) { // Rotation case 0: q = ReadQuaternion(stream); // get the transformation if (rmin == false) // store it in min or max { motion.RotationMin = q; // (min first, then max if min is full) motion.RotationMax = q; // (fill max too in case no 2nd key) rmin = true; } else motion.RotationMax = q; break; // Translation case 1: v = ReadVector(stream); if (smin == false) { motion.ScaleMin = v; motion.ScaleMax = v; smin = true; } else motion.ScaleMax = v; break; // Scale case 2: v = ReadVector(stream); if (tmin == false) { motion.TranslationMin = v; motion.TranslationMax = v; tmin = true; } else motion.TranslationMax = v; break; } } node.Unlock(); // release the node }