public BvhNode(BvhHierarchy hierarchy, BvhNode parent, BvhNodeType type = BvhNodeType.NONE, string name = "my_node") { this.hierarchy = hierarchy; this.parent = parent; this.type = type; this.name = name; }
public BvhNode AddNewNode(BvhNode parent, BvhNodeType type, string name) { BvhNode newNode = new BvhNode(this, parent, type, name); nodes.Add(newNode); return(newNode); }
public int RegisterChannels(int number, BvhNode node) { int startIndex = channelIndex; for (int i = 0; i < number; i++) { channelNodes.Add(channelIndex, node); channelIndex++; } return(startIndex); }
public BvhNode AddChild(BvhNode childNode) { children.Add(childNode); return(childNode); }
public static BvhHierarchy FromFileData(string fileData) { BvhHierarchy hierarchy = new BvhHierarchy(); BvhNode currentNode = null; Section currentSection = Section.NONE; string[] lines = fileData.Split('\n'); // Loop each line in file foreach (string str in lines) { string str_noTab = Regex.Replace(str, @"\t", ""); // get rid of '\t' List <string> args = str_noTab.Split(' ').ToList(); if (args.Count == 0) { continue; } try { switch (args[0].Trim()) { case "": break; case "HIERARCHY": currentSection = Section.HIERARCHY; break; case "MOTION": currentSection = Section.MOTION; break; case "ROOT": currentNode = hierarchy.AddNewNode(null, BvhNodeType.ROOT, args[1]); break; case "JOINT": currentNode = currentNode.AddChild(hierarchy.AddNewNode(currentNode, BvhNodeType.JOINT, args[1])); break; case "End": currentNode = currentNode.AddChild(hierarchy.AddNewNode(currentNode, BvhNodeType.ENDSITE, "_end")); break; case "OFFSET": currentNode.SetOffset(args[1], args[2], args[3]); break; case "CHANNELS": List <string> names = new List <string>(args); names.RemoveRange(0, 2); currentNode.SetChannels(args[1], names); break; case "{": break; case "}": if (currentNode.type != BvhNodeType.ROOT) { currentNode = currentNode.parent; } break; case "Frames:": hierarchy.frameNumber = int.Parse(args[1]); break; case "Frame": hierarchy.frameTime = float.Parse(args[2]); break; default: // Number lines if (currentSection == Section.MOTION) { if (!TryParsingNumbers(hierarchy, args)) { Debug.LogWarning("Grammar not desired: " + str_noTab); } } else { Debug.Log(args[0][9].ToString()); Debug.LogWarning("Grammar not desired: " + str_noTab); } break; } }catch (Exception err) { Debug.Log(err); Debug.Log("Error in load BVH: in " + str_noTab); } } return(hierarchy); }