local speck = asset.syncedResource({
  Name = "Background Radiation Speck Files",
  Type = "HttpSynchronization",
  Identifier = "digitaluniverse_backgroundradiation_speck",
  Version = 1
})

local textures = asset.syncedResource({
  Name = "Background Radiation Textures",
  Type = "HttpSynchronization",
  Identifier = "digitaluniverse_backgroundradiation_textures",
  Version = 2
})


local WMAP = {
  Identifier = "WMAP",
  Transform = {
    Rotation = {
      Type = "StaticRotation",
      Rotation = { 0, 0, math.pi }
    }
  },
  Renderable = {
    Type = "RenderableSphere",
    Enabled = false,
    Size = 3975.41417036064E23,
    Segments = 80,
    Opacity = 0.5,
    Texture = textures .. "wmap_ilc_7yr_v4_200uK_RGB_sos.png",
    Orientation = "Both",
    MirrorTexture = true,
    FadeInThreshold = 0.4
  },
  GUI = {
    Name = "Wilkinson Microwave Anisotropy Probe (WMAP)",
    Path = "/Universe/Cosmic Microwave Background"
  }
}

local CBE = {
  Identifier = "CBE",
  Transform = {
    Rotation = {
      Type = "StaticRotation",
      Rotation = { 0, 0, math.pi }
    }
  },
  Renderable = {
    Type = "RenderableSphere",
    Enabled = false,
    Size = 3975.41417036064E23,
    Segments = 80,
    Opacity = 0.5,
    Texture = textures .. "COBErect.png",
    Orientation = "Both",
    MirrorTexture = true,
    FadeInThreshold = 0.4
  },
  GUI = {
    Name = "Cosmic Background Explorer",
    Path = "/Universe/Cosmic Microwave Background"
  }
}

local Planck = {
  Identifier = "Planck",
  Transform = {
    Rotation = {
      Type = "StaticRotation",
      Rotation = { 0, 0, math.pi }
    }
  },
  Renderable = {
    Type = "RenderableSphere",
    Enabled = true,
    Size = 3975.41417036064E23,
    Segments = 80,
    Opacity = 0.3,
    Texture = textures .. "cmb4k.jpg",
    Orientation = "Both",
    MirrorTexture = true,
    FadeInThreshold = 0.4
  },
  GUI = {
    Name = "Planck",
    Path = "/Universe/Cosmic Microwave Background"
  }
}


local HAlpha = {
  Identifier = "HAlpha",
  Transform = {
    Rotation = {
      Type = "StaticRotation",
      Rotation = { 0, 0, math.pi }
    }
  },
  Renderable = {
    Type = "RenderableSphere",
    Enabled = false,
    Size = 9.2E21,
    Segments = 40,
    Opacity = 0.4,
    Texture = textures .. "mwHalpha-f.png",
    Orientation = "Inside",
    MirrorTexture = true,
    FadeOutThreshold = 0.025,
    Background = true
  },
  GUI = {
    Name = "H Alpha",
    Path = "/Milky Way/All Sky Images"
  }
}


asset.onInitialize(function()
  openspace.addSceneGraphNode(WMAP)
  openspace.addSceneGraphNode(CBE)
  openspace.addSceneGraphNode(Planck)
  openspace.addSceneGraphNode(HAlpha)
end)

asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(HAlpha)
  openspace.removeSceneGraphNode(Planck)
  openspace.removeSceneGraphNode(CBE)
  openspace.removeSceneGraphNode(WMAP)
end)

asset.export(WMAP)
asset.export(CBE)
asset.export(Planck)
asset.export(HAlpha)



asset.meta = {
  Name = "Background Radiation",
  Version = "2.1",
  Description = [[Various AllSky images for the Milky Way and observable Universe.
      Included: Wilkinson Microwave Anisotropy Probe (WMAP), Cosmic Background Explorer,
      Planck, and H Alpha <br><br> Data Reference: Planck/ESA and the Planck
      Collaboration, Wilkinson Microwave Anisotropy Probe/NASA, Doug
      Finkbeiner (Princeton)]],
  Author = "Brian Abbott (AMNH), OpenSpace Team",
  URL = "https://www.amnh.org/research/hayden-planetarium/digital-universe",
  License = "AMNH Digital Universe"
}
