【发布时间】:2018-07-13 22:39:26
【问题描述】:
我目前正在开展一个学校项目,我将在其中使用动作捕捉和统一。它是为老年人设计的,以改善他们的认知和运动功能。我希望 unity 能够将他们的动作记录到 csv 文件中,以查看他们的表现如何。我想在excel中记录x、y和z坐标。
我使用感知神经元进行动作捕捉,总共有 32 个传感器。统一的 3D 模型有 32 个不同的可移动部分/肢体,包括手指。我在这里添加了一张图片:
This is what the 3D model for perception neuron looks like
我尝试使用此示例,但它会将数据提取为文本文件。
using UnityEngine;
using System.Collections;
using System.IO;
using System;
public class fileMaker : MonoBehaviour
{
public static void putBytes(ref byte[] output, int index, float value)
{
//turns a float into its 4 bytes and then puts them into the output array
//at the given index
byte[] data = BitConverter.GetBytes(value);
output[index] = data[0];
output[index + 1] = data[1];
output[index + 2] = data[2];
output[index + 3] = data[3];
}
public static void makeFile(Vector3 position)
{
//each float is 4 bytes.
//3 floats in a vector 3(x,y,z) and 3x4 =12!
byte[] output = new byte[12];
//get bytes for each part of our lil vector3
putBytes(ref output, 0, position.x);
putBytes(ref output, 4, position.y);
putBytes(ref output, 8, position.z);
File.WriteAllBytes(Application.dataPath + "/log.txt", output);
}
public static void loadFile()
{
//converts it all back into pretty print
if (File.Exists(Application.dataPath + "/log.txt"))
{
byte[] input = File.ReadAllBytes(Application.dataPath + "/log.txt");
int length = input.Length;
if (length == 12)
{
Vector3 ourVector3 = new Vector3();
ourVector3.x = (float)BitConverter.ToSingle(input, 0);
ourVector3.y = (float)BitConverter.ToSingle(input, 4);
ourVector3.z = (float)BitConverter.ToSingle(input, 8);
print("Position saved in file (" + Application.dataPath + "/log.txt): " + ourVector3.ToString());
}
}
}
}
我希望统一记录每个部分的位置数据。这是否意味着我必须为每个肢体(这是一个游戏对象)编写一个脚本,或者我可以编写一个脚本并连接到所有肢体?
我还想知道是否可以更改上面的代码以将数据存储为 csv 文件而不是文本文件;我可以更改几行还是必须制作一个新脚本?我对统一和计算机编程非常陌生。
【问题讨论】:
-
这完全取决于您如何为应用程序存储数据。可能有只有您知道的各种考虑因素(速度、可编辑性等)。没有好的或坏的解决方案,只有满足您要求的和不符合要求的。