From 3566296f202bb2e4d3fc86a0487203549c1d9526 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 18 Jul 2024 14:35:42 +0200 Subject: [PATCH] Only provide a single Lua function for creating debug axes --- modules/debugging/debuggingmodule.cpp | 3 +- modules/debugging/debuggingmodule_lua.inl | 55 ----------------------- modules/debugging/scripts/axes.lua | 36 ++++++++++----- 3 files changed, 25 insertions(+), 69 deletions(-) diff --git a/modules/debugging/debuggingmodule.cpp b/modules/debugging/debuggingmodule.cpp index 5781dc60f2..1a38bf8cb0 100644 --- a/modules/debugging/debuggingmodule.cpp +++ b/modules/debugging/debuggingmodule.cpp @@ -161,8 +161,7 @@ scripting::LuaLibrary DebuggingModule::luaLibrary() const { codegen::lua::RenderCameraPath, codegen::lua::RemoveRenderedCameraPath, codegen::lua::RenderPathControlPoints, - codegen::lua::RemovePathControlPoints, - codegen::lua::AddCartesianAxes + codegen::lua::RemovePathControlPoints }, .scripts = { absPath("${MODULE_DEBUGGING}/scripts/axes.lua") diff --git a/modules/debugging/debuggingmodule_lua.inl b/modules/debugging/debuggingmodule_lua.inl index 06d543cc1e..63c5b9c106 100644 --- a/modules/debugging/debuggingmodule_lua.inl +++ b/modules/debugging/debuggingmodule_lua.inl @@ -247,61 +247,6 @@ constexpr glm::vec3 OrientationLineColor = glm::vec3(0.0, 1.0, 1.0); ); } -/** - * Adds a set of Cartesian axes to the scene graph node identified by the first string, to - * illustrate its local coordinate system. The second (optional) argument is a scale - * value, in meters. - */ -[[codegen::luawrap]] void addCartesianAxes(std::string nodeIdentifier, - std::optional scale) -{ - using namespace openspace; - SceneGraphNode* n = global::renderEngine->scene()->sceneGraphNode(nodeIdentifier); - if (!n) { - throw ghoul::lua::LuaError("Unknown scene graph node: " + nodeIdentifier); - } - - if (!scale.has_value()) { - scale = 2.0 * n->boundingSphere(); - if (n->boundingSphere() <= 0.0) { - LWARNINGC( - "Debugging: Cartesian Axes", - "Using zero bounding sphere for scale of created axes. You need to set " - "the scale manually for them to be visible" - ); - scale = 1.0; - } - } - - const std::string identifier = makeIdentifier(nodeIdentifier + "_AxesXYZ"); - const std::string& axes = "{" - "Identifier = '" + identifier + "'," - "Parent = '" + nodeIdentifier + "'," - "Transform = { " - "Scale = {" - "Type = 'StaticScale'," - "Scale = " + std::to_string(*scale) + "" - "}" - "}," - "Renderable = {" - "Type = 'RenderableCartesianAxes'," - "Enabled = true," - "XColor = { 1.0, 0.0, 0.0 }," - "YColor = { 0.0, 1.0, 0.0 }," - "ZColor = { 0.0, 0.0, 1.0 }" - "}," - "GUI = {" - "Name = '" + identifier + "'," - "Path = '" + DebuggingGuiPath + "/Coordiante Systems'" - "}" - "}"; - - global::scriptEngine->queueScript( - std::format("openspace.addSceneGraphNode({});", axes), - scripting::ScriptEngine::ShouldBeSynchronized::Yes, - scripting::ScriptEngine::ShouldSendToRemote::Yes - ); -} #include "debuggingmodule_lua_codegen.cpp" diff --git a/modules/debugging/scripts/axes.lua b/modules/debugging/scripts/axes.lua index 4fa5dac1f1..d6fbda714d 100644 --- a/modules/debugging/scripts/axes.lua +++ b/modules/debugging/scripts/axes.lua @@ -1,35 +1,47 @@ openspace.debugging.documentation = { { Name = "createCoordinateAxes", - Arguments = {}, + Arguments = { + { "nodeIdentifier", "String?" }, + { "scale", "Number?" } + }, Documentation = [[ Creates a new scene graph node that show the coordinate system used for the - currently selected focus node. + currently selected focus node. The first argument specifies the name of the + scene graph node for which the axes should be added. If this parameter is + not specified, the current focus node is used instead. The second argument + provides the length of the coordinate axis in meters. If this value is not + specified 2.5 times the interaction sphere of the selected node is used + instead. ]] } } -openspace.debugging.createCoordinateAxes = function () - local anchor = openspace.navigation.getNavigationState().Anchor - local radius = openspace.propertyValue("Scene." .. anchor .. ".EvaluatedInteractionSphere") +openspace.debugging.createCoordinateAxes = function (nodeIdentifier, scale) + local node = nodeIdentifier or openspace.navigation.getNavigationState().Anchor + local sphere = openspace.propertyValue("Scene." .. node .. ".EvaluatedInteractionSphere") + if sphere == -1 then + sphere = 1 + end + local size = scale or sphere * 2.5 - local node = { - Identifier = anchor .. "_DebugAxes", - Parent = anchor, + local nodespec = { + Identifier = node .. "_DebugAxes", + Parent = node, Transform = { Scale = { Type = "StaticScale", - Scale = radius * 2.5 + Scale = size } }, Renderable = { Type = "RenderableCartesianAxes" }, GUI = { - Name = anchor .. " (Debug Axes)", - Path = openspace.propertyValue("Scene." .. anchor .. ".GuiPath") + Name = node .. " (Debug Axes)", + Path = openspace.propertyValue("Scene." .. node .. ".GuiPath") } } - openspace.addSceneGraphNode(node) + openspace.addSceneGraphNode(nodespec) end