csv bookmark files

This commit is contained in:
Micah
2020-01-26 09:13:48 -05:00
parent f481ff78b3
commit ad29ea53f5
4 changed files with 116 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
local assetHelper = asset.require("util/asset_helper")
local bookmarkHelper = asset.require("util/generate_bookmarks")
local nodes = bookmarkHelper.getBookmarks("Local Bookmarks",'${ASSETS}/customization/localbookmarks.csv')
assetHelper.registerSceneGraphNodesAndExport(asset, nodes);

View File

@@ -0,0 +1,2 @@
Group (optional),Name (required),Globe (optional),Lat (required if globe),Lon (required if globe),Altitude (optional if globe),x (required if not globe),y (required if not globe),z (required if not globe),Scale (optional),LineWidth (optional)
Local Bookmarks,Murrow,Earth,40.619,-73.959,,,,,,
1 Group (optional) Name (required) Globe (optional) Lat (required if globe) Lon (required if globe) Altitude (optional if globe) x (required if not globe) y (required if not globe) z (required if not globe) Scale (optional) LineWidth (optional)
2 Local Bookmarks Murrow Earth 40.619 -73.959

View File

@@ -0,0 +1,80 @@
local assetHelper = asset.require('util/asset_helper')
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, linewitdh = line:match(matchstring)
scale = (scale == '' and 75000 or scale)
linewitdh = (linewitdh == '' and 2.0 or tonumber(linewitdh))
group = (group == "" and globe or group)
local parent = (globe == "" and 'Root' or globe)
local sgn = {
Identifier = guiPath .. "-" .. name,
Parent = parent,
Transform = {
Translation = {
},
Scale = {
Type = "StaticScale",
Scale = tonumber(scale);
}
},
Renderable = {
Type = "RenderableSphericalGrid",
Enabled = false,
GridColor = { 0.3, 0.84, 1.0, 0.3},
LineWidth = linewitdh,
GridMatrix = { -0.05487554, 0.4941095, -0.8676661 , 0.0,
-0.9938214 , -0.1109906, -0.0003515167, 0.0,
-0.09647644, 0.8622859, 0.4971472 , 0.0,
0.0 , 0.0 , 0.0 , 1.0 }
},
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}
}
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
end
end
return genBookmarks
end
asset.export("getBookmarks", getBookmarks)

View File

@@ -0,0 +1,27 @@
local assetHelper = asset.require("util/asset_helper")
local bookmarkHelper = asset.require("util/generate_bookmarks")
local dataProvider = "https://pastebin.com/raw/k17aC8VW" -- "http://data.openspaceproject.com/bookmarks.csv"
local bookmarksCSV = asset.syncedResource({
Identifier = "openspace_bookmarks",
Name = "OpenSpace Bookmarks",
Type = "UrlSynchronization",
UseHash = false,
Override = true,
Url = dataProvider
})
asset.onInitialize(function ()
local nodes = bookmarkHelper.getBookmarks("OpenSpace Bookmarks", bookmarksCSV .. '/k17aC8VW')
for i, n in ipairs(nodes) do
openspace.addSceneGraphNode(n);
end
end)
asset.onDeinitialize(function ()
local nodes = bookmarkHelper.addBookmarks("OpenSpace Bookmarks", bookmarksCSV .. '/k17aC8VW')
for i, n in ipairs(nodes) do
openspace.removeSceneGraphNode(n);
end
end)