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



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


-- local MarsRadii = { 3396190.0, 3396190.0, 3376200.0 }
local MarsRadii = { 3396190.0, 3396190.0, 3396190.0 }

local Mars = {
  Identifier = "Mars",
  Parent = transforms.MarsBarycenter.Identifier,
  Transform = {
    Translation = {
      Type = "SpiceTranslation",
      Target = "MARS",
      Observer = "MARS BARYCENTER"
    },
    Rotation = {
      Type = "SpiceRotation",
      SourceFrame = "IAU_MARS",
      DestinationFrame = "GALACTIC"
    }
  },
  Renderable = {
    Type = "RenderableGlobe",
    Radii = MarsRadii,
    SegmentsPerPatch = 90,
    Layers = {},
    Labels = {
      Enabled = false,
      FileName = labelsPath .. "mars.labels",
      AlignmentOption = "Horizontally", -- or Circularly
      FontSize = 20.0,
      Size = 8.7,
      FadeInEnabled = true,
      FadeOutEnabled = true,
      FadeDistances = { 750000.0, 2000000.0 },
      DistanceEPS = 2500000.0,
      Color = { 1.0, 1.0, 0.0 }
    }
  },
  Tag = { "planet_solarSystem", "planet_terrestrial" },
  GUI = {
    Name = "Mars",
    Path = "/Solar System/Planets/Mars",
    Description = "Main globe for Mars with labels and map layers"
  }
}

local MarsLabel = {
  Identifier = "MarsLabel",
  Parent = Mars.Identifier,
  Renderable = {
    Enabled = false,
    Type = "RenderableLabel",
    Text = "Mars",
    FontSize = 70.0,
    Size = 8.50,
    MinMaxSize = { 1, 50 },
    OrientationOption = "Camera View Direction",
    BlendMode = "Additive",
    TransformationMatrix = {
      1.0, 0.0, 0.0, -8.0E6,
      0.0, 1.0, 0.0, 0.0,
      0.0, 0.0, 1.0, 1.0E7,
      0.0, 0.0, 0.0, 1.0
    },
    EnableFading = true,
    FadeUnit = "au",
    FadeDistances = { 1.5, 40.0 },
    FadeWidths = { 1.0, 50.0 }
  },
  Tag = { "solarsystem_labels" },
  GUI = {
    Name = "Mars Label",
    Path = "/Solar System/Planets/Mars",
    Description = "Main label for Mars"
  }
}


asset.onInitialize(function()
  openspace.addSceneGraphNode(Mars)
  openspace.addSceneGraphNode(MarsLabel)
end)

asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(MarsLabel)
  openspace.removeSceneGraphNode(Mars)
end)

asset.export(Mars)
asset.export(MarsLabel)



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