だから私はいくつかのデータを辞書に入れています。文字列(名前)とボーン(位置などを保持するために使用)。kinectから骨の位置を読み取ってから、それを辞書に入れて、後で.txtファイルに保存します。それらはすべて同じであるため、今私はかなり混乱しています。しばらくの間、いくつかの骨のさまざまな位置を示すいくつかのラベルがあり、それらはすべて変化していました。つまり、それは私の辞書に入れることと関係があるということですか?
これが私の入力方法です:
JointCollection joints = skele.Joints;
List<Bone> temp = current_bones;
Frame temp_f = new Frame(temp);
Joint h_j = joints[JointType.Head];
foreach (Joint j in joints)
{
try
{
switch (j.JointType)
{
#region cases
case (JointType.Head):
temp_f.frame_bones["Head"].setPosition(j.Position.X, j.Position.Y, j.Position.Z);
break;
...Other stuff that basically repeats but with different jointtypes
}
}
catch (Exception ex) { /*MessageBox.Show("Error getting joints: " + ex.Message);*/ }
}
if (recording)
{
if (newR)
{
bvhBuilder.resetAnimation(); //Resets a list of frames
newR = false;
}
bvhBuilder.add_frame(temp_f);//adds a frame to the list
}
ボーンクラスの主なもの:
public Bone(String b_name)
{
name = b_name;
}
public void setPosition(float _x, float _y, float _z)
{
x = _x; y = _y; z = _z;
}
私のBVHBuilderクラスに関連するもの:
List<Bone> current_bones = new List<Bone>();
Frame current_frame;
List<Frame> animation_frames = new List<Frame>();
public BVHBuilder(List<Bone> bones)
{
current_bones = bones;
}
public String build()
{
StringBuilder builder = new StringBuilder();
builder.AppendLine(build_bones());
builder.AppendLine(build_anim());
return builder.ToString();
}
public String build_anim()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("MOTION");
sb.AppendLine("Frames: " + getFrameCount());
sb.AppendLine("Frame Time: " + (float)((float)1/(float)30));
foreach (Frame frame in animation_frames)
{
String line = "";
int b_i = 0;
float root_x = frame.root.x;
float root_y = frame.root.y;
float root_z = frame.root.z;
Console.WriteLine("Root: (" + root_x + "," + root_y + "," + root_z + ")");
for (int i = 0; i < frame.frame_bones.Count; i++)
{
Bone bone = frame.frame_bones.Values.ElementAt(i);
line += (bone.x - root_x) + " ";
line += (bone.y - root_y) + " ";
if (b_i >= frame.frame_bones.Count) { line += (root_z - bone.z); } //Don't want a space at the end
else { line += (root_z - bone.z) + " "; }
b_i++;
}
sb.AppendLine(line);
}
return sb.ToString();
}
フレームクラス:
class Frame
{
public Dictionary<String, Bone> frame_bones = new Dictionary<String, Bone>();
public Bone root = null;
int root_pos = 0;
public Frame(List<Bone> bones)
{
int i = 0;
foreach (Bone b in bones)
{
frame_bones.Add(b.name,b);
if (b.root) { root_pos = i; root = b; }
i++;
}
}
}
そして、これはそれが節約するところです:
private void saveAnim()
{
int times = 0;
String path = "";
Boolean exists = true;
while (exists)
{
path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\" + "nectrecord" + times + ".txt";
exists = File.Exists(path);
times++;
}
currP = path;
Console.WriteLine(currP);
StreamWriter sw = new StreamWriter(currP);
String write = bvhBuilder.build();
int max_i = write.Length;
progressBar1.Maximum = max_i;
int c_i = 0;
foreach (char c in write)
{
sw.Write(c);
c_i++;
progressBar1.Value = c_i;
}
sw.Flush();//make sure everything wrote
sw.Close();
MessageBox.Show("Saved to :" + currP);
}
私はそれがたくさんのコードであることを知っています、しかし私はこれをおそらく4時間デバッグしようとしています。うまくいけば、新鮮な目が問題を見つけるのに役立つでしょう。
ところで、これは出力ファイルがどのように見えるかです:
HIERARCHY
ROOT Hip_C
{
OFFSET 0 0 0
CHANNELS 3 Xposition Yposition Zposition
JOINT Spine
{
OFFSET 0 0 0
CHANNELS 3 Xposition Yposition Zposition
JOINT Shoulder_C
{
OFFSET 0 0 0
CHANNELS 3 Xposition Yposition Zposition
JOINT Head
{
OFFSET 0 0 0
CHANNELS 3 Xposition Yposition Zposition
}
JOINT Shoulder_R
{
OFFSET 0 0 0
CHANNELS 3 Xposition Yposition Zposition
JOINT Elbow_R
{
OFFSET 0 0 0
CHANNELS 3 Xposition Yposition Zposition
JOINT Wrist_R
{
OFFSET 0 0 0
CHANNELS 3 Xposition Yposition Zposition
JOINT Hand_R
{
OFFSET 0 0 0
CHANNELS 3 Xposition Yposition Zposition
}
}
}
}
JOINT Shoulder_L
{
OFFSET 0 0 0
CHANNELS 3 Xposition Yposition Zposition
JOINT Elbow_L
{
OFFSET 0 0 0
CHANNELS 3 Xposition Yposition Zposition
JOINT Wrist_L
{
OFFSET 0 0 0
CHANNELS 3 Xposition Yposition Zposition
JOINT Hand_L
{
OFFSET 0 0 0
CHANNELS 3 Xposition Yposition Zposition
}
}
}
}
}
}
JOINT Hip_R
{
OFFSET 0 0 0
CHANNELS 3 Xposition Yposition Zposition
JOINT Knee_R
{
OFFSET 0 0 0
CHANNELS 3 Xposition Yposition Zposition
JOINT Ankle_R
{
OFFSET 0 0 0
CHANNELS 3 Xposition Yposition Zposition
JOINT Foot_R
{
OFFSET 0 0 0
CHANNELS 3 Xposition Yposition Zposition
}
}
}
}
JOINT Hip_L
{
OFFSET 0 0 0
CHANNELS 3 Xposition Yposition Zposition
JOINT Knee_L
{
OFFSET 0 0 0
CHANNELS 3 Xposition Yposition Zposition
JOINT Ankle_L
{
OFFSET 0 0 0
CHANNELS 3 Xposition Yposition Zposition
JOINT Foot_L
{
OFFSET 0 0 0
CHANNELS 3 Xposition Yposition Zposition
}
}
}
}
}
MOTION
Frames: 210
Frame Time: 0.03333334
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.05713073 -0.009174455 -0.2937571 0.2087359 -0.2028138 -0.902887 0.2087359 -0.2028138 -0.9028869 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.05713073 -0.009174455 -0.2937571 0.2087359 -0.2028138 -0.902887 0.2087359 -0.2028138 -0.9028869 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.05713073 -0.009174455 -0.2937571 0.2087359 -0.2028138 -0.902887 0.2087359 -0.2028138 -0.9028869 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.05713073 -0.009174455 -0.2937571 0.2087359 -0.2028138 -0.902887 0.2087359 -0.2028138 -0.9028869 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.05713073 -0.009174455 -0.2937571 0.2087359 -0.2028138 -0.902887 0.2087359 -0.2028138 -0.9028869 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.05713073 -0.009174455 -0.2937571 0.2087359 -0.2028138 -0.902887 0.2087359 -0.2028138 -0.9028869 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.05713073 -0.009174455 -0.2937571 0.2087359 -0.2028138 -0.902887 0.2087359 -0.2028138 -0.9028869 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.05713073 -0.009174455 -0.2937571 0.2087359 -0.2028138 -0.902887 0.2087359 -0.2028138 -0.9028869 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.05713073 -0.009174455 -0.2937571 0.2087359 -0.2028138 -0.902887 0.2087359 -0.2028138 -0.9028869 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
...そしてそれはしばらく続きます