Merge branch 'master' into feature/animation-fixes

This commit is contained in:
Malin E
2021-09-22 15:00:19 +02:00
8 changed files with 99 additions and 15 deletions
+13 -3
View File
@@ -434,13 +434,23 @@ scripting::LuaLibrary PathNavigator::luaLibrary() {
"motion. If the optional bool is set to true, the target up vector for "
"camera is set based on the target node. Either of the optional "
"parameters can be left out."
},
{
"goToNavigationState",
&luascriptfunctions::goToNavigationState,
{},
"table, [double]",
"Create a path to the navigation state described by the input table. "
"The optional double specifies the target duration of the motion. Note "
"that roll must be included for the target up direction to be taken "
"into account."
},
{
"generatePath",
&luascriptfunctions::generatePath,
"createPath",
&luascriptfunctions::createPath,
{},
"table",
"Generate the path as described by the lua table input argument"
"Create the path as described by the lua table input argument"
},
}
};
+44 -3
View File
@@ -26,6 +26,7 @@
#include <openspace/engine/globals.h>
#include <openspace/engine/moduleengine.h>
#include <openspace/navigation/navigationhandler.h>
#include <openspace/navigation/navigationstate.h>
#include <openspace/navigation/pathnavigator.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/scripting/lualibrary.h>
@@ -124,7 +125,7 @@ int goToHeight(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, { 2, 4 }, "lua::goToHeight");
auto [nodeIdentifier, height, useUpFromTargetOrDuration, duration] =
ghoul::lua::values<
std::string, double, std::optional<std::variant<bool, double>>,
std::string, double, std::optional<std::variant<bool, double>>,
std::optional<double>
>(L);
@@ -170,8 +171,48 @@ int goToHeight(lua_State* L) {
return 0;
}
int generatePath(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::generatePath");
int goToNavigationState(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, { 1, 2 }, "lua::goToNavigationState");
auto [navigationState, duration] =
ghoul::lua::values<ghoul::Dictionary, std::optional<double>>(L);
try {
openspace::documentation::testSpecificationAndThrow(
interaction::NavigationState::Documentation(),
navigationState,
"NavigationState"
);
}
catch (documentation::SpecificationError& e) {
LERRORC("goToNavigationState", ghoul::to_string(e.result));
return ghoul::lua::luaError(
L, fmt::format("Unable to create a path: {}", e.what())
);
}
using namespace std::string_literals;
ghoul::Dictionary instruction;
instruction.setValue("TargetType", "NavigationState"s);
instruction.setValue("NavigationState", navigationState);
if (duration.has_value()) {
double d = *duration;
if (d <= Epsilon) {
return ghoul::lua::luaError(L, "Duration must be larger than zero");
}
instruction.setValue("Duration", d);
}
global::navigationHandler->pathNavigator().createPath(instruction);
if (global::navigationHandler->pathNavigator().hasCurrentPath()) {
global::navigationHandler->pathNavigator().startPath();
}
return 0;
}
int createPath(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::createPath");
ghoul::Dictionary dictionary = ghoul::lua::value<ghoul::Dictionary>(L);
global::navigationHandler->pathNavigator().createPath(dictionary);