diff --git a/data/assets/global/localbookmarks.asset b/data/assets/global/localbookmarks.asset index 9f5b6b6433..c37774d2c2 100644 --- a/data/assets/global/localbookmarks.asset +++ b/data/assets/global/localbookmarks.asset @@ -1,5 +1,9 @@ local bookmarkHelper = asset.require("util/generate_bookmarks") +-- Most of the local bookmarks we are loading are relative to the Earth so we should +-- ensure that it is loaded first +asset.require("scene/solarsystem/planets/earth/earth") + local nodes = bookmarkHelper.getBookmarks("Local Bookmarks", "${ASSETS}/customization/localbookmarks.csv") diff --git a/data/assets/util/generate_bookmarks.asset b/data/assets/util/generate_bookmarks.asset index 587059c6af..13910fa592 100644 --- a/data/assets/util/generate_bookmarks.asset +++ b/data/assets/util/generate_bookmarks.asset @@ -1,82 +1,90 @@ local getBookmarks = function (guiPath, bookmarkfile) local genBookmarks = {}; - local notFirstLine = false; local PARSEC_CONSTANT = 3.0856776E16; - for line in io.lines(openspace.absPath(bookmarkfile)) do - if (notFirstLine) then - local matchstring = "(.-),(.-),(.-),(.-),(.-),(.-),(.-),(.-),(.-),(.-),(.-)$" - local group, name, globe, lat, lon, altitude, x, y, z, scale, linewidth = line:match(matchstring) - local identifier = string.gsub(guiPath .. "-" .. name, " ", "_") + local extract_first_line = false + local contents = openspace.readCSVFile(openspace.absPath(bookmarkfile), extract_first_line); + openspace.printWarning(contents) - scale = (scale == "" and 75000 or scale) - linewidth = (linewidth == "" and 2.0 or tonumber(linewidth)) - group = (group == "" and globe or group) + for _,v in ipairs(contents) do + local group = v[1] + local name = v[2] + local globe = v[3] + local lat = v[4] + local lon = v[5] + local altitude = v[6] + local x = v[7] + local y = v[8] + local z = v[9] + local scale = v[10] + local linewidth = v[11] - local parent = (globe == "" and "Root" or globe) + local identifier = string.gsub(guiPath .. "-" .. name, " ", "_") - local sgn = { - Identifier = identifier, - Parent = parent, - Transform = { - Scale = { - Type = "StaticScale", - Scale = tonumber(scale); - }, + scale = (scale == "" and 75000 or scale) + linewidth = (linewidth == "" and 2.0 or tonumber(linewidth)) + + local parent = (globe == "" and "Root" or globe) + + local sgn = { + Identifier = identifier, + Parent = parent, + Transform = { + Scale = { + Type = "StaticScale", + Scale = tonumber(scale); + }, + Rotation = { + Type = "StaticRotation", Rotation = { - Type = "StaticRotation", - Rotation = { - -0.05487554, 0.4941095, -0.8676661, - -0.9938214 , -0.1109906, -0.0003515167, - -0.09647644, 0.8622859, 0.4971472 - } + -0.05487554, 0.4941095, -0.8676661, + -0.9938214 , -0.1109906, -0.0003515167, + -0.09647644, 0.8622859, 0.4971472 } - }, - Renderable = { - Type = "RenderableSphericalGrid", - Enabled = false, - Opacity = 0.3, - Color = { 0.3, 0.84, 1.0}, - LineWidth = linewidth - }, - GUI = { - Name = name, - Path = "/" .. guiPath + } + }, + Renderable = { + Type = "RenderableSphericalGrid", + Enabled = false, + Opacity = 0.3, + Color = { 0.3, 0.84, 1.0}, + LineWidth = linewidth + }, + GUI = { + Name = name, + Path = "/" .. guiPath + } + } + + if (group ~= "") then + sgn.GUI.Path = sgn.GUI.Path .. "/" .. group + end + + if (globe == "") then + sgn.Transform.Translation = { + Type = "StaticTranslation", + Position = { + tonumber(x) * PARSEC_CONSTANT, + tonumber(y) * PARSEC_CONSTANT, + tonumber(z) * PARSEC_CONSTANT } } - - if (group ~= "") then - sgn.GUI.Path = sgn.GUI.Path .. "/" .. group - end - - if (globe == "") then - sgn.Transform.Translation = { - Type = "StaticTranslation", - Position = { - tonumber(x) * PARSEC_CONSTANT, - tonumber(y) * PARSEC_CONSTANT, - tonumber(z) * PARSEC_CONSTANT - } - } - else - sgn.Transform.Translation = { - Type = "GlobeTranslation", - Globe = globe, - Latitude = tonumber(lat), - Longitude = tonumber(lon) - } - if (altitude == nil) then - sgn.Transform.Translation.UseHeightMap = true; - else - sgn.Transform.Translation.UseHeightMap = false; - sgn.Transform.Translation.Altitude = tonumber(altitude); - end - end - - table.insert(genBookmarks, sgn); else - notFirstLine = true + sgn.Transform.Translation = { + Type = "GlobeTranslation", + Globe = globe, + Latitude = tonumber(lat), + Longitude = tonumber(lon) + } + if (altitude == nil) then + sgn.Transform.Translation.UseHeightMap = true; + else + sgn.Transform.Translation.UseHeightMap = false; + sgn.Transform.Translation.Altitude = tonumber(altitude); + end end + + table.insert(genBookmarks, sgn); end return genBookmarks end diff --git a/ext/ghoul b/ext/ghoul index dc16fc5267..81a4ac0d8a 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit dc16fc5267e11f8c5f00a7c6f0e8114e41efcbc7 +Subproject commit 81a4ac0d8a0e5fad4a46854aa698e8d0b6335936 diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index c83585f4c5..5fec1e031b 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1689,7 +1689,8 @@ scripting::LuaLibrary OpenSpaceEngine::luaLibrary() { codegen::lua::DownloadFile, codegen::lua::CreateSingleColorImage, codegen::lua::IsMaster, - codegen::lua::Version + codegen::lua::Version, + codegen::lua::ReadCSVFile }, { absPath("${SCRIPTS}/core_scripts.lua") diff --git a/src/engine/openspaceengine_lua.inl b/src/engine/openspaceengine_lua.inl index 738cb4c3da..e6c4921516 100644 --- a/src/engine/openspaceengine_lua.inl +++ b/src/engine/openspaceengine_lua.inl @@ -23,6 +23,7 @@ ****************************************************************************************/ #include +#include namespace { @@ -206,4 +207,23 @@ namespace { return res; } +/** + * Loads the CSV file provided as a parameter and returns it as a vector containing the + * values of the each row. The inner vector has the same number of values as the CSV has + * columns. The second parameter controls whether the first entry in the returned outer + * vector is containing the names of the columns + */ +[[codegen::luawrap]] std::vector> readCSVFile( + std::filesystem::path file, + bool includeFirstLine = false) +{ + if (!std::filesystem::exists(file) || !std::filesystem::is_regular_file(file)) { + throw ghoul::lua::LuaError(fmt::format("Could not find file {}", file)); + } + + std::vector> res = + ghoul::loadCSVFile(file.string(), includeFirstLine); + return res; +} + #include "openspaceengine_lua_codegen.cpp"