diff --git a/ext/ghoul b/ext/ghoul index b019427a8f..bd812defd7 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit b019427a8f6df48c3ed46f2980821deb79e701d3 +Subproject commit bd812defd787ad34119cfe7ecef2be71a7a1553e diff --git a/include/openspace/interaction/orbitalnavigator.h b/include/openspace/interaction/orbitalnavigator.h index c453691809..e541ab23fd 100644 --- a/include/openspace/interaction/orbitalnavigator.h +++ b/include/openspace/interaction/orbitalnavigator.h @@ -65,9 +65,9 @@ public: void setCamera(Camera* camera); void clearPreviousState(); - SceneGraphNode* focusNode() const; - void setFocusNode(const SceneGraphNode* focusNode); - void setFocusNode(const std::string& focusNode); + void setFocusNode(const SceneGraphNode* focusNode, + bool resetVelocitiesOnChange = true); + void setFocusNode(const std::string& focusNode, bool resetVelocitiesOnChange = true); void setAnchorNode(const std::string& anchorNode); void setAimNode(const std::string& aimNode); @@ -121,7 +121,8 @@ private: properties::FloatProperty friction; }; - void setAnchorNode(const SceneGraphNode* anchorNode); + void setAnchorNode(const SceneGraphNode* anchorNode, + bool resetVelocitiesOnChange = true); void setAimNode(const SceneGraphNode* aimNode); Camera* _camera; diff --git a/modules/server/src/topics/flightcontrollertopic.cpp b/modules/server/src/topics/flightcontrollertopic.cpp index 6d8dc96573..3e2289c5a5 100644 --- a/modules/server/src/topics/flightcontrollertopic.cpp +++ b/modules/server/src/topics/flightcontrollertopic.cpp @@ -75,6 +75,11 @@ namespace { // Change focus JSON keys constexpr const char* FocusKey = "focus"; + constexpr const char* AnchorKey = "anchor"; + constexpr const char* AimKey = "aim"; + constexpr const char* ResetVelocitiesKey = "resetVelocities"; + constexpr const char* RetargetAnchorKey = "retargetAnchor"; + constexpr const char* RetargetAimKey = "retargetAim"; constexpr const char* SceneNodeName = "identifier"; constexpr const char* SceneNodeEnabled = "enabled"; @@ -282,31 +287,68 @@ void FlightControllerTopic::setInterestingTimes() { } void FlightControllerTopic::updateView(const nlohmann::json& json) const { - if (json.find(FocusKey) != json.end()) { - changeFocus(json); - } + if (json.find(RenderableKey) != json.end()) { setRenderableEnabled(json); } + else { + changeFocus(json); + } } void FlightControllerTopic::changeFocus(const nlohmann::json& json) const { - if (json[FocusKey].find(SceneNodeName) == json[FocusKey].end()) { + if (json.find(FocusKey) == json.end()) { const std::string j = json; LWARNING( fmt::format("Could not find {} key in JSON. JSON was:\n{}", FocusKey, j) ); - return; + if (json.find(AimKey) == json.end()) { + const std::string j = json; + LWARNING( + fmt::format("Could not find {} key in JSON. JSON was:\n{}", AimKey, j) + ); + if (json.find(AnchorKey) == json.end()) { + const std::string j = json; + LWARNING(fmt::format( + "Could not find {} key in JSON. JSON was:\n{}", AnchorKey, j + )); + return; + } + } } - const std::string focus = json[FocusKey][SceneNodeName]; - const SceneGraphNode* node = global::renderEngine.scene()->sceneGraphNode(focus); - if (node) { - global::navigationHandler.orbitalNavigator().setFocusNode(node->identifier()); - global::navigationHandler.orbitalNavigator().startRetargetAnchor(); + const std::string focus = json.find(FocusKey) != json.end() ? json[FocusKey] : ""; + const std::string aim = json.find(AimKey) != json.end() ? json[AimKey] : ""; + const std::string anchor = json.find(AnchorKey) != json.end() ? json[AnchorKey] : ""; + + const bool resetVelocities = json[ResetVelocitiesKey]; + const bool retargetAnchor = json[RetargetAnchorKey]; + const bool retargetAim = json[RetargetAimKey]; + + Scene* scene = global::renderEngine.scene(); + const SceneGraphNode* focusNode = scene->sceneGraphNode(focus); + const SceneGraphNode* aimNode = scene->sceneGraphNode(aim); + const SceneGraphNode* anchorNode = scene->sceneGraphNode(anchor); + if (focusNode) { + global::navigationHandler.orbitalNavigator().setFocusNode( + focusNode, + resetVelocities + ); } else { - LWARNING(fmt::format("Could not find node named {}", focus)); + if (aimNode) { + global::navigationHandler.orbitalNavigator().setAimNode(aim); + } + if (anchorNode) { + global::navigationHandler.orbitalNavigator().setAnchorNode(anchor); + } + } + + if (retargetAnchor) { + global::navigationHandler.orbitalNavigator().startRetargetAnchor(); + } + if (retargetAim) { + global::navigationHandler.orbitalNavigator().startRetargetAim(); } } diff --git a/src/interaction/orbitalnavigator.cpp b/src/interaction/orbitalnavigator.cpp index bbee6702f0..bbeeb8c7d8 100644 --- a/src/interaction/orbitalnavigator.cpp +++ b/src/interaction/orbitalnavigator.cpp @@ -659,17 +659,21 @@ glm::dvec3 OrbitalNavigator::cameraToSurfaceVector(const glm::dvec3& cameraPos, return centerToActualSurface - posDiff; } -void OrbitalNavigator::setFocusNode(const SceneGraphNode* focusNode) { - setAnchorNode(focusNode); +void OrbitalNavigator::setFocusNode(const SceneGraphNode* focusNode, + bool resetVelocitiesOnChange) +{ + setAnchorNode(focusNode, resetVelocitiesOnChange); setAimNode(nullptr); } -void OrbitalNavigator::setFocusNode(const std::string& focusNode) { +void OrbitalNavigator::setFocusNode(const std::string& focusNode, bool) { _anchor.set(focusNode); _aim.set(std::string("")); } -void OrbitalNavigator::setAnchorNode(const SceneGraphNode* anchorNode) { +void OrbitalNavigator::setAnchorNode(const SceneGraphNode* anchorNode, + bool resetVelocitiesOnChange) +{ if (!_anchorNode) { _directlySetStereoDistance = true; } @@ -679,7 +683,7 @@ void OrbitalNavigator::setAnchorNode(const SceneGraphNode* anchorNode) { // Need to reset velocities after the actual switch in anchor node, // since the reset behavior depends on the anchor node. - if (changedAnchor) { + if (changedAnchor && resetVelocitiesOnChange) { resetVelocities(); }