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



local kernels = asset.syncedResource({
  Name = "Mars Spice Kernels",
  Type = "HttpSynchronization",
  Identifier = "mars_kernels",
  Version = 1
})


local DeimosGlobe = {
  Identifier = "Deimos_Globe",
  Parent = transforms.MarsBarycenter.Identifier,
  Transform = {
    Rotation = {
      Type = "SpiceRotation",
      SourceFrame = "IAU_DEIMOS",
      DestinationFrame = "GALACTIC"
    },
    Translation = {
      Type = "SpiceTranslation",
      Target = "DEIMOS",
      Observer = "MARS BARYCENTER"
    }
  },
  Renderable = {
    Type = "RenderableGlobe",
    Radii = { 7500, 6100, 5200 },
--Radius source
--https://sci.esa.int/documents/35171/36506/1567259108230-5-ESLAB46-Day2-Rosenblatt.pdf
    SegmentsPerPatch = 90,
    Layers = {}
  },
  Tag = { "moon_solarSystem", "moon_terrestrial", "moon_mars" },
  GUI = {
    Name = "Deimos_Globe",
    Path = "/Solar System/Planets/Mars/Moons/Deimos",
    Description = "One of two moons of Mars"
  }
}


asset.onInitialize(function()
  openspace.spice.loadKernel(kernels .. "mar097.bsp")

  openspace.addSceneGraphNode(DeimosGlobe)
end)

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

  openspace.spice.unloadKernel(kernels .. "mar097.bsp")
end)

asset.export(DeimosGlobe)



asset.meta = {
  Name = "Deimos Globe",
  Version = "1.0",
  Description = "RenderableGlobe for Deimos",
  Author = "OpenSpace Team",
  URL = "http://openspaceproject.com",
  License = "MIT license"
}
