From 205374fee2bc38d69742c571ae4ebb94bbc98573 Mon Sep 17 00:00:00 2001 From: Malin Ejdbo Date: Thu, 18 Mar 2021 15:20:23 +0100 Subject: [PATCH] Use codegen in ModelProjection and make use of new dictionary --- modules/base/rendering/renderablemodel.cpp | 12 +- .../rendering/renderablemodelprojection.cpp | 165 ++++++++---------- 2 files changed, 79 insertions(+), 98 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 3da3695999..2a387cbd9d 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -372,14 +372,12 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) _disableFaceCulling = *p.disableFaceCulling; } - if (dictionary.hasKey(LightSourcesInfo.identifier)) { - const ghoul::Dictionary& lsDictionary = - dictionary.value(LightSourcesInfo.identifier); + if (p.lightSources.has_value()) { + std::vector lightsources = *p.lightSources; - for (std::string_view k : lsDictionary.keys()) { - std::unique_ptr lightSource = LightSource::createFromDictionary( - lsDictionary.value(k) - ); + for (const ghoul::Dictionary& lsDictionary : lightsources) { + std::unique_ptr lightSource = + LightSource::createFromDictionary(lsDictionary); _lightSourcePropertyOwner.addPropertySubOwner(lightSource.get()); _lightSources.push_back(std::move(lightSource)); } diff --git a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp index d91c07fe59..eb3fdf4cd2 100644 --- a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp +++ b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp @@ -42,6 +42,7 @@ #include #include #include +#include namespace { constexpr const char* _loggerCat = "RenderableModelProjection"; @@ -73,131 +74,113 @@ namespace { "location to the Sun. If this value is disabled, shading is disabled and the " "entire model is rendered brightly." }; + + struct [[codegen::Dictionary(RenderableModelProjection)]] Parameters { + // The file or files that should be loaded in this RenderableModel. The file can + // contain filesystem tokens or can be specified relatively to the + // location of the .mod file. + // This specifies the model that is rendered by the Renderable. + std::variant> geometryFile; + + // Contains information about projecting onto this planet. + ghoul::Dictionary projection [[codegen::reference("newhorizons_projectioncomponent")]]; + + // [[codegen::verbatim(PerformShadingInfo.description)]] + std::optional performShading; + + // The radius of the bounding sphere of this object. This has to be a + // radius that is larger than anything that is rendered by it. It has to + // be at least as big as the convex hull of the object. The default value + // is 10e9 meters. + std::optional boundingSphereRadius; + }; +#include "renderablemodelprojection_codegen.cpp" } // namespace namespace openspace { documentation::Documentation RenderableModelProjection::Documentation() { - using namespace documentation; - - return { - "Renderable Model Projection", - "newhorizons_renderable_modelprojection", - { - { - KeyGeomModelFile, - new OrVerifier({ new StringVerifier, new StringListVerifier }), - Optional::No, - "The file or files that are used for rendering of this model" - }, - { - keyProjection, - new ReferencingVerifier("newhorizons_projectioncomponent"), - Optional::No, - "Contains information about projecting onto this planet." - }, - { - PerformShadingInfo.identifier, - new BoolVerifier, - Optional::Yes, - PerformShadingInfo.description - }, - { - keyBoundingSphereRadius, - new DoubleVerifier, - Optional::Yes, - "The radius of the bounding sphere of this object. This has to be a " - "radius that is larger than anything that is rendered by it. It has to " - "be at least as big as the convex hull of the object. The default value " - "is 10e9 meters." - } - } - }; + documentation::Documentation doc = codegen::doc(); + doc.id = "newhorizons_renderable_modelprojection"; + return doc; } RenderableModelProjection::RenderableModelProjection(const ghoul::Dictionary& dictionary) : Renderable(dictionary) , _performShading(PerformShadingInfo, true) { - documentation::testSpecificationAndThrow( - Documentation(), - dictionary, - "RenderableModelProjection" - ); + const Parameters p = codegen::bake(dictionary); - if (dictionary.hasKey(KeyGeomModelFile)) { + if (std::holds_alternative(p.geometryFile)) { + // Handle single file std::string file; + file = absPath(std::get(p.geometryFile)); + _geometry = ghoul::io::ModelReader::ref().loadModel( + file, + ghoul::io::ModelReader::ForceRenderInvisible::No, + ghoul::io::ModelReader::NotifyInvisibleDropped::Yes + ); + } + else if (std::holds_alternative>(p.geometryFile)) { + LWARNING("Loading a model with several files is deprecated and will be " + "removed in a future release, TESTING" + ); + /* + ghoul::Dictionary fileDictionary = dictionary.value( + KeyGeomModelFile + ); + std::vector> geometries; - if (dictionary.hasValue(KeyGeomModelFile)) { - // Handle single file - file = absPath(dictionary.value(KeyGeomModelFile)); - _geometry = ghoul::io::ModelReader::ref().loadModel( + for (std::string_view k : fileDictionary.keys()) { + // Handle each file + file = absPath(fileDictionary.value(k)); + geometries.push_back(ghoul::io::ModelReader::ref().loadModel( file, ghoul::io::ModelReader::ForceRenderInvisible::No, ghoul::io::ModelReader::NotifyInvisibleDropped::Yes - ); + )); } - else if (dictionary.hasValue(KeyGeomModelFile)) { - LWARNING("Loading a model with several files is deprecated and will be " - "removed in a future release" - ); - ghoul::Dictionary fileDictionary = dictionary.value( - KeyGeomModelFile - ); - std::vector> geometries; + if (!geometries.empty()) { + std::unique_ptr combinedGeometry = + std::move(geometries[0]); - for (std::string_view k : fileDictionary.keys()) { - // Handle each file - file = absPath(fileDictionary.value(k)); - geometries.push_back(ghoul::io::ModelReader::ref().loadModel( - file, - ghoul::io::ModelReader::ForceRenderInvisible::No, - ghoul::io::ModelReader::NotifyInvisibleDropped::Yes - )); - } - - if (!geometries.empty()) { - std::unique_ptr combinedGeometry = - std::move(geometries[0]); - - // Combine all models into one ModelGeometry - for (unsigned int i = 1; i < geometries.size(); ++i) { - for (ghoul::io::ModelMesh& mesh : geometries[i]->meshes()) { - combinedGeometry->meshes().push_back( - std::move(mesh) - ); - } - - for (ghoul::modelgeometry::ModelGeometry::TextureEntry& texture : - geometries[i]->textureStorage()) - { - combinedGeometry->textureStorage().push_back( - std::move(texture) - ); - } + // Combine all models into one ModelGeometry + for (unsigned int i = 1; i < geometries.size(); ++i) { + for (ghoul::io::ModelMesh& mesh : geometries[i]->meshes()) { + combinedGeometry->meshes().push_back( + std::move(mesh) + ); + } + + for (ghoul::modelgeometry::ModelGeometry::TextureEntry& texture : + geometries[i]->textureStorage()) + { + combinedGeometry->textureStorage().push_back( + std::move(texture) + ); } - _geometry = std::move(combinedGeometry); - _geometry->calculateBoundingRadius(); } - } + _geometry = std::move(combinedGeometry); + _geometry->calculateBoundingRadius(); + }*/ } addPropertySubOwner(_projectionComponent); _projectionComponent.initialize( identifier(), - dictionary.value(keyProjection) + p.projection ); double boundingSphereRadius = 1.0e9; - if (dictionary.hasValue(keyBoundingSphereRadius)) { - boundingSphereRadius = dictionary.value(keyBoundingSphereRadius); + if (p.boundingSphereRadius.has_value()) { + boundingSphereRadius = *p.boundingSphereRadius; } setBoundingSphere(boundingSphereRadius); - if (dictionary.hasValue(PerformShadingInfo.identifier)) { - _performShading = dictionary.value(PerformShadingInfo.identifier); + if (p.performShading.has_value()) { + _performShading = *p.performShading; } addProperty(_performShading);