From d060780f99d7962b5990c2965cba5fe3b88ee63d Mon Sep 17 00:00:00 2001 From: Gene Payne Date: Mon, 22 Mar 2021 12:21:32 -0600 Subject: [PATCH] Added method for saving current value of a property while recording --- include/openspace/interaction/sessionrecording.h | 13 +++++++++++++ src/interaction/sessionrecording.cpp | 8 ++++++++ src/scene/scene_lua.inl | 6 ++++++ 3 files changed, 27 insertions(+) diff --git a/include/openspace/interaction/sessionrecording.h b/include/openspace/interaction/sessionrecording.h index 3f52d346a6..a27f6711c6 100644 --- a/include/openspace/interaction/sessionrecording.h +++ b/include/openspace/interaction/sessionrecording.h @@ -420,6 +420,18 @@ public: void saveScriptKeyframeAscii(Timestamps& times, datamessagestructures::ScriptMessage& sm, std::ofstream& file); + /** + * Since session recordings only record changes, the initial conditions aren't + * preserved when a playback starts. This function is called whenever a property + * value is set and a recording is in progress. Before the set happens, this + * function will read the current value of the property and store it so that when + * the recording is finished, the initial state will be added as a set property + * command at the beginning of the recording file, to be applied when playback + * starts. + * + * \param prop The property being set + */ + void savePropertyBaseline(properties::Property& prop); /** * Reads header information from a session recording file * @@ -658,6 +670,7 @@ protected: std::vector _keyframesTime; std::vector _keyframesScript; std::vector _timeline; + std::vector _keyframesSavePropertiesBaseline; unsigned int _idxTimeline_nonCamera = 0; unsigned int _idxTime = 0; diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index b5c418708d..10d067480b 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -701,6 +701,14 @@ void SessionRecording::saveScriptKeyframeAscii(Timestamps& times, saveKeyframeToFile(keyframeLine.str(), file); } +void SessionRecording::savePropertyBaseline(properties::Property& prop) { + std::string initialScriptCommand = fmt::format( + "openspace.setPropertyValueSingle(\"{}\", {})", + prop.fullyQualifiedIdentifier(), prop.getStringValue() + ); + _keyframesSavePropertiesBaseline.push_back(initialScriptCommand); +} + void SessionRecording::preSynchronization() { ZoneScoped diff --git a/src/scene/scene_lua.inl b/src/scene/scene_lua.inl index ca45fad370..6092fba38c 100644 --- a/src/scene/scene_lua.inl +++ b/src/scene/scene_lua.inl @@ -194,6 +194,9 @@ void applyRegularExpression(lua_State* L, const std::string& regex, // value change if the types agree foundMatching = true; + if (global::sessionRecording->isRecording()) { + global::sessionRecording->savePropertyBaseline(*prop); + } if (interpolationDuration == 0.0) { global::renderEngine->scene()->removePropertyInterpolation(prop); prop->setLuaValue(L); @@ -265,6 +268,9 @@ int setPropertyCall_single(properties::Property& prop, const std::string& uri, ); } else { + if (global::sessionRecording->isRecording()) { + global::sessionRecording->savePropertyBaseline(prop); + } if (duration == 0.0) { global::renderEngine->scene()->removePropertyInterpolation(&prop); prop.setLuaValue(L);