Example #1
0
        public static Bvh Parse(string src)
        {
            using (var r = new StringReader(src))
            {
                if (r.ReadLine() != "HIERARCHY")
                {
                    throw new BvhException("not start with HIERARCHY");
                }

                var root = ParseNode(r);

                if (root == null)
                {
                    return(null);
                }

                var frames    = 0;
                var frameTime = 0.0f;
                if (r.ReadLine() == "MOTION")
                {
                    var      tmp = r.ReadLine();
                    string[] frameSplited;
                    if (tmp.Split(':')[0] != "Frames")
                    {
                        frameSplited = r.ReadLine().Split(':');
                    }
                    else
                    {
                        frameSplited = tmp.Split(':');
                    }

                    if (frameSplited[0] != "Frames")
                    {
                        throw new BvhException("Frames is not found");
                    }

                    frames = int.Parse(frameSplited[1]);

                    var frameTimeSplited = r.ReadLine().Split(':');

                    if (frameTimeSplited[0] != "Frame Time")
                    {
                        throw new BvhException("Frame Time is not found");
                    }

                    frameTime = float.Parse(frameTimeSplited[1], CultureInfo.InvariantCulture.NumberFormat);
                }

                var bvh = new Bvh(root, frames, frameTime);

                for (int i = 0; i < frames; ++i)
                {
                    var line = r.ReadLine();
                    bvh.ParseFrame(i, line);
                }

                return(bvh);
            }
        }
Example #2
0
File: Bvh.cs Project: vrm-c/UniVRM
        public static Bvh Parse(string src)
        {
            using (var r = new StringReader(src))
            {
                var first = r.ReadLine();
                if (first != "HIERARCHY")
                {
                    throw new BvhException("not start with HIERARCHY");
                }

                var root = ParseNode(r);
                if (root == null)
                {
                    return(null);
                }

                var frames    = 0;
                var frameTime = 0.0f;
                if (r.ReadLine() == "MOTION")
                {
                    var frameSplit = r.ReadLine().Split(':');
                    if (frameSplit[0] != "Frames")
                    {
                        throw new BvhException("Frames is not found");
                    }
                    frames = int.Parse(frameSplit[1]);

                    var frameTimeSplit = r.ReadLine().Split(':');
                    if (frameTimeSplit[0] != "Frame Time")
                    {
                        throw new BvhException("Frame Time is not found");
                    }
                    frameTime = float.Parse(frameTimeSplit[1], System.Globalization.CultureInfo.InvariantCulture);
                }

                var bvh = new Bvh(root, frames, frameTime);

                for (int i = 0; i < frames; ++i)
                {
                    var line = r.ReadLine();
                    bvh.ParseFrame(i, line);
                }

                return(bvh);
            }
        }
Example #3
0
        public static Bvh Parse(string src)
        {
            using (var r = new StringReader(src))
            {
                if (r.ReadLine() != "HIERARCHY")
                {
                    throw new BvhException("not start with HIERARCHY");
                }

                var root = ParseNode(r);
                if (root == null)
                {
                    return(null);
                }

                if (r.ReadLine() != "MOTION")
                {
                    throw new BvhException("MOTION is not found");
                }

                var frameSplited = r.ReadLine().Split(':');
                if (frameSplited[0] != "Frames")
                {
                    throw new BvhException("Frames is not found");
                }
                var frames = int.Parse(frameSplited[1]);

                var frameTimeSplited = r.ReadLine().Split(':');
                if (frameTimeSplited[0] != "Frame Time")
                {
                    throw new BvhException("Frame Time is not found");
                }
                var frameTime = float.Parse(frameTimeSplited[1]);

                var bvh = new Bvh(root, frames, frameTime);

                for (int i = 0; i < frames; ++i)
                {
                    var line = r.ReadLine();
                    bvh.ParseFrame(i, line);
                }

                return(bvh);
            }
        }