local trail = asset.require("./trail")
local marsTransforms = asset.require("scene/solarsystem/planets/mars/transforms")
local sun = asset.require("scene/solarsystem/sun/sun")

local models = asset.syncedResource({
  Name = "Perseverance Model",
  Type = "HttpSynchronization",
  Identifier = "perseverance_models",
  Version = 2
})

-- Perseverance Model --
local Perseverance = {
  Identifier = "Perseverance",
  Parent = trail.PerseveranceNode.Identifier,
  GUI = {
    Name = "Perseverance",
    Path = "/Solar System/Missions/Perseverance"
  }
}

-- Perseverance Model --
local PerseveranceModel = {
  Identifier = "PerseveranceModel",
  Parent = Perseverance.Identifier,
  GUI = {
    Name = "Perseverance Model",
    Path = "/Solar System/Missions/Perseverance",
    Hidden = true
  }
}

-- Perseverance Model Instruments --
local Body = {
  Identifier = "Perseverance_body",
  Parent = PerseveranceModel.Identifier,
  Renderable = {
    Type = "RenderableModel",
    Body = "MARS SCIENCE LABORATORY",
    GeometryFile = models .. "Perseverance.obj",
    LightSources = {
      sun.LightSource,
      {
        Identifier = "Camera",
        Type = "CameraLightSource",
        Intensity = 0.5
      }
    },
    PerformShading = false,
    RotationVector = {65.940000,201.389999,263.980011}
  },
  GUI = {
    Name = "Perseverance Model Body",
    Path = "/Solar System/Missions/Perseverance/Model",
    Hidden = true
  }
}


asset.onInitialize(function()
  openspace.addSceneGraphNode(Perseverance)
  openspace.addSceneGraphNode(PerseveranceModel)
  openspace.addSceneGraphNode(Body)
end)
    
asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(Body)
  openspace.removeSceneGraphNode(PerseveranceModel)
  openspace.removeSceneGraphNode(Perseverance)
end)
    
asset.export(Perseverance)
asset.export(PerseveranceModel)
asset.export(Body)
