Add Lua method to check whether a scenegraphnode is present in the scene

Make use of the function to guard mark_interesting_nodes against a nonexisting scenegraph node
This commit is contained in:
Alexander Bock
2017-10-24 03:41:02 -07:00
parent 1c2622248c
commit a1b2695765
3 changed files with 22 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
mark_interesting_nodes = function(nodes)
for _, n in pairs(nodes) do
openspace.addTag(n, "GUI.Interesting")
if openspace.hasSceneGraphNode(n) then
openspace.addTag(n, "GUI.Interesting")
end
end
end

View File

@@ -416,6 +416,13 @@ scripting::LuaLibrary Scene::luaLibrary() {
&luascriptfunctions::removeSceneGraphNode,
"string",
"Removes the SceneGraphNode identified by name"
},
{
"hasSceneGraphNode",
&luascriptfunctions::hasSceneGraphNode,
"string",
"Checks whether the specifies SceneGraphNode is present in the current "
"scene"
}
}
};

View File

@@ -390,4 +390,16 @@ int removeSceneGraphNode(lua_State* L) {
return 1;
}
int hasSceneGraphNode(lua_State* L) {
int nArguments = lua_gettop(L);
SCRIPT_CHECK_ARGUMENTS("removeSceneGraphNode", L, 1, nArguments);
std::string nodeName = luaL_checkstring(L, -1);
SceneGraphNode* node = OsEng.renderEngine().scene()->sceneGraphNode(nodeName);
lua_pushboolean(L, node != nullptr);
return 1;
}
} // namespace openspace::luascriptfunctions