public BVHData Parse(TextAsset BVHFile) { lines = BVHFile.text.Split('\n'); currLine = 0; currChannelIndex = 0; parsedData = new BVHData(); string[] line; while ((line = getNextLine()) != null) { if (line[KEYWORD] == "HIERARCHY") { ParseHierarchySection(); } else if (line[KEYWORD] == "MOTION") { ParseMotionSection(); } else { PrintError("Unkown command in BVH data"); } } Debug.Log("Finished Parsing BVH"); return(parsedData); }
// Start is called before the first frame update void Start() { BVHParser parser = new BVHParser(); data = parser.Parse(BVHFile); CreateJoint(data.rootJoint, Vector3.zero); }
public SimBody(BVHData bvhData, BodyData bodyData) { BVHData = bvhData; BodyData = bodyData; bvhLimits = new BVHLimits(bvhData); //bvhLimits.FitAnimation(); bvhLimits.ExpandToAnimation(false); }
void Start() { bvhData = new BVHParser().Parse(bvhFilePath); // move hips up bvhData.Skeletons[0].Offset = new Vector3(0, 35f, 0); BodyData bodyData = new BodyData(); simBody = new SimBody(bvhData, bodyData); GameObject simBodyGO = new GameObject { name = "Sim Body" }; simBodyGO.transform.parent = transform; simBodyGO.transform.localPosition = Vector3.right * 5f; GameObject simOriginSphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); simOriginSphere.transform.parent = simBodyGO.transform; simOriginSphere.transform.localPosition = Vector3.zero; simOriginSphere.transform.localScale = Vector3.one * 0.5f; if (simMaterial) { simOriginSphere.GetComponent <Renderer>().material = simMaterial; } simOriginSphere.GetComponent <Collider>().enabled = false; simBody.Material = simMaterial; simBody.Generate(simBodyGO.transform); refBody = new RefBody(bvhData, bodyData); GameObject refBodyGO = new GameObject { name = "Ref Body" }; refBodyGO.transform.parent = transform; refBodyGO.transform.localPosition = Vector3.left * 5f; GameObject refOriginSphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); refOriginSphere.transform.parent = refBodyGO.transform; refOriginSphere.transform.localPosition = Vector3.zero; refOriginSphere.transform.localScale = Vector3.one * 0.5f; if (refMaterial) { refOriginSphere.GetComponent <Renderer>().material = refMaterial; } refOriginSphere.GetComponent <Collider>().enabled = false; refBody.Material = refMaterial; refBody.Generate(refBodyGO.transform); }
public void Load(string path) { Name = path.Substring(path.LastIndexOf("/") + 1); string[] lines = File.ReadAllLines(path); char[] whitespace = new char[] { ' ' }; int index = 0; //Read BVH Source = new BVHData(); string name = string.Empty; string parent = string.Empty; Vector3 offset = Vector3.zero; int[] channels = null; for (index = 0; index < lines.Length; index++) { if (lines[index] == "MOTION") { break; } string[] entries = lines[index].Split(whitespace); for (int entry = 0; entry < entries.Length; entry++) { if (entries[entry].Contains("ROOT")) { parent = "None"; name = entries[entry + 1]; break; } else if (entries[entry].Contains("JOINT")) { parent = name; name = entries[entry + 1]; break; } else if (entries[entry].Contains("End")) { parent = name; name = name + entries[entry + 1]; string[] subEntries = lines[index + 2].Split(whitespace); for (int subEntry = 0; subEntry < subEntries.Length; subEntry++) { if (subEntries[subEntry].Contains("OFFSET")) { offset.x = Utility.ReadFloat(subEntries[subEntry + 1]); offset.y = Utility.ReadFloat(subEntries[subEntry + 2]); offset.z = Utility.ReadFloat(subEntries[subEntry + 3]); break; } } Source.AddBone(name, parent, offset, new int[0]); index += 2; break; } else if (entries[entry].Contains("OFFSET")) { offset.x = Utility.ReadFloat(entries[entry + 1]); offset.y = Utility.ReadFloat(entries[entry + 2]); offset.z = Utility.ReadFloat(entries[entry + 3]); break; } else if (entries[entry].Contains("CHANNELS")) { channels = new int[Utility.ReadInt(entries[entry + 1])]; for (int i = 0; i < channels.Length; i++) { if (entries[entry + 2 + i] == "Xposition") { channels[i] = 1; } else if (entries[entry + 2 + i] == "Yposition") { channels[i] = 2; } else if (entries[entry + 2 + i] == "Zposition") { channels[i] = 3; } else if (entries[entry + 2 + i] == "Xrotation") { channels[i] = 4; } else if (entries[entry + 2 + i] == "Yrotation") { channels[i] = 5; } else if (entries[entry + 2 + i] == "Zrotation") { channels[i] = 6; } } Source.AddBone(name, parent, offset, channels); break; } else if (entries[entry].Contains("}")) { name = parent; parent = name == "None" ? "None" : Source.FindBone(name).Parent; break; } } } //Read frame count index += 1; while (lines[index].Length == 0) { index += 1; } ArrayExtensions.Resize(ref Frames, Utility.ReadInt(lines[index].Substring(8))); //Read frame time index += 1; Framerate = Mathf.RoundToInt(1f / Utility.ReadFloat(lines[index].Substring(12))); //Read motions index += 1; for (int i = index; i < lines.Length; i++) { Source.AddMotion(Utility.ReadArray(lines[i])); } //Detect settings DetectHips(); DetectHead(); DetectSymmetry(); //Create frames for (int i = 0; i < GetTotalFrames(); i++) { Frames[i] = new Frame(this, i + 1, (float)i / Framerate); } //Generate Generate(); }
public MotionData Create(string path, string currentDirectory) { Name = path.Substring(path.LastIndexOf("/") + 1); if (AssetDatabase.LoadAssetAtPath(currentDirectory + Name + ".asset", typeof(MotionData)) == null) { AssetDatabase.CreateAsset(this, currentDirectory + Name + ".asset"); } else { int i = 1; while (AssetDatabase.LoadAssetAtPath(currentDirectory + Name + Name + " (" + i + ").asset", typeof(MotionData)) != null) { i += 1; } AssetDatabase.CreateAsset(this, currentDirectory + Name + Name + " (" + i + ").asset"); } string[] lines = File.ReadAllLines(path); char[] whitespace = new char[] { ' ' }; int index = 0; //Read BVH Source = new BVHData(); string name = string.Empty; string parent = string.Empty; Vector3 offset = Vector3.zero; int[] channels = null; for (index = 0; index < lines.Length; index++) { if (lines[index] == "MOTION") { break; } string[] entries = lines[index].Split(whitespace); for (int entry = 0; entry < entries.Length; entry++) { if (entries[entry].Contains("ROOT")) { parent = "None"; name = entries[entry + 1]; break; } else if (entries[entry].Contains("JOINT")) { parent = name; name = entries[entry + 1]; break; } else if (entries[entry].Contains("End")) { parent = name; name = name + entries[entry + 1]; string[] subEntries = lines[index + 2].Split(whitespace); for (int subEntry = 0; subEntry < subEntries.Length; subEntry++) { if (subEntries[subEntry].Contains("OFFSET")) { offset.x = Utility.ReadFloat(subEntries[subEntry + 1]); offset.y = Utility.ReadFloat(subEntries[subEntry + 2]); offset.z = Utility.ReadFloat(subEntries[subEntry + 3]); break; } } Source.AddBone(name, parent, offset, new int[0]); index += 2; break; } else if (entries[entry].Contains("OFFSET")) { offset.x = Utility.ReadFloat(entries[entry + 1]); offset.y = Utility.ReadFloat(entries[entry + 2]); offset.z = Utility.ReadFloat(entries[entry + 3]); break; } else if (entries[entry].Contains("CHANNELS")) { channels = new int[Utility.ReadInt(entries[entry + 1])]; for (int i = 0; i < channels.Length; i++) { if (entries[entry + 2 + i] == "Xposition") { channels[i] = 1; } else if (entries[entry + 2 + i] == "Yposition") { channels[i] = 2; } else if (entries[entry + 2 + i] == "Zposition") { channels[i] = 3; } else if (entries[entry + 2 + i] == "Xrotation") { channels[i] = 4; } else if (entries[entry + 2 + i] == "Yrotation") { channels[i] = 5; } else if (entries[entry + 2 + i] == "Zrotation") { channels[i] = 6; } } Source.AddBone(name, parent, offset, channels); break; } else if (entries[entry].Contains("}")) { name = parent; parent = name == "None" ? "None" : Source.FindBone(name).Parent; break; } } } //Read frame count index += 1; while (lines[index].Length == 0) { index += 1; } ArrayExtensions.Resize(ref Frames, Utility.ReadInt(lines[index].Substring(8))); //Read frame time index += 1; Framerate = Mathf.RoundToInt(1f / Utility.ReadFloat(lines[index].Substring(12))); //Read motions index += 1; for (int i = index; i < lines.Length; i++) { Source.AddMotion(Utility.ReadArray(lines[i])); } //Detect settings DetectHeightMapSensor(); DetectDepthMapSensor(); DetectSymmetry(); DetectCorrections(); //Create frames for (int i = 0; i < GetTotalFrames(); i++) { Frames[i] = new Frame(this, i + 1, (float)i / Framerate); } //Generate ComputePostures(); ComputeStyles(); AddSequence(); //Finish return(this); }
public RefBody(BVHData bvhData, BodyData bodyData) { BVHData = bvhData; BodyData = bodyData; }
public BVHLimits(BVHData bvhData) { this.bvhData = bvhData; Limits = new Dictionary <string, BVHElementLimit>(); // default limits // (left and right reversed) Limits["Hips"] = new BVHElementLimit { AngularXLow = -180f, AngularXHigh = 180f, AngularYLow = -180f, AngularYHigh = 180f, AngularZLow = -180f, AngularZHigh = 180f }; Limits["LeftUpLeg"] = new BVHElementLimit { AngularXLow = -65f, AngularXHigh = 30f, AngularYLow = -45f, AngularYHigh = 48f, AngularZLow = -15f, AngularZHigh = 45f }; Limits["LeftLeg"] = new BVHElementLimit { AngularXLow = -3f, AngularXHigh = 150f, AngularYLow = -15f, AngularYHigh = 15f, AngularZLow = 0f, AngularZHigh = 0f }; Limits["LeftFoot"] = new BVHElementLimit { AngularXLow = -25f, AngularXHigh = 35f, AngularYLow = -19f, AngularYHigh = 15f, AngularZLow = -22f, AngularZHigh = 16f }; Limits["RightUpLeg"] = new BVHElementLimit { AngularXLow = -65f, AngularXHigh = 30f, AngularYLow = -48f, AngularYHigh = 45f, AngularZLow = -45f, AngularZHigh = 15f }; Limits["RightLeg"] = new BVHElementLimit { AngularXLow = -3f, AngularXHigh = 150f, AngularYLow = -15f, AngularYHigh = 15f, AngularZLow = 0f, AngularZHigh = 0f }; Limits["RightFoot"] = new BVHElementLimit { AngularXLow = -25f, AngularXHigh = 35f, AngularYLow = -15f, AngularYHigh = 19f, AngularZLow = -16f, AngularZHigh = 22f }; Limits["Spine"] = new BVHElementLimit { AngularXLow = -25f, AngularXHigh = 45f, AngularYLow = -25f, AngularYHigh = 25f, AngularZLow = -20f, AngularZHigh = 20f }; Limits["Spine1"] = new BVHElementLimit { AngularXLow = -27f, AngularXHigh = 40f, AngularYLow = -20f, AngularYHigh = 20f, AngularZLow = -20f, AngularZHigh = 20f }; Limits["Neck"] = new BVHElementLimit { AngularXLow = -20f, AngularXHigh = 20f, AngularYLow = -25f, AngularYHigh = 25f, AngularZLow = -10f, AngularZHigh = 10f }; Limits["Head"] = new BVHElementLimit { AngularXLow = -35f, AngularXHigh = 17f, AngularYLow = -12f, AngularYHigh = 12f, AngularZLow = -15f, AngularZHigh = 15f }; Limits["LeftShoulder"] = new BVHElementLimit { AngularXLow = 0f, AngularXHigh = 0f, AngularYLow = -30f, AngularYHigh = 30f, AngularZLow = -12f, AngularZHigh = 31f }; Limits["LeftArm"] = new BVHElementLimit { AngularXLow = -30f, AngularXHigh = 35f, AngularYLow = -45f, AngularYHigh = 35f, AngularZLow = -85f, AngularZHigh = 45f }; // angularY 15 -> 3 Limits["LeftForeArm"] = new BVHElementLimit { AngularXLow = -85f, AngularXHigh = 45f, AngularYLow = -130f, AngularYHigh = 3f, AngularZLow = 0f, AngularZHigh = 0f }; Limits["LeftHand"] = new BVHElementLimit { AngularXLow = 0f, AngularXHigh = 0f, AngularYLow = -20f, AngularYHigh = 20f, AngularZLow = -80f, AngularZHigh = 70f }; Limits["RightShoulder"] = new BVHElementLimit { AngularXLow = 0f, AngularXHigh = 0f, AngularYLow = -30f, AngularYHigh = 30f, AngularZLow = -31f, AngularZHigh = 12f }; Limits["RightArm"] = new BVHElementLimit { AngularXLow = -30f, AngularXHigh = 35f, AngularYLow = -35f, AngularYHigh = 45f, AngularZLow = -45f, AngularZHigh = 85f }; // angularY 15 -> 3 Limits["RightForeArm"] = new BVHElementLimit { AngularXLow = -85f, AngularXHigh = 45f, AngularYLow = -3f, AngularYHigh = 130f, AngularZLow = 0f, AngularZHigh = 0f }; Limits["RightHand"] = new BVHElementLimit { AngularXLow = 0f, AngularXHigh = 0f, AngularYLow = -20f, AngularYHigh = 20f, AngularZLow = -70f, AngularZHigh = 80f }; // from data Limits["LeftToeBase"] = new BVHElementLimit { AngularXLow = -28f, AngularXHigh = 32f, AngularYLow = 0f, AngularYHigh = 0f, AngularZLow = 0f, AngularZHigh = 0f }; Limits["RightToeBase"] = new BVHElementLimit { AngularXLow = -28f, AngularXHigh = 32f, AngularYLow = 0f, AngularYHigh = 0f, AngularZLow = 0f, AngularZHigh = 0f }; Limits["LeftHandThumb"] = new BVHElementLimit { AngularXLow = 0f, AngularXHigh = 0f, AngularYLow = 0f, AngularYHigh = 0f, AngularZLow = 0f, AngularZHigh = 0f }; Limits["L_Wrist_End"] = new BVHElementLimit { AngularXLow = 0f, AngularXHigh = 0f, AngularYLow = 0f, AngularYHigh = 0f, AngularZLow = 0f, AngularZHigh = 0f }; Limits["RightHandThumb"] = new BVHElementLimit { AngularXLow = 0f, AngularXHigh = 0f, AngularYLow = 0f, AngularYHigh = 0f, AngularZLow = 0f, AngularZHigh = 0f }; Limits["R_Wrist_End"] = new BVHElementLimit { AngularXLow = 0f, AngularXHigh = 0f, AngularYLow = 0f, AngularYHigh = 0f, AngularZLow = 0f, AngularZHigh = 0f }; Limits["End Site"] = new BVHElementLimit { AngularXLow = 0f, AngularXHigh = 0f, AngularYLow = 0f, AngularYHigh = 0f, AngularZLow = 0f, AngularZHigh = 0f }; }