debris_shared and satellite_shared

This commit is contained in:
Elon
2019-04-17 14:23:23 -06:00
committed by ElonOlsson
parent 2895df2144
commit 23832046d6
9 changed files with 257 additions and 26 deletions
@@ -1,5 +1,5 @@
local assetHelper = asset.require('util/asset_helper')
local shared = asset.require('../satellites_shared')
local shared = asset.require('../debris_shared')
local group = {
Title = "Breeze-M Breakup",
@@ -1,5 +1,5 @@
local assetHelper = asset.require('util/asset_helper')
local shared = asset.require('../satellites_shared')
local shared = asset.require('../debris_shared')
local group = {
Title = "Fengyun Debris",
@@ -1,5 +1,5 @@
local assetHelper = asset.require('util/asset_helper')
local shared = asset.require('../satellites_shared')
local shared = asset.require('../debris_shared')
local group = {
Title = "Iridium 33 Debris",
@@ -1,5 +1,5 @@
local assetHelper = asset.require('util/asset_helper')
local shared = asset.require('../satellites_shared')
local shared = asset.require('../debris_shared')
local group = {
Title = "Kosmos 2251 Debris",
@@ -0,0 +1,90 @@
local transforms = asset.require('scene/solarsystem/planets/earth/transforms')
local assetHelper = asset.require('util/asset_helper')
local satImageFolder = asset.syncedResource({
Name = "Satellite Image Files",
Type = "HttpSynchronization",
Identifier = "tle_satellites_images",
Version = 1
})
function downloadTLEFile(sceneAsset, url, name)
local identifier = name
identifier = identifier:gsub(" ", "")
identifier = identifier:gsub("&", "")
identifier = identifier:gsub("-", "")
return sceneAsset.syncedResource({
Name = "Satellite TLE Data (" .. name .. ")",
Type = "UrlSynchronization",
Identifier = "satellite_tle_data_" .. identifier,
Url = url
})
end
local addSatelliteGroupObjects = function(group, tleFolder, shouldAddDuplicates)
local filename = group.Url:match("([^/]+)$")
local filenameSansExt = filename:gsub(filename:match("(%.%w+)$"), "")
local path = tleFolder .. "/" .. filename
function numLinesInFile(filename)
local ctr = 0
for _ in io.lines(filename) do ctr = ctr + 1 end
return ctr
end
-- Check format of a set of 3 TLE file lines and return nonzero if there is a format error
function isValidTLEFileFormat(lineArr)
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
function debris(title, file)
return {
Identifier = title,
Parent = transforms.EarthInertial.Identifier,
Renderable = {
Type = "RenderableSatellites",
Path = file,
-- The initialization with "-" is just a placeholder.
-- (needed to be initialized)
Segments = 160,
EccentricityColumn = "-",
SemiMajorAxisColumn = "-",
SemiMajorAxisUnit = 1,
InclinationColumn = "-",
AscendingNodeColumn = "-",
ArgumentOfPeriapsisColumn = "-",
MeanAnomalyAtEpochColumn = "-",
EpochColumn = "-",
},
GUI = {
Path = "/Solar System/Planets/Earth/Satellites"
}
}
end
local Debris = debris(filenameSansExt, path)
assetHelper.registerSceneGraphNodesAndExport(asset, { Debris })
-- asset.export("satImageFolder", satImageFolder)
end
asset.export("downloadTLEFile", downloadTLEFile)
asset.export("addSatelliteGroupObjects", addSatelliteGroupObjects)
@@ -1,5 +1,4 @@
asset.request('./debris/debris_asat')
--asset.request('./debris/debris_breezem')
--asset.request('./debris/debris_fengyun')
--asset.request('./debris/debris_iridium33')
--asset.request('./debris/debris_kosmos2251')
asset.request('./debris/debris_breezem')
asset.request('./debris/debris_fengyun')
asset.request('./debris/debris_iridium33')
asset.request('./debris/debris_kosmos2251')
@@ -1,5 +1,4 @@
local transforms = asset.require('scene/solarsystem/planets/earth/transforms')
local assetHelper = asset.require('util/asset_helper')
local satImageFolder = asset.syncedResource({
Name = "Satellite Image Files",
@@ -22,11 +21,6 @@ function downloadTLEFile(sceneAsset, url, name)
end
local addSatelliteGroupObjects = function(group, tleFolder, shouldAddDuplicates)
local filename = group.Url:match("([^/]+)$")
local filenameSansExt = filename:gsub(filename:match("(%.%w+)$"), "")
local path = tleFolder .. "/" .. filename
function numLinesInFile(filename)
local ctr = 0
for _ in io.lines(filename) do ctr = ctr + 1 end
@@ -49,6 +43,7 @@ local addSatelliteGroupObjects = function(group, tleFolder, shouldAddDuplicates)
return true
end
<<<<<<< HEAD
function debris(title, file, color)
return {
Identifier = title,
@@ -71,21 +66,132 @@ local addSatelliteGroupObjects = function(group, tleFolder, shouldAddDuplicates)
Color = color
},
=======
function getSat(title, file, lineNum, textureFile, group)
return {
Identifier = title,
Parent = transforms.EarthInertial.Identifier,
Renderable = {
Type = "RenderablePlaneImageLocal",
Enabled = false,
Size = 3e4,
Origin = "Center",
Body = "TLE",
Billboard = true,
Texture = textureFile
},
Transform = {
Translation = {
Type = "TLETranslation",
Body = title,
Observer = transforms.EarthInertial.Identifier,
File = file,
LineNumber = lineNum
},
Scale = {
Type = "StaticScale",
Scale = 1
}
},
Tag = { "earth_satellite_" .. group, "earth_satellite_" .. group .. "_marker" },
>>>>>>> debris_shared and satellite_shared
GUI = {
Path = "/Solar System/Planets/Earth/Satellites"
}
}
}
end
<<<<<<< HEAD
local Debris = debris(filenameSansExt, path, group.TrailColor)
assetHelper.registerSceneGraphNodesAndExport(asset, { Debris })
=======
function getSatTrail(title, file, lineNum, per, color, group)
return {
Identifier = title .. "_trail",
Parent = transforms.EarthInertial.Identifier,
Renderable = {
Type = "RenderableTrailOrbit",
Translation = {
Type = "TLETranslation",
Body = title,
Observer = transforms.EarthInertial.Identifier,
File = file,
LineNumber = lineNum
},
Color = color,
Period = per,
Resolution = 160
},
Tag = { "earth_satellite_" .. group, "earth_satellite_" .. group .. "_trail"},
GUI = {
Path = "/Solar System/Planets/Earth/Satellites"
}
}
end
>>>>>>> debris_shared and satellite_shared
-- asset.export("satImageFolder", satImageFolder)
local filename = group.Url:match("([^/]+)$")
local filenameSansExt = filename:gsub(filename:match("(%.%w+)$"), "")
local path = tleFolder .. "/" .. filename
local texture = satImageFolder .. "/" .. "satB.png"
local file = io.open(path, "r")
assert(file, "File not found: " .. path)
local obj = {}
--now loop through the tle file and get each set of 3 lines
for n = 1, numLinesInFile(path), 3 do
local line = {
file:read('*l'), --title line
file:read('*l'),
file:read('*l')
}
assert(isValidTLEFileFormat(line), "TLE file syntax error on line " .. n .. ": " .. 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]
-- Get period from correct location of the string
local per = tonumber(string.sub(line[3], 53, 63))
-- Trail for 2x a single revolution
per = 1.0 / per * 2.0
local satName = filenameSansExt .. "_" .. title
local shouldAddNotes = true
if openspace.hasSceneGraphNode(satName) then
if shouldAddDuplicates then
local originalSatName = satName
local i = 1
while openspace.hasSceneGraphNode(satName) do
satName = originalSatName .. "_" .. tostring(i)
i = i + 1
end
else
shouldAddNotes = false
end
end
if shouldAddNotes then
-- Register satellite object and trail
local sat_var = getSat(satName, path, n, texture, group.Title)
openspace.addSceneGraphNode(sat_var)
table.insert(obj, sat_var.Identifier)
local satTrail_var = getSatTrail(satName, path, n, per, group.TrailColor, group.Title)
openspace.addSceneGraphNode(satTrail_var)
table.insert(obj, satTrail_var.Identifier)
end
end
return obj
end
asset.export("satImageFolder", satImageFolder)
asset.export("downloadTLEFile", downloadTLEFile)
asset.export("addSatelliteGroupObjects", addSatelliteGroupObjects)
asset.export("addSatelliteGroupObjects", addSatelliteGroupObjects)
+2 -2
View File
@@ -16,8 +16,8 @@ asset.require('util/webgui')
--asset.request('customization/globebrowsing')
-- asset.request('scene/solarsystem/planets/earth/satellites/satellites_all')
asset.request('scene/solarsystem/planets/earth/satellites/satellites_debris')
asset.request('scene/solarsystem/planets/earth/satellites/satellites_all')
-- asset.request('scene/solarsystem/planets/earth/satellites/satellites_debris')
-- Keybindings that are specific for this scene
local Keybindings = {