From 8a30dc570e06c454554de1a631934230d725e6ca Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Tue, 27 Apr 2021 09:24:36 +0200 Subject: [PATCH] Add Logarithmic sliders and Color picker (#1564) * Pass ViewOptions meta data to WebUi * Add Color ViewOption * Add Logarithmic ViewOption * Update gui hash to get slider and color picker UI features --- data/assets/util/webgui.asset | 2 +- include/openspace/properties/property.h | 13 +++-- .../base/rendering/grids/renderablegrid.cpp | 3 +- modules/base/rendering/renderabledisc.cpp | 1 + modules/base/rendering/renderablenodeline.cpp | 1 + modules/base/rendering/renderableplane.cpp | 2 + modules/base/rendering/renderablesphere.cpp | 1 + modules/base/rendering/renderabletrail.cpp | 1 + .../base/translation/statictranslation.cpp | 1 + .../rendering/renderabledebugplane.cpp | 5 +- .../rendering/renderablepoints.cpp | 1 + modules/globebrowsing/src/ringscomponent.cpp | 31 ++++++------ src/properties/property.cpp | 47 ++++++++++--------- 13 files changed, 60 insertions(+), 49 deletions(-) diff --git a/data/assets/util/webgui.asset b/data/assets/util/webgui.asset index 61d64e4c51..05b5cb9b83 100644 --- a/data/assets/util/webgui.asset +++ b/data/assets/util/webgui.asset @@ -3,7 +3,7 @@ asset.require('./static_server') local guiCustomization = asset.require('customization/gui') -- Select which commit hashes to use for the frontend and backend -local frontendHash = "02d6b86e40ea4db4bd8755bf7ade22fd9d839785" +local frontendHash = "391f8d3ed74e598a0e8a1b16016324d8f747e18d" local dataProvider = "data.openspaceproject.com/files/webgui" local frontend = asset.syncedResource({ diff --git a/include/openspace/properties/property.h b/include/openspace/properties/property.h index b0257ef484..b900cf8335 100644 --- a/include/openspace/properties/property.h +++ b/include/openspace/properties/property.h @@ -381,22 +381,21 @@ public: /** * Default view options that can be used in the Property::setViewOption method. The - * values are: Property::ViewOptions::Color = \c color, - * Property::ViewOptions::LightPosition = \c lightPosition + * values are: Property::ViewOptions::Color = \c Color, + * Property::ViewOptions::Logarithmic = \c Logarithmic */ struct ViewOptions { static const char* Color; - static const char* LightPosition; + static const char* Logarithmic; }; /** * This method allows the developer to give hints to the GUI about different * representations for the GUI. The same Property (for example Vec4Property) can be * used in different ways, each requiring a different input method. These values are - * stored in the metaData object using the views. prefix in front of the - * option parameter. See Property::ViewOptions for a default list of - * possible options. As these are only hints, the GUI is free to ignore any suggestion - * by the developer. + * stored in the metaData object under ViewOptions. + * See Property::ViewOptions for a default list of possible options. As these are + * only hints, the GUI is free to ignore any suggestion by the developer. * \param option The view option that should be modified * \param value Determines if the view option should be active (true) or * deactivated (false) diff --git a/modules/base/rendering/grids/renderablegrid.cpp b/modules/base/rendering/grids/renderablegrid.cpp index 1f364157f1..c79f5785dc 100644 --- a/modules/base/rendering/grids/renderablegrid.cpp +++ b/modules/base/rendering/grids/renderablegrid.cpp @@ -92,7 +92,7 @@ RenderableGrid::RenderableGrid(const ghoul::Dictionary& dictionary) , _color(ColorInfo, glm::vec3(0.5f), glm::vec3(0.f), glm::vec3(1.f)) , _segments(SegmentsInfo, glm::uvec2(10), glm::uvec2(1), glm::uvec2(200)) , _lineWidth(LineWidthInfo, 0.5f, 1.f, 20.f) - , _size(SizeInfo, glm::vec2(1e20f), glm::vec2(1.f), glm::vec2(1e35f)) + , _size(SizeInfo, glm::vec2(1e10f), glm::vec2(1.f), glm::vec2(1e20f)) { const Parameters p = codegen::bake(dictionary); @@ -110,6 +110,7 @@ RenderableGrid::RenderableGrid(const ghoul::Dictionary& dictionary) _lineWidth = p.lineWidth.value_or(_lineWidth); addProperty(_lineWidth); + _size.setViewOption(properties::Property::ViewOptions::Logarithmic); _size = p.size.value_or(_size); _size.onChange([&]() { _gridIsDirty = true; }); addProperty(_size); diff --git a/modules/base/rendering/renderabledisc.cpp b/modules/base/rendering/renderabledisc.cpp index d15ed1deb9..ca17160453 100644 --- a/modules/base/rendering/renderabledisc.cpp +++ b/modules/base/rendering/renderabledisc.cpp @@ -99,6 +99,7 @@ RenderableDisc::RenderableDisc(const ghoul::Dictionary& dictionary) _texturePath.onChange([&]() { _texture->loadFromFile(_texturePath); }); addProperty(_texturePath); + _size.setViewOption(properties::Property::ViewOptions::Logarithmic); _size = p.size.value_or(_size); setBoundingSphere(_size); _size.onChange([&]() { _planeIsDirty = true; }); diff --git a/modules/base/rendering/renderablenodeline.cpp b/modules/base/rendering/renderablenodeline.cpp index b8eaed01d6..0c6de14407 100644 --- a/modules/base/rendering/renderablenodeline.cpp +++ b/modules/base/rendering/renderablenodeline.cpp @@ -127,6 +127,7 @@ RenderableNodeLine::RenderableNodeLine(const ghoul::Dictionary& dictionary) addProperty(_end); _lineColor = p.color.value_or(_lineColor); + _lineColor.setViewOption(properties::Property::ViewOptions::Color); addProperty(_lineColor); _lineWidth = p.lineWidth.value_or(_lineWidth); diff --git a/modules/base/rendering/renderableplane.cpp b/modules/base/rendering/renderableplane.cpp index 0e10ee8f2a..a029a4f576 100644 --- a/modules/base/rendering/renderableplane.cpp +++ b/modules/base/rendering/renderableplane.cpp @@ -153,9 +153,11 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary) } _multiplyColor = p.multiplyColor.value_or(_multiplyColor); + _multiplyColor.setViewOption(properties::Property::ViewOptions::Color); addProperty(_billboard); + _size.setViewOption(properties::Property::ViewOptions::Logarithmic); addProperty(_size); _size.onChange([this](){ _planeIsDirty = true; }); diff --git a/modules/base/rendering/renderablesphere.cpp b/modules/base/rendering/renderablesphere.cpp index dc9248f3f1..0dae86d42c 100644 --- a/modules/base/rendering/renderablesphere.cpp +++ b/modules/base/rendering/renderablesphere.cpp @@ -215,6 +215,7 @@ RenderableSphere::RenderableSphere(const ghoul::Dictionary& dictionary) } addProperty(_orientation); + _size.setViewOption(properties::Property::ViewOptions::Logarithmic); _size.onChange([this]() { setBoundingSphere(_size); _sphereIsDirty = true; diff --git a/modules/base/rendering/renderabletrail.cpp b/modules/base/rendering/renderabletrail.cpp index daab021b50..889772bc58 100644 --- a/modules/base/rendering/renderabletrail.cpp +++ b/modules/base/rendering/renderabletrail.cpp @@ -204,6 +204,7 @@ RenderableTrail::Appearance::Appearance() { RenderingModeLinesPoints, "Lines+Points" } }); + lineColor.setViewOption(properties::Property::ViewOptions::Color); addProperty(lineColor); addProperty(useLineFade); addProperty(lineFade); diff --git a/modules/base/translation/statictranslation.cpp b/modules/base/translation/statictranslation.cpp index 7cdaa8cee6..b4987cccf3 100644 --- a/modules/base/translation/statictranslation.cpp +++ b/modules/base/translation/statictranslation.cpp @@ -58,6 +58,7 @@ StaticTranslation::StaticTranslation() glm::dvec3(std::numeric_limits::max()) ) { + _position.setViewOption(properties::Property::ViewOptions::Logarithmic); addProperty(_position); _position.onChange([this]() { diff --git a/modules/debugging/rendering/renderabledebugplane.cpp b/modules/debugging/rendering/renderabledebugplane.cpp index 723458ed8a..335e48b3b7 100644 --- a/modules/debugging/rendering/renderabledebugplane.cpp +++ b/modules/debugging/rendering/renderabledebugplane.cpp @@ -116,12 +116,13 @@ RenderableDebugPlane::RenderableDebugPlane(const ghoul::Dictionary& dictionary) _texture = p.texture.value_or(_texture); addProperty(_texture); - + + _size.setViewOption(properties::Property::ViewOptions::Logarithmic); _size.onChange([this](){ _planeIsDirty = true; }); _size = p.size.value_or(_size); setBoundingSphere(_size); addProperty(_size); - + _billboard = p.billboard.value_or(_billboard); addProperty(_billboard); diff --git a/modules/digitaluniverse/rendering/renderablepoints.cpp b/modules/digitaluniverse/rendering/renderablepoints.cpp index 906f6f84f4..96c5420b91 100644 --- a/modules/digitaluniverse/rendering/renderablepoints.cpp +++ b/modules/digitaluniverse/rendering/renderablepoints.cpp @@ -170,6 +170,7 @@ RenderablePoints::RenderablePoints(const ghoul::Dictionary& dictionary) } _pointColor = p.color; + _pointColor.setViewOption(properties::Property::ViewOptions::Color); addProperty(_pointColor); if (p.texture.has_value()) { diff --git a/modules/globebrowsing/src/ringscomponent.cpp b/modules/globebrowsing/src/ringscomponent.cpp index 68c44f6677..e59917235b 100644 --- a/modules/globebrowsing/src/ringscomponent.cpp +++ b/modules/globebrowsing/src/ringscomponent.cpp @@ -56,14 +56,14 @@ namespace { constexpr const std::array UniformNames = { "modelViewProjectionMatrix", "textureOffset", "colorFilterValue", "_nightFactor", - "sunPosition", "ringTexture", "shadowMatrix", "shadowMapTexture", + "sunPosition", "ringTexture", "shadowMatrix", "shadowMapTexture", "zFightingPercentage" }; constexpr const std::array UniformNamesAdvancedRings = { "modelViewProjectionMatrix", "textureOffset", "colorFilterValue", "_nightFactor", - "sunPosition", "sunPositionObj", "camPositionObj", "ringTextureFwrd", - "ringTextureBckwrd", "ringTextureUnlit", "ringTextureColor", + "sunPosition", "sunPositionObj", "camPositionObj", "ringTextureFwrd", + "ringTextureBckwrd", "ringTextureUnlit", "ringTextureColor", "ringTextureTransparency", "shadowMatrix", "shadowMapTexture", "zFightingPercentage" }; @@ -251,6 +251,7 @@ void RingsComponent::initialize() { addProperty(_enabled); + _size.setViewOption(properties::Property::ViewOptions::Logarithmic); _size = p.size.value_or(_size); _size.onChange([&]() { _planeIsDirty = true; }); addProperty(_size); @@ -262,7 +263,7 @@ void RingsComponent::initialize() { addProperty(_texturePath); _textureFile->setCallback([&](const File&) { _textureIsDirty = true; }); } - + if (p.textureFwrd.has_value()) { _textureFwrdPath = absPath(p.textureFwrd->string()); _textureFileForwards = std::make_unique(_textureFwrdPath); @@ -423,11 +424,11 @@ void RingsComponent::draw(const RenderData& data, ); _shader->setUniform( - _uniformCacheAdvancedRings.sunPositionObj, + _uniformCacheAdvancedRings.sunPositionObj, sunPositionObjectSpace ); _shader->setUniform( - _uniformCacheAdvancedRings.zFightingPercentage, + _uniformCacheAdvancedRings.zFightingPercentage, _zFightingPercentage ); _shader->setUniform( @@ -438,21 +439,21 @@ void RingsComponent::draw(const RenderData& data, ringTextureFwrdUnit.activate(); _textureForwards->bind(); _shader->setUniform( - _uniformCacheAdvancedRings.ringTextureFwrd, + _uniformCacheAdvancedRings.ringTextureFwrd, ringTextureFwrdUnit ); ringTextureBckwrdUnit.activate(); _textureBackwards->bind(); _shader->setUniform( - _uniformCacheAdvancedRings.ringTextureBckwrd, + _uniformCacheAdvancedRings.ringTextureBckwrd, ringTextureBckwrdUnit ); ringTextureUnlitUnit.activate(); _textureUnlit->bind(); _shader->setUniform( - _uniformCacheAdvancedRings.ringTextureUnlit, + _uniformCacheAdvancedRings.ringTextureUnlit, ringTextureUnlitUnit ); @@ -488,7 +489,7 @@ void RingsComponent::draw(const RenderData& data, ); _shader->setUniform( - _uniformCacheAdvancedRings.camPositionObj, + _uniformCacheAdvancedRings.camPositionObj, _camPositionObjectSpace ); @@ -513,7 +514,7 @@ void RingsComponent::draw(const RenderData& data, _shader->setUniform(_uniformCache.sunPosition, _sunPosition); _shader->setUniform(_uniformCache.zFightingPercentage, _zFightingPercentage); _shader->setUniform( - _uniformCache.modelViewProjectionMatrix, + _uniformCache.modelViewProjectionMatrix, modelViewProjectionTransform ); @@ -533,7 +534,7 @@ void RingsComponent::draw(const RenderData& data, shadowMapUnit.activate(); glBindTexture(GL_TEXTURE_2D, shadowData.shadowDepthTexture); _shader->setUniform(_uniformCache.shadowMapTexture, shadowMapUnit); - } + } glEnable(GL_DEPTH_TEST); glEnablei(GL_BLEND, 0); @@ -831,7 +832,7 @@ void RingsComponent::compileShadowShader() { // Uses multiple textures for the Rings // See https://bjj.mmedia.is/data/s_rings/index.html for theory behind it - if (_isAdvancedTextureEnabled) { + if (_isAdvancedTextureEnabled) { _shader = global::renderEngine->buildRenderProgram( "AdvancedRingsProgram", absPath("${MODULE_GLOBEBROWSING}/shaders/advanced_rings_vs.glsl"), @@ -840,8 +841,8 @@ void RingsComponent::compileShadowShader() { ); ghoul::opengl::updateUniformLocations( - *_shader, - _uniformCacheAdvancedRings, + *_shader, + _uniformCacheAdvancedRings, UniformNamesAdvancedRings ); } diff --git a/src/properties/property.cpp b/src/properties/property.cpp index cdfed64adc..5985da3dc6 100644 --- a/src/properties/property.cpp +++ b/src/properties/property.cpp @@ -23,21 +23,17 @@ ****************************************************************************************/ #include - #include - -#include - -#include - #include +#include +#include +#include namespace { constexpr const char* MetaDataKeyGroup = "Group"; - constexpr const char* MetaDataKeyVisibility = "Visibility"; constexpr const char* MetaDataKeyReadOnly = "isReadOnly"; - - constexpr const char* _metaDataKeyViewPrefix = "view"; + constexpr const char* MetaDataKeyViewOptions = "ViewOptions"; + constexpr const char* MetaDataKeyVisibility = "Visibility"; } // namespace @@ -46,8 +42,8 @@ namespace openspace::properties { Property::OnChangeHandle Property::OnChangeHandleAll = std::numeric_limits::max(); -const char* Property::ViewOptions::Color = "color"; -const char* Property::ViewOptions::LightPosition = "lightPosition"; +const char* Property::ViewOptions::Color = "Color"; +const char* Property::ViewOptions::Logarithmic = "Logarithmic"; const char* Property::IdentifierKey = "Identifier"; const char* Property::NameKey = "Name"; @@ -209,14 +205,14 @@ void Property::setReadOnly(bool state) { void Property::setViewOption(std::string option, bool value) { ghoul::Dictionary d; d.setValue(option, value); - _metaData.setValue(_metaDataKeyViewPrefix, d); + _metaData.setValue(MetaDataKeyViewOptions, d); } bool Property::viewOption(const std::string& option, bool defaultValue) const { - if (!_metaData.hasValue(_metaDataKeyViewPrefix)) { + if (!_metaData.hasValue(MetaDataKeyViewOptions)) { return defaultValue; } - ghoul::Dictionary d = _metaData.value(_metaDataKeyViewPrefix); + ghoul::Dictionary d = _metaData.value(MetaDataKeyViewOptions); if (d.hasKey(option)) { return d.value(option); } @@ -357,18 +353,23 @@ std::string Property::generateMetaDataJsonDescription() const { if (_metaData.hasValue(MetaDataKeyReadOnly)) { isReadOnly = _metaData.value(MetaDataKeyReadOnly); } + std::string isReadOnlyString = (isReadOnly ? "true" : "false"); - std::string gIdent = groupIdentifier(); - std::string gIdentSan = sanitizeString(gIdent); + std::string groupId = groupIdentifier(); + std::string sanitizedGroupId = sanitizeString(groupId); + + std::string viewOptions = "{}"; + if (_metaData.hasValue(MetaDataKeyViewOptions)) { + viewOptions = ghoul::formatJson( + _metaData.value(MetaDataKeyViewOptions) + ); + } std::string result = "{ "; - result += - "\"" + std::string(MetaDataKeyGroup) + "\": \"" + gIdentSan + "\", "; - result += - "\"" + std::string(MetaDataKeyVisibility) + "\": \"" + vis + "\", "; - result += - "\"" + std::string(MetaDataKeyReadOnly) + "\": " + - (isReadOnly ? "true" : "false"); + result += fmt::format("\"{}\": \"{}\",", MetaDataKeyGroup, sanitizedGroupId); + result += fmt::format("\"{}\": \"{}\",", MetaDataKeyVisibility, vis); + result += fmt::format("\"{}\": {},", MetaDataKeyReadOnly, isReadOnlyString); + result += fmt::format("\"{}\": {}", MetaDataKeyViewOptions, viewOptions); result += " }"; return result; }