mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 03:37:49 +02:00
got input recording working
This commit is contained in:
parent
cd095915ef
commit
5cd4007aaa
6 changed files with 105 additions and 37 deletions
|
@ -77,6 +77,7 @@
|
||||||
#include <InfoView.h>
|
#include <InfoView.h>
|
||||||
#include <input-plugins/InputPlugin.h>
|
#include <input-plugins/InputPlugin.h>
|
||||||
#include <controllers/UserInputMapper.h>
|
#include <controllers/UserInputMapper.h>
|
||||||
|
#include <controllers/InputRecorder.h>
|
||||||
#include <controllers/ScriptingInterface.h>
|
#include <controllers/ScriptingInterface.h>
|
||||||
#include <controllers/StateController.h>
|
#include <controllers/StateController.h>
|
||||||
#include <UserActivityLoggerScriptingInterface.h>
|
#include <UserActivityLoggerScriptingInterface.h>
|
||||||
|
@ -2731,6 +2732,9 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
||||||
if (isMeta) {
|
if (isMeta) {
|
||||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||||
offscreenUi->load("Browser.qml");
|
offscreenUi->load("Browser.qml");
|
||||||
|
} else if (isOption) {
|
||||||
|
controller::InputRecorder* inputRecorder = controller::InputRecorder::getInstance();
|
||||||
|
inputRecorder->togglePlayback();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -2929,6 +2933,9 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,72 +8,122 @@
|
||||||
|
|
||||||
#include "InputRecorder.h"
|
#include "InputRecorder.h"
|
||||||
|
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <GLMHelpers.h>
|
||||||
namespace controller {
|
namespace controller {
|
||||||
|
|
||||||
|
void poseToJsonObject(const Pose pose) {
|
||||||
|
}
|
||||||
|
|
||||||
InputRecorder::InputRecorder() {}
|
InputRecorder::InputRecorder() {}
|
||||||
|
|
||||||
InputRecorder::~InputRecorder() {}
|
InputRecorder::~InputRecorder() {}
|
||||||
|
|
||||||
InputRecorder& InputRecorder::getInstance() {
|
InputRecorder* InputRecorder::getInstance() {
|
||||||
static InputRecorder inputRecorder;
|
static InputRecorder inputRecorder;
|
||||||
return inputRecorder;
|
return &inputRecorder;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputRecorder::startRecording() {
|
void InputRecorder::startRecording() {
|
||||||
_recording = true;
|
_recording = true;
|
||||||
|
_playback = false;
|
||||||
_framesRecorded = 0;
|
_framesRecorded = 0;
|
||||||
_poseStateList.clear();
|
_poseStateList.clear();
|
||||||
_actionStateList.clear();
|
_actionStateList.clear();
|
||||||
qDebug() << "-------------> input recording starting <---------------";
|
}
|
||||||
|
|
||||||
|
void InputRecorder::saveRecording() {
|
||||||
|
QJsonObject data;
|
||||||
|
data["frameCount"] = _framesRecorded;
|
||||||
|
|
||||||
|
QJsonArray actionArrayList;
|
||||||
|
QJsonArray poseArrayList;
|
||||||
|
for(const ActionStates actionState _actionStateList) {
|
||||||
|
QJsonArray actionArray;
|
||||||
|
for (const float value, actionState) {
|
||||||
|
actionArray.append(value);
|
||||||
|
}
|
||||||
|
actionArrayList.append(actionArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const PoseStates poseState, _poseStateList) {
|
||||||
|
QJsonArray poseArray;
|
||||||
|
for (const Pose pose, poseState) {
|
||||||
|
|
||||||
|
}
|
||||||
|
poseArrayList.append(poseArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void InputRecorder::loadRecording() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputRecorder::stopRecording() {
|
void InputRecorder::stopRecording() {
|
||||||
_recording = false;
|
_recording = false;
|
||||||
qDebug() << "--------------> input recording stopping <-----------------";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputRecorder::startPlayback() {
|
void InputRecorder::startPlayback() {
|
||||||
_playback = true;
|
_playback = true;
|
||||||
_recording = false;
|
_recording = false;
|
||||||
qDebug() << "-----------------> starting playback <---------------";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputRecorder::stopPlayback() {
|
void InputRecorder::stopPlayback() {
|
||||||
_playback = false;
|
_playback = false;
|
||||||
_recording = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputRecorder::setActionState(controller::Action action, float value) {
|
void InputRecorder::setActionState(controller::Action action, float value) {
|
||||||
if (_recording) {
|
if (_recording) {
|
||||||
qDebug() << "-----------------> setiing action state <---------------";
|
_currentFrameActions[toInt(action)] += value;
|
||||||
_actionStateList[_framesRecorded][toInt(action)] = value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputRecorder::setActionState(controller::Action action, const controller::Pose pose) {
|
void InputRecorder::setActionState(controller::Action action, const controller::Pose pose) {
|
||||||
if (_recording) {
|
if (_recording) {
|
||||||
qDebug() << "-----------------> setiing Pose state <---------------";
|
_currentFramePoses[toInt(action)] = pose;
|
||||||
_poseStateList[_framesRecorded][toInt(action)] = pose;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InputRecorder::resetFrame() {
|
||||||
|
if (_recording) {
|
||||||
|
for(auto& channel : _currentFramePoses) {
|
||||||
|
channel = Pose();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto& channel : _currentFrameActions) {
|
||||||
|
channel = 0.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
float InputRecorder::getActionState(controller::Action action) {
|
float InputRecorder::getActionState(controller::Action action) {
|
||||||
return _actionStateList[_playCount][toInt(action)];
|
if (_actionStateList.size() > 0 ) {
|
||||||
|
return _actionStateList[_playCount][toInt(action)];
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
controller::Pose InputRecorder::getPoseState(controller::Action action) {
|
controller::Pose InputRecorder::getPoseState(controller::Action action) {
|
||||||
return _poseStateList[_playCount][toInt(action)];
|
if (_poseStateList.size() > 0) {
|
||||||
|
return _poseStateList[_playCount][toInt(action)];
|
||||||
|
}
|
||||||
|
|
||||||
|
return Pose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputRecorder::frameTick() {
|
void InputRecorder::frameTick() {
|
||||||
if (_recording) {
|
if (_recording) {
|
||||||
_framesRecorded++;
|
_framesRecorded++;
|
||||||
|
_poseStateList.push_back(_currentFramePoses);
|
||||||
|
_actionStateList.push_back(_currentFrameActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_playback) {
|
if (_playback) {
|
||||||
if (_playCount < _framesRecorded) {
|
_playCount++;
|
||||||
_playCount++;
|
if (_playCount == _framesRecorded) {
|
||||||
} else {
|
|
||||||
_playCount = 0;
|
_playCount = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,11 +25,17 @@ namespace controller {
|
||||||
InputRecorder();
|
InputRecorder();
|
||||||
~InputRecorder();
|
~InputRecorder();
|
||||||
|
|
||||||
static InputRecorder& getInstance();
|
static InputRecorder* getInstance();
|
||||||
|
|
||||||
|
void saveRecording();
|
||||||
|
void loadRecording();
|
||||||
void startRecording();
|
void startRecording();
|
||||||
void startPlayback();
|
void startPlayback();
|
||||||
void stopPlayback();
|
void stopPlayback();
|
||||||
void stopRecording();
|
void stopRecording();
|
||||||
|
void toggleRecording() { _recording = !_recording; }
|
||||||
|
void togglePlayback() { _playback = !_playback; }
|
||||||
|
void resetFrame();
|
||||||
bool isRecording() { return _recording; }
|
bool isRecording() { return _recording; }
|
||||||
bool isPlayingback() { return _playback; }
|
bool isPlayingback() { return _playback; }
|
||||||
void setActionState(controller::Action action, float value);
|
void setActionState(controller::Action action, float value);
|
||||||
|
@ -40,8 +46,10 @@ namespace controller {
|
||||||
private:
|
private:
|
||||||
bool _recording { false };
|
bool _recording { false };
|
||||||
bool _playback { false };
|
bool _playback { false };
|
||||||
std::vector<PoseStates> _poseStateList;
|
std::vector<PoseStates> _poseStateList = std::vector<PoseStates>();
|
||||||
std::vector<ActionStates> _actionStateList;
|
std::vector<ActionStates> _actionStateList = std::vector<ActionStates>();
|
||||||
|
PoseStates _currentFramePoses = PoseStates(toInt(Action::NUM_ACTIONS));
|
||||||
|
ActionStates _currentFrameActions = ActionStates(toInt(Action::NUM_ACTIONS));
|
||||||
|
|
||||||
int _framesRecorded { 0 };
|
int _framesRecorded { 0 };
|
||||||
int _playCount { 0 };
|
int _playCount { 0 };
|
||||||
|
|
|
@ -156,23 +156,23 @@ namespace controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptingInterface::startInputRecording() {
|
void ScriptingInterface::startInputRecording() {
|
||||||
auto inputRecorder = InputRecorder::getInstance();
|
InputRecorder* inputRecorder = InputRecorder::getInstance();
|
||||||
inputRecorder.startRecording();
|
inputRecorder->startRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptingInterface::stopInputRecording() {
|
void ScriptingInterface::stopInputRecording() {
|
||||||
auto inputRecorder = InputRecorder::getInstance();
|
InputRecorder* inputRecorder = InputRecorder::getInstance();
|
||||||
inputRecorder.stopRecording();
|
inputRecorder->stopRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptingInterface::startInputPlayback() {
|
void ScriptingInterface::startInputPlayback() {
|
||||||
auto inputRecorder = InputRecorder::getInstance();
|
InputRecorder* inputRecorder = InputRecorder::getInstance();
|
||||||
inputRecorder.startPlayback();
|
inputRecorder->startPlayback();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptingInterface::stopInputPlayback() {
|
void ScriptingInterface::stopInputPlayback() {
|
||||||
auto inputRecorder = InputRecorder::getInstance();
|
InputRecorder* inputRecorder = InputRecorder::getInstance();
|
||||||
inputRecorder.stopPlayback();
|
inputRecorder->stopPlayback();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScriptingInterface::triggerHapticPulseOnDevice(unsigned int device, float strength, float duration, controller::Hand hand) const {
|
bool ScriptingInterface::triggerHapticPulseOnDevice(unsigned int device, float strength, float duration, controller::Hand hand) const {
|
||||||
|
|
|
@ -243,10 +243,11 @@ void fixBisectedAxis(float& full, float& negative, float& positive) {
|
||||||
|
|
||||||
void UserInputMapper::update(float deltaTime) {
|
void UserInputMapper::update(float deltaTime) {
|
||||||
Locker locker(_lock);
|
Locker locker(_lock);
|
||||||
auto inputRecorder = InputRecorder::getInstance();
|
InputRecorder* inputRecorder = InputRecorder::getInstance();
|
||||||
static uint64_t updateCount = 0;
|
static uint64_t updateCount = 0;
|
||||||
++updateCount;
|
++updateCount;
|
||||||
|
|
||||||
|
inputRecorder->resetFrame();
|
||||||
// Reset the axis state for next loop
|
// Reset the axis state for next loop
|
||||||
for (auto& channel : _actionStates) {
|
for (auto& channel : _actionStates) {
|
||||||
channel = 0.0f;
|
channel = 0.0f;
|
||||||
|
@ -298,7 +299,7 @@ void UserInputMapper::update(float deltaTime) {
|
||||||
emit inputEvent(input.id, value);
|
emit inputEvent(input.id, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inputRecorder.frameTick();
|
inputRecorder->frameTick();
|
||||||
}
|
}
|
||||||
|
|
||||||
Input::NamedVector UserInputMapper::getAvailableInputs(uint16 deviceID) const {
|
Input::NamedVector UserInputMapper::getAvailableInputs(uint16 deviceID) const {
|
||||||
|
@ -509,6 +510,7 @@ bool UserInputMapper::applyRoute(const Route::Pointer& route, bool force) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the source hasn't been written yet, defer processing of this route
|
// If the source hasn't been written yet, defer processing of this route
|
||||||
|
auto inputRecorder = InputRecorder::getInstance();
|
||||||
auto source = route->source;
|
auto source = route->source;
|
||||||
auto sourceInput = source->getInput();
|
auto sourceInput = source->getInput();
|
||||||
if (sourceInput.device == STANDARD_DEVICE && !force && source->writeable()) {
|
if (sourceInput.device == STANDARD_DEVICE && !force && source->writeable()) {
|
||||||
|
@ -572,7 +574,6 @@ bool UserInputMapper::applyRoute(const Route::Pointer& route, bool force) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// no filters yet for pose
|
// no filters yet for pose
|
||||||
qDebug() << "--------------> applying destination <----------------";
|
|
||||||
destination->apply(value, source);
|
destination->apply(value, source);
|
||||||
} else {
|
} else {
|
||||||
// Fetch the value, may have been overriden by previous loopback routes
|
// Fetch the value, may have been overriden by previous loopback routes
|
||||||
|
|
|
@ -16,23 +16,25 @@
|
||||||
using namespace controller;
|
using namespace controller;
|
||||||
|
|
||||||
void ActionEndpoint::apply(float newValue, const Pointer& source) {
|
void ActionEndpoint::apply(float newValue, const Pointer& source) {
|
||||||
|
InputRecorder* inputRecorder = InputRecorder::getInstance();
|
||||||
|
if(inputRecorder->isPlayingback()) {
|
||||||
|
newValue = inputRecorder->getActionState(Action(_input.getChannel()));
|
||||||
|
}
|
||||||
|
|
||||||
_currentValue += newValue;
|
_currentValue += newValue;
|
||||||
if (_input != Input::INVALID_INPUT) {
|
if (_input != Input::INVALID_INPUT) {
|
||||||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||||
userInputMapper->deltaActionState(Action(_input.getChannel()), newValue);
|
userInputMapper->deltaActionState(Action(_input.getChannel()), newValue);
|
||||||
}
|
}
|
||||||
auto inputRecorder = InputRecorder::getInstance();
|
inputRecorder->setActionState(Action(_input.getChannel()), newValue);
|
||||||
inputRecorder.setActionState(Action(_input.getChannel()), _currentValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionEndpoint::apply(const Pose& value, const Pointer& source) {
|
void ActionEndpoint::apply(const Pose& value, const Pointer& source) {
|
||||||
_currentPose = value;
|
_currentPose = value;
|
||||||
auto inputRecorder = InputRecorder::getInstance();
|
InputRecorder* inputRecorder = InputRecorder::getInstance();
|
||||||
inputRecorder.setActionState(Action(_input.getChannel()), _currentPose);
|
inputRecorder->setActionState(Action(_input.getChannel()), _currentPose);
|
||||||
qDebug << "<--------------- destination";
|
if (inputRecorder->isPlayingback()) {
|
||||||
if (inputRecorder.isPlayingback()) {
|
_currentPose = inputRecorder->getPoseState(Action(_input.getChannel()));
|
||||||
qDebug() << "-------------> playing back <--------------";
|
|
||||||
_currentPose = inputRecorder.getPoseState(Action(_input.getChannel()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_currentPose.isValid()) {
|
if (!_currentPose.isValid()) {
|
||||||
|
|
Loading…
Reference in a new issue