local textures = asset.syncedResource({
  Name = "Deep Sky Objects Textures",
  Type = "HttpSynchronization",
  Identifier = "digitaluniverse_deepsky_textures",
  Version = 1
})

local speck = asset.syncedResource({
  Name = "Deep Sky Objects Speck Files",
  Type = "HttpSynchronization",
  Identifier = "digitaluniverse_deepsky_speck",
  Version = 1
})

local deepSkyPoints = {
  Identifier = "DeepSkyObjects",
  Renderable = {
    Type = "RenderableBillboardsCloud",
    Enabled = false,
    Color = { 1.0, 1.0, 0.0 },
    Opacity = 0.99,
    ScaleFactor = 500.0,
    File = speck .. "dso.speck",
    Texture = textures .. "point3.png",
    --ColorMap = speck .. "tully.cmap",
    --ColorMap = speck .. "lss.cmap",
    --ColorOption = { "proximity" },
    --ColorOption = { "prox5Mpc" },
    --ColorRange = { { 1.0, 30.0 } },
    LabelFile = speck .. "dso.label",
    Unit = "pc",
    TextColor = { 0.1, 0.4, 0.6 },
    TextSize = 20.50,
    TextMinMaxSize = { 16, 20 },
    --FadeInDistances = { 0.05, 1.0 }, -- Fade in value in the same unit as "Unit"
    BillboardMinMaxSize = { 0.0, 8.22 }, -- in pixels
    --CorrectionSizeEndDistance = 22.0,
    --CorrectionSizeFactor = 10.45
    EnablePixelSizeControl = true
  },
  Transform = {
    Rotation = {
      Type = "StaticRotation",
      Rotation = { 0, 0, math.pi }
    }
  },
  GUI = {
    Name = "Deep Sky Objects Points",
    Path = "/Universe/Galaxies",
    Description = "Point cloud and labels for Deep Sky Objects"
  }
}

local deepSkyImages = {
  Identifier = "DeepSkyObjectsImages",
  Renderable = {
    Type = "RenderablePlanesCloud",
    Enabled = false,
    Color = { 1.0, 1.0, 1.0 },
    Opacity = 0.99,
    ScaleFactor = 1.0,
    File = speck .. "dso.speck",
    TexturePath = textures,
    Luminosity = "radius",
    ScaleLuminosity = 0.001,
    Unit = "pc",
    -- Fade in value in the same unit as "Unit"
    --FadeInDistances = {0.001, 0.05010},
    PlaneMinSize = 5.0
  },
  Transform = {
    Rotation = {
      Type = "StaticRotation",
      Rotation = { math.pi, math.pi, 0 }
    }
  },
  GUI = {
    Name = "Deep Sky Objects Images",
    Path = "/Universe/Galaxies",
    Description = [[Census: 63 images and labels. DU Version 1.3. <br> These data are
      2-D images of Messier objects placed in 3-D space. Not only do we place these 
      images at the proper location and give them the correct orientation, we also
      size them accurately so that you can fly to the globular cluster M13, for
      example, and see just how small the cluster of hundreds of thousands of stars
      is relative to the rest of the Galaxy. Included Messier Objects by number are:
      6, 7, 11, 16, 18, 21, 23-26, 29, 34-39, 41, 46-48, 50, 52, 67, 93, 103, 2-5,
      9, 10, 12-15, 19, 22, 28, 30, 53-56, 68-72, 75, 79, 80, 92, 107, 27, 57, 76,
      97, 8, 17, 20, 78, 1 (Description from URL) <br><br> Data Reference: Largely
      NOAO and various other sources (each image has a ref)]],
  }
}

asset.onInitialize(function()
  openspace.addSceneGraphNode(deepSkyPoints)
  openspace.addSceneGraphNode(deepSkyImages)
end)
  
asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(deepSkyImages)
  openspace.removeSceneGraphNode(deepSkyPoints)
end)
  
asset.export(deepSkyPoints)
asset.export(deepSkyImages)



asset.meta = {
  Name = "Deep Sky Objects Images",
  Version = "1.1",
  Description = "Digital Universe asset for Deep Sky Objects and their Images",
  Author = "Nate Greenstein, Matt Everhart, Brian Abbott (AMNH)",
  URL = "https://www.amnh.org/research/hayden-planetarium/digital-universe",
  License = "AMNH Digital Universe"
}
