コード例 #1
0
        public static BVHNode ToBVHData(Bone node, MotionData motionData, out BVHMotionData bvhMotionData)
        {
            Dictionary <BVHNode, List <Quaternion> > data = new Dictionary <BVHNode, List <Quaternion> >();
            var resultNode = ToBVHNode(node, motionData.Data, null, data);

            bvhMotionData = new BVHMotionData(1.0 / motionData.FPS, data);

            return(resultNode);
        }
コード例 #2
0
        /// <summary>
        /// reads BVH hierarchical data from a BVH file
        /// </summary>
        public static BVHNode ReadBvh(string file, out BVHMotionData motionData)
        {
            using (var reader = new StreamReader(file))
            {
                var line = reader.ReadLine().ToLower().Trim();
                if (line != "hierarchy")
                {
                    throw new FileFormatException("File has to start with HIERARCHY keyword");
                }

                var root = ReadNode(reader, reader.ReadLine(), 0);
                motionData = ReadMotionData(reader, root);

                return(root);
            }
        }
コード例 #3
0
        /// <summary>
        /// converts BVH hierarchical structure to the applications own kinematic model definition
        /// </summary>
        public static Bone ToBones(BVHNode bvhNode, Bone parent, BVHMotionData bvhMotionData,
                                   MotionData resultMotionData)
        {
            Bone result = new Bone(parent, name: bvhNode.Name, offset: bvhNode.Offset);

            if (bvhNode.Type != BVHNodeTypes.EndSite)
            {
                resultMotionData.Data.Add(result, bvhMotionData.Data[bvhNode].ToList());
            }

            foreach (BVHNode item in bvhNode.Children)
            {
                result.Children.Add(ToBones(item, result, bvhMotionData, resultMotionData));
            }

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Writes a BVH motion data file
        /// </summary>
        public static void WriteBvh(string file, BVHNode root, BVHMotionData motionData)
        {
            using (var writer = new StreamWriter(file))
            {
                writer.WriteLine("HIERARCHY");
                WriteBvhNode(root, writer, 0);
                writer.WriteLine("MOTION");

                int numFrames = motionData.Data.First().Value.Count;
                writer.WriteLine($"Frames: {numFrames}");
                writer.WriteLine($"Frame Time: {motionData.FrameTime}");
                for (int i = 0; i < numFrames; i++)
                {
                    foreach (var node in motionData.Data.Keys)
                    {
                        double yaw, pitch, roll;
                        motionData.Data[node][i].ToYawPitchRoll(out yaw, out pitch, out roll);

                        writer.Write($"{yaw * 180 / Math.PI} {pitch * 180 / Math.PI} {roll * 180 / Math.PI} ");
                    }
                    writer.WriteLine();
                }
            }
        }