diff --git a/modules/autonavigation/autonavigationmodule.cpp b/modules/autonavigation/autonavigationmodule.cpp index a42a736e54..37c48e3283 100644 --- a/modules/autonavigation/autonavigationmodule.cpp +++ b/modules/autonavigation/autonavigationmodule.cpp @@ -92,9 +92,18 @@ scripting::LuaLibrary AutoNavigationModule::luaLibrary() const { &autonavigation::luascriptfunctions::goTo, {}, "string, [double]", - "Mov the camera to the node with the specified. The optional parameter " + "Move the camera to the node with the specified name. The optional parameter " "specifies the duration of the motion." }, + { + "goToHeight", + &autonavigation::luascriptfunctions::goToHeight, + {}, + "string, double, [double]", + "Move the camera to the node with the specified name. The second input " + "parameter is the desired target height and the the optional third " + "parameter specifies the duration of the motion." + }, { "generatePath", &autonavigation::luascriptfunctions::generatePath, diff --git a/modules/autonavigation/autonavigationmodule_lua.inl b/modules/autonavigation/autonavigationmodule_lua.inl index 53894ed82d..a23ae226e4 100644 --- a/modules/autonavigation/autonavigationmodule_lua.inl +++ b/modules/autonavigation/autonavigationmodule_lua.inl @@ -45,8 +45,7 @@ int continuePath(lua_State* L) { ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::continuePath"); AutoNavigationModule* module = global::moduleEngine->module(); - AutoNavigationHandler& handler = module->AutoNavigationHandler(); - handler.continuePath(); + module->AutoNavigationHandler().continuePath(); return 0; } @@ -55,8 +54,7 @@ int stopPath(lua_State* L) { ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::stopPath"); AutoNavigationModule* module = global::moduleEngine->module(); - AutoNavigationHandler& handler = module->AutoNavigationHandler(); - handler.abortPath(); + module->AutoNavigationHandler().abortPath(); return 0; } @@ -86,8 +84,42 @@ int goTo(lua_State* L) { PathSpecification spec = PathSpecification(TargetNodeInstruction{insDict}); AutoNavigationModule* module = global::moduleEngine->module(); - AutoNavigationHandler& handler = module->AutoNavigationHandler(); - handler.createPath(spec); + module->AutoNavigationHandler().createPath(spec); + + lua_settop(L, 0); + ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack"); + return 0; +} + +int goToHeight(lua_State* L) { + int nArguments = ghoul::lua::checkArgumentsAndThrow(L, { 2, 3 }, "lua::goToHeight"); + + const std::string& nodeIdentifier = ghoul::lua::value(L, 1); + + if (!sceneGraphNode(nodeIdentifier)) { + lua_settop(L, 0); + return ghoul::lua::luaError(L, "Unknown node name: " + nodeIdentifier); + } + + double height = ghoul::lua::value(L, 2); + + ghoul::Dictionary insDict; + insDict.setValue("Target", nodeIdentifier); + insDict.setValue("Height", height); + + if (nArguments > 2) { + double duration = ghoul::lua::value(L, 3); + if (duration <= EPSILON) { + lua_settop(L, 0); + return ghoul::lua::luaError(L, "Duration must be larger than zero."); + } + insDict.setValue("Duration", duration); + } + + PathSpecification spec = PathSpecification(TargetNodeInstruction{ insDict }); + + AutoNavigationModule* module = global::moduleEngine->module(); + module->AutoNavigationHandler().createPath(spec); lua_settop(L, 0); ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack"); @@ -109,8 +141,7 @@ int generatePath(lua_State* L) { } AutoNavigationModule* module = global::moduleEngine->module(); - AutoNavigationHandler& handler = module->AutoNavigationHandler(); - handler.createPath(spec); + module->AutoNavigationHandler().createPath(spec); lua_settop(L, 0); ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack"); @@ -163,8 +194,7 @@ int generatePathFromFile(lua_State* L) { LINFOC("AutoNavigationModule", "Reading succeeded. Creating path"); AutoNavigationModule* module = global::moduleEngine->module(); - AutoNavigationHandler& handler = module->AutoNavigationHandler(); - handler.createPath(spec); + module->AutoNavigationHandler().createPath(spec); ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack"); return 0;