local transforms = asset.require("./transforms")
local sunTransforms = asset.require("scene/solarsystem/sun/transforms")



local textures = asset.syncedResource({
  Name = "Charon Textures",
  Type = "HttpSynchronization",
  Identifier = "charon_textures",
  Version = 3
})


local CharonRadius = 603500

local CharonProjection = {
  Identifier = "CharonProjection",
  Parent = transforms.PlutoBarycenterAccurate.Identifier,
  Transform = {
    Translation = {
      Type = "SpiceTranslation",
      Target = "CHARON",
      Observer = "PLUTO BARYCENTER"
    },
    Rotation = {
      Type = "SpiceRotation",
      SourceFrame = "IAU_CHARON",
      DestinationFrame = "GALACTIC"
    }
  },
  Renderable = {
    Type = "RenderablePlanetProjection",
    Radius = CharonRadius,
    Segments = 350,
    ColorTexturePaths = {
      textures .. "NH_Charon_mosaic.png",
      textures .. "NH_Charon_mosaic_8192.png"
    },
    HeightTexturePaths = {
      textures .. "NH_Charon_DTM.png",
      textures .. "NH_Charon_DTM_8192.png"
    },
    MeridianShift = true,
    Projection = {
      Observer = "NEW HORIZONS",
      Target = "CHARON",
      Aberration = "NONE",
      AspectRatio = 2,
      Instrument = {
        Name = "NH_LORRI",
        Method = "ELLIPSOID",
        Aberration = "NONE",
        Fovy = 0.2907,
        Aspect = 1,
        Near = 0.2,
        Far = 10000
      },
      PotentialTargets = {
        "PLUTO",
        "CHARON"
      }
    }
  },
  GUI = {
    Path = "/Solar System/Dwarf Planets/Pluto",
    Name = "Charon Projection"
  }
}

local CharonText = {
  Identifier = "CharonText",
  Parent = CharonProjection.Identifier,
  Transform = {
    Translation = {
      Type = "StaticTranslation",
      Position = { 0, -1000000.0, 0 }
    }
  },
  Renderable = {
    Type = "RenderablePlaneImageLocal",
    Size = 19952623.15,
    Origin = "Center",
    Billboard = true,
    Texture = textures .. "Charon-Text.png",
    BlendMode = "Additive"
  },
  GUI = {
    Name = "Charon Text",
    Path = "/Solar System/Dwarf Planets/Pluto"
  }
}

local CharonShadow = {
  Identifier = "CharonShadow",
  Parent = CharonProjection.Identifier,
  Renderable = {
    Type = "RenderableShadowCylinder",
    Opacity = 0.25,
    TerminatorType = "PENUMBRAL",
    LightSource = "SUN",
    Observer = "NEW HORIZONS",
    Body = "CHARON",
    BodyFrame = "IAU_CHARON",
    Aberration = "NONE"
  },
  GUI = {
    Name = "Charon Shadow",
    Path = "/Solar System/Dwarf Planets/Pluto"
  }
}


asset.onInitialize(function()
  openspace.addSceneGraphNode(CharonProjection)
  openspace.addSceneGraphNode(CharonText)
  openspace.addSceneGraphNode(CharonShadow)
end)

asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(CharonShadow)
  openspace.removeSceneGraphNode(CharonText)
  openspace.removeSceneGraphNode(CharonProjection)
end)

asset.export(CharonProjection)
asset.export(CharonText)
asset.export(CharonShadow)
