mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-01 17:20:09 -06:00
Apply simplification of shadow sources and casters to RenderableGlobe
This commit is contained in:
@@ -6,99 +6,98 @@ local assetHelper = asset.require('util/asset_helper')
|
||||
-- local earthEllipsoid = { 6378137.0, 6378137.0, 6356752.314245 }
|
||||
local earthEllipsoid = { 6378137.0, 6378137.0, 6378137.0 }
|
||||
local Atmosphere = {
|
||||
Identifier = "EarthAtmosphere",
|
||||
Parent = transforms.Earth.Identifier,
|
||||
Renderable = {
|
||||
Type = "RenderableAtmosphere",
|
||||
-- Atmosphere radius in Km
|
||||
AtmosphereHeight = 6447.0 - 6377.0,
|
||||
PlanetRadius = 6377.0,
|
||||
PlanetAverageGroundReflectance = 0.1,
|
||||
GroundRadianceEmission = 0.6,
|
||||
SunIntensity = 6.9,
|
||||
Rayleigh = {
|
||||
Coefficients = {
|
||||
-- Wavelengths are given in 10^-9m
|
||||
Wavelengths = { 680, 550, 440 },
|
||||
-- Reflection coefficients are given in km^-1
|
||||
Scattering = { 5.8E-3, 13.5E-3, 33.1E-3 },
|
||||
-- In Rayleigh scattering, the coefficients of absorption and scattering are the same.
|
||||
},
|
||||
-- Thichkness of atmosphere if its density were uniform, in Km
|
||||
H_R = 8.0
|
||||
},
|
||||
--[[
|
||||
Ozone = {
|
||||
Coefficients = {
|
||||
-- Extinction coefficients
|
||||
Extinction = {3.426, 8.298, 0.356}
|
||||
},
|
||||
H_O = 8.0,
|
||||
},
|
||||
]]
|
||||
-- Default
|
||||
Mie = {
|
||||
Coefficients = {
|
||||
-- Reflection coefficients are given in km^-1
|
||||
Scattering = { 4.0e-3, 4.0e-3, 4.0e-3 },
|
||||
-- Extinction coefficients are a fraction of the Mie coefficients
|
||||
Extinction = { 4.0e-3/0.9, 4.0e-3/0.9, 4.0e-3/0.9 }
|
||||
},
|
||||
-- Height scale (atmosphere thickness for constant density) in Km
|
||||
H_M = 1.2,
|
||||
-- Mie Phase Function Value (G e [-1.0, 1.0]. If G = 1.0, Mie phase function = Rayleigh Phase Function)
|
||||
G = 0.85
|
||||
},
|
||||
-- Clear Sky
|
||||
-- Mie = {
|
||||
-- Coefficients = {
|
||||
-- Scattering = {20e-3, 20e-3, 20e-3},
|
||||
-- Extinction = 1.0/0.9,
|
||||
-- }
|
||||
-- H_M = 1.2,
|
||||
-- G = 0.76,
|
||||
-- },
|
||||
-- Cloudy
|
||||
-- Mie = {
|
||||
-- Coefficients = {
|
||||
-- Scattering = {3e-3, 3e-3, 3e-3},
|
||||
-- Extinction = 1.0/0.9,
|
||||
-- }
|
||||
-- H_M = 3.0,
|
||||
-- G = 0.65,
|
||||
-- },
|
||||
Debug = {
|
||||
PreCalculatedTextureScale = 1.0,
|
||||
SaveCalculatedTextures = false
|
||||
Identifier = "EarthAtmosphere",
|
||||
Parent = transforms.Earth.Identifier,
|
||||
Renderable = {
|
||||
Type = "RenderableAtmosphere",
|
||||
-- Atmosphere radius in Km
|
||||
AtmosphereHeight = 6447.0 - 6377.0,
|
||||
PlanetRadius = 6377.0,
|
||||
PlanetAverageGroundReflectance = 0.1,
|
||||
GroundRadianceEmission = 0.6,
|
||||
SunIntensity = 6.9,
|
||||
Rayleigh = {
|
||||
Coefficients = {
|
||||
-- Wavelengths are given in 10^-9m
|
||||
Wavelengths = { 680, 550, 440 },
|
||||
-- Reflection coefficients are given in km^-1
|
||||
Scattering = { 5.8E-3, 13.5E-3, 33.1E-3 },
|
||||
-- In Rayleigh scattering, the coefficients of absorption and scattering are the same.
|
||||
},
|
||||
ShadowGroup = {
|
||||
Sources = {
|
||||
{ Name = "Sun", Radius = 696.3E6 },
|
||||
-- { Name = "Monolith", Radius = 0.01E6 }
|
||||
-- Thichkness of atmosphere if its density were uniform, in Km
|
||||
H_R = 8.0
|
||||
},
|
||||
--[[
|
||||
Ozone = {
|
||||
Coefficients = {
|
||||
-- Extinction coefficients
|
||||
Extinction = {3.426, 8.298, 0.356}
|
||||
},
|
||||
H_O = 8.0,
|
||||
},
|
||||
]]
|
||||
-- Default
|
||||
Mie = {
|
||||
Coefficients = {
|
||||
-- Reflection coefficients are given in km^-1
|
||||
Scattering = { 4.0e-3, 4.0e-3, 4.0e-3 },
|
||||
-- Extinction coefficients are a fraction of the Mie coefficients
|
||||
Extinction = { 4.0e-3/0.9, 4.0e-3/0.9, 4.0e-3/0.9 }
|
||||
},
|
||||
Casters = {
|
||||
{ Name = "Moon", Radius = 1.737E6 },
|
||||
-- { Name = "Independence Day Ship", Radius = 0.0 }
|
||||
|
||||
}
|
||||
}
|
||||
-- Height scale (atmosphere thickness for constant density) in Km
|
||||
H_M = 1.2,
|
||||
-- Mie Phase Function Value (G e [-1.0, 1.0]. If G = 1.0, Mie phase function = Rayleigh Phase Function)
|
||||
G = 0.85
|
||||
},
|
||||
-- Clear Sky
|
||||
-- Mie = {
|
||||
-- Coefficients = {
|
||||
-- Scattering = {20e-3, 20e-3, 20e-3},
|
||||
-- Extinction = 1.0/0.9,
|
||||
-- }
|
||||
-- H_M = 1.2,
|
||||
-- G = 0.76,
|
||||
-- },
|
||||
-- Cloudy
|
||||
-- Mie = {
|
||||
-- Coefficients = {
|
||||
-- Scattering = {3e-3, 3e-3, 3e-3},
|
||||
-- Extinction = 1.0/0.9,
|
||||
-- }
|
||||
-- H_M = 3.0,
|
||||
-- G = 0.65,
|
||||
-- },
|
||||
Debug = {
|
||||
PreCalculatedTextureScale = 1.0,
|
||||
SaveCalculatedTextures = false
|
||||
},
|
||||
GUI = {
|
||||
Name = "Earth Atmosphere",
|
||||
Path = "/Solar System/Planets/Earth",
|
||||
Description = [[ Atmosphere of Earth.]]
|
||||
ShadowGroup = {
|
||||
Sources = {
|
||||
{ Name = "Sun", Radius = 696.3E6 },
|
||||
-- { Name = "Monolith", Radius = 0.01E6 }
|
||||
},
|
||||
Casters = {
|
||||
{ Name = "Moon", Radius = 1.737E6 },
|
||||
-- { Name = "Independence Day Ship", Radius = 0.0 }
|
||||
}
|
||||
}
|
||||
},
|
||||
GUI = {
|
||||
Name = "Earth Atmosphere",
|
||||
Path = "/Solar System/Planets/Earth",
|
||||
Description = [[ Atmosphere of Earth.]]
|
||||
}
|
||||
}
|
||||
|
||||
assetHelper.registerSceneGraphNodesAndExport(asset, { Atmosphere })
|
||||
|
||||
|
||||
asset.meta = {
|
||||
Name = "Earth Atmosphere",
|
||||
Version = "1.0",
|
||||
Description = [[ RenderableAtmosphere for Earth.]],
|
||||
Author = "OpenSpace Team",
|
||||
URL = "http://openspaceproject.com",
|
||||
License = "MIT license",
|
||||
Identifiers = {"EarthAtmosphere"}
|
||||
Name = "Earth Atmosphere",
|
||||
Version = "1.0",
|
||||
Description = [[ RenderableAtmosphere for Earth.]],
|
||||
Author = "OpenSpace Team",
|
||||
URL = "http://openspaceproject.com",
|
||||
License = "MIT license",
|
||||
Identifiers = { "EarthAtmosphere" }
|
||||
}
|
||||
|
||||
@@ -15,15 +15,11 @@ local Earth = {
|
||||
PerformShading = false,
|
||||
Layers = {},
|
||||
ShadowGroup = {
|
||||
Source1 = {
|
||||
Name = "Sun",
|
||||
-- All radius in meters
|
||||
Radius = 696.3E6
|
||||
Sources = {
|
||||
{ Name = "Sun", Radius = 696.3E6 },
|
||||
},
|
||||
Caster1 = {
|
||||
Name = "Moon",
|
||||
-- All radius in meters
|
||||
Radius = 1.737E6
|
||||
Casters = {
|
||||
{ Name = "Moon", Radius = 1.737E6 },
|
||||
}
|
||||
},
|
||||
Labels = {
|
||||
|
||||
@@ -26,15 +26,13 @@ local Moon = {
|
||||
SegmentsPerPatch = 64,
|
||||
Layers = {},
|
||||
ShadowGroup = {
|
||||
Source1 = {
|
||||
Name = sunAsset.Sun.Name,
|
||||
Radius = 696.3E6
|
||||
Sources = {
|
||||
{ Name = sunAsset.Sun.Identifier, Radius = 696.3E6 },
|
||||
},
|
||||
Caster1 = {
|
||||
Name = earthAsset.Earth.Name,
|
||||
Radius = 6.371E6
|
||||
Casters = {
|
||||
{ Name = earthAsset.Earth.Identifier, Radius = 6.371E6 },
|
||||
}
|
||||
},
|
||||
},
|
||||
Labels = {
|
||||
Enable = false,
|
||||
FileName = labelsPath .. "/moon.labels",
|
||||
|
||||
@@ -19,31 +19,15 @@ local Jupiter = {
|
||||
SegmentsPerPatch = 64,
|
||||
Layers = {},
|
||||
ShadowGroup = {
|
||||
Source1 = {
|
||||
Name = "Sun",
|
||||
-- All radius in meters
|
||||
Radius = 696.3E6
|
||||
},
|
||||
Caster1 = {
|
||||
Name = "Ganymede",
|
||||
-- All radius in meters
|
||||
Radius = 2631000
|
||||
},
|
||||
Caster2 = {
|
||||
Name = "Io",
|
||||
-- All radius in meters
|
||||
Radius = 1821600
|
||||
},
|
||||
Caster3 = {
|
||||
Name = "Europa",
|
||||
-- All radius in meters
|
||||
Radius = 1560800
|
||||
},
|
||||
Caster4 = {
|
||||
Name = "Callisto",
|
||||
-- All radius in meters
|
||||
Radius = 2410000
|
||||
Sources = {
|
||||
{ Name = "Sun", Radius = 696.3E6 },
|
||||
},
|
||||
Casters = {
|
||||
{ Name = "Ganymede", Radius = 2631000 },
|
||||
{ Name = "Io", Radius = 1821600 },
|
||||
{ Name = "Europa", Radius = 1560800 },
|
||||
{ Name = "Callisto", Radius = 2410000 }
|
||||
}
|
||||
}
|
||||
},
|
||||
Tag = { "planet_solarSystem", "planet_giants" },
|
||||
|
||||
@@ -60,20 +60,20 @@ namespace {
|
||||
constexpr const char* KeyShadowSource = "Source";
|
||||
constexpr const char* KeyShadowCaster = "Caster";
|
||||
|
||||
constexpr const char* keyPlanetRadius = "PlanetRadius";
|
||||
constexpr const char* keyAverageGroundReflectance = "PlanetAverageGroundReflectance";
|
||||
constexpr const char* keyRayleigh = "Rayleigh";
|
||||
constexpr const char* keyRayleighHeightScale = "H_R";
|
||||
constexpr const char* keyOzone = "Ozone";
|
||||
constexpr const char* keyOzoneHeightScale = "H_O";
|
||||
constexpr const char* keyMie = "Mie";
|
||||
constexpr const char* keyMieHeightScale = "H_M";
|
||||
constexpr const char* keyMiePhaseConstant = "G";
|
||||
constexpr const char* keyImage = "Image";
|
||||
constexpr const char* keyToneMappingOp = "ToneMapping";
|
||||
constexpr const char* keyATMDebug = "Debug";
|
||||
constexpr const char* keyTextureScale = "PreCalculatedTextureScale";
|
||||
constexpr const char* keySaveTextures = "SaveCalculatedTextures";
|
||||
constexpr const char* KeyPlanetRadius = "PlanetRadius";
|
||||
constexpr const char* KeyAverageGroundReflectance = "PlanetAverageGroundReflectance";
|
||||
constexpr const char* KeyRayleigh = "Rayleigh";
|
||||
constexpr const char* KeyRayleighHeightScale = "H_R";
|
||||
constexpr const char* KeyOzone = "Ozone";
|
||||
constexpr const char* KeyOzoneHeightScale = "H_O";
|
||||
constexpr const char* KeyMie = "Mie";
|
||||
constexpr const char* KeyMieHeightScale = "H_M";
|
||||
constexpr const char* KeyMiePhaseConstant = "G";
|
||||
constexpr const char* KeyImage = "Image";
|
||||
constexpr const char* KeyToneMappingOp = "ToneMapping";
|
||||
constexpr const char* KeyATMDebug = "Debug";
|
||||
constexpr const char* KeyTextureScale = "PreCalculatedTextureScale";
|
||||
constexpr const char* KeySaveTextures = "SaveCalculatedTextures";
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo AtmosphereHeightInfo = {
|
||||
"AtmosphereHeight",
|
||||
@@ -137,7 +137,7 @@ namespace {
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo MieScatteringCoeffInfo = {
|
||||
"MieScatteringCoeff",
|
||||
"Mie Scattering Coeff (x10e-3)",
|
||||
"Mie Scattering Coeff",
|
||||
"Mie sea-level scattering coefficients in meters"
|
||||
};
|
||||
|
||||
@@ -214,18 +214,18 @@ documentation::Documentation RenderableAtmosphere::Documentation() {
|
||||
{
|
||||
"*",
|
||||
new TableVerifier({
|
||||
{
|
||||
"Name",
|
||||
new StringVerifier,
|
||||
Optional::No,
|
||||
"The scene graph node name of the caster"
|
||||
},
|
||||
{
|
||||
"Radius",
|
||||
new DoubleVerifier,
|
||||
Optional::No,
|
||||
"The radius of the object in meters"
|
||||
}
|
||||
{
|
||||
"Name",
|
||||
new StringVerifier,
|
||||
Optional::No,
|
||||
"The scene graph node name of the caster"
|
||||
},
|
||||
{
|
||||
"Radius",
|
||||
new DoubleVerifier,
|
||||
Optional::No,
|
||||
"The radius of the object in meters"
|
||||
}
|
||||
}),
|
||||
Optional::Yes,
|
||||
"Individual shadow casters"
|
||||
@@ -257,7 +257,7 @@ documentation::Documentation RenderableAtmosphere::Documentation() {
|
||||
""
|
||||
},
|
||||
{
|
||||
keyRayleighHeightScale,
|
||||
KeyRayleighHeightScale,
|
||||
new DoubleVerifier,
|
||||
Optional::No,
|
||||
""
|
||||
@@ -266,7 +266,7 @@ documentation::Documentation RenderableAtmosphere::Documentation() {
|
||||
|
||||
TableVerifier* ozoneTable = new TableVerifier({
|
||||
{
|
||||
keyOzoneHeightScale,
|
||||
KeyOzoneHeightScale,
|
||||
new DoubleVerifier,
|
||||
Optional::Yes,
|
||||
""
|
||||
@@ -288,7 +288,7 @@ documentation::Documentation RenderableAtmosphere::Documentation() {
|
||||
|
||||
TableVerifier* mieTable = new TableVerifier({
|
||||
{
|
||||
keyMieHeightScale,
|
||||
KeyMieHeightScale,
|
||||
new DoubleVerifier,
|
||||
Optional::No,
|
||||
""
|
||||
@@ -313,7 +313,7 @@ documentation::Documentation RenderableAtmosphere::Documentation() {
|
||||
""
|
||||
},
|
||||
{
|
||||
keyMiePhaseConstant,
|
||||
KeyMiePhaseConstant,
|
||||
new DoubleInRangeVerifier(-1.0, 1.0),
|
||||
Optional::No,
|
||||
""
|
||||
@@ -338,13 +338,13 @@ documentation::Documentation RenderableAtmosphere::Documentation() {
|
||||
AtmosphereHeightInfo.description
|
||||
},
|
||||
{
|
||||
keyPlanetRadius,
|
||||
KeyPlanetRadius,
|
||||
new DoubleVerifier,
|
||||
Optional::No,
|
||||
"The radius of the planet in meters"
|
||||
},
|
||||
{
|
||||
keyAverageGroundReflectance,
|
||||
KeyAverageGroundReflectance,
|
||||
new DoubleVerifier,
|
||||
Optional::No,
|
||||
""
|
||||
@@ -368,34 +368,34 @@ documentation::Documentation RenderableAtmosphere::Documentation() {
|
||||
GroundRadianceEmittioninfo.description
|
||||
},
|
||||
{
|
||||
keyRayleigh,
|
||||
KeyRayleigh,
|
||||
rayleighTable,
|
||||
Optional::No,
|
||||
""
|
||||
},
|
||||
{
|
||||
keyOzone,
|
||||
KeyOzone,
|
||||
ozoneTable,
|
||||
Optional::Yes,
|
||||
""
|
||||
},
|
||||
{
|
||||
keyMie,
|
||||
KeyMie,
|
||||
mieTable,
|
||||
Optional::No,
|
||||
""
|
||||
},
|
||||
{
|
||||
keyATMDebug,
|
||||
KeyATMDebug,
|
||||
new TableVerifier({
|
||||
{
|
||||
keyTextureScale,
|
||||
KeyTextureScale,
|
||||
new DoubleInRangeVerifier(0.0, 1.0),
|
||||
Optional::Yes,
|
||||
""
|
||||
},
|
||||
{
|
||||
keySaveTextures,
|
||||
KeySaveTextures,
|
||||
new BoolVerifier,
|
||||
Optional::Yes,
|
||||
""
|
||||
@@ -451,7 +451,6 @@ RenderableAtmosphere::RenderableAtmosphere(const ghoul::Dictionary& dictionary)
|
||||
ghoul::Dictionary shadowDictionary =
|
||||
dictionary.value<ghoul::Dictionary>(KeyShadowGroup);
|
||||
|
||||
|
||||
std::vector<std::pair<std::string, double>> sourceArray;
|
||||
ghoul::Dictionary sources = shadowDictionary.value<ghoul::Dictionary>("Sources");
|
||||
for (std::string_view k : sources.keys()) {
|
||||
@@ -489,9 +488,9 @@ RenderableAtmosphere::RenderableAtmosphere(const ghoul::Dictionary& dictionary)
|
||||
_atmosphereHeight = static_cast<float>(
|
||||
dictionary.value<double>(AtmosphereHeightInfo.identifier)
|
||||
);
|
||||
_planetRadius = static_cast<float>(dictionary.value<double>(keyPlanetRadius));
|
||||
_planetRadius = static_cast<float>(dictionary.value<double>(KeyPlanetRadius));
|
||||
_groundAverageReflectance = static_cast<float>(
|
||||
dictionary.value<double>(keyAverageGroundReflectance)
|
||||
dictionary.value<double>(KeyAverageGroundReflectance)
|
||||
);
|
||||
_groundRadianceEmission = static_cast<float>(
|
||||
dictionary.value<double>(GroundRadianceEmittioninfo.identifier)
|
||||
@@ -510,22 +509,22 @@ RenderableAtmosphere::RenderableAtmosphere(const ghoul::Dictionary& dictionary)
|
||||
}
|
||||
|
||||
{
|
||||
ghoul::Dictionary rayleighDict = dictionary.value<ghoul::Dictionary>(keyRayleigh);
|
||||
ghoul::Dictionary rayleighDict = dictionary.value<ghoul::Dictionary>(KeyRayleigh);
|
||||
|
||||
ghoul::Dictionary coeffs = rayleighDict.value<ghoul::Dictionary>("Coefficients");
|
||||
_rayleighScatteringCoeff = coeffs.value<glm::dvec3>("Scattering");
|
||||
|
||||
_rayleighHeightScale = static_cast<float>(
|
||||
rayleighDict.value<double>(keyRayleighHeightScale)
|
||||
rayleighDict.value<double>(KeyRayleighHeightScale)
|
||||
);
|
||||
}
|
||||
|
||||
if (dictionary.hasValue<ghoul::Dictionary>(keyOzone)) {
|
||||
ghoul::Dictionary ozoneDict = dictionary.value<ghoul::Dictionary>(keyOzone);
|
||||
if (dictionary.hasValue<ghoul::Dictionary>(KeyOzone)) {
|
||||
ghoul::Dictionary ozoneDict = dictionary.value<ghoul::Dictionary>(KeyOzone);
|
||||
|
||||
if (ozoneDict.hasValue<double>(keyOzoneHeightScale)) {
|
||||
if (ozoneDict.hasValue<double>(KeyOzoneHeightScale)) {
|
||||
_ozoneHeightScale = static_cast<float>(
|
||||
ozoneDict.value<double>(keyOzoneHeightScale)
|
||||
ozoneDict.value<double>(KeyOzoneHeightScale)
|
||||
);
|
||||
_ozoneEnabled = true;
|
||||
}
|
||||
@@ -539,8 +538,8 @@ RenderableAtmosphere::RenderableAtmosphere(const ghoul::Dictionary& dictionary)
|
||||
}
|
||||
|
||||
{
|
||||
ghoul::Dictionary mieDict = dictionary.value<ghoul::Dictionary>(keyMie);
|
||||
_mieHeightScale = static_cast<float>(mieDict.value<double>(keyMieHeightScale));
|
||||
ghoul::Dictionary mieDict = dictionary.value<ghoul::Dictionary>(KeyMie);
|
||||
_mieHeightScale = static_cast<float>(mieDict.value<double>(KeyMieHeightScale));
|
||||
|
||||
ghoul::Dictionary coeffs = mieDict.value<ghoul::Dictionary>("Coefficients");
|
||||
|
||||
@@ -548,23 +547,23 @@ RenderableAtmosphere::RenderableAtmosphere(const ghoul::Dictionary& dictionary)
|
||||
_mieExtinctionCoeff = coeffs.value<glm::dvec3>("Extinction");
|
||||
|
||||
_miePhaseConstant = static_cast<float>(
|
||||
mieDict.value<double>(keyMiePhaseConstant)
|
||||
mieDict.value<double>(KeyMiePhaseConstant)
|
||||
);
|
||||
}
|
||||
|
||||
if (dictionary.hasValue<ghoul::Dictionary>(keyATMDebug)) {
|
||||
ghoul::Dictionary debugDict = dictionary.value<ghoul::Dictionary>(keyATMDebug);
|
||||
if (debugDict.hasKey(keyTextureScale)) {
|
||||
if (dictionary.hasValue<ghoul::Dictionary>(KeyATMDebug)) {
|
||||
ghoul::Dictionary debugDict = dictionary.value<ghoul::Dictionary>(KeyATMDebug);
|
||||
if (debugDict.hasKey(KeyTextureScale)) {
|
||||
_preCalculatedTexturesScale = static_cast<float>(
|
||||
debugDict.value<double>(keyTextureScale)
|
||||
debugDict.value<double>(KeyTextureScale)
|
||||
);
|
||||
LDEBUG(fmt::format(
|
||||
"Atmosphere Texture Scaled to {}", _preCalculatedTexturesScale
|
||||
));
|
||||
}
|
||||
|
||||
if (debugDict.hasKey(keySaveTextures)) {
|
||||
_saveCalculationsToTexture = debugDict.value<bool>(keySaveTextures);
|
||||
if (debugDict.hasKey(KeySaveTextures)) {
|
||||
_saveCalculationsToTexture = debugDict.value<bool>(KeySaveTextures);
|
||||
LDEBUG("Saving Precalculated Atmosphere Textures");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -633,84 +633,43 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary)
|
||||
_localChunkBuffer.resize(2048);
|
||||
_traversalMemory.resize(512);
|
||||
|
||||
//================================================================
|
||||
//======== Reads Shadow (Eclipses) Entries in mod file ===========
|
||||
//================================================================
|
||||
bool success = dictionary.hasValue<ghoul::Dictionary>(KeyShadowGroup);
|
||||
bool disableShadows = false;
|
||||
if (success) {
|
||||
// ================================================================
|
||||
// ======== Reads Shadow (Eclipses) Entries in asset file =========
|
||||
// ================================================================
|
||||
if (dictionary.hasValue<ghoul::Dictionary>(KeyShadowGroup)) {
|
||||
ghoul::Dictionary shadowDictionary =
|
||||
dictionary.value<ghoul::Dictionary>(KeyShadowGroup);
|
||||
|
||||
std::vector<std::pair<std::string, double>> sourceArray;
|
||||
unsigned int sourceCounter = 1;
|
||||
while (success) {
|
||||
std::string keyName =
|
||||
KeyShadowSource + std::to_string(sourceCounter) + ".Name";
|
||||
std::string keyRadius =
|
||||
KeyShadowSource + std::to_string(sourceCounter) + ".Radius";
|
||||
ghoul::Dictionary sources = shadowDictionary.value<ghoul::Dictionary>("Sources");
|
||||
for (std::string_view k : sources.keys()) {
|
||||
ghoul::Dictionary source = sources.value<ghoul::Dictionary>(k);
|
||||
|
||||
success = shadowDictionary.hasValue<std::string>(keyName);
|
||||
if (success) {
|
||||
std::string sourceName = shadowDictionary.value<std::string>(keyName);
|
||||
success = shadowDictionary.hasValue<double>(keyRadius);
|
||||
if (success) {
|
||||
double sourceRadius = shadowDictionary.value<double>(keyRadius);
|
||||
sourceArray.emplace_back(sourceName, sourceRadius);
|
||||
}
|
||||
else {
|
||||
//LWARNING("No Radius value expecified for Shadow Source Name "
|
||||
// << sourceName << " from " << name
|
||||
// << " planet.\nDisabling shadows for this planet.");
|
||||
disableShadows = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
sourceCounter++;
|
||||
std::string name = source.value<std::string>("Name");
|
||||
double radius = source.value<double>("Radius");
|
||||
sourceArray.emplace_back(name, radius);
|
||||
}
|
||||
|
||||
if (!disableShadows && !sourceArray.empty()) {
|
||||
success = true;
|
||||
std::vector<std::pair<std::string, double>> casterArray;
|
||||
unsigned int casterCounter = 1;
|
||||
while (success) {
|
||||
std::string keyName =
|
||||
KeyShadowCaster + std::to_string(casterCounter) + ".Name";
|
||||
std::string keyRadius =
|
||||
KeyShadowCaster + std::to_string(casterCounter) + ".Radius";
|
||||
success = shadowDictionary.hasValue<std::string>(keyName);
|
||||
std::vector<std::pair<std::string, double>> casterArray;
|
||||
ghoul::Dictionary casters = shadowDictionary.value<ghoul::Dictionary>("Casters");
|
||||
for (std::string_view k : casters.keys()) {
|
||||
ghoul::Dictionary caster = casters.value<ghoul::Dictionary>(k);
|
||||
|
||||
if (success) {
|
||||
std::string casterName = shadowDictionary.value<std::string>(keyName);
|
||||
success = shadowDictionary.hasValue<double>(keyRadius);
|
||||
if (success) {
|
||||
double casterRadius = shadowDictionary.value<double>(keyRadius);
|
||||
casterArray.emplace_back(casterName, casterRadius);
|
||||
}
|
||||
else {
|
||||
//LWARNING("No Radius value expecified for Shadow Caster Name "
|
||||
// << casterName << " from " << name
|
||||
// << " planet.\nDisabling shadows for this planet.");
|
||||
disableShadows = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::string name = caster.value<std::string>("Name");
|
||||
double radius = caster.value<double>("Radius");
|
||||
casterArray.emplace_back(name, radius);
|
||||
}
|
||||
|
||||
casterCounter++;
|
||||
}
|
||||
|
||||
std::vector<Ellipsoid::ShadowConfiguration> shadowConfArray;
|
||||
if (!disableShadows && (!sourceArray.empty() && !casterArray.empty())) {
|
||||
for (const std::pair<std::string, double>& source : sourceArray) {
|
||||
for (const std::pair<std::string, double>& caster : casterArray) {
|
||||
Ellipsoid::ShadowConfiguration sc;
|
||||
sc.source = source;
|
||||
sc.caster = caster;
|
||||
shadowConfArray.push_back(sc);
|
||||
}
|
||||
}
|
||||
_ellipsoid.setShadowConfigurationArray(shadowConfArray);
|
||||
std::vector<Ellipsoid::ShadowConfiguration> shadowConfArray;
|
||||
for (const std::pair<std::string, double>& source : sourceArray) {
|
||||
for (const std::pair<std::string, double>& caster : casterArray) {
|
||||
Ellipsoid::ShadowConfiguration sc;
|
||||
sc.source = source;
|
||||
sc.caster = caster;
|
||||
shadowConfArray.push_back(sc);
|
||||
}
|
||||
}
|
||||
_ellipsoid.setShadowConfigurationArray(shadowConfArray);
|
||||
}
|
||||
|
||||
// Labels Dictionary
|
||||
|
||||
Reference in New Issue
Block a user