local transforms = asset.require("../transforms")
local kernel = asset.require("../kernels")



local Nereid = {
  Identifier = "Nereid",
  Parent = transforms.NeptuneBarycenter.Identifier,
  Transform = {
    Translation = {
      Type = "SpiceTranslation",
      Target = "NEREID",
      Observer = "NEPTUNE BARYCENTER"
    }
  },
  Renderable = {
    Type = "RenderableGlobe",
    Radii = { 357000, 340000, 340000 },
    SegmentsPerPatch = 64,
    Layers = {}
  },
  Tag = { "moon_solarSystem", "moon_giants", "moon_neptune", "moon_major_neptune" },
  GUI = {
    Name = "Nereid",
    Path = "/Solar System/Planets/Neptune/Major Moons/Nereid"
  }
}

local NereidTrail = {
  Identifier = "NereidTrail",
  Parent = transforms.NeptuneBarycenter.Identifier,
  Renderable = {
    Type = "RenderableTrailOrbit",
    Translation = {
      Type = "SpiceTranslation",
      Target = "NEREID",
      Observer = "NEPTUNE BARYCENTER"
    },
    Color = { 0.2, 0.5, 0.75 },
    Period = 360.13,
    Resolution = 1000
  },
  Tag = { "moonTrail_solarSystem", "moonTrail_giants", "moonTrail_neptune", "moonTrail_major_neptune" },
  GUI = {
    Name = "Nereid Trail",
    Path = "/Solar System/Planets/Neptune/Major Moons/Nereid"
  }
}

local NereidLabel = {
  Identifier = "NereidLabel",
  Parent = Nereid.Identifier,
  Renderable = {
    Enabled = false,
    Type = "RenderableLabel",
    Text = "Nereid",
    FontSize = 50.0,
    Size = 7.0,
    MinMaxSize = { 1, 25 },
    OrientationOption = "Camera View Direction",
    BlendMode = "Additive",
    EnableFading = true,
    FadeUnit = "Gm",
    FadeDistances = { 1, 15.0 },
    FadeWidths = { 1, 15.0 }
  },
  Tag = { "solarsystem_labels", "moon_labels", "major_moon_labels" },
  GUI = {
    Name = "Nereid Label",
    Path = "/Solar System/Planets/Neptune/Major Moons/Nereid",
    Description = "Label for Neptune's moon Nereid"
  }
}


asset.onInitialize(function()
  openspace.spice.loadKernel(kernel.nep101xl_802)


  openspace.addSceneGraphNode(Nereid)
  openspace.addSceneGraphNode(NereidTrail)
  openspace.addSceneGraphNode(NereidLabel)
end)

asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(NereidLabel)
  openspace.removeSceneGraphNode(NereidTrail)
  openspace.removeSceneGraphNode(Nereid)


  openspace.spice.unloadKernel(kernel.nep101xl_802)
end)

asset.export(Nereid)
asset.export(NereidTrail)
asset.export(NereidLabel)



asset.meta = {
  Name = "Nereid",
  Version = "1.1",
  Description = [[Procedural Globe asset containing Neptune's moon: Nereid. A blank globe
    and SPICE trail are generated for the moon]],
  Author = "OpenSpace Team",
  URL = "http://openspaceproject.com",
  License = "MIT license"
}
