public void LoadBoneMapping() { BoneMapping = new int[GetActor().Bones.Length]; for (int i = 0; i < GetActor().Bones.Length; i++) { MotionData.Hierarchy.Bone bone = Data.Source.FindBone(GetActor().Bones[i].GetName()); BoneMapping[i] = bone == null ? -1 : bone.Index; } }
protected override void DerivedInitialize() { MotionData.Hierarchy.Bone bone = Data.Source.FindBoneContains("Head"); if (bone == null) { Debug.Log("Could not find depth map sensor."); } else { Sensor = bone.Index; } }
public override Module Initialise(MotionData data) { Data = data; MotionData.Hierarchy.Bone bone = Data.Source.FindBoneContains("Head"); if (bone == null) { Debug.Log("Could not find depth map sensor."); } else { Sensor = bone.Index; } return(this); }
public void Setup() { MotionData.Hierarchy.Bone rs = Data.Root.FindBoneContains("RightShoulder"); RightShoulder = rs == null ? 0 : rs.Index; MotionData.Hierarchy.Bone ls = Data.Root.FindBoneContains("LeftShoulder"); LeftShoulder = ls == null ? 0 : ls.Index; MotionData.Hierarchy.Bone rh = Data.Root.FindBoneContains("RightUpLeg"); RightUpLeg = rh == null ? 0 : rh.Index; MotionData.Hierarchy.Bone lh = Data.Root.FindBoneContains("LeftUpLeg"); LeftUpLeg = lh == null ? 0 : lh.Index; MotionData.Hierarchy.Bone n = Data.Root.FindBoneContains("Neck"); Neck = n == null ? 0 : n.Index; MotionData.Hierarchy.Bone h = Data.Root.FindBoneContains("Hips"); Hips = h == null ? 0 : h.Index; }
protected override void DerivedInitialize() { MotionData.Hierarchy.Bone rs = Data.Source.FindBoneContains("RightShoulder"); RightShoulder = rs == null ? 0 : rs.Index; MotionData.Hierarchy.Bone ls = Data.Source.FindBoneContains("LeftShoulder"); LeftShoulder = ls == null ? 0 : ls.Index; MotionData.Hierarchy.Bone rh = Data.Source.FindBoneContains("RightHip", "RightUpLeg"); RightHip = rh == null ? 0 : rh.Index; MotionData.Hierarchy.Bone lh = Data.Source.FindBoneContains("LeftHip", "LeftUpLeg"); LeftHip = lh == null ? 0 : lh.Index; MotionData.Hierarchy.Bone n = Data.Source.FindBoneContains("Neck"); Neck = n == null ? 0 : n.Index; MotionData.Hierarchy.Bone h = Data.Source.FindBoneContains("Hips"); Hips = h == null ? 0 : h.Index; Ground = LayerMask.GetMask("Ground"); }
public void DetectSetup() { MotionData.Hierarchy.Bone rs = Data.Source.FindBoneContains("RightShoulder"); RightShoulder = rs == null ? 0 : rs.Index; MotionData.Hierarchy.Bone ls = Data.Source.FindBoneContains("LeftShoulder"); LeftShoulder = ls == null ? 0 : ls.Index; MotionData.Hierarchy.Bone rh = Data.Source.FindBoneContains("RightHip"); RightHip = rh == null ? 0 : rh.Index; MotionData.Hierarchy.Bone lh = Data.Source.FindBoneContains("LeftHip"); LeftHip = lh == null ? 0 : lh.Index; MotionData.Hierarchy.Bone n = Data.Source.FindBoneContains("Neck"); Neck = n == null ? 0 : n.Index; MotionData.Hierarchy.Bone h = Data.Source.FindBoneContains("Hips"); Hips = h == null ? 0 : h.Index; Ground = LayerMask.GetMask("Ground"); }
public override Module Initialise(MotionData data) { Data = data; Inspect = true; MotionData.Hierarchy.Bone bone = Data.Source.FindBoneContains("Hip"); if (bone == null) { Debug.Log("Could not find umbrella map sensor."); } else { Sensor = bone.Index; } Names = new string[Data.Source.Bones.Length]; for (int i = 0; i < Data.Source.Bones.Length; i++) { Names[i] = Data.Source.Bones[i].Name; } return(this); }
public float GetContact(Frame frame, bool mirrored) { if (Contacts == null || Contacts.Length != Module.Data.Frames.Length) { Debug.Log("Restoring missing contacts for sensor " + ID + " in asset " + Module.Data.GetName() + "."); Contacts = new float[Module.Data.Frames.Length]; } if (!mirrored) { return(Contacts[frame.Index - 1]); } if (MirrorSensor == null) { MotionData.Hierarchy.Bone bone = Module.Data.Source.FindBone(ID); if (bone != null) { MirrorSensor = Module.GetSensor(Module.Data.Source.Bones[Module.Data.Symmetry[bone.Index]].Name); } } return(MirrorSensor == null ? 0f : MirrorSensor.Contacts[frame.Index - 1]); }
public void InitPivot() { int index = 0; string name = string.Empty; PivotBone bone = null; //MotionData.Hierarchy.Bone head = Data.Root.FindBoneContains("Head"); //index = head == null ? 0 : head.Index; //name = head == null ? string.Empty : head.Name; //bone = new PivotBone(this, index, name); //Pivots[0] = bone; MotionData.Hierarchy.Bone lh = Data.Root.FindBoneContains("LeftHand"); index = lh == null ? 0 : lh.Index; name = lh == null ? string.Empty : lh.Name; bone = new PivotBone(this, index, name); Pivots[0] = bone; MotionData.Hierarchy.Bone rh = Data.Root.FindBoneContains("RightHand"); index = rh == null ? 0 : rh.Index; name = rh == null ? string.Empty : rh.Name; bone = new PivotBone(this, index, name); Pivots[1] = bone; }
private IEnumerator ImportMotionData() { string destination = "Assets/" + Destination; if (!AssetDatabase.IsValidFolder(destination)) { Debug.Log("Folder " + "'" + destination + "'" + " is not valid."); } else { Importing = true; for (int f = 0; f < Files.Length; f++) { if (Files[f].Import) { string fileName = Files[f].Object.Name.Replace(".bvh", ""); if (!Directory.Exists(destination + "/" + fileName)) { AssetDatabase.CreateFolder(destination, fileName); MotionData data = ScriptableObject.CreateInstance <MotionData>(); data.name = fileName; AssetDatabase.CreateAsset(data, destination + "/" + fileName + "/" + data.name + ".asset"); string[] lines = System.IO.File.ReadAllLines(Files[f].Object.FullName); char[] whitespace = new char[] { ' ' }; int index = 0; //Create Source Data List <Vector3> offsets = new List <Vector3>(); List <int[]> channels = new List <int[]>(); List <float[]> motions = new List <float[]>(); data.Source = new MotionData.Hierarchy(); string name = string.Empty; string parent = string.Empty; Vector3 offset = Vector3.zero; int[] channel = 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 = FileUtility.ReadFloat(subEntries[subEntry + 1]); offset.y = FileUtility.ReadFloat(subEntries[subEntry + 2]); offset.z = FileUtility.ReadFloat(subEntries[subEntry + 3]); break; } } data.Source.AddBone(name, parent); offsets.Add(offset); channels.Add(new int[0]); index += 2; break; } else if (entries[entry].Contains("OFFSET")) { offset.x = FileUtility.ReadFloat(entries[entry + 1]); offset.y = FileUtility.ReadFloat(entries[entry + 2]); offset.z = FileUtility.ReadFloat(entries[entry + 3]); break; } else if (entries[entry].Contains("CHANNELS")) { channel = new int[FileUtility.ReadInt(entries[entry + 1])]; for (int i = 0; i < channel.Length; i++) { if (entries[entry + 2 + i] == "Xposition") { channel[i] = 1; } else if (entries[entry + 2 + i] == "Yposition") { channel[i] = 2; } else if (entries[entry + 2 + i] == "Zposition") { channel[i] = 3; } else if (entries[entry + 2 + i] == "Xrotation") { channel[i] = 4; } else if (entries[entry + 2 + i] == "Yrotation") { channel[i] = 5; } else if (entries[entry + 2 + i] == "Zrotation") { channel[i] = 6; } } data.Source.AddBone(name, parent); offsets.Add(offset); channels.Add(channel); break; } else if (entries[entry].Contains("}")) { name = parent; parent = name == "None" ? "None" : data.Source.FindBone(name).Parent; break; } } } //Set Frames index += 1; while (lines[index].Length == 0) { index += 1; } ArrayExtensions.Resize(ref data.Frames, FileUtility.ReadInt(lines[index].Substring(8))); //Set Framerate index += 1; data.Framerate = Mathf.RoundToInt(1f / FileUtility.ReadFloat(lines[index].Substring(12))); //Compute Frames index += 1; for (int i = index; i < lines.Length; i++) { motions.Add(FileUtility.ReadArray(lines[i])); } for (int k = 0; k < data.GetTotalFrames(); k++) { data.Frames[k] = new Frame(data, k + 1, (float)k / data.Framerate); int idx = 0; for (int i = 0; i < data.Source.Bones.Length; i++) { MotionData.Hierarchy.Bone info = data.Source.Bones[i]; Vector3 position = Vector3.zero; Quaternion rotation = Quaternion.identity; for (int j = 0; j < channels[i].Length; j++) { if (channels[i][j] == 1) { position.x = motions[k][idx]; idx += 1; } if (channels[i][j] == 2) { position.y = motions[k][idx]; idx += 1; } if (channels[i][j] == 3) { position.z = motions[k][idx]; idx += 1; } if (channels[i][j] == 4) { rotation *= Quaternion.AngleAxis(motions[k][idx], Vector3.right); idx += 1; } if (channels[i][j] == 5) { rotation *= Quaternion.AngleAxis(motions[k][idx], Vector3.up); idx += 1; } if (channels[i][j] == 6) { rotation *= Quaternion.AngleAxis(motions[k][idx], Vector3.forward); idx += 1; } } position = (position == Vector3.zero ? offsets[i] : position) / 100f; //unit scale Matrix4x4 local = Matrix4x4.TRS(position, rotation, Vector3.one); if (Flip) { local = local.GetMirror(Axis); } data.Frames[k].World[i] = info.Parent == "None" ? local : data.Frames[k].World[data.Source.FindBone(info.Parent).Index] * local; } /* * for(int i=0; i<data.Source.Bones.Length; i++) { * data.Frames[k].Local[i] *= Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(data.Corrections[i]), Vector3.one); * data.Frames[k].World[i] *= Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(data.Corrections[i]), Vector3.one); * } */ } if (data.GetTotalFrames() == 1) { Frame reference = data.Frames.First(); ArrayExtensions.Resize(ref data.Frames, Mathf.RoundToInt(data.Framerate)); for (int k = 0; k < data.GetTotalFrames(); k++) { data.Frames[k] = new Frame(data, k + 1, (float)k / data.Framerate); data.Frames[k].World = (Matrix4x4[])reference.World.Clone(); } } //Detect Symmetry data.DetectSymmetry(); //Add Scene data.CreateScene(); data.AddSequence(); //Save EditorUtility.SetDirty(data); } else { Debug.Log("File with name " + fileName + " already exists."); } yield return(new WaitForSeconds(0f)); } } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); Importing = false; } yield return(new WaitForSeconds(0f)); }
public void ImportFile(string FileName) { string[] lines = File.ReadAllLines(Folder + "\\" + FileName); int index = 0; string name = string.Empty; string parent = string.Empty; Data = ScriptableObject.CreateInstance <MotionData>(); Data.name = FileName; if (!AssetDatabase.IsValidFolder(Destination) && Destination != "Assets/") { AssetDatabase.CreateFolder("Assets", Destination.Substring(Mathf.Min(7, Destination.Length))); Debug.Log("No Directory Found, New Created!"); } AssetDatabase.CreateAsset(Data, Destination + "\\" + FixedFileName(Data.name) + ".asset"); List <Vector3> offsets = new List <Vector3>(); Vector3 offset = Vector3.zero; List <int[]> channels = new List <int[]>(); int[] channel = null; List <float[]> motions = new List <float[]>(); for (index = 0; index < lines.Length; index++) { if (lines[index] == "MOTION") { break; } string[] entries = lines[index].Split(TextSpace); for (int entry = 0; entry < entries.Length; entry++) { if (entries[entry].Contains("ROOT")) { parent = "None"; name = FixedBoneName(entries[entry + 1]); break; } else if (entries[entry].Contains("JOINT")) { parent = name; name = FixedBoneName(entries[entry + 1]); break; } else if (entries[entry].Contains("End")) { parent = name; name = FixedBoneName(parent + entries[entry + 1]); string[] offsetEntries = lines[index + 2].Split(TextSpace); for (int offsetEntry = 0; offsetEntry < offsetEntries.Length; offsetEntry++) { if (offsetEntries[offsetEntry].Contains("OFFSET")) { offset.x = float.Parse(offsetEntries[offsetEntry + 1]); offset.y = float.Parse(offsetEntries[offsetEntry + 2]); offset.z = float.Parse(offsetEntries[offsetEntry + 3]); break; } } Data.Root.AddBone(name, parent); offsets.Add(offset); channels.Add(new int[0]); index += 2; break; } else if (entries[entry].Contains("OFFSET")) { offset.x = float.Parse(entries[entry + 1]); offset.y = float.Parse(entries[entry + 2]); offset.z = float.Parse(entries[entry + 3]); break; } else if (entries[entry].Contains("CHANNEL")) { channel = new int[int.Parse(entries[entry + 1])]; for (int i = 0; i < channel.Length; i++) { if (entries[entry + 2 + i] == "Xposition") { channel[i] = 1; } else if (entries[entry + 2 + i] == "Yposition") { channel[i] = 2; } else if (entries[entry + 2 + i] == "Zposition") { channel[i] = 3; } else if (entries[entry + 2 + i] == "Xrotation") { channel[i] = 4; } else if (entries[entry + 2 + i] == "Yrotation") { channel[i] = 5; } else if (entries[entry + 2 + i] == "Zrotation") { channel[i] = 6; } } Data.Root.AddBone(name, parent); offsets.Add(offset); channels.Add(channel); break; } else if (entries[entry].Contains("}")) { name = parent; parent = name == "None" ? "None" : Data.Root.FindBone(name).Parent; break; } } } index += 1; while (lines[index].Length == 0) { index += 1; } ArrayExtensions.Resize(ref Data.Frames, int.Parse(lines[index].Substring(8))); index += 1; Data.Framerate = Mathf.RoundToInt(1.0f / float.Parse(lines[index].Substring(12))); index += 1; for (int i = index; i < lines.Length; i++) { motions.Add(ParseFloatArray(lines[i])); } for (int i = 0; i < Data.GetTotalFrames(); i++) { Data.Frames[i] = new Frame(Data, i + 1, (float)i / Data.Framerate); int channelIndex = 0; for (int j = 0; j < Data.Root.Bones.Length; j++) { MotionData.Hierarchy.Bone bone = Data.Root.Bones[j]; Vector3 position = Vector3.zero; Quaternion rotation = Quaternion.identity; for (int k = 0; k < channels[j].Length; k++) { if (channels[j][k] == 1) { position.x = motions[i][channelIndex]; channelIndex++; } if (channels[j][k] == 2) { position.y = motions[i][channelIndex]; channelIndex++; } if (channels[j][k] == 3) { position.z = motions[i][channelIndex]; channelIndex++; } if (channels[j][k] == 4) { rotation *= Quaternion.AngleAxis(motions[i][channelIndex], Vector3.right); channelIndex++; } if (channels[j][k] == 5) { rotation *= Quaternion.AngleAxis(motions[i][channelIndex], Vector3.up); channelIndex++; } if (channels[j][k] == 6) { rotation *= Quaternion.AngleAxis(motions[i][channelIndex], Vector3.forward); channelIndex++; } } position = (position == Vector3.zero ? offsets[j] : position) / 100.0f; Matrix4x4 local = Matrix4x4.TRS(position, rotation, Vector3.one); Data.Frames[i].World[j] = bone.Parent == "None" ? local : Data.Frames[i].World[Data.Root.FindBone(bone.Parent).Index] * local; EditorUtility.SetDirty(Data); } } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); Debug.Log("Import File: " + FileName + " Successfully!"); }
private IEnumerator ImportMotionData() { string destination = "Assets/" + Destination; if (!AssetDatabase.IsValidFolder(destination)) { Debug.Log("Folder " + "'" + destination + "'" + " is not valid."); } else { Importing = true; for (int f = 0; f < Files.Length; f++) { if (Import[f]) { MotionData data = ScriptableObject.CreateInstance <MotionData>(); data.Name = Files[f].FullName.Substring(Files[f].FullName.LastIndexOf("/") + 1); if (AssetDatabase.LoadAssetAtPath(destination + "/" + data.Name + ".asset", typeof(MotionData)) == null) { AssetDatabase.CreateAsset(data, destination + "/" + data.Name + ".asset"); } else { int i = 1; while (AssetDatabase.LoadAssetAtPath(destination + "/" + data.Name + data.Name + " (" + i + ").asset", typeof(MotionData)) != null) { i += 1; } AssetDatabase.CreateAsset(data, destination + "/" + data.Name + data.Name + " (" + i + ").asset"); } string[] lines = File.ReadAllLines(Files[f].FullName); char[] whitespace = new char[] { ' ' }; int index = 0; //Create Source Data List <Vector3> offsets = new List <Vector3>(); List <int[]> channels = new List <int[]>(); List <float[]> motions = new List <float[]>(); data.Source = new MotionData.Hierarchy(); string name = string.Empty; string parent = string.Empty; Vector3 offset = Vector3.zero; int[] channel = 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; } } data.Source.AddBone(name, parent); offsets.Add(offset); channels.Add(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")) { channel = new int[Utility.ReadInt(entries[entry + 1])]; for (int i = 0; i < channel.Length; i++) { if (entries[entry + 2 + i] == "Xposition") { channel[i] = 1; } else if (entries[entry + 2 + i] == "Yposition") { channel[i] = 2; } else if (entries[entry + 2 + i] == "Zposition") { channel[i] = 3; } else if (entries[entry + 2 + i] == "Xrotation") { channel[i] = 4; } else if (entries[entry + 2 + i] == "Yrotation") { channel[i] = 5; } else if (entries[entry + 2 + i] == "Zrotation") { channel[i] = 6; } } data.Source.AddBone(name, parent); offsets.Add(offset); channels.Add(channel); break; } else if (entries[entry].Contains("}")) { name = parent; parent = name == "None" ? "None" : data.Source.FindBone(name).Parent; break; } } } //REMOVE LATER //data.Corrections = new Vector3[data.Source.Bones.Length]; // //Set Frames index += 1; while (lines[index].Length == 0) { index += 1; } ArrayExtensions.Resize(ref data.Frames, Utility.ReadInt(lines[index].Substring(8))); //Set Framerate index += 1; data.Framerate = Mathf.RoundToInt(1f / Utility.ReadFloat(lines[index].Substring(12))); //Compute Frames index += 1; for (int i = index; i < lines.Length; i++) { motions.Add(Utility.ReadArray(lines[i])); } for (int k = 0; k < data.GetTotalFrames(); k++) { data.Frames[k] = new MotionData.Frame(data, k + 1, (float)k / data.Framerate); int idx = 0; for (int i = 0; i < data.Source.Bones.Length; i++) { MotionData.Hierarchy.Bone info = data.Source.Bones[i]; Vector3 position = Vector3.zero; Quaternion rotation = Quaternion.identity; for (int j = 0; j < channels[i].Length; j++) { if (channels[i][j] == 1) { position.x = motions[k][idx]; idx += 1; } if (channels[i][j] == 2) { position.y = motions[k][idx]; idx += 1; } if (channels[i][j] == 3) { position.z = motions[k][idx]; idx += 1; } if (channels[i][j] == 4) { rotation *= Quaternion.AngleAxis(motions[k][idx], Vector3.right); idx += 1; } if (channels[i][j] == 5) { rotation *= Quaternion.AngleAxis(motions[k][idx], Vector3.up); idx += 1; } if (channels[i][j] == 6) { rotation *= Quaternion.AngleAxis(motions[k][idx], Vector3.forward); idx += 1; } } position = (position == Vector3.zero ? offsets[i] : position) / 100f; //unit scale data.Frames[k].Local[i] = Matrix4x4.TRS(position, rotation, Vector3.one); data.Frames[k].World[i] = info.Parent == "None" ? data.Frames[k].Local[i] : data.Frames[k].World[data.Source.FindBone(info.Parent).Index] * data.Frames[k].Local[i]; } /* * for(int i=0; i<data.Source.Bones.Length; i++) { * data.Frames[k].Local[i] *= Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(data.Corrections[i]), Vector3.one); * data.Frames[k].World[i] *= Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(data.Corrections[i]), Vector3.one); * } */ } //Finalise data.DetectHeightMapSensor(); data.DetectDepthMapSensor(); data.DetectSymmetry(); data.ComputeStyles(); data.AddSequence(); yield return(new WaitForSeconds(0f)); } } Importing = false; } yield return(new WaitForSeconds(0f)); }