コード例 #1
0
        public static BvhData Parse(BvhTokenizer tokenizer)
        {
            while (tokenizer.Current.Kind == BvhTokenizer.NewLineTokenKind)
            {
                tokenizer.MoveNext();
            }

            var rt = new BvhData();

            if (tokenizer.Current.Kind == BvhTokenizer.IdentifierTokenKind)
            {
                rt.Name = tokenizer.Current.Text;
                tokenizer.MoveNext();
            }

            rt.Values = tokenizer.StartWith(tokenizer.Current)
                        .TakeWhile(_ => _.Kind != BvhTokenizer.NewLineTokenKind && _.Kind != BvhTokenizer.BeginChildrenTokenKind)
                        .Select(_ => _.Text)
                        .ToList();

            if (tokenizer.Current.Kind == BvhTokenizer.NewLineTokenKind &&
                tokenizer.PeekNext().Kind == BvhTokenizer.BeginChildrenTokenKind)
            {
                tokenizer.MoveNext(BvhTokenizer.NewLineTokenKind);
                rt.Children = tokenizer.TakeWhile(_ => _.Kind != BvhTokenizer.EndChildrenTokenKind)
                              .Select(_ => Parse(tokenizer))
                              .ToList();
                tokenizer.MoveNext(BvhTokenizer.EndChildrenTokenKind);
            }

            return(rt);
        }
コード例 #2
0
ファイル: BvhDocument.cs プロジェクト: ZeusAFK/Keystone
        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);
        }
コード例 #3
0
        public BvhData Child(string name, bool createIfNotFound = true)
        {
            if (this.Children == null)
            {
                if (createIfNotFound)
                {
                    this.Children = new List <BvhData>();
                }
                else
                {
                    return(null);
                }
            }

            var value = this.Children.FirstOrDefault(_ => _.Name.Equals(name));

            if (createIfNotFound && value == null)
            {
                this.Children.Add(value = new BvhData
                {
                    Name = name,
                });
            }

            return(value);
        }
コード例 #4
0
ファイル: BvhData.cs プロジェクト: mfakane/Keystone
        public static BvhData Parse(BvhTokenizer tokenizer)
        {
            while (tokenizer.Current.Kind == BvhTokenizer.NewLineTokenKind)
                tokenizer.MoveNext();

            var rt = new BvhData();

            if (tokenizer.Current.Kind == BvhTokenizer.IdentifierTokenKind)
            {
                rt.Name = tokenizer.Current.Text;
                tokenizer.MoveNext();
            }

            rt.Values = tokenizer.StartWith(tokenizer.Current)
                                 .TakeWhile(_ => _.Kind != BvhTokenizer.NewLineTokenKind && _.Kind != BvhTokenizer.BeginChildrenTokenKind)
                                 .Select(_ => _.Text)
                                 .ToList();

            if (tokenizer.Current.Kind == BvhTokenizer.NewLineTokenKind &&
                tokenizer.PeekNext().Kind == BvhTokenizer.BeginChildrenTokenKind)
            {
                tokenizer.MoveNext(BvhTokenizer.NewLineTokenKind);
                rt.Children = tokenizer.TakeWhile(_ => _.Kind != BvhTokenizer.EndChildrenTokenKind)
                                       .Select(_ => Parse(tokenizer))
                                       .ToList();
                tokenizer.MoveNext(BvhTokenizer.EndChildrenTokenKind);
            }

            return rt;
        }
コード例 #5
0
ファイル: BvhJoint.cs プロジェクト: mfakane/Keystone
        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;
        }
コード例 #6
0
ファイル: BvhJoint.cs プロジェクト: mfakane/Keystone
        public BvhData ToData()
        {
            baseData = baseData ?? new BvhData();
            baseData.Name = this.Kind == BvhKind.End ? "End" : this.Kind.ToString().ToUpper();
            baseData.SetValues(this.Name);
            baseData.Child("OFFSET").SetValues(this.Offset.Select(_ => _.ToString("0.00")));

            if (this.Channels.Any())
                baseData.Child("CHANNELS").SetValues(new[] { this.Channels.Length.ToString() }.Concat(this.Channels.Select(_ => _.ToString()).Select(_ => _.Substring(0, 1).ToUpper() + _.Substring(1).ToLower())));
            else
                baseData.RemoveChildren("CHANNELS");

            baseData.RemoveChildren("JOINT");
            baseData.RemoveChildren("End");
            baseData.Children.AddRange(this.Children.Select(_ => _.ToData()));

            return baseData;
        }
コード例 #7
0
ファイル: BvhJoint.cs プロジェクト: ZeusAFK/Keystone
        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);
        }
コード例 #8
0
ファイル: BvhJoint.cs プロジェクト: ZeusAFK/Keystone
        public BvhData ToData()
        {
            baseData      = baseData ?? new BvhData();
            baseData.Name = this.Kind == BvhKind.End ? "End" : this.Kind.ToString().ToUpper();
            baseData.SetValues(this.Name);
            baseData.Child("OFFSET").SetValues(this.Offset.Select(_ => _.ToString("0.00")));

            if (this.Channels.Any())
            {
                baseData.Child("CHANNELS").SetValues(new[] { this.Channels.Length.ToString() }.Concat(this.Channels.Select(_ => _.ToString()).Select(_ => _.Substring(0, 1).ToUpper() + _.Substring(1).ToLower())));
            }
            else
            {
                baseData.RemoveChildren("CHANNELS");
            }

            baseData.RemoveChildren("JOINT");
            baseData.RemoveChildren("End");
            baseData.Children.AddRange(this.Children.Select(_ => _.ToData()));

            return(baseData);
        }
コード例 #9
0
ファイル: BvhData.cs プロジェクト: mfakane/Keystone
        public BvhData Child(string name, bool createIfNotFound = true)
        {
            if (this.Children == null)
                if (createIfNotFound)
                    this.Children = new List<BvhData>();
                else
                    return null;

            var value = this.Children.FirstOrDefault(_ => _.Name.Equals(name));

            if (createIfNotFound && value == null)
                this.Children.Add(value = new BvhData
                {
                    Name = name,
                });

            return value;
        }