local transforms = asset.require("./transforms")
asset.require("spice/base")
asset.require("./trail")

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

local Mercury = {
  Identifier = "Mercury",
  Parent = transforms.MercuryBarycenter.Identifier,
  Transform = {
    Translation = {
      Type = "SpiceTranslation",
      Target = "MERCURY",
      Observer = "MERCURY BARYCENTER"
    },
    Rotation = {
      Type = "SpiceRotation",
      SourceFrame = "IAU_MERCURY",
      DestinationFrame = "GALACTIC"
    }
  },
  Renderable = {
    Type = "RenderableGlobe",
    Radii = 2439700,
    Frame = "IAU_MERCURY",
    Body = "MERCURY",
    CameraMinHeight = 300,
    SegmentsPerPatch = 64,
    Layers = {},
    Labels = {
      Enabled = false,
      FileName = labelsPath .. "Mercury.labels",
      AlignmentOption = "Horizontally", -- or Circularly
      FontSize = 20.0,
      Size = 10.1,
      FadeInEnabled = true,
      FadeOutEnabled = true,
      FadeDistances = { 1800000.0, 5000000.0 },
      DistanceEPS = 1500000.0,
      Color = { 1.0, 1.0, 0.0 }
    }
  },
  Tag = { "planet_solarSystem", "planet_terrestrial" },
  GUI = {
    Path = "/Solar System/Planets/Mercury"
  }
}

local MercuryLabel = {
  Identifier = "MercuryLabel",
  Parent = Mercury.Identifier,
  Renderable = {
    Enabled = false,
    Type = "RenderableLabels",
    Text = "Mercury",
    FontSize = 70.0,
    Size = 8.46,
    MinMaxSize = { 1, 100 },
    OrientationOption = "Camera View Direction",
    BlendMode = "Additive"
  },
  Tag = { "solarsystem_labels" },
  GUI = {
    Name = "Mercury Label",
    Path = "/Solar System/Planets/Mercury",
  }
}

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



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