local transforms = asset.require("scene/solarsystem/planets/earth/transforms")
local sunAsset = asset.require("scene/solarsystem/sun/sun")
local earthAsset = asset.require("../earth")
asset.require("spice/base")

local labelsPath = asset.syncedResource({
  Name = "Moon Labels",
  Type = "HttpSynchronization",
  Identifier = "moon_labels",
  Version = 1
})

local Moon = {
  Identifier = "Moon",
  Parent = transforms.EarthBarycenter.Identifier,
  Transform = {
    Translation = {
      Type = "SpiceTranslation",
      Target = "MOON",
      Observer = "EARTH BARYCENTER"
    },
    Rotation = {
      Type = "SpiceRotation",
      SourceFrame = "IAU_MOON",
      DestinationFrame = "GALACTIC"
    }
  },
  Renderable = {
    Type = "RenderableGlobe",
    Radii = 1738140,
    SegmentsPerPatch = 64,
    Layers = {},
    ShadowGroup = {
      Sources = {
        { Name = sunAsset.Sun.Identifier, Radius = 696.3E6 },
      },
      Casters = {
        { Name = earthAsset.Earth.Identifier, Radius = 6.371E6 },
      }
    },        
    Labels = {
      Enabled = false,
      FileName = labelsPath .. "moon.labels",
      AlignmentOption = "Horizontally", -- or Circularly
      FontSize = 20.0,
      Size = 7.6,
      FadeInEnabled = true,
      FadeOutEnabled = true,
      FadeDistances = { 100000.0, 500000.0 },
      DistanceEPS = 1350000.0,
      Color = { 1.0, 1.0, 0.0 }
    }
  },
  GUI = {
    Path = "/Solar System/Planets/Earth/Moon"
  }
}

asset.onInitialize(function()
  openspace.addSceneGraphNode(Moon)
end)
  
asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(Moon)
end)
  
asset.export(Moon)



asset.meta = {
  Name = "Moon",
  Version = "1.1",
  Description = "Moon globe with labels",
  Author = "OpenSpace Team",
  URL = "http://openspaceproject.com",
  License = "MIT license"
}
