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



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

local Charon = {
  Identifier = "Charon",
  Parent = transforms.PlutoBarycenter.Identifier,
  Transform = {
    Translation = {
      Type = "SpiceTranslation",
      Target = "CHARON",
      Observer = "PLUTO BARYCENTER"
    },
    Rotation = {
      Type = "SpiceRotation",
      SourceFrame = "IAU_CHARON",
      DestinationFrame = "GALACTIC"
    }
  },
  Renderable = {
    Type = "RenderableGlobe",
    Radii = { 6.035E5, 6.035E5, 6.035E5 },
    SegmentsPerPatch = 64,
    Layers = {},
    Labels = {
      Enabled = false,
      FileName = labelsPath .. "charon.labels",
      AlignmentOption = "Horizontally", -- or Circularly
      FontSize = 20.0,
      Size = 9.0,
      FadeInEnabled = true,
      FadeOutEnabled = true,
      Distances = { 800000.0, 2000000.0 },
      DistanceEPS = 250000.0,
      Color = { 1.0, 1.0, 0.0 }
    }
  },
  Tag = { "planet_solarSystem", "planet_terrestrial" },
  GUI = {
    Path = "/Solar System/Dwarf Planets/Pluto/Charon"
  }
}

local CharonLabel = {
  Identifier = "CharonLabel",
  Parent = Charon.Identifier,
  Renderable = {
    Enabled = false,
    Type = "RenderableLabel",
    Text = "Charon",
    FontSize = 70.0,
    Size = 6.0,
    MinMaxSize = { 1, 25 },
    OrientationOption = "Camera View Direction",
    BlendMode = "Normal",
    EnableFading = true,
    FadeUnit = "Mm",
    FadeDistances = { 250.0, 500.0 },
    FadeWidths = { 150.0, 250.0 }
  },
  Tag = { "solarsystem_labels", "moon_labels", "major_moon_labels" },
  GUI = {
    Name = "Charon Label",
    Path = "/Solar System/Dwarf Planets/Pluto/Charon",
    Description = "Label for Pluto's moon Charon"
  }
}


asset.onInitialize(function()
  openspace.addSceneGraphNode(Charon)
  openspace.addSceneGraphNode(CharonLabel)
end)

asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(CharonLabel)
  openspace.removeSceneGraphNode(Charon)
end)

asset.export(Charon)
asset.export(CharonLabel)



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