diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index e72cd9f986..9ed0159885 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -40,13 +40,11 @@ #include #include #include +#include namespace { constexpr const char* _loggerCat = "RenderableModel"; - constexpr const char* ProgramName = "ModelProgram"; - constexpr const char* KeyGeomModelFile = "GeometryFile"; - constexpr const char* KeyForceRenderInvisible = "ForceRenderInvisible"; constexpr const int DefaultBlending = 0; constexpr const int AdditiveBlending = 1; @@ -126,7 +124,7 @@ namespace { }; constexpr openspace::properties::Property::PropertyInfo BlendingOptionInfo = { - "BledingOption", + "BlendingOption", "Blending Options", "Debug option for blending colors." }; @@ -136,106 +134,64 @@ namespace { "Enable Opacity Blending", "Enable Opacity Blending." }; + + struct [[codegen::Dictionary(RenderableModel)]] 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; + + // Set if invisible parts (parts with no textures or materials) of the model + // should be forced to render or not. + std::optional forceRenderInvisible; + + // The date and time that the model animation should start. + // In format 'YYYY MM DD hh:mm:ss'. + std::optional animationStartTime [[codegen::dateTime()]]; + + // [[codegen::verbatim(AmbientIntensityInfo.description)]] + std::optional ambientIntensity; + + // [[codegen::verbatim(DiffuseIntensityInfo.description)]] + std::optional diffuseIntensity; + + // [[codegen::verbatim(SpecularIntensityInfo.description)]] + std::optional specularIntensity; + + // [[codegen::verbatim(ShadingInfo.description)]] + std::optional performShading; + + // [[codegen::verbatim(DisableFaceCullingInfo.description)]] + std::optional disableFaceCulling; + + // [[codegen::verbatim(ModelTransformInfo.description)]] + std::optional modelTransform; + + // [[codegen::verbatim(RotationVecInfo.description)]] + std::optional rotationVector; + + // [[codegen::verbatim(LightSourcesInfo.description)]] + std::optional> lightSources [[codegen::reference("core_light_source")]]; + + // [[codegen::verbatim(DisableDepthTestInfo.description)]] + std::optional disableDepthTest; + + // [[codegen::verbatim(BlendingOptionInfo.description)]] + std::optional blendingOption; + + // [[codegen::verbatim(EnableOpacityBlendingInfo.description)]] + std::optional enableOpacityBlending; + }; +#include "renderablemodel_codegen.cpp" } // namespace namespace openspace { documentation::Documentation RenderableModel::Documentation() { - using namespace documentation; - return { - "RenderableModel", - "base_renderable_model", - { - { - KeyGeomModelFile, - new OrVerifier({ new StringVerifier, new StringListVerifier }), - Optional::No, - "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." - }, - { - KeyForceRenderInvisible, - new BoolVerifier, - Optional::Yes, - "Set if invisible parts (parts with no textures or materials) of the model " - "should be forced to render or not." - }, - { - AmbientIntensityInfo.identifier, - new DoubleVerifier, - Optional::Yes, - AmbientIntensityInfo.description - }, - { - DiffuseIntensityInfo.identifier, - new DoubleVerifier, - Optional::Yes, - DiffuseIntensityInfo.description - }, - { - SpecularIntensityInfo.identifier, - new DoubleVerifier, - Optional::Yes, - SpecularIntensityInfo.description - }, - { - ShadingInfo.identifier, - new BoolVerifier, - Optional::Yes, - ShadingInfo.description - }, - { - DisableFaceCullingInfo.identifier, - new BoolVerifier, - Optional::Yes, - DisableFaceCullingInfo.description - }, - { - ModelTransformInfo.identifier, - new DoubleMatrix3Verifier, - Optional::Yes, - ModelTransformInfo.description - }, - { - RotationVecInfo.identifier, - new DoubleVector3Verifier, - Optional::Yes, - RotationVecInfo.description - }, - { - LightSourcesInfo.identifier, - new TableVerifier({ - { - "*", - new ReferencingVerifier("core_light_source"), - Optional::Yes - } - }), - Optional::Yes, - LightSourcesInfo.description - }, - { - DisableDepthTestInfo.identifier, - new BoolVerifier, - Optional::Yes, - DisableDepthTestInfo.description - }, - { - BlendingOptionInfo.identifier, - new StringVerifier, - Optional::Yes, - BlendingOptionInfo.description - }, - { - EnableOpacityBlendingInfo.identifier, - new BoolVerifier, - Optional::Yes, - EnableOpacityBlendingInfo.description - }, - } - }; + documentation::Documentation doc = codegen::doc(); + doc.id = "base_renderable_model"; + return doc; } RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) @@ -260,17 +216,13 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) ) , _lightSourcePropertyOwner({ "LightSources", "Light Sources" }) { - documentation::testSpecificationAndThrow( - Documentation(), - dictionary, - "RenderableModel" - ); + const Parameters p = codegen::bake(dictionary); addProperty(_opacity); registerUpdateRenderBinFromOpacity(); - if (dictionary.hasKey(KeyForceRenderInvisible)) { - _forceRenderInvisible = dictionary.value(KeyForceRenderInvisible); + if (p.forceRenderInvisible.has_value()) { + _forceRenderInvisible = *p.forceRenderInvisible; if (!_forceRenderInvisible) { // Asset file have specifically said to not render invisible parts, @@ -279,88 +231,87 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& 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(_forceRenderInvisible), + ghoul::io::ModelReader::NotifyInvisibleDropped(_notifyInvisibleDropped) + ); + } + 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" + ); + /* + //TODO: update to use new codegen stuff + std::string file; + 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(_forceRenderInvisible), ghoul::io::ModelReader::NotifyInvisibleDropped(_notifyInvisibleDropped) - ); + )); } - 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(_forceRenderInvisible), - ghoul::io::ModelReader::NotifyInvisibleDropped(_notifyInvisibleDropped) - )); - } - - 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(); + }*/ } - if (dictionary.hasKey(ModelTransformInfo.identifier)) { - _modelTransform = dictionary.value(ModelTransformInfo.identifier); + if (p.modelTransform.has_value()) { + _modelTransform = *p.modelTransform; } - if (dictionary.hasKey(AmbientIntensityInfo.identifier)) { - _ambientIntensity = dictionary.value(AmbientIntensityInfo.identifier); + if (p.ambientIntensity.has_value()) { + _ambientIntensity = *p.ambientIntensity; } - if (dictionary.hasKey(DiffuseIntensityInfo.identifier)) { - _diffuseIntensity = dictionary.value(DiffuseIntensityInfo.identifier); + if (p.diffuseIntensity.has_value()) { + _diffuseIntensity = *p.diffuseIntensity; } - if (dictionary.hasKey(SpecularIntensityInfo.identifier)) { - _specularIntensity = dictionary.value(SpecularIntensityInfo.identifier); + if (p.specularIntensity.has_value()) { + _specularIntensity = *p.specularIntensity; } - if (dictionary.hasKey(ShadingInfo.identifier)) { - _performShading = dictionary.value(ShadingInfo.identifier); + if (p.performShading.has_value()) { + _performShading = *p.performShading; } - if (dictionary.hasKey(DisableDepthTestInfo.identifier)) { - _disableDepthTest = dictionary.value(DisableDepthTestInfo.identifier); + if (p.disableDepthTest.has_value()) { + _disableDepthTest = *p.disableDepthTest; } - if (dictionary.hasKey(DisableFaceCullingInfo.identifier)) { - _disableFaceCulling = dictionary.value(DisableFaceCullingInfo.identifier); + if (p.disableFaceCulling.has_value()) { + _disableFaceCulling = *p.disableFaceCulling; } if (dictionary.hasKey(LightSourcesInfo.identifier)) { @@ -391,8 +342,8 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) }); - if (dictionary.hasKey(RotationVecInfo.identifier)) { - _rotationVec = dictionary.value(RotationVecInfo.identifier); + if (p.rotationVector.has_value()) { + _rotationVec = *p.rotationVector; } _blendingFuncOption.addOption(DefaultBlending, "Default"); @@ -403,17 +354,13 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) addProperty(_blendingFuncOption); - if (dictionary.hasKey(BlendingOptionInfo.identifier)) { - const std::string blendingOpt = dictionary.value( - BlendingOptionInfo.identifier - ); + if (p.blendingOption.has_value()) { + const std::string blendingOpt = *p.blendingOption; _blendingFuncOption.set(BlendingMapping[blendingOpt]); } - if (dictionary.hasKey(DisableDepthTestInfo.identifier)) { - _enableOpacityBlending = dictionary.value( - EnableOpacityBlendingInfo.identifier - ); + if (p.enableOpacityBlending.has_value()) { + _enableOpacityBlending = *p.enableOpacityBlending; } addProperty(_enableOpacityBlending); diff --git a/src/documentation/verifier.cpp b/src/documentation/verifier.cpp index 751bb0ee9b..2e2e4f00d0 100644 --- a/src/documentation/verifier.cpp +++ b/src/documentation/verifier.cpp @@ -249,7 +249,7 @@ TestResult DateTimeVerifier::operator()(const ghoul::Dictionary& dict, TestResult::Offense off; off.offender = key; off.reason = TestResult::Offense::Reason::Verification; - off.explanation = "Not a valid format"; + off.explanation = "Not a valid format, should be: YYYY MM DD hh:mm:ss"; res.offenses.push_back(off); } // then check if valid date diff --git a/support/coding/codegen b/support/coding/codegen index 1ca72c0202..37b4ff6f5a 160000 --- a/support/coding/codegen +++ b/support/coding/codegen @@ -1 +1 @@ -Subproject commit 1ca72c0202e3bd4b61510f84797db131591c8ca3 +Subproject commit 37b4ff6f5a7d62fdacded6da12ef6d455cda9241