mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-02 16:59:37 -05:00
8b74493d96
- Remove the asset_helper file and call the onInitialize and onDeinitialize functions directly - Small compile fix on Windows - Removes the need for the registerIdentifierWithMeta function by automatically doing that for all asset.export statements - Allow the passing of either identifiers (as before) or entire tables to the removeSceneGraphNode, removeScreenSpaceRenderable, deleteLayer, removeAction, and export methods. In that case, the Identifier key from the table is extracted and used instead
125 lines
3.4 KiB
Lua
125 lines
3.4 KiB
Lua
local transforms = asset.require("scene/solarsystem/planets/earth/transforms")
|
|
|
|
function downloadTLEFile(sceneAsset, url, name, filename)
|
|
local identifier = name
|
|
identifier = identifier:gsub(" ", "")
|
|
identifier = identifier:gsub("&", "")
|
|
identifier = identifier:gsub("-", "")
|
|
|
|
local urlSyncTable = {
|
|
Name = "Satellite TLE Data (" .. name .. ")",
|
|
Type = "UrlSynchronization",
|
|
Identifier = "satellite_tle_data_" .. identifier,
|
|
Url = url,
|
|
Override = true
|
|
}
|
|
|
|
if (filename ~= "") then
|
|
urlSyncTable.Filename = filename
|
|
end
|
|
|
|
return sceneAsset.syncedResource(urlSyncTable)
|
|
end
|
|
|
|
-- Check format of a set of 3 TLE file lines and return nonzero if there is a format error
|
|
function isValidTLEFileFormat(lineArr)
|
|
local function isEmpty(s) return s == nil or s == "" end
|
|
|
|
if isEmpty(lineArr[1]) or isEmpty(lineArr[2]) or isEmpty(lineArr[3]) then
|
|
return false
|
|
end
|
|
if string.sub(lineArr[2], 1, 2) ~= "1 " then
|
|
return false
|
|
end
|
|
if string.sub(lineArr[3], 1, 2) ~= "2 " then
|
|
return false
|
|
end
|
|
return true
|
|
end
|
|
|
|
local makeSingleLineElement = function(tle, filename)
|
|
local path = tle .. "/" .. filename
|
|
local file = io.open(path, "r")
|
|
assert(file, "File not found: " .. path)
|
|
|
|
local line = {
|
|
file:read("*l"), --title line
|
|
file:read("*l"),
|
|
file:read("*l")
|
|
}
|
|
|
|
assert(isValidTLEFileFormat(line), "TLE file syntax error on line " .. 1 .. ": " .. path)
|
|
|
|
-- Trim string
|
|
line[1] = line[1]:gsub("^%s*(.-)%s*$", "%1")
|
|
line[1] = line[1]:gsub("%s+", "_")
|
|
line[1] = line[1]:gsub("[%-()]", "")
|
|
--local title = line[1]
|
|
|
|
return line
|
|
end
|
|
|
|
function numLinesInFile(filename)
|
|
local ctr = 0
|
|
for _ in io.lines(filename) do ctr = ctr + 1 end
|
|
return ctr
|
|
end
|
|
|
|
local getPeriodFromElement = function(element)
|
|
-- Get period from correct location of the string
|
|
local per = tonumber(string.sub(element[3], 53, 63))
|
|
-- Trail for 2x a single revolution
|
|
per = 1.0 / per
|
|
|
|
return per
|
|
end
|
|
|
|
function satellites(title, file, color, group)
|
|
return {
|
|
Identifier = title,
|
|
Parent = transforms.EarthInertial.Identifier,
|
|
Renderable = {
|
|
Type = "RenderableSatellites",
|
|
Path = file,
|
|
SegmentQuality = 3,
|
|
Color = color,
|
|
Fade = 1.5,
|
|
RenderBinMode = "PostDeferredTransparent",
|
|
StartRenderIdx = group.StartRenderIdx,
|
|
RenderSize = group.RenderSize
|
|
},
|
|
Tag = { "earth_satellites" },
|
|
GUI = {
|
|
Name = group.Title,
|
|
Path = "/Solar System/Planets/Earth/Satellites",
|
|
Description = group.Description
|
|
}
|
|
}
|
|
end
|
|
|
|
local registerSatelliteGroupObjects = function(containingAsset, group, tleFolder, shouldAddDuplicates)
|
|
local filename = group.Url:match("([^/]+)$")
|
|
local filenameSansExt = filename:gsub(filename:match("(%.%w+)$"), "")
|
|
|
|
local path = tleFolder .. "/" .. filename
|
|
|
|
local SatelliteBatch = satellites(filenameSansExt, path, group.TrailColor, group)
|
|
|
|
containingAsset.onInitialize(function()
|
|
openspace.addSceneGraphNode(SatelliteBatch)
|
|
end)
|
|
|
|
containingAsset.onDeinitialize(function()
|
|
openspace.removeSceneGraphNode(SatelliteBatch)
|
|
end)
|
|
|
|
containingAsset.export(SatelliteBatch)
|
|
end
|
|
|
|
asset.export("downloadTLEFile", downloadTLEFile)
|
|
asset.export("isValidTLEFileFormat", isValidTLEFileFormat)
|
|
asset.export("numLinesInFile", numLinesInFile)
|
|
asset.export("makeSingleLineElement", makeSingleLineElement)
|
|
asset.export("getPeriodFromElement", getPeriodFromElement)
|
|
asset.export("registerSatelliteGroupObjects", registerSatelliteGroupObjects)
|