mirror of
https://github.com/overte-org/overte.git
synced 2025-08-05 00:59:56 +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 <input-plugins/InputPlugin.h>
|
||||
#include <controllers/UserInputMapper.h>
|
||||
#include <controllers/InputRecorder.h>
|
||||
#include <controllers/ScriptingInterface.h>
|
||||
#include <controllers/StateController.h>
|
||||
#include <UserActivityLoggerScriptingInterface.h>
|
||||
|
@ -2731,6 +2732,9 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
|||
if (isMeta) {
|
||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||
offscreenUi->load("Browser.qml");
|
||||
} else if (isOption) {
|
||||
controller::InputRecorder* inputRecorder = controller::InputRecorder::getInstance();
|
||||
inputRecorder->togglePlayback();
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -2929,6 +2933,9 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
|||
Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, !isFirstPersonChecked);
|
||||
Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, isFirstPersonChecked);
|
||||
cameraMenuChanged();
|
||||
} else if (isOption) {
|
||||
controller::InputRecorder* inputRecorder = controller::InputRecorder::getInstance();
|
||||
inputRecorder->toggleRecording();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -8,72 +8,122 @@
|
|||
|
||||
#include "InputRecorder.h"
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
#include <GLMHelpers.h>
|
||||
namespace controller {
|
||||
|
||||
void poseToJsonObject(const Pose pose) {
|
||||
}
|
||||
|
||||
InputRecorder::InputRecorder() {}
|
||||
|
||||
InputRecorder::~InputRecorder() {}
|
||||
|
||||
InputRecorder& InputRecorder::getInstance() {
|
||||
InputRecorder* InputRecorder::getInstance() {
|
||||
static InputRecorder inputRecorder;
|
||||
return inputRecorder;
|
||||
return &inputRecorder;
|
||||
}
|
||||
|
||||
void InputRecorder::startRecording() {
|
||||
_recording = true;
|
||||
_playback = false;
|
||||
_framesRecorded = 0;
|
||||
_poseStateList.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() {
|
||||
_recording = false;
|
||||
qDebug() << "--------------> input recording stopping <-----------------";
|
||||
}
|
||||
|
||||
void InputRecorder::startPlayback() {
|
||||
_playback = true;
|
||||
_recording = false;
|
||||
qDebug() << "-----------------> starting playback <---------------";
|
||||
}
|
||||
|
||||
void InputRecorder::stopPlayback() {
|
||||
_playback = false;
|
||||
_recording = false;
|
||||
}
|
||||
|
||||
void InputRecorder::setActionState(controller::Action action, float value) {
|
||||
if (_recording) {
|
||||
qDebug() << "-----------------> setiing action state <---------------";
|
||||
_actionStateList[_framesRecorded][toInt(action)] = value;
|
||||
_currentFrameActions[toInt(action)] += value;
|
||||
}
|
||||
}
|
||||
|
||||
void InputRecorder::setActionState(controller::Action action, const controller::Pose pose) {
|
||||
if (_recording) {
|
||||
qDebug() << "-----------------> setiing Pose state <---------------";
|
||||
_poseStateList[_framesRecorded][toInt(action)] = pose;
|
||||
_currentFramePoses[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) {
|
||||
return _actionStateList[_playCount][toInt(action)];
|
||||
if (_actionStateList.size() > 0 ) {
|
||||
return _actionStateList[_playCount][toInt(action)];
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
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() {
|
||||
if (_recording) {
|
||||
_framesRecorded++;
|
||||
_poseStateList.push_back(_currentFramePoses);
|
||||
_actionStateList.push_back(_currentFrameActions);
|
||||
}
|
||||
|
||||
if (_playback) {
|
||||
if (_playCount < _framesRecorded) {
|
||||
_playCount++;
|
||||
} else {
|
||||
_playCount++;
|
||||
if (_playCount == _framesRecorded) {
|
||||
_playCount = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,11 +25,17 @@ namespace controller {
|
|||
InputRecorder();
|
||||
~InputRecorder();
|
||||
|
||||
static InputRecorder& getInstance();
|
||||
static InputRecorder* getInstance();
|
||||
|
||||
void saveRecording();
|
||||
void loadRecording();
|
||||
void startRecording();
|
||||
void startPlayback();
|
||||
void stopPlayback();
|
||||
void stopRecording();
|
||||
void toggleRecording() { _recording = !_recording; }
|
||||
void togglePlayback() { _playback = !_playback; }
|
||||
void resetFrame();
|
||||
bool isRecording() { return _recording; }
|
||||
bool isPlayingback() { return _playback; }
|
||||
void setActionState(controller::Action action, float value);
|
||||
|
@ -40,8 +46,10 @@ namespace controller {
|
|||
private:
|
||||
bool _recording { false };
|
||||
bool _playback { false };
|
||||
std::vector<PoseStates> _poseStateList;
|
||||
std::vector<ActionStates> _actionStateList;
|
||||
std::vector<PoseStates> _poseStateList = std::vector<PoseStates>();
|
||||
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 _playCount { 0 };
|
||||
|
|
|
@ -156,23 +156,23 @@ namespace controller {
|
|||
}
|
||||
|
||||
void ScriptingInterface::startInputRecording() {
|
||||
auto inputRecorder = InputRecorder::getInstance();
|
||||
inputRecorder.startRecording();
|
||||
InputRecorder* inputRecorder = InputRecorder::getInstance();
|
||||
inputRecorder->startRecording();
|
||||
}
|
||||
|
||||
void ScriptingInterface::stopInputRecording() {
|
||||
auto inputRecorder = InputRecorder::getInstance();
|
||||
inputRecorder.stopRecording();
|
||||
InputRecorder* inputRecorder = InputRecorder::getInstance();
|
||||
inputRecorder->stopRecording();
|
||||
}
|
||||
|
||||
void ScriptingInterface::startInputPlayback() {
|
||||
auto inputRecorder = InputRecorder::getInstance();
|
||||
inputRecorder.startPlayback();
|
||||
InputRecorder* inputRecorder = InputRecorder::getInstance();
|
||||
inputRecorder->startPlayback();
|
||||
}
|
||||
|
||||
void ScriptingInterface::stopInputPlayback() {
|
||||
auto inputRecorder = InputRecorder::getInstance();
|
||||
inputRecorder.stopPlayback();
|
||||
InputRecorder* inputRecorder = InputRecorder::getInstance();
|
||||
inputRecorder->stopPlayback();
|
||||
}
|
||||
|
||||
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) {
|
||||
Locker locker(_lock);
|
||||
auto inputRecorder = InputRecorder::getInstance();
|
||||
InputRecorder* inputRecorder = InputRecorder::getInstance();
|
||||
static uint64_t updateCount = 0;
|
||||
++updateCount;
|
||||
|
||||
inputRecorder->resetFrame();
|
||||
// Reset the axis state for next loop
|
||||
for (auto& channel : _actionStates) {
|
||||
channel = 0.0f;
|
||||
|
@ -298,7 +299,7 @@ void UserInputMapper::update(float deltaTime) {
|
|||
emit inputEvent(input.id, value);
|
||||
}
|
||||
}
|
||||
inputRecorder.frameTick();
|
||||
inputRecorder->frameTick();
|
||||
}
|
||||
|
||||
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
|
||||
auto inputRecorder = InputRecorder::getInstance();
|
||||
auto source = route->source;
|
||||
auto sourceInput = source->getInput();
|
||||
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
|
||||
qDebug() << "--------------> applying destination <----------------";
|
||||
destination->apply(value, source);
|
||||
} else {
|
||||
// Fetch the value, may have been overriden by previous loopback routes
|
||||
|
|
|
@ -16,23 +16,25 @@
|
|||
using namespace controller;
|
||||
|
||||
void ActionEndpoint::apply(float newValue, const Pointer& source) {
|
||||
InputRecorder* inputRecorder = InputRecorder::getInstance();
|
||||
if(inputRecorder->isPlayingback()) {
|
||||
newValue = inputRecorder->getActionState(Action(_input.getChannel()));
|
||||
}
|
||||
|
||||
_currentValue += newValue;
|
||||
if (_input != Input::INVALID_INPUT) {
|
||||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||
userInputMapper->deltaActionState(Action(_input.getChannel()), newValue);
|
||||
}
|
||||
auto inputRecorder = InputRecorder::getInstance();
|
||||
inputRecorder.setActionState(Action(_input.getChannel()), _currentValue);
|
||||
inputRecorder->setActionState(Action(_input.getChannel()), newValue);
|
||||
}
|
||||
|
||||
void ActionEndpoint::apply(const Pose& value, const Pointer& source) {
|
||||
_currentPose = value;
|
||||
auto inputRecorder = InputRecorder::getInstance();
|
||||
inputRecorder.setActionState(Action(_input.getChannel()), _currentPose);
|
||||
qDebug << "<--------------- destination";
|
||||
if (inputRecorder.isPlayingback()) {
|
||||
qDebug() << "-------------> playing back <--------------";
|
||||
_currentPose = inputRecorder.getPoseState(Action(_input.getChannel()));
|
||||
InputRecorder* inputRecorder = InputRecorder::getInstance();
|
||||
inputRecorder->setActionState(Action(_input.getChannel()), _currentPose);
|
||||
if (inputRecorder->isPlayingback()) {
|
||||
_currentPose = inputRecorder->getPoseState(Action(_input.getChannel()));
|
||||
}
|
||||
|
||||
if (!_currentPose.isValid()) {
|
||||
|
|
Loading…
Reference in a new issue