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



local data = asset.syncedResource({
  Name = "Milkyway Volume Data",
  Type = "HttpSynchronization",
  Identifier = "milkyway_volume_data",
  Version = 1
})

local kiloparsec = 3.086E19

local MilkyWayVolumeGalaxy = {
  Identifier = "MilkyWayVolume",
  Parent = transforms.SolarSystemBarycenter.Identifier,
  Transform = {
    Translation = {
      Type = "StaticTranslation",
      -- The center of the Milky Way is approximately 8 kiloparsec from the Sun.
      -- The x-axis of galactic coordinates points from the sun towards the center
      -- of the galaxy.
      Position = { 8 * kiloparsec, 0, 0 }
    }
  },
  Renderable = {
    Type = "RenderableGalaxy",
    StepSize = 0.01,
    AbsorptionMultiply = 200,
    EmissionMultiply = 250,
    Rotation = { math.pi, 3.1248, 4.45741 },
    Volume = {
      Type = "Volume",
      Filename = openspace.absPath(data .. "MilkyWayRGBAVolume1024x1024x128.raw"),
      Dimensions = { 1024, 1024, 128 },
      Size = { 1.2E21, 1.2E21, 0.15E21 },
      Downscale = 0.4,
    },
    Points = {
      Type = "Points",
      Filename = openspace.absPath(data .. "MilkyWayPoints.off"),
      EnabledPointsRatio = 0.3,
      Texture = openspace.absPath(data .. "halo.png")
    }
  },
  GUI = {
    Path = "/Milky Way",
    Name = "Milky Way Volume",
    Description = "Volumetric rendering of Milky Way galaxy based on simulation from NAOJ"
  }
}

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



asset.meta = {
  Name = "Milky Way Volume",
  Version = "1.1",
  Description = "Volumetric rendering of Milky Way galaxy based on simulations from NAOJ",
  Author = "OpenSpace Team",
  URL = "http://openspaceproject.com",
  License = "MIT License"
}
