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); }
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; }
public static BvhMotion Parse(BvhDocument doc, BvhTokenizer tokenizer) { var rt = new BvhMotion(); if (tokenizer.Current.EnsureKind(BvhTokenizer.IdentifierTokenKind).Text == "MOTION") tokenizer.MoveNext(); tokenizer.MoveNext(BvhTokenizer.NewLineTokenKind); var frames = tokenizer.Current.EnsureKind(BvhTokenizer.IdentifierTokenKind).Text == "Frames" ? int.Parse(tokenizer.MoveNext().Text) : 0; tokenizer.MoveNext(); tokenizer.MoveNext(BvhTokenizer.NewLineTokenKind); if (tokenizer.Current.EnsureKind(BvhTokenizer.IdentifierTokenKind).Text == "Frame") tokenizer.MoveNext(); rt.FrameTime = tokenizer.Current.EnsureKind(BvhTokenizer.IdentifierTokenKind).Text == "Time" ? float.Parse(tokenizer.MoveNext().Text) : 0; tokenizer.MoveNext(); var joints = GetJoints(doc.Root).ToArray(); for (int i = 0; i < frames; i++) { var values = tokenizer.TakeWhile(_ => _.Kind != BvhTokenizer.NewLineTokenKind).Select(_ => _.Text).Select(float.Parse).ToArray(); var j = 0; rt.Frames.Add(joints.ToDictionary(_ => _, _ => { var jm = new BvhJointMotion(); var position = new float[3]; var rotation = new float[3]; foreach (var c in _.Channels) switch (c) { case BvhChannel.XPosition: case BvhChannel.YPosition: case BvhChannel.ZPosition: jm.Position = position; position[(int)c] = values[j++]; break; case BvhChannel.XRotation: case BvhChannel.YRotation: case BvhChannel.ZRotation: jm.Rotation = rotation; rotation[c - BvhChannel.XRotation] = values[j++]; break; } return jm; })); } return rt; }
public static BvhMotion Parse(BvhDocument doc, BvhTokenizer tokenizer) { var rt = new BvhMotion(); if (tokenizer.Current.EnsureKind(BvhTokenizer.IdentifierTokenKind).Text == "MOTION") { tokenizer.MoveNext(); } tokenizer.MoveNext(BvhTokenizer.NewLineTokenKind); var frames = tokenizer.Current.EnsureKind(BvhTokenizer.IdentifierTokenKind).Text == "Frames" ? int.Parse(tokenizer.MoveNext().Text) : 0; tokenizer.MoveNext(); tokenizer.MoveNext(BvhTokenizer.NewLineTokenKind); if (tokenizer.Current.EnsureKind(BvhTokenizer.IdentifierTokenKind).Text == "Frame") { tokenizer.MoveNext(); } rt.FrameTime = tokenizer.Current.EnsureKind(BvhTokenizer.IdentifierTokenKind).Text == "Time" ? float.Parse(tokenizer.MoveNext().Text) : 0; tokenizer.MoveNext(); var joints = GetJoints(doc.Root).ToArray(); for (int i = 0; i < frames; i++) { var values = tokenizer.TakeWhile(_ => _.Kind != BvhTokenizer.NewLineTokenKind).Select(_ => _.Text).Select(float.Parse).ToArray(); var j = 0; rt.Frames.Add(joints.ToDictionary(_ => _, _ => { var jm = new BvhJointMotion(); var position = new float[3]; var rotation = new float[3]; foreach (var c in _.Channels) { switch (c) { case BvhChannel.XPosition: case BvhChannel.YPosition: case BvhChannel.ZPosition: jm.Position = position; position[(int)c] = values[j++]; break; case BvhChannel.XRotation: case BvhChannel.YRotation: case BvhChannel.ZRotation: jm.Rotation = rotation; rotation[c - BvhChannel.XRotation] = values[j++]; break; } } return(jm); })); } return(rt); }