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


local model = asset.syncedResource({
  Name = "Juno Model",
  Type = "HttpSynchronization",
  Identifier = "juno_model",
  Version = 2
})


local kernels = asset.syncedResource({
  Name = "Juno Kernels",
  Type = "HttpSynchronization",
  Identifier = "juno_kernels",
  Version = 2
})

local JunoKernels = {
  kernels .. "juno_v12.tf",
  kernels .. "JNO_SCLKSCET.00039.tsc",
  kernels .. "juno_jade_v00.ti",
  kernels .. "juno_jedi_v00.ti",
  kernels .. "juno_jiram_v01.ti",
  kernels .. "juno_junocam_v00.ti",
  kernels .. "juno_mag_v00.ti",
  kernels .. "juno_mwr_v01.ti",
  kernels .. "juno_struct_v01.ti",
  kernels .. "juno_uvs_v00.ti",
  kernels .. "juno_waves_v00.ti",
  kernels .. "juno_mwr_v01.ti",
  kernels .. "spk_merge_110805_171017_130515.bsp",
  kernels .. "juno_sc_nom_110807_171016_v01.bc",
  kernels .. "juno_sc_prl_110930_111028_jc003c01_v01.bc",
  kernels .. "juno_sc_prl_111028_111125_jc004b00_v01.bc",
  kernels .. "juno_sc_prl_111125_111223_jc005b00_v01.bc",
  kernels .. "juno_sc_prl_111223_120127_jc006a02_v01.bc",
  kernels .. "juno_sc_prl_120127_120217_jc007a00_v01.bc",
  kernels .. "juno_sc_prl_120217_120316_jc008b00_v02.bc",
  kernels .. "juno_sc_prl_120316_120413_jc009a00_v01.bc",
  kernels .. "juno_sc_prl_120413_120511_jc010a04_v01.bc",
  kernels .. "juno_sc_prl_120511_120608_jc011a01_v02.bc",
  kernels .. "juno_sc_prl_120608_120706_jc012b01_v01.bc",
  kernels .. "juno_sc_prl_120706_120802_jc013a01_v01.bc",
  kernels .. "juno_sc_prl_120802_120824_jc014b01_v01.bc",
  kernels .. "juno_sc_prl_120824_120928_jc015m00_v01.bc",
  kernels .. "juno_sc_prl_120919_120928_jc015o00_v01.bc",
  kernels .. "juno_sc_prl_120928_121026_jc016c03_v01.bc",
  kernels .. "juno_sc_prl_121026_121123_jc017a01_v01.bc",
  kernels .. "juno_sc_prl_121123_121221_jc018b01_v01.bc",
  kernels .. "juno_sc_prl_121221_130118_jc019a01_v01.bc",
  kernels .. "juno_sc_prl_130118_130215_jc020b01_v01.bc",
  kernels .. "juno_sc_prl_130315_130412_jc022b01_v01.bc",
  kernels .. "juno_sc_prl_130412_130510_jc023b03_v01.bc",
  kernels .. "juno_sc_prl_130510_130607_jc024a01_v01.bc",
  kernels .. "juno_sc_prl_130607_130705_jc025a00_v01.bc",
  kernels .. "juno_sc_prl_130705_130802_jc026a01_v01.bc",
  kernels .. "juno_sc_prl_130726_131020_jx024a02_EFB_v03.bc",
  kernels .. "juno_sc_prl_130802_130830_jc027a02_v01.bc",
  kernels .. "juno_sc_prl_130830_130927_jc028a01_v01.bc",
  kernels .. "juno_sc_prl_130926_131025_jc029a00_v01.bc",
  kernels .. "juno_sc_prl_130927_131025_jc029c01_v01.bc",
  kernels .. "juno_sc_prl_131022_131025_jc029f00_v01.bc",
  kernels .. "juno_sc_prl_131025_131122_jc030b04_v01.bc",
  kernels .. "juno_sc_prl_131122_131220_jc031b01_v01.bc",
  kernels .. "juno_sc_prl_131220_140124_jc032a01_v01.bc",
  kernels .. "juno_sc_prl_140124_140214_jc033a01_v01.bc",
  kernels .. "juno_sc_prl_140214_140314_jc034b01_v01.bc",
  kernels .. "juno_sc_prl_140314_140411_jc035a01_v01.bc",
  kernels .. "juno_sc_prl_140411_140509_jc036b01_v01.bc",
  kernels .. "juno_sc_prl_140509_140606_jc037b02_v01.bc",
  kernels .. "juno_sc_prl_140606_140704_jc038a01_v01.bc",
  kernels .. "juno_sc_prl_140704_140801_jc039b01_v01.bc",
  kernels .. "juno_sc_prl_140801_140829_jc040a01_v01.bc",
  kernels .. "juno_sc_prl_140829_140926_jc041a01_v01.bc",
  kernels .. "juno_sc_prl_140926_141024_jc042a01_v01.bc",
  kernels .. "juno_sc_prl_141024_141121_jc043a01_v01.bc",
  kernels .. "juno_sc_prl_141105_141121_jc043m01_v01.bc",
  kernels .. "juno_sc_prl_141107_141121_jc043s01_v01.bc",
  kernels .. "juno_sc_prl_141121_141219_jc044a01_v01.bc",
  kernels .. "juno_sc_prl_141219_150123_jc045a01_v01.bc",
  kernels .. "juno_sc_prl_150123_150213_jc046a01_v01.bc",
  kernels .. "juno_sc_prl_150213_150313_jc047a01_v01.bc",
  kernels .. "juno_sc_prl_150312_150409_jc048a01_v01.bc",
  kernels .. "juno_sc_prl_150410_150508_jc049a01_v01.bc",
  kernels .. "juno_sc_prl_150508_150605_jc050a01_v01.bc",
  kernels .. "juno_sc_prl_150605_150703_jc051a01_v01.bc",
  kernels .. "juno_sc_prl_150703_150731_jc052a01_v01.bc",
  kernels .. "juno_sc_prl_150731_150828_jc053a01_v01.bc",
  kernels .. "juno_sc_prl_150805_150828_jc053m00_v01.bc",
  kernels .. "juno_sc_prl_150807_150828_jc053s00_v01.bc",
  kernels .. "juno_sc_prl_150828_150924_jc054a00_v01.bc",
  kernels .. "juno_sc_prl_150924_151023_jc055a00_v01.bc",
  kernels .. "juno_sc_prl_151023_151120_jc056a00_v01.bc",
  kernels .. "juno_sc_prl_151120_151218_jc057a00_v01.bc",
  kernels .. "juno_sc_prl_151218_160115_jc058a00_v01.bc",
  kernels .. "juno_sc_prl_160115_160212_jc059a00_v01.bc",
  kernels .. "juno_sc_prl_160212_160311_jc060a00_v01.bc",
  kernels .. "juno_sc_prl_160311_160408_jc061a00_v01.bc",
  kernels .. "juno_sc_prl_160408_160506_jc062a00_v01.bc",
  kernels .. "juno_sc_prl_160506_160603_jc063a00_v01.bc",
  kernels .. "juno_sc_prl_160603_160630_jc064a00_v01.bc",
  kernels .. "juno_sc_prl_160708_160729_jm0001rp_v02.bc",
  kernels .. "juno_sc_prl_160729_160826_jm0002rp_v01.bc",
  kernels .. "juno_sc_prl_160827_160920_jm0003a00_v01.bc",
  kernels .. "juno_sc_prl_160924_161019_jm0004a00_v01.bc",
  kernels .. "juno_sc_prl_161014_161115_jm0005a00_v01.bc",
  kernels .. "juno_sc_prl_161022_161115_jm0005b00_v01.bc",
  kernels .. "juno_sc_prl_161115_161213_jx0405rp_v01.bc",
  kernels .. "juno_sc_prl_161210_170115_jm0031a00_v01.bc",
  kernels .. "juno_sc_prl_170115_170201_jm0032a00_v01.bc",
  kernels .. "juno_sc_prl_170201_170309_jm0041a00_v01.bc",
  kernels .. "juno_sc_prl_170309_170326_jm0042rp_v01.bc",
  kernels .. "juno_sc_prl_170326_170427_jm0051rp_v01.bc",
  kernels .. "juno_sc_prl_170427_170518_jm0052rp_v01.bc",
  kernels .. "juno_sc_prl_170518_170615_jm0061a00_v01.bc",
  kernels .. "juno_sc_prl_170615_170710_jm0062a00_v01.bc",
  kernels .. "juno_sc_prl_170710_170805_jm0071a00_v01.bc",
  kernels .. "juno_sc_prl_170805_170831_jm0072a00_v01.bc",
  kernels .. "juno_sc_prl_170831_170927_jm0081a00_v01.bc",
  kernels .. "juno_sc_prl_170927_171023_jm0082a00_v01.bc",
  kernels .. "juno_sc_prl_171023_171030_jm0091a00_v01.bc",
  kernels .. "juno_sc_prl_171023_171030_jm0091a00_v01.bc"
}

local RotationMatrix = {
  0, 1, 0,
  0, 0, 1,
  1, 0, 0
}

local Juno = {
  Identifier = "Juno",
  Parent = transforms.JupiterBarycenter.Identifier,
  Transform = {
    Translation = {
      Type = "SpiceTranslation",
      Target = "JUNO",
      Observer = "JUPITER BARYCENTER",
      Kernels = JunoKernels
    },
    Rotation = {
      Type = "SpiceRotation",
      SourceFrame = "JUNO_SPACECRAFT",
      DestinationFrame = "GALACTIC",
      Kernels = JunoKernels
    }
  },
  Renderable = {
    Type = "RenderableModel",
    GeometryFile = model .. "Juno.obj",
    ModelTransform = RotationMatrix,
    LightSources = {
      sun.LightSource,
      {
        Identifier = "Camera",
        Type = "CameraLightSource",
        Intensity = 0.5
      }
    }
  },
  TimeFrame = {
    Type = "TimeFrameInterval",
    Start = "2011-08-07T17:15:00",
    End = "2017-10-16T19:29:24"
  },
  GUI = {
    Path = "/Solar System/Missions/Juno"
  }
}

local JunoTrail = {
  Identifier = "JunoTrail",
  Parent = transforms.JupiterBarycenter.Identifier,
  Renderable = {
    Type = "RenderableTrailTrajectory",
    Translation = {
      Type = "SpiceTranslation",
      Target = "JUNO",
      Observer = "JUPITER BARYCENTER",
      Kernels = JunoKernels
    },
    Color = { 0.70, 0.50, 0.20 },
    StartTime = "2016 JUL 01",
    EndTime = "2016 DEC 13",
    SampleInterval = 3600
  },
  GUI = {
    Name = "Juno Trail",
    Path = "/Solar System/Missions/Juno"
  }
}

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