diff --git a/src/animations.cpp b/src/animations.cpp index 8498e2d..245a5cf 100644 --- a/src/animations.cpp +++ b/src/animations.cpp @@ -260,6 +260,14 @@ void _Animations::setSceneScale(float scale) _sceneScale = scale; } +void _Animations::reset() +{ + propsMap.clear(); + trackersMap.clear(); + actorsMap.clear(); + facesMap.clear(); +} + void _Animations::animatePropOrTracker(QJsonObject obj, const MDagPath &dagPath) { // bool isLive = obj["isLive"].toBool(); diff --git a/src/animations.h b/src/animations.h index b888db0..d21f08f 100644 --- a/src/animations.h +++ b/src/animations.h @@ -31,6 +31,7 @@ class _Animations float sceneScale() { return _sceneScale; } float timestamp; float playbackTimestamp; + void reset(); private: float _sceneScale = 1.0; // prop id - json diff --git a/src/constants.h b/src/constants.h index 86d53db..b36d397 100644 --- a/src/constants.h +++ b/src/constants.h @@ -10,7 +10,7 @@ static const int DEFAULT_RS_PORT = 14043; static const int DEFAULT_RS_API_PORT = 14053; static const int VERSION_MAJOR = 0; -static const int VERSION_MINOR = 1; +static const int VERSION_MINOR = 2; static const int VERSION_PATCH = 0; static const int RECEIVER_FPS = 30; diff --git a/src/main.cpp b/src/main.cpp index 64f82f6..e1715f2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,6 @@ #include "ui/rootwidget.h" #include "constants.h" -#include "mapping.h" +#include "utils.h" #include #include @@ -56,6 +56,7 @@ MStatus uninitializePlugin(MObject plugin) rsmlScrollArea.clear(); } - Mapping::get()->resetCallbacks(); + Utils::RSLMShutdown(); + return result; } diff --git a/src/mapping.cpp b/src/mapping.cpp index 0cc3d30..fac2361 100644 --- a/src/mapping.cpp +++ b/src/mapping.cpp @@ -134,19 +134,7 @@ _Mapping::_Mapping() studioTPose["rightFoot"] = MQuaternion(-0.000, 0.707, -0.707, 0.000); studioTPose["rightToe"] = MQuaternion(0.000, 0.707, -0.707, 0.000); - // register callbacks - MCallbackId beforeNewId = MSceneMessage::addCheckCallback(MSceneMessage::kBeforeNewCheck, [](bool* recCode, void* clientData) { - Q_UNUSED(clientData) - Mapping::get()->clear(); - *recCode = true; - }); - MCallbackId beforeOpenId = MSceneMessage::addCheckCallback(MSceneMessage::kBeforeOpenCheck, [](bool* recCode, void* clientData) { - Q_UNUSED(clientData) - Mapping::get()->clear(); - *recCode = true; - }); - callbacks.append(beforeNewId); - callbacks.append(beforeOpenId); + installCallbacks(); faceShapeNames << "eyeBlinkLeft" << "eyeLookDownLeft" @@ -681,11 +669,35 @@ void _Mapping::clear() objectsMap.clear(); } +void _Mapping::reset() +{ + clear(); + resetCallbacks(); +} + +void _Mapping::installCallbacks() +{ + // register callbacks + MCallbackId beforeNewId = MSceneMessage::addCheckCallback(MSceneMessage::kBeforeNewCheck, [](bool* recCode, void* clientData) { + Q_UNUSED(clientData) + Mapping::get()->clear(); + *recCode = true; + }); + MCallbackId beforeOpenId = MSceneMessage::addCheckCallback(MSceneMessage::kBeforeOpenCheck, [](bool* recCode, void* clientData) { + Q_UNUSED(clientData) + Mapping::get()->clear(); + *recCode = true; + }); + callbacks.append(beforeNewId); + callbacks.append(beforeOpenId); +} + void _Mapping::resetCallbacks() { for(MCallbackId id : callbacks) { MSceneMessage::removeCallback(id); } + callbacks.clear(); } const QMultiMap &_Mapping::getObjectMapping() diff --git a/src/mapping.h b/src/mapping.h index 7b6c57c..4804e12 100644 --- a/src/mapping.h +++ b/src/mapping.h @@ -44,6 +44,9 @@ class _Mapping void unmapAllFaces(QString rsId); void clear(); + + void reset(); + void installCallbacks(); void resetCallbacks(); const QMultiMap &getObjectMapping(); diff --git a/src/receiverworker.cpp b/src/receiverworker.cpp index e562f8d..0b3b419 100644 --- a/src/receiverworker.cpp +++ b/src/receiverworker.cpp @@ -17,6 +17,11 @@ DataReceivingWorker::DataReceivingWorker(QObject* parent) hearbeat.start(); } +DataReceivingWorker::~DataReceivingWorker() +{ + +} + void DataReceivingWorker::pause() { socket->abort(); } diff --git a/src/receiverworker.h b/src/receiverworker.h index 35fcebf..97b4a3c 100644 --- a/src/receiverworker.h +++ b/src/receiverworker.h @@ -15,6 +15,7 @@ class DataReceivingWorker : public QObject Q_OBJECT public: DataReceivingWorker(QObject* parent=nullptr); + ~DataReceivingWorker(); public slots: void start(int port=DEFAULT_RS_PORT); void pause(); diff --git a/src/recorder.cpp b/src/recorder.cpp index 3d72572..55df795 100644 --- a/src/recorder.cpp +++ b/src/recorder.cpp @@ -98,3 +98,8 @@ QList _Recorder::sortedTimeStamps() std::sort(timestamps.begin(), timestamps.end()); return timestamps; } + +void _Recorder::reset() +{ + recordedData.clear(); +} diff --git a/src/recorder.h b/src/recorder.h index b87ba36..1f7385c 100644 --- a/src/recorder.h +++ b/src/recorder.h @@ -37,6 +37,7 @@ class _Recorder float recordingStartTime() {return mRecordingStartTime ;} QList sortedTimeStamps(); + void reset(); private: // timestamp - set keyframe function QHash>> recordedData; diff --git a/src/ui/infocontent.cpp b/src/ui/infocontent.cpp index 99b9d2b..0229373 100644 --- a/src/ui/infocontent.cpp +++ b/src/ui/infocontent.cpp @@ -1,3 +1,4 @@ +#include "constants.h" #include "utils.h" #include "infocontent.h" #include @@ -25,7 +26,8 @@ InfoContent::InfoContent(QWidget* parent) : QWidget(parent) QLabel* infoLabel = new QLabel(this); infoLabel->setWordWrap(true); - infoLabel->setText("Rokoko Studio Live for Maya v1.0.0\n\nDeveloped by Rokoko Electronics Aps"); + QString infoText = QString("Rokoko Studio Live for Maya v%1.%2.%3\n\nDeveloped by Rokoko Electronics Aps").arg(VERSION_MAJOR).arg(VERSION_MINOR).arg(VERSION_PATCH); + infoLabel->setText(infoText); infoLayout->addWidget(infoLabel, 0, Qt::AlignLeft); mainLayout->addLayout(infoLayout); diff --git a/src/ui/receivercontent.cpp b/src/ui/receivercontent.cpp index 720d042..091cbe4 100644 --- a/src/ui/receivercontent.cpp +++ b/src/ui/receivercontent.cpp @@ -67,13 +67,16 @@ ReceiverContent::ReceiverContent(QWidget* parent) : QWidget(parent) formLayout->addRow("Scene scale:", sceneScaleBox); mainLayout->addLayout(formLayout); - // reset scene on stop option - QCheckBox* cbResetSceneOnStop = new QCheckBox("Reset Scene on Stop", this); - mainLayout->addWidget(cbResetSceneOnStop); + if(false) + { + // reset scene on stop option + QCheckBox* cbResetSceneOnStop = new QCheckBox("Reset Scene on Stop", this); + mainLayout->addWidget(cbResetSceneOnStop); - // hide meshes during play - QCheckBox* cbHideMeshesDuringPlay = new QCheckBox("Hide Meshes during Play", this); - mainLayout->addWidget(cbHideMeshesDuringPlay); + // hide meshes during play + QCheckBox* cbHideMeshesDuringPlay = new QCheckBox("Hide Meshes during Play", this); + mainLayout->addWidget(cbHideMeshesDuringPlay); + } // start receiver button ButtonParams receiverBtnParams; @@ -141,6 +144,7 @@ ReceiverContent::~ReceiverContent() for(MCallbackId id : callbacks) { MSceneMessage::removeCallback(id); } + callbacks.clear(); } diff --git a/src/ui/receivercontent.h b/src/ui/receivercontent.h index b44978e..e1ca93c 100644 --- a/src/ui/receivercontent.h +++ b/src/ui/receivercontent.h @@ -17,6 +17,8 @@ class ReceiverContent : public QWidget public: ReceiverContent(QWidget* parent=nullptr); ~ReceiverContent(); + + void reset(); private: void onReceiverToggled(bool); QSpinBox* portBox=nullptr; @@ -29,7 +31,6 @@ class ReceiverContent : public QWidget void recordingToggled(bool checked); void populateTree(); void clearTreeWidget(); - void reset(); MCallbackIdArray callbacks; }; diff --git a/src/ui/rootwidget.cpp b/src/ui/rootwidget.cpp index 9b20541..c526563 100644 --- a/src/ui/rootwidget.cpp +++ b/src/ui/rootwidget.cpp @@ -1,5 +1,8 @@ #include +#include "mapping.h" +#include "utils.h" + #include "ui/rootwidget.h" #include "ui/categoryheader.h" #include "ui/infocontent.h" @@ -78,3 +81,26 @@ RootWidget::~RootWidget() { } + +void RootWidget::closeEvent(QCloseEvent *event) +{ + QWidget::closeEvent(event); + +} + +void RootWidget::showEvent(QShowEvent *event) +{ + QWidget::showEvent(event); + + Utils::RSLMInit(); +} + +void RootWidget::hideEvent(QHideEvent *event) +{ + QWidget::hideEvent(event); + + receiverContent->reset(); + + Utils::RSLMShutdown(); + +} diff --git a/src/ui/rootwidget.h b/src/ui/rootwidget.h index cb1cde9..9985961 100644 --- a/src/ui/rootwidget.h +++ b/src/ui/rootwidget.h @@ -12,6 +12,10 @@ class RootWidget : public QWidget public: RootWidget(QWidget *parent = nullptr); ~RootWidget(); +protected: + void closeEvent(QCloseEvent *event) override; + void showEvent(QShowEvent *event) override; + void hideEvent(QHideEvent *event) override; private: ReceiverContent* receiverContent=nullptr; }; diff --git a/src/utils.cpp b/src/utils.cpp index ab04f15..1cec9e0 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1,5 +1,9 @@ #include "utils.h" +#include "mapping.h" +#include "animations.h" +#include "recorder.h" + #include #include @@ -49,3 +53,16 @@ void Utils::fillFaceWeightsMap(const MFnBlendShapeDeformer &bsFn, QHashinstallCallbacks(); + Mapping::get()->syncMapping(); +} + +void Utils::RSLMShutdown() +{ + Recorder::get()->reset(); + Mapping::get()->reset(); + Animations::get()->reset(); +} diff --git a/src/utils.h b/src/utils.h index 84165a8..432ceae 100644 --- a/src/utils.h +++ b/src/utils.h @@ -13,6 +13,8 @@ class Utils { static MVector rsToMaya(MVector); static MQuaternion rsToMaya(MQuaternion); static void fillFaceWeightsMap(const MFnBlendShapeDeformer &bsFn, QHash &map); + static void RSLMInit(); + static void RSLMShutdown(); };