Ejemplo n.º 1
0
        public static BvhDocument Parse(string text)
        {
            var rt        = new BvhDocument();
            var tokenizer = new BvhTokenizer(text);
            var header    = new[] { "HIERARCHY" };

            if (!tokenizer.Take(header.Length).Select(_ => _.Text).SequenceEqual(header))
            {
                throw new InvalidOperationException("invalid format");
            }

            foreach (var i in tokenizer)
            {
                if (i.Kind == BvhTokenizer.IdentifierTokenKind)
                {
                    switch (i.Text)
                    {
                    case "ROOT":
                        rt.Root = BvhJoint.Parse(BvhData.Parse(tokenizer));

                        break;

                    case "MOTION":
                        rt.Motion = BvhMotion.Parse(rt, tokenizer);

                        break;
                    }
                }
            }

            return(rt);
        }
Ejemplo n.º 2
0
        public static BvhJoint Parse(BvhData data)
        {
            var rt = new BvhJoint
            {
                baseData = data,
                Kind = (BvhKind)Enum.Parse(typeof(BvhKind), data.Name, true),
                Name = data.Values.First(),
                Offset = data.Child("OFFSET").Values.Select(_ => float.Parse(_)).ToArray(),
                Channels = data.Child("CHANNELS").Values.Skip(1).Select(_ => (BvhChannel)Enum.Parse(typeof(BvhChannel), _, true)).ToArray(),
            };

            foreach (var i in data.Children)
                if (i.Name == "JOINT" || i.Name == "End")
                    rt.Children.Add(Parse(i));

            return rt;
        }
Ejemplo n.º 3
0
        public static BvhJoint Parse(BvhData data)
        {
            var rt = new BvhJoint
            {
                baseData = data,
                Kind     = (BvhKind)Enum.Parse(typeof(BvhKind), data.Name, true),
                Name     = data.Values.First(),
                Offset   = data.Child("OFFSET").Values.Select(_ => float.Parse(_)).ToArray(),
                Channels = data.Child("CHANNELS").Values.Skip(1).Select(_ => (BvhChannel)Enum.Parse(typeof(BvhChannel), _, true)).ToArray(),
            };

            foreach (var i in data.Children)
            {
                if (i.Name == "JOINT" || i.Name == "End")
                {
                    rt.Children.Add(Parse(i));
                }
            }

            return(rt);
        }
Ejemplo n.º 4
0
 static IEnumerable<BvhJoint> GetJoints(BvhJoint item)
 {
     return new[] { item }.Concat(item.Children.SelectMany(GetJoints));
 }
Ejemplo n.º 5
0
 static IEnumerable <BvhJoint> GetJoints(BvhJoint item)
 {
     return(new[] { item }.Concat(item.Children.SelectMany(GetJoints)));
 }