local mercuryTransforms = asset.require("scene/solarsystem/planets/mercury/transforms")

local localFolder = asset.syncedResource({
  Name = "Mercury Magnetosphere",
  Type = "HttpSynchronization",
  Identifier = "mercury_magnetosphere",
  Version = 3
})


local MercuryRadius = 2439700

local Magnetosphere = {
  Name = "Mercury Magnetosphere",
  Identifier = "MercuryMagnetosphere",
  Parent = mercuryTransforms.MercuryBarycenter.Identifier,
  Transform = {
    Translation = {
      Type = "SpiceTranslation",
      Target = "MERCURY",
      Observer = "MERCURY BARYCENTER"
    },
    Rotation = {
      Type = "SpiceRotation",
      SourceFrame = "MERCURYSE",
      DestinationFrame = "GALACTIC"
    },
    Scale = {
      Type = "StaticScale",
      Scale = MercuryRadius
    }
  },
  Renderable = {
    Type = "RenderableTimeVaryingVolume",
    SourceDirectory = localFolder,
    TransferFunction = localFolder .. "transferfunction.txt",
    Variable = "rho",
    StepSize = 0.003,
    Dimensions = { 64, 64, 64 },
    GridType = "Cartesian",
    SecondsBefore = 24 * 60 * 60 * 365 * 100,
    SecondsAfter = 24 * 60 * 60 * 365 * 100,
    Enabled = false
  },
  GUI = {
    Name = "Mercury Magnetosphere",
    Path = "/Solar System/Missions/Messenger"
  }
}


asset.onInitialize(function()
  openspace.spice.loadKernel(localFolder .. "openspace_mercury.ti")

  openspace.addSceneGraphNode(Magnetosphere)
end)

asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(Magnetosphere)

  openspace.spice.unloadKernel(localFolder .. "openspace_mercury.ti")
end)

asset.export(Magnetosphere)
