mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 06:23:35 +02:00
got input recording to work
This commit is contained in:
parent
64fcfd33a4
commit
d057dfebf0
3 changed files with 86 additions and 14 deletions
|
@ -110,6 +110,20 @@ Rectangle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HifiControls.Button {
|
||||||
|
id: playBack
|
||||||
|
anchors.right: browse.left
|
||||||
|
anchors.top: selectedFile.bottom
|
||||||
|
anchors.topMargin: 10
|
||||||
|
|
||||||
|
text: "Playback"
|
||||||
|
color: hifi.buttons.black
|
||||||
|
enabled: true
|
||||||
|
onClicked: {
|
||||||
|
sendToScript({method: "playback"});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function getFileSelected(file) {
|
function getFileSelected(file) {
|
||||||
console.log("------------> file selected <----------------");
|
console.log("------------> file selected <----------------");
|
||||||
|
|
|
@ -2740,7 +2740,7 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
||||||
offscreenUi->load("Browser.qml");
|
offscreenUi->load("Browser.qml");
|
||||||
} else if (isOption) {
|
} else if (isOption) {
|
||||||
controller::InputRecorder* inputRecorder = controller::InputRecorder::getInstance();
|
controller::InputRecorder* inputRecorder = controller::InputRecorder::getInstance();
|
||||||
inputRecorder->saveRecording();
|
inputRecorder->stopPlayback();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -2939,9 +2939,6 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
||||||
Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, !isFirstPersonChecked);
|
Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, !isFirstPersonChecked);
|
||||||
Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, isFirstPersonChecked);
|
Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, isFirstPersonChecked);
|
||||||
cameraMenuChanged();
|
cameraMenuChanged();
|
||||||
} else if (isOption) {
|
|
||||||
controller::InputRecorder* inputRecorder = controller::InputRecorder::getInstance();
|
|
||||||
inputRecorder->toggleRecording();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,36 @@ namespace controller {
|
||||||
return newPose;
|
return newPose;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Pose jsonObjectToPose(const QJsonObject object) {
|
||||||
|
Pose pose;
|
||||||
|
QJsonArray translation = object["translation"].toArray();
|
||||||
|
QJsonArray rotation = object["rotation"].toArray();
|
||||||
|
QJsonArray velocity = object["velocity"].toArray();
|
||||||
|
QJsonArray angularVelocity = object["angularVelocity"].toArray();
|
||||||
|
|
||||||
|
pose.valid = object["valid"].toBool();
|
||||||
|
|
||||||
|
pose.translation.x = translation[0].toDouble();
|
||||||
|
pose.translation.y = translation[1].toDouble();
|
||||||
|
pose.translation.z = translation[2].toDouble();
|
||||||
|
|
||||||
|
pose.rotation.x = rotation[0].toDouble();
|
||||||
|
pose.rotation.y = rotation[1].toDouble();
|
||||||
|
pose.rotation.z = rotation[2].toDouble();
|
||||||
|
pose.rotation.w = rotation[3].toDouble();
|
||||||
|
|
||||||
|
pose.velocity.x = velocity[0].toDouble();
|
||||||
|
pose.velocity.y = velocity[1].toDouble();
|
||||||
|
pose.velocity.z = velocity[2].toDouble();
|
||||||
|
|
||||||
|
pose.angularVelocity.x = angularVelocity[0].toDouble();
|
||||||
|
pose.angularVelocity.y = angularVelocity[1].toDouble();
|
||||||
|
pose.angularVelocity.z = angularVelocity[2].toDouble();
|
||||||
|
|
||||||
|
return pose;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void exportToFile(QJsonObject& object) {
|
void exportToFile(QJsonObject& object) {
|
||||||
if (!QDir(SAVE_DIRECTORY).exists()) {
|
if (!QDir(SAVE_DIRECTORY).exists()) {
|
||||||
QDir().mkdir(SAVE_DIRECTORY);
|
QDir().mkdir(SAVE_DIRECTORY);
|
||||||
|
@ -65,6 +95,7 @@ namespace controller {
|
||||||
QString timeStamp = QDateTime::currentDateTime().toString(Qt::ISODate);
|
QString timeStamp = QDateTime::currentDateTime().toString(Qt::ISODate);
|
||||||
timeStamp.replace(":", "-");
|
timeStamp.replace(":", "-");
|
||||||
QString fileName = SAVE_DIRECTORY + FILE_PREFIX_NAME + timeStamp + COMPRESS_EXTENSION;
|
QString fileName = SAVE_DIRECTORY + FILE_PREFIX_NAME + timeStamp + COMPRESS_EXTENSION;
|
||||||
|
qDebug() << fileName;
|
||||||
QFile saveFile (fileName);
|
QFile saveFile (fileName);
|
||||||
if (!saveFile.open(QIODevice::WriteOnly)) {
|
if (!saveFile.open(QIODevice::WriteOnly)) {
|
||||||
qWarning() << "could not open file: " << fileName;
|
qWarning() << "could not open file: " << fileName;
|
||||||
|
@ -75,16 +106,19 @@ namespace controller {
|
||||||
saveFile.write(compressedData);
|
saveFile.write(compressedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool openFile(const QString& file, QJsonObject& object) {
|
QJsonObject openFile(const QString& file, bool& status) {
|
||||||
|
QJsonObject object;
|
||||||
QFile openFile(file);
|
QFile openFile(file);
|
||||||
if (!openFile.open(QIODevice::ReadOnly)) {
|
if (!openFile.open(QIODevice::ReadOnly)) {
|
||||||
qWarning() << "could not open file: " << file;
|
qWarning() << "could not open file: " << file;
|
||||||
return false;
|
status = false;
|
||||||
|
return object;
|
||||||
}
|
}
|
||||||
QByteArray compressedData = qUncompress(openFile.readAll());
|
QByteArray compressedData = qUncompress(openFile.readAll());
|
||||||
QJsonDocument jsonDoc = QJsonDocument::fromBinaryData(compressedData);
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(compressedData);
|
||||||
object = jsonDoc.object();
|
object = jsonDoc.object();
|
||||||
return true;
|
status = true;
|
||||||
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
InputRecorder::InputRecorder() {}
|
InputRecorder::InputRecorder() {}
|
||||||
|
@ -132,15 +166,42 @@ namespace controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputRecorder::loadRecording(const QString& path) {
|
void InputRecorder::loadRecording(const QString& path) {
|
||||||
QFileInfo info(path);
|
resetFrame();
|
||||||
QString extension = info.suffix();
|
_poseStateList.clear();
|
||||||
|
_actionStateList.clear();
|
||||||
|
QString filePath = path;
|
||||||
|
filePath.remove(0,8);
|
||||||
|
QFileInfo info(filePath);
|
||||||
|
QString extension = info.suffix();
|
||||||
if (extension != "gz") {
|
if (extension != "gz") {
|
||||||
qWarning() << "Could not open file of that type";
|
qWarning() << "Could not open file of type " << extension;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QJsonObject data;
|
bool success = false;
|
||||||
bool success = openFile(path, data);
|
QJsonObject data = openFile(info.absoluteFilePath(), success);
|
||||||
qDebug() << "-------------------> loading file -------------->";
|
int count = 0;
|
||||||
|
if (success) {
|
||||||
|
_framesRecorded = data["frameCount"].toInt();
|
||||||
|
QJsonArray actionArrayList = data["actionList"].toArray();
|
||||||
|
QJsonArray poseArrayList = data["poseList"].toArray();
|
||||||
|
for (int actionIndex = 0; actionIndex < actionArrayList.size(); actionIndex++) {
|
||||||
|
QJsonArray actionState = actionArrayList[actionIndex].toArray();
|
||||||
|
for (int index = 0; index < actionState.size(); index++) {
|
||||||
|
_currentFrameActions[index] = actionState[index].toInt();
|
||||||
|
}
|
||||||
|
_actionStateList.push_back(_currentFrameActions);
|
||||||
|
_currentFrameActions = ActionStates(toInt(Action::NUM_ACTIONS));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int poseIndex = 0; poseIndex < poseArrayList.size(); poseIndex++) {
|
||||||
|
QJsonArray poseState = poseArrayList[poseIndex].toArray();
|
||||||
|
for (int index = 0; index < poseState.size(); index++) {
|
||||||
|
_currentFramePoses[index] = jsonObjectToPose(poseState[index].toObject());
|
||||||
|
}
|
||||||
|
_poseStateList.push_back(_currentFramePoses);
|
||||||
|
_currentFramePoses = PoseStates(toInt(Action::NUM_ACTIONS));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputRecorder::stopRecording() {
|
void InputRecorder::stopRecording() {
|
||||||
|
|
Loading…
Reference in a new issue