public void RecordFrame() { foreach (User user in metagen_comp.World.AllUsers) { RefID user_id = user.ReferenceID; if (boness.ContainsKey(user_id)) { IKSolverVR.References bones = boness[user_id]; BodyNode node = bonesList[0]; if (bones[node] != null) { Slot bone = bones[node]; float3 pos = bone.GlobalPosition; float3 rot = bone.GlobalRotation.EulerAngles; fileWriters[user_id].Write(string.Format("{0:0.000000}\t{1:0.000000}\t{2:0.000000}", pos.X, pos.Y, pos.Z) + "\t"); fileWriters[user_id].Write(string.Format("{0:0.000000}\t{1:0.000000}\t{2:0.000000}", rot.Z, rot.X, rot.Y) + "\t"); } for (int i = 1; i < bonesList.Count; i++) { node = bonesList[i]; if (bones[node] != null) { Slot bone = bones[node]; float3 rot = bone.LocalRotationToSpace(floatQ.Identity, bones[boneParents[node]]).EulerAngles; //float3 rot = bone.LocalRotation.EulerAngles; //float3 pos = bone.LocalPointToSpace(float3.Zero, bones[boneParents[node]]); //float3 rot = floatQ.LookRotation(pos).EulerAngles; if (tracking_rotations[node]) { fileWriters[user_id].Write(string.Format("{0:0.000000}\t{1:0.000000}\t{2:0.000000}", rot.Z, rot.X, rot.Y) + "\t"); } } } fileWriters[user_id].Write("\n"); } } }
void BvhHeaderWrite(StreamWriter writer, IKSolverVR.References bones) { writer.WriteLine("HIERARCHY"); BodyNode node = bonesList[0]; int depth = boneDepths[node]; string tabs = new string('\t', depth); if (bones[node] != null) { Slot bone = bones[node]; writer.WriteLine(tabs + "ROOT\t" + node.ToString()); writer.WriteLine(tabs + "{"); writer.WriteLine(tabs + "\t" + "OFFSET\t0.00\t0.00\t0.00"); writer.WriteLine(tabs + "\t" + "CHANNELS\t6\tXposition\tYposition\tZposition\tZrotation\tXrotation\tYrotation"); tracking_rotations[node] = true; } int last_depth = depth; for (int i = 1; i < bonesList.Count - 1; i++) { node = bonesList[i]; depth = boneDepths[node]; BodyNode next_node = bonesList[i + 1]; depth = boneDepths[node]; int next_depth = boneDepths[next_node]; tabs = new string('\t', depth); if (bones[node] != null) { int closing_brackets = Math.Max(last_depth + 1 - depth, 0); for (int j = 0; j < closing_brackets; j++) { string lasttabs = new string('\t', last_depth); writer.WriteLine(lasttabs.Substring(0, last_depth - j) + "}"); } Slot bone = bones[node]; //float3 pos = bone.LocalPosition; float3 pos = bone.LocalPointToSpace(new float3(0f, 0f, 0f), bones[boneParents[node]]); pos = pos * bone.GlobalScale; if (next_depth > depth) { writer.WriteLine(tabs + "JOINT\t" + node.ToString()); } else { writer.WriteLine(tabs + "End Site"); } writer.WriteLine(tabs + "{"); writer.WriteLine(tabs + "\t" + "OFFSET\t" + string.Format("{0:0.000000}\t{1:0.000000}\t{2:0.000000}", pos.X, pos.Y, pos.Z)); if (next_depth > depth) { writer.WriteLine(tabs + "\t" + "CHANNELS\t3\tZrotation\tXrotation\tYrotation"); tracking_rotations[node] = true; } else { tracking_rotations[node] = false; } last_depth = depth; } } node = bonesList[bonesList.Count - 1]; depth = boneDepths[node]; depth = boneDepths[node]; tabs = new string('\t', depth); if (bones[node] != null) { int closing_brackets = Math.Max(last_depth + 1 - depth, 0); for (int j = 0; j < closing_brackets; j++) { string lasttabs = new string('\t', last_depth); writer.WriteLine(lasttabs.Substring(0, last_depth - j) + "}"); } Slot bone = bones[node]; //float3 pos = bone.LocalPosition; float3 pos = bone.LocalPointToSpace(new float3(0f, 0f, 0f), bones[boneParents[node]]); pos = pos * bone.GlobalScale; writer.WriteLine(tabs + "End Site"); writer.WriteLine(tabs + "{"); writer.WriteLine(tabs + "\t" + "OFFSET\t" + string.Format("{0:0.000000}\t{1:0.000000}\t{2:0.000000}", pos.X, pos.Y, pos.Z)); tracking_rotations[node] = false; last_depth = depth; } for (int j = 0; j < Math.Max(last_depth + 1, 0); j++) { string lasttabs = new string('\t', last_depth); writer.WriteLine(lasttabs.Substring(0, last_depth - j) + "}"); } writer.WriteLine("MOTION"); writer.WriteLine("Frame Time: 0.033333"); }