From d1821ae0e412bc760f4cc8abc5f1aaa0757e3291 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Tue, 23 Nov 2021 10:00:51 +0100 Subject: [PATCH] Add lua functions to get the bounding and interaction sphere values for a SGN --- src/scene/scene.cpp | 14 ++++++++++++++ src/scene/scene_lua.inl | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index f13197155b..5cf74e1ccf 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -915,6 +915,20 @@ scripting::LuaLibrary Scene::luaLibrary() { "string, string", "The scene graph node identified by the first string is reparented to be " "a child of the scene graph node identified by the second string." + }, + { + "boundingSphere", + &luascriptfunctions::boundingSphere, + "string", + "Returns the bounding sphere of the scene graph node with the given " + "string as identifier" + }, + { + "interactionSphere", + &luascriptfunctions::interactionSphere, + "string", + "Returns the interaction sphere of the scene graph node with the given " + "string as identifier" } } }; diff --git a/src/scene/scene_lua.inl b/src/scene/scene_lua.inl index bd6650045b..384dd85da2 100644 --- a/src/scene/scene_lua.inl +++ b/src/scene/scene_lua.inl @@ -926,6 +926,40 @@ int setParent(lua_State* L) { return 0; } +int boundingSphere(lua_State* L) { + ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::boundingSphere"); + const std::string identifier = ghoul::lua::value(L); + + SceneGraphNode* node = sceneGraphNode(identifier); + if (!node) { + return ghoul::lua::luaError( + L, + fmt::format("Did not find a match for identifier: {} ", identifier) + ); + } + + double bs = node->boundingSphere(); + ghoul::lua::push(L, bs); + return 1; +} + +int interactionSphere(lua_State* L) { + ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::interactionSphere"); + const std::string identifier = ghoul::lua::value(L); + + SceneGraphNode* node = sceneGraphNode(identifier); + if (!node) { + return ghoul::lua::luaError( + L, + fmt::format("Did not find a match for identifier: {} ", identifier) + ); + } + + double is = node->interactionSphere(); + ghoul::lua::push(L, is); + return 1; +} + /** * \ingroup LuaScripts * isBoolValue(const std::string& s):