From 3ab97231bb92d2169be05c174bb1b5572a1083b8 Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 2 Aug 2022 09:38:30 +0200 Subject: [PATCH 01/79] Add selection property to RenderableDUMeshes --- .../rendering/renderabledumeshes.cpp | 100 +++++++++++++++++- .../rendering/renderabledumeshes.h | 15 ++- 2 files changed, 110 insertions(+), 5 deletions(-) diff --git a/modules/digitaluniverse/rendering/renderabledumeshes.cpp b/modules/digitaluniverse/rendering/renderabledumeshes.cpp index 1ac9ebdf62..0d40fa6720 100644 --- a/modules/digitaluniverse/rendering/renderabledumeshes.cpp +++ b/modules/digitaluniverse/rendering/renderabledumeshes.cpp @@ -121,6 +121,12 @@ namespace { "Debug option for rendering of billboards and texts" }; + constexpr openspace::properties::Property::PropertyInfo MeshSelectionInfo = { + "MeshSelection", + "Mesh Selection", + "Property to select one or more of the meshes to be rendered." + }; + struct [[codegen::Dictionary(RenderableDUMeshes)]] Parameters { // The path to the SPECK file that contains information about the astronomical // object being rendered @@ -160,6 +166,9 @@ namespace { // [[codegen::verbatim(MeshColorInfo.description)]] std::optional> meshColor; + + // [[codegen::verbatim(MeshSelectionInfo.description)]] + std::optional> selectedMeshes; }; #include "renderabledumeshes_codegen.cpp" } // namespace @@ -185,6 +194,7 @@ RenderableDUMeshes::RenderableDUMeshes(const ghoul::Dictionary& dictionary) ) , _lineWidth(LineWidthInfo, 2.f, 1.f, 16.f) , _renderOption(RenderOptionInfo, properties::OptionProperty::DisplayType::Dropdown) + , _selectedMeshes(MeshSelectionInfo) { const Parameters p = codegen::bake(dictionary); @@ -248,6 +258,66 @@ RenderableDUMeshes::RenderableDUMeshes(const ghoul::Dictionary& dictionary) _meshColorMap.insert({ static_cast(i) + 1, ops[i] }); } } + + _selectedMeshes.onChange([this]() { selectionPropertyHasChanged(); }); + addProperty(_selectedMeshes); + + if (p.selectedMeshes.has_value()) { + const std::vector options = _selectedMeshes.options(); + std::set selectedNames; + + for (const std::string& s : *p.selectedMeshes) { + const auto it = std::find(options.begin(), options.end(), s); + if (it == options.end()) { + // The user has specified a mesh name that doesn't exist + LWARNING(fmt::format("Option '{}' not found in list of meshes", s)); + } + else { + selectedNames.insert(s); + } + } + _selectedMeshes = selectedNames; + } +} + +void RenderableDUMeshes::fillSelectionProperty() { + for (const std::pair& pair : _renderingMeshesMap) { + if (pair.second.name.empty()) { + continue; + } + + auto it = std::find( + _selectedMeshes.options().begin(), + _selectedMeshes.options().end(), + pair.second.name + ); + if (it != _selectedMeshes.options().end()) { + continue; + } + _selectedMeshes.addOption(pair.second.name); + } + + if (_selectedMeshes.options().empty()) { + _selectedMeshes.setVisibility(properties::Property::Visibility::Developer); + } + else { + _selectedMeshes.setVisibility(properties::Property::Visibility::NoviceUser); + } +} + +void RenderableDUMeshes::selectionPropertyHasChanged() { + // If no values are selected (the default), we want to show all constellations + if (!_selectedMeshes.hasSelected()) { + for (std::pair& pair : _renderingMeshesMap) { + pair.second.isEnabled = true; + } + } + else { + // Enable all constellations that are selected + for (std::pair& pair : _renderingMeshesMap) { + pair.second.isEnabled = _selectedMeshes.isSelected(pair.second.name); + } + } } bool RenderableDUMeshes::isReady() const { @@ -322,6 +392,10 @@ void RenderableDUMeshes::renderMeshes(const RenderData&, _program->setUniform(_uniformCache.alphaValue, opacity()); for (const std::pair& pair : _renderingMeshesMap) { + if (!pair.second.isEnabled) { + continue; + } + _program->setUniform(_uniformCache.color, _meshColorMap[pair.second.colorIndex]); for (size_t i = 0; i < pair.second.vaoArray.size(); ++i) { glBindVertexArray(pair.second.vaoArray[i]); @@ -535,9 +609,26 @@ bool RenderableDUMeshes::readSpeckFile() { } while (dummy != "{"); std::getline(file, line); - std::stringstream dim(line); - dim >> mesh.numU; // numU - dim >> mesh.numV; // numV + std::stringstream dimOrName(line); + std::string dummyU, dummyV; + + // Try to read name of mesh if it exist + dimOrName >> dummyU; // numU or "name" + dimOrName >> dummyV; // numV or the name of the mesh + + if (dummyU == "name") { + mesh.name = dummyV; + + // Dimensions are specified in the next line as usual + std::getline(file, line); + std::stringstream dim(line); + dim >> mesh.numU; // numU + dim >> mesh.numV; // numV + } + else { + mesh.numU = stoi(dummyU); + mesh.numV = stoi(dummyV); + } // We can now read the vertices data: for (int l = 0; l < mesh.numU * mesh.numV; ++l) { @@ -603,6 +694,7 @@ bool RenderableDUMeshes::readSpeckFile() { } } + fillSelectionProperty(); setBoundingSphere(maxRadius); return true; @@ -636,7 +728,7 @@ void RenderableDUMeshes::createMeshes() { // in_position glEnableVertexAttribArray(0); // (2022-03-23, emmbr) This code was actually never used. We only read three - // values per line and di not handle any texture cooridnates, even if there + // values per line and did not handle any texture cooridnates, even if there // would have been some in the file //// U and V may not be given by the user //if (p.second.vertices.size() / (p.second.numU * p.second.numV) > 3) { diff --git a/modules/digitaluniverse/rendering/renderabledumeshes.h b/modules/digitaluniverse/rendering/renderabledumeshes.h index 5c6222abeb..3d6f991711 100644 --- a/modules/digitaluniverse/rendering/renderabledumeshes.h +++ b/modules/digitaluniverse/rendering/renderabledumeshes.h @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -84,13 +85,15 @@ private: // "If you wish to draw a line between points, then numU will be 1 while // numV will equal the number of points to connect. // If you want a square, 4000×4000 grid with lines every 200 units, - // then numU numU will both equal 21 + // then numU numV will both equal 21 int numU; int numV; MeshType style; std::vector vaoArray; std::vector vboArray; std::vector vertices; + bool isEnabled = true; + std::string name; }; void createMeshes(); @@ -102,6 +105,15 @@ private: bool loadData(); bool readSpeckFile(); + /// Fills the _selectedMeshes property with all available meshes + void fillSelectionProperty(); + + /** + * Callback method that gets triggered when _selectedMeshes + * changes. + */ + void selectionPropertyHasChanged(); + bool _hasSpeckFile = false; bool _dataIsDirty = true; bool _textColorIsDirty = true; @@ -114,6 +126,7 @@ private: properties::BoolProperty _drawLabels; properties::IVec2Property _textMinMaxSize; properties::FloatProperty _lineWidth; + properties::SelectionProperty _selectedMeshes; // DEBUG: properties::OptionProperty _renderOption; From 4df76934807237ed27125ae15806002ef5c98555 Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 2 Aug 2022 10:59:26 +0200 Subject: [PATCH 02/79] Make DUMeshes selection property visible even if list is empty --- modules/digitaluniverse/rendering/renderabledumeshes.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/modules/digitaluniverse/rendering/renderabledumeshes.cpp b/modules/digitaluniverse/rendering/renderabledumeshes.cpp index 0d40fa6720..25ac5be0c2 100644 --- a/modules/digitaluniverse/rendering/renderabledumeshes.cpp +++ b/modules/digitaluniverse/rendering/renderabledumeshes.cpp @@ -296,13 +296,6 @@ void RenderableDUMeshes::fillSelectionProperty() { } _selectedMeshes.addOption(pair.second.name); } - - if (_selectedMeshes.options().empty()) { - _selectedMeshes.setVisibility(properties::Property::Visibility::Developer); - } - else { - _selectedMeshes.setVisibility(properties::Property::Visibility::NoviceUser); - } } void RenderableDUMeshes::selectionPropertyHasChanged() { From 9470faddbb21f1fcb5ae35567e0cce6dc40ca149 Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 2 Aug 2022 11:44:48 +0200 Subject: [PATCH 03/79] Change GUI name for the selection property --- modules/digitaluniverse/rendering/renderabledumeshes.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/digitaluniverse/rendering/renderabledumeshes.cpp b/modules/digitaluniverse/rendering/renderabledumeshes.cpp index 25ac5be0c2..2227ea5b6d 100644 --- a/modules/digitaluniverse/rendering/renderabledumeshes.cpp +++ b/modules/digitaluniverse/rendering/renderabledumeshes.cpp @@ -123,8 +123,8 @@ namespace { constexpr openspace::properties::Property::PropertyInfo MeshSelectionInfo = { "MeshSelection", - "Mesh Selection", - "Property to select one or more of the meshes to be rendered." + "Selection", + "Selected objects" }; struct [[codegen::Dictionary(RenderableDUMeshes)]] Parameters { From 39b8914917399cb67cc0db5a8422d848329b287f Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 2 Aug 2022 13:34:31 +0200 Subject: [PATCH 04/79] Fix bug when constellations have several words in its name --- modules/digitaluniverse/rendering/renderabledumeshes.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/digitaluniverse/rendering/renderabledumeshes.cpp b/modules/digitaluniverse/rendering/renderabledumeshes.cpp index 2227ea5b6d..b2763d8045 100644 --- a/modules/digitaluniverse/rendering/renderabledumeshes.cpp +++ b/modules/digitaluniverse/rendering/renderabledumeshes.cpp @@ -606,11 +606,15 @@ bool RenderableDUMeshes::readSpeckFile() { std::string dummyU, dummyV; // Try to read name of mesh if it exist - dimOrName >> dummyU; // numU or "name" - dimOrName >> dummyV; // numV or the name of the mesh + dimOrName >> dummyU; // numU or "name" + std::getline(dimOrName, dummyV); // numV or the name of the mesh if (dummyU == "name") { mesh.name = dummyV; + // Trim leading whitespace + if (!mesh.name.empty() && mesh.name[0] == ' ') { + mesh.name = mesh.name.substr(1); + } // Dimensions are specified in the next line as usual std::getline(file, line); From 9c39874efcc8bb48f0a8ceed0cc85bc1cef171d2 Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 2 Aug 2022 14:05:39 +0200 Subject: [PATCH 05/79] Load spaeck file in initialize instead of initialiseGL --- .../rendering/renderabledumeshes.cpp | 48 ++++++++++--------- .../rendering/renderabledumeshes.h | 2 + 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/modules/digitaluniverse/rendering/renderabledumeshes.cpp b/modules/digitaluniverse/rendering/renderabledumeshes.cpp index b2763d8045..6ef7bd79d8 100644 --- a/modules/digitaluniverse/rendering/renderabledumeshes.cpp +++ b/modules/digitaluniverse/rendering/renderabledumeshes.cpp @@ -262,22 +262,7 @@ RenderableDUMeshes::RenderableDUMeshes(const ghoul::Dictionary& dictionary) _selectedMeshes.onChange([this]() { selectionPropertyHasChanged(); }); addProperty(_selectedMeshes); - if (p.selectedMeshes.has_value()) { - const std::vector options = _selectedMeshes.options(); - std::set selectedNames; - - for (const std::string& s : *p.selectedMeshes) { - const auto it = std::find(options.begin(), options.end(), s); - if (it == options.end()) { - // The user has specified a mesh name that doesn't exist - LWARNING(fmt::format("Option '{}' not found in list of meshes", s)); - } - else { - selectedNames.insert(s); - } - } - _selectedMeshes = selectedNames; - } + _assetSelectedMeshes = p.selectedMeshes.value_or(_assetSelectedMeshes); } void RenderableDUMeshes::fillSelectionProperty() { @@ -318,6 +303,30 @@ bool RenderableDUMeshes::isReady() const { (!_renderingMeshesMap.empty() || (!_labelset.entries.empty())); } +void RenderableDUMeshes::initialize() { + bool success = loadData(); + if (!success) { + throw ghoul::RuntimeError("Error loading data"); + } + + fillSelectionProperty(); + + const std::vector options = _selectedMeshes.options(); + std::set selectedNames; + + for (const std::string& s : _assetSelectedMeshes) { + const auto it = std::find(options.begin(), options.end(), s); + if (it == options.end()) { + // The user has specified a mesh name that doesn't exist + LWARNING(fmt::format("Option '{}' not found in list of meshes", s)); + } + else { + selectedNames.insert(s); + } + } + _selectedMeshes = selectedNames; +} + void RenderableDUMeshes::initializeGL() { _program = DigitalUniverseModule::ProgramObjectManager.request( "RenderableDUMeshes", @@ -332,11 +341,6 @@ void RenderableDUMeshes::initializeGL() { ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); - bool success = loadData(); - if (!success) { - throw ghoul::RuntimeError("Error loading data"); - } - createMeshes(); if (_hasLabel) { @@ -690,8 +694,6 @@ bool RenderableDUMeshes::readSpeckFile() { } } } - - fillSelectionProperty(); setBoundingSphere(maxRadius); return true; diff --git a/modules/digitaluniverse/rendering/renderabledumeshes.h b/modules/digitaluniverse/rendering/renderabledumeshes.h index 3d6f991711..4e331daab5 100644 --- a/modules/digitaluniverse/rendering/renderabledumeshes.h +++ b/modules/digitaluniverse/rendering/renderabledumeshes.h @@ -56,6 +56,7 @@ public: explicit RenderableDUMeshes(const ghoul::Dictionary& dictionary); ~RenderableDUMeshes() override = default; + void initialize() override; void initializeGL() override; void deinitializeGL() override; @@ -118,6 +119,7 @@ private: bool _dataIsDirty = true; bool _textColorIsDirty = true; bool _hasLabel = false; + std::vector _assetSelectedMeshes; properties::Vec3Property _textColor; properties::FloatProperty _textOpacity; From e98e9fe4a3af50a6db241420012dd2caa556855a Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 5 Aug 2022 11:05:57 +0200 Subject: [PATCH 06/79] WIP initiali version of new constellation classes --- .../digitaluniverse/constellationbounds.asset | 2 +- .../digitaluniverse/constellations.asset | 3 +- .../rendering/renderabledumeshes.cpp | 6 +- modules/space/CMakeLists.txt | 6 + .../rendering/renderableconstellation.cpp | 379 ++++++++++++ .../space/rendering/renderableconstellation.h | 121 ++++ .../renderableconstellationbounds.cpp | 140 +---- .../rendering/renderableconstellationbounds.h | 30 +- .../renderableconstellationlines.cpp | 581 ++++++++++++++++++ .../rendering/renderableconstellationlines.h | 137 +++++ .../space/shaders/constellationlines_fs.glsl | 49 ++ .../space/shaders/constellationlines_vs.glsl | 47 ++ modules/space/spacemodule.cpp | 5 + modules/space/speckloader.cpp | 18 +- modules/space/speckloader.h | 1 + 15 files changed, 1373 insertions(+), 152 deletions(-) create mode 100644 modules/space/rendering/renderableconstellation.cpp create mode 100644 modules/space/rendering/renderableconstellation.h create mode 100644 modules/space/rendering/renderableconstellationlines.cpp create mode 100644 modules/space/rendering/renderableconstellationlines.h create mode 100644 modules/space/shaders/constellationlines_fs.glsl create mode 100644 modules/space/shaders/constellationlines_vs.glsl diff --git a/data/assets/scene/digitaluniverse/constellationbounds.asset b/data/assets/scene/digitaluniverse/constellationbounds.asset index c53f0bead2..273fad59da 100644 --- a/data/assets/scene/digitaluniverse/constellationbounds.asset +++ b/data/assets/scene/digitaluniverse/constellationbounds.asset @@ -16,7 +16,7 @@ local object = { Type = "RenderableConstellationBounds", Enabled = false, File = data .. "bound_20.dat", - ConstellationFile = data .. "constellations.dat" + ConstellationNamesFile = data .. "constellations.dat" -- ConstellationSelection = zodiacs }, Transform = { diff --git a/data/assets/scene/digitaluniverse/constellations.asset b/data/assets/scene/digitaluniverse/constellations.asset index 9bd8d72f18..3c0bcafa09 100644 --- a/data/assets/scene/digitaluniverse/constellations.asset +++ b/data/assets/scene/digitaluniverse/constellations.asset @@ -29,11 +29,12 @@ local constellationsExtragalactic = { local constellations = { Identifier = "Constellations", Renderable = { - Type = "RenderableDUMeshes", + Type = "RenderableConstellationLines", Enabled = false, Opacity = 0.3, File = speck .. "constellations.speck", LabelFile = speck .. "constellations.label", + ConstellationNamesFile = "C:/Users/malej60/Documents/Sync/http/digitaluniverse_constellationbounds_data/1/constellations.dat", TextColor = { 0.8, 0.8, 0.8 }, TextOpacity = 0.3, TextSize = 14.5, diff --git a/modules/digitaluniverse/rendering/renderabledumeshes.cpp b/modules/digitaluniverse/rendering/renderabledumeshes.cpp index 6ef7bd79d8..01dc22f4ca 100644 --- a/modules/digitaluniverse/rendering/renderabledumeshes.cpp +++ b/modules/digitaluniverse/rendering/renderabledumeshes.cpp @@ -311,6 +311,10 @@ void RenderableDUMeshes::initialize() { fillSelectionProperty(); + if (_assetSelectedMeshes.empty()) { + return; + } + const std::vector options = _selectedMeshes.options(); std::set selectedNames; @@ -613,7 +617,7 @@ bool RenderableDUMeshes::readSpeckFile() { dimOrName >> dummyU; // numU or "name" std::getline(dimOrName, dummyV); // numV or the name of the mesh - if (dummyU == "name") { + if (dummyU == "id") { mesh.name = dummyV; // Trim leading whitespace if (!mesh.name.empty() && mesh.name[0] == ' ') { diff --git a/modules/space/CMakeLists.txt b/modules/space/CMakeLists.txt index dc8f0ddfd2..cc294fce94 100644 --- a/modules/space/CMakeLists.txt +++ b/modules/space/CMakeLists.txt @@ -27,7 +27,9 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake) set(HEADER_FILES horizonsfile.h speckloader.h + rendering/renderableconstellation.h rendering/renderableconstellationbounds.h + rendering/renderableconstellationlines.h rendering/renderablefluxnodes.h rendering/renderablehabitablezone.h rendering/renderablerings.h @@ -48,7 +50,9 @@ set(SOURCE_FILES horizonsfile.cpp spacemodule_lua.inl speckloader.cpp + rendering/renderableconstellation.cpp rendering/renderableconstellationbounds.cpp + rendering/renderableconstellationlines.cpp rendering/renderablefluxnodes.cpp rendering/renderablehabitablezone.cpp rendering/renderablerings.cpp @@ -68,6 +72,8 @@ source_group("Source Files" FILES ${SOURCE_FILES}) set(SHADER_FILES shaders/constellationbounds_fs.glsl shaders/constellationbounds_vs.glsl + shaders/constellationlines_fs.glsl + shaders/constellationlines_vs.glsl shaders/debrisViz_fs.glsl shaders/debrisViz_vs.glsl shaders/fluxnodes_fs.glsl diff --git a/modules/space/rendering/renderableconstellation.cpp b/modules/space/rendering/renderableconstellation.cpp new file mode 100644 index 0000000000..08f8d2d184 --- /dev/null +++ b/modules/space/rendering/renderableconstellation.cpp @@ -0,0 +1,379 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2022 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SpiceUsr.h" + +namespace { + constexpr int RenderOptionViewDirection = 0; + constexpr int RenderOptionPositionNormal = 1; + + constexpr openspace::properties::Property::PropertyInfo TextColorInfo = { + "TextColor", + "Text Color", + "The text color for the astronomical object" + }; + + constexpr openspace::properties::Property::PropertyInfo TextOpacityInfo = { + "TextOpacity", + "Text Opacity", + "Determines the transparency of the text label, where 1 is completely opaque " + "and 0 fully transparent" + }; + + constexpr openspace::properties::Property::PropertyInfo TextSizeInfo = { + "TextSize", + "Text Size", + "The text size for the astronomical object labels" + }; + + constexpr openspace::properties::Property::PropertyInfo LabelFileInfo = { + "LabelFile", + "Label File", + "The path to the label file that contains information about the astronomical " + "objects being rendered" + }; + + constexpr openspace::properties::Property::PropertyInfo LabelMinMaxSizeInfo = { + "TextMinMaxSize", + "Text Min/Max Size", + "The minimum and maximum size (in pixels) of the text for the labels for the " + "astronomical objects being rendered" + }; + + constexpr openspace::properties::Property::PropertyInfo ConstellationInfo = { + "ConstellationFile", + "Constellation File Path", + "Specifies the file that contains the mapping between constellation " + "abbreviations and full name of the constellation. If this value is empty, the " + "abbreviations are used as the full names" + }; + + constexpr openspace::properties::Property::PropertyInfo LineWidthInfo = { + "LineWidth", + "Line Width", + "The line width of the constellation " + }; + + constexpr openspace::properties::Property::PropertyInfo DrawLabelInfo = { + "DrawLabels", + "Draw Labels", + "Determines whether labels should be drawn or hidden" + }; + + constexpr openspace::properties::Property::PropertyInfo RenderOptionInfo = { + "RenderOption", + "Render Option", + "Debug option for rendering of billboards and texts" + }; + + constexpr openspace::properties::Property::PropertyInfo SelectionInfo = { + "ConstellationSelection", + "Constellation Selection", + "The constellations that are selected are displayed on the celestial sphere" + }; + + struct [[codegen::Dictionary(RenderableConstellation)]] Parameters { + // [[codegen::verbatim(DrawLabelInfo.description)]] + std::optional drawLabels; + + // [[codegen::verbatim(ConstellationInfo.description)]] + std::string constellationNamesFile; + + // [[codegen::verbatim(TextColorInfo.description)]] + std::optional textColor [[codegen::color()]]; + + // [[codegen::verbatim(TextOpacityInfo.description)]] + std::optional textOpacity; + + // [[codegen::verbatim(TextSizeInfo.description)]] + std::optional textSize; + + // [[codegen::verbatim(LabelFileInfo.description)]] + std::optional labelFile; + + // [[codegen::verbatim(LabelMinMaxSizeInfo.description)]] + std::optional textMinMaxSize; + + // [[codegen::verbatim(LineWidthInfo.description)]] + std::optional lineWidth; + + // [[codegen::verbatim(SelectionInfo.description)]] + std::optional> constellationSelection; + }; +#include "renderableconstellation_codegen.cpp" +} // namespace + +namespace openspace { + +documentation::Documentation RenderableConstellation::Documentation() { + return codegen::doc("space_renderable_constellation"); +} + +RenderableConstellation::RenderableConstellation(const ghoul::Dictionary& dictionary) + : Renderable(dictionary) + , _textColor(TextColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f)) + , _textOpacity(TextOpacityInfo, 1.f, 0.f, 1.f) + , _textSize(TextSizeInfo, 8.f, 0.5f, 24.f) + , _drawLabels(DrawLabelInfo, false) + , _textMinMaxSize( + LabelMinMaxSizeInfo, + glm::ivec2(8, 500), + glm::ivec2(0), + glm::ivec2(1000) + ) + , _lineWidth(LineWidthInfo, 2.f, 1.f, 16.f) + , _renderOption(RenderOptionInfo, properties::OptionProperty::DisplayType::Dropdown) + , _constellationNamesFilename(ConstellationInfo) + , _constellationSelection(SelectionInfo) +{ + const Parameters p = codegen::bake(dictionary); + + addProperty(_opacity); + registerUpdateRenderBinFromOpacity(); + + _renderOption.addOption(RenderOptionViewDirection, "Camera View Direction"); + _renderOption.addOption(RenderOptionPositionNormal, "Camera Position Normal"); + // @TODO (abock. 2021-01-31) In the other DU classes, this is done with an enum, and + // doing it based on the fisheye rendering seems a bit brittle? + if (global::windowDelegate->isFisheyeRendering()) { + _renderOption = RenderOptionPositionNormal; + } + else { + _renderOption = RenderOptionViewDirection; + } + addProperty(_renderOption); + + // Avoid reading the translation file here, instead do it in the initialize() + _constellationNamesFilename = p.constellationNamesFile; + _constellationNamesFilename.onChange([&](){ loadConstellationFile(); }); + addProperty(_constellationNamesFilename); + + _lineWidth = p.lineWidth.value_or(_lineWidth); + addProperty(_lineWidth); + + if (p.labelFile.has_value()) { + _labelFile = absPath(*p.labelFile).string(); + _hasLabel = true; + + _drawLabels = p.drawLabels.value_or(_drawLabels); + addProperty(_drawLabels); + + _textColor = p.textColor.value_or(_textColor); + _hasLabel = p.textColor.has_value(); + _textColor.setViewOption(properties::Property::ViewOptions::Color); + addProperty(_textColor); + _textColor.onChange([&]() { _textColorIsDirty = true; }); + + _textOpacity = p.textOpacity.value_or(_textOpacity); + addProperty(_textOpacity); + + _textSize = p.textSize.value_or(_textSize); + addProperty(_textSize); + + _textMinMaxSize = p.textMinMaxSize.value_or(_textMinMaxSize); + _textMinMaxSize.setViewOption(properties::Property::ViewOptions::MinMaxRange); + addProperty(_textMinMaxSize); + } + + fillSelectionProperty(); + _constellationSelection.onChange([this]() { selectionPropertyHasChanged(); }); + addProperty(_constellationSelection); + + if (p.constellationSelection.has_value()) { + const std::vector options = _constellationSelection.options(); + + std::set selectedNames; + for (const std::string& s : *p.constellationSelection) { + const auto it = std::find(options.begin(), options.end(), s); + if (it == options.end()) { + // The user has specified a constellation name that doesn't exist + LWARNINGC( + "RenderableConstellation", + fmt::format("Option '{}' not found in list of constellations", s) + ); + } + else { + selectedNames.insert(s); + } + } + _constellationSelection = selectedNames; + } +} + +bool RenderableConstellation::loadConstellationFile() { + if (_constellationNamesFilename.value().empty()) { + return true; + } + + std::ifstream file; + file.exceptions(std::ifstream::goodbit); + file.open(absPath(_constellationNamesFilename)); + + std::string line; + int index = 0; + while (file.good()) { + std::getline(file, line); + if (line.empty()) { + continue; + } + + std::string abbreviation; + std::stringstream s(line); + s >> abbreviation; + + std::string fullName; + std::getline(s, fullName); + ghoul::trimWhitespace(fullName); + _constellationNamesTranslation.insert({ abbreviation, fullName }); + + ++index; + } + + return true; +} + +void RenderableConstellation::fillSelectionProperty() { + for (const std::pair& pair : _constellationNamesTranslation) { + _constellationSelection.addOption(pair.second); + } +} + +void RenderableConstellation::initialize() { + loadConstellationFile(); + + if (!_hasLabel) { + return; + } + + if (!_font) { + constexpr int FontSize = 50; + _font = global::fontManager->font( + "Mono", + static_cast(FontSize), + ghoul::fontrendering::FontManager::Outline::Yes, + ghoul::fontrendering::FontManager::LoadGlyphs::No + ); + } + + std::string labelFile = _labelFile; + if (!labelFile.empty()) { + _labelset = speck::label::loadFileWithCache(_labelFile); + } + + for (speck::Labelset::Entry& entry : _labelset.entries) { + if (!entry.identifier.empty()) { + entry.text = _constellationNamesTranslation[entry.identifier]; + } + } +} + +void RenderableConstellation::render(const RenderData& data, RendererTasks&) { + const glm::dmat4 modelMatrix = + glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation + glm::dmat4(data.modelTransform.rotation) * // Spice rotation + glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)); + + const glm::dmat4 modelViewMatrix = data.camera.combinedViewMatrix() * modelMatrix; + const glm::dmat4 projectionMatrix = data.camera.projectionMatrix(); + const glm::dmat4 modelViewProjectionMatrix = projectionMatrix * modelViewMatrix; + + const glm::vec3 lookup = data.camera.lookUpVectorWorldSpace(); + const glm::vec3 viewDirection = data.camera.viewDirectionWorldSpace(); + glm::vec3 right = glm::cross(viewDirection, lookup); + const glm::vec3 up = glm::cross(right, viewDirection); + + const glm::dmat4 worldToModelTransform = glm::inverse(modelMatrix); + glm::vec3 orthoRight = glm::normalize( + glm::vec3(worldToModelTransform * glm::vec4(right, 0.0)) + ); + + if (orthoRight == glm::vec3(0.0)) { + glm::vec3 otherVector(lookup.y, lookup.x, lookup.z); + right = glm::cross(viewDirection, otherVector); + orthoRight = glm::normalize( + glm::vec3(worldToModelTransform * glm::vec4(right, 0.0)) + ); + } + + if (_drawLabels && _hasLabel) { + const glm::vec3 orthoUp = glm::normalize( + glm::vec3(worldToModelTransform * glm::dvec4(up, 0.0)) + ); + renderLabels(data, modelViewProjectionMatrix, orthoRight, orthoUp); + } +} + +void RenderableConstellation::renderLabels(const RenderData& data, + const glm::dmat4& modelViewProjectionMatrix, + const glm::vec3& orthoRight, + const glm::vec3& orthoUp) +{ + float scale = static_cast(toMeter(_labelUnit)); + + ghoul::fontrendering::FontRenderer::ProjectedLabelsInformation labelInfo; + labelInfo.orthoRight = orthoRight; + labelInfo.orthoUp = orthoUp; + labelInfo.minSize = _textMinMaxSize.value().x; + labelInfo.maxSize = _textMinMaxSize.value().y; + labelInfo.cameraPos = data.camera.positionVec3(); + labelInfo.cameraLookUp = data.camera.lookUpVectorWorldSpace(); + labelInfo.renderType = _renderOption; + labelInfo.mvpMatrix = modelViewProjectionMatrix; + labelInfo.scale = pow(10.f, _textSize); + labelInfo.enableDepth = true; + labelInfo.enableFalseDepth = false; + + glm::vec4 textColor = glm::vec4(glm::vec3(_textColor), _textOpacity); + + for (const speck::Labelset::Entry& e : _labelset.entries) { + glm::vec3 scaledPos(e.position); + scaledPos *= scale; + ghoul::fontrendering::FontRenderer::defaultProjectionRenderer().render( + *_font, + scaledPos, + e.text, + textColor, + labelInfo + ); + } +} + +} // namespace openspace diff --git a/modules/space/rendering/renderableconstellation.h b/modules/space/rendering/renderableconstellation.h new file mode 100644 index 0000000000..fd1acd37eb --- /dev/null +++ b/modules/space/rendering/renderableconstellation.h @@ -0,0 +1,121 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2022 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_MODULE_SPACE___RENDERABLECONSTELLATION___H__ +#define __OPENSPACE_MODULE_SPACE___RENDERABLECONSTELLATION___H__ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace ghoul::fontrendering { class Font; } +namespace ghoul::opengl { class ProgramObject; } + +namespace openspace { + +namespace documentation { struct Documentation; } + +class RenderableConstellation : public Renderable { +public: + virtual ~RenderableConstellation() override = default; + + virtual void initialize() override; + virtual void initializeGL() override = 0; + virtual void deinitialize() override = 0; + virtual void deinitializeGL() override = 0; + + virtual bool isReady() const override = 0; + + virtual void render(const RenderData& data, RendererTasks& rendererTask) override; + void renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix, + const glm::vec3& orthoRight, const glm::vec3& orthoUp); + virtual void update(const UpdateData& data) override = 0; + + static documentation::Documentation Documentation(); + +protected: + explicit RenderableConstellation(const ghoul::Dictionary& dictionary); + + /** + * Callback method that gets triggered when _constellationSelection + * changes. + */ + virtual void selectionPropertyHasChanged() = 0; + + // Map over the constellations names and theis abbreviations + // key = abbreviations, value = full name + std::map _constellationNamesTranslation; + + // Linewidth for the constellation bounds + properties::FloatProperty _lineWidth; + + /// The property that stores all indices of constellations that should be drawn + properties::SelectionProperty _constellationSelection; + + bool _hasLabel = false; + properties::BoolProperty _drawLabels; + speck::Labelset _labelset; + +private: + /** + * Loads the file specified in _constellationNamesFilename that contains the mapping + * between abbreviations and full names of constellations. + * + * \return true if the loading succeeded, false otherwise + */ + bool loadConstellationFile(); + + /// Fills the _constellationSelection property with all constellations + void fillSelectionProperty(); + + /// The file containing constellation names and abbreviations + properties::StringProperty _constellationNamesFilename; + + //Label text settings + std::string _labelFile; + properties::Vec3Property _textColor; + bool _textColorIsDirty = true; + properties::FloatProperty _textOpacity; + properties::FloatProperty _textSize; + properties::IVec2Property _textMinMaxSize; + std::shared_ptr _font = nullptr; + DistanceUnit _labelUnit = DistanceUnit::Parsec; + + properties::OptionProperty _renderOption; +}; + +} // namespace openspace + +#endif // __OPENSPACE_MODULE_SPACE___RENDERABLECONSTELLATION___H__ diff --git a/modules/space/rendering/renderableconstellationbounds.cpp b/modules/space/rendering/renderableconstellationbounds.cpp index 6a1c798c5c..998e82e127 100644 --- a/modules/space/rendering/renderableconstellationbounds.cpp +++ b/modules/space/rendering/renderableconstellationbounds.cpp @@ -50,14 +50,6 @@ namespace { "constellations" }; - constexpr openspace::properties::Property::PropertyInfo ConstellationInfo = { - "ConstellationFile", - "Constellation File Path", - "Specifies the file that contains the mapping between constellation " - "abbreviations and full name of the constellation. If this value is empty, the " - "abbreviations are used as the full names" - }; - constexpr openspace::properties::Property::PropertyInfo ColorInfo = { "Color", "Color of constellation lines", @@ -65,33 +57,12 @@ namespace { "full opacity" }; - constexpr openspace::properties::Property::PropertyInfo LineWidthInfo = { - "LineWidth", - "Line Width", - "The line width of the constellation bounds" - }; - - constexpr openspace::properties::Property::PropertyInfo SelectionInfo = { - "ConstellationSelection", - "Constellation Selection", - "The constellations that are selected are displayed on the celestial sphere" - }; - struct [[codegen::Dictionary(RenderableConstellationBounds)]] Parameters { // [[codegen::verbatim(VertexInfo.description)]] std::string file; - // [[codegen::verbatim(ConstellationInfo.description)]] - std::optional constellationFile; - // [[codegen::verbatim(ColorInfo.description)]] std::optional color [[codegen::color()]]; - - // [[codegen::verbatim(LineWidthInfo.description)]] - std::optional lineWidth; - - // [[codegen::verbatim(SelectionInfo.description)]] - std::optional> constellationSelection; }; #include "renderableconstellationbounds_codegen.cpp" } // namespace @@ -103,54 +74,27 @@ documentation::Documentation RenderableConstellationBounds::Documentation() { } RenderableConstellationBounds::RenderableConstellationBounds( - const ghoul::Dictionary& dictionary) - : Renderable(dictionary) + const ghoul::Dictionary& dictionary) + : RenderableConstellation(dictionary) , _vertexFilename(VertexInfo) - , _constellationFilename(ConstellationInfo) , _color(ColorInfo, glm::vec3(1.f, 0.f, 0.f), glm::vec3(0.f), glm::vec3(1.f)) - , _lineWidth(LineWidthInfo, 2.f, 1.f, 32.f) - , _constellationSelection(SelectionInfo) { const Parameters p = codegen::bake(dictionary); + // Avoid loading the vertex file here, do it in multithreded initialize() instead + _vertexFilename = p.file; _vertexFilename.onChange([&](){ loadVertexFile(); }); addProperty(_vertexFilename); - _vertexFilename = p.file; - - _constellationFilename.onChange([&](){ loadConstellationFile(); }); - _constellationFilename = p.constellationFile.value_or(_constellationFilename); - addProperty(_constellationFilename); _color.setViewOption(properties::Property::ViewOptions::Color); _color = p.color.value_or(_color); addProperty(_color); +} - _lineWidth = p.lineWidth.value_or(_lineWidth); - addProperty(_lineWidth); +void RenderableConstellationBounds::initialize() { + RenderableConstellation::initialize(); - fillSelectionProperty(); - _constellationSelection.onChange([this]() { selectionPropertyHasChanged(); }); - addProperty(_constellationSelection); - - if (p.constellationSelection.has_value()) { - const std::vector options = _constellationSelection.options(); - - std::set selectedNames; - for (const std::string& s : *p.constellationSelection) { - const auto it = std::find(options.begin(), options.end(), s); - if (it == options.end()) { - // The user has specified a constellation name that doesn't exist - LWARNINGC( - "RenderableConstellationBounds", - fmt::format("Option '{}' not found in list of constellations", s) - ); - } - else { - selectedNames.insert(s); - } - } - _constellationSelection = selectedNames; - } + loadVertexFile(); } void RenderableConstellationBounds::initializeGL() { @@ -179,6 +123,9 @@ void RenderableConstellationBounds::initializeGL() { glBindVertexArray(0); } +void RenderableConstellationBounds::deinitialize() { +} + void RenderableConstellationBounds::deinitializeGL() { glDeleteBuffers(1, &_vbo); _vbo = 0; @@ -192,10 +139,10 @@ void RenderableConstellationBounds::deinitializeGL() { } bool RenderableConstellationBounds::isReady() const { - return (_vao != 0) && (_vbo != 0) && _program; + return _program && _vao != 0 && _vbo != 0 && !_labelset.entries.empty(); } -void RenderableConstellationBounds::render(const RenderData& data, RendererTasks&) { +void RenderableConstellationBounds::render(const RenderData& data, RendererTasks& tasks) { _program->activate(); _program->setUniform("campos", glm::vec4(data.camera.positionVec3(), 1.f)); @@ -223,6 +170,12 @@ void RenderableConstellationBounds::render(const RenderData& data, RendererTasks } glBindVertexArray(0); _program->deactivate(); + + RenderableConstellation::render(data, tasks); +} + +void RenderableConstellationBounds::update(const UpdateData& data) { + } bool RenderableConstellationBounds::loadVertexFile() { @@ -326,61 +279,6 @@ bool RenderableConstellationBounds::loadVertexFile() { return true; } -bool RenderableConstellationBounds::loadConstellationFile() { - if (_constellationFilename.value().empty()) { - return true; - } - - std::ifstream file; - file.exceptions(std::ifstream::goodbit); - file.open(absPath(_constellationFilename)); - - std::string line; - int index = 0; - while (file.good()) { - std::getline(file, line); - if (line.empty()) { - continue; - } - - std::string abbreviation; - std::stringstream s(line); - s >> abbreviation; - - const auto it = std::find_if( - _constellationBounds.begin(), - _constellationBounds.end(), - [abbreviation](const ConstellationBound& bound) { - return bound.constellationAbbreviation == abbreviation; - } - ); - if (it == _constellationBounds.end()) { - LERRORC( - "RenderableConstellationBounds", - fmt::format("Could not find constellation '{}' in list", abbreviation) - ); - return false; - } - - // Update the constellations full name - std::string fullName; - std::getline(s, fullName); - ghoul::trimWhitespace(fullName); - it->constellationFullName = std::move(fullName); - - ++index; - } - - return true; -} - -void RenderableConstellationBounds::fillSelectionProperty() { - for (int i = 0 ; i < static_cast(_constellationBounds.size()); ++i) { - const ConstellationBound& bound = _constellationBounds[i]; - _constellationSelection.addOption(bound.constellationFullName); - } -} - void RenderableConstellationBounds::selectionPropertyHasChanged() { // If no values are selected (the default), we want to show all constellations if (!_constellationSelection.hasSelected()) { diff --git a/modules/space/rendering/renderableconstellationbounds.h b/modules/space/rendering/renderableconstellationbounds.h index bf52622de4..877187a4c4 100644 --- a/modules/space/rendering/renderableconstellationbounds.h +++ b/modules/space/rendering/renderableconstellationbounds.h @@ -25,9 +25,8 @@ #ifndef __OPENSPACE_MODULE_SPACE___RENDERABLECONSTELLATIONBOUNDS___H__ #define __OPENSPACE_MODULE_SPACE___RENDERABLECONSTELLATIONBOUNDS___H__ -#include +#include -#include #include #include #include @@ -48,16 +47,19 @@ namespace documentation { struct Documentation; } * _distance property. Currently, all constellation bounds are lines, which * leads to artifacts if the radius is very small. */ -class RenderableConstellationBounds : public Renderable { +class RenderableConstellationBounds : public RenderableConstellation { public: RenderableConstellationBounds(const ghoul::Dictionary& dictionary); + void initialize() override; void initializeGL() override; + void deinitialize() override; void deinitializeGL() override; bool isReady() const override; void render(const RenderData& data, RendererTasks& rendererTask) override; + void update(const UpdateData& data) override; static documentation::Documentation Documentation(); @@ -80,35 +82,18 @@ private: */ bool loadVertexFile(); - /** - * Loads the file specified in _constellationFilename that contains the mapping - * between abbreviations and full names of constellations. - * - * \return true if the loading succeeded, false otherwise - */ - bool loadConstellationFile(); - - /// Fills the _constellationSelection property with all constellations - void fillSelectionProperty(); - /** * Callback method that gets triggered when _constellationSelection * changes. */ - void selectionPropertyHasChanged(); + void selectionPropertyHasChanged() override; /// The filename containing the constellation bounds properties::StringProperty _vertexFilename; - /// The file containing constellation names - properties::StringProperty _constellationFilename; - /// Determines the color of the constellation lines properties::Vec3Property _color; - // Linewidth for the constellation bounds - properties::FloatProperty _lineWidth; - std::unique_ptr _program; /// The list of all loaded constellation bounds @@ -121,9 +106,6 @@ private: }; std::vector _vertexValues; ///< A list of all vertices of all bounds - /// The property that stores all indices of constellations that should be drawn - properties::SelectionProperty _constellationSelection; - GLuint _vao = 0; GLuint _vbo = 0; }; diff --git a/modules/space/rendering/renderableconstellationlines.cpp b/modules/space/rendering/renderableconstellationlines.cpp new file mode 100644 index 0000000000..06452e2621 --- /dev/null +++ b/modules/space/rendering/renderableconstellationlines.cpp @@ -0,0 +1,581 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2022 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + constexpr std::string_view _loggerCat = "RenderableConstellationLines"; + + constexpr std::array UniformNames = { + "modelViewTransform", "projectionTransform", "alphaValue", "color" + }; + + constexpr int RenderOptionViewDirection = 0; + constexpr int RenderOptionPositionNormal = 1; + + constexpr openspace::properties::Property::PropertyInfo DrawElementsInfo = { + "DrawElements", + "Draw Elements", + "Enables/Disables the drawing of the astronomical objects" + }; + + constexpr openspace::properties::Property::PropertyInfo MeshColorInfo = { + "MeshColor", + "Meshes colors", + "The defined colors for the meshes to be rendered" + }; + + struct [[codegen::Dictionary(RenderableConstellationLines)]] Parameters { + // The path to the SPECK file that contains information about the astronomical + // object being rendered + std::string file; + + enum class [[codegen::map(openspace::DistanceUnit)]] Unit { + Meter [[codegen::key("m")]], + Kilometer [[codegen::key("Km")]], + Parsec [[codegen::key("pc")]], + Kiloparsec [[codegen::key("Kpc")]], + Megaparsec [[codegen::key("Mpc")]], + Gigaparsec [[codegen::key("Gpc")]], + Gigalightyear [[codegen::key("Gly")]] + }; + std::optional unit; + + // [[codegen::verbatim(MeshColorInfo.description)]] + std::optional> meshColor; + }; +#include "renderableconstellationlines_codegen.cpp" +} // namespace + +namespace openspace { + +documentation::Documentation RenderableConstellationLines::Documentation() { + return codegen::doc("space_renderable_constellationlines"); +} + +RenderableConstellationLines::RenderableConstellationLines( + const ghoul::Dictionary& dictionary) + : RenderableConstellation(dictionary) + , _drawElements(DrawElementsInfo, true) +{ + const Parameters p = codegen::bake(dictionary); + + _speckFile = absPath(p.file).string(); + _hasSpeckFile = true; + _drawElements.onChange([&]() { _hasSpeckFile = !_hasSpeckFile; }); + addProperty(_drawElements); + + if (p.unit.has_value()) { + _unit = codegen::map(*p.unit); + } + else { + _unit = DistanceUnit::Meter; + } + + if (p.meshColor.has_value()) { + std::vector ops = *p.meshColor; + for (size_t i = 0; i < ops.size(); ++i) { + _meshColorMap.insert({ static_cast(i) + 1, ops[i] }); + } + } +} + +void RenderableConstellationLines::selectionPropertyHasChanged() { + // If no values are selected (the default), we want to show all constellations + if (!_constellationSelection.hasSelected()) { + for (std::pair& pair : _renderingMeshesMap) { + pair.second.isEnabled = true; + } + } + else { + // Enable all constellations that are selected + for (std::pair& pair : _renderingMeshesMap) { + pair.second.isEnabled = + _constellationSelection.isSelected(pair.second.identifier); + } + } +} + +bool RenderableConstellationLines::isReady() const { + return (_program != nullptr) && !_renderingMeshesMap.empty() && + !_labelset.entries.empty(); +} + +void RenderableConstellationLines::initialize() { + RenderableConstellation::initialize(); + + bool success = loadData(); + if (!success) { + throw ghoul::RuntimeError("Error loading data"); + } +} + +void RenderableConstellationLines::initializeGL() { + _program = DigitalUniverseModule::ProgramObjectManager.request( + "RenderableConstellationLines", + []() { + return global::renderEngine->buildRenderProgram( + "RenderableConstellationLines", + absPath("${MODULE_SPACE}/shaders/constellationlines_vs.glsl"), + absPath("${MODULE_SPACE}/shaders/constellationlines_fs.glsl") + ); + } + ); + + ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); + + createMeshes(); +} + +void RenderableConstellationLines::deinitialize() { +} + +void RenderableConstellationLines::deinitializeGL() { + for (const std::pair& pair : _renderingMeshesMap) { + for (int i = 0; i < pair.second.numU; ++i) { + glDeleteVertexArrays(1, &pair.second.vaoArray[i]); + glDeleteBuffers(1, &pair.second.vboArray[i]); + } + } + + DigitalUniverseModule::ProgramObjectManager.release( + "RenderableConstellationLines", + [](ghoul::opengl::ProgramObject* p) { + global::renderEngine->removeRenderProgram(p); + } + ); +} + +void RenderableConstellationLines::renderMeshes(const RenderData&, + const glm::dmat4& modelViewMatrix, + const glm::dmat4& projectionMatrix) +{ + glEnablei(GL_BLEND, 0); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDepthMask(false); + glEnable(GL_DEPTH_TEST); + + _program->activate(); + + _program->setUniform(_uniformCache.modelViewTransform, modelViewMatrix); + _program->setUniform(_uniformCache.projectionTransform, projectionMatrix); + _program->setUniform(_uniformCache.alphaValue, opacity()); + + for (const std::pair& pair : _renderingMeshesMap) { + if (!pair.second.isEnabled) { + continue; + } + + _program->setUniform(_uniformCache.color, _meshColorMap[pair.second.colorIndex]); + for (size_t i = 0; i < pair.second.vaoArray.size(); ++i) { + glBindVertexArray(pair.second.vaoArray[i]); + switch (pair.second.style) { + case Solid: + break; + case Wire: + glLineWidth(_lineWidth); + glDrawArrays(GL_LINE_STRIP, 0, pair.second.numV); + global::renderEngine->openglStateCache().resetLineState(); + break; + case Point: + glDrawArrays(GL_POINTS, 0, pair.second.numV); + break; + default: + break; + } + } + } + + glBindVertexArray(0); + _program->deactivate(); + + // Restores GL State + global::renderEngine->openglStateCache().resetDepthState(); + global::renderEngine->openglStateCache().resetBlendState(); +} + +void RenderableConstellationLines::render(const RenderData& data, RendererTasks& tasks) { + const glm::dmat4 modelMatrix = + glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation + glm::dmat4(data.modelTransform.rotation) * // Spice rotation + glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)); + + const glm::dmat4 modelViewMatrix = data.camera.combinedViewMatrix() * modelMatrix; + const glm::dmat4 projectionMatrix = data.camera.projectionMatrix(); + + if (_hasSpeckFile) { + renderMeshes(data, modelViewMatrix, projectionMatrix); + } + + RenderableConstellation::render(data, tasks); +} + +void RenderableConstellationLines::update(const UpdateData&) { + if (_program->isDirty()) { + _program->rebuildFromFile(); + ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); + } +} + +bool RenderableConstellationLines::loadData() { + bool success = false; + if (_hasSpeckFile) { + LINFO(fmt::format("Loading Speck file {}", std::filesystem::path(_speckFile))); + success = readSpeckFile(); + if (!success) { + return false; + } + } + + return success; +} + +bool RenderableConstellationLines::readSpeckFile() { + std::ifstream file(_speckFile); + if (!file.good()) { + LERROR(fmt::format( + "Failed to open Speck file {}", std::filesystem::path(_speckFile) + )); + return false; + } + + const float scale = static_cast(toMeter(_unit)); + double maxRadius = 0.0; + + int meshIndex = 0; + + // The beginning of the speck file has a header that either contains comments + // (signaled by a preceding '#') or information about the structure of the file + // (signaled by the keywords 'datavar', 'texturevar', and 'texture') + std::string line; + while (true) { + std::getline(file, line); + + if (file.eof()) { + break; + } + + // Guard against wrong line endings (copying files from Windows to Mac) causes + // lines to have a final \r + if (!line.empty() && line.back() == '\r') { + line = line.substr(0, line.length() - 1); + } + + if (line.empty() || line[0] == '#') { + continue; + } + + std::size_t found = line.find("mesh"); + if (found == std::string::npos) { + continue; + } + else { + // mesh lines are structured as follows: + // mesh -t texnum -c colorindex -s style { + // where textnum is the index of the texture; + // colorindex is the index of the color for the mesh + // and style is solid, wire or point (for now we support only wire) + std::stringstream str(line); + + RenderingMesh mesh; + mesh.meshIndex = meshIndex; + + std::string dummy; + str >> dummy; // mesh command + dummy.clear(); + str >> dummy; // texture index command? + do { + if (dummy == "-t") { + dummy.clear(); + str >> mesh.textureIndex; // texture index + } + else if (dummy == "-c") { + dummy.clear(); + str >> mesh.colorIndex; // color index command + } + else if (dummy == "-s") { + dummy.clear(); + str >> dummy; // style value command + if (dummy == "solid") { + mesh.style = Solid; + } + else if (dummy == "wire") { + mesh.style = Wire; + } + else if (dummy == "point") { + mesh.style = Point; + } + else { + mesh.style = INVALID; + break; + } + } + dummy.clear(); + str >> dummy; + } while (dummy != "{"); + + std::getline(file, line); + std::stringstream dimOrName(line); + std::string dummyU, dummyV; + + // Try to read name of mesh if it exist + dimOrName >> dummyU; // numU or "id" + std::getline(dimOrName, dummyV); // numV or the identifier of the mesh + + if (dummyU == "id") { + ghoul::trimWhitespace(dummyV); + mesh.identifier = _constellationNamesTranslation[dummyV]; + + // Dimensions are specified in the next line as usual + std::getline(file, line); + std::stringstream dim(line); + dim >> mesh.numU; // numU + dim >> mesh.numV; // numV + } + else { + mesh.numU = stoi(dummyU); + mesh.numV = stoi(dummyV); + } + + // We can now read the vertices data: + for (int l = 0; l < mesh.numU * mesh.numV; ++l) { + std::getline(file, line); + if (line.substr(0, 1) == "}") { + break; + } + + std::stringstream lineData(line); + + // Try to read three values for the position + glm::vec3 pos; + bool success = true; + for (int i = 0; i < 3; ++i) { + GLfloat value; + lineData >> value; + bool errorReading = lineData.rdstate() & std::ifstream::failbit; + if (errorReading) { + success = false; + break; + } + + GLfloat scaledValue = value * scale; + pos[i] = scaledValue; + mesh.vertices.push_back(scaledValue); + } + + if (!success) { + LERROR(fmt::format( + "Failed reading position on line {} of mesh {} in file: '{}'. " + "Stopped reading mesh data", l, meshIndex, _speckFile + )); + break; + } + + // Check if new max radius + const double r = glm::length(glm::dvec3(pos)); + maxRadius = std::max(maxRadius, r); + + // OLD CODE: + // (2022-03-23, emmbr) None of our files included texture coordinates, + // and if they would they would still not be used by the shader + //for (int i = 0; i < 7; ++i) { + // GLfloat value; + // lineData >> value; + // bool errorReading = lineData.rdstate() & std::ifstream::failbit; + // if (!errorReading) { + // mesh.vertices.push_back(value); + // } + // else { + // break; + // } + //} + } + + std::getline(file, line); + if (line.substr(0, 1) == "}") { + _renderingMeshesMap.insert({ meshIndex++, mesh }); + } + else { + return false; + } + } + } + setBoundingSphere(maxRadius); + + return true; +} + +void RenderableConstellationLines::createMeshes() { + if (!(_dataIsDirty && _hasSpeckFile)) { + return; + } + LDEBUG("Creating planes"); + + for (std::pair& p : _renderingMeshesMap) { + for (int i = 0; i < p.second.numU; ++i) { + GLuint vao; + glGenVertexArrays(1, &vao); + p.second.vaoArray.push_back(vao); + + GLuint vbo; + glGenBuffers(1, &vbo); + p.second.vboArray.push_back(vbo); + + glBindVertexArray(vao); + glBindBuffer(GL_ARRAY_BUFFER, vbo); + //glBufferData(GL_ARRAY_BUFFER, it->second.numV * sizeof(GLfloat), + glBufferData( + GL_ARRAY_BUFFER, + p.second.vertices.size() * sizeof(GLfloat), + &p.second.vertices[0], + GL_STATIC_DRAW + ); + // in_position + glEnableVertexAttribArray(0); + // (2022-03-23, emmbr) This code was actually never used. We only read three + // values per line and did not handle any texture cooridnates, even if there + // would have been some in the file + //// U and V may not be given by the user + //if (p.second.vertices.size() / (p.second.numU * p.second.numV) > 3) { + // glVertexAttribPointer( + // 0, + // 3, + // GL_FLOAT, + // GL_FALSE, + // sizeof(GLfloat) * 5, + // reinterpret_cast(sizeof(GLfloat) * i * p.second.numV) + // ); + + // // texture coords + // glEnableVertexAttribArray(1); + // glVertexAttribPointer( + // 1, + // 2, + // GL_FLOAT, + // GL_FALSE, + // sizeof(GLfloat) * 7, + // reinterpret_cast(sizeof(GLfloat) * 3 * i * p.second.numV) + // ); + //} + //else { // no U and V: + glVertexAttribPointer( + 0, + 3, + GL_FLOAT, + GL_FALSE, + 0, + reinterpret_cast(sizeof(GLfloat) * 3 * i * p.second.numV) + ); + //} + } + + // Grid: we need columns + if (p.second.numU > 1) { + for (int i = 0; i < p.second.numV; ++i) { + GLuint cvao; + glGenVertexArrays(1, &cvao); + p.second.vaoArray.push_back(cvao); + + GLuint cvbo; + glGenBuffers(1, &cvbo); + p.second.vboArray.push_back(cvbo); + + glBindVertexArray(cvao); + glBindBuffer(GL_ARRAY_BUFFER, cvbo); + glBufferData( + GL_ARRAY_BUFFER, + p.second.vertices.size() * sizeof(GLfloat), + &p.second.vertices[0], + GL_STATIC_DRAW + ); + // in_position + glEnableVertexAttribArray(0); + // U and V may not be given by the user + if (p.second.vertices.size() / (p.second.numU * p.second.numV) > 3) { + glVertexAttribPointer( + 0, + 3, + GL_FLOAT, + GL_FALSE, + p.second.numV * sizeof(GLfloat) * 5, + reinterpret_cast(sizeof(GLfloat) * i) + ); + + // texture coords + glEnableVertexAttribArray(1); + glVertexAttribPointer( + 1, + 2, + GL_FLOAT, + GL_FALSE, + p.second.numV * sizeof(GLfloat) * 7, + reinterpret_cast(sizeof(GLfloat) * 3 * i) + ); + } + else { // no U and V: + glVertexAttribPointer( + 0, + 3, + GL_FLOAT, + GL_FALSE, + p.second.numV * sizeof(GLfloat) * 3, + reinterpret_cast(sizeof(GLfloat) * 3 * i) + ); + } + } + } + } + + glBindVertexArray(0); + + _dataIsDirty = false; +} + +} // namespace openspace diff --git a/modules/space/rendering/renderableconstellationlines.h b/modules/space/rendering/renderableconstellationlines.h new file mode 100644 index 0000000000..985ebaaac3 --- /dev/null +++ b/modules/space/rendering/renderableconstellationlines.h @@ -0,0 +1,137 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2022 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLECONSTELLATIONLINES___H__ +#define __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLECONSTELLATIONLINES___H__ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace ghoul::filesystem { class File; } +namespace ghoul::fontrendering { class Font; } +namespace ghoul::opengl { + class ProgramObject; + class Texture; +} // namespace ghoul::opengl + +namespace openspace { + +namespace documentation { struct Documentation; } + +class RenderableConstellationLines : public RenderableConstellation { +public: + explicit RenderableConstellationLines(const ghoul::Dictionary& dictionary); + ~RenderableConstellationLines() override = default; + + void initialize() override; + void initializeGL() override; + void deinitialize() override; + void deinitializeGL() override; + + bool isReady() const override; + + void render(const RenderData& data, RendererTasks& rendererTask) override; + void update(const UpdateData& data) override; + + static documentation::Documentation Documentation(); + +private: + enum MeshType { + Solid = 0, + Wire = 1, + Point = 2, + INVALID = 9 + }; + + struct RenderingMesh { + int meshIndex; + int colorIndex; + int textureIndex; + // From: Partiview User's Guide + // Brian Abbott + // Hayden Planetarium American Museum of Natural History New York, USA + // "Specifies the dimensions of the mesh" + // "If you wish to draw a line between points, then numU will be 1 while + // numV will equal the number of points to connect. + // If you want a square, 4000×4000 grid with lines every 200 units, + // then numU numV will both equal 21 + int numU; + int numV; + MeshType style; + std::vector vaoArray; + std::vector vboArray; + std::vector vertices; + bool isEnabled = true; + std::string identifier; + }; + + void createMeshes(); + void renderMeshes(const RenderData& data, const glm::dmat4& modelViewMatrix, + const glm::dmat4& projectionMatrix); + + bool loadData(); + bool readSpeckFile(); + + /** + * Callback method that gets triggered when _selectedMeshes + * changes. + */ + void selectionPropertyHasChanged(); + + bool _hasSpeckFile = false; + bool _dataIsDirty = true; + bool _textColorIsDirty = true; + std::vector _assetSelectedMeshes; + + properties::BoolProperty _drawElements; + + ghoul::opengl::ProgramObject* _program = nullptr; + UniformCache(modelViewTransform, projectionTransform, alphaValue, + color) _uniformCache; + std::shared_ptr _font = nullptr; + + std::string _speckFile; + + DistanceUnit _unit = DistanceUnit::Parsec; + + std::vector _fullData; + + std::unordered_map _meshColorMap; + std::unordered_map _renderingMeshesMap; +}; +} // namespace openspace + +#endif // __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLECONSTELLATIONLINES___H__ diff --git a/modules/space/shaders/constellationlines_fs.glsl b/modules/space/shaders/constellationlines_fs.glsl new file mode 100644 index 0000000000..243d5c66a5 --- /dev/null +++ b/modules/space/shaders/constellationlines_fs.glsl @@ -0,0 +1,49 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2022 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include "fragment.glsl" + +in float vs_screenSpaceDepth; +in vec4 vs_positionViewSpace; + +uniform vec3 color; +uniform float alphaValue; + + +Fragment getFragment() { + Fragment frag; + + if (alphaValue == 0.0) { + discard; + } + + frag.color = vec4(color, alphaValue); + frag.depth = vs_screenSpaceDepth; + + // JCC: Need to change the position to camera space + frag.gPosition = vs_positionViewSpace; + frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0); + + return frag; +} diff --git a/modules/space/shaders/constellationlines_vs.glsl b/modules/space/shaders/constellationlines_vs.glsl new file mode 100644 index 0000000000..e8611e67d3 --- /dev/null +++ b/modules/space/shaders/constellationlines_vs.glsl @@ -0,0 +1,47 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2022 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#version __CONTEXT__ + +#include "PowerScaling/powerScaling_vs.hglsl" + +in vec3 in_position; + +out float vs_screenSpaceDepth; +out vec4 vs_positionViewSpace; + +uniform dmat4 modelViewTransform; +uniform dmat4 projectionTransform; + + +void main() { + dvec4 positionViewSpace = modelViewTransform * dvec4(in_position, 1.0); + vec4 positionClipSpace = vec4(projectionTransform * positionViewSpace); + vec4 positionScreenSpace = vec4(z_normalization(positionClipSpace)); + + vs_screenSpaceDepth = positionScreenSpace.w; + vs_positionViewSpace = vec4(positionViewSpace); + + gl_Position = positionScreenSpace; +} diff --git a/modules/space/spacemodule.cpp b/modules/space/spacemodule.cpp index 6bf6ec7c20..588d373799 100644 --- a/modules/space/spacemodule.cpp +++ b/modules/space/spacemodule.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -80,6 +81,9 @@ void SpaceModule::internalInitialize(const ghoul::Dictionary& dictionary) { fRenderable->registerClass( "RenderableConstellationBounds" ); + fRenderable->registerClass( + "RenderableConstellationLines" + ); fRenderable->registerClass("RenderableFluxNodes"); fRenderable->registerClass("RenderableHabitableZone"); fRenderable->registerClass("RenderableRings"); @@ -117,6 +121,7 @@ std::vector SpaceModule::documentations() const { HorizonsTranslation::Documentation(), KeplerTranslation::Documentation(), RenderableConstellationBounds::Documentation(), + RenderableConstellationLines::Documentation(), RenderableFluxNodes::Documentation(), RenderableHabitableZone::Documentation(), RenderableRings::Documentation(), diff --git a/modules/space/speckloader.cpp b/modules/space/speckloader.cpp index 05fa8fb817..a0811b3fce 100644 --- a/modules/space/speckloader.cpp +++ b/modules/space/speckloader.cpp @@ -321,7 +321,7 @@ Dataset loadFile(std::filesystem::path path, SkipAllZeroLines skipAllZeroLines) if (!str.good()) { // Need to subtract one of the line number here as we increase the current - // line count in the beginning of the while loop we are currently in + // line count in the beginning of the while loop we are currently in throw ghoul::RuntimeError(fmt::format( "Error loading position information out of data line {} in file {}. " "Value was not a number", @@ -346,7 +346,7 @@ Dataset loadFile(std::filesystem::path path, SkipAllZeroLines skipAllZeroLines) if (valueStream.fail()) { // Need to subtract one of the line number here as we increase the // current line count in the beginning of the while loop we are - // currently in + // currently in throw ghoul::RuntimeError(fmt::format( "Error loading data value {} out of data line {} in file {}. " "Value was not a number", @@ -674,10 +674,20 @@ Labelset loadFile(std::filesystem::path path, SkipAllZeroLines) { std::getline(str, rest); strip(rest); + if (startsWith(rest, "id")) { + // optional arument with identifier + // Remove the 'id' text + rest = rest.substr(std::string_view("id ").size()); + size_t index = rest.find("text"); + entry.identifier = rest.substr(0, index); + + // update the rest, remove the identifier + rest = rest.substr(index); + } if (!startsWith(rest, "text")) { throw ghoul::RuntimeError(fmt::format( - "Error loading label file {}: File contains some value between " - "positions and text label, which is unsupported", path + "Error loading label file {}: File contains an unsupported value " + "between positions and text label", path )); } diff --git a/modules/space/speckloader.h b/modules/space/speckloader.h index 0cc13c686e..8e48dbd764 100644 --- a/modules/space/speckloader.h +++ b/modules/space/speckloader.h @@ -68,6 +68,7 @@ struct Labelset { struct Entry { glm::vec3 position = glm::vec3(0.f); + std::string identifier; std::string text; }; std::vector entries; From 94a85ec719a742562349579ef9158f4ec696000d Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 5 Aug 2022 13:05:36 +0200 Subject: [PATCH 07/79] Fix constellation label rendering --- .../rendering/renderableconstellation.cpp | 29 +++++++++++-------- modules/space/speckloader.cpp | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/modules/space/rendering/renderableconstellation.cpp b/modules/space/rendering/renderableconstellation.cpp index 08f8d2d184..47d8828970 100644 --- a/modules/space/rendering/renderableconstellation.cpp +++ b/modules/space/rendering/renderableconstellation.cpp @@ -181,9 +181,8 @@ RenderableConstellation::RenderableConstellation(const ghoul::Dictionary& dictio } addProperty(_renderOption); - // Avoid reading the translation file here, instead do it in the initialize() + _constellationNamesFilename.onChange([&]() { loadConstellationFile(); }); _constellationNamesFilename = p.constellationNamesFile; - _constellationNamesFilename.onChange([&](){ loadConstellationFile(); }); addProperty(_constellationNamesFilename); _lineWidth = p.lineWidth.value_or(_lineWidth); @@ -262,7 +261,7 @@ bool RenderableConstellation::loadConstellationFile() { std::string fullName; std::getline(s, fullName); ghoul::trimWhitespace(fullName); - _constellationNamesTranslation.insert({ abbreviation, fullName }); + _constellationNamesTranslation[abbreviation] = fullName; ++index; } @@ -277,8 +276,6 @@ void RenderableConstellation::fillSelectionProperty() { } void RenderableConstellation::initialize() { - loadConstellationFile(); - if (!_hasLabel) { return; } @@ -300,12 +297,16 @@ void RenderableConstellation::initialize() { for (speck::Labelset::Entry& entry : _labelset.entries) { if (!entry.identifier.empty()) { - entry.text = _constellationNamesTranslation[entry.identifier]; + entry.text = _constellationNamesTranslation.at(entry.identifier); } } } void RenderableConstellation::render(const RenderData& data, RendererTasks&) { + if (!_hasLabel || !_drawLabels) { + return; + } + const glm::dmat4 modelMatrix = glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation glm::dmat4(data.modelTransform.rotation) * // Spice rotation @@ -333,12 +334,10 @@ void RenderableConstellation::render(const RenderData& data, RendererTasks&) { ); } - if (_drawLabels && _hasLabel) { - const glm::vec3 orthoUp = glm::normalize( - glm::vec3(worldToModelTransform * glm::dvec4(up, 0.0)) - ); - renderLabels(data, modelViewProjectionMatrix, orthoRight, orthoUp); - } + const glm::vec3 orthoUp = glm::normalize( + glm::vec3(worldToModelTransform * glm::dvec4(up, 0.0)) + ); + renderLabels(data, modelViewProjectionMatrix, orthoRight, orthoUp); } void RenderableConstellation::renderLabels(const RenderData& data, @@ -364,6 +363,12 @@ void RenderableConstellation::renderLabels(const RenderData& data, glm::vec4 textColor = glm::vec4(glm::vec3(_textColor), _textOpacity); for (const speck::Labelset::Entry& e : _labelset.entries) { + if (_constellationSelection.hasSelected() && + !_constellationSelection.isSelected(e.text)) + { + continue; + } + glm::vec3 scaledPos(e.position); scaledPos *= scale; ghoul::fontrendering::FontRenderer::defaultProjectionRenderer().render( diff --git a/modules/space/speckloader.cpp b/modules/space/speckloader.cpp index a0811b3fce..4462c8f688 100644 --- a/modules/space/speckloader.cpp +++ b/modules/space/speckloader.cpp @@ -679,7 +679,7 @@ Labelset loadFile(std::filesystem::path path, SkipAllZeroLines) { // Remove the 'id' text rest = rest.substr(std::string_view("id ").size()); size_t index = rest.find("text"); - entry.identifier = rest.substr(0, index); + entry.identifier = rest.substr(0, index - 1); // update the rest, remove the identifier rest = rest.substr(index); From 62aaa45ff54c809ffd1c78eb6cb747cdd929d493 Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 5 Aug 2022 14:08:36 +0200 Subject: [PATCH 08/79] Move file reading to initialize instead of constructor --- .../rendering/renderableconstellation.cpp | 56 +++++++++++-------- .../space/rendering/renderableconstellation.h | 4 +- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/modules/space/rendering/renderableconstellation.cpp b/modules/space/rendering/renderableconstellation.cpp index 47d8828970..6e0c2936dd 100644 --- a/modules/space/rendering/renderableconstellation.cpp +++ b/modules/space/rendering/renderableconstellation.cpp @@ -181,8 +181,9 @@ RenderableConstellation::RenderableConstellation(const ghoul::Dictionary& dictio } addProperty(_renderOption); - _constellationNamesFilename.onChange([&]() { loadConstellationFile(); }); + // Read all files in the initialize() instead, multithreaded _constellationNamesFilename = p.constellationNamesFile; + _constellationNamesFilename.onChange([&]() { loadConstellationFile(); }); addProperty(_constellationNamesFilename); _lineWidth = p.lineWidth.value_or(_lineWidth); @@ -212,36 +213,21 @@ RenderableConstellation::RenderableConstellation(const ghoul::Dictionary& dictio addProperty(_textMinMaxSize); } - fillSelectionProperty(); _constellationSelection.onChange([this]() { selectionPropertyHasChanged(); }); addProperty(_constellationSelection); - if (p.constellationSelection.has_value()) { - const std::vector options = _constellationSelection.options(); - - std::set selectedNames; - for (const std::string& s : *p.constellationSelection) { - const auto it = std::find(options.begin(), options.end(), s); - if (it == options.end()) { - // The user has specified a constellation name that doesn't exist - LWARNINGC( - "RenderableConstellation", - fmt::format("Option '{}' not found in list of constellations", s) - ); - } - else { - selectedNames.insert(s); - } - } - _constellationSelection = selectedNames; - } + _assetSelectedMeshes = p.constellationSelection.value_or(_assetSelectedMeshes); } -bool RenderableConstellation::loadConstellationFile() { +void RenderableConstellation::loadConstellationFile() { if (_constellationNamesFilename.value().empty()) { - return true; + return; } + // Reset + _constellationSelection.clearOptions(); + _constellationNamesTranslation.clear(); + std::ifstream file; file.exceptions(std::ifstream::goodbit); file.open(absPath(_constellationNamesFilename)); @@ -266,7 +252,7 @@ bool RenderableConstellation::loadConstellationFile() { ++index; } - return true; + fillSelectionProperty(); } void RenderableConstellation::fillSelectionProperty() { @@ -276,6 +262,28 @@ void RenderableConstellation::fillSelectionProperty() { } void RenderableConstellation::initialize() { + loadConstellationFile(); + + if (!_assetSelectedMeshes.empty()) { + const std::vector options = _constellationSelection.options(); + std::set selectedConstellations; + + for (const std::string& s : _assetSelectedMeshes) { + const auto it = std::find(options.begin(), options.end(), s); + if (it == options.end()) { + // The user has specified a mesh name that doesn't exist + LWARNINGC( + "RenderableConstellation", + fmt::format("Option '{}' not found in list of meshes", s) + ); + } + else { + selectedConstellations.insert(s); + } + } + _constellationSelection = selectedConstellations; + } + if (!_hasLabel) { return; } diff --git a/modules/space/rendering/renderableconstellation.h b/modules/space/rendering/renderableconstellation.h index fd1acd37eb..06021d4f72 100644 --- a/modules/space/rendering/renderableconstellation.h +++ b/modules/space/rendering/renderableconstellation.h @@ -89,13 +89,15 @@ protected: speck::Labelset _labelset; private: + std::vector _assetSelectedMeshes; + /** * Loads the file specified in _constellationNamesFilename that contains the mapping * between abbreviations and full names of constellations. * * \return true if the loading succeeded, false otherwise */ - bool loadConstellationFile(); + void loadConstellationFile(); /// Fills the _constellationSelection property with all constellations void fillSelectionProperty(); From a2938c83841dd9529f0f453c8f346f8802dbc483 Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 5 Aug 2022 15:12:43 +0200 Subject: [PATCH 09/79] Update label file cache format --- .../space/rendering/renderableconstellation.cpp | 11 ++++++++++- modules/space/speckloader.cpp | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/modules/space/rendering/renderableconstellation.cpp b/modules/space/rendering/renderableconstellation.cpp index 6e0c2936dd..14d6903b3a 100644 --- a/modules/space/rendering/renderableconstellation.cpp +++ b/modules/space/rendering/renderableconstellation.cpp @@ -305,7 +305,16 @@ void RenderableConstellation::initialize() { for (speck::Labelset::Entry& entry : _labelset.entries) { if (!entry.identifier.empty()) { - entry.text = _constellationNamesTranslation.at(entry.identifier); + try { + entry.text = _constellationNamesTranslation.at(entry.identifier); + } + catch (const std::out_of_range&) { + std::string message = fmt::format( + "Identifier '{}' could not be found in list of constellations", + entry.identifier + ); + throw ghoul::RuntimeError(message, "RenderableConstellation"); + } } } } diff --git a/modules/space/speckloader.cpp b/modules/space/speckloader.cpp index 4462c8f688..889be4b38e 100644 --- a/modules/space/speckloader.cpp +++ b/modules/space/speckloader.cpp @@ -37,7 +37,7 @@ namespace { constexpr int8_t DataCacheFileVersion = 10; - constexpr int8_t LabelCacheFileVersion = 10; + constexpr int8_t LabelCacheFileVersion = 11; constexpr int8_t ColorCacheFileVersion = 10; bool startsWith(std::string lhs, std::string_view rhs) noexcept { @@ -741,6 +741,13 @@ std::optional loadCachedFile(std::filesystem::path path) { file.read(reinterpret_cast(&e.position.y), sizeof(float)); file.read(reinterpret_cast(&e.position.z), sizeof(float)); + // Identifier + uint8_t idLen; + file.read(reinterpret_cast(&idLen), sizeof(uint8_t)); + e.identifier.resize(idLen); + file.read(e.identifier.data(), idLen); + + // Text uint16_t len; file.read(reinterpret_cast(&len), sizeof(uint16_t)); e.text.resize(len); @@ -773,6 +780,13 @@ void saveCachedFile(const Labelset& labelset, std::filesystem::path path) { file.write(reinterpret_cast(&e.position.y), sizeof(float)); file.write(reinterpret_cast(&e.position.z), sizeof(float)); + // Identifier + checkSize(e.identifier.size(), "Identifier too long"); + uint8_t idLen = static_cast(e.identifier.size()); + file.write(reinterpret_cast(&idLen), sizeof(uint8_t)); + file.write(e.identifier.data(), idLen); + + // Text checkSize(e.text.size(), "Text too long"); uint16_t len = static_cast(e.text.size()); file.write(reinterpret_cast(&len), sizeof(uint16_t)); From 6efb99e5510378edfa04aebf14390f19d4b2773a Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 5 Aug 2022 16:59:04 +0200 Subject: [PATCH 10/79] Fix constellation bounds render issue --- .../rendering/renderableconstellation.cpp | 25 +++++++++++-------- .../space/rendering/renderableconstellation.h | 8 +++--- .../renderableconstellationbounds.cpp | 13 ++++++---- .../renderableconstellationlines.cpp | 2 +- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/modules/space/rendering/renderableconstellation.cpp b/modules/space/rendering/renderableconstellation.cpp index 14d6903b3a..c7093c8009 100644 --- a/modules/space/rendering/renderableconstellation.cpp +++ b/modules/space/rendering/renderableconstellation.cpp @@ -219,6 +219,20 @@ RenderableConstellation::RenderableConstellation(const ghoul::Dictionary& dictio _assetSelectedMeshes = p.constellationSelection.value_or(_assetSelectedMeshes); } +std::string RenderableConstellation::constellationFullName( + const std::string& identifier) const +{ + try { + return _constellationNamesTranslation.at(identifier); + } + catch (const std::out_of_range&) { + std::string message = fmt::format( + "Identifier '{}' could not be found in list of constellations", identifier + ); + throw ghoul::RuntimeError(message, "RenderableConstellation"); + } +} + void RenderableConstellation::loadConstellationFile() { if (_constellationNamesFilename.value().empty()) { return; @@ -305,16 +319,7 @@ void RenderableConstellation::initialize() { for (speck::Labelset::Entry& entry : _labelset.entries) { if (!entry.identifier.empty()) { - try { - entry.text = _constellationNamesTranslation.at(entry.identifier); - } - catch (const std::out_of_range&) { - std::string message = fmt::format( - "Identifier '{}' could not be found in list of constellations", - entry.identifier - ); - throw ghoul::RuntimeError(message, "RenderableConstellation"); - } + entry.text = constellationFullName(entry.identifier); } } } diff --git a/modules/space/rendering/renderableconstellation.h b/modules/space/rendering/renderableconstellation.h index 06021d4f72..b8d4b1a548 100644 --- a/modules/space/rendering/renderableconstellation.h +++ b/modules/space/rendering/renderableconstellation.h @@ -74,9 +74,7 @@ protected: */ virtual void selectionPropertyHasChanged() = 0; - // Map over the constellations names and theis abbreviations - // key = abbreviations, value = full name - std::map _constellationNamesTranslation; + std::string constellationFullName(const std::string& identifier) const; // Linewidth for the constellation bounds properties::FloatProperty _lineWidth; @@ -89,6 +87,10 @@ protected: speck::Labelset _labelset; private: + // Map over the constellations names and theis abbreviations + // key = abbreviations, value = full name + std::map _constellationNamesTranslation; + std::vector _assetSelectedMeshes; /** diff --git a/modules/space/rendering/renderableconstellationbounds.cpp b/modules/space/rendering/renderableconstellationbounds.cpp index 998e82e127..f58f038579 100644 --- a/modules/space/rendering/renderableconstellationbounds.cpp +++ b/modules/space/rendering/renderableconstellationbounds.cpp @@ -139,6 +139,9 @@ void RenderableConstellationBounds::deinitializeGL() { } bool RenderableConstellationBounds::isReady() const { + if (!_hasLabel) { + return _program && _vao != 0 && _vbo != 0; + } return _program && _vao != 0 && _vbo != 0 && !_labelset.entries.empty(); } @@ -214,8 +217,8 @@ bool RenderableConstellationBounds::loadVertexFile() { float dec; s >> dec; - std::string constellationName; - s >> constellationName; + std::string abbreviation; + s >> abbreviation; if (!s.good()) { // If this evaluates to true, the stream was not completely filled, which @@ -230,7 +233,7 @@ bool RenderableConstellationBounds::loadVertexFile() { } // Did we arrive at a new constellation? - if (constellationName != currentBound.constellationAbbreviation) { + if (abbreviation != currentBound.constellationAbbreviation) { // Store how many vertices we read during the active time of the constellation currentBound.nVertices = static_cast( _vertexValues.size() - currentBound.startIndex @@ -239,8 +242,8 @@ bool RenderableConstellationBounds::loadVertexFile() { _constellationBounds.push_back(currentBound); currentBound = ConstellationBound(); currentBound.isEnabled = true; - currentBound.constellationAbbreviation = constellationName; - currentBound.constellationFullName = constellationName; + currentBound.constellationAbbreviation = abbreviation; + currentBound.constellationFullName = constellationFullName(abbreviation); currentBound.startIndex = static_cast(_vertexValues.size()); } diff --git a/modules/space/rendering/renderableconstellationlines.cpp b/modules/space/rendering/renderableconstellationlines.cpp index 06452e2621..9a3b8984bf 100644 --- a/modules/space/rendering/renderableconstellationlines.cpp +++ b/modules/space/rendering/renderableconstellationlines.cpp @@ -371,7 +371,7 @@ bool RenderableConstellationLines::readSpeckFile() { if (dummyU == "id") { ghoul::trimWhitespace(dummyV); - mesh.identifier = _constellationNamesTranslation[dummyV]; + mesh.identifier = constellationFullName(dummyV); // Dimensions are specified in the next line as usual std::getline(file, line); From 8c01d536b65f3fc9eef4a197758b1f5c4df1ea33 Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 5 Aug 2022 17:01:12 +0200 Subject: [PATCH 11/79] Restore RenderableDUMeshes class --- .../rendering/renderabledumeshes.cpp | 99 +------------------ .../rendering/renderabledumeshes.h | 14 --- 2 files changed, 2 insertions(+), 111 deletions(-) diff --git a/modules/digitaluniverse/rendering/renderabledumeshes.cpp b/modules/digitaluniverse/rendering/renderabledumeshes.cpp index 01dc22f4ca..367d2ac91b 100644 --- a/modules/digitaluniverse/rendering/renderabledumeshes.cpp +++ b/modules/digitaluniverse/rendering/renderabledumeshes.cpp @@ -121,12 +121,6 @@ namespace { "Debug option for rendering of billboards and texts" }; - constexpr openspace::properties::Property::PropertyInfo MeshSelectionInfo = { - "MeshSelection", - "Selection", - "Selected objects" - }; - struct [[codegen::Dictionary(RenderableDUMeshes)]] Parameters { // The path to the SPECK file that contains information about the astronomical // object being rendered @@ -166,9 +160,6 @@ namespace { // [[codegen::verbatim(MeshColorInfo.description)]] std::optional> meshColor; - - // [[codegen::verbatim(MeshSelectionInfo.description)]] - std::optional> selectedMeshes; }; #include "renderabledumeshes_codegen.cpp" } // namespace @@ -194,7 +185,6 @@ RenderableDUMeshes::RenderableDUMeshes(const ghoul::Dictionary& dictionary) ) , _lineWidth(LineWidthInfo, 2.f, 1.f, 16.f) , _renderOption(RenderOptionInfo, properties::OptionProperty::DisplayType::Dropdown) - , _selectedMeshes(MeshSelectionInfo) { const Parameters p = codegen::bake(dictionary); @@ -258,44 +248,6 @@ RenderableDUMeshes::RenderableDUMeshes(const ghoul::Dictionary& dictionary) _meshColorMap.insert({ static_cast(i) + 1, ops[i] }); } } - - _selectedMeshes.onChange([this]() { selectionPropertyHasChanged(); }); - addProperty(_selectedMeshes); - - _assetSelectedMeshes = p.selectedMeshes.value_or(_assetSelectedMeshes); -} - -void RenderableDUMeshes::fillSelectionProperty() { - for (const std::pair& pair : _renderingMeshesMap) { - if (pair.second.name.empty()) { - continue; - } - - auto it = std::find( - _selectedMeshes.options().begin(), - _selectedMeshes.options().end(), - pair.second.name - ); - if (it != _selectedMeshes.options().end()) { - continue; - } - _selectedMeshes.addOption(pair.second.name); - } -} - -void RenderableDUMeshes::selectionPropertyHasChanged() { - // If no values are selected (the default), we want to show all constellations - if (!_selectedMeshes.hasSelected()) { - for (std::pair& pair : _renderingMeshesMap) { - pair.second.isEnabled = true; - } - } - else { - // Enable all constellations that are selected - for (std::pair& pair : _renderingMeshesMap) { - pair.second.isEnabled = _selectedMeshes.isSelected(pair.second.name); - } - } } bool RenderableDUMeshes::isReady() const { @@ -308,27 +260,6 @@ void RenderableDUMeshes::initialize() { if (!success) { throw ghoul::RuntimeError("Error loading data"); } - - fillSelectionProperty(); - - if (_assetSelectedMeshes.empty()) { - return; - } - - const std::vector options = _selectedMeshes.options(); - std::set selectedNames; - - for (const std::string& s : _assetSelectedMeshes) { - const auto it = std::find(options.begin(), options.end(), s); - if (it == options.end()) { - // The user has specified a mesh name that doesn't exist - LWARNING(fmt::format("Option '{}' not found in list of meshes", s)); - } - else { - selectedNames.insert(s); - } - } - _selectedMeshes = selectedNames; } void RenderableDUMeshes::initializeGL() { @@ -393,10 +324,6 @@ void RenderableDUMeshes::renderMeshes(const RenderData&, _program->setUniform(_uniformCache.alphaValue, opacity()); for (const std::pair& pair : _renderingMeshesMap) { - if (!pair.second.isEnabled) { - continue; - } - _program->setUniform(_uniformCache.color, _meshColorMap[pair.second.colorIndex]); for (size_t i = 0; i < pair.second.vaoArray.size(); ++i) { glBindVertexArray(pair.second.vaoArray[i]); @@ -610,30 +537,8 @@ bool RenderableDUMeshes::readSpeckFile() { } while (dummy != "{"); std::getline(file, line); - std::stringstream dimOrName(line); - std::string dummyU, dummyV; - - // Try to read name of mesh if it exist - dimOrName >> dummyU; // numU or "name" - std::getline(dimOrName, dummyV); // numV or the name of the mesh - - if (dummyU == "id") { - mesh.name = dummyV; - // Trim leading whitespace - if (!mesh.name.empty() && mesh.name[0] == ' ') { - mesh.name = mesh.name.substr(1); - } - - // Dimensions are specified in the next line as usual - std::getline(file, line); - std::stringstream dim(line); - dim >> mesh.numU; // numU - dim >> mesh.numV; // numV - } - else { - mesh.numU = stoi(dummyU); - mesh.numV = stoi(dummyV); - } + std::stringstream dim(line); + dim >> mesh.numU >> mesh.numV; // We can now read the vertices data: for (int l = 0; l < mesh.numU * mesh.numV; ++l) { diff --git a/modules/digitaluniverse/rendering/renderabledumeshes.h b/modules/digitaluniverse/rendering/renderabledumeshes.h index 4e331daab5..afdf483479 100644 --- a/modules/digitaluniverse/rendering/renderabledumeshes.h +++ b/modules/digitaluniverse/rendering/renderabledumeshes.h @@ -29,7 +29,6 @@ #include #include -#include #include #include #include @@ -93,8 +92,6 @@ private: std::vector vaoArray; std::vector vboArray; std::vector vertices; - bool isEnabled = true; - std::string name; }; void createMeshes(); @@ -106,20 +103,10 @@ private: bool loadData(); bool readSpeckFile(); - /// Fills the _selectedMeshes property with all available meshes - void fillSelectionProperty(); - - /** - * Callback method that gets triggered when _selectedMeshes - * changes. - */ - void selectionPropertyHasChanged(); - bool _hasSpeckFile = false; bool _dataIsDirty = true; bool _textColorIsDirty = true; bool _hasLabel = false; - std::vector _assetSelectedMeshes; properties::Vec3Property _textColor; properties::FloatProperty _textOpacity; @@ -128,7 +115,6 @@ private: properties::BoolProperty _drawLabels; properties::IVec2Property _textMinMaxSize; properties::FloatProperty _lineWidth; - properties::SelectionProperty _selectedMeshes; // DEBUG: properties::OptionProperty _renderOption; From 54dcdcf0f1cdf1cc674473681d2360e1439e3138 Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 9 Aug 2022 08:54:41 +0200 Subject: [PATCH 12/79] Some clean up --- .../digitaluniverse/constellations.asset | 5 +- .../rendering/renderableconstellation.cpp | 33 +++- .../space/rendering/renderableconstellation.h | 37 ++-- .../renderableconstellationbounds.cpp | 2 +- .../rendering/renderableconstellationbounds.h | 9 +- .../renderableconstellationlines.cpp | 164 ++++++++---------- .../rendering/renderableconstellationlines.h | 47 ++--- .../space/shaders/constellationbounds_fs.glsl | 11 +- 8 files changed, 145 insertions(+), 163 deletions(-) diff --git a/data/assets/scene/digitaluniverse/constellations.asset b/data/assets/scene/digitaluniverse/constellations.asset index 3c0bcafa09..62f4d4f1e8 100644 --- a/data/assets/scene/digitaluniverse/constellations.asset +++ b/data/assets/scene/digitaluniverse/constellations.asset @@ -39,8 +39,9 @@ local constellations = { TextOpacity = 0.3, TextSize = 14.5, TextMinMaxSize = { 8, 170 }, - MeshColor = { { 0.6, 0.4, 0.4 }, { 0.8, 0.0, 0.0 }, { 0.0, 0.3, 0.8 } }, - Unit = "pc" + LabelUnit = "pc", + ConstellationColor = { { 0.6, 0.4, 0.4 }, { 0.8, 0.0, 0.0 }, { 0.0, 0.3, 0.8 } }, + ConstellationUnit = "pc" }, GUI = { Name = "Constellations", diff --git a/modules/space/rendering/renderableconstellation.cpp b/modules/space/rendering/renderableconstellation.cpp index c7093c8009..4d7c96b101 100644 --- a/modules/space/rendering/renderableconstellation.cpp +++ b/modules/space/rendering/renderableconstellation.cpp @@ -104,6 +104,12 @@ namespace { "Debug option for rendering of billboards and texts" }; + constexpr openspace::properties::Property::PropertyInfo LabelUnitInfo = { + "LabelUnit", + "Label Unit", + "The unit used for the label data" + }; + constexpr openspace::properties::Property::PropertyInfo SelectionInfo = { "ConstellationSelection", "Constellation Selection", @@ -135,6 +141,18 @@ namespace { // [[codegen::verbatim(LineWidthInfo.description)]] std::optional lineWidth; + enum class [[codegen::map(openspace::DistanceUnit)]] Unit { + Meter [[codegen::key("m")]], + Kilometer [[codegen::key("Km")]], + Parsec [[codegen::key("pc")]], + Kiloparsec [[codegen::key("Kpc")]], + Megaparsec [[codegen::key("Mpc")]], + Gigaparsec [[codegen::key("Gpc")]], + Gigalightyear [[codegen::key("Gly")]] + }; + // [[codegen::verbatim(LabelUnitInfo.description)]] + std::optional labelUnit; + // [[codegen::verbatim(SelectionInfo.description)]] std::optional> constellationSelection; }; @@ -200,7 +218,6 @@ RenderableConstellation::RenderableConstellation(const ghoul::Dictionary& dictio _hasLabel = p.textColor.has_value(); _textColor.setViewOption(properties::Property::ViewOptions::Color); addProperty(_textColor); - _textColor.onChange([&]() { _textColorIsDirty = true; }); _textOpacity = p.textOpacity.value_or(_textOpacity); addProperty(_textOpacity); @@ -211,12 +228,20 @@ RenderableConstellation::RenderableConstellation(const ghoul::Dictionary& dictio _textMinMaxSize = p.textMinMaxSize.value_or(_textMinMaxSize); _textMinMaxSize.setViewOption(properties::Property::ViewOptions::MinMaxRange); addProperty(_textMinMaxSize); + + if (p.labelUnit.has_value()) { + _labelUnit = codegen::map(*p.labelUnit); + } + else { + _labelUnit = DistanceUnit::Meter; + } } _constellationSelection.onChange([this]() { selectionPropertyHasChanged(); }); addProperty(_constellationSelection); - _assetSelectedMeshes = p.constellationSelection.value_or(_assetSelectedMeshes); + _assetSelectedConstellations = + p.constellationSelection.value_or(_assetSelectedConstellations); } std::string RenderableConstellation::constellationFullName( @@ -278,11 +303,11 @@ void RenderableConstellation::fillSelectionProperty() { void RenderableConstellation::initialize() { loadConstellationFile(); - if (!_assetSelectedMeshes.empty()) { + if (!_assetSelectedConstellations.empty()) { const std::vector options = _constellationSelection.options(); std::set selectedConstellations; - for (const std::string& s : _assetSelectedMeshes) { + for (const std::string& s : _assetSelectedConstellations) { const auto it = std::find(options.begin(), options.end(), s); if (it == options.end()) { // The user has specified a mesh name that doesn't exist diff --git a/modules/space/rendering/renderableconstellation.h b/modules/space/rendering/renderableconstellation.h index b8d4b1a548..514cffe511 100644 --- a/modules/space/rendering/renderableconstellation.h +++ b/modules/space/rendering/renderableconstellation.h @@ -29,10 +29,7 @@ #include #include -#include -#include #include -#include #include #include #include @@ -70,52 +67,54 @@ protected: /** * Callback method that gets triggered when _constellationSelection - * changes. + * changes */ virtual void selectionPropertyHasChanged() = 0; + /// Takes the given constellation identifier and returns the coresponding + /// full name std::string constellationFullName(const std::string& identifier) const; - // Linewidth for the constellation bounds + // Width for the rendered lines properties::FloatProperty _lineWidth; - /// The property that stores all indices of constellations that should be drawn + // Property that stores all constellations chosen by the user to be drawn properties::SelectionProperty _constellationSelection; + // Label text settings bool _hasLabel = false; - properties::BoolProperty _drawLabels; speck::Labelset _labelset; + properties::BoolProperty _drawLabels; private: - // Map over the constellations names and theis abbreviations - // key = abbreviations, value = full name + // Map over the constellations names and their abbreviations + // key = abbreviation, value = full name std::map _constellationNamesTranslation; - std::vector _assetSelectedMeshes; + // Temporary storage of which constellations should be rendered as stated in the + // asset file + std::vector _assetSelectedConstellations; /** - * Loads the file specified in _constellationNamesFilename that contains the mapping - * between abbreviations and full names of constellations. - * - * \return true if the loading succeeded, false otherwise + * Loads the file specified in _constellationNamesFilename that contains + * the mapping between abbreviations and full names of constellations */ void loadConstellationFile(); /// Fills the _constellationSelection property with all constellations void fillSelectionProperty(); - /// The file containing constellation names and abbreviations + // The file containing constellation names and abbreviations properties::StringProperty _constellationNamesFilename; - //Label text settings + // Label text settings std::string _labelFile; + std::shared_ptr _font = nullptr; + DistanceUnit _labelUnit = DistanceUnit::Parsec; properties::Vec3Property _textColor; - bool _textColorIsDirty = true; properties::FloatProperty _textOpacity; properties::FloatProperty _textSize; properties::IVec2Property _textMinMaxSize; - std::shared_ptr _font = nullptr; - DistanceUnit _labelUnit = DistanceUnit::Parsec; properties::OptionProperty _renderOption; }; diff --git a/modules/space/rendering/renderableconstellationbounds.cpp b/modules/space/rendering/renderableconstellationbounds.cpp index f58f038579..a0ac82f046 100644 --- a/modules/space/rendering/renderableconstellationbounds.cpp +++ b/modules/space/rendering/renderableconstellationbounds.cpp @@ -162,6 +162,7 @@ void RenderableConstellationBounds::render(const RenderData& data, RendererTasks _program->setUniform("ViewProjection", data.camera.viewProjectionMatrix()); _program->setUniform("ModelTransform", glm::mat4(modelTransform)); _program->setUniform("color", _color); + _program->setUniform("alphaValue", opacity()); glLineWidth(_lineWidth); @@ -178,7 +179,6 @@ void RenderableConstellationBounds::render(const RenderData& data, RendererTasks } void RenderableConstellationBounds::update(const UpdateData& data) { - } bool RenderableConstellationBounds::loadVertexFile() { diff --git a/modules/space/rendering/renderableconstellationbounds.h b/modules/space/rendering/renderableconstellationbounds.h index 877187a4c4..eacb03aca9 100644 --- a/modules/space/rendering/renderableconstellationbounds.h +++ b/modules/space/rendering/renderableconstellationbounds.h @@ -27,11 +27,6 @@ #include -#include -#include -#include -#include - namespace ghoul::opengl { class ProgramObject; } namespace openspace { @@ -94,11 +89,11 @@ private: /// Determines the color of the constellation lines properties::Vec3Property _color; - std::unique_ptr _program; - /// The list of all loaded constellation bounds std::vector _constellationBounds; + std::unique_ptr _program; + struct Vertex { float x; float y; diff --git a/modules/space/rendering/renderableconstellationlines.cpp b/modules/space/rendering/renderableconstellationlines.cpp index 9a3b8984bf..6f46b952c8 100644 --- a/modules/space/rendering/renderableconstellationlines.cpp +++ b/modules/space/rendering/renderableconstellationlines.cpp @@ -24,7 +24,6 @@ #include -#include #include #include #include @@ -56,24 +55,26 @@ namespace { "modelViewTransform", "projectionTransform", "alphaValue", "color" }; - constexpr int RenderOptionViewDirection = 0; - constexpr int RenderOptionPositionNormal = 1; - constexpr openspace::properties::Property::PropertyInfo DrawElementsInfo = { "DrawElements", "Draw Elements", - "Enables/Disables the drawing of the astronomical objects" + "Enables/Disables the drawing of the constellations" }; - constexpr openspace::properties::Property::PropertyInfo MeshColorInfo = { - "MeshColor", - "Meshes colors", - "The defined colors for the meshes to be rendered" + constexpr openspace::properties::Property::PropertyInfo ConstellationUnitInfo = { + "ConstellationUnit", + "Constellation Unit", + "The unit used for the constellation data" + }; + + constexpr openspace::properties::Property::PropertyInfo ConstellationColorInfo = { + "ConstellationColor", + "Constellation colors", + "The defined colors for the constellations to be rendered" }; struct [[codegen::Dictionary(RenderableConstellationLines)]] Parameters { - // The path to the SPECK file that contains information about the astronomical - // object being rendered + // The path to the SPECK file that contains constellation lines data std::string file; enum class [[codegen::map(openspace::DistanceUnit)]] Unit { @@ -85,10 +86,11 @@ namespace { Gigaparsec [[codegen::key("Gpc")]], Gigalightyear [[codegen::key("Gly")]] }; - std::optional unit; + // [[codegen::verbatim(ConstellationUnitInfo.description)]] + std::optional constellationUnit; - // [[codegen::verbatim(MeshColorInfo.description)]] - std::optional> meshColor; + // [[codegen::verbatim(ConstellationColorInfo.description)]] + std::optional> constellationColor; }; #include "renderableconstellationlines_codegen.cpp" } // namespace @@ -111,17 +113,17 @@ RenderableConstellationLines::RenderableConstellationLines( _drawElements.onChange([&]() { _hasSpeckFile = !_hasSpeckFile; }); addProperty(_drawElements); - if (p.unit.has_value()) { - _unit = codegen::map(*p.unit); + if (p.constellationUnit.has_value()) { + _constellationUnit = codegen::map(*p.constellationUnit); } else { - _unit = DistanceUnit::Meter; + _constellationUnit = DistanceUnit::Meter; } - if (p.meshColor.has_value()) { - std::vector ops = *p.meshColor; + if (p.constellationColor.has_value()) { + std::vector ops = *p.constellationColor; for (size_t i = 0; i < ops.size(); ++i) { - _meshColorMap.insert({ static_cast(i) + 1, ops[i] }); + _constellationColorMap.insert({ static_cast(i) + 1, ops[i] }); } } } @@ -129,13 +131,17 @@ RenderableConstellationLines::RenderableConstellationLines( void RenderableConstellationLines::selectionPropertyHasChanged() { // If no values are selected (the default), we want to show all constellations if (!_constellationSelection.hasSelected()) { - for (std::pair& pair : _renderingMeshesMap) { + for (std::pair& pair : + _renderingConstellationsMap) + { pair.second.isEnabled = true; } } else { // Enable all constellations that are selected - for (std::pair& pair : _renderingMeshesMap) { + for (std::pair& pair : + _renderingConstellationsMap) + { pair.second.isEnabled = _constellationSelection.isSelected(pair.second.identifier); } @@ -143,7 +149,7 @@ void RenderableConstellationLines::selectionPropertyHasChanged() { } bool RenderableConstellationLines::isReady() const { - return (_program != nullptr) && !_renderingMeshesMap.empty() && + return (_program != nullptr) && !_renderingConstellationsMap.empty() && !_labelset.entries.empty(); } @@ -157,44 +163,37 @@ void RenderableConstellationLines::initialize() { } void RenderableConstellationLines::initializeGL() { - _program = DigitalUniverseModule::ProgramObjectManager.request( + _program = global::renderEngine->buildRenderProgram( "RenderableConstellationLines", - []() { - return global::renderEngine->buildRenderProgram( - "RenderableConstellationLines", - absPath("${MODULE_SPACE}/shaders/constellationlines_vs.glsl"), - absPath("${MODULE_SPACE}/shaders/constellationlines_fs.glsl") - ); - } + absPath("${MODULE_SPACE}/shaders/constellationlines_vs.glsl"), + absPath("${MODULE_SPACE}/shaders/constellationlines_fs.glsl") ); ghoul::opengl::updateUniformLocations(*_program, _uniformCache, UniformNames); - createMeshes(); + createConstellations(); } void RenderableConstellationLines::deinitialize() { } void RenderableConstellationLines::deinitializeGL() { - for (const std::pair& pair : _renderingMeshesMap) { + for (const std::pair& pair : _renderingConstellationsMap) { for (int i = 0; i < pair.second.numU; ++i) { glDeleteVertexArrays(1, &pair.second.vaoArray[i]); glDeleteBuffers(1, &pair.second.vboArray[i]); } } - DigitalUniverseModule::ProgramObjectManager.release( - "RenderableConstellationLines", - [](ghoul::opengl::ProgramObject* p) { - global::renderEngine->removeRenderProgram(p); - } - ); + if (_program) { + global::renderEngine->removeRenderProgram(_program.get()); + _program = nullptr; + } } -void RenderableConstellationLines::renderMeshes(const RenderData&, - const glm::dmat4& modelViewMatrix, - const glm::dmat4& projectionMatrix) +void RenderableConstellationLines::renderConstellations(const RenderData&, + const glm::dmat4& modelViewMatrix, + const glm::dmat4& projectionMatrix) { glEnablei(GL_BLEND, 0); glBlendFunc(GL_SRC_ALPHA, GL_ONE); @@ -208,28 +207,24 @@ void RenderableConstellationLines::renderMeshes(const RenderData&, _program->setUniform(_uniformCache.projectionTransform, projectionMatrix); _program->setUniform(_uniformCache.alphaValue, opacity()); - for (const std::pair& pair : _renderingMeshesMap) { + for (const std::pair& pair : + _renderingConstellationsMap) + { if (!pair.second.isEnabled) { continue; } - _program->setUniform(_uniformCache.color, _meshColorMap[pair.second.colorIndex]); + _program->setUniform( + _uniformCache.color, + _constellationColorMap[pair.second.colorIndex] + ); for (size_t i = 0; i < pair.second.vaoArray.size(); ++i) { glBindVertexArray(pair.second.vaoArray[i]); - switch (pair.second.style) { - case Solid: - break; - case Wire: - glLineWidth(_lineWidth); - glDrawArrays(GL_LINE_STRIP, 0, pair.second.numV); - global::renderEngine->openglStateCache().resetLineState(); - break; - case Point: - glDrawArrays(GL_POINTS, 0, pair.second.numV); - break; - default: - break; - } + + // Always render as lines + glLineWidth(_lineWidth); + glDrawArrays(GL_LINE_STRIP, 0, pair.second.numV); + global::renderEngine->openglStateCache().resetLineState(); } } @@ -251,7 +246,7 @@ void RenderableConstellationLines::render(const RenderData& data, RendererTasks& const glm::dmat4 projectionMatrix = data.camera.projectionMatrix(); if (_hasSpeckFile) { - renderMeshes(data, modelViewMatrix, projectionMatrix); + renderConstellations(data, modelViewMatrix, projectionMatrix); } RenderableConstellation::render(data, tasks); @@ -286,10 +281,10 @@ bool RenderableConstellationLines::readSpeckFile() { return false; } - const float scale = static_cast(toMeter(_unit)); + const float scale = static_cast(toMeter(_constellationUnit)); double maxRadius = 0.0; - int meshIndex = 0; + int lineIndex = 0; // The beginning of the speck file has a header that either contains comments // (signaled by a preceding '#') or information about the structure of the file @@ -324,8 +319,8 @@ bool RenderableConstellationLines::readSpeckFile() { // and style is solid, wire or point (for now we support only wire) std::stringstream str(line); - RenderingMesh mesh; - mesh.meshIndex = meshIndex; + ConstellationLine constellationLine; + constellationLine.lineIndex = lineIndex; std::string dummy; str >> dummy; // mesh command @@ -334,28 +329,11 @@ bool RenderableConstellationLines::readSpeckFile() { do { if (dummy == "-t") { dummy.clear(); - str >> mesh.textureIndex; // texture index + str >> constellationLine.textureIndex; // texture index } else if (dummy == "-c") { dummy.clear(); - str >> mesh.colorIndex; // color index command - } - else if (dummy == "-s") { - dummy.clear(); - str >> dummy; // style value command - if (dummy == "solid") { - mesh.style = Solid; - } - else if (dummy == "wire") { - mesh.style = Wire; - } - else if (dummy == "point") { - mesh.style = Point; - } - else { - mesh.style = INVALID; - break; - } + str >> constellationLine.colorIndex; // color index command } dummy.clear(); str >> dummy; @@ -371,21 +349,21 @@ bool RenderableConstellationLines::readSpeckFile() { if (dummyU == "id") { ghoul::trimWhitespace(dummyV); - mesh.identifier = constellationFullName(dummyV); + constellationLine.identifier = constellationFullName(dummyV); // Dimensions are specified in the next line as usual std::getline(file, line); std::stringstream dim(line); - dim >> mesh.numU; // numU - dim >> mesh.numV; // numV + dim >> constellationLine.numU; // numU + dim >> constellationLine.numV; // numV } else { - mesh.numU = stoi(dummyU); - mesh.numV = stoi(dummyV); + constellationLine.numU = stoi(dummyU); + constellationLine.numV = stoi(dummyV); } // We can now read the vertices data: - for (int l = 0; l < mesh.numU * mesh.numV; ++l) { + for (int l = 0; l < constellationLine.numU * constellationLine.numV; ++l) { std::getline(file, line); if (line.substr(0, 1) == "}") { break; @@ -407,13 +385,13 @@ bool RenderableConstellationLines::readSpeckFile() { GLfloat scaledValue = value * scale; pos[i] = scaledValue; - mesh.vertices.push_back(scaledValue); + constellationLine.vertices.push_back(scaledValue); } if (!success) { LERROR(fmt::format( "Failed reading position on line {} of mesh {} in file: '{}'. " - "Stopped reading mesh data", l, meshIndex, _speckFile + "Stopped reading mesh data", l, lineIndex, _speckFile )); break; } @@ -440,7 +418,7 @@ bool RenderableConstellationLines::readSpeckFile() { std::getline(file, line); if (line.substr(0, 1) == "}") { - _renderingMeshesMap.insert({ meshIndex++, mesh }); + _renderingConstellationsMap.insert({ lineIndex++, constellationLine }); } else { return false; @@ -452,13 +430,13 @@ bool RenderableConstellationLines::readSpeckFile() { return true; } -void RenderableConstellationLines::createMeshes() { +void RenderableConstellationLines::createConstellations() { if (!(_dataIsDirty && _hasSpeckFile)) { return; } LDEBUG("Creating planes"); - for (std::pair& p : _renderingMeshesMap) { + for (std::pair& p : _renderingConstellationsMap) { for (int i = 0; i < p.second.numU; ++i) { GLuint vao; glGenVertexArrays(1, &vao); diff --git a/modules/space/rendering/renderableconstellationlines.h b/modules/space/rendering/renderableconstellationlines.h index 985ebaaac3..0742ce50c3 100644 --- a/modules/space/rendering/renderableconstellationlines.h +++ b/modules/space/rendering/renderableconstellationlines.h @@ -27,16 +27,6 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include @@ -69,15 +59,10 @@ public: static documentation::Documentation Documentation(); private: - enum MeshType { - Solid = 0, - Wire = 1, - Point = 2, - INVALID = 9 - }; - - struct RenderingMesh { - int meshIndex; + struct ConstellationLine { + bool isEnabled = true; + std::string identifier; + int lineIndex; int colorIndex; int textureIndex; // From: Partiview User's Guide @@ -90,47 +75,41 @@ private: // then numU numV will both equal 21 int numU; int numV; - MeshType style; std::vector vaoArray; std::vector vboArray; std::vector vertices; - bool isEnabled = true; - std::string identifier; }; - void createMeshes(); - void renderMeshes(const RenderData& data, const glm::dmat4& modelViewMatrix, + void createConstellations(); + void renderConstellations(const RenderData& data, const glm::dmat4& modelViewMatrix, const glm::dmat4& projectionMatrix); bool loadData(); bool readSpeckFile(); /** - * Callback method that gets triggered when _selectedMeshes - * changes. + * Callback method that gets triggered when _constellationSelection + * changes */ - void selectionPropertyHasChanged(); + void selectionPropertyHasChanged() override; bool _hasSpeckFile = false; bool _dataIsDirty = true; - bool _textColorIsDirty = true; - std::vector _assetSelectedMeshes; properties::BoolProperty _drawElements; - ghoul::opengl::ProgramObject* _program = nullptr; + std::unique_ptr _program = nullptr; UniformCache(modelViewTransform, projectionTransform, alphaValue, color) _uniformCache; - std::shared_ptr _font = nullptr; std::string _speckFile; - DistanceUnit _unit = DistanceUnit::Parsec; + DistanceUnit _constellationUnit = DistanceUnit::Parsec; std::vector _fullData; - std::unordered_map _meshColorMap; - std::unordered_map _renderingMeshesMap; + std::unordered_map _constellationColorMap; + std::unordered_map _renderingConstellationsMap; }; } // namespace openspace diff --git a/modules/space/shaders/constellationbounds_fs.glsl b/modules/space/shaders/constellationbounds_fs.glsl index 52237023b8..0d138b106d 100644 --- a/modules/space/shaders/constellationbounds_fs.glsl +++ b/modules/space/shaders/constellationbounds_fs.glsl @@ -28,13 +28,18 @@ in vec4 vs_position; uniform vec3 color; +uniform float alphaValue; Fragment getFragment() { - vec4 position = vs_position; - Fragment frag; - frag.color = vec4(color, 1.0); + if (alphaValue == 0.0) { + discard; + } + + vec4 position = vs_position; + + frag.color = vec4(color, alphaValue); frag.depth = pscDepth(position); return frag; From ceaf85f606f656acf9c0894428d1a70a6346b36d Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 9 Aug 2022 14:28:16 +0200 Subject: [PATCH 13/79] Some more cleanup --- .../rendering/renderableconstellation.cpp | 3 - .../renderableconstellationbounds.cpp | 2 - .../renderableconstellationlines.cpp | 209 ++++-------------- .../rendering/renderableconstellationlines.h | 6 +- 4 files changed, 40 insertions(+), 180 deletions(-) diff --git a/modules/space/rendering/renderableconstellation.cpp b/modules/space/rendering/renderableconstellation.cpp index 4d7c96b101..cd60d9cc17 100644 --- a/modules/space/rendering/renderableconstellation.cpp +++ b/modules/space/rendering/renderableconstellation.cpp @@ -25,7 +25,6 @@ #include #include -#include #include #include #include @@ -34,12 +33,10 @@ #include #include #include -#include #include #include #include #include -#include "SpiceUsr.h" namespace { constexpr int RenderOptionViewDirection = 0; diff --git a/modules/space/rendering/renderableconstellationbounds.cpp b/modules/space/rendering/renderableconstellationbounds.cpp index a0ac82f046..4d1756fa05 100644 --- a/modules/space/rendering/renderableconstellationbounds.cpp +++ b/modules/space/rendering/renderableconstellationbounds.cpp @@ -25,13 +25,11 @@ #include #include -#include #include #include #include #include #include -#include #include #include #include diff --git a/modules/space/rendering/renderableconstellationlines.cpp b/modules/space/rendering/renderableconstellationlines.cpp index 6f46b952c8..2e6e0456d5 100644 --- a/modules/space/rendering/renderableconstellationlines.cpp +++ b/modules/space/rendering/renderableconstellationlines.cpp @@ -25,25 +25,16 @@ #include #include -#include #include #include -#include #include #include #include -#include -#include #include -#include -#include #include #include #include -#include -#include #include -#include #include #include #include @@ -179,10 +170,8 @@ void RenderableConstellationLines::deinitialize() { void RenderableConstellationLines::deinitializeGL() { for (const std::pair& pair : _renderingConstellationsMap) { - for (int i = 0; i < pair.second.numU; ++i) { - glDeleteVertexArrays(1, &pair.second.vaoArray[i]); - glDeleteBuffers(1, &pair.second.vboArray[i]); - } + glDeleteVertexArrays(1, &pair.second.vaoArray); + glDeleteBuffers(1, &pair.second.vboArray); } if (_program) { @@ -197,7 +186,6 @@ void RenderableConstellationLines::renderConstellations(const RenderData&, { glEnablei(GL_BLEND, 0); glBlendFunc(GL_SRC_ALPHA, GL_ONE); - //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDepthMask(false); glEnable(GL_DEPTH_TEST); @@ -218,14 +206,12 @@ void RenderableConstellationLines::renderConstellations(const RenderData&, _uniformCache.color, _constellationColorMap[pair.second.colorIndex] ); - for (size_t i = 0; i < pair.second.vaoArray.size(); ++i) { - glBindVertexArray(pair.second.vaoArray[i]); - // Always render as lines - glLineWidth(_lineWidth); - glDrawArrays(GL_LINE_STRIP, 0, pair.second.numV); - global::renderEngine->openglStateCache().resetLineState(); - } + glBindVertexArray(pair.second.vaoArray); + + glLineWidth(_lineWidth); + glDrawArrays(GL_LINE_STRIP, 0, pair.second.numV); + global::renderEngine->openglStateCache().resetLineState(); } glBindVertexArray(0); @@ -327,11 +313,7 @@ bool RenderableConstellationLines::readSpeckFile() { dummy.clear(); str >> dummy; // texture index command? do { - if (dummy == "-t") { - dummy.clear(); - str >> constellationLine.textureIndex; // texture index - } - else if (dummy == "-c") { + if (dummy == "-c") { dummy.clear(); str >> constellationLine.colorIndex; // color index command } @@ -340,30 +322,23 @@ bool RenderableConstellationLines::readSpeckFile() { } while (dummy != "{"); std::getline(file, line); - std::stringstream dimOrName(line); - std::string dummyU, dummyV; - // Try to read name of mesh if it exist - dimOrName >> dummyU; // numU or "id" - std::getline(dimOrName, dummyV); // numV or the identifier of the mesh + // Read the identifier + std::stringstream name(line); + std::string identifier; - if (dummyU == "id") { - ghoul::trimWhitespace(dummyV); - constellationLine.identifier = constellationFullName(dummyV); + name >> dummy; + std::getline(name, identifier); + ghoul::trimWhitespace(identifier); + constellationLine.identifier = constellationFullName(identifier); - // Dimensions are specified in the next line as usual - std::getline(file, line); - std::stringstream dim(line); - dim >> constellationLine.numU; // numU - dim >> constellationLine.numV; // numV - } - else { - constellationLine.numU = stoi(dummyU); - constellationLine.numV = stoi(dummyV); - } + // Read the number of vertices + std::getline(file, line); + std::stringstream dim(line); + dim >> constellationLine.numV; // We can now read the vertices data: - for (int l = 0; l < constellationLine.numU * constellationLine.numV; ++l) { + for (int l = 0; l < constellationLine.numV; ++l) { std::getline(file, line); if (line.substr(0, 1) == "}") { break; @@ -399,21 +374,6 @@ bool RenderableConstellationLines::readSpeckFile() { // Check if new max radius const double r = glm::length(glm::dvec3(pos)); maxRadius = std::max(maxRadius, r); - - // OLD CODE: - // (2022-03-23, emmbr) None of our files included texture coordinates, - // and if they would they would still not be used by the shader - //for (int i = 0; i < 7; ++i) { - // GLfloat value; - // lineData >> value; - // bool errorReading = lineData.rdstate() & std::ifstream::failbit; - // if (!errorReading) { - // mesh.vertices.push_back(value); - // } - // else { - // break; - // } - //} } std::getline(file, line); @@ -434,121 +394,28 @@ void RenderableConstellationLines::createConstellations() { if (!(_dataIsDirty && _hasSpeckFile)) { return; } - LDEBUG("Creating planes"); + LDEBUG("Creating constellations"); for (std::pair& p : _renderingConstellationsMap) { - for (int i = 0; i < p.second.numU; ++i) { - GLuint vao; - glGenVertexArrays(1, &vao); - p.second.vaoArray.push_back(vao); + GLuint vao; + glGenVertexArrays(1, &vao); + p.second.vaoArray = vao; - GLuint vbo; - glGenBuffers(1, &vbo); - p.second.vboArray.push_back(vbo); + GLuint vbo; + glGenBuffers(1, &vbo); + p.second.vboArray = vbo; - glBindVertexArray(vao); - glBindBuffer(GL_ARRAY_BUFFER, vbo); - //glBufferData(GL_ARRAY_BUFFER, it->second.numV * sizeof(GLfloat), - glBufferData( - GL_ARRAY_BUFFER, - p.second.vertices.size() * sizeof(GLfloat), - &p.second.vertices[0], - GL_STATIC_DRAW - ); - // in_position - glEnableVertexAttribArray(0); - // (2022-03-23, emmbr) This code was actually never used. We only read three - // values per line and did not handle any texture cooridnates, even if there - // would have been some in the file - //// U and V may not be given by the user - //if (p.second.vertices.size() / (p.second.numU * p.second.numV) > 3) { - // glVertexAttribPointer( - // 0, - // 3, - // GL_FLOAT, - // GL_FALSE, - // sizeof(GLfloat) * 5, - // reinterpret_cast(sizeof(GLfloat) * i * p.second.numV) - // ); - - // // texture coords - // glEnableVertexAttribArray(1); - // glVertexAttribPointer( - // 1, - // 2, - // GL_FLOAT, - // GL_FALSE, - // sizeof(GLfloat) * 7, - // reinterpret_cast(sizeof(GLfloat) * 3 * i * p.second.numV) - // ); - //} - //else { // no U and V: - glVertexAttribPointer( - 0, - 3, - GL_FLOAT, - GL_FALSE, - 0, - reinterpret_cast(sizeof(GLfloat) * 3 * i * p.second.numV) - ); - //} - } - - // Grid: we need columns - if (p.second.numU > 1) { - for (int i = 0; i < p.second.numV; ++i) { - GLuint cvao; - glGenVertexArrays(1, &cvao); - p.second.vaoArray.push_back(cvao); - - GLuint cvbo; - glGenBuffers(1, &cvbo); - p.second.vboArray.push_back(cvbo); - - glBindVertexArray(cvao); - glBindBuffer(GL_ARRAY_BUFFER, cvbo); - glBufferData( - GL_ARRAY_BUFFER, - p.second.vertices.size() * sizeof(GLfloat), - &p.second.vertices[0], - GL_STATIC_DRAW - ); - // in_position - glEnableVertexAttribArray(0); - // U and V may not be given by the user - if (p.second.vertices.size() / (p.second.numU * p.second.numV) > 3) { - glVertexAttribPointer( - 0, - 3, - GL_FLOAT, - GL_FALSE, - p.second.numV * sizeof(GLfloat) * 5, - reinterpret_cast(sizeof(GLfloat) * i) - ); - - // texture coords - glEnableVertexAttribArray(1); - glVertexAttribPointer( - 1, - 2, - GL_FLOAT, - GL_FALSE, - p.second.numV * sizeof(GLfloat) * 7, - reinterpret_cast(sizeof(GLfloat) * 3 * i) - ); - } - else { // no U and V: - glVertexAttribPointer( - 0, - 3, - GL_FLOAT, - GL_FALSE, - p.second.numV * sizeof(GLfloat) * 3, - reinterpret_cast(sizeof(GLfloat) * 3 * i) - ); - } - } - } + glBindVertexArray(vao); + glBindBuffer(GL_ARRAY_BUFFER, vbo); + glBufferData( + GL_ARRAY_BUFFER, + p.second.vertices.size() * sizeof(GLfloat), + p.second.vertices.data(), + GL_STATIC_DRAW + ); + // in_position + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr); } glBindVertexArray(0); diff --git a/modules/space/rendering/renderableconstellationlines.h b/modules/space/rendering/renderableconstellationlines.h index 0742ce50c3..f99a286729 100644 --- a/modules/space/rendering/renderableconstellationlines.h +++ b/modules/space/rendering/renderableconstellationlines.h @@ -64,7 +64,6 @@ private: std::string identifier; int lineIndex; int colorIndex; - int textureIndex; // From: Partiview User's Guide // Brian Abbott // Hayden Planetarium American Museum of Natural History New York, USA @@ -73,10 +72,9 @@ private: // numV will equal the number of points to connect. // If you want a square, 4000×4000 grid with lines every 200 units, // then numU numV will both equal 21 - int numU; int numV; - std::vector vaoArray; - std::vector vboArray; + GLuint vaoArray; + GLuint vboArray; std::vector vertices; }; From 87a45e7376f1f05dd70ac21df4f5cf735d48a42a Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 9 Aug 2022 17:01:41 +0200 Subject: [PATCH 14/79] Fix asset selection of constellations --- .../digitaluniverse/constellationbounds.asset | 4 +-- .../digitaluniverse/constellations.asset | 8 +++--- .../rendering/renderableconstellation.cpp | 20 -------------- .../space/rendering/renderableconstellation.h | 9 ++++--- .../renderableconstellationbounds.cpp | 23 +++++++++++++--- .../rendering/renderableconstellationbounds.h | 1 - .../renderableconstellationlines.cpp | 27 ++++++++++++++++--- .../rendering/renderableconstellationlines.h | 1 - .../space/shaders/constellationlines_fs.glsl | 3 +-- 9 files changed, 55 insertions(+), 41 deletions(-) diff --git a/data/assets/scene/digitaluniverse/constellationbounds.asset b/data/assets/scene/digitaluniverse/constellationbounds.asset index 273fad59da..f3ce0deb86 100644 --- a/data/assets/scene/digitaluniverse/constellationbounds.asset +++ b/data/assets/scene/digitaluniverse/constellationbounds.asset @@ -1,7 +1,7 @@ local data = asset.syncedResource({ - Name = "Constellation Bounds Data", + Name = "Constellation Files", Type = "HttpSynchronization", - Identifier = "digitaluniverse_constellationbounds_data", + Identifier = "digitaluniverse_constellations_data", Version = 1 }) diff --git a/data/assets/scene/digitaluniverse/constellations.asset b/data/assets/scene/digitaluniverse/constellations.asset index 62f4d4f1e8..9515e8fb29 100644 --- a/data/assets/scene/digitaluniverse/constellations.asset +++ b/data/assets/scene/digitaluniverse/constellations.asset @@ -1,8 +1,8 @@ local speck = asset.syncedResource({ - Name = "Constellation Speck Files", + Name = "Constellation Files", Type = "HttpSynchronization", - Identifier = "digitaluniverse_constellations_speck", - Version = 2 + Identifier = "digitaluniverse_constellations_data", + Version = 1 }) local constellationsExtragalactic = { @@ -34,7 +34,7 @@ local constellations = { Opacity = 0.3, File = speck .. "constellations.speck", LabelFile = speck .. "constellations.label", - ConstellationNamesFile = "C:/Users/malej60/Documents/Sync/http/digitaluniverse_constellationbounds_data/1/constellations.dat", + ConstellationNamesFile = speck .. "constellations.dat", TextColor = { 0.8, 0.8, 0.8 }, TextOpacity = 0.3, TextSize = 14.5, diff --git a/modules/space/rendering/renderableconstellation.cpp b/modules/space/rendering/renderableconstellation.cpp index cd60d9cc17..eaf49d7bf3 100644 --- a/modules/space/rendering/renderableconstellation.cpp +++ b/modules/space/rendering/renderableconstellation.cpp @@ -300,26 +300,6 @@ void RenderableConstellation::fillSelectionProperty() { void RenderableConstellation::initialize() { loadConstellationFile(); - if (!_assetSelectedConstellations.empty()) { - const std::vector options = _constellationSelection.options(); - std::set selectedConstellations; - - for (const std::string& s : _assetSelectedConstellations) { - const auto it = std::find(options.begin(), options.end(), s); - if (it == options.end()) { - // The user has specified a mesh name that doesn't exist - LWARNINGC( - "RenderableConstellation", - fmt::format("Option '{}' not found in list of meshes", s) - ); - } - else { - selectedConstellations.insert(s); - } - } - _constellationSelection = selectedConstellations; - } - if (!_hasLabel) { return; } diff --git a/modules/space/rendering/renderableconstellation.h b/modules/space/rendering/renderableconstellation.h index 514cffe511..2fed346b4e 100644 --- a/modules/space/rendering/renderableconstellation.h +++ b/modules/space/rendering/renderableconstellation.h @@ -50,7 +50,6 @@ public: virtual void initialize() override; virtual void initializeGL() override = 0; - virtual void deinitialize() override = 0; virtual void deinitializeGL() override = 0; virtual bool isReady() const override = 0; @@ -81,6 +80,10 @@ protected: // Property that stores all constellations chosen by the user to be drawn properties::SelectionProperty _constellationSelection; + // Temporary storage of which constellations should be rendered as stated in the + // asset file + std::vector _assetSelectedConstellations; + // Label text settings bool _hasLabel = false; speck::Labelset _labelset; @@ -91,9 +94,7 @@ private: // key = abbreviation, value = full name std::map _constellationNamesTranslation; - // Temporary storage of which constellations should be rendered as stated in the - // asset file - std::vector _assetSelectedConstellations; + /** * Loads the file specified in _constellationNamesFilename that contains diff --git a/modules/space/rendering/renderableconstellationbounds.cpp b/modules/space/rendering/renderableconstellationbounds.cpp index 4d1756fa05..df3aab3106 100644 --- a/modules/space/rendering/renderableconstellationbounds.cpp +++ b/modules/space/rendering/renderableconstellationbounds.cpp @@ -93,6 +93,26 @@ void RenderableConstellationBounds::initialize() { RenderableConstellation::initialize(); loadVertexFile(); + + if (!_assetSelectedConstellations.empty()) { + const std::vector options = _constellationSelection.options(); + std::set selectedConstellations; + + for (const std::string& s : _assetSelectedConstellations) { + const auto it = std::find(options.begin(), options.end(), s); + if (it == options.end()) { + // The user has specified a mesh name that doesn't exist + LWARNINGC( + "RenderableConstellation", + fmt::format("Option '{}' not found in list of meshes", s) + ); + } + else { + selectedConstellations.insert(s); + } + } + _constellationSelection = selectedConstellations; + } } void RenderableConstellationBounds::initializeGL() { @@ -121,9 +141,6 @@ void RenderableConstellationBounds::initializeGL() { glBindVertexArray(0); } -void RenderableConstellationBounds::deinitialize() { -} - void RenderableConstellationBounds::deinitializeGL() { glDeleteBuffers(1, &_vbo); _vbo = 0; diff --git a/modules/space/rendering/renderableconstellationbounds.h b/modules/space/rendering/renderableconstellationbounds.h index eacb03aca9..3925e37c6e 100644 --- a/modules/space/rendering/renderableconstellationbounds.h +++ b/modules/space/rendering/renderableconstellationbounds.h @@ -48,7 +48,6 @@ public: void initialize() override; void initializeGL() override; - void deinitialize() override; void deinitializeGL() override; bool isReady() const override; diff --git a/modules/space/rendering/renderableconstellationlines.cpp b/modules/space/rendering/renderableconstellationlines.cpp index 2e6e0456d5..8aea735267 100644 --- a/modules/space/rendering/renderableconstellationlines.cpp +++ b/modules/space/rendering/renderableconstellationlines.cpp @@ -151,6 +151,26 @@ void RenderableConstellationLines::initialize() { if (!success) { throw ghoul::RuntimeError("Error loading data"); } + + if (!_assetSelectedConstellations.empty()) { + const std::vector options = _constellationSelection.options(); + std::set selectedConstellations; + + for (const std::string& s : _assetSelectedConstellations) { + const auto it = std::find(options.begin(), options.end(), s); + if (it == options.end()) { + // The user has specified a mesh name that doesn't exist + LWARNINGC( + "RenderableConstellation", + fmt::format("Option '{}' not found in list of meshes", s) + ); + } + else { + selectedConstellations.insert(s); + } + } + _constellationSelection = selectedConstellations; + } } void RenderableConstellationLines::initializeGL() { @@ -165,11 +185,10 @@ void RenderableConstellationLines::initializeGL() { createConstellations(); } -void RenderableConstellationLines::deinitialize() { -} - void RenderableConstellationLines::deinitializeGL() { - for (const std::pair& pair : _renderingConstellationsMap) { + for (const std::pair& pair : + _renderingConstellationsMap) + { glDeleteVertexArrays(1, &pair.second.vaoArray); glDeleteBuffers(1, &pair.second.vboArray); } diff --git a/modules/space/rendering/renderableconstellationlines.h b/modules/space/rendering/renderableconstellationlines.h index f99a286729..f10c359974 100644 --- a/modules/space/rendering/renderableconstellationlines.h +++ b/modules/space/rendering/renderableconstellationlines.h @@ -48,7 +48,6 @@ public: void initialize() override; void initializeGL() override; - void deinitialize() override; void deinitializeGL() override; bool isReady() const override; diff --git a/modules/space/shaders/constellationlines_fs.glsl b/modules/space/shaders/constellationlines_fs.glsl index 243d5c66a5..f8cfcda68d 100644 --- a/modules/space/shaders/constellationlines_fs.glsl +++ b/modules/space/shaders/constellationlines_fs.glsl @@ -33,7 +33,6 @@ uniform float alphaValue; Fragment getFragment() { Fragment frag; - if (alphaValue == 0.0) { discard; } @@ -44,6 +43,6 @@ Fragment getFragment() { // JCC: Need to change the position to camera space frag.gPosition = vs_positionViewSpace; frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0); - + return frag; } From 5bdd3d0f8c4b17c6f904ce55a1a33ad65596145a Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 10 Aug 2022 13:57:47 +0200 Subject: [PATCH 15/79] Make the Constellations name file optional --- .../digitaluniverse/constellationbounds.asset | 4 +-- .../digitaluniverse/constellations.asset | 18 ++++++++---- .../rendering/renderableconstellation.cpp | 29 ++++++++++++------- .../space/rendering/renderableconstellation.h | 2 -- .../renderableconstellationbounds.cpp | 7 +++-- .../renderableconstellationlines.cpp | 23 ++++++++------- .../rendering/renderableconstellationlines.h | 10 +------ 7 files changed, 50 insertions(+), 43 deletions(-) diff --git a/data/assets/scene/digitaluniverse/constellationbounds.asset b/data/assets/scene/digitaluniverse/constellationbounds.asset index f3ce0deb86..4003e15b39 100644 --- a/data/assets/scene/digitaluniverse/constellationbounds.asset +++ b/data/assets/scene/digitaluniverse/constellationbounds.asset @@ -16,7 +16,7 @@ local object = { Type = "RenderableConstellationBounds", Enabled = false, File = data .. "bound_20.dat", - ConstellationNamesFile = data .. "constellations.dat" + ConstellationNamesFile = data .. "constellations.dat", -- ConstellationSelection = zodiacs }, Transform = { @@ -52,7 +52,7 @@ asset.export(object) asset.meta = { Name = "Constellation Bounds", - Version = "1.1", + Version = "1.2", Description = [[DU asset providing a Spherical mesh dividing the sky into regions that fit the constellations]], Author = "Brian Abbott (AMNH)", diff --git a/data/assets/scene/digitaluniverse/constellations.asset b/data/assets/scene/digitaluniverse/constellations.asset index 9515e8fb29..401f9ae594 100644 --- a/data/assets/scene/digitaluniverse/constellations.asset +++ b/data/assets/scene/digitaluniverse/constellations.asset @@ -5,6 +5,11 @@ local speck = asset.syncedResource({ Version = 1 }) +local zodiacs = { + "Cancer", "Taurus", "Pisces", "Aries", "Libra", "Aquarius", "Capricornus", "Scorpius", + "Virgo", "Sagittarius", "Gemini", "Leo" +} + local constellationsExtragalactic = { Identifier = "ConstellationsExtragalactic", Renderable = { @@ -39,12 +44,13 @@ local constellations = { TextOpacity = 0.3, TextSize = 14.5, TextMinMaxSize = { 8, 170 }, - LabelUnit = "pc", ConstellationColor = { { 0.6, 0.4, 0.4 }, { 0.8, 0.0, 0.0 }, { 0.0, 0.3, 0.8 } }, - ConstellationUnit = "pc" + LabelUnit = "pc", + ConstellationUnit = "pc", + -- ConstellationSelection = zodiacs }, GUI = { - Name = "Constellations", + Name = "Constellations", Path = "/Milky Way/Constellations", Description = [[Census 88 constellations and labels. DU Version 2.3.
These modern constellations are largely based on those of the Babylonians and @@ -62,12 +68,12 @@ asset.onInitialize(function() openspace.addSceneGraphNode(constellationsExtragalactic) openspace.addSceneGraphNode(constellations) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(constellations) openspace.removeSceneGraphNode(constellationsExtragalactic) end) - + asset.export(constellationsExtragalactic) asset.export(constellations) @@ -75,7 +81,7 @@ asset.export(constellations) asset.meta = { Name = "Constellations", - Version = "1.1", + Version = "1.2", Description = "Digital Universe asset for constellation lines", Author = "Brian Abbott (AMNH)", URL = "https://www.amnh.org/research/hayden-planetarium/digital-universe", diff --git a/modules/space/rendering/renderableconstellation.cpp b/modules/space/rendering/renderableconstellation.cpp index eaf49d7bf3..bd483546f7 100644 --- a/modules/space/rendering/renderableconstellation.cpp +++ b/modules/space/rendering/renderableconstellation.cpp @@ -45,7 +45,7 @@ namespace { constexpr openspace::properties::Property::PropertyInfo TextColorInfo = { "TextColor", "Text Color", - "The text color for the astronomical object" + "The text color of the labels for the constellations" }; constexpr openspace::properties::Property::PropertyInfo TextOpacityInfo = { @@ -58,28 +58,27 @@ namespace { constexpr openspace::properties::Property::PropertyInfo TextSizeInfo = { "TextSize", "Text Size", - "The text size for the astronomical object labels" + "The text size of the labels for the constellations" }; constexpr openspace::properties::Property::PropertyInfo LabelFileInfo = { "LabelFile", "Label File", - "The path to the label file that contains information about the astronomical " - "objects being rendered" + "The path to the label file that contains information about the constellations" }; constexpr openspace::properties::Property::PropertyInfo LabelMinMaxSizeInfo = { "TextMinMaxSize", "Text Min/Max Size", - "The minimum and maximum size (in pixels) of the text for the labels for the " - "astronomical objects being rendered" + "The minimum and maximum size (in pixels) for the text of the labels for the " + "constellations" }; constexpr openspace::properties::Property::PropertyInfo ConstellationInfo = { "ConstellationFile", "Constellation File Path", "Specifies the file that contains the mapping between constellation " - "abbreviations and full name of the constellation. If this value is empty, the " + "abbreviations and full names of the constellations. If this value is empty, the " "abbreviations are used as the full names" }; @@ -118,7 +117,7 @@ namespace { std::optional drawLabels; // [[codegen::verbatim(ConstellationInfo.description)]] - std::string constellationNamesFile; + std::optional constellationNamesFile; // [[codegen::verbatim(TextColorInfo.description)]] std::optional textColor [[codegen::color()]]; @@ -197,7 +196,8 @@ RenderableConstellation::RenderableConstellation(const ghoul::Dictionary& dictio addProperty(_renderOption); // Read all files in the initialize() instead, multithreaded - _constellationNamesFilename = p.constellationNamesFile; + _constellationNamesFilename = + p.constellationNamesFile.value_or(_constellationNamesFilename); _constellationNamesFilename.onChange([&]() { loadConstellationFile(); }); addProperty(_constellationNamesFilename); @@ -244,6 +244,12 @@ RenderableConstellation::RenderableConstellation(const ghoul::Dictionary& dictio std::string RenderableConstellation::constellationFullName( const std::string& identifier) const { + if (_constellationNamesTranslation.empty() || identifier.empty()) { + std::string message = "List of constellations or the given identifier was empty"; + LWARNINGC("RenderableConstellation", message); + return ""; + } + try { return _constellationNamesTranslation.at(identifier); } @@ -321,7 +327,10 @@ void RenderableConstellation::initialize() { for (speck::Labelset::Entry& entry : _labelset.entries) { if (!entry.identifier.empty()) { - entry.text = constellationFullName(entry.identifier); + std::string fullName = constellationFullName(entry.identifier); + if (!fullName.empty()) { + entry.text = fullName; + } } } } diff --git a/modules/space/rendering/renderableconstellation.h b/modules/space/rendering/renderableconstellation.h index 2fed346b4e..7d2a88f14c 100644 --- a/modules/space/rendering/renderableconstellation.h +++ b/modules/space/rendering/renderableconstellation.h @@ -94,8 +94,6 @@ private: // key = abbreviation, value = full name std::map _constellationNamesTranslation; - - /** * Loads the file specified in _constellationNamesFilename that contains * the mapping between abbreviations and full names of constellations diff --git a/modules/space/rendering/renderableconstellationbounds.cpp b/modules/space/rendering/renderableconstellationbounds.cpp index df3aab3106..24bf422786 100644 --- a/modules/space/rendering/renderableconstellationbounds.cpp +++ b/modules/space/rendering/renderableconstellationbounds.cpp @@ -101,10 +101,10 @@ void RenderableConstellationBounds::initialize() { for (const std::string& s : _assetSelectedConstellations) { const auto it = std::find(options.begin(), options.end(), s); if (it == options.end()) { - // The user has specified a mesh name that doesn't exist + // The user has specified a constellation name that doesn't exist LWARNINGC( "RenderableConstellation", - fmt::format("Option '{}' not found in list of meshes", s) + fmt::format("Option '{}' not found in list of constellations", s) ); } else { @@ -258,7 +258,8 @@ bool RenderableConstellationBounds::loadVertexFile() { currentBound = ConstellationBound(); currentBound.isEnabled = true; currentBound.constellationAbbreviation = abbreviation; - currentBound.constellationFullName = constellationFullName(abbreviation); + std::string name = constellationFullName(abbreviation); + currentBound.constellationFullName = name.empty() ? abbreviation : name; currentBound.startIndex = static_cast(_vertexValues.size()); } diff --git a/modules/space/rendering/renderableconstellationlines.cpp b/modules/space/rendering/renderableconstellationlines.cpp index 8aea735267..c2ac4b2dc1 100644 --- a/modules/space/rendering/renderableconstellationlines.cpp +++ b/modules/space/rendering/renderableconstellationlines.cpp @@ -134,7 +134,7 @@ void RenderableConstellationLines::selectionPropertyHasChanged() { _renderingConstellationsMap) { pair.second.isEnabled = - _constellationSelection.isSelected(pair.second.identifier); + _constellationSelection.isSelected(pair.second.name); } } } @@ -159,10 +159,10 @@ void RenderableConstellationLines::initialize() { for (const std::string& s : _assetSelectedConstellations) { const auto it = std::find(options.begin(), options.end(), s); if (it == options.end()) { - // The user has specified a mesh name that doesn't exist + // The user has specified a constellation name that doesn't exist LWARNINGC( "RenderableConstellation", - fmt::format("Option '{}' not found in list of meshes", s) + fmt::format("Option '{}' not found in list of constellations", s) ); } else { @@ -318,10 +318,8 @@ bool RenderableConstellationLines::readSpeckFile() { } else { // mesh lines are structured as follows: - // mesh -t texnum -c colorindex -s style { - // where textnum is the index of the texture; + // mesh -c colorindex { // colorindex is the index of the color for the mesh - // and style is solid, wire or point (for now we support only wire) std::stringstream str(line); ConstellationLine constellationLine; @@ -343,13 +341,16 @@ bool RenderableConstellationLines::readSpeckFile() { std::getline(file, line); // Read the identifier - std::stringstream name(line); + std::stringstream id(line); std::string identifier; - name >> dummy; - std::getline(name, identifier); + id >> dummy; + std::getline(id, identifier); ghoul::trimWhitespace(identifier); - constellationLine.identifier = constellationFullName(identifier); + std::string name = constellationFullName(identifier); + if (!name.empty()) { + constellationLine.name = name; + } // Read the number of vertices std::getline(file, line); @@ -385,7 +386,7 @@ bool RenderableConstellationLines::readSpeckFile() { if (!success) { LERROR(fmt::format( "Failed reading position on line {} of mesh {} in file: '{}'. " - "Stopped reading mesh data", l, lineIndex, _speckFile + "Stopped reading constellation data", l, lineIndex, _speckFile )); break; } diff --git a/modules/space/rendering/renderableconstellationlines.h b/modules/space/rendering/renderableconstellationlines.h index f10c359974..e9fb792a6e 100644 --- a/modules/space/rendering/renderableconstellationlines.h +++ b/modules/space/rendering/renderableconstellationlines.h @@ -60,17 +60,9 @@ public: private: struct ConstellationLine { bool isEnabled = true; - std::string identifier; + std::string name; int lineIndex; int colorIndex; - // From: Partiview User's Guide - // Brian Abbott - // Hayden Planetarium American Museum of Natural History New York, USA - // "Specifies the dimensions of the mesh" - // "If you wish to draw a line between points, then numU will be 1 while - // numV will equal the number of points to connect. - // If you want a square, 4000×4000 grid with lines every 200 units, - // then numU numV will both equal 21 int numV; GLuint vaoArray; GLuint vboArray; From 15533a76662c924d1f9c30fe8949665c36a7e79b Mon Sep 17 00:00:00 2001 From: Malin E Date: Mon, 15 Aug 2022 18:09:22 +0200 Subject: [PATCH 16/79] Initial working version --- .../solarsystem/missions/jwst/trail.asset | 40 ++++++++++++++++++- .../planets/earth/lagrange_points/L2.asset | 36 +++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/data/assets/scene/solarsystem/missions/jwst/trail.asset b/data/assets/scene/solarsystem/missions/jwst/trail.asset index 15fb544305..b91a92288e 100644 --- a/data/assets/scene/solarsystem/missions/jwst/trail.asset +++ b/data/assets/scene/solarsystem/missions/jwst/trail.asset @@ -7,7 +7,7 @@ local kernels = asset.syncedResource({ Name = "JWST Kernel", Type = "HttpSynchronization", Identifier = "jwst_kernels", - Version = 2 + Version = 3 }) local launchTime = "2021 DEC 25 12:20:00" @@ -85,7 +85,7 @@ local JWSTTrailCruise = { -- Gives a better trail history of the orbit around L2 than if it was relative to Earth local JWSTTrailOrbit = { Identifier = "JWSTTrailOrbit", - Parent = transforms.L2.Identifier, + Parent = transforms.L2Position.Identifier, TimeFrame = { Type = "TimeFrameInterval", Start = L2orbitInsertionTime, @@ -113,6 +113,39 @@ local JWSTTrailOrbit = { } } +local JWSTTrailCoOrbit = { + Identifier = "JWSTTrailCoOrbit", + Parent = transforms.L2CoRotFrame.Identifier, + TimeFrame = { + Type = "TimeFrameInterval", + Start = L2orbitInsertionTime, + End = endTime + }, + Renderable = { + Type = "RenderableTrailOrbit", + Translation = { + Type = 'SpiceTranslation', + Target = 170, -- JWST + Observer = 392, -- L2 + Frame = 'L2_COROT', + Kernels = { + kernels .. "webb.bsp", + kernels .. "l2_corot.tf" + } + }, + Color = { 0.0, 0.9, 0.9 }, + Period = 182.621099, -- About 6 months + Resolution = 183 -- About a sample rate of once per day + }, + GUI = { + Name = "JWST L2 Co Orbit Trail", + Path = "/Solar System/Missions/JWST/Trails", + Description = [[ + James Webb Space Telescope Orbit Trail co-revolving with L2. + ]], + } +} + local JWSTSunTrail = { Identifier = "JWSTSunTrail", Parent = sunTransforms.SolarSystemBarycenter.Identifier, @@ -147,11 +180,13 @@ asset.onInitialize(function() openspace.addSceneGraphNode(JWSTTrailLaunch) openspace.addSceneGraphNode(JWSTTrailCruise) openspace.addSceneGraphNode(JWSTTrailOrbit) + openspace.addSceneGraphNode(JWSTTrailCoOrbit) openspace.addSceneGraphNode(JWSTSunTrail) end) asset.onDeinitialize(function() openspace.removeSceneGraphNode(JWSTSunTrail) + openspace.removeSceneGraphNode(JWSTTrailCoOrbit) openspace.removeSceneGraphNode(JWSTTrailOrbit) openspace.removeSceneGraphNode(JWSTTrailCruise) openspace.removeSceneGraphNode(JWSTTrailLaunch) @@ -160,6 +195,7 @@ end) asset.export(JWSTTrailLaunch) asset.export(JWSTTrailCruise) asset.export(JWSTTrailOrbit) +asset.export(JWSTTrailCoOrbit) asset.export(JWSTSunTrail) diff --git a/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset b/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset index 62a317284a..39ad74349e 100644 --- a/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset +++ b/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset @@ -15,6 +15,13 @@ local kernels = asset.syncedResource({ Version = 1 }) +local corotkernels = asset.syncedResource({ + Name = "JWST Kernel", + Type = "HttpSynchronization", + Identifier = "jwst_kernels", + Version = 3 +}) + local L2Position = { Identifier = "L2Position", Parent = transforms.SolarSystemBarycenter.Identifier, @@ -34,6 +41,34 @@ local L2Position = { } } +local L2CoRotFrame = { + Identifier = "L2CoRotFrame", + Parent = transforms.SolarSystemBarycenter.Identifier, + Transform = { + Translation = { + Type = "SpiceTranslation", + Target = 392, -- L2 + Observer = "SSB", + Kernels = kernels .. "L2_de431.bsp" + }, + Rotation = { + Type = "SpiceRotation", + SourceFrame = "L2_COROT", + DestinationFrame = 'GALACTIC', + Kernels = { + kernels .. "L2_de431.bsp", + corotkernels .. "l2_corot.tf" + } + } + }, + Tag = { "lagrange_points_earth", "lagrange_points_earth_l2" }, + GUI = { + Name = "L2 CoRot Position", + Path = "/Solar System/Planets/Earth/Lagrange points", + Hidden = true + } +} + local L2Small = { Identifier = "L2Small", Parent = L2Position.Identifier, @@ -131,6 +166,7 @@ local L2SunLine = { local nodes = { L2Position, + L2CoRotFrame, L2Small, L2, L2SunLine, From 8a865bde1032137f938a78faa93895f46c2042f7 Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 16 Aug 2022 11:16:05 +0200 Subject: [PATCH 17/79] Clean up --- .../solarsystem/missions/jwst/trail.asset | 23 ++++++++----------- .../planets/earth/lagrange_points/L2.asset | 13 +++-------- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/data/assets/scene/solarsystem/missions/jwst/trail.asset b/data/assets/scene/solarsystem/missions/jwst/trail.asset index b91a92288e..a3adf09bde 100644 --- a/data/assets/scene/solarsystem/missions/jwst/trail.asset +++ b/data/assets/scene/solarsystem/missions/jwst/trail.asset @@ -7,7 +7,7 @@ local kernels = asset.syncedResource({ Name = "JWST Kernel", Type = "HttpSynchronization", Identifier = "jwst_kernels", - Version = 3 + Version = 2 }) local launchTime = "2021 DEC 25 12:20:00" @@ -113,8 +113,8 @@ local JWSTTrailOrbit = { } } -local JWSTTrailCoOrbit = { - Identifier = "JWSTTrailCoOrbit", +local JWSTTrailCoRotOrbit = { + Identifier = "JWSTTrailCoRotOrbit", Parent = transforms.L2CoRotFrame.Identifier, TimeFrame = { Type = "TimeFrameInterval", @@ -128,20 +128,17 @@ local JWSTTrailCoOrbit = { Target = 170, -- JWST Observer = 392, -- L2 Frame = 'L2_COROT', - Kernels = { - kernels .. "webb.bsp", - kernels .. "l2_corot.tf" - } + Kernels = { kernels .. "webb.bsp" } }, Color = { 0.0, 0.9, 0.9 }, Period = 182.621099, -- About 6 months Resolution = 183 -- About a sample rate of once per day }, GUI = { - Name = "JWST L2 Co Orbit Trail", + Name = "JWST L2 Co-rotating Orbit Trail", Path = "/Solar System/Missions/JWST/Trails", Description = [[ - James Webb Space Telescope Orbit Trail co-revolving with L2. + James Webb Space Telescope Orbit Trail that Co-rotates with L2. ]], } } @@ -180,13 +177,13 @@ asset.onInitialize(function() openspace.addSceneGraphNode(JWSTTrailLaunch) openspace.addSceneGraphNode(JWSTTrailCruise) openspace.addSceneGraphNode(JWSTTrailOrbit) - openspace.addSceneGraphNode(JWSTTrailCoOrbit) + openspace.addSceneGraphNode(JWSTTrailCoRotOrbit) openspace.addSceneGraphNode(JWSTSunTrail) end) asset.onDeinitialize(function() openspace.removeSceneGraphNode(JWSTSunTrail) - openspace.removeSceneGraphNode(JWSTTrailCoOrbit) + openspace.removeSceneGraphNode(JWSTTrailCoRotOrbit) openspace.removeSceneGraphNode(JWSTTrailOrbit) openspace.removeSceneGraphNode(JWSTTrailCruise) openspace.removeSceneGraphNode(JWSTTrailLaunch) @@ -195,7 +192,7 @@ end) asset.export(JWSTTrailLaunch) asset.export(JWSTTrailCruise) asset.export(JWSTTrailOrbit) -asset.export(JWSTTrailCoOrbit) +asset.export(JWSTTrailCoRotOrbit) asset.export(JWSTSunTrail) @@ -203,7 +200,7 @@ asset.meta = { Name = "James Webb Space Telescope Trails", Version = "1.0", Description = [[ - Trail of James Webb Space Telescope in respect to Earth, L2 and the Sun + Trail of James Webb Space Telescope in respect to Earth, L2, and the Sun ]], Author = "OpenSpace Team", URL = "http://openspaceproject.com", diff --git a/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset b/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset index 39ad74349e..85a87561dd 100644 --- a/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset +++ b/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset @@ -12,14 +12,7 @@ local kernels = asset.syncedResource({ Name = "Lagrange Kernels", Type = "HttpSynchronization", Identifier = "earth_lagrange_kernels", - Version = 1 -}) - -local corotkernels = asset.syncedResource({ - Name = "JWST Kernel", - Type = "HttpSynchronization", - Identifier = "jwst_kernels", - Version = 3 + Version = 2 }) local L2Position = { @@ -57,13 +50,13 @@ local L2CoRotFrame = { DestinationFrame = 'GALACTIC', Kernels = { kernels .. "L2_de431.bsp", - corotkernels .. "l2_corot.tf" + kernels .. "L2_corot.tf" } } }, Tag = { "lagrange_points_earth", "lagrange_points_earth_l2" }, GUI = { - Name = "L2 CoRot Position", + Name = "L2 Co-rotation Frame", Path = "/Solar System/Planets/Earth/Lagrange points", Hidden = true } From 460b849361250a7f695662abbbc7faa55bc74e2f Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 16 Aug 2022 11:45:36 +0200 Subject: [PATCH 18/79] Make L2 co-rot trail turn on/off together with the other JWST trails --- .../scene/solarsystem/missions/jwst/toggle_trail.asset | 8 +++++++- .../assets/scene/solarsystem/missions/jwst/trail.asset | 5 ++++- .../solarsystem/planets/earth/lagrange_points/L2.asset | 10 +++------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/data/assets/scene/solarsystem/missions/jwst/toggle_trail.asset b/data/assets/scene/solarsystem/missions/jwst/toggle_trail.asset index 9f8d42dc16..6360f6283c 100644 --- a/data/assets/scene/solarsystem/missions/jwst/toggle_trail.asset +++ b/data/assets/scene/solarsystem/missions/jwst/toggle_trail.asset @@ -17,6 +17,7 @@ local toggle_trail = { local launchTrail = "JWSTTrailLaunch" local cruiseTrail = "JWSTTrailCruise" local orbitTrail = "JWSTTrailOrbit" + local coOrbitTrail = "JWSTTrailCoRotOrbit" local visibility if is_declared("args") then @@ -31,7 +32,8 @@ local toggle_trail = { visibility = not ( openspace.getPropertyValue("Scene." .. launchTrail .. ".Renderable.Enabled") or openspace.getPropertyValue("Scene." .. cruiseTrail .. ".Renderable.Enabled") or - openspace.getPropertyValue("Scene." .. orbitTrail .. ".Renderable.Enabled") + openspace.getPropertyValue("Scene." .. orbitTrail .. ".Renderable.Enabled") or + openspace.getPropertyValue("Scene." .. coOrbitTrail .. ".Renderable.Enabled") ) end @@ -47,6 +49,10 @@ local toggle_trail = { "Scene." .. orbitTrail .. ".Renderable.Enabled", visibility ) + openspace.setPropertyValueSingle( + "Scene." .. coOrbitTrail .. ".Renderable.Enabled", + visibility + ) ]], Documentation = [[Toggles the visibility of the JWST trail with an approaching/exiting event. This action takes optional arguments to 1) determine which diff --git a/data/assets/scene/solarsystem/missions/jwst/trail.asset b/data/assets/scene/solarsystem/missions/jwst/trail.asset index a3adf09bde..09aee9de85 100644 --- a/data/assets/scene/solarsystem/missions/jwst/trail.asset +++ b/data/assets/scene/solarsystem/missions/jwst/trail.asset @@ -83,6 +83,7 @@ local JWSTTrailCruise = { -- Trail of JWST relative to L2 after first month to reach L2 -- Gives a better trail history of the orbit around L2 than if it was relative to Earth +-- This does NOT co-rotate withe L2 and gives a saddle look of the trail local JWSTTrailOrbit = { Identifier = "JWSTTrailOrbit", Parent = transforms.L2Position.Identifier, @@ -113,6 +114,8 @@ local JWSTTrailOrbit = { } } +-- Trail of JWST in orbit around L2 that co-rotates with L2 around the Sun +-- This gives the trail a look of a wheel going along L2 around the Sun local JWSTTrailCoRotOrbit = { Identifier = "JWSTTrailCoRotOrbit", Parent = transforms.L2CoRotFrame.Identifier, @@ -130,7 +133,7 @@ local JWSTTrailCoRotOrbit = { Frame = 'L2_COROT', Kernels = { kernels .. "webb.bsp" } }, - Color = { 0.0, 0.9, 0.9 }, + Color = { 0.9, 0.0, 0.9 }, Period = 182.621099, -- About 6 months Resolution = 183 -- About a sample rate of once per day }, diff --git a/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset b/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset index 85a87561dd..98a835c794 100644 --- a/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset +++ b/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset @@ -34,16 +34,12 @@ local L2Position = { } } +-- This ref. frame co-rotates with L2 and is needed for a more intuitive trail of JWST in +-- relation to L2 local L2CoRotFrame = { Identifier = "L2CoRotFrame", - Parent = transforms.SolarSystemBarycenter.Identifier, + Parent = L2Position.Identifier, Transform = { - Translation = { - Type = "SpiceTranslation", - Target = 392, -- L2 - Observer = "SSB", - Kernels = kernels .. "L2_de431.bsp" - }, Rotation = { Type = "SpiceRotation", SourceFrame = "L2_COROT", From b8a36c984533e79553d8d12b5fb658479af54260 Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 16 Aug 2022 13:24:18 +0200 Subject: [PATCH 19/79] Some small clean up --- .../scene/solarsystem/missions/jwst/toggle_trail.asset | 6 +++--- data/assets/scene/solarsystem/missions/jwst/trail.asset | 4 ++-- .../solarsystem/planets/earth/lagrange_points/L2.asset | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/data/assets/scene/solarsystem/missions/jwst/toggle_trail.asset b/data/assets/scene/solarsystem/missions/jwst/toggle_trail.asset index 6360f6283c..91b11e8ace 100644 --- a/data/assets/scene/solarsystem/missions/jwst/toggle_trail.asset +++ b/data/assets/scene/solarsystem/missions/jwst/toggle_trail.asset @@ -17,7 +17,7 @@ local toggle_trail = { local launchTrail = "JWSTTrailLaunch" local cruiseTrail = "JWSTTrailCruise" local orbitTrail = "JWSTTrailOrbit" - local coOrbitTrail = "JWSTTrailCoRotOrbit" + local coRotOrbitTrail = "JWSTTrailCoRotOrbit" local visibility if is_declared("args") then @@ -33,7 +33,7 @@ local toggle_trail = { openspace.getPropertyValue("Scene." .. launchTrail .. ".Renderable.Enabled") or openspace.getPropertyValue("Scene." .. cruiseTrail .. ".Renderable.Enabled") or openspace.getPropertyValue("Scene." .. orbitTrail .. ".Renderable.Enabled") or - openspace.getPropertyValue("Scene." .. coOrbitTrail .. ".Renderable.Enabled") + openspace.getPropertyValue("Scene." .. coRotOrbitTrail .. ".Renderable.Enabled") ) end @@ -50,7 +50,7 @@ local toggle_trail = { visibility ) openspace.setPropertyValueSingle( - "Scene." .. coOrbitTrail .. ".Renderable.Enabled", + "Scene." .. coRotOrbitTrail .. ".Renderable.Enabled", visibility ) ]], diff --git a/data/assets/scene/solarsystem/missions/jwst/trail.asset b/data/assets/scene/solarsystem/missions/jwst/trail.asset index 09aee9de85..fe213d316b 100644 --- a/data/assets/scene/solarsystem/missions/jwst/trail.asset +++ b/data/assets/scene/solarsystem/missions/jwst/trail.asset @@ -83,7 +83,7 @@ local JWSTTrailCruise = { -- Trail of JWST relative to L2 after first month to reach L2 -- Gives a better trail history of the orbit around L2 than if it was relative to Earth --- This does NOT co-rotate withe L2 and gives a saddle look of the trail +-- This does NOT co-rotate with L2 and gives a saddle look of the trail local JWSTTrailOrbit = { Identifier = "JWSTTrailOrbit", Parent = transforms.L2Position.Identifier, @@ -203,7 +203,7 @@ asset.meta = { Name = "James Webb Space Telescope Trails", Version = "1.0", Description = [[ - Trail of James Webb Space Telescope in respect to Earth, L2, and the Sun + Trail of James Webb Space Telescope in respect to Earth, L2 and the Sun ]], Author = "OpenSpace Team", URL = "http://openspaceproject.com", diff --git a/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset b/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset index 98a835c794..05c4724d5e 100644 --- a/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset +++ b/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset @@ -52,7 +52,7 @@ local L2CoRotFrame = { }, Tag = { "lagrange_points_earth", "lagrange_points_earth_l2" }, GUI = { - Name = "L2 Co-rotation Frame", + Name = "L2 Co-rotating Reference Frame", Path = "/Solar System/Planets/Earth/Lagrange points", Hidden = true } From 91513fafca3b4a24a2fc3d9d450d92ee7ac57faa Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 16 Aug 2022 16:50:23 +0200 Subject: [PATCH 20/79] Make new trail default and change the colors --- .../scene/solarsystem/missions/jwst/toggle_trail.asset | 6 ------ data/assets/scene/solarsystem/missions/jwst/trail.asset | 4 ++-- data/profiles/jwst.profile | 5 +++++ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/data/assets/scene/solarsystem/missions/jwst/toggle_trail.asset b/data/assets/scene/solarsystem/missions/jwst/toggle_trail.asset index 91b11e8ace..8f9ed79db2 100644 --- a/data/assets/scene/solarsystem/missions/jwst/toggle_trail.asset +++ b/data/assets/scene/solarsystem/missions/jwst/toggle_trail.asset @@ -16,7 +16,6 @@ local toggle_trail = { local launchTrail = "JWSTTrailLaunch" local cruiseTrail = "JWSTTrailCruise" - local orbitTrail = "JWSTTrailOrbit" local coRotOrbitTrail = "JWSTTrailCoRotOrbit" local visibility @@ -32,7 +31,6 @@ local toggle_trail = { visibility = not ( openspace.getPropertyValue("Scene." .. launchTrail .. ".Renderable.Enabled") or openspace.getPropertyValue("Scene." .. cruiseTrail .. ".Renderable.Enabled") or - openspace.getPropertyValue("Scene." .. orbitTrail .. ".Renderable.Enabled") or openspace.getPropertyValue("Scene." .. coRotOrbitTrail .. ".Renderable.Enabled") ) end @@ -45,10 +43,6 @@ local toggle_trail = { "Scene." .. cruiseTrail .. ".Renderable.Enabled", visibility ) - openspace.setPropertyValueSingle( - "Scene." .. orbitTrail .. ".Renderable.Enabled", - visibility - ) openspace.setPropertyValueSingle( "Scene." .. coRotOrbitTrail .. ".Renderable.Enabled", visibility diff --git a/data/assets/scene/solarsystem/missions/jwst/trail.asset b/data/assets/scene/solarsystem/missions/jwst/trail.asset index fe213d316b..313f66b67b 100644 --- a/data/assets/scene/solarsystem/missions/jwst/trail.asset +++ b/data/assets/scene/solarsystem/missions/jwst/trail.asset @@ -101,7 +101,7 @@ local JWSTTrailOrbit = { Frame = 'GALACTIC', Kernels = { kernels .. "webb.bsp" } }, - Color = { 0.9, 0.9, 0.0 }, + Color = { 0.863, 0.0, 0.902 }, Period = 182.621099, -- About 6 months Resolution = 183 -- About a sample rate of once per day }, @@ -133,7 +133,7 @@ local JWSTTrailCoRotOrbit = { Frame = 'L2_COROT', Kernels = { kernels .. "webb.bsp" } }, - Color = { 0.9, 0.0, 0.9 }, + Color = { 1.0, 0.663, 0.157 }, Period = 182.621099, -- About 6 months Resolution = 183 -- About a sample rate of once per day }, diff --git a/data/profiles/jwst.profile b/data/profiles/jwst.profile index 38fb91dbd1..336b97ae82 100644 --- a/data/profiles/jwst.profile +++ b/data/profiles/jwst.profile @@ -294,6 +294,11 @@ "type": "setPropertyValueSingle", "value": "false" }, + { + "name": "Scene.JWSTTrailOrbit.Renderable.Enabled", + "type": "setPropertyValueSingle", + "value": "false" + }, { "name": "Scene.JWSTSunTrail.Renderable.Enabled", "type": "setPropertyValueSingle", From 08fa825381e972a6d14a3e1e8c0af5d4bb2e1e54 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 17 Aug 2022 09:02:36 +0200 Subject: [PATCH 21/79] Make the co-rotating trail longer --- data/assets/scene/solarsystem/missions/jwst/trail.asset | 4 ++-- data/profiles/jwst.profile | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/data/assets/scene/solarsystem/missions/jwst/trail.asset b/data/assets/scene/solarsystem/missions/jwst/trail.asset index 313f66b67b..5c2709b446 100644 --- a/data/assets/scene/solarsystem/missions/jwst/trail.asset +++ b/data/assets/scene/solarsystem/missions/jwst/trail.asset @@ -134,8 +134,8 @@ local JWSTTrailCoRotOrbit = { Kernels = { kernels .. "webb.bsp" } }, Color = { 1.0, 0.663, 0.157 }, - Period = 182.621099, -- About 6 months - Resolution = 183 -- About a sample rate of once per day + Period = 365.242198, -- About a year, 2 orbits. 1 orbit would be 182.621099 (6 months) + Resolution = 365 -- About a sample rate of once per day }, GUI = { Name = "JWST L2 Co-rotating Orbit Trail", diff --git a/data/profiles/jwst.profile b/data/profiles/jwst.profile index 336b97ae82..9ccf2cf029 100644 --- a/data/profiles/jwst.profile +++ b/data/profiles/jwst.profile @@ -73,12 +73,12 @@ "script": "local list = openspace.getProperty('{planetTrail_solarSystem}.Renderable.Enabled'); for _,v in pairs(list) do openspace.setPropertyValueSingle(v, not openspace.getPropertyValue(v)) end local moonlist = openspace.getProperty('{moonTrail_solarSystem}.Renderable.Enabled') for _,v in pairs(moonlist) do openspace.setPropertyValueSingle(v, not openspace.getPropertyValue(v)) end openspace.setPropertyValueSingle('Scene.MoonTrail.Renderable.Enabled', true)" }, { - "documentation": "Toggle JWST launch, cruise and orbit trails, not the Sun trail", + "documentation": "Toggle JWST launch, cruise and L2 co-revolving orbit trails, not the Sun trail", "gui_path": "/JWST", "identifier": "profile.toggle.jwst_trails", "is_local": false, "name": "Toggle JWST trail", - "script": "local list = {'Scene.JWSTTrailLaunch.Renderable.Enabled', 'Scene.JWSTTrailCruise.Renderable.Enabled', 'Scene.JWSTTrailOrbit.Renderable.Enabled'}; for _,v in pairs(list) do openspace.setPropertyValueSingle(v, not openspace.getPropertyValue(v)); end" + "script": "local list = {'Scene.JWSTTrailLaunch.Renderable.Enabled', 'Scene.JWSTTrailCruise.Renderable.Enabled', 'Scene.JWSTTrailCoRotOrbit.Renderable.Enabled'}; for _,v in pairs(list) do openspace.setPropertyValueSingle(v, not openspace.getPropertyValue(v)); end" } ], "additional_scripts": [ From 44aa45d36f85e97fdefda0bd0eaaf0fdcba635d8 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 17 Aug 2022 09:26:21 +0200 Subject: [PATCH 22/79] Change name from co-rotating to co-revolving --- .../missions/jwst/toggle_trail.asset | 6 +++--- .../solarsystem/missions/jwst/trail.asset | 20 +++++++++---------- .../planets/earth/lagrange_points/L2.asset | 14 ++++++------- data/profiles/jwst.profile | 2 +- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/data/assets/scene/solarsystem/missions/jwst/toggle_trail.asset b/data/assets/scene/solarsystem/missions/jwst/toggle_trail.asset index 8f9ed79db2..37c8900d1c 100644 --- a/data/assets/scene/solarsystem/missions/jwst/toggle_trail.asset +++ b/data/assets/scene/solarsystem/missions/jwst/toggle_trail.asset @@ -16,7 +16,7 @@ local toggle_trail = { local launchTrail = "JWSTTrailLaunch" local cruiseTrail = "JWSTTrailCruise" - local coRotOrbitTrail = "JWSTTrailCoRotOrbit" + local coRevOrbitTrail = "JWSTTrailCoRevOrbit" local visibility if is_declared("args") then @@ -31,7 +31,7 @@ local toggle_trail = { visibility = not ( openspace.getPropertyValue("Scene." .. launchTrail .. ".Renderable.Enabled") or openspace.getPropertyValue("Scene." .. cruiseTrail .. ".Renderable.Enabled") or - openspace.getPropertyValue("Scene." .. coRotOrbitTrail .. ".Renderable.Enabled") + openspace.getPropertyValue("Scene." .. coRevOrbitTrail .. ".Renderable.Enabled") ) end @@ -44,7 +44,7 @@ local toggle_trail = { visibility ) openspace.setPropertyValueSingle( - "Scene." .. coRotOrbitTrail .. ".Renderable.Enabled", + "Scene." .. coRevOrbitTrail .. ".Renderable.Enabled", visibility ) ]], diff --git a/data/assets/scene/solarsystem/missions/jwst/trail.asset b/data/assets/scene/solarsystem/missions/jwst/trail.asset index 5c2709b446..0f91d4caca 100644 --- a/data/assets/scene/solarsystem/missions/jwst/trail.asset +++ b/data/assets/scene/solarsystem/missions/jwst/trail.asset @@ -114,11 +114,11 @@ local JWSTTrailOrbit = { } } --- Trail of JWST in orbit around L2 that co-rotates with L2 around the Sun +-- Trail of JWST in orbit around L2 that co-revolves with L2 around the Sun -- This gives the trail a look of a wheel going along L2 around the Sun -local JWSTTrailCoRotOrbit = { - Identifier = "JWSTTrailCoRotOrbit", - Parent = transforms.L2CoRotFrame.Identifier, +local JWSTTrailCoRevOrbit = { + Identifier = "JWSTTrailCoRevOrbit", + Parent = transforms.L2CoRevFrame.Identifier, TimeFrame = { Type = "TimeFrameInterval", Start = L2orbitInsertionTime, @@ -130,7 +130,7 @@ local JWSTTrailCoRotOrbit = { Type = 'SpiceTranslation', Target = 170, -- JWST Observer = 392, -- L2 - Frame = 'L2_COROT', + Frame = 'L2_COREV', Kernels = { kernels .. "webb.bsp" } }, Color = { 1.0, 0.663, 0.157 }, @@ -138,10 +138,10 @@ local JWSTTrailCoRotOrbit = { Resolution = 365 -- About a sample rate of once per day }, GUI = { - Name = "JWST L2 Co-rotating Orbit Trail", + Name = "JWST L2 Co-revolving Orbit Trail", Path = "/Solar System/Missions/JWST/Trails", Description = [[ - James Webb Space Telescope Orbit Trail that Co-rotates with L2. + James Webb Space Telescope Orbit Trail that Co-revolves with L2. ]], } } @@ -180,13 +180,13 @@ asset.onInitialize(function() openspace.addSceneGraphNode(JWSTTrailLaunch) openspace.addSceneGraphNode(JWSTTrailCruise) openspace.addSceneGraphNode(JWSTTrailOrbit) - openspace.addSceneGraphNode(JWSTTrailCoRotOrbit) + openspace.addSceneGraphNode(JWSTTrailCoRevOrbit) openspace.addSceneGraphNode(JWSTSunTrail) end) asset.onDeinitialize(function() openspace.removeSceneGraphNode(JWSTSunTrail) - openspace.removeSceneGraphNode(JWSTTrailCoRotOrbit) + openspace.removeSceneGraphNode(JWSTTrailCoRevOrbit) openspace.removeSceneGraphNode(JWSTTrailOrbit) openspace.removeSceneGraphNode(JWSTTrailCruise) openspace.removeSceneGraphNode(JWSTTrailLaunch) @@ -195,7 +195,7 @@ end) asset.export(JWSTTrailLaunch) asset.export(JWSTTrailCruise) asset.export(JWSTTrailOrbit) -asset.export(JWSTTrailCoRotOrbit) +asset.export(JWSTTrailCoRevOrbit) asset.export(JWSTSunTrail) diff --git a/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset b/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset index 05c4724d5e..972e66717f 100644 --- a/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset +++ b/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset @@ -34,25 +34,25 @@ local L2Position = { } } --- This ref. frame co-rotates with L2 and is needed for a more intuitive trail of JWST in +-- This ref. frame co-revolves with L2 and is needed for a more intuitive trail of JWST in -- relation to L2 -local L2CoRotFrame = { - Identifier = "L2CoRotFrame", +local L2CoRevFrame = { + Identifier = "L2CoRevFrame", Parent = L2Position.Identifier, Transform = { Rotation = { Type = "SpiceRotation", - SourceFrame = "L2_COROT", + SourceFrame = "L2_COREV", DestinationFrame = 'GALACTIC', Kernels = { kernels .. "L2_de431.bsp", - kernels .. "L2_corot.tf" + kernels .. "L2_corev.tf" } } }, Tag = { "lagrange_points_earth", "lagrange_points_earth_l2" }, GUI = { - Name = "L2 Co-rotating Reference Frame", + Name = "L2 Co-revolving Reference Frame", Path = "/Solar System/Planets/Earth/Lagrange points", Hidden = true } @@ -155,7 +155,7 @@ local L2SunLine = { local nodes = { L2Position, - L2CoRotFrame, + L2CoRevFrame, L2Small, L2, L2SunLine, diff --git a/data/profiles/jwst.profile b/data/profiles/jwst.profile index 9ccf2cf029..ecf38ad0f5 100644 --- a/data/profiles/jwst.profile +++ b/data/profiles/jwst.profile @@ -78,7 +78,7 @@ "identifier": "profile.toggle.jwst_trails", "is_local": false, "name": "Toggle JWST trail", - "script": "local list = {'Scene.JWSTTrailLaunch.Renderable.Enabled', 'Scene.JWSTTrailCruise.Renderable.Enabled', 'Scene.JWSTTrailCoRotOrbit.Renderable.Enabled'}; for _,v in pairs(list) do openspace.setPropertyValueSingle(v, not openspace.getPropertyValue(v)); end" + "script": "local list = {'Scene.JWSTTrailLaunch.Renderable.Enabled', 'Scene.JWSTTrailCruise.Renderable.Enabled', 'Scene.JWSTTrailCoRevOrbit.Renderable.Enabled'}; for _,v in pairs(list) do openspace.setPropertyValueSingle(v, not openspace.getPropertyValue(v)); end" } ], "additional_scripts": [ From b3d87b63cc486241cb7c375bc38fbd4ae496b1c9 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 17 Aug 2022 10:50:50 +0200 Subject: [PATCH 23/79] Slow down shoot off part of timelapse of JWST deployment --- .../scene/solarsystem/missions/jwst/timelapse.asset | 12 +++++++++--- .../scene/solarsystem/missions/jwst/trail.asset | 12 ++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/data/assets/scene/solarsystem/missions/jwst/timelapse.asset b/data/assets/scene/solarsystem/missions/jwst/timelapse.asset index 9efb08325c..8ebc3c0956 100644 --- a/data/assets/scene/solarsystem/missions/jwst/timelapse.asset +++ b/data/assets/scene/solarsystem/missions/jwst/timelapse.asset @@ -50,13 +50,15 @@ local function createForwardTimelapse() -- array complete openspace.scriptScheduler.loadScheduledScript("]] .. advance(launchTime, 0, 0, 30, 42) .. [[", - "openspace.time.interpolateDeltaTime(7200)" .. - "openspace.setPropertyValueSingle(\"Dashboard.JWSTStateText.Text\", \"Time speed: 2 hours/second\")" + "openspace.time.interpolateDeltaTime(2400)" .. + "openspace.setPropertyValueSingle(\"Dashboard.JWSTStateText.Text\", \"Time speed: 40 minutes/second\")" ) -- Make night layer more visible, at around 14:00 openspace.scriptScheduler.loadScheduledScript("]] .. advance(detachTime, 0, 1, 10, 0) .. [[", + "openspace.time.interpolateDeltaTime(7200)" .. + "openspace.setPropertyValueSingle(\"Dashboard.JWSTStateText.Text\", \"Time speed: 2 hours/second\")" .. "openspace.setPropertyValueSingle(\"Scene.Earth.Renderable.Layers.NightLayers.Earth_at_Night_2012.Settings.Gamma\", 0.7)" .. "openspace.setPropertyValueSingle(\"Scene.EarthAtmosphere.Renderable.Enabled\", false)" ) @@ -280,8 +282,10 @@ local function createBackwardTimelapse() -- Reset night layer, at around 14:00 openspace.scriptScheduler.loadScheduledScript("]] .. - advance(detachTime, 0, 1, 10, 0) .. [[", + advance(detachTime, 0, 1 + 1, 10, 0) .. [[", -- 1h pre delay so time to interpolate "", + "openspace.time.interpolateDeltaTime(-2400)" .. + "openspace.setPropertyValueSingle(\"Dashboard.JWSTStateText.Text\", \"Time speed: -40 minutes/second\")" .. "openspace.setPropertyValueSingle(\"Scene.Earth.Renderable.Layers.NightLayers.Earth_at_Night_2012.Settings.Gamma\", 1.0)" .. "openspace.setPropertyValueSingle(\"Scene.EarthAtmosphere.Renderable.Enabled\", true)" ) @@ -520,6 +524,8 @@ local function createActions() openspace.scriptScheduler.clear(0) openspace.time.setDeltaTime(1) openspace.setPropertyValueSingle("Dashboard.JWSTStateText.Text", "") + openspace.setPropertyValueSingle("Scene.Earth.Renderable.Layers.NightLayers.Earth_at_Night_2012.Settings.Gamma", 1.0) + openspace.setPropertyValueSingle("Scene.EarthAtmosphere.Renderable.Enabled", true) openspace.time.setTime("]] .. detachTime .. [[") ]] .. createForwardTimelapse() .. [[ openspace.time.setDeltaTime(1) diff --git a/data/assets/scene/solarsystem/missions/jwst/trail.asset b/data/assets/scene/solarsystem/missions/jwst/trail.asset index 0f91d4caca..b5cebc8991 100644 --- a/data/assets/scene/solarsystem/missions/jwst/trail.asset +++ b/data/assets/scene/solarsystem/missions/jwst/trail.asset @@ -127,12 +127,12 @@ local JWSTTrailCoRevOrbit = { Renderable = { Type = "RenderableTrailOrbit", Translation = { - Type = 'SpiceTranslation', - Target = 170, -- JWST - Observer = 392, -- L2 - Frame = 'L2_COREV', - Kernels = { kernels .. "webb.bsp" } - }, + Type = 'SpiceTranslation', + Target = 170, -- JWST + Observer = 392, -- L2 + Frame = 'L2_COREV', + Kernels = { kernels .. "webb.bsp" } + }, Color = { 1.0, 0.663, 0.157 }, Period = 365.242198, -- About a year, 2 orbits. 1 orbit would be 182.621099 (6 months) Resolution = 365 -- About a sample rate of once per day From 49236e3a1a79f9392de4075afaf325d027b64342 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 24 Aug 2022 12:02:39 +0200 Subject: [PATCH 24/79] Update Ipac example asset to use actions --- data/assets/util/ipac.asset | 193 +++++++++++++++++++++++++++++++----- 1 file changed, 169 insertions(+), 24 deletions(-) diff --git a/data/assets/util/ipac.asset b/data/assets/util/ipac.asset index 34d9d79272..50019e38cc 100644 --- a/data/assets/util/ipac.asset +++ b/data/assets/util/ipac.asset @@ -1,30 +1,175 @@ +local orbit_right = { + Identifier = "ipac.orbit_right", + Name = "Orbit right", + Command = [[ openspace.navigation.addGlobalRotation(-5.0, 0.0) ]], + Documentation = "Orbits the camera to the right around the current focus", + GuiPath = "/Ipac", + IsLocal = false +} +asset.export("IpacOrbitRight", orbit_right) + +local orbit_left = { + Identifier = "ipac.orbit_left", + Name = "Orbit left", + Command = [[ openspace.navigation.addGlobalRotation(5.0, 0.0) ]], + Documentation = "Orbits the camera to the left around the current focus", + GuiPath = "/Ipac", + IsLocal = false +} +asset.export("IpacOrbitLeft", orbit_left) + +local orbit_up = { + Identifier = "ipac.orbit_up", + Name = "Orbit up", + Command = [[ openspace.navigation.addGlobalRotation(0.0, 5.0) ]], + Documentation = "Orbits the camera up around the current focus", + GuiPath = "/Ipac", + IsLocal = false +} +asset.export("IpacOrbitUp", orbit_up) + +local orbit_down = { + Identifier = "ipac.orbit_down", + Name = "Orbit down", + Command = [[ openspace.navigation.addGlobalRotation(0.0, -5.0) ]], + Documentation = "Orbits the camera down around the current focus", + GuiPath = "/Ipac", + IsLocal = false +} +asset.export("IpacOrbitDown", orbit_down) + + +local pan_right = { + Identifier = "ipac.pan_right", + Name = "Pan right", + Command = [[ openspace.navigation.addLocalRotation(-5.0, 0.0) ]], + Documentation = "Pans the camera to the right", + GuiPath = "/Ipac", + IsLocal = false +} +asset.export("IpacPanRight", pan_right) + +local pan_left = { + Identifier = "ipac.pan_left", + Name = "Pan left", + Command = [[ openspace.navigation.addLocalRotation(5.0, 0.0) ]], + Documentation = "Pans the camera to the left", + GuiPath = "/Ipac", + IsLocal = false +} +asset.export("IpacPanLeft", pan_left) + +local pan_up = { + Identifier = "ipac.pan_up", + Name = "Pan up", + Command = [[ openspace.navigation.addLocalRotation(0.0, 5.0) ]], + Documentation = "Pans the camera up", + GuiPath = "/Ipac", + IsLocal = false +} +asset.export("IpacPanUp", pan_up) + +local pan_down = { + Identifier = "ipac.pan_down", + Name = "Pan down", + Command = [[ openspace.navigation.addLocalRotation(0.0, -5.0) ]], + Documentation = "Pans the camera down", + GuiPath = "/Ipac", + IsLocal = false +} +asset.export("IpacPanDown", pan_down) + + +local zoom_in = { + Identifier = "ipac.zoom_in", + Name = "Zoom in", + Command = [[ openspace.navigation.addTruckMovement(0.0, 5.0) ]], + Documentation = "Zooms the camera in, towards the current focus", + GuiPath = "/Ipac", + IsLocal = false +} +asset.export("IpacZoomIn", zoom_in) + +local zoom_out = { + Identifier = "ipac.zoom_out", + Name = "Zoom out", + Command = [[ openspace.navigation.addTruckMovement(0.0, -5.0) ]], + Documentation = "Zooms the camera out, away form the current focus", + GuiPath = "/Ipac", + IsLocal = false +} +asset.export("IpacZoomOut", zoom_out) + + +local focus_moon = { + Identifier = "ipac.focus_moon", + Name = "Focus on the Moon", + Command = [[ + openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Aim", ""); + openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Anchor", "Moon"); + openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.RetargetAnchor", nil); + ]], + Documentation = "Focuses the camera on the Moon", + GuiPath = "/Ipac", + IsLocal = false +} +asset.export("IpacFocusMoon", focus_moon) + +local focus_earth = { + Identifier = "ipac.focus_earth", + Name = "Focus on the Earth", + Command = [[ + openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Aim", ""); + openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Anchor", "Earth"); + openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.RetargetAnchor", nil) + ]], + Documentation = "Focuses the camera on Earth", + GuiPath = "/Ipac", + IsLocal = false +} +asset.export("IpacFocusEarth", focus_earth) + + +local actions = { + orbit_right, + orbit_left, + orbit_up, + orbit_down, + pan_right, + pan_left, + pan_up, + pan_down, + zoom_in, + zoom_out, + focus_moon, + focus_earth +} + asset.onInitialize(function() + for _, a in ipairs(actions) do + openspace.action.registerAction(a) + end + openspace.clearKeys() - openspace.bindKey("RIGHT", "openspace.navigation.addGlobalRotation(-5.0, 0.0)"); - openspace.bindKey("LEFT", "openspace.navigation.addGlobalRotation(5.0, 0.0)"); - openspace.bindKey("UP", "openspace.navigation.addGlobalRotation(0.0, 5.0)"); - openspace.bindKey("DOWN", "openspace.navigation.addGlobalRotation(0.0, -5.0)"); + openspace.bindKey("RIGHT", orbit_right.Identifier) + openspace.bindKey("LEFT", orbit_left.Identifier) + openspace.bindKey("UP", orbit_up.Identifier) + openspace.bindKey("DOWN", orbit_down.Identifier) - openspace.bindKey("CTRL+RIGHT", "openspace.navigation.addLocalRotation(-5.0, 0.0)"); - openspace.bindKey("CTRL+LEFT", "openspace.navigation.addLocalRotation(5.0, 0.0)"); - openspace.bindKey("CTRL+UP", "openspace.navigation.addLocalRotation(0.0, 5.0)"); - openspace.bindKey("CTRL+DOWN", "openspace.navigation.addLocalRotation(0.0, -5.0)"); + openspace.bindKey("CTRL+RIGHT", pan_right.Identifier) + openspace.bindKey("CTRL+LEFT", pan_left.Identifier) + openspace.bindKey("CTRL+UP", pan_up.Identifier) + openspace.bindKey("CTRL+DOWN", pan_down.Identifier) - openspace.bindKey("ALT+UP", "openspace.navigation.addTruckMovement(0.0, 5.0)"); - openspace.bindKey("ALT+DOWN", "openspace.navigation.addTruckMovement(0.0, -5.0)"); + openspace.bindKey("ALT+UP", zoom_in.Identifier) + openspace.bindKey("ALT+DOWN", zoom_out.Identifier) - openspace.bindKey( - "SPACE", - [[ - openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Aim", ""); - openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Anchor", "Moon"); - openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.RetargetAnchor", nil) - ]]) - openspace.bindKey( - "Z", - [[ - openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Aim", ""); - openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Anchor", "Earth"); - openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.RetargetAnchor", nil) - ]]) + openspace.bindKey("SPACE", focus_moon.Identifier) + openspace.bindKey("Z", focus_earth.Identifier) +end) + +asset.onDeinitialize(function () + for i = #actions, 1, -1 do + openspace.action.removeAction(actions[i]) + end end) From a63a9c1ca93401b4982e00079f5009cee466a880 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 24 Aug 2022 16:56:54 +0200 Subject: [PATCH 25/79] Convert the extragalactic constellations to use new class --- data/assets/scene/digitaluniverse/constellations.asset | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/data/assets/scene/digitaluniverse/constellations.asset b/data/assets/scene/digitaluniverse/constellations.asset index 401f9ae594..1dafb17052 100644 --- a/data/assets/scene/digitaluniverse/constellations.asset +++ b/data/assets/scene/digitaluniverse/constellations.asset @@ -13,17 +13,20 @@ local zodiacs = { local constellationsExtragalactic = { Identifier = "ConstellationsExtragalactic", Renderable = { - Type = "RenderableDUMeshes", + Type = "RenderableConstellationLines", Enabled = false, Opacity = 0.4, File = speck .. "constellationsEXGAL.speck", LabelFile = speck .. "constellationsEXGAL.label", + ConstellationNamesFile = speck .. "constellations.dat", TextColor = { 0.8, 0.8, 0.8 }, TextOpacity = 0.4, TextSize = 20.0, TextMinMaxSize = { 20, 30 }, - MeshColor = { { 0.6, 0.4, 0.4 }, { 0.8, 0.0, 0.0 }, { 0.0, 0.3, 0.8 } }, - Unit = "Mpc" + ConstellationColor = { { 0.6, 0.4, 0.4 }, { 0.8, 0.0, 0.0 }, { 0.0, 0.3, 0.8 } }, + LabelUnit = "Mpc", + ConstellationUnit = "Mpc", + -- ConstellationSelection = zodiacs }, GUI = { Name = "Constellations (Extragalactic)", From b8f365e6dec5d1e82be2ee51464d3fedb779b830 Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 25 Aug 2022 08:57:35 +0200 Subject: [PATCH 26/79] Name all constellations from the same source --- .../constellations/constellation_art.asset | 51 +++++++++++++++++-- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/data/assets/scene/milkyway/constellations/constellation_art.asset b/data/assets/scene/milkyway/constellations/constellation_art.asset index d96754f498..94fa56bb4f 100644 --- a/data/assets/scene/milkyway/constellations/constellation_art.asset +++ b/data/assets/scene/milkyway/constellations/constellation_art.asset @@ -2,12 +2,48 @@ local constellationsCSV = asset.localResource("constellation_data.csv") local transforms = asset.require("scene/solarsystem/sun/transforms") local images = asset.syncedResource({ - Name = "Constellation Images", - Type = "HttpSynchronization", - Identifier = "constellation_images", - Version = 4 + Name = "Constellation Images", + Type = "HttpSynchronization", + Identifier = "constellation_images", + Version = 4 }) +local data = asset.syncedResource({ + Name = "Constellation Files", + Type = "HttpSynchronization", + Identifier = "digitaluniverse_constellations_data", + Version = 1 +}) + + +-- Function that returns the full name of a constellation given its abbreviation +-- The function uses the constellations.dat file to find the name +-- If the file does not exist or if a match could not be found, it returns nil +local findFullName = function(abbreviation) + local namesFile = data .. "constellations.dat" + + local file = io.open(namesFile, "r") + if file ~= nil then + io.close(file) + for line in io.lines(namesFile) do + local index, length = string.find(line, abbreviation) + + if index ~= nil and index < 4 then + return string.sub(line, length + 1) + end + + local fullLine = line + local lowerLine = string.lower(line) + index, length = string.find(lowerLine, string.lower(abbreviation)) + if index ~= nil and index < 4 then + return string.sub(fullLine, length + 1) + end + end + end + return nil +end + + --function that reads the file local createConstellations = function (baseIdentifier, guiPath, constellationfile) local genConstellations = {}; @@ -30,6 +66,13 @@ local createConstellations = function (baseIdentifier, guiPath, constellationfil local normy = y/magVec local normz = z/magVec + -- Use the full name in the data constellations.dat if possible + -- Otherwise, use the given name in the constellation_data.csv file + local foundName = findFullName(abbreviation) + if foundName ~= nil then + name = foundName + end + group = (group == "" and globe or group) local aconstellation = { From 40267804bdba7f315b87d4f0390107d736899230 Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 25 Aug 2022 13:48:48 +0200 Subject: [PATCH 27/79] Some clean up --- .../constellations/constellation_art.asset | 2 +- .../space/rendering/renderableconstellation.cpp | 17 ++++++++--------- .../rendering/renderableconstellationbounds.cpp | 6 +++--- .../rendering/renderableconstellationlines.cpp | 17 ++++++++++------- modules/space/spacemodule.cpp | 2 +- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/data/assets/scene/milkyway/constellations/constellation_art.asset b/data/assets/scene/milkyway/constellations/constellation_art.asset index 94fa56bb4f..0bf65abd00 100644 --- a/data/assets/scene/milkyway/constellations/constellation_art.asset +++ b/data/assets/scene/milkyway/constellations/constellation_art.asset @@ -215,7 +215,7 @@ end asset.meta = { Name = "Constellation Images", - Version = "1.1", + Version = "1.2", Description = "Artistic images depicting the constellations", Author = "James Hedberg", URL = "http://jameshedberg.com", diff --git a/modules/space/rendering/renderableconstellation.cpp b/modules/space/rendering/renderableconstellation.cpp index bd483546f7..01215c0a68 100644 --- a/modules/space/rendering/renderableconstellation.cpp +++ b/modules/space/rendering/renderableconstellation.cpp @@ -85,7 +85,7 @@ namespace { constexpr openspace::properties::Property::PropertyInfo LineWidthInfo = { "LineWidth", "Line Width", - "The line width of the constellation " + "The line width of the constellation" }; constexpr openspace::properties::Property::PropertyInfo DrawLabelInfo = { @@ -117,7 +117,7 @@ namespace { std::optional drawLabels; // [[codegen::verbatim(ConstellationInfo.description)]] - std::optional constellationNamesFile; + std::optional constellationNamesFile; // [[codegen::verbatim(TextColorInfo.description)]] std::optional textColor [[codegen::color()]]; @@ -185,7 +185,7 @@ RenderableConstellation::RenderableConstellation(const ghoul::Dictionary& dictio _renderOption.addOption(RenderOptionViewDirection, "Camera View Direction"); _renderOption.addOption(RenderOptionPositionNormal, "Camera Position Normal"); - // @TODO (abock. 2021-01-31) In the other DU classes, this is done with an enum, and + // @TODO (abock. 2021-01-31) In the other classes, this is done with an enum, and // doing it based on the fisheye rendering seems a bit brittle? if (global::windowDelegate->isFisheyeRendering()) { _renderOption = RenderOptionPositionNormal; @@ -195,9 +195,11 @@ RenderableConstellation::RenderableConstellation(const ghoul::Dictionary& dictio } addProperty(_renderOption); - // Read all files in the initialize() instead, multithreaded - _constellationNamesFilename = - p.constellationNamesFile.value_or(_constellationNamesFilename); + // Avoid reading files here, instead do it in multithreaded initialize() + if (p.constellationNamesFile.has_value()) { + _constellationNamesFilename = + absPath(p.constellationNamesFile.value().string()).string(); + } _constellationNamesFilename.onChange([&]() { loadConstellationFile(); }); addProperty(_constellationNamesFilename); @@ -275,7 +277,6 @@ void RenderableConstellation::loadConstellationFile() { file.open(absPath(_constellationNamesFilename)); std::string line; - int index = 0; while (file.good()) { std::getline(file, line); if (line.empty()) { @@ -290,8 +291,6 @@ void RenderableConstellation::loadConstellationFile() { std::getline(s, fullName); ghoul::trimWhitespace(fullName); _constellationNamesTranslation[abbreviation] = fullName; - - ++index; } fillSelectionProperty(); diff --git a/modules/space/rendering/renderableconstellationbounds.cpp b/modules/space/rendering/renderableconstellationbounds.cpp index 24bf422786..a1cafc053c 100644 --- a/modules/space/rendering/renderableconstellationbounds.cpp +++ b/modules/space/rendering/renderableconstellationbounds.cpp @@ -57,7 +57,7 @@ namespace { struct [[codegen::Dictionary(RenderableConstellationBounds)]] Parameters { // [[codegen::verbatim(VertexInfo.description)]] - std::string file; + std::filesystem::path file; // [[codegen::verbatim(ColorInfo.description)]] std::optional color [[codegen::color()]]; @@ -79,8 +79,8 @@ RenderableConstellationBounds::RenderableConstellationBounds( { const Parameters p = codegen::bake(dictionary); - // Avoid loading the vertex file here, do it in multithreded initialize() instead - _vertexFilename = p.file; + // Avoid reading files here, instead do it in multithreaded initialize() + _vertexFilename = absPath(p.file.string()).string(); _vertexFilename.onChange([&](){ loadVertexFile(); }); addProperty(_vertexFilename); diff --git a/modules/space/rendering/renderableconstellationlines.cpp b/modules/space/rendering/renderableconstellationlines.cpp index c2ac4b2dc1..659f346809 100644 --- a/modules/space/rendering/renderableconstellationlines.cpp +++ b/modules/space/rendering/renderableconstellationlines.cpp @@ -66,7 +66,7 @@ namespace { struct [[codegen::Dictionary(RenderableConstellationLines)]] Parameters { // The path to the SPECK file that contains constellation lines data - std::string file; + std::filesystem::path file; enum class [[codegen::map(openspace::DistanceUnit)]] Unit { Meter [[codegen::key("m")]], @@ -99,7 +99,7 @@ RenderableConstellationLines::RenderableConstellationLines( { const Parameters p = codegen::bake(dictionary); - _speckFile = absPath(p.file).string(); + _speckFile = absPath(p.file.string()).string(); _hasSpeckFile = true; _drawElements.onChange([&]() { _hasSpeckFile = !_hasSpeckFile; }); addProperty(_drawElements); @@ -140,7 +140,10 @@ void RenderableConstellationLines::selectionPropertyHasChanged() { } bool RenderableConstellationLines::isReady() const { - return (_program != nullptr) && !_renderingConstellationsMap.empty() && + if (!_hasLabel) { + return _program && !_renderingConstellationsMap.empty(); + } + return _program && !_renderingConstellationsMap.empty() && !_labelset.entries.empty(); } @@ -328,10 +331,9 @@ bool RenderableConstellationLines::readSpeckFile() { std::string dummy; str >> dummy; // mesh command dummy.clear(); - str >> dummy; // texture index command? + str >> dummy; // color index command? do { if (dummy == "-c") { - dummy.clear(); str >> constellationLine.colorIndex; // color index command } dummy.clear(); @@ -344,8 +346,9 @@ bool RenderableConstellationLines::readSpeckFile() { std::stringstream id(line); std::string identifier; - id >> dummy; - std::getline(id, identifier); + id >> dummy; // id command + dummy.clear(); + std::getline(id, identifier); // identifier ghoul::trimWhitespace(identifier); std::string name = constellationFullName(identifier); if (!name.empty()) { diff --git a/modules/space/spacemodule.cpp b/modules/space/spacemodule.cpp index 7084f12639..bb06bed639 100644 --- a/modules/space/spacemodule.cpp +++ b/modules/space/spacemodule.cpp @@ -82,7 +82,7 @@ void SpaceModule::internalInitialize(const ghoul::Dictionary& dictionary) { ); fRenderable->registerClass( "RenderableConstellationLines" - ); + ); fRenderable->registerClass("RenderableFluxNodes"); fRenderable->registerClass("RenderableHabitableZone"); fRenderable->registerClass("RenderableRings"); From 5565fb662cca4216757e6c8757cfaea765682fbc Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 25 Aug 2022 15:48:47 +0200 Subject: [PATCH 28/79] Convert RenderableDUMeshes grids to use RenderableGrid class --- data/assets/scene/digitaluniverse/grids.asset | 226 +++++++++++++----- 1 file changed, 170 insertions(+), 56 deletions(-) diff --git a/data/assets/scene/digitaluniverse/grids.asset b/data/assets/scene/digitaluniverse/grids.asset index 91a8619ba7..14134a1ed1 100644 --- a/data/assets/scene/digitaluniverse/grids.asset +++ b/data/assets/scene/digitaluniverse/grids.asset @@ -20,6 +20,10 @@ local speck = asset.syncedResource({ Version = 2 }) +local lightDay = 2.59020684E13 +local lightMonth = 7.771E14 +local lightYear = 9.4605284E15 + local radio = { Identifier = "RadioSphere", Parent = earth_transforms.EarthBarycenter.Identifier, @@ -233,16 +237,13 @@ local plane1ld = { } }, Renderable = { - Type = "RenderableDUMeshes", + Type = "RenderableGrid", Enabled = false, Opacity = 0.4, - File = speck .. "1ld.speck", - MeshColor = {{ 0.1, 0.5, 0.6 }}, - LabelFile = speck .. "1ld.label", - TextColor = { 0.0, 0.2, 0.5 }, - TextSize = 10.3, - TextMinMaxSize = { 0, 30 }, - Unit = "Km" + Color = { 0.1, 0.5, 0.6 }, + LineWidth = 2.0, + Segments = { 20, 20 }, + Size = { 2*lightDay, 2*lightDay }, }, GUI = { Name = "1ld Grid", @@ -260,16 +261,13 @@ local plane1lm = { } }, Renderable = { - Type = "RenderableDUMeshes", + Type = "RenderableGrid", Enabled = false, Opacity = 0.4, - File = speck .. "1lm.speck", - MeshColor = {{ 0.1, 0.5, 0.6 }}, - LabelFile = speck .. "1lm.label", - TextColor = { 0.0, 0.2, 0.5 }, - TextSize = 11.8, - TextMinMaxSize = { 0, 30 }, - Unit = "pc" + Color = { 0.1, 0.5, 0.6 }, + LineWidth = 2.0, + Segments = { 20, 20 }, + Size = { 2*lightMonth, 2*lightMonth }, }, GUI = { Name = "1lm Grid", @@ -287,16 +285,13 @@ local plane1ly = { } }, Renderable = { - Type = "RenderableDUMeshes", + Type = "RenderableGrid", Enabled = false, Opacity = 0.4, - File = speck .. "1ly.speck", - MeshColor = {{ 0.1, 0.5, 0.6 }}, - LabelFile = speck .. "1ly.label", - TextColor = { 0.0, 0.2, 0.5 }, - TextSize = 13.0, - TextMinMaxSize = { 0, 30 }, - Unit = "pc" + Color = { 0.1, 0.5, 0.6 }, + LineWidth = 2.0, + Segments = { 20, 20 }, + Size = { 2*lightYear, 2*lightYear }, }, GUI = { Name = "1ly Grid", @@ -311,19 +306,20 @@ local plane10ly = { Rotation = { Type = "StaticRotation", Rotation = eclipticRotationMatrix + }, + Scale = { + Type = "StaticScale", + Scale = 10 } }, Renderable = { - Type = "RenderableDUMeshes", + Type = "RenderableGrid", Enabled = false, Opacity = 0.4, - File = speck .. "10ly.speck", - MeshColor = {{ 0.1, 0.5, 0.6 }}, - LabelFile = speck .. "10ly.label", - TextColor = { 0.0, 0.2, 0.5 }, - TextSize = 14.17, - TextMinMaxSize = { 0, 30 }, - Unit = "pc" + Color = { 0.1, 0.5, 0.6 }, + LineWidth = 2.0, + Segments = { 20, 20 }, + Size = { 2*lightYear, 2*lightYear }, }, GUI = { Name = "10ly Grid", @@ -338,19 +334,20 @@ local plane100ly = { Rotation = { Type = "StaticRotation", Rotation = eclipticRotationMatrix + }, + Scale = { + Type = "StaticScale", + Scale = 100 } }, Renderable = { - Type = "RenderableDUMeshes", + Type = "RenderableGrid", Enabled = false, Opacity = 0.4, - File = speck .. "100ly.speck", - MeshColor = {{ 0.1, 0.5, 0.6 }}, - LabelFile = speck .. "100ly.label", - TextColor = { 0.0, 0.2, 0.5 }, - TextSize = 15.0, - TextMinMaxSize = { 0, 30 }, - Unit = "pc" + Color = { 0.1, 0.5, 0.6 }, + LineWidth = 2.0, + Segments = { 20, 20 }, + Size = { 2*lightYear, 2*lightYear }, }, GUI = { Name = "100ly Grid", @@ -365,19 +362,20 @@ local plane1kly = { Rotation = { Type = "StaticRotation", Rotation = eclipticRotationMatrix + }, + Scale = { + Type = "StaticScale", + Scale = 1000 } }, Renderable = { - Type = "RenderableDUMeshes", + Type = "RenderableGrid", Enabled = false, Opacity = 0.4, - File = speck .. "1kly.speck", - MeshColor = {{ 0.1, 0.5, 0.6 }}, - LabelFile = speck .. "1kly.label", - TextColor = { 0.0, 0.2, 0.5 }, - TextSize = 16.0, - TextMinMaxSize = { 0, 30 }, - Unit = "pc" + Color = { 0.1, 0.5, 0.6 }, + LineWidth = 2.0, + Segments = { 20, 20 }, + Size = { 2*lightYear, 2*lightYear }, }, GUI = { Name = "1kly Grid", @@ -392,19 +390,20 @@ local plane10kly = { Rotation = { Type = "StaticRotation", Rotation = eclipticRotationMatrix + }, + Scale = { + Type = "StaticScale", + Scale = 10000 } }, Renderable = { - Type = "RenderableDUMeshes", + Type = "RenderableGrid", Enabled = false, Opacity = 0.4, - File = speck .. "10kly.speck", - MeshColor = {{ 0.1, 0.5, 0.6 }}, - LabelFile = speck .. "10kly.label", - TextColor = { 0.0, 0.2, 0.5 }, - TextSize = 17.25, - TextMinMaxSize = { 0, 30 }, - Unit = "pc" + Color = { 0.1, 0.5, 0.6 }, + LineWidth = 2.0, + Segments = { 20, 20 }, + Size = { 2*lightYear, 2*lightYear }, }, GUI = { Name = "10kly Grid", @@ -431,6 +430,29 @@ local plane100kly = { Path = "/Other/Grids" } } +--[[ +local plane100klynew = { + Identifier = "100klyGridnew", + Transform = { + Scale = { + Type = "StaticScale", + Scale = 100000 + } + }, + Renderable = { + Type = "RenderableGrid", + Enabled = false, + Opacity = 0.4, + Color = { 0.1, 0.5, 0.6 }, + LineWidth = 2.0, + Segments = { 20, 20 }, + Size = { 2*lightYear, 2*lightYear }, + }, + GUI = { + Name = "100kly Grid new", + Path = "/Other/Grids" + } +}]] local plane1Mly = { Identifier = "1MlyGrid", @@ -451,6 +473,29 @@ local plane1Mly = { Path = "/Other/Grids" } } +--[[ +local plane1Mlynew = { + Identifier = "1MlyGridnew", + Transform = { + Scale = { + Type = "StaticScale", + Scale = 1000000 + } + }, + Renderable = { + Type = "RenderableGrid", + Enabled = false, + Opacity = 0.4, + Color = { 0.1, 0.5, 0.6 }, + LineWidth = 2.0, + Segments = { 20, 20 }, + Size = { 2*lightYear, 2*lightYear }, + }, + GUI = { + Name = "1Mly Grid new", + Path = "/Other/Grids" + } +}]] local plane10Mly = { Identifier = "10MlyGrid", @@ -471,6 +516,29 @@ local plane10Mly = { Path = "/Other/Grids" } } +--[[ +local plane10Mlynew = { + Identifier = "10MlyGridnew", + Transform = { + Scale = { + Type = "StaticScale", + Scale = 10000000 + } + }, + Renderable = { + Type = "RenderableGrid", + Enabled = false, + Opacity = 0.4, + Color = { 0.1, 0.5, 0.6 }, + LineWidth = 2.0, + Segments = { 20, 20 }, + Size = { 2*lightYear, 2*lightYear }, + }, + GUI = { + Name = "10Mly Grid new", + Path = "/Other/Grids" + } +}]] local plane100Mly = { Identifier = "100MlyGrid", @@ -491,6 +559,29 @@ local plane100Mly = { Path = "/Other/Grids" } } +--[[ +local plane100Mlynew = { + Identifier = "100MlyGridnew", + Transform = { + Scale = { + Type = "StaticScale", + Scale = 100000000 + } + }, + Renderable = { + Type = "RenderableGrid", + Enabled = false, + Opacity = 0.4, + Color = { 0.1, 0.5, 0.6 }, + LineWidth = 2.0, + Segments = { 20, 20 }, + Size = { 2*lightYear, 2*lightYear }, + }, + GUI = { + Name = "100Mly Grid new", + Path = "/Other/Grids" + } +}]] local plane20Gly = { Identifier = "20GlyGrid", @@ -511,6 +602,29 @@ local plane20Gly = { Path = "/Other/Grids" } } +--[[ +local plane20Glynew = { + Identifier = "20GlyGridnew", + Transform = { + Scale = { + Type = "StaticScale", + Scale = 20000000000 + } + }, + Renderable = { + Type = "RenderableGrid", + Enabled = false, + Opacity = 0.4, + Color = { 0.1, 0.5, 0.6 }, + LineWidth = 2.0, + Segments = { 20, 20 }, + Size = { 2*lightYear, 2*lightYear }, + }, + GUI = { + Name = "20Gly Grid new", + Path = "/Other/Grids" + } +}]] local nodes = { radio, oort, ecliptic, eclipticLabels, equatorial, equatorialLabels, From 01eabd1b0286b068baa7c1639629b9ee1aabbd6b Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Fri, 26 Aug 2022 09:13:02 +0200 Subject: [PATCH 29/79] Consistent allocation of callback vectors --- src/engine/globalscallbacks.cpp | 66 ++++++++++++++++----------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/engine/globalscallbacks.cpp b/src/engine/globalscallbacks.cpp index e7e871e42b..d7f32f697c 100644 --- a/src/engine/globalscallbacks.cpp +++ b/src/engine/globalscallbacks.cpp @@ -66,75 +66,75 @@ void create() { #endif // WIN32 #ifdef WIN32 - initialize = new (currentPos) std::vector>; + initialize = new (currentPos) std::vector>(); ghoul_assert(initialize, "No initialize"); currentPos += sizeof(std::vector>); #else // ^^^ WIN32 / !WIN32 vvv - initialize = new std::vector>; + initialize = new std::vector>(); #endif // WIN32 #ifdef WIN32 - deinitialize = new (currentPos) std::vector>; + deinitialize = new (currentPos) std::vector>(); ghoul_assert(deinitialize, "No deinitialize"); currentPos += sizeof(std::vector>); #else // ^^^ WIN32 / !WIN32 vvv - deinitialize = new std::vector>; + deinitialize = new std::vector>(); #endif // WIN32 #ifdef WIN32 - initializeGL = new (currentPos) std::vector>; + initializeGL = new (currentPos) std::vector>(); ghoul_assert(initializeGL, "No initializeGL"); currentPos += sizeof(std::vector>); #else // ^^^ WIN32 / !WIN32 vvv - initializeGL = new std::vector>; + initializeGL = new std::vector(); #endif // WIN32 #ifdef WIN32 - deinitializeGL = new (currentPos) std::vector>; + deinitializeGL = new (currentPos) std::vector>(); ghoul_assert(deinitializeGL, "No deinitializeGL"); currentPos += sizeof(std::vector>); #else // ^^^ WIN32 / !WIN32 vvv - deinitializeGL = new std::vector>; + deinitializeGL = new std::vector>(); #endif // WIN32 #ifdef WIN32 - preSync = new (currentPos) std::vector>; + preSync = new (currentPos) std::vector>(); ghoul_assert(preSync, "No preSync"); currentPos += sizeof(std::vector>); #else // ^^^ WIN32 / !WIN32 vvv - preSync = new std::vector>; + preSync = new std::vector>(); #endif // WIN32 #ifdef WIN32 - postSyncPreDraw = new (currentPos) std::vector>; + postSyncPreDraw = new (currentPos) std::vector>(); ghoul_assert(postSyncPreDraw, "No postSyncPreDraw"); currentPos += sizeof(std::vector>); #else // ^^^ WIN32 / !WIN32 vvv - postSyncPreDraw = new std::vector>; + postSyncPreDraw = new std::vector>(); #endif // WIN32 #ifdef WIN32 - render = new (currentPos) std::vector>; + render = new (currentPos) std::vector>(); ghoul_assert(render, "No render"); currentPos += sizeof(std::vector>); #else // ^^^ WIN32 / !WIN32 vvv - render = new std::vector>; + render = new std::vector>(); #endif // WIN32 #ifdef WIN32 - draw2D = new (currentPos) std::vector>; + draw2D = new (currentPos) std::vector>(); ghoul_assert(draw2D, "No draw2D"); currentPos += sizeof(std::vector>); #else // ^^^ WIN32 / !WIN32 vvv - draw2D = new std::vector>; + draw2D = new std::vector>(); #endif // WIN32 #ifdef WIN32 - postDraw = new (currentPos) std::vector>; + postDraw = new (currentPos) std::vector>(); ghoul_assert(postDraw, "No postDraw"); currentPos += sizeof(std::vector>); #else // ^^^ WIN32 / !WIN32 vvv - postDraw = new std::vector>; + postDraw = new std::vector>(); #endif // WIN32 #ifdef WIN32 @@ -142,64 +142,64 @@ void create() { ghoul_assert(keyboard, "No keyboard"); currentPos += sizeof(std::vector); #else // ^^^ WIN32 / !WIN32 vvv - keyboard = new std::vector; + keyboard = new std::vector(); #endif // WIN32 #ifdef WIN32 - character = new (currentPos) std::vector; + character = new (currentPos) std::vector(); ghoul_assert(character, "No character"); currentPos += sizeof(std::vector); #else // ^^^ WIN32 / !WIN32 vvv - character = new std::vector; + character = new std::vector(); #endif // WIN32 #ifdef WIN32 - mouseButton = new (currentPos) std::vector; + mouseButton = new (currentPos) std::vector(); ghoul_assert(mouseButton, "No mouseButton"); currentPos += sizeof(std::vector); #else // ^^^ WIN32 / !WIN32 vvv - mouseButton = new std::vector; + mouseButton = new std::vector(); #endif // WIN32 #ifdef WIN32 mousePosition = - new (currentPos) std::vector; + new (currentPos) std::vector(); ghoul_assert(mousePosition, "No mousePosition"); currentPos += sizeof(std::vector); #else // ^^^ WIN32 / !WIN32 vvv - mousePosition = new std::vector; + mousePosition = new std::vector(); #endif // WIN32 #ifdef WIN32 - mouseScrollWheel = new (currentPos) std::vector; + mouseScrollWheel = new (currentPos) std::vector(); ghoul_assert(mouseScrollWheel, "No mouseScrollWheel"); currentPos += sizeof(std::vector); #else // ^^^ WIN32 / !WIN32 vvv - mouseScrollWheel = new std::vector; + mouseScrollWheel = new std::vector(); #endif // WIN32 #ifdef WIN32 - touchDetected = new (currentPos) std::vector>; + touchDetected = new (currentPos) std::vector>(); ghoul_assert(touchDetected, "No touchDetected"); currentPos += sizeof(std::vector>); #else // ^^^ WIN32 / !WIN32 vvv - touchDetected = new std::vector>; + touchDetected = new std::vector>(); #endif // WIN32 #ifdef WIN32 - touchUpdated = new (currentPos) std::vector>; + touchUpdated = new (currentPos) std::vector>(); ghoul_assert(touchUpdated, "No touchUpdated"); currentPos += sizeof(std::vector>); #else // ^^^ WIN32 / !WIN32 vvv - touchUpdated = new std::vector>; + touchUpdated = new std::vector>(); #endif // WIN32 #ifdef WIN32 - touchExit = new (currentPos) std::vector>; + touchExit = new (currentPos) std::vector>(); ghoul_assert(touchExit, "No touchExit"); //currentPos += sizeof(std::vector>); #else // ^^^ WIN32 / !WIN32 vvv - touchExit = new std::vector>; + touchExit = new std::vector>(); #endif // WIN32 } From 742754424301e4a3ebf6fde42372ac49ef704409 Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 26 Aug 2022 11:22:47 +0200 Subject: [PATCH 30/79] Add initial version of highlight feature * Note that it currently does not work well if the number of segments are odd --- .../base/rendering/grids/renderablegrid.cpp | 158 ++++++++++++++++-- modules/base/rendering/grids/renderablegrid.h | 6 + 2 files changed, 152 insertions(+), 12 deletions(-) diff --git a/modules/base/rendering/grids/renderablegrid.cpp b/modules/base/rendering/grids/renderablegrid.cpp index eb472e597f..a0bd21f103 100644 --- a/modules/base/rendering/grids/renderablegrid.cpp +++ b/modules/base/rendering/grids/renderablegrid.cpp @@ -42,6 +42,12 @@ namespace { "This value determines the color of the grid lines that are rendered" }; + constexpr openspace::properties::Property::PropertyInfo HighlightColorInfo = { + "HighlightColor", + "Highlight Color", + "This value determines the color of the highlighted lines in the grid" + }; + constexpr openspace::properties::Property::PropertyInfo SegmentsInfo = { "Segments", "Number of Segments", @@ -49,12 +55,24 @@ namespace { "grid in each direction" }; + constexpr openspace::properties::Property::PropertyInfo HighlightRateInfo = { + "HighlightRate", + "Highlight Rate", + "The rate the columns and rows are highlighted" + }; + constexpr openspace::properties::Property::PropertyInfo LineWidthInfo = { "LineWidth", "Line Width", "This value specifies the line width of the grid" }; + constexpr openspace::properties::Property::PropertyInfo HighlightLineWidthInfo = { + "HighlightLineWidth", + "HighlightLine Width", + "This value specifies the line width of the highlighted lines in the grid" + }; + constexpr openspace::properties::Property::PropertyInfo SizeInfo = { "Size", "Grid Size", @@ -65,12 +83,21 @@ namespace { // [[codegen::verbatim(ColorInfo.description)]] std::optional color [[codegen::color()]]; + // [[codegen::verbatim(HighlightColorInfo.description)]] + std::optional highlightColor [[codegen::color()]]; + // [[codegen::verbatim(SegmentsInfo.description)]] std::optional segments; + // [[codegen::verbatim(HighlightRateInfo.description)]] + std::optional highlightRate; + // [[codegen::verbatim(LineWidthInfo.description)]] std::optional lineWidth; + // [[codegen::verbatim(HighlightLineWidthInfo.description)]] + std::optional highlightLineWidth; + // [[codegen::verbatim(SizeInfo.description)]] std::optional size; }; @@ -86,8 +113,11 @@ documentation::Documentation RenderableGrid::Documentation() { RenderableGrid::RenderableGrid(const ghoul::Dictionary& dictionary) : Renderable(dictionary) , _color(ColorInfo, glm::vec3(0.5f), glm::vec3(0.f), glm::vec3(1.f)) + , _highlightColor(HighlightColorInfo, glm::vec3(0.8f), glm::vec3(0.f), glm::vec3(1.f)) , _segments(SegmentsInfo, glm::uvec2(10), glm::uvec2(1), glm::uvec2(200)) + , _highlightRate(HighlightRateInfo, glm::uvec2(5), glm::uvec2(0), glm::uvec2(200)) , _lineWidth(LineWidthInfo, 0.5f, 1.f, 20.f) + , _highlightLineWidth(HighlightLineWidthInfo, 0.5f, 1.f, 20.f) , _size(SizeInfo, glm::vec2(1.f), glm::vec2(1.f), glm::vec2(1e11f)) { const Parameters p = codegen::bake(dictionary); @@ -99,13 +129,24 @@ RenderableGrid::RenderableGrid(const ghoul::Dictionary& dictionary) _color.setViewOption(properties::Property::ViewOptions::Color); addProperty(_color); + _highlightColor = p.highlightColor.value_or(_highlightColor); + _highlightColor.setViewOption(properties::Property::ViewOptions::Color); + addProperty(_highlightColor); + _segments = p.segments.value_or(_segments); _segments.onChange([&]() { _gridIsDirty = true; }); addProperty(_segments); + _highlightRate = p.highlightRate.value_or(_highlightRate); + _highlightRate.onChange([&]() { _gridIsDirty = true; }); + addProperty(_highlightRate); + _lineWidth = p.lineWidth.value_or(_lineWidth); addProperty(_lineWidth); + _highlightLineWidth = p.highlightLineWidth.value_or(_highlightLineWidth); + addProperty(_highlightLineWidth); + _size.setExponent(10.f); _size = p.size.value_or(_size); _size.onChange([&]() { _gridIsDirty = true; }); @@ -130,9 +171,14 @@ void RenderableGrid::initializeGL() { glGenVertexArrays(1, &_vaoID); glGenBuffers(1, &_vBufferID); + glGenVertexArrays(1, &_highlightVaoID); + glGenBuffers(1, &_highlightVBufferID); glBindVertexArray(_vaoID); glBindBuffer(GL_ARRAY_BUFFER, _vBufferID); + glBindVertexArray(_highlightVaoID); + glBindBuffer(GL_ARRAY_BUFFER, _highlightVBufferID); + glEnableVertexAttribArray(0); glBindVertexArray(0); } @@ -140,9 +186,13 @@ void RenderableGrid::initializeGL() { void RenderableGrid::deinitializeGL() { glDeleteVertexArrays(1, &_vaoID); _vaoID = 0; + glDeleteVertexArrays(1, &_highlightVaoID); + _highlightVaoID = 0; glDeleteBuffers(1, &_vBufferID); _vBufferID = 0; + glDeleteBuffers(1, &_highlightVBufferID); + _highlightVBufferID = 0; BaseModule::ProgramObjectManager.release( "GridProgram", @@ -182,13 +232,24 @@ void RenderableGrid::render(const RenderData& data, RendererTasks&){ glEnable(GL_LINE_SMOOTH); glDepthMask(false); + // Render minor grid glBindVertexArray(_vaoID); glDrawArrays(_mode, 0, static_cast(_varray.size())); - glBindVertexArray(0); - _gridProgram->deactivate(); + // Render major grid +#ifndef __APPLE__ + glLineWidth(_highlightLineWidth); +#else + glLineWidth(1.f); +#endif + _gridProgram->setUniform("gridColor", _highlightColor); + + glBindVertexArray(_highlightVaoID); + glDrawArrays(_mode, 0, static_cast(_highlightArray.size())); // Restore GL State + glBindVertexArray(0); + _gridProgram->deactivate(); global::renderEngine->openglStateCache().resetBlendState(); global::renderEngine->openglStateCache().resetLineState(); global::renderEngine->openglStateCache().resetDepthState(); @@ -205,10 +266,14 @@ void RenderableGrid::update(const UpdateData&) { const int nLines = (2 * nSegments.x * nSegments.y) + nSegments.x + nSegments.y; const int nVertices = 2 * nLines; - _varray.resize(nVertices); + _varray.clear(); + _varray.reserve(nVertices); + _highlightArray.clear(); + _highlightArray.reserve(nVertices); // OBS! Could be optimized further by removing duplicate vertices - int nr = 0; + const glm::uvec2 center = glm::uvec2(nSegments.x / 2.f, nSegments.y / 2.f); + for (unsigned int i = 0; i < nSegments.x; ++i) { for (unsigned int j = 0; j < nSegments.y; ++j) { const float y0 = -halfSize.y + j * step.y; @@ -217,11 +282,39 @@ void RenderableGrid::update(const UpdateData&) { const float x0 = -halfSize.x + i * step.x; const float x1 = x0 + step.x; - _varray[nr++] = { x0, y0, 0.f }; - _varray[nr++] = { x0, y1, 0.f }; + // Line in y direction + if (_highlightRate.value().y != 0) { + int rest = static_cast(i - center.y) % _highlightRate.value().y; + if (abs(rest) == 0) { + _highlightArray.push_back({ x0, y0, 0.f }); + _highlightArray.push_back({ x0, y1, 0.f }); + } + else { + _varray.push_back({ x0, y0, 0.f }); + _varray.push_back({ x0, y1, 0.f }); + } + } + else { + _varray.push_back({ x0, y0, 0.f }); + _varray.push_back({ x0, y1, 0.f }); + } - _varray[nr++] = { x0, y0, 0.f }; - _varray[nr++] = { x1, y0, 0.f }; + // Line in x direction + if (_highlightRate.value().x != 0) { + int rest = static_cast(j - center.x) % _highlightRate.value().x; + if (abs(rest) == 0) { + _highlightArray.push_back({ x0, y0, 0.f }); + _highlightArray.push_back({ x1, y0, 0.f }); + } + else { + _varray.push_back({ x0, y0, 0.f }); + _varray.push_back({ x1, y0, 0.f }); + } + } + else { + _varray.push_back({ x0, y0, 0.f }); + _varray.push_back({ x1, y0, 0.f }); + } } } @@ -229,20 +322,49 @@ void RenderableGrid::update(const UpdateData&) { for (unsigned int i = 0; i < nSegments.x; ++i) { const float x0 = -halfSize.x + i * step.x; const float x1 = x0 + step.x; - _varray[nr++] = { x0, halfSize.y, 0.f }; - _varray[nr++] = { x1, halfSize.y, 0.f }; + + if (_highlightRate.value().x != 0) { + int rest = static_cast(nSegments.y - center.x) % _highlightRate.value().x; + if (abs(rest) == 0) { + _highlightArray.push_back({ x0, halfSize.y, 0.f }); + _highlightArray.push_back({ x1, halfSize.y, 0.f }); + } + else { + _varray.push_back({ x0, halfSize.y, 0.f }); + _varray.push_back({ x1, halfSize.y, 0.f }); + } + } + else { + _varray.push_back({ x0, halfSize.y, 0.f }); + _varray.push_back({ x1, halfSize.y, 0.f }); + } } // last y col for (unsigned int i = 0; i < nSegments.y; ++i) { const float y0 = -halfSize.y + i * step.y; const float y1 = y0 + step.y; - _varray[nr++] = { halfSize.x, y0, 0.f }; - _varray[nr++] = { halfSize.x, y1, 0.f }; + + if (_highlightRate.value().y != 0) { + int rest = static_cast(nSegments.x - center.y) % _highlightRate.value().y; + if (abs(rest) == 0) { + _highlightArray.push_back({ halfSize.x, y0, 0.f }); + _highlightArray.push_back({ halfSize.x, y1, 0.f }); + } + else { + _varray.push_back({ halfSize.x, y0, 0.f }); + _varray.push_back({ halfSize.x, y1, 0.f }); + } + } + else { + _varray.push_back({ halfSize.x, y0, 0.f }); + _varray.push_back({ halfSize.x, y1, 0.f }); + } } setBoundingSphere(glm::length(glm::dvec2(halfSize))); + // Minor grid glBindVertexArray(_vaoID); glBindBuffer(GL_ARRAY_BUFFER, _vBufferID); glBufferData( @@ -251,7 +373,19 @@ void RenderableGrid::update(const UpdateData&) { _varray.data(), GL_STATIC_DRAW ); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), nullptr); + // Major grid + glBindVertexArray(_highlightVaoID); + glBindBuffer(GL_ARRAY_BUFFER, _highlightVBufferID); + glBufferData( + GL_ARRAY_BUFFER, + _highlightArray.size() * sizeof(Vertex), + _highlightArray.data(), + GL_STATIC_DRAW + ); + glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), nullptr); glBindVertexArray(0); diff --git a/modules/base/rendering/grids/renderablegrid.h b/modules/base/rendering/grids/renderablegrid.h index 4b9c71701e..3ebfa0f589 100644 --- a/modules/base/rendering/grids/renderablegrid.h +++ b/modules/base/rendering/grids/renderablegrid.h @@ -61,19 +61,25 @@ protected: ghoul::opengl::ProgramObject* _gridProgram = nullptr; properties::Vec3Property _color; + properties::Vec3Property _highlightColor; // @TODO (abock, 2021-01-28) This was a UVec2Property before, but it wasn't supported // be the codegen. As soon as it does, this should be changed back properties::IVec2Property _segments; + properties::IVec2Property _highlightRate; properties::FloatProperty _lineWidth; + properties::FloatProperty _highlightLineWidth; properties::Vec2Property _size; bool _gridIsDirty = true; GLuint _vaoID = 0; GLuint _vBufferID = 0; + GLuint _highlightVaoID = 0; + GLuint _highlightVBufferID = 0; GLenum _mode = GL_LINES; std::vector _varray; + std::vector _highlightArray; }; }// namespace openspace From 767f6aa547acd65ddd14949d4a65420ade9616b0 Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 26 Aug 2022 13:46:33 +0200 Subject: [PATCH 31/79] Use highlight feature on large grids --- data/assets/scene/digitaluniverse/grids.asset | 148 ++++-------------- .../base/rendering/grids/renderablegrid.cpp | 6 +- src/rendering/renderable.cpp | 6 +- 3 files changed, 36 insertions(+), 124 deletions(-) diff --git a/data/assets/scene/digitaluniverse/grids.asset b/data/assets/scene/digitaluniverse/grids.asset index 14134a1ed1..44e81c0ff1 100644 --- a/data/assets/scene/digitaluniverse/grids.asset +++ b/data/assets/scene/digitaluniverse/grids.asset @@ -413,26 +413,6 @@ local plane10kly = { local plane100kly = { Identifier = "100klyGrid", - Renderable = { - Type = "RenderableDUMeshes", - Enabled = false, - Opacity = 0.4, - File = speck .. "100kly.speck", - MeshColor = {{ 0.1, 0.5, 0.6 }}, - LabelFile = speck .. "100kly.label", - TextColor = { 0.0, 0.2, 0.5 }, - TextSize = 18.6, - TextMinMaxSize = { 0, 30 }, - Unit = "Mpc" - }, - GUI = { - Name = "100kly Grid", - Path = "/Other/Grids" - } -} ---[[ -local plane100klynew = { - Identifier = "100klyGridnew", Transform = { Scale = { Type = "StaticScale", @@ -444,38 +424,20 @@ local plane100klynew = { Enabled = false, Opacity = 0.4, Color = { 0.1, 0.5, 0.6 }, + HighlightColor = { 0.3, 0.7, 0.8 }, LineWidth = 2.0, Segments = { 20, 20 }, + HighlightRate = { 5, 5}, Size = { 2*lightYear, 2*lightYear }, }, GUI = { - Name = "100kly Grid new", - Path = "/Other/Grids" - } -}]] - -local plane1Mly = { - Identifier = "1MlyGrid", - Renderable = { - Type = "RenderableDUMeshes", - Enabled = false, - Opacity = 0.4, - File = speck .. "1Mly.speck", - MeshColor = {{ 0.1, 0.5, 0.6 }}, - LabelFile = speck .. "1Mly.label", - TextColor = { 0.0, 0.2, 0.5 }, - TextSize = 19.6, - TextMinMaxSize = { 0, 30 }, - Unit = "Mpc" - }, - GUI = { - Name = "1Mly Grid", + Name = "100kly Grid", Path = "/Other/Grids" } } ---[[ -local plane1Mlynew = { - Identifier = "1MlyGridnew", + +local plane1Mly = { + Identifier = "1MlyGrid", Transform = { Scale = { Type = "StaticScale", @@ -487,38 +449,20 @@ local plane1Mlynew = { Enabled = false, Opacity = 0.4, Color = { 0.1, 0.5, 0.6 }, + HighlightColor = {0.3, 0.7, 0.8 }, LineWidth = 2.0, Segments = { 20, 20 }, + HighlightRate = { 5, 5}, Size = { 2*lightYear, 2*lightYear }, }, GUI = { - Name = "1Mly Grid new", - Path = "/Other/Grids" - } -}]] - -local plane10Mly = { - Identifier = "10MlyGrid", - Renderable = { - Type = "RenderableDUMeshes", - Enabled = false, - Opacity = 0.4, - File = speck .. "10Mly.speck", - MeshColor = {{ 0.1, 0.5, 0.6 }}, - LabelFile = speck .. "10Mly.label", - TextColor = { 0.0, 0.2, 0.5 }, - TextSize = 20.6, - TextMinMaxSize = { 0, 30 }, - Unit = "Mpc" - }, - GUI = { - Name = "10Mly Grid", + Name = "1Mly Grid", Path = "/Other/Grids" } } ---[[ -local plane10Mlynew = { - Identifier = "10MlyGridnew", + +local plane10Mly = { + Identifier = "10MlyGrid", Transform = { Scale = { Type = "StaticScale", @@ -530,38 +474,20 @@ local plane10Mlynew = { Enabled = false, Opacity = 0.4, Color = { 0.1, 0.5, 0.6 }, + HighlightColor = { 0.3, 0.7, 0.8 }, LineWidth = 2.0, Segments = { 20, 20 }, + HighlightRate = { 5, 5}, Size = { 2*lightYear, 2*lightYear }, }, GUI = { - Name = "10Mly Grid new", - Path = "/Other/Grids" - } -}]] - -local plane100Mly = { - Identifier = "100MlyGrid", - Renderable = { - Type = "RenderableDUMeshes", - Enabled = false, - Opacity = 0.4, - File = speck .. "100Mly.speck", - MeshColor = {{ 0.1, 0.5, 0.6 }}, - LabelFile = speck .. "100Mly.label", - TextColor = { 0.0, 0.2, 0.5 }, - TextSize = 21.6, - TextMinMaxSize = { 0, 30 }, - Unit = "Mpc" - }, - GUI = { - Name = "100Mly Grid", + Name = "10Mly Grid", Path = "/Other/Grids" } } ---[[ -local plane100Mlynew = { - Identifier = "100MlyGridnew", + +local plane100Mly = { + Identifier = "100MlyGrid", Transform = { Scale = { Type = "StaticScale", @@ -573,38 +499,20 @@ local plane100Mlynew = { Enabled = false, Opacity = 0.4, Color = { 0.1, 0.5, 0.6 }, + HighlightColor = { 0.3, 0.7, 0.8 }, LineWidth = 2.0, Segments = { 20, 20 }, + HighlightRate = { 5, 5}, Size = { 2*lightYear, 2*lightYear }, }, GUI = { - Name = "100Mly Grid new", - Path = "/Other/Grids" - } -}]] - -local plane20Gly = { - Identifier = "20GlyGrid", - Renderable = { - Type = "RenderableDUMeshes", - Enabled = false, - Opacity = 0.4, - File = speck .. "20Gly.speck", - MeshColor = {{ 0.1, 0.5, 0.6 }}, - LabelFile = speck .. "20Gly.label", - TextColor = { 0.0, 0.2, 0.5 }, - TextSize = 23.6, - TextMinMaxSize = { 0, 30 }, - Unit = "Mpc" - }, - GUI = { - Name = "20Gly Grid", + Name = "100Mly Grid", Path = "/Other/Grids" } } ---[[ -local plane20Glynew = { - Identifier = "20GlyGridnew", + +local plane20Gly = { + Identifier = "20GlyGrid", Transform = { Scale = { Type = "StaticScale", @@ -616,15 +524,17 @@ local plane20Glynew = { Enabled = false, Opacity = 0.4, Color = { 0.1, 0.5, 0.6 }, + HighlightColor = { 0.3, 0.7, 0.8 }, LineWidth = 2.0, - Segments = { 20, 20 }, + Segments = { 40, 40 }, + HighlightRate = { 5, 5}, Size = { 2*lightYear, 2*lightYear }, }, GUI = { - Name = "20Gly Grid new", + Name = "20Gly Grid", Path = "/Other/Grids" } -}]] +} local nodes = { radio, oort, ecliptic, eclipticLabels, equatorial, equatorialLabels, diff --git a/modules/base/rendering/grids/renderablegrid.cpp b/modules/base/rendering/grids/renderablegrid.cpp index a0bd21f103..51a115d3b0 100644 --- a/modules/base/rendering/grids/renderablegrid.cpp +++ b/modules/base/rendering/grids/renderablegrid.cpp @@ -129,7 +129,8 @@ RenderableGrid::RenderableGrid(const ghoul::Dictionary& dictionary) _color.setViewOption(properties::Property::ViewOptions::Color); addProperty(_color); - _highlightColor = p.highlightColor.value_or(_highlightColor); + // If no highlight color is specified then use the base color + _highlightColor = p.highlightColor.value_or(_color); _highlightColor.setViewOption(properties::Property::ViewOptions::Color); addProperty(_highlightColor); @@ -144,7 +145,8 @@ RenderableGrid::RenderableGrid(const ghoul::Dictionary& dictionary) _lineWidth = p.lineWidth.value_or(_lineWidth); addProperty(_lineWidth); - _highlightLineWidth = p.highlightLineWidth.value_or(_highlightLineWidth); + // If no highlight line width is specified then use the base line width + _highlightLineWidth = p.highlightLineWidth.value_or(_lineWidth); addProperty(_highlightLineWidth); _size.setExponent(10.f); diff --git a/src/rendering/renderable.cpp b/src/rendering/renderable.cpp index 90db17c018..3b54240258 100644 --- a/src/rendering/renderable.cpp +++ b/src/rendering/renderable.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include #include @@ -207,7 +207,7 @@ Renderable::Renderable(const ghoul::Dictionary& dictionary) if (p.renderBinMode.has_value()) { setRenderBin(codegen::map(*p.renderBinMode)); } - + _dimInAtmosphere = p.dimInAtmosphere.value_or(_dimInAtmosphere); addProperty(_dimInAtmosphere); } @@ -313,7 +313,7 @@ void Renderable::registerUpdateRenderBinFromOpacity() { } float Renderable::opacity() const { - // Rendering should depend on if camera is in the atmosphere and if camera is at the + // Rendering should depend on if camera is in the atmosphere and if camera is at the // dark part of the globe return _dimInAtmosphere ? _opacity * _fade * global::navigationHandler->camera()->atmosphereDimmingFactor() : From d1259c83a22677d0db18d87b8f4adc3208868956 Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 26 Aug 2022 14:10:02 +0200 Subject: [PATCH 32/79] Small clean up --- modules/base/rendering/grids/renderablegrid.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/base/rendering/grids/renderablegrid.cpp b/modules/base/rendering/grids/renderablegrid.cpp index 51a115d3b0..01f5243771 100644 --- a/modules/base/rendering/grids/renderablegrid.cpp +++ b/modules/base/rendering/grids/renderablegrid.cpp @@ -274,8 +274,8 @@ void RenderableGrid::update(const UpdateData&) { _highlightArray.reserve(nVertices); // OBS! Could be optimized further by removing duplicate vertices + // If the number of segments are uneven the center won't be completly centered const glm::uvec2 center = glm::uvec2(nSegments.x / 2.f, nSegments.y / 2.f); - for (unsigned int i = 0; i < nSegments.x; ++i) { for (unsigned int j = 0; j < nSegments.y; ++j) { const float y0 = -halfSize.y + j * step.y; @@ -375,7 +375,6 @@ void RenderableGrid::update(const UpdateData&) { _varray.data(), GL_STATIC_DRAW ); - glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), nullptr); // Major grid @@ -387,7 +386,6 @@ void RenderableGrid::update(const UpdateData&) { _highlightArray.data(), GL_STATIC_DRAW ); - glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), nullptr); glBindVertexArray(0); From 664eb60f4f11a34cefb63d114efffe29b88fc126 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 26 Aug 2022 16:32:21 +0200 Subject: [PATCH 33/79] Increase the compile times by including more precompiled headers (#2217) * Define WIN32_LEAN_AND_MEAN and VC_EXTRALEAN globally * Use forked version of TUIO, some more work on precompiled headers * Improvements for the Kameleon module --- .gitmodules | 2 +- apps/OpenSpace/ext/launcher/CMakeLists.txt | 23 ++++++-- apps/OpenSpace/ext/sgct | 2 +- apps/OpenSpace/main.cpp | 28 +++------- ext/CMakeLists.txt | 1 + ext/ghoul | 2 +- ext/spice | 2 +- include/openspace/util/histogram.h | 2 - .../rendering/renderableatmosphere.cpp | 1 + modules/base/CMakeLists.txt | 11 ++++ modules/cefwebgui/CMakeLists.txt | 14 +++++ .../util/kameleonfieldlinehelper.cpp | 1 + modules/fitsfilereader/CMakeLists.txt | 5 ++ modules/globebrowsing/CMakeLists.txt | 6 ++ modules/globebrowsing/src/shadowcomponent.cpp | 9 ++- modules/iswa/CMakeLists.txt | 4 ++ modules/iswa/rendering/iswacygnet.h | 2 + modules/iswa/util/iswamanager.cpp | 55 +++++++++---------- modules/kameleon/CMakeLists.txt | 14 +++++ modules/kameleon/ext/kameleon | 2 +- modules/kameleon/src/kameleonhelper.cpp | 1 + modules/kameleon/src/kameleonwrapper.cpp | 2 + .../kameleonvolume/kameleonvolumereader.cpp | 1 + .../rendering/histogrammanager.h | 1 - modules/server/CMakeLists.txt | 7 +++ modules/skybrowser/CMakeLists.txt | 4 ++ modules/space/CMakeLists.txt | 9 +++ modules/spacecraftinstruments/CMakeLists.txt | 3 + modules/statemachine/CMakeLists.txt | 29 ++++++---- modules/statemachine/src/statemachine.cpp | 1 + modules/touch/ext/CMakeLists.txt | 17 ++++++ modules/touch/ext/libTUIO11 | 2 +- modules/touch/touchmodule.cpp | 7 --- modules/webbrowser/CMakeLists.txt | 26 ++++++++- src/CMakeLists.txt | 9 +++ src/engine/downloadmanager.cpp | 1 + src/engine/openspaceengine.cpp | 5 ++ src/interaction/sessionrecording.cpp | 2 +- src/rendering/helper.cpp | 1 + src/rendering/loadingscreen.cpp | 1 + src/rendering/luaconsole.cpp | 1 + src/rendering/renderengine.cpp | 1 + src/rendering/screenspacerenderable.cpp | 1 + src/rendering/transferfunction.cpp | 1 + src/scene/scene.cpp | 1 + src/util/blockplaneintersectiongeometry.cpp | 1 + src/util/boxgeometry.cpp | 1 + src/util/planegeometry.cpp | 1 + src/util/sphere.cpp | 1 + support/cmake/application_definition.cmake | 34 ++++++------ support/cmake/module_definition.cmake | 10 ++-- .../set_openspace_compile_settings.cmake | 4 +- support/coding/codegen | 2 +- 53 files changed, 261 insertions(+), 113 deletions(-) diff --git a/.gitmodules b/.gitmodules index 112e7a1300..3632c848dd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -9,7 +9,7 @@ url = https://github.com/OpenSpace/Spice.git [submodule "modules/touch/ext/libTUIO11"] path = modules/touch/ext/libTUIO11 - url = https://github.com/mkalten/TUIO11_CPP + url = https://github.com/OpenSpace/TUIO11_CPP.git [submodule "apps/OpenSpace-MinVR/ext/minvr"] path = apps/OpenSpace-MinVR/ext/minvr url = https://github.com/OpenSpace/minvr diff --git a/apps/OpenSpace/ext/launcher/CMakeLists.txt b/apps/OpenSpace/ext/launcher/CMakeLists.txt index 033750ebbf..1c85bd7569 100644 --- a/apps/OpenSpace/ext/launcher/CMakeLists.txt +++ b/apps/OpenSpace/ext/launcher/CMakeLists.txt @@ -127,11 +127,24 @@ target_link_libraries( Qt${QT_VERSION_MAJOR}::Network ) -if (MSVC) -set(MSVC_WARNINGS - "/wd4619" # #pragma warning: there is no warning number (raised by Qt headers) - "/wd4946" # reinterpret_cast used between related classes: +target_precompile_headers(openspace-ui-launcher PRIVATE + + + + + + + + + + + ) -target_compile_options(openspace-ui-launcher INTERFACE ${MSVC_WARNINGS}) +if (MSVC) + set(MSVC_WARNINGS + "/wd4619" # #pragma warning: there is no warning number (raised by Qt headers) + "/wd4946" # reinterpret_cast used between related classes: + ) + target_compile_options(openspace-ui-launcher INTERFACE ${MSVC_WARNINGS}) endif () diff --git a/apps/OpenSpace/ext/sgct b/apps/OpenSpace/ext/sgct index 6ab4ac31bf..e40111d616 160000 --- a/apps/OpenSpace/ext/sgct +++ b/apps/OpenSpace/ext/sgct @@ -1 +1 @@ -Subproject commit 6ab4ac31bf24dd7e60e58d8eedd37e4c2cc6df08 +Subproject commit e40111d616e85b61632b74a6b900fe6b88d2b74b diff --git a/apps/OpenSpace/main.cpp b/apps/OpenSpace/main.cpp index 1a9700ce4b..0799a706b6 100644 --- a/apps/OpenSpace/main.cpp +++ b/apps/OpenSpace/main.cpp @@ -28,21 +28,15 @@ #include #include #include -#include -#include +#include #include -#include +#include +#include #include #include -#include #include -#include -#include #include -#include -#include -#include -#include +#include #ifdef WIN32 #define GLFW_EXPOSE_NATIVE_WIN32 #endif @@ -54,25 +48,17 @@ #include #include #include -#include #include #include -#include +#include #include #include -#include -#include -#include -#include +#include +#include #ifdef WIN32 -#include -#include -#include #include #include -#include -#include #endif // WIN32 #ifdef OPENVR_SUPPORT diff --git a/ext/CMakeLists.txt b/ext/CMakeLists.txt index 1cf2528db1..079c95117b 100644 --- a/ext/CMakeLists.txt +++ b/ext/CMakeLists.txt @@ -56,6 +56,7 @@ set_folder_location(GhoulTest "Unit Tests") begin_dependency("Spice") set(SPICE_BUILD_SHARED_LIBRARY OFF CACHE BOOL "" FORCE) add_subdirectory(spice) +target_compile_features(spice PUBLIC cxx_std_20) set_folder_location(spice "External") end_dependency() diff --git a/ext/ghoul b/ext/ghoul index 7d53430d8c..1f420ed0f0 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 7d53430d8c0c810baffdb7b636e195957360e812 +Subproject commit 1f420ed0f03347ed3c8bb7550d58798f9a02cbc0 diff --git a/ext/spice b/ext/spice index 82e9b1fb97..bb7eded3a4 160000 --- a/ext/spice +++ b/ext/spice @@ -1 +1 @@ -Subproject commit 82e9b1fb978c42161edc535949d0fd6186e5a38c +Subproject commit bb7eded3a4c45eff33cee41f4d24fffe5248d01a diff --git a/include/openspace/util/histogram.h b/include/openspace/util/histogram.h index 047fa43ac8..828be5609e 100644 --- a/include/openspace/util/histogram.h +++ b/include/openspace/util/histogram.h @@ -80,11 +80,9 @@ private: float _minValue = 0.f; float _maxValue = 0.f; - float* _data = nullptr; std::vector _equalizer; int _numValues = 0; - }; } // namespace openspace diff --git a/modules/atmosphere/rendering/renderableatmosphere.cpp b/modules/atmosphere/rendering/renderableatmosphere.cpp index a9adf06243..6dc5035c7b 100644 --- a/modules/atmosphere/rendering/renderableatmosphere.cpp +++ b/modules/atmosphere/rendering/renderableatmosphere.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/modules/base/CMakeLists.txt b/modules/base/CMakeLists.txt index 4f975e1b8d..35a1526a97 100644 --- a/modules/base/CMakeLists.txt +++ b/modules/base/CMakeLists.txt @@ -165,3 +165,14 @@ create_new_module( STATIC ${HEADER_FILES} ${SOURCE_FILES} ${SHADER_FILES} ) +target_precompile_headers(${base_module} PRIVATE + + + + + + + + + +) diff --git a/modules/cefwebgui/CMakeLists.txt b/modules/cefwebgui/CMakeLists.txt index e664632cf4..d398c0926b 100644 --- a/modules/cefwebgui/CMakeLists.txt +++ b/modules/cefwebgui/CMakeLists.txt @@ -48,4 +48,18 @@ create_new_module( ${OPENSPACE_HEADER_FILES} ${OPENSPACE_SOURCE_FILES} ) +target_precompile_headers(${cefwebgui_module} PRIVATE + [["include/capi/cef_base_capi.h"]] + [["include/cef_render_handler.h"]] + + + + +) +if (WIN32) + target_precompile_headers(${cefwebgui_module} PRIVATE + + ) +endif () + set_modules_dependency_on_cef_libraries(${cefwebgui_module}) diff --git a/modules/fieldlinessequence/util/kameleonfieldlinehelper.cpp b/modules/fieldlinessequence/util/kameleonfieldlinehelper.cpp index c7c8fe9a5e..0811dba583 100644 --- a/modules/fieldlinessequence/util/kameleonfieldlinehelper.cpp +++ b/modules/fieldlinessequence/util/kameleonfieldlinehelper.cpp @@ -41,6 +41,7 @@ #include #include +#include #include #ifdef _MSC_VER diff --git a/modules/fitsfilereader/CMakeLists.txt b/modules/fitsfilereader/CMakeLists.txt index d849ea9d41..d111d5b60a 100644 --- a/modules/fitsfilereader/CMakeLists.txt +++ b/modules/fitsfilereader/CMakeLists.txt @@ -64,3 +64,8 @@ disable_external_warnings(CCfits) target_include_directories(openspace-module-fitsfilereader SYSTEM PRIVATE ${INCLUDES_FOR_TARGET}) target_link_libraries(openspace-module-fitsfilereader PRIVATE cfitsio CCfits) + +target_precompile_headers(CCfits PRIVATE + + +) diff --git a/modules/globebrowsing/CMakeLists.txt b/modules/globebrowsing/CMakeLists.txt index 70085041b4..aa26ff6b6c 100644 --- a/modules/globebrowsing/CMakeLists.txt +++ b/modules/globebrowsing/CMakeLists.txt @@ -139,6 +139,12 @@ create_new_module( STATIC ${HEADER_FILES} ${SOURCE_FILES} ${SHADER_FILES} ) +target_precompile_headers(${globebrowsing_module} PRIVATE + + + + +) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/gdal_data DESTINATION modules/globebrowsing) diff --git a/modules/globebrowsing/src/shadowcomponent.cpp b/modules/globebrowsing/src/shadowcomponent.cpp index ccff3cb64d..6f3ba1871c 100644 --- a/modules/globebrowsing/src/shadowcomponent.cpp +++ b/modules/globebrowsing/src/shadowcomponent.cpp @@ -512,7 +512,7 @@ void ShadowComponent::saveDepthBuffer() { << std::endl; ppmFile << "255" << std::endl; - std::cout << "\n\nSaving depth texture to file depthBufferShadowMapping.ppm\n\n"; + LDEBUG("Saving depth texture to file depthBufferShadowMapping.ppm"); int k = 0; for (int i = 0; i < _shadowDepthTextureWidth; i++) { for (int j = 0; j < _shadowDepthTextureHeight; j++, k++) { @@ -523,8 +523,7 @@ void ShadowComponent::saveDepthBuffer() { } ppmFile.close(); - - std::cout << "Texture saved to file depthBufferShadowMapping.ppm\n\n"; + LDEBUG("Texture saved to file depthBufferShadowMapping.ppm"); } buffer.clear(); @@ -552,7 +551,7 @@ void ShadowComponent::saveDepthBuffer() { << std::endl; ppmFile << "255" << std::endl; - std::cout << "\n\nSaving texture position to positionBufferShadowMapping.ppm\n\n"; + LDEBUG("Saving texture position to positionBufferShadowMapping.ppm"); float biggestValue = 0.f; @@ -580,7 +579,7 @@ void ShadowComponent::saveDepthBuffer() { ppmFile.close(); - LINFO("Texture saved to file positionBufferShadowMapping.ppm"); + LDEBUG("Texture saved to file positionBufferShadowMapping.ppm"); } } diff --git a/modules/iswa/CMakeLists.txt b/modules/iswa/CMakeLists.txt index 7d670e07b6..e547537a34 100644 --- a/modules/iswa/CMakeLists.txt +++ b/modules/iswa/CMakeLists.txt @@ -80,3 +80,7 @@ create_new_module( STATIC ${HEADER_FILES} ${SOURCE_FILES} ${SHADER_FILES} ) +target_precompile_headers(${iswa_module} PRIVATE + + +) diff --git a/modules/iswa/rendering/iswacygnet.h b/modules/iswa/rendering/iswacygnet.h index 7d1e355f89..dcd1dfa345 100644 --- a/modules/iswa/rendering/iswacygnet.h +++ b/modules/iswa/rendering/iswacygnet.h @@ -93,6 +93,7 @@ protected: * \return \c true if update was successful */ virtual bool updateTexture() = 0; + /** * Is called before updateTexture. For IswaCygnets getting data from a HTTP request, * this function should get the dataFile from the future object. @@ -100,6 +101,7 @@ protected: * \return \c true if update was successful */ virtual bool updateTextureResource() = 0; + /** * Should send a HTTP request to get the resource it needs to create a texture. For * Texture cygnets, this should be an image. For DataCygnets, this should be the data diff --git a/modules/iswa/util/iswamanager.cpp b/modules/iswa/util/iswamanager.cpp index dc7440f1f8..62a23c63ad 100644 --- a/modules/iswa/util/iswamanager.cpp +++ b/modules/iswa/util/iswamanager.cpp @@ -64,27 +64,25 @@ #endif // OPENSPACE_MODULE_KAMELEON_ENABLED -constexpr std::string_view monthNumber(std::string_view month) { - if (month == "JAN") return "01"; - else if (month == "FEB") return "02"; - else if (month == "MAR") return "03"; - else if (month == "APR") return "04"; - else if (month == "MAY") return "05"; - else if (month == "JUN") return "06"; - else if (month == "JUL") return "07"; - else if (month == "AUG") return "08"; - else if (month == "SEP") return "09"; - else if (month == "OCT") return "10"; - else if (month == "NOV") return "11"; - else if (month == "DEC") return "12"; - else return ""; -} - - namespace { - using json = nlohmann::json; constexpr std::string_view _loggerCat = "IswaManager"; + constexpr std::string_view monthNumber(std::string_view month) { + if (month == "JAN") return "01"; + else if (month == "FEB") return "02"; + else if (month == "MAR") return "03"; + else if (month == "APR") return "04"; + else if (month == "MAY") return "05"; + else if (month == "JUN") return "06"; + else if (month == "JUL") return "07"; + else if (month == "AUG") return "08"; + else if (month == "SEP") return "09"; + else if (month == "OCT") return "10"; + else if (month == "NOV") return "11"; + else if (month == "DEC") return "12"; + else return ""; + } + void createScreenSpace(int id) { std::string idStr = std::to_string(id); openspace::global::scriptEngine->queueScript( @@ -92,7 +90,6 @@ namespace { openspace::scripting::ScriptEngine::RemoteScripting::Yes ); } - } // namespace namespace openspace { @@ -178,7 +175,7 @@ void IswaManager::addIswaCygnet(int id, const std::string& type, std::string gro metaFuture.json = res; //convert to json - json j = json::parse(res); + nlohmann::json j = nlohmann::json::parse(res); // Check what kind of geometry here if (j["Coordinate Type"].is_null()) { @@ -357,7 +354,7 @@ std::string IswaManager::jsonPlaneToLuaTable(MetadataFuture& data) { if (data.json.empty()) { return ""; } - json j = json::parse(data.json); + nlohmann::json j = nlohmann::json::parse(data.json); std::string parent = j["Central Body"]; std::string frame = j["Coordinates"]; @@ -473,7 +470,7 @@ std::string IswaManager::jsonSphereToLuaTable(MetadataFuture& data) { return ""; } - json j = json::parse(data.json); + nlohmann::json j = nlohmann::json::parse(data.json); j = j["metadata"]; std::string parent = j["central_body"]; parent[0] = static_cast(toupper(static_cast(parent[0]))); @@ -667,16 +664,16 @@ void IswaManager::createFieldline(std::string name, std::string cdfPath, void IswaManager::fillCygnetInfo(std::string jsonString) { if (jsonString != "") { - json j = json::parse(jsonString); + nlohmann::json j = nlohmann::json::parse(jsonString); std::set lists = {"listOfPriorityCygnets", "listOfOKCygnets" // ,"listOfStaleCygnets", "listOfInactiveCygnets", }; for (const std::string& list : lists) { - json jsonList = j[list]; + nlohmann::json jsonList = j[list]; for (size_t i = 0; i < jsonList.size(); ++i) { - json jCygnet = jsonList.at(i); + nlohmann::json jCygnet = jsonList.at(i); std::string name = jCygnet["cygnetDisplayTitle"]; std::replace(name.begin(), name.end(),'.', ','); @@ -706,9 +703,9 @@ void IswaManager::addCdfFiles(std::string cdfpath) { std::ifstream jsonFile(cdfFile); if (jsonFile.is_open()) { - json cdfGroups = json::parse(jsonFile); + nlohmann::json cdfGroups = nlohmann::json::parse(jsonFile); for(size_t i = 0; i < cdfGroups.size(); ++i) { - json cdfGroup = cdfGroups.at(i); + nlohmann::json cdfGroup = cdfGroups.at(i); std::string groupName = cdfGroup["group"]; std::string fieldlineSeedsIndexFile = cdfGroup["fieldlinefile"]; @@ -720,9 +717,9 @@ void IswaManager::addCdfFiles(std::string cdfpath) { _cdfInformation[groupName] = std::vector(); - json cdfs = cdfGroup["cdfs"]; + nlohmann::json cdfs = cdfGroup["cdfs"]; for (size_t j = 0; j < cdfs.size(); j++) { - json cdf = cdfs.at(j); + nlohmann::json cdf = cdfs.at(j); std::string name = cdf["name"]; std::string path = cdf["path"]; diff --git a/modules/kameleon/CMakeLists.txt b/modules/kameleon/CMakeLists.txt index 51d5344b3a..1eb778e449 100644 --- a/modules/kameleon/CMakeLists.txt +++ b/modules/kameleon/CMakeLists.txt @@ -71,6 +71,20 @@ if (TARGET cdf) set_folder_location(cdf "External") endif () +target_precompile_headers(cdf PRIVATE + [["stdio.h"]] + [["stdlib.h"]] + [["string.h"]] +) + +target_precompile_headers(ccmc PRIVATE + "$<$:iostream>" + "$<$:map>" + "$<$:unordered_map>" + "$<$:vector>" + "$<$:boost/unordered_map.hpp>" +) + if (WIN32) target_compile_options(ccmc PRIVATE /MP) if (TARGET cdf) diff --git a/modules/kameleon/ext/kameleon b/modules/kameleon/ext/kameleon index 606edb945b..08b0e5dbfc 160000 --- a/modules/kameleon/ext/kameleon +++ b/modules/kameleon/ext/kameleon @@ -1 +1 @@ -Subproject commit 606edb945b62d0151f20270ddb2db4a9f558aaa1 +Subproject commit 08b0e5dbfc142ebb77d05409115d9df335d8abf7 diff --git a/modules/kameleon/src/kameleonhelper.cpp b/modules/kameleon/src/kameleonhelper.cpp index 95ca9bf3f2..cba12da3b1 100644 --- a/modules/kameleon/src/kameleonhelper.cpp +++ b/modules/kameleon/src/kameleonhelper.cpp @@ -35,6 +35,7 @@ #endif // _MSC_VER #include +#include #ifdef _MSC_VER #pragma warning (pop) diff --git a/modules/kameleon/src/kameleonwrapper.cpp b/modules/kameleon/src/kameleonwrapper.cpp index 654df4e8d1..774d146136 100644 --- a/modules/kameleon/src/kameleonwrapper.cpp +++ b/modules/kameleon/src/kameleonwrapper.cpp @@ -39,6 +39,8 @@ #endif // WIN32 #include +#include +#include #include #include #include diff --git a/modules/kameleonvolume/kameleonvolumereader.cpp b/modules/kameleonvolume/kameleonvolumereader.cpp index 841fb06e08..e3c0bb5530 100644 --- a/modules/kameleonvolume/kameleonvolumereader.cpp +++ b/modules/kameleonvolume/kameleonvolumereader.cpp @@ -42,6 +42,7 @@ #include #include +#include #include #include #include diff --git a/modules/multiresvolume/rendering/histogrammanager.h b/modules/multiresvolume/rendering/histogrammanager.h index 5500f98480..40f3ff9838 100644 --- a/modules/multiresvolume/rendering/histogrammanager.h +++ b/modules/multiresvolume/rendering/histogrammanager.h @@ -27,7 +27,6 @@ #include #include -#include namespace openspace { diff --git a/modules/server/CMakeLists.txt b/modules/server/CMakeLists.txt index 63fb71d65a..c7749c31d4 100644 --- a/modules/server/CMakeLists.txt +++ b/modules/server/CMakeLists.txt @@ -82,3 +82,10 @@ create_new_module( server_module ${HEADER_FILES} ${SOURCE_FILES} ) + +target_precompile_headers(${server_module} PRIVATE + + + + +) diff --git a/modules/skybrowser/CMakeLists.txt b/modules/skybrowser/CMakeLists.txt index 6746d36731..af3b6c6045 100644 --- a/modules/skybrowser/CMakeLists.txt +++ b/modules/skybrowser/CMakeLists.txt @@ -63,3 +63,7 @@ create_new_module( STATIC ${HEADER_FILES} ${SOURCE_FILES} ${SHADER_FILES} ) +target_precompile_headers(${skybrowser_module} PRIVATE + [["include/cef_accessibility_handler.h"]] + [["include/cef_render_handler.h"]] +) diff --git a/modules/space/CMakeLists.txt b/modules/space/CMakeLists.txt index 3337872afe..4a073ce284 100644 --- a/modules/space/CMakeLists.txt +++ b/modules/space/CMakeLists.txt @@ -88,3 +88,12 @@ create_new_module( STATIC ${HEADER_FILES} ${SOURCE_FILES} ${SHADER_FILES} ) +target_precompile_headers(${space_module} PRIVATE + + + + + + + +) diff --git a/modules/spacecraftinstruments/CMakeLists.txt b/modules/spacecraftinstruments/CMakeLists.txt index 8e9d526d79..9e7ab871b8 100644 --- a/modules/spacecraftinstruments/CMakeLists.txt +++ b/modules/spacecraftinstruments/CMakeLists.txt @@ -91,3 +91,6 @@ create_new_module( STATIC ${HEADER_FILES} ${SOURCE_FILES} ${SHADER_FILES} ) + +target_precompile_headers(${spacecraftinstruments_module} PRIVATE +) diff --git a/modules/statemachine/CMakeLists.txt b/modules/statemachine/CMakeLists.txt index a5f946dbe1..5af6de1297 100644 --- a/modules/statemachine/CMakeLists.txt +++ b/modules/statemachine/CMakeLists.txt @@ -25,23 +25,30 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake) set(HEADER_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/include/state.h - ${CMAKE_CURRENT_SOURCE_DIR}/include/transition.h - ${CMAKE_CURRENT_SOURCE_DIR}/include/statemachine.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/state.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/transition.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/statemachine.h ) source_group("Header Files" FILES ${HEADER_FILES}) set(SOURCE_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/statemachinemodule_lua.inl - ${CMAKE_CURRENT_SOURCE_DIR}/src/state.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/transition.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/statemachine.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/statemachinemodule_lua.inl + ${CMAKE_CURRENT_SOURCE_DIR}/src/state.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/transition.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/statemachine.cpp ) source_group("Source Files" FILES ${SOURCE_FILES}) create_new_module( - "StateMachine" - statemachine_module - STATIC - ${HEADER_FILES} ${SOURCE_FILES} + "StateMachine" + statemachine_module + STATIC + ${HEADER_FILES} ${SOURCE_FILES} +) +target_precompile_headers(${statemachine_module} PRIVATE + + + + + ) diff --git a/modules/statemachine/src/statemachine.cpp b/modules/statemachine/src/statemachine.cpp index 81d5bf6ba7..e563d9a6c5 100644 --- a/modules/statemachine/src/statemachine.cpp +++ b/modules/statemachine/src/statemachine.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include diff --git a/modules/touch/ext/CMakeLists.txt b/modules/touch/ext/CMakeLists.txt index 8dde1535d6..b6d3927102 100644 --- a/modules/touch/ext/CMakeLists.txt +++ b/modules/touch/ext/CMakeLists.txt @@ -76,6 +76,23 @@ target_include_directories(libTUIO11 SYSTEM "${PROJECT_SOURCE_DIR}/libTUIO11/" "${PROJECT_SOURCE_DIR}/libTUIO11/oscpack" ) +target_precompile_headers(libTUIO11 PRIVATE + + + + +) +# # [["tuiopoint.h"]] +# # [["tuiocontainer.h"]] +# # [["tuiotime.h"]] +# # [["tuioobject.h"]] +# # [["tuiodispatcher.h"]] +# # [["tuiolistener.h"]] +# # [["tuioclient.h"]] +# # [["oscreceiver.h"]] +# +# +# ) if (WIN32) # Tuio dependencies diff --git a/modules/touch/ext/libTUIO11 b/modules/touch/ext/libTUIO11 index a164db7a95..9c543bc229 160000 --- a/modules/touch/ext/libTUIO11 +++ b/modules/touch/ext/libTUIO11 @@ -1 +1 @@ -Subproject commit a164db7a95420aa1cdcb7aec1b2cdf64827ebc57 +Subproject commit 9c543bc229cc99dcf9628f6e401287af54bc533d diff --git a/modules/touch/touchmodule.cpp b/modules/touch/touchmodule.cpp index 1aaf939bc5..e1b8742671 100644 --- a/modules/touch/touchmodule.cpp +++ b/modules/touch/touchmodule.cpp @@ -28,16 +28,9 @@ #include #include #include -#include #include #include #include -#include -#include -#include -#include -#include -#include using namespace TUIO; diff --git a/modules/webbrowser/CMakeLists.txt b/modules/webbrowser/CMakeLists.txt index 3ab05c1f10..bd01c449f9 100644 --- a/modules/webbrowser/CMakeLists.txt +++ b/modules/webbrowser/CMakeLists.txt @@ -99,6 +99,25 @@ if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") target_compile_options(libcef_dll_wrapper PRIVATE "-w") endif () +target_precompile_headers(libcef_dll_wrapper PRIVATE + [["include/cef_client.h"]] + [["include/capi/cef_browser_capi.h"]] + [["include/capi/cef_client_capi.h"]] + [["include/cef_client.h"]] + [["include/capi/cef_base_capi.h"]] + [["include/cef_render_handler.h"]] + + + + +) + +if (WIN32) + target_precompile_headers(libcef_dll_wrapper PRIVATE + + ) +endif () + ########################################################################################## # Add CEF client files @@ -241,10 +260,15 @@ create_new_module( ${HEADER_FILES} ${SOURCE_FILES} ) +target_precompile_headers(${webbrowser_module} PRIVATE + + + +) + set_folder_location(libcef_dll_wrapper "Helper") set_folder_location(openspace_web_helper "Helper") - # Display CEF configuration settings. # PRINT_CEF_CONFIG() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 383edb9306..af3748c61d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -446,6 +446,8 @@ target_include_directories(openspace-core ) target_precompile_headers(openspace-core PRIVATE + + [["ghoul/fmt.h"]] [["ghoul/glm.h"]] [["ghoul/misc/assert.h"]] @@ -453,12 +455,19 @@ target_precompile_headers(openspace-core PRIVATE [["ghoul/misc/exception.h"]] [["ghoul/misc/invariants.h"]] [["ghoul/misc/profiling.h"]] + [["ghoul/opengl/ghoul_gl.h"]] + + + + + + ) diff --git a/src/engine/downloadmanager.cpp b/src/engine/downloadmanager.cpp index de84c4bd03..7b57907d13 100644 --- a/src/engine/downloadmanager.cpp +++ b/src/engine/downloadmanager.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include namespace { diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 8e9308742a..17d75934b3 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -82,6 +82,7 @@ #include #include #include +#include #include #include #include @@ -94,6 +95,10 @@ #include #include +#ifdef WIN32 +#include +#endif // WIN32 + #ifdef __APPLE__ #include #endif // __APPLE__ diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index 070d6a60fd..0eadd4499e 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -55,7 +55,7 @@ #include #ifdef WIN32 -#include +#include #endif // WIN32 #include "sessionrecording_lua.inl" diff --git a/src/rendering/helper.cpp b/src/rendering/helper.cpp index 956b388dc4..57e067c3a7 100644 --- a/src/rendering/helper.cpp +++ b/src/rendering/helper.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include diff --git a/src/rendering/loadingscreen.cpp b/src/rendering/loadingscreen.cpp index 59cba07b89..1be8d567d6 100644 --- a/src/rendering/loadingscreen.cpp +++ b/src/rendering/loadingscreen.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include diff --git a/src/rendering/luaconsole.cpp b/src/rendering/luaconsole.cpp index 06b16d2bf3..e4bcd43207 100644 --- a/src/rendering/luaconsole.cpp +++ b/src/rendering/luaconsole.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 4803954ae2..19ab3b5ae9 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -63,6 +63,7 @@ #include #include #include +#include #include #include #include diff --git a/src/rendering/screenspacerenderable.cpp b/src/rendering/screenspacerenderable.cpp index 0dd57fb310..3969ea00cc 100644 --- a/src/rendering/screenspacerenderable.cpp +++ b/src/rendering/screenspacerenderable.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include diff --git a/src/rendering/transferfunction.cpp b/src/rendering/transferfunction.cpp index d802b6188c..891c58c0a1 100644 --- a/src/rendering/transferfunction.cpp +++ b/src/rendering/transferfunction.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include namespace { diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index 4f460e4bb4..6e4390e277 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include diff --git a/src/util/blockplaneintersectiongeometry.cpp b/src/util/blockplaneintersectiongeometry.cpp index bfeed98405..13e26b16a7 100644 --- a/src/util/blockplaneintersectiongeometry.cpp +++ b/src/util/blockplaneintersectiongeometry.cpp @@ -25,6 +25,7 @@ #include #include +#include #include namespace { diff --git a/src/util/boxgeometry.cpp b/src/util/boxgeometry.cpp index 37e5d50554..5d39116390 100644 --- a/src/util/boxgeometry.cpp +++ b/src/util/boxgeometry.cpp @@ -25,6 +25,7 @@ #include #include +#include #include namespace { diff --git a/src/util/planegeometry.cpp b/src/util/planegeometry.cpp index bef8ca990e..10edcb77ae 100644 --- a/src/util/planegeometry.cpp +++ b/src/util/planegeometry.cpp @@ -25,6 +25,7 @@ #include #include +#include #include namespace openspace { diff --git a/src/util/sphere.cpp b/src/util/sphere.cpp index 87e0b04e44..c1c1fc01ce 100644 --- a/src/util/sphere.cpp +++ b/src/util/sphere.cpp @@ -25,6 +25,7 @@ #include #include +#include #include namespace { diff --git a/support/cmake/application_definition.cmake b/support/cmake/application_definition.cmake index 2df5522f95..100f51f740 100644 --- a/support/cmake/application_definition.cmake +++ b/support/cmake/application_definition.cmake @@ -31,22 +31,24 @@ function (create_new_application application_name) # We currently can't reuse the precompiled header because that one has the Kameleon # definition stuck into it #target_precompile_headers(${library_name} REUSE_FROM openspace-core) - target_precompile_headers(${application_name} PRIVATE - [["ghoul/fmt.h"]] - [["ghoul/glm.h"]] - [["ghoul/misc/assert.h"]] - [["ghoul/misc/boolean.h"]] - [["ghoul/misc/exception.h"]] - [["ghoul/misc/invariants.h"]] - [["ghoul/misc/profiling.h"]] - - - - - - - - ) + #target_precompile_headers(${application_name} PRIVATE + # [["ghoul/fmt.h"]] + # [["ghoul/glm.h"]] + # [["ghoul/misc/assert.h"]] + # [["ghoul/misc/boolean.h"]] + # [["ghoul/misc/exception.h"]] + # [["ghoul/misc/invariants.h"]] + # [["ghoul/misc/profiling.h"]] + # + # + # + # + # + # + # + # + # + #) if (WIN32) get_external_library_dependencies(ext_lib) diff --git a/support/cmake/module_definition.cmake b/support/cmake/module_definition.cmake index 808dfce1e4..34dbd45be8 100644 --- a/support/cmake/module_definition.cmake +++ b/support/cmake/module_definition.cmake @@ -108,9 +108,6 @@ endfunction () function (handle_module_dependencies target_name module_name) # We always want to link against Ghoul and the core library target_link_libraries(${library_name} PRIVATE Ghoul openspace-core) - # We currently can't reuse the precompiled header because that one has the Kameleon - # definition stuck into it - #target_precompile_headers(${library_name} REUSE_FROM openspace-core) target_precompile_headers(${library_name} PRIVATE [["ghoul/fmt.h"]] [["ghoul/glm.h"]] @@ -119,12 +116,13 @@ function (handle_module_dependencies target_name module_name) [["ghoul/misc/exception.h"]] [["ghoul/misc/invariants.h"]] [["ghoul/misc/profiling.h"]] - + [["ghoul/opengl/ghoul_gl.h"]] - + - + + ) diff --git a/support/cmake/set_openspace_compile_settings.cmake b/support/cmake/set_openspace_compile_settings.cmake index fd7f0fde1e..668107cf1b 100644 --- a/support/cmake/set_openspace_compile_settings.cmake +++ b/support/cmake/set_openspace_compile_settings.cmake @@ -23,7 +23,7 @@ ########################################################################################## function (set_openspace_compile_settings target) - target_compile_features(${target} PRIVATE cxx_std_20) + target_compile_features(${target} PUBLIC cxx_std_20) set(MSVC_WARNINGS "/MP" # Multi-threading support @@ -195,6 +195,8 @@ function (set_openspace_compile_settings target) # Boost as of 1.64 still uses unary_function unless we define this target_compile_definitions(${target} PRIVATE "_HAS_AUTO_PTR_ETC") target_compile_definitions(${target} PRIVATE "NOMINMAX") + target_compile_definitions(${target} PRIVATE "WIN32_LEAN_AND_MEAN") + target_compile_definitions(${target} PRIVATE "VC_EXTRALEAN") elseif (NOT LINUX AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") if (OPENSPACE_WARNINGS_AS_ERRORS) target_compile_options(${target} PRIVATE "-Werror") diff --git a/support/coding/codegen b/support/coding/codegen index 8ee86de09a..93fb390f1b 160000 --- a/support/coding/codegen +++ b/support/coding/codegen @@ -1 +1 @@ -Subproject commit 8ee86de09a2c902448d37d1a2828130839e2582d +Subproject commit 93fb390f1b239f737346a42e06dcf7815fdaa77c From 41d52f7f0455bc5fc1357327089cfaf9e9480bb8 Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 26 Aug 2022 16:58:48 +0200 Subject: [PATCH 34/79] Start addressing PR comments --- .../digitaluniverse/constellationbounds.asset | 4 +- .../digitaluniverse/constellations.asset | 16 ++-- modules/space/CMakeLists.txt | 4 +- .../renderableconstellationbounds.cpp | 34 ++++---- .../rendering/renderableconstellationbounds.h | 4 +- .../renderableconstellationlines.cpp | 83 ++++++++++--------- .../rendering/renderableconstellationlines.h | 6 +- ...n.cpp => renderableconstellationsbase.cpp} | 82 +++++++++--------- ...ation.h => renderableconstellationsbase.h} | 23 ++--- .../space/shaders/constellationbounds_fs.glsl | 6 +- .../space/shaders/constellationlines_fs.glsl | 7 +- .../space/shaders/constellationlines_vs.glsl | 6 +- 12 files changed, 141 insertions(+), 134 deletions(-) rename modules/space/rendering/{renderableconstellation.cpp => renderableconstellationsbase.cpp} (84%) rename modules/space/rendering/{renderableconstellation.h => renderableconstellationsbase.h} (87%) diff --git a/data/assets/scene/digitaluniverse/constellationbounds.asset b/data/assets/scene/digitaluniverse/constellationbounds.asset index 4003e15b39..4c0494e4f3 100644 --- a/data/assets/scene/digitaluniverse/constellationbounds.asset +++ b/data/assets/scene/digitaluniverse/constellationbounds.asset @@ -16,8 +16,8 @@ local object = { Type = "RenderableConstellationBounds", Enabled = false, File = data .. "bound_20.dat", - ConstellationNamesFile = data .. "constellations.dat", - -- ConstellationSelection = zodiacs + NamesFile = data .. "constellations.dat", + -- Selection = zodiacs }, Transform = { Rotation = { diff --git a/data/assets/scene/digitaluniverse/constellations.asset b/data/assets/scene/digitaluniverse/constellations.asset index 1dafb17052..a5530f6eb1 100644 --- a/data/assets/scene/digitaluniverse/constellations.asset +++ b/data/assets/scene/digitaluniverse/constellations.asset @@ -18,15 +18,15 @@ local constellationsExtragalactic = { Opacity = 0.4, File = speck .. "constellationsEXGAL.speck", LabelFile = speck .. "constellationsEXGAL.label", - ConstellationNamesFile = speck .. "constellations.dat", + NamesFile = speck .. "constellations.dat", TextColor = { 0.8, 0.8, 0.8 }, TextOpacity = 0.4, TextSize = 20.0, TextMinMaxSize = { 20, 30 }, - ConstellationColor = { { 0.6, 0.4, 0.4 }, { 0.8, 0.0, 0.0 }, { 0.0, 0.3, 0.8 } }, + Colors = { { 0.6, 0.4, 0.4 }, { 0.8, 0.0, 0.0 }, { 0.0, 0.3, 0.8 } }, LabelUnit = "Mpc", - ConstellationUnit = "Mpc", - -- ConstellationSelection = zodiacs + LineUnit = "Mpc", + -- Selection = zodiacs }, GUI = { Name = "Constellations (Extragalactic)", @@ -42,15 +42,15 @@ local constellations = { Opacity = 0.3, File = speck .. "constellations.speck", LabelFile = speck .. "constellations.label", - ConstellationNamesFile = speck .. "constellations.dat", + NamesFile = speck .. "constellations.dat", TextColor = { 0.8, 0.8, 0.8 }, TextOpacity = 0.3, TextSize = 14.5, TextMinMaxSize = { 8, 170 }, - ConstellationColor = { { 0.6, 0.4, 0.4 }, { 0.8, 0.0, 0.0 }, { 0.0, 0.3, 0.8 } }, + Colors = { { 0.6, 0.4, 0.4 }, { 0.8, 0.0, 0.0 }, { 0.0, 0.3, 0.8 } }, LabelUnit = "pc", - ConstellationUnit = "pc", - -- ConstellationSelection = zodiacs + LineUnit = "pc", + -- Selection = zodiacs }, GUI = { Name = "Constellations", diff --git a/modules/space/CMakeLists.txt b/modules/space/CMakeLists.txt index c6e3ced6d8..3a28b950e4 100644 --- a/modules/space/CMakeLists.txt +++ b/modules/space/CMakeLists.txt @@ -28,7 +28,7 @@ set(HEADER_FILES horizonsfile.h kepler.h speckloader.h - rendering/renderableconstellation.h + rendering/renderableconstellationsbase.h rendering/renderableconstellationbounds.h rendering/renderableconstellationlines.h rendering/renderablefluxnodes.h @@ -50,7 +50,7 @@ set(SOURCE_FILES kepler.cpp spacemodule_lua.inl speckloader.cpp - rendering/renderableconstellation.cpp + rendering/renderableconstellationsbase.cpp rendering/renderableconstellationbounds.cpp rendering/renderableconstellationlines.cpp rendering/renderablefluxnodes.cpp diff --git a/modules/space/rendering/renderableconstellationbounds.cpp b/modules/space/rendering/renderableconstellationbounds.cpp index a1cafc053c..7972203696 100644 --- a/modules/space/rendering/renderableconstellationbounds.cpp +++ b/modules/space/rendering/renderableconstellationbounds.cpp @@ -73,7 +73,7 @@ documentation::Documentation RenderableConstellationBounds::Documentation() { RenderableConstellationBounds::RenderableConstellationBounds( const ghoul::Dictionary& dictionary) - : RenderableConstellation(dictionary) + : RenderableConstellationsBase(dictionary) , _vertexFilename(VertexInfo) , _color(ColorInfo, glm::vec3(1.f, 0.f, 0.f), glm::vec3(0.f), glm::vec3(1.f)) { @@ -90,20 +90,20 @@ RenderableConstellationBounds::RenderableConstellationBounds( } void RenderableConstellationBounds::initialize() { - RenderableConstellation::initialize(); + RenderableConstellationsBase::initialize(); loadVertexFile(); - if (!_assetSelectedConstellations.empty()) { - const std::vector options = _constellationSelection.options(); + if (!_assetSelection.empty()) { + const std::vector options = _selection.options(); std::set selectedConstellations; - for (const std::string& s : _assetSelectedConstellations) { + for (const std::string& s : _assetSelection) { const auto it = std::find(options.begin(), options.end(), s); if (it == options.end()) { // The user has specified a constellation name that doesn't exist LWARNINGC( - "RenderableConstellation", + "RenderableConstellationsBase", fmt::format("Option '{}' not found in list of constellations", s) ); } @@ -111,7 +111,7 @@ void RenderableConstellationBounds::initialize() { selectedConstellations.insert(s); } } - _constellationSelection = selectedConstellations; + _selection = selectedConstellations; } } @@ -154,10 +154,13 @@ void RenderableConstellationBounds::deinitializeGL() { } bool RenderableConstellationBounds::isReady() const { - if (!_hasLabel) { - return _program && _vao != 0 && _vbo != 0; + bool isReady = _program && _vao != 0 && _vbo != 0; + + // If we have labels, they also need to be loaded + if (_hasLabel) { + return isReady && !_labelset.entries.empty(); } - return _program && _vao != 0 && _vbo != 0 && !_labelset.entries.empty(); + return isReady; } void RenderableConstellationBounds::render(const RenderData& data, RendererTasks& tasks) { @@ -177,7 +180,7 @@ void RenderableConstellationBounds::render(const RenderData& data, RendererTasks _program->setUniform("ViewProjection", data.camera.viewProjectionMatrix()); _program->setUniform("ModelTransform", glm::mat4(modelTransform)); _program->setUniform("color", _color); - _program->setUniform("alphaValue", opacity()); + _program->setUniform("opacity", opacity()); glLineWidth(_lineWidth); @@ -190,11 +193,10 @@ void RenderableConstellationBounds::render(const RenderData& data, RendererTasks glBindVertexArray(0); _program->deactivate(); - RenderableConstellation::render(data, tasks); + RenderableConstellationsBase::render(data, tasks); } -void RenderableConstellationBounds::update(const UpdateData& data) { -} +void RenderableConstellationBounds::update(const UpdateData& data) { } bool RenderableConstellationBounds::loadVertexFile() { if (_vertexFilename.value().empty()) { @@ -300,7 +302,7 @@ bool RenderableConstellationBounds::loadVertexFile() { void RenderableConstellationBounds::selectionPropertyHasChanged() { // If no values are selected (the default), we want to show all constellations - if (!_constellationSelection.hasSelected()) { + if (!_selection.hasSelected()) { for (ConstellationBound& b : _constellationBounds) { b.isEnabled = true; } @@ -308,7 +310,7 @@ void RenderableConstellationBounds::selectionPropertyHasChanged() { else { // Enable all constellations that are selected for (ConstellationBound& b : _constellationBounds) { - b.isEnabled = _constellationSelection.isSelected(b.constellationFullName); + b.isEnabled = _selection.isSelected(b.constellationFullName); } } } diff --git a/modules/space/rendering/renderableconstellationbounds.h b/modules/space/rendering/renderableconstellationbounds.h index 3925e37c6e..b5fcefe299 100644 --- a/modules/space/rendering/renderableconstellationbounds.h +++ b/modules/space/rendering/renderableconstellationbounds.h @@ -25,7 +25,7 @@ #ifndef __OPENSPACE_MODULE_SPACE___RENDERABLECONSTELLATIONBOUNDS___H__ #define __OPENSPACE_MODULE_SPACE___RENDERABLECONSTELLATIONBOUNDS___H__ -#include +#include namespace ghoul::opengl { class ProgramObject; } @@ -42,7 +42,7 @@ namespace documentation { struct Documentation; } * _distance property. Currently, all constellation bounds are lines, which * leads to artifacts if the radius is very small. */ -class RenderableConstellationBounds : public RenderableConstellation { +class RenderableConstellationBounds : public RenderableConstellationsBase { public: RenderableConstellationBounds(const ghoul::Dictionary& dictionary); diff --git a/modules/space/rendering/renderableconstellationlines.cpp b/modules/space/rendering/renderableconstellationlines.cpp index 659f346809..852e17d3ef 100644 --- a/modules/space/rendering/renderableconstellationlines.cpp +++ b/modules/space/rendering/renderableconstellationlines.cpp @@ -25,13 +25,13 @@ #include #include -#include #include #include -#include +#include #include -#include +#include #include +#include #include #include #include @@ -43,7 +43,7 @@ namespace { constexpr std::string_view _loggerCat = "RenderableConstellationLines"; constexpr std::array UniformNames = { - "modelViewTransform", "projectionTransform", "alphaValue", "color" + "modelViewTransform", "projectionTransform", "opacity", "color" }; constexpr openspace::properties::Property::PropertyInfo DrawElementsInfo = { @@ -52,16 +52,17 @@ namespace { "Enables/Disables the drawing of the constellations" }; - constexpr openspace::properties::Property::PropertyInfo ConstellationUnitInfo = { - "ConstellationUnit", - "Constellation Unit", - "The unit used for the constellation data" + constexpr openspace::properties::Property::PropertyInfo LineUnitInfo = { + "LineUnit", + "Line Unit", + "The distance unit used for the constellation lines data" }; - constexpr openspace::properties::Property::PropertyInfo ConstellationColorInfo = { - "ConstellationColor", - "Constellation colors", - "The defined colors for the constellations to be rendered" + constexpr openspace::properties::Property::PropertyInfo ColorsInfo = { + "Colors", + "Constellation Colors", + "The defined colors for the constellations to be rendered. " + "There can be several groups of constellaitons that can have distinct colors." }; struct [[codegen::Dictionary(RenderableConstellationLines)]] Parameters { @@ -77,11 +78,11 @@ namespace { Gigaparsec [[codegen::key("Gpc")]], Gigalightyear [[codegen::key("Gly")]] }; - // [[codegen::verbatim(ConstellationUnitInfo.description)]] - std::optional constellationUnit; + // [[codegen::verbatim(LineUnitInfo.description)]] + std::optional lineUnit; - // [[codegen::verbatim(ConstellationColorInfo.description)]] - std::optional> constellationColor; + // [[codegen::verbatim(ColorsInfo.description)]] + std::optional> colors; }; #include "renderableconstellationlines_codegen.cpp" } // namespace @@ -94,7 +95,7 @@ documentation::Documentation RenderableConstellationLines::Documentation() { RenderableConstellationLines::RenderableConstellationLines( const ghoul::Dictionary& dictionary) - : RenderableConstellation(dictionary) + : RenderableConstellationsBase(dictionary) , _drawElements(DrawElementsInfo, true) { const Parameters p = codegen::bake(dictionary); @@ -104,15 +105,15 @@ RenderableConstellationLines::RenderableConstellationLines( _drawElements.onChange([&]() { _hasSpeckFile = !_hasSpeckFile; }); addProperty(_drawElements); - if (p.constellationUnit.has_value()) { - _constellationUnit = codegen::map(*p.constellationUnit); + if (p.lineUnit.has_value()) { + _constellationUnit = codegen::map(*p.lineUnit); } else { _constellationUnit = DistanceUnit::Meter; } - if (p.constellationColor.has_value()) { - std::vector ops = *p.constellationColor; + if (p.colors.has_value()) { + std::vector ops = *p.colors; for (size_t i = 0; i < ops.size(); ++i) { _constellationColorMap.insert({ static_cast(i) + 1, ops[i] }); } @@ -121,7 +122,7 @@ RenderableConstellationLines::RenderableConstellationLines( void RenderableConstellationLines::selectionPropertyHasChanged() { // If no values are selected (the default), we want to show all constellations - if (!_constellationSelection.hasSelected()) { + if (!_selection.hasSelected()) { for (std::pair& pair : _renderingConstellationsMap) { @@ -133,38 +134,39 @@ void RenderableConstellationLines::selectionPropertyHasChanged() { for (std::pair& pair : _renderingConstellationsMap) { - pair.second.isEnabled = - _constellationSelection.isSelected(pair.second.name); + pair.second.isEnabled = _selection.isSelected(pair.second.name); } } } bool RenderableConstellationLines::isReady() const { - if (!_hasLabel) { - return _program && !_renderingConstellationsMap.empty(); + bool isReady = _program && !_renderingConstellationsMap.empty(); + + // If we have labels, they also need to be loaded + if (_hasLabel) { + return isReady && !_labelset.entries.empty(); } - return _program && !_renderingConstellationsMap.empty() && - !_labelset.entries.empty(); + return isReady; } void RenderableConstellationLines::initialize() { - RenderableConstellation::initialize(); + RenderableConstellationsBase::initialize(); bool success = loadData(); if (!success) { throw ghoul::RuntimeError("Error loading data"); } - if (!_assetSelectedConstellations.empty()) { - const std::vector options = _constellationSelection.options(); + if (!_assetSelection.empty()) { + const std::vector options = _selection.options(); std::set selectedConstellations; - for (const std::string& s : _assetSelectedConstellations) { + for (const std::string& s : _assetSelection) { const auto it = std::find(options.begin(), options.end(), s); if (it == options.end()) { // The user has specified a constellation name that doesn't exist LWARNINGC( - "RenderableConstellation", + "RenderableConstellationsBase", fmt::format("Option '{}' not found in list of constellations", s) ); } @@ -172,7 +174,7 @@ void RenderableConstellationLines::initialize() { selectedConstellations.insert(s); } } - _constellationSelection = selectedConstellations; + _selection = selectedConstellations; } } @@ -215,7 +217,7 @@ void RenderableConstellationLines::renderConstellations(const RenderData&, _program->setUniform(_uniformCache.modelViewTransform, modelViewMatrix); _program->setUniform(_uniformCache.projectionTransform, projectionMatrix); - _program->setUniform(_uniformCache.alphaValue, opacity()); + _program->setUniform(_uniformCache.opacity, opacity()); for (const std::pair& pair : _renderingConstellationsMap) @@ -257,7 +259,7 @@ void RenderableConstellationLines::render(const RenderData& data, RendererTasks& renderConstellations(data, modelViewMatrix, projectionMatrix); } - RenderableConstellation::render(data, tasks); + RenderableConstellationsBase::render(data, tasks); } void RenderableConstellationLines::update(const UpdateData&) { @@ -331,10 +333,15 @@ bool RenderableConstellationLines::readSpeckFile() { std::string dummy; str >> dummy; // mesh command dummy.clear(); - str >> dummy; // color index command? + str >> dummy; // color index command do { if (dummy == "-c") { - str >> constellationLine.colorIndex; // color index command + str >> constellationLine.colorIndex; // color index + } + else { + std::string message = fmt::format("Unknown command '{}' found in " + "constellation file '{}'", dummy, _speckFile); + LWARNING(message); } dummy.clear(); str >> dummy; diff --git a/modules/space/rendering/renderableconstellationlines.h b/modules/space/rendering/renderableconstellationlines.h index e9fb792a6e..51dfe2044c 100644 --- a/modules/space/rendering/renderableconstellationlines.h +++ b/modules/space/rendering/renderableconstellationlines.h @@ -25,7 +25,7 @@ #ifndef __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLECONSTELLATIONLINES___H__ #define __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLECONSTELLATIONLINES___H__ -#include +#include #include #include @@ -41,7 +41,7 @@ namespace openspace { namespace documentation { struct Documentation; } -class RenderableConstellationLines : public RenderableConstellation { +class RenderableConstellationLines : public RenderableConstellationsBase { public: explicit RenderableConstellationLines(const ghoul::Dictionary& dictionary); ~RenderableConstellationLines() override = default; @@ -88,7 +88,7 @@ private: properties::BoolProperty _drawElements; std::unique_ptr _program = nullptr; - UniformCache(modelViewTransform, projectionTransform, alphaValue, + UniformCache(modelViewTransform, projectionTransform, opacity, color) _uniformCache; std::string _speckFile; diff --git a/modules/space/rendering/renderableconstellation.cpp b/modules/space/rendering/renderableconstellationsbase.cpp similarity index 84% rename from modules/space/rendering/renderableconstellation.cpp rename to modules/space/rendering/renderableconstellationsbase.cpp index 01215c0a68..5925fd5da3 100644 --- a/modules/space/rendering/renderableconstellation.cpp +++ b/modules/space/rendering/renderableconstellationsbase.cpp @@ -22,7 +22,7 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include #include #include @@ -74,9 +74,9 @@ namespace { "constellations" }; - constexpr openspace::properties::Property::PropertyInfo ConstellationInfo = { - "ConstellationFile", - "Constellation File Path", + constexpr openspace::properties::Property::PropertyInfo NamesFileInfo = { + "NamesFile", + "Constellation Names File Path", "Specifies the file that contains the mapping between constellation " "abbreviations and full names of the constellations. If this value is empty, the " "abbreviations are used as the full names" @@ -112,12 +112,12 @@ namespace { "The constellations that are selected are displayed on the celestial sphere" }; - struct [[codegen::Dictionary(RenderableConstellation)]] Parameters { + struct [[codegen::Dictionary(RenderableConstellationsBase)]] Parameters { // [[codegen::verbatim(DrawLabelInfo.description)]] std::optional drawLabels; - // [[codegen::verbatim(ConstellationInfo.description)]] - std::optional constellationNamesFile; + // [[codegen::verbatim(NamesFileInfo.description)]] + std::optional namesFile; // [[codegen::verbatim(TextColorInfo.description)]] std::optional textColor [[codegen::color()]]; @@ -150,18 +150,18 @@ namespace { std::optional labelUnit; // [[codegen::verbatim(SelectionInfo.description)]] - std::optional> constellationSelection; + std::optional> selection; }; -#include "renderableconstellation_codegen.cpp" +#include "renderableconstellationsbase_codegen.cpp" } // namespace namespace openspace { -documentation::Documentation RenderableConstellation::Documentation() { - return codegen::doc("space_renderable_constellation"); +documentation::Documentation RenderableConstellationsBase::Documentation() { + return codegen::doc("space_renderable_constellationsbase"); } -RenderableConstellation::RenderableConstellation(const ghoul::Dictionary& dictionary) +RenderableConstellationsBase::RenderableConstellationsBase(const ghoul::Dictionary& dictionary) : Renderable(dictionary) , _textColor(TextColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f)) , _textOpacity(TextOpacityInfo, 1.f, 0.f, 1.f) @@ -175,8 +175,8 @@ RenderableConstellation::RenderableConstellation(const ghoul::Dictionary& dictio ) , _lineWidth(LineWidthInfo, 2.f, 1.f, 16.f) , _renderOption(RenderOptionInfo, properties::OptionProperty::DisplayType::Dropdown) - , _constellationNamesFilename(ConstellationInfo) - , _constellationSelection(SelectionInfo) + , _namesFilename(NamesFileInfo) + , _selection(SelectionInfo) { const Parameters p = codegen::bake(dictionary); @@ -196,12 +196,11 @@ RenderableConstellation::RenderableConstellation(const ghoul::Dictionary& dictio addProperty(_renderOption); // Avoid reading files here, instead do it in multithreaded initialize() - if (p.constellationNamesFile.has_value()) { - _constellationNamesFilename = - absPath(p.constellationNamesFile.value().string()).string(); + if (p.namesFile.has_value()) { + _namesFilename = absPath(p.namesFile.value().string()).string(); } - _constellationNamesFilename.onChange([&]() { loadConstellationFile(); }); - addProperty(_constellationNamesFilename); + _namesFilename.onChange([&]() { loadConstellationFile(); }); + addProperty(_namesFilename); _lineWidth = p.lineWidth.value_or(_lineWidth); addProperty(_lineWidth); @@ -236,45 +235,44 @@ RenderableConstellation::RenderableConstellation(const ghoul::Dictionary& dictio } } - _constellationSelection.onChange([this]() { selectionPropertyHasChanged(); }); - addProperty(_constellationSelection); + _selection.onChange([this]() { selectionPropertyHasChanged(); }); + addProperty(_selection); - _assetSelectedConstellations = - p.constellationSelection.value_or(_assetSelectedConstellations); + _assetSelection = p.selection.value_or(_assetSelection); } -std::string RenderableConstellation::constellationFullName( +std::string RenderableConstellationsBase::constellationFullName( const std::string& identifier) const { - if (_constellationNamesTranslation.empty() || identifier.empty()) { + if (_namesTranslation.empty() || identifier.empty()) { std::string message = "List of constellations or the given identifier was empty"; - LWARNINGC("RenderableConstellation", message); + LWARNINGC("RenderableConstellationsBase", message); return ""; } try { - return _constellationNamesTranslation.at(identifier); + return _namesTranslation.at(identifier); } catch (const std::out_of_range&) { std::string message = fmt::format( "Identifier '{}' could not be found in list of constellations", identifier ); - throw ghoul::RuntimeError(message, "RenderableConstellation"); + throw ghoul::RuntimeError(message, "RenderableConstellationsBase"); } } -void RenderableConstellation::loadConstellationFile() { - if (_constellationNamesFilename.value().empty()) { +void RenderableConstellationsBase::loadConstellationFile() { + if (_namesFilename.value().empty()) { return; } // Reset - _constellationSelection.clearOptions(); - _constellationNamesTranslation.clear(); + _selection.clearOptions(); + _namesTranslation.clear(); std::ifstream file; file.exceptions(std::ifstream::goodbit); - file.open(absPath(_constellationNamesFilename)); + file.open(absPath(_namesFilename)); std::string line; while (file.good()) { @@ -290,19 +288,19 @@ void RenderableConstellation::loadConstellationFile() { std::string fullName; std::getline(s, fullName); ghoul::trimWhitespace(fullName); - _constellationNamesTranslation[abbreviation] = fullName; + _namesTranslation[abbreviation] = fullName; } fillSelectionProperty(); } -void RenderableConstellation::fillSelectionProperty() { - for (const std::pair& pair : _constellationNamesTranslation) { - _constellationSelection.addOption(pair.second); +void RenderableConstellationsBase::fillSelectionProperty() { + for (const std::pair& pair : _namesTranslation) { + _selection.addOption(pair.second); } } -void RenderableConstellation::initialize() { +void RenderableConstellationsBase::initialize() { loadConstellationFile(); if (!_hasLabel) { @@ -334,7 +332,7 @@ void RenderableConstellation::initialize() { } } -void RenderableConstellation::render(const RenderData& data, RendererTasks&) { +void RenderableConstellationsBase::render(const RenderData& data, RendererTasks&) { if (!_hasLabel || !_drawLabels) { return; } @@ -372,7 +370,7 @@ void RenderableConstellation::render(const RenderData& data, RendererTasks&) { renderLabels(data, modelViewProjectionMatrix, orthoRight, orthoUp); } -void RenderableConstellation::renderLabels(const RenderData& data, +void RenderableConstellationsBase::renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix, const glm::vec3& orthoRight, const glm::vec3& orthoUp) @@ -395,9 +393,7 @@ void RenderableConstellation::renderLabels(const RenderData& data, glm::vec4 textColor = glm::vec4(glm::vec3(_textColor), _textOpacity); for (const speck::Labelset::Entry& e : _labelset.entries) { - if (_constellationSelection.hasSelected() && - !_constellationSelection.isSelected(e.text)) - { + if (_selection.hasSelected() && !_selection.isSelected(e.text)) { continue; } diff --git a/modules/space/rendering/renderableconstellation.h b/modules/space/rendering/renderableconstellationsbase.h similarity index 87% rename from modules/space/rendering/renderableconstellation.h rename to modules/space/rendering/renderableconstellationsbase.h index 7d2a88f14c..8da74feedc 100644 --- a/modules/space/rendering/renderableconstellation.h +++ b/modules/space/rendering/renderableconstellationsbase.h @@ -22,8 +22,8 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef __OPENSPACE_MODULE_SPACE___RENDERABLECONSTELLATION___H__ -#define __OPENSPACE_MODULE_SPACE___RENDERABLECONSTELLATION___H__ +#ifndef __OPENSPACE_MODULE_SPACE___RENDERABLECONSTELLATIONSBASE___H__ +#define __OPENSPACE_MODULE_SPACE___RENDERABLECONSTELLATIONSBASE___H__ #include @@ -44,9 +44,12 @@ namespace openspace { namespace documentation { struct Documentation; } -class RenderableConstellation : public Renderable { +/** + * This is a base class for constellation lines and bounds + */ +class RenderableConstellationsBase : public Renderable { public: - virtual ~RenderableConstellation() override = default; + virtual ~RenderableConstellationsBase() override = default; virtual void initialize() override; virtual void initializeGL() override = 0; @@ -62,7 +65,7 @@ public: static documentation::Documentation Documentation(); protected: - explicit RenderableConstellation(const ghoul::Dictionary& dictionary); + explicit RenderableConstellationsBase(const ghoul::Dictionary& dictionary); /** * Callback method that gets triggered when _constellationSelection @@ -78,11 +81,11 @@ protected: properties::FloatProperty _lineWidth; // Property that stores all constellations chosen by the user to be drawn - properties::SelectionProperty _constellationSelection; + properties::SelectionProperty _selection; // Temporary storage of which constellations should be rendered as stated in the // asset file - std::vector _assetSelectedConstellations; + std::vector _assetSelection; // Label text settings bool _hasLabel = false; @@ -92,7 +95,7 @@ protected: private: // Map over the constellations names and their abbreviations // key = abbreviation, value = full name - std::map _constellationNamesTranslation; + std::map _namesTranslation; /** * Loads the file specified in _constellationNamesFilename that contains @@ -104,7 +107,7 @@ private: void fillSelectionProperty(); // The file containing constellation names and abbreviations - properties::StringProperty _constellationNamesFilename; + properties::StringProperty _namesFilename; // Label text settings std::string _labelFile; @@ -120,4 +123,4 @@ private: } // namespace openspace -#endif // __OPENSPACE_MODULE_SPACE___RENDERABLECONSTELLATION___H__ +#endif // __OPENSPACE_MODULE_SPACE___RENDERABLECONSTELLATIONSBASE___H__ diff --git a/modules/space/shaders/constellationbounds_fs.glsl b/modules/space/shaders/constellationbounds_fs.glsl index 0d138b106d..ce1a490d4e 100644 --- a/modules/space/shaders/constellationbounds_fs.glsl +++ b/modules/space/shaders/constellationbounds_fs.glsl @@ -28,18 +28,18 @@ in vec4 vs_position; uniform vec3 color; -uniform float alphaValue; +uniform float opacity; Fragment getFragment() { Fragment frag; - if (alphaValue == 0.0) { + if (opacity == 0.0) { discard; } vec4 position = vs_position; - frag.color = vec4(color, alphaValue); + frag.color = vec4(color, opacity); frag.depth = pscDepth(position); return frag; diff --git a/modules/space/shaders/constellationlines_fs.glsl b/modules/space/shaders/constellationlines_fs.glsl index f8cfcda68d..06311674c6 100644 --- a/modules/space/shaders/constellationlines_fs.glsl +++ b/modules/space/shaders/constellationlines_fs.glsl @@ -28,19 +28,18 @@ in float vs_screenSpaceDepth; in vec4 vs_positionViewSpace; uniform vec3 color; -uniform float alphaValue; +uniform float opacity; Fragment getFragment() { Fragment frag; - if (alphaValue == 0.0) { + if (opacity == 0.0) { discard; } - frag.color = vec4(color, alphaValue); + frag.color = vec4(color, opacity); frag.depth = vs_screenSpaceDepth; - // JCC: Need to change the position to camera space frag.gPosition = vs_positionViewSpace; frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0); diff --git a/modules/space/shaders/constellationlines_vs.glsl b/modules/space/shaders/constellationlines_vs.glsl index e8611e67d3..1fa6aa80fe 100644 --- a/modules/space/shaders/constellationlines_vs.glsl +++ b/modules/space/shaders/constellationlines_vs.glsl @@ -36,11 +36,11 @@ uniform dmat4 projectionTransform; void main() { - dvec4 positionViewSpace = modelViewTransform * dvec4(in_position, 1.0); - vec4 positionClipSpace = vec4(projectionTransform * positionViewSpace); + dvec4 positionViewSpace = modelViewTransform * dvec4(in_position, 1.0); + vec4 positionClipSpace = vec4(projectionTransform * positionViewSpace); vec4 positionScreenSpace = vec4(z_normalization(positionClipSpace)); - vs_screenSpaceDepth = positionScreenSpace.w; + vs_screenSpaceDepth = positionScreenSpace.w; vs_positionViewSpace = vec4(positionViewSpace); gl_Position = positionScreenSpace; From 3cf80e0fdc24c54ad75fa0e729b08d6f32a98616 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 29 Aug 2022 08:09:33 +0200 Subject: [PATCH 35/79] Linux compile fix --- src/engine/globalscallbacks.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/globalscallbacks.cpp b/src/engine/globalscallbacks.cpp index d7f32f697c..819ec6e4a8 100644 --- a/src/engine/globalscallbacks.cpp +++ b/src/engine/globalscallbacks.cpp @@ -86,7 +86,7 @@ void create() { ghoul_assert(initializeGL, "No initializeGL"); currentPos += sizeof(std::vector>); #else // ^^^ WIN32 / !WIN32 vvv - initializeGL = new std::vector(); + initializeGL = new std::vector>(); #endif // WIN32 #ifdef WIN32 From 53b2d0e76c44172d69a8a270f57f9d4caadeb0f5 Mon Sep 17 00:00:00 2001 From: Malin E Date: Mon, 29 Aug 2022 11:44:21 +0200 Subject: [PATCH 36/79] Address some more PR comments --- .../digitaluniverse/constellationbounds.asset | 4 +-- .../renderableconstellationlines.cpp | 27 ++++--------------- .../rendering/renderableconstellationlines.h | 11 +++----- .../renderableconstellationsbase.cpp | 22 +++++++-------- 4 files changed, 22 insertions(+), 42 deletions(-) diff --git a/data/assets/scene/digitaluniverse/constellationbounds.asset b/data/assets/scene/digitaluniverse/constellationbounds.asset index 4c0494e4f3..346e516c7e 100644 --- a/data/assets/scene/digitaluniverse/constellationbounds.asset +++ b/data/assets/scene/digitaluniverse/constellationbounds.asset @@ -41,11 +41,11 @@ local object = { asset.onInitialize(function() openspace.addSceneGraphNode(object) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(object) end) - + asset.export(object) diff --git a/modules/space/rendering/renderableconstellationlines.cpp b/modules/space/rendering/renderableconstellationlines.cpp index 852e17d3ef..4b5c2d100c 100644 --- a/modules/space/rendering/renderableconstellationlines.cpp +++ b/modules/space/rendering/renderableconstellationlines.cpp @@ -100,9 +100,7 @@ RenderableConstellationLines::RenderableConstellationLines( { const Parameters p = codegen::bake(dictionary); - _speckFile = absPath(p.file.string()).string(); - _hasSpeckFile = true; - _drawElements.onChange([&]() { _hasSpeckFile = !_hasSpeckFile; }); + _speckFile = absPath(p.file); addProperty(_drawElements); if (p.lineUnit.has_value()) { @@ -255,7 +253,7 @@ void RenderableConstellationLines::render(const RenderData& data, RendererTasks& const glm::dmat4 modelViewMatrix = data.camera.combinedViewMatrix() * modelMatrix; const glm::dmat4 projectionMatrix = data.camera.projectionMatrix(); - if (_hasSpeckFile) { + if (_drawElements) { renderConstellations(data, modelViewMatrix, projectionMatrix); } @@ -270,24 +268,14 @@ void RenderableConstellationLines::update(const UpdateData&) { } bool RenderableConstellationLines::loadData() { - bool success = false; - if (_hasSpeckFile) { - LINFO(fmt::format("Loading Speck file {}", std::filesystem::path(_speckFile))); - success = readSpeckFile(); - if (!success) { - return false; - } - } - - return success; + return readSpeckFile(); } bool RenderableConstellationLines::readSpeckFile() { + LINFO(fmt::format("Loading Speck file {}", _speckFile)); std::ifstream file(_speckFile); if (!file.good()) { - LERROR(fmt::format( - "Failed to open Speck file {}", std::filesystem::path(_speckFile) - )); + LERROR(fmt::format("Failed to open Speck file {}", _speckFile)); return false; } @@ -421,9 +409,6 @@ bool RenderableConstellationLines::readSpeckFile() { } void RenderableConstellationLines::createConstellations() { - if (!(_dataIsDirty && _hasSpeckFile)) { - return; - } LDEBUG("Creating constellations"); for (std::pair& p : _renderingConstellationsMap) { @@ -449,8 +434,6 @@ void RenderableConstellationLines::createConstellations() { } glBindVertexArray(0); - - _dataIsDirty = false; } } // namespace openspace diff --git a/modules/space/rendering/renderableconstellationlines.h b/modules/space/rendering/renderableconstellationlines.h index 51dfe2044c..4bfcda7b61 100644 --- a/modules/space/rendering/renderableconstellationlines.h +++ b/modules/space/rendering/renderableconstellationlines.h @@ -22,8 +22,8 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLECONSTELLATIONLINES___H__ -#define __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLECONSTELLATIONLINES___H__ +#ifndef __OPENSPACE_MODULE_SPACE___RENDERABLECONSTELLATIONLINES___H__ +#define __OPENSPACE_MODULE_SPACE___RENDERABLECONSTELLATIONLINES___H__ #include @@ -82,16 +82,13 @@ private: */ void selectionPropertyHasChanged() override; - bool _hasSpeckFile = false; - bool _dataIsDirty = true; - properties::BoolProperty _drawElements; std::unique_ptr _program = nullptr; UniformCache(modelViewTransform, projectionTransform, opacity, color) _uniformCache; - std::string _speckFile; + std::filesystem::path _speckFile; DistanceUnit _constellationUnit = DistanceUnit::Parsec; @@ -102,4 +99,4 @@ private: }; } // namespace openspace -#endif // __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLECONSTELLATIONLINES___H__ +#endif // __OPENSPACE_MODULE_SPACE___RENDERABLECONSTELLATIONLINES___H__ diff --git a/modules/space/rendering/renderableconstellationsbase.cpp b/modules/space/rendering/renderableconstellationsbase.cpp index 5925fd5da3..6d6ca5d06b 100644 --- a/modules/space/rendering/renderableconstellationsbase.cpp +++ b/modules/space/rendering/renderableconstellationsbase.cpp @@ -250,15 +250,15 @@ std::string RenderableConstellationsBase::constellationFullName( return ""; } - try { + if (_namesTranslation.contains(identifier)) { return _namesTranslation.at(identifier); } - catch (const std::out_of_range&) { - std::string message = fmt::format( - "Identifier '{}' could not be found in list of constellations", identifier - ); - throw ghoul::RuntimeError(message, "RenderableConstellationsBase"); - } + + std::string message = fmt::format( + "Identifier '{}' could not be found in list of constellations", identifier + ); + LERRORC("RenderableConstellationsBase", message); + return ""; } void RenderableConstellationsBase::loadConstellationFile() { @@ -353,19 +353,19 @@ void RenderableConstellationsBase::render(const RenderData& data, RendererTasks& const glm::dmat4 worldToModelTransform = glm::inverse(modelMatrix); glm::vec3 orthoRight = glm::normalize( - glm::vec3(worldToModelTransform * glm::vec4(right, 0.0)) + glm::vec3(worldToModelTransform * glm::vec4(right, 0.f)) ); - if (orthoRight == glm::vec3(0.0)) { + if (orthoRight == glm::vec3(0.f)) { glm::vec3 otherVector(lookup.y, lookup.x, lookup.z); right = glm::cross(viewDirection, otherVector); orthoRight = glm::normalize( - glm::vec3(worldToModelTransform * glm::vec4(right, 0.0)) + glm::vec3(worldToModelTransform * glm::vec4(right, 0.f)) ); } const glm::vec3 orthoUp = glm::normalize( - glm::vec3(worldToModelTransform * glm::dvec4(up, 0.0)) + glm::vec3(worldToModelTransform * glm::dvec4(up, 0.f)) ); renderLabels(data, modelViewProjectionMatrix, orthoRight, orthoUp); } From dc55105000dfbb4ab91b920b031636c8fbae72ac Mon Sep 17 00:00:00 2001 From: Malin E Date: Mon, 29 Aug 2022 13:13:47 +0200 Subject: [PATCH 37/79] Move loading of data error handling --- .../rendering/renderableconstellationbounds.cpp | 12 ++++++++++-- .../space/rendering/renderableconstellationbounds.h | 1 + .../space/rendering/renderableconstellationlines.cpp | 12 +++++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/modules/space/rendering/renderableconstellationbounds.cpp b/modules/space/rendering/renderableconstellationbounds.cpp index 7972203696..2dc8eea9c0 100644 --- a/modules/space/rendering/renderableconstellationbounds.cpp +++ b/modules/space/rendering/renderableconstellationbounds.cpp @@ -81,7 +81,7 @@ RenderableConstellationBounds::RenderableConstellationBounds( // Avoid reading files here, instead do it in multithreaded initialize() _vertexFilename = absPath(p.file.string()).string(); - _vertexFilename.onChange([&](){ loadVertexFile(); }); + _vertexFilename.onChange([&](){ loadData(); }); addProperty(_vertexFilename); _color.setViewOption(properties::Property::ViewOptions::Color); @@ -92,7 +92,7 @@ RenderableConstellationBounds::RenderableConstellationBounds( void RenderableConstellationBounds::initialize() { RenderableConstellationsBase::initialize(); - loadVertexFile(); + loadData(); if (!_assetSelection.empty()) { const std::vector options = _selection.options(); @@ -198,6 +198,14 @@ void RenderableConstellationBounds::render(const RenderData& data, RendererTasks void RenderableConstellationBounds::update(const UpdateData& data) { } +bool RenderableConstellationBounds::loadData() { + bool success = loadVertexFile(); + if (!success) { + throw ghoul::RuntimeError("Error loading data"); + } + return success; +} + bool RenderableConstellationBounds::loadVertexFile() { if (_vertexFilename.value().empty()) { return false; diff --git a/modules/space/rendering/renderableconstellationbounds.h b/modules/space/rendering/renderableconstellationbounds.h index b5fcefe299..e5fda8c9d6 100644 --- a/modules/space/rendering/renderableconstellationbounds.h +++ b/modules/space/rendering/renderableconstellationbounds.h @@ -75,6 +75,7 @@ private: * \return \c true if the loading succeeded, \c false otherwise */ bool loadVertexFile(); + bool loadData(); /** * Callback method that gets triggered when _constellationSelection diff --git a/modules/space/rendering/renderableconstellationlines.cpp b/modules/space/rendering/renderableconstellationlines.cpp index 4b5c2d100c..baf6343591 100644 --- a/modules/space/rendering/renderableconstellationlines.cpp +++ b/modules/space/rendering/renderableconstellationlines.cpp @@ -101,6 +101,7 @@ RenderableConstellationLines::RenderableConstellationLines( const Parameters p = codegen::bake(dictionary); _speckFile = absPath(p.file); + addProperty(_drawElements); if (p.lineUnit.has_value()) { @@ -150,10 +151,7 @@ bool RenderableConstellationLines::isReady() const { void RenderableConstellationLines::initialize() { RenderableConstellationsBase::initialize(); - bool success = loadData(); - if (!success) { - throw ghoul::RuntimeError("Error loading data"); - } + loadData(); if (!_assetSelection.empty()) { const std::vector options = _selection.options(); @@ -268,7 +266,11 @@ void RenderableConstellationLines::update(const UpdateData&) { } bool RenderableConstellationLines::loadData() { - return readSpeckFile(); + bool success = readSpeckFile(); + if (!success) { + throw ghoul::RuntimeError("Error loading data"); + } + return success; } bool RenderableConstellationLines::readSpeckFile() { From 3e142e5f2ff4c984dfe80021bac0b5a4ab2ec4b7 Mon Sep 17 00:00:00 2001 From: Malin E Date: Mon, 29 Aug 2022 13:57:40 +0200 Subject: [PATCH 38/79] Change default to not use highlight in grids --- modules/base/rendering/grids/renderablegrid.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/base/rendering/grids/renderablegrid.cpp b/modules/base/rendering/grids/renderablegrid.cpp index 01f5243771..bc4a260a34 100644 --- a/modules/base/rendering/grids/renderablegrid.cpp +++ b/modules/base/rendering/grids/renderablegrid.cpp @@ -115,7 +115,7 @@ RenderableGrid::RenderableGrid(const ghoul::Dictionary& dictionary) , _color(ColorInfo, glm::vec3(0.5f), glm::vec3(0.f), glm::vec3(1.f)) , _highlightColor(HighlightColorInfo, glm::vec3(0.8f), glm::vec3(0.f), glm::vec3(1.f)) , _segments(SegmentsInfo, glm::uvec2(10), glm::uvec2(1), glm::uvec2(200)) - , _highlightRate(HighlightRateInfo, glm::uvec2(5), glm::uvec2(0), glm::uvec2(200)) + , _highlightRate(HighlightRateInfo, glm::uvec2(0), glm::uvec2(0), glm::uvec2(200)) , _lineWidth(LineWidthInfo, 0.5f, 1.f, 20.f) , _highlightLineWidth(HighlightLineWidthInfo, 0.5f, 1.f, 20.f) , _size(SizeInfo, glm::vec2(1.f), glm::vec2(1.f), glm::vec2(1e11f)) @@ -375,6 +375,7 @@ void RenderableGrid::update(const UpdateData&) { _varray.data(), GL_STATIC_DRAW ); + glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), nullptr); // Major grid From 933c97167379c31d57cd96e29e8958bd7856a817 Mon Sep 17 00:00:00 2001 From: Malin E Date: Mon, 29 Aug 2022 16:27:33 +0200 Subject: [PATCH 39/79] Start addressing PR comments --- data/assets/scene/digitaluniverse/grids.asset | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/data/assets/scene/digitaluniverse/grids.asset b/data/assets/scene/digitaluniverse/grids.asset index 44e81c0ff1..ac28d20348 100644 --- a/data/assets/scene/digitaluniverse/grids.asset +++ b/data/assets/scene/digitaluniverse/grids.asset @@ -427,7 +427,7 @@ local plane100kly = { HighlightColor = { 0.3, 0.7, 0.8 }, LineWidth = 2.0, Segments = { 20, 20 }, - HighlightRate = { 5, 5}, + HighlightRate = { 5, 5 }, Size = { 2*lightYear, 2*lightYear }, }, GUI = { @@ -449,10 +449,10 @@ local plane1Mly = { Enabled = false, Opacity = 0.4, Color = { 0.1, 0.5, 0.6 }, - HighlightColor = {0.3, 0.7, 0.8 }, + HighlightColor = { 0.3, 0.7, 0.8 }, LineWidth = 2.0, Segments = { 20, 20 }, - HighlightRate = { 5, 5}, + HighlightRate = { 5, 5 }, Size = { 2*lightYear, 2*lightYear }, }, GUI = { @@ -477,7 +477,7 @@ local plane10Mly = { HighlightColor = { 0.3, 0.7, 0.8 }, LineWidth = 2.0, Segments = { 20, 20 }, - HighlightRate = { 5, 5}, + HighlightRate = { 5, 5 }, Size = { 2*lightYear, 2*lightYear }, }, GUI = { @@ -502,7 +502,7 @@ local plane100Mly = { HighlightColor = { 0.3, 0.7, 0.8 }, LineWidth = 2.0, Segments = { 20, 20 }, - HighlightRate = { 5, 5}, + HighlightRate = { 5, 5 }, Size = { 2*lightYear, 2*lightYear }, }, GUI = { @@ -527,7 +527,7 @@ local plane20Gly = { HighlightColor = { 0.3, 0.7, 0.8 }, LineWidth = 2.0, Segments = { 40, 40 }, - HighlightRate = { 5, 5}, + HighlightRate = { 5, 5 }, Size = { 2*lightYear, 2*lightYear }, }, GUI = { From 47b36e503628753afe7debf7227794f2dbdef23f Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Tue, 30 Aug 2022 13:06:14 +0200 Subject: [PATCH 40/79] Add multiply color to renderableorbitdisc --- .../rendering/renderableorbitdisc.cpp | 20 +++++++++++++++++-- .../rendering/renderableorbitdisc.h | 4 +++- modules/exoplanets/shaders/orbitdisc_fs.glsl | 2 ++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/modules/exoplanets/rendering/renderableorbitdisc.cpp b/modules/exoplanets/rendering/renderableorbitdisc.cpp index c244d82654..6325e93486 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.cpp +++ b/modules/exoplanets/rendering/renderableorbitdisc.cpp @@ -40,9 +40,9 @@ #include namespace { - constexpr std::array UniformNames = { + constexpr std::array UniformNames = { "modelViewProjectionTransform", "offset", "opacity", - "discTexture", "eccentricity", "semiMajorAxis" + "discTexture", "eccentricity", "semiMajorAxis", "multiplyColor" }; constexpr openspace::properties::Property::PropertyInfo TextureInfo = { @@ -74,6 +74,13 @@ namespace { "from the semi-major axis and 1 is a whole semi-major axis's worth of deviation" }; + constexpr openspace::properties::Property::PropertyInfo MultiplyColorInfo = { + "MultiplyColor", + "Multiply Color", + "If set, the disc's texture is multiplied with this color. " + "Useful for applying a color grayscale images" + }; + struct [[codegen::Dictionary(RenderableOrbitDisc)]] Parameters { // [[codegen::verbatim(TextureInfo.description)]] std::filesystem::path texture; @@ -86,6 +93,9 @@ namespace { // [[codegen::verbatim(OffsetInfo.description)]] std::optional offset; + + // [[codegen::verbatim(MultiplyColorInfo.description)]] + std::optional multiplyColor [[codegen::color()]]; }; #include "renderableorbitdisc_codegen.cpp" } // namespace @@ -102,6 +112,7 @@ RenderableOrbitDisc::RenderableOrbitDisc(const ghoul::Dictionary& dictionary) , _size(SizeInfo, 1.f, 0.f, 3.0e12f) , _eccentricity(EccentricityInfo, 0.f, 0.f, 1.f) , _offset(OffsetInfo, glm::vec2(0.f), glm::vec2(0.f), glm::vec2(1.f)) + , _multiplyColor(MultiplyColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f)) { const Parameters p = codegen::bake(dictionary); @@ -119,6 +130,10 @@ RenderableOrbitDisc::RenderableOrbitDisc(const ghoul::Dictionary& dictionary) _texturePath.onChange([&]() { _texture->loadFromFile(_texturePath.value()); }); addProperty(_texturePath); + _multiplyColor = p.multiplyColor.value_or(_multiplyColor); + _multiplyColor.setViewOption(properties::Property::ViewOptions::Color); + addProperty(_multiplyColor); + _eccentricity = p.eccentricity; _eccentricity.onChange([&]() { _planeIsDirty = true; }); addProperty(_eccentricity); @@ -179,6 +194,7 @@ void RenderableOrbitDisc::render(const RenderData& data, RendererTasks&) { _shader->setUniform(_uniformCache.opacity, opacity()); _shader->setUniform(_uniformCache.eccentricity, _eccentricity); _shader->setUniform(_uniformCache.semiMajorAxis, _size); + _shader->setUniform(_uniformCache.multiplyColor, _multiplyColor); ghoul::opengl::TextureUnit unit; unit.activate(); diff --git a/modules/exoplanets/rendering/renderableorbitdisc.h b/modules/exoplanets/rendering/renderableorbitdisc.h index e20fdd7b24..0320e8dc62 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.h +++ b/modules/exoplanets/rendering/renderableorbitdisc.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -64,10 +65,11 @@ private: properties::FloatProperty _size; properties::FloatProperty _eccentricity; properties::Vec2Property _offset; + properties::Vec3Property _multiplyColor; std::unique_ptr _shader = nullptr; UniformCache(modelViewProjection, offset, opacity, texture, - eccentricity, semiMajorAxis) _uniformCache; + eccentricity, semiMajorAxis, multiplyColor) _uniformCache; std::unique_ptr _plane; std::unique_ptr _texture; diff --git a/modules/exoplanets/shaders/orbitdisc_fs.glsl b/modules/exoplanets/shaders/orbitdisc_fs.glsl index 9dc3209e2d..bf2a53ce46 100644 --- a/modules/exoplanets/shaders/orbitdisc_fs.glsl +++ b/modules/exoplanets/shaders/orbitdisc_fs.glsl @@ -32,6 +32,7 @@ uniform vec2 offset; // relative to semi major axis uniform float opacity; uniform float eccentricity; uniform float semiMajorAxis; +uniform vec3 multiplyColor = vec3(1.0); const float Epsilon = 0.0000001; @@ -122,6 +123,7 @@ Fragment getFragment() { vec4 diffuse = texture(discTexture, textureCoord); diffuse.a *= opacity; + diffuse.rgb *= multiplyColor; Fragment frag; frag.color = diffuse; From f247b500c08f40f476da2afef1e4eaca08f12ea1 Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 30 Aug 2022 18:03:47 +0200 Subject: [PATCH 41/79] Address some more PR comments --- data/assets/scene/digitaluniverse/grids.asset | 14 ++++---- .../base/rendering/grids/renderablegrid.cpp | 34 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/data/assets/scene/digitaluniverse/grids.asset b/data/assets/scene/digitaluniverse/grids.asset index ac28d20348..7cbbbe7102 100644 --- a/data/assets/scene/digitaluniverse/grids.asset +++ b/data/assets/scene/digitaluniverse/grids.asset @@ -365,7 +365,7 @@ local plane1kly = { }, Scale = { Type = "StaticScale", - Scale = 1000 + Scale = 1E3 } }, Renderable = { @@ -393,7 +393,7 @@ local plane10kly = { }, Scale = { Type = "StaticScale", - Scale = 10000 + Scale = 10E3 } }, Renderable = { @@ -416,7 +416,7 @@ local plane100kly = { Transform = { Scale = { Type = "StaticScale", - Scale = 100000 + Scale = 100E3 } }, Renderable = { @@ -441,7 +441,7 @@ local plane1Mly = { Transform = { Scale = { Type = "StaticScale", - Scale = 1000000 + Scale = 1E6 } }, Renderable = { @@ -466,7 +466,7 @@ local plane10Mly = { Transform = { Scale = { Type = "StaticScale", - Scale = 10000000 + Scale = 10E6 } }, Renderable = { @@ -491,7 +491,7 @@ local plane100Mly = { Transform = { Scale = { Type = "StaticScale", - Scale = 100000000 + Scale = 100E6 } }, Renderable = { @@ -516,7 +516,7 @@ local plane20Gly = { Transform = { Scale = { Type = "StaticScale", - Scale = 20000000000 + Scale = 20E9 } }, Renderable = { diff --git a/modules/base/rendering/grids/renderablegrid.cpp b/modules/base/rendering/grids/renderablegrid.cpp index bc4a260a34..fc4d6605b2 100644 --- a/modules/base/rendering/grids/renderablegrid.cpp +++ b/modules/base/rendering/grids/renderablegrid.cpp @@ -58,7 +58,9 @@ namespace { constexpr openspace::properties::Property::PropertyInfo HighlightRateInfo = { "HighlightRate", "Highlight Rate", - "The rate the columns and rows are highlighted" + "The rate that the columns and rows are highlighted, counted with respect to the " + "center of the grid. If the number of segments in the grid is odd, the " + "highlighting might be offsett from the center." }; constexpr openspace::properties::Property::PropertyInfo LineWidthInfo = { @@ -285,16 +287,15 @@ void RenderableGrid::update(const UpdateData&) { const float x1 = x0 + step.x; // Line in y direction + bool shouldHighlight = false; if (_highlightRate.value().y != 0) { int rest = static_cast(i - center.y) % _highlightRate.value().y; - if (abs(rest) == 0) { - _highlightArray.push_back({ x0, y0, 0.f }); - _highlightArray.push_back({ x0, y1, 0.f }); - } - else { - _varray.push_back({ x0, y0, 0.f }); - _varray.push_back({ x0, y1, 0.f }); - } + shouldHighlight = abs(rest) == 0; + } + + if (shouldHighlight) { + _highlightArray.push_back({ x0, y0, 0.f }); + _highlightArray.push_back({ x0, y1, 0.f }); } else { _varray.push_back({ x0, y0, 0.f }); @@ -302,16 +303,15 @@ void RenderableGrid::update(const UpdateData&) { } // Line in x direction + shouldHighlight = false; if (_highlightRate.value().x != 0) { int rest = static_cast(j - center.x) % _highlightRate.value().x; - if (abs(rest) == 0) { - _highlightArray.push_back({ x0, y0, 0.f }); - _highlightArray.push_back({ x1, y0, 0.f }); - } - else { - _varray.push_back({ x0, y0, 0.f }); - _varray.push_back({ x1, y0, 0.f }); - } + shouldHighlight = abs(rest) == 0; + } + + if (shouldHighlight) { + _highlightArray.push_back({ x0, y0, 0.f }); + _highlightArray.push_back({ x1, y0, 0.f }); } else { _varray.push_back({ x0, y0, 0.f }); From 0ce7874b90114ccd57b6f621c907b88a25d30a59 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 31 Aug 2022 09:10:18 +0200 Subject: [PATCH 42/79] Address more PR comments --- .../base/rendering/grids/renderablegrid.cpp | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/modules/base/rendering/grids/renderablegrid.cpp b/modules/base/rendering/grids/renderablegrid.cpp index fc4d6605b2..094278edec 100644 --- a/modules/base/rendering/grids/renderablegrid.cpp +++ b/modules/base/rendering/grids/renderablegrid.cpp @@ -325,16 +325,16 @@ void RenderableGrid::update(const UpdateData&) { const float x0 = -halfSize.x + i * step.x; const float x1 = x0 + step.x; + bool shouldHighlight = false; if (_highlightRate.value().x != 0) { - int rest = static_cast(nSegments.y - center.x) % _highlightRate.value().x; - if (abs(rest) == 0) { - _highlightArray.push_back({ x0, halfSize.y, 0.f }); - _highlightArray.push_back({ x1, halfSize.y, 0.f }); - } - else { - _varray.push_back({ x0, halfSize.y, 0.f }); - _varray.push_back({ x1, halfSize.y, 0.f }); - } + int rest = + static_cast(nSegments.y - center.x) % _highlightRate.value().x; + shouldHighlight = abs(rest) == 0; + } + + if (shouldHighlight) { + _highlightArray.push_back({ x0, halfSize.y, 0.f }); + _highlightArray.push_back({ x1, halfSize.y, 0.f }); } else { _varray.push_back({ x0, halfSize.y, 0.f }); @@ -347,16 +347,15 @@ void RenderableGrid::update(const UpdateData&) { const float y0 = -halfSize.y + i * step.y; const float y1 = y0 + step.y; + bool shouldHighlight = false; if (_highlightRate.value().y != 0) { - int rest = static_cast(nSegments.x - center.y) % _highlightRate.value().y; - if (abs(rest) == 0) { - _highlightArray.push_back({ halfSize.x, y0, 0.f }); - _highlightArray.push_back({ halfSize.x, y1, 0.f }); - } - else { - _varray.push_back({ halfSize.x, y0, 0.f }); - _varray.push_back({ halfSize.x, y1, 0.f }); - } + int rest = + static_cast(nSegments.x - center.y) % _highlightRate.value().y; + shouldHighlight = abs(rest) == 0; + } + if (shouldHighlight) { + _highlightArray.push_back({ halfSize.x, y0, 0.f }); + _highlightArray.push_back({ halfSize.x, y1, 0.f }); } else { _varray.push_back({ halfSize.x, y0, 0.f }); From 719786452d8bc93e98b875f6610e11db5b05cb54 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 31 Aug 2022 10:58:34 +0200 Subject: [PATCH 43/79] Address some more PR commnets --- .../renderableconstellationlines.cpp | 42 ++++++++----------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/modules/space/rendering/renderableconstellationlines.cpp b/modules/space/rendering/renderableconstellationlines.cpp index baf6343591..d27c73d4ae 100644 --- a/modules/space/rendering/renderableconstellationlines.cpp +++ b/modules/space/rendering/renderableconstellationlines.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -120,18 +121,18 @@ RenderableConstellationLines::RenderableConstellationLines( } void RenderableConstellationLines::selectionPropertyHasChanged() { + using ConstellationKeyValuePair = std::pair; + // If no values are selected (the default), we want to show all constellations if (!_selection.hasSelected()) { - for (std::pair& pair : - _renderingConstellationsMap) + for (ConstellationKeyValuePair& pair : _renderingConstellationsMap) { pair.second.isEnabled = true; } } else { // Enable all constellations that are selected - for (std::pair& pair : - _renderingConstellationsMap) + for (ConstellationKeyValuePair& pair : _renderingConstellationsMap) { pair.second.isEnabled = _selection.isSelected(pair.second.name); } @@ -187,8 +188,8 @@ void RenderableConstellationLines::initializeGL() { } void RenderableConstellationLines::deinitializeGL() { - for (const std::pair& pair : - _renderingConstellationsMap) + using ConstellationKeyValuePair = std::pair; + for (const ConstellationKeyValuePair& pair : _renderingConstellationsMap) { glDeleteVertexArrays(1, &pair.second.vaoArray); glDeleteBuffers(1, &pair.second.vboArray); @@ -215,8 +216,8 @@ void RenderableConstellationLines::renderConstellations(const RenderData&, _program->setUniform(_uniformCache.projectionTransform, projectionMatrix); _program->setUniform(_uniformCache.opacity, opacity()); - for (const std::pair& pair : - _renderingConstellationsMap) + using ConstellationKeyValuePair = std::pair; + for (const ConstellationKeyValuePair& pair : _renderingConstellationsMap) { if (!pair.second.isEnabled) { continue; @@ -364,31 +365,22 @@ bool RenderableConstellationLines::readSpeckFile() { break; } - std::stringstream lineData(line); - // Try to read three values for the position glm::vec3 pos; bool success = true; - for (int i = 0; i < 3; ++i) { - GLfloat value; - lineData >> value; - bool errorReading = lineData.rdstate() & std::ifstream::failbit; - if (errorReading) { - success = false; - break; - } - - GLfloat scaledValue = value * scale; - pos[i] = scaledValue; - constellationLine.vertices.push_back(scaledValue); + auto reading = scn::scan(line, "{} {} {}", pos.x, pos.y, pos.z); + if (reading) { + pos *= scale; + constellationLine.vertices.push_back(pos.x); + constellationLine.vertices.push_back(pos.y); + constellationLine.vertices.push_back(pos.z); } - - if (!success) { + else { + success = false; LERROR(fmt::format( "Failed reading position on line {} of mesh {} in file: '{}'. " "Stopped reading constellation data", l, lineIndex, _speckFile )); - break; } // Check if new max radius From 7b4b0ab20273db8509495aae96a8e663435b6f25 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 31 Aug 2022 13:44:31 +0200 Subject: [PATCH 44/79] Make the constellation lines data file a property --- .../renderableconstellationbounds.cpp | 2 -- .../rendering/renderableconstellationbounds.h | 1 - .../renderableconstellationlines.cpp | 27 ++++++++++++++----- .../rendering/renderableconstellationlines.h | 2 +- .../rendering/renderableconstellationsbase.h | 1 - 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/modules/space/rendering/renderableconstellationbounds.cpp b/modules/space/rendering/renderableconstellationbounds.cpp index 2dc8eea9c0..db292afaab 100644 --- a/modules/space/rendering/renderableconstellationbounds.cpp +++ b/modules/space/rendering/renderableconstellationbounds.cpp @@ -196,8 +196,6 @@ void RenderableConstellationBounds::render(const RenderData& data, RendererTasks RenderableConstellationsBase::render(data, tasks); } -void RenderableConstellationBounds::update(const UpdateData& data) { } - bool RenderableConstellationBounds::loadData() { bool success = loadVertexFile(); if (!success) { diff --git a/modules/space/rendering/renderableconstellationbounds.h b/modules/space/rendering/renderableconstellationbounds.h index e5fda8c9d6..f6486a50de 100644 --- a/modules/space/rendering/renderableconstellationbounds.h +++ b/modules/space/rendering/renderableconstellationbounds.h @@ -53,7 +53,6 @@ public: bool isReady() const override; void render(const RenderData& data, RendererTasks& rendererTask) override; - void update(const UpdateData& data) override; static documentation::Documentation Documentation(); diff --git a/modules/space/rendering/renderableconstellationlines.cpp b/modules/space/rendering/renderableconstellationlines.cpp index d27c73d4ae..a0c6a1a23d 100644 --- a/modules/space/rendering/renderableconstellationlines.cpp +++ b/modules/space/rendering/renderableconstellationlines.cpp @@ -47,6 +47,12 @@ namespace { "modelViewTransform", "projectionTransform", "opacity", "color" }; + constexpr openspace::properties::Property::PropertyInfo SpeckInfo = { + "File", + "Constellation Data File Path", + "The file that contains the data for the constellation lines" + }; + constexpr openspace::properties::Property::PropertyInfo DrawElementsInfo = { "DrawElements", "Draw Elements", @@ -97,11 +103,15 @@ documentation::Documentation RenderableConstellationLines::Documentation() { RenderableConstellationLines::RenderableConstellationLines( const ghoul::Dictionary& dictionary) : RenderableConstellationsBase(dictionary) + , _speckFile(SpeckInfo) , _drawElements(DrawElementsInfo, true) { const Parameters p = codegen::bake(dictionary); - _speckFile = absPath(p.file); + // Avoid reading files here, instead do it in multithreaded initialize() + _speckFile = absPath(p.file.string()).string(); + _speckFile.onChange([&]() { loadData(); }); + addProperty(_speckFile); addProperty(_drawElements); @@ -275,10 +285,15 @@ bool RenderableConstellationLines::loadData() { } bool RenderableConstellationLines::readSpeckFile() { - LINFO(fmt::format("Loading Speck file {}", _speckFile)); - std::ifstream file(_speckFile); + if (_speckFile.value().empty()) { + return false; + } + std::filesystem::path fileName = absPath(_speckFile); + + LINFO(fmt::format("Loading Speck file {}", fileName)); + std::ifstream file(fileName); if (!file.good()) { - LERROR(fmt::format("Failed to open Speck file {}", _speckFile)); + LERROR(fmt::format("Failed to open Speck file {}", fileName)); return false; } @@ -331,7 +346,7 @@ bool RenderableConstellationLines::readSpeckFile() { } else { std::string message = fmt::format("Unknown command '{}' found in " - "constellation file '{}'", dummy, _speckFile); + "constellation file '{}'", dummy, fileName); LWARNING(message); } dummy.clear(); @@ -379,7 +394,7 @@ bool RenderableConstellationLines::readSpeckFile() { success = false; LERROR(fmt::format( "Failed reading position on line {} of mesh {} in file: '{}'. " - "Stopped reading constellation data", l, lineIndex, _speckFile + "Stopped reading constellation data", l, lineIndex, fileName )); } diff --git a/modules/space/rendering/renderableconstellationlines.h b/modules/space/rendering/renderableconstellationlines.h index 4bfcda7b61..8453fc5dc5 100644 --- a/modules/space/rendering/renderableconstellationlines.h +++ b/modules/space/rendering/renderableconstellationlines.h @@ -88,7 +88,7 @@ private: UniformCache(modelViewTransform, projectionTransform, opacity, color) _uniformCache; - std::filesystem::path _speckFile; + properties::StringProperty _speckFile; DistanceUnit _constellationUnit = DistanceUnit::Parsec; diff --git a/modules/space/rendering/renderableconstellationsbase.h b/modules/space/rendering/renderableconstellationsbase.h index 8da74feedc..3752201577 100644 --- a/modules/space/rendering/renderableconstellationsbase.h +++ b/modules/space/rendering/renderableconstellationsbase.h @@ -60,7 +60,6 @@ public: virtual void render(const RenderData& data, RendererTasks& rendererTask) override; void renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix, const glm::vec3& orthoRight, const glm::vec3& orthoUp); - virtual void update(const UpdateData& data) override = 0; static documentation::Documentation Documentation(); From bb638faf1095f75a2fab1a5fd1df5da24cc99454 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 31 Aug 2022 13:58:08 +0200 Subject: [PATCH 45/79] Move the scaling into the size parameter of the grids --- data/assets/scene/digitaluniverse/grids.asset | 64 +++---------------- .../base/rendering/grids/renderablegrid.cpp | 2 +- 2 files changed, 10 insertions(+), 56 deletions(-) diff --git a/data/assets/scene/digitaluniverse/grids.asset b/data/assets/scene/digitaluniverse/grids.asset index 7cbbbe7102..3d4db8ccde 100644 --- a/data/assets/scene/digitaluniverse/grids.asset +++ b/data/assets/scene/digitaluniverse/grids.asset @@ -307,10 +307,6 @@ local plane10ly = { Type = "StaticRotation", Rotation = eclipticRotationMatrix }, - Scale = { - Type = "StaticScale", - Scale = 10 - } }, Renderable = { Type = "RenderableGrid", @@ -319,7 +315,7 @@ local plane10ly = { Color = { 0.1, 0.5, 0.6 }, LineWidth = 2.0, Segments = { 20, 20 }, - Size = { 2*lightYear, 2*lightYear }, + Size = { 10*2*lightYear, 10*2*lightYear }, }, GUI = { Name = "10ly Grid", @@ -335,10 +331,6 @@ local plane100ly = { Type = "StaticRotation", Rotation = eclipticRotationMatrix }, - Scale = { - Type = "StaticScale", - Scale = 100 - } }, Renderable = { Type = "RenderableGrid", @@ -347,7 +339,7 @@ local plane100ly = { Color = { 0.1, 0.5, 0.6 }, LineWidth = 2.0, Segments = { 20, 20 }, - Size = { 2*lightYear, 2*lightYear }, + Size = { 100*2*lightYear, 100*2*lightYear }, }, GUI = { Name = "100ly Grid", @@ -363,10 +355,6 @@ local plane1kly = { Type = "StaticRotation", Rotation = eclipticRotationMatrix }, - Scale = { - Type = "StaticScale", - Scale = 1E3 - } }, Renderable = { Type = "RenderableGrid", @@ -375,7 +363,7 @@ local plane1kly = { Color = { 0.1, 0.5, 0.6 }, LineWidth = 2.0, Segments = { 20, 20 }, - Size = { 2*lightYear, 2*lightYear }, + Size = { 1E3*2*lightYear, 1E3*2*lightYear }, }, GUI = { Name = "1kly Grid", @@ -391,10 +379,6 @@ local plane10kly = { Type = "StaticRotation", Rotation = eclipticRotationMatrix }, - Scale = { - Type = "StaticScale", - Scale = 10E3 - } }, Renderable = { Type = "RenderableGrid", @@ -403,7 +387,7 @@ local plane10kly = { Color = { 0.1, 0.5, 0.6 }, LineWidth = 2.0, Segments = { 20, 20 }, - Size = { 2*lightYear, 2*lightYear }, + Size = { 10E3*2*lightYear, 10E3*2*lightYear }, }, GUI = { Name = "10kly Grid", @@ -413,12 +397,6 @@ local plane10kly = { local plane100kly = { Identifier = "100klyGrid", - Transform = { - Scale = { - Type = "StaticScale", - Scale = 100E3 - } - }, Renderable = { Type = "RenderableGrid", Enabled = false, @@ -428,7 +406,7 @@ local plane100kly = { LineWidth = 2.0, Segments = { 20, 20 }, HighlightRate = { 5, 5 }, - Size = { 2*lightYear, 2*lightYear }, + Size = { 100E3*2*lightYear, 100E3*2*lightYear }, }, GUI = { Name = "100kly Grid", @@ -438,12 +416,6 @@ local plane100kly = { local plane1Mly = { Identifier = "1MlyGrid", - Transform = { - Scale = { - Type = "StaticScale", - Scale = 1E6 - } - }, Renderable = { Type = "RenderableGrid", Enabled = false, @@ -453,7 +425,7 @@ local plane1Mly = { LineWidth = 2.0, Segments = { 20, 20 }, HighlightRate = { 5, 5 }, - Size = { 2*lightYear, 2*lightYear }, + Size = { 1E6*2*lightYear, 1E6*2*lightYear }, }, GUI = { Name = "1Mly Grid", @@ -463,12 +435,6 @@ local plane1Mly = { local plane10Mly = { Identifier = "10MlyGrid", - Transform = { - Scale = { - Type = "StaticScale", - Scale = 10E6 - } - }, Renderable = { Type = "RenderableGrid", Enabled = false, @@ -478,7 +444,7 @@ local plane10Mly = { LineWidth = 2.0, Segments = { 20, 20 }, HighlightRate = { 5, 5 }, - Size = { 2*lightYear, 2*lightYear }, + Size = { 10E6*2*lightYear, 10E6*2*lightYear }, }, GUI = { Name = "10Mly Grid", @@ -488,12 +454,6 @@ local plane10Mly = { local plane100Mly = { Identifier = "100MlyGrid", - Transform = { - Scale = { - Type = "StaticScale", - Scale = 100E6 - } - }, Renderable = { Type = "RenderableGrid", Enabled = false, @@ -503,7 +463,7 @@ local plane100Mly = { LineWidth = 2.0, Segments = { 20, 20 }, HighlightRate = { 5, 5 }, - Size = { 2*lightYear, 2*lightYear }, + Size = { 100E6*2*lightYear, 100E6*2*lightYear }, }, GUI = { Name = "100Mly Grid", @@ -513,12 +473,6 @@ local plane100Mly = { local plane20Gly = { Identifier = "20GlyGrid", - Transform = { - Scale = { - Type = "StaticScale", - Scale = 20E9 - } - }, Renderable = { Type = "RenderableGrid", Enabled = false, @@ -528,7 +482,7 @@ local plane20Gly = { LineWidth = 2.0, Segments = { 40, 40 }, HighlightRate = { 5, 5 }, - Size = { 2*lightYear, 2*lightYear }, + Size = { 20E9*2*lightYear, 20E9*2*lightYear }, }, GUI = { Name = "20Gly Grid", diff --git a/modules/base/rendering/grids/renderablegrid.cpp b/modules/base/rendering/grids/renderablegrid.cpp index 094278edec..bf03877e12 100644 --- a/modules/base/rendering/grids/renderablegrid.cpp +++ b/modules/base/rendering/grids/renderablegrid.cpp @@ -60,7 +60,7 @@ namespace { "Highlight Rate", "The rate that the columns and rows are highlighted, counted with respect to the " "center of the grid. If the number of segments in the grid is odd, the " - "highlighting might be offsett from the center." + "highlighting might be offset from the center." }; constexpr openspace::properties::Property::PropertyInfo LineWidthInfo = { From fe3e1865365cd9efcd100bd74ceb7a5ed2c75589 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 31 Aug 2022 16:01:15 +0200 Subject: [PATCH 46/79] Remove incorrect indentation in asset file --- .../solarsystem/missions/jwst/trail.asset | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/data/assets/scene/solarsystem/missions/jwst/trail.asset b/data/assets/scene/solarsystem/missions/jwst/trail.asset index b5cebc8991..ab74967e98 100644 --- a/data/assets/scene/solarsystem/missions/jwst/trail.asset +++ b/data/assets/scene/solarsystem/missions/jwst/trail.asset @@ -28,12 +28,12 @@ local JWSTTrailLaunch = { Renderable = { Type = "RenderableTrailTrajectory", Translation = { - Type = 'SpiceTranslation', - Target = 170, -- JWST - Observer = 'EARTH', - Frame = 'IAU_EARTH', - Kernels = { kernels .. "webb.bsp" } - }, + Type = 'SpiceTranslation', + Target = 170, -- JWST + Observer = 'EARTH', + Frame = 'IAU_EARTH', + Kernels = { kernels .. "webb.bsp" } + }, Color = { 0.9, 0.9, 0.0 }, StartTime = launchTime, EndTime = detachTime, @@ -61,12 +61,12 @@ local JWSTTrailCruise = { Renderable = { Type = "RenderableTrailTrajectory", Translation = { - Type = 'SpiceTranslation', - Target = 170, -- JWST - Observer = 'EARTH', - Frame = 'GALACTIC', - Kernels = { kernels .. "webb.bsp" } - }, + Type = 'SpiceTranslation', + Target = 170, -- JWST + Observer = 'EARTH', + Frame = 'GALACTIC', + Kernels = { kernels .. "webb.bsp" } + }, Color = { 0.9, 0.9, 0.0 }, StartTime = detachTime, EndTime = L2orbitInsertionTime, @@ -95,12 +95,12 @@ local JWSTTrailOrbit = { Renderable = { Type = "RenderableTrailOrbit", Translation = { - Type = 'SpiceTranslation', - Target = 170, -- JWST - Observer = 392, -- L2 - Frame = 'GALACTIC', - Kernels = { kernels .. "webb.bsp" } - }, + Type = 'SpiceTranslation', + Target = 170, -- JWST + Observer = 392, -- L2 + Frame = 'GALACTIC', + Kernels = { kernels .. "webb.bsp" } + }, Color = { 0.863, 0.0, 0.902 }, Period = 182.621099, -- About 6 months Resolution = 183 -- About a sample rate of once per day @@ -157,12 +157,12 @@ local JWSTSunTrail = { Renderable = { Type = "RenderableTrailOrbit", Translation = { - Type = 'SpiceTranslation', - Target = 170, -- JWST - Observer = 'SSB', - Frame = 'GALACTIC', - Kernels = { kernels .. "webb.bsp" } - }, + Type = 'SpiceTranslation', + Target = 170, -- JWST + Observer = 'SSB', + Frame = 'GALACTIC', + Kernels = { kernels .. "webb.bsp" } + }, Color = { 0.0, 0.9, 0.9 }, Period = 365.242, Resolution = 365 -- About a sample rate of once per day From 14347cfaba9926a2428721de997a196d047257c6 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 31 Aug 2022 17:02:35 +0200 Subject: [PATCH 47/79] Rename RenderableLabels to RenderableLabel * Since it only creates one label and not several --- modules/base/CMakeLists.txt | 4 +-- modules/base/basemodule.cpp | 6 ++-- ...nderablelabels.cpp => renderablelabel.cpp} | 30 +++++++++---------- .../{renderablelabels.h => renderablelabel.h} | 10 +++---- .../rendering/renderabledistancelabel.cpp | 2 +- .../rendering/renderabledistancelabel.h | 4 +-- 6 files changed, 28 insertions(+), 28 deletions(-) rename modules/base/rendering/{renderablelabels.cpp => renderablelabel.cpp} (95%) rename modules/base/rendering/{renderablelabels.h => renderablelabel.h} (94%) diff --git a/modules/base/CMakeLists.txt b/modules/base/CMakeLists.txt index 35a1526a97..cb0f531ca0 100644 --- a/modules/base/CMakeLists.txt +++ b/modules/base/CMakeLists.txt @@ -44,7 +44,7 @@ set(HEADER_FILES rendering/grids/renderablesphericalgrid.h rendering/renderablecartesianaxes.h rendering/renderabledisc.h - rendering/renderablelabels.h + rendering/renderablelabel.h rendering/renderablemodel.h rendering/renderablenodeline.h rendering/renderableplane.h @@ -98,7 +98,7 @@ set(SOURCE_FILES rendering/grids/renderablesphericalgrid.cpp rendering/renderablecartesianaxes.cpp rendering/renderabledisc.cpp - rendering/renderablelabels.cpp + rendering/renderablelabel.cpp rendering/renderablemodel.cpp rendering/renderablenodeline.cpp rendering/renderableplane.cpp diff --git a/modules/base/basemodule.cpp b/modules/base/basemodule.cpp index b952604ea5..5dbbcd999e 100644 --- a/modules/base/basemodule.cpp +++ b/modules/base/basemodule.cpp @@ -43,7 +43,7 @@ #include #include #include -#include +#include #include #include #include @@ -129,7 +129,7 @@ void BaseModule::internalInitialize(const ghoul::Dictionary&) { fRenderable->registerClass("RenderableCartesianAxes"); fRenderable->registerClass("RenderableDisc"); fRenderable->registerClass("RenderableGrid"); - fRenderable->registerClass("RenderableLabels"); + fRenderable->registerClass("RenderableLabel"); fRenderable->registerClass("RenderableModel"); fRenderable->registerClass("RenderableNodeLine"); fRenderable->registerClass("RenderablePlaneImageLocal"); @@ -212,7 +212,7 @@ std::vector BaseModule::documentations() const { RenderableCartesianAxes::Documentation(), RenderableDisc::Documentation(), RenderableGrid::Documentation(), - RenderableLabels::Documentation(), + RenderableLabel::Documentation(), RenderableModel::Documentation(), RenderableNodeLine::Documentation(), RenderablePlane::Documentation(), diff --git a/modules/base/rendering/renderablelabels.cpp b/modules/base/rendering/renderablelabel.cpp similarity index 95% rename from modules/base/rendering/renderablelabels.cpp rename to modules/base/rendering/renderablelabel.cpp index 9a0b556b73..fb5338a13f 100644 --- a/modules/base/rendering/renderablelabels.cpp +++ b/modules/base/rendering/renderablelabel.cpp @@ -22,7 +22,7 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include #include #include @@ -166,7 +166,7 @@ namespace { "Distance unit for fade-in/-out distance calculations. Defaults to \"au\"" }; - struct [[codegen::Dictionary(RenderableLabels)]] Parameters { + struct [[codegen::Dictionary(RenderableLabel)]] Parameters { enum class [[codegen::map(BlendMode)]] BlendMode { Normal, Additive @@ -228,16 +228,16 @@ namespace { // [[codegen::verbatim(FadeWidthsInfo.description)]] std::optional fadeWidths; }; -#include "renderablelabels_codegen.cpp" +#include "renderablelabel_codegen.cpp" } // namespace namespace openspace { -documentation::Documentation RenderableLabels::Documentation() { +documentation::Documentation RenderableLabel::Documentation() { return codegen::doc("base_renderable_labels"); } -RenderableLabels::RenderableLabels(const ghoul::Dictionary& dictionary) +RenderableLabel::RenderableLabel(const ghoul::Dictionary& dictionary) : Renderable(dictionary) , _blendMode(BlendModeInfo, properties::OptionProperty::DisplayType::Dropdown) , _color(ColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f)) @@ -357,17 +357,17 @@ RenderableLabels::RenderableLabels(const ghoul::Dictionary& dictionary) addProperty(_fadeWidths); } -bool RenderableLabels::isReady() const { +bool RenderableLabel::isReady() const { return true; } -void RenderableLabels::initialize() { +void RenderableLabel::initialize() { ZoneScoped setRenderBin(Renderable::RenderBin::PreDeferredTransparent); } -void RenderableLabels::initializeGL() { +void RenderableLabel::initializeGL() { if (_font == nullptr) { _font = global::fontManager->font( "Mono", @@ -378,9 +378,9 @@ void RenderableLabels::initializeGL() { } } -void RenderableLabels::deinitializeGL() {} +void RenderableLabel::deinitializeGL() {} -void RenderableLabels::render(const RenderData& data, RendererTasks&) { +void RenderableLabel::render(const RenderData& data, RendererTasks&) { glDepthMask(true); glBlendFunc(GL_SRC_ALPHA, GL_ONE); @@ -421,11 +421,11 @@ void RenderableLabels::render(const RenderData& data, RendererTasks&) { } -void RenderableLabels::setLabelText(const std::string & newText) { +void RenderableLabel::setLabelText(const std::string & newText) { _text = newText; } -void RenderableLabels::renderLabels(const RenderData& data, +void RenderableLabel::renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix, const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, float fadeInVariable) @@ -463,7 +463,7 @@ void RenderableLabels::renderLabels(const RenderData& data, ); } -float RenderableLabels::computeFadeFactor(float distanceNodeToCamera) const { +float RenderableLabel::computeFadeFactor(float distanceNodeToCamera) const { float distanceUnit = unit(_fadeUnitOption); float x = distanceNodeToCamera; @@ -487,7 +487,7 @@ float RenderableLabels::computeFadeFactor(float distanceNodeToCamera) const { } } -float RenderableLabels::unit(int unit) const { +float RenderableLabel::unit(int unit) const { switch (static_cast(unit)) { case Meter: return 1.f; case Kilometer: return 1e3f; @@ -505,7 +505,7 @@ float RenderableLabels::unit(int unit) const { } } -std::string_view RenderableLabels::toString(int unit) const { +std::string_view RenderableLabel::toString(int unit) const { switch (static_cast(unit)) { case Meter: return MeterUnit; case Kilometer: return KilometerUnit; diff --git a/modules/base/rendering/renderablelabels.h b/modules/base/rendering/renderablelabel.h similarity index 94% rename from modules/base/rendering/renderablelabels.h rename to modules/base/rendering/renderablelabel.h index cf77a20730..e56d6b45c6 100644 --- a/modules/base/rendering/renderablelabels.h +++ b/modules/base/rendering/renderablelabel.h @@ -22,8 +22,8 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef __OPENSPACE_MODULE_BASE___RENDERABLELABELS___H__ -#define __OPENSPACE_MODULE_BASE___RENDERABLELABELS___H__ +#ifndef __OPENSPACE_MODULE_BASE___RenderableLabel___H__ +#define __OPENSPACE_MODULE_BASE___RenderableLabel___H__ #include @@ -54,9 +54,9 @@ namespace documentation { struct Documentation; } struct LinePoint; -class RenderableLabels : public Renderable { +class RenderableLabel : public Renderable { public: - RenderableLabels(const ghoul::Dictionary& dictionary); + RenderableLabel(const ghoul::Dictionary& dictionary); void initialize() override; void initializeGL() override; @@ -111,4 +111,4 @@ private: } // namespace openspace -#endif // __OPENSPACE_MODULE_BASE___RENDERABLELABELS___H__ +#endif // __OPENSPACE_MODULE_BASE___RenderableLabel___H__ diff --git a/modules/vislab/rendering/renderabledistancelabel.cpp b/modules/vislab/rendering/renderabledistancelabel.cpp index 1833a452f9..6b4a06a28c 100644 --- a/modules/vislab/rendering/renderabledistancelabel.cpp +++ b/modules/vislab/rendering/renderabledistancelabel.cpp @@ -78,7 +78,7 @@ documentation::Documentation RenderableDistanceLabel::Documentation() { } RenderableDistanceLabel::RenderableDistanceLabel(const ghoul::Dictionary& dictionary) - : RenderableLabels(dictionary) + : RenderableLabel(dictionary) , _nodelineId(NodeLineInfo) , _distanceUnit(DistanceUnitInfo, 1, 0, 11) , _customUnitDescriptor(CustomUnitDescriptorInfo) diff --git a/modules/vislab/rendering/renderabledistancelabel.h b/modules/vislab/rendering/renderabledistancelabel.h index 3a0b765aad..b10fa9bff1 100644 --- a/modules/vislab/rendering/renderabledistancelabel.h +++ b/modules/vislab/rendering/renderabledistancelabel.h @@ -25,13 +25,13 @@ #ifndef __OPENSPACE_MODULE_VISLAB___RENDERABLEDISTANCELABEL___H__ #define __OPENSPACE_MODULE_VISLAB___RENDERABLEDISTANCELABEL___H__ -#include +#include namespace openspace { namespace documentation { struct Documentation; } -class RenderableDistanceLabel : public RenderableLabels { +class RenderableDistanceLabel : public RenderableLabel { public: RenderableDistanceLabel(const ghoul::Dictionary& dictionary); From bd5aceeff93fbe4769c73171f52a6599bb20c8f6 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 31 Aug 2022 17:07:51 +0200 Subject: [PATCH 48/79] Fix RenderableLabel specification in assets --- data/assets/scene/solarsystem/dwarf_planets/pluto/pluto.asset | 2 +- data/assets/scene/solarsystem/missions/jwst/jwst.asset | 2 +- data/assets/scene/solarsystem/planets/earth/earth.asset | 2 +- .../scene/solarsystem/planets/earth/lagrange_points/L1.asset | 2 +- .../scene/solarsystem/planets/earth/lagrange_points/L2.asset | 4 ++-- .../scene/solarsystem/planets/earth/lagrange_points/L4.asset | 2 +- .../scene/solarsystem/planets/earth/lagrange_points/L5.asset | 2 +- .../scene/solarsystem/planets/earth/satellites/misc/iss.asset | 2 +- .../solarsystem/planets/earth/satellites/weather/aqua.asset | 2 +- .../solarsystem/planets/earth/satellites/weather/snpp.asset | 2 +- .../solarsystem/planets/earth/satellites/weather/terra.asset | 2 +- data/assets/scene/solarsystem/planets/jupiter/jupiter.asset | 2 +- data/assets/scene/solarsystem/planets/mars/mars.asset | 2 +- data/assets/scene/solarsystem/planets/mercury/mercury.asset | 2 +- data/assets/scene/solarsystem/planets/neptune/neptune.asset | 2 +- data/assets/scene/solarsystem/planets/saturn/saturn.asset | 2 +- data/assets/scene/solarsystem/planets/uranus/uranus.asset | 2 +- data/assets/scene/solarsystem/planets/venus/venus.asset | 2 +- data/assets/scene/solarsystem/sun/sun.asset | 2 +- 19 files changed, 20 insertions(+), 20 deletions(-) diff --git a/data/assets/scene/solarsystem/dwarf_planets/pluto/pluto.asset b/data/assets/scene/solarsystem/dwarf_planets/pluto/pluto.asset index a40164704d..da1200f3bf 100644 --- a/data/assets/scene/solarsystem/dwarf_planets/pluto/pluto.asset +++ b/data/assets/scene/solarsystem/dwarf_planets/pluto/pluto.asset @@ -54,7 +54,7 @@ local PlutoLabel = { Parent = Pluto.Identifier, Renderable = { Enabled = false, - Type = "RenderableLabels", + Type = "RenderableLabel", Text = "Pluto", FontSize = 70.0, Size = 9.05, diff --git a/data/assets/scene/solarsystem/missions/jwst/jwst.asset b/data/assets/scene/solarsystem/missions/jwst/jwst.asset index 7e15b87ad1..cefeb1e481 100644 --- a/data/assets/scene/solarsystem/missions/jwst/jwst.asset +++ b/data/assets/scene/solarsystem/missions/jwst/jwst.asset @@ -131,7 +131,7 @@ local JWSTLabel = { End = endTime }, Renderable = { - Type = "RenderableLabels", + Type = "RenderableLabel", Text = "JWST", FontSize = 50, Size = 6.5, diff --git a/data/assets/scene/solarsystem/planets/earth/earth.asset b/data/assets/scene/solarsystem/planets/earth/earth.asset index dfa2afafc9..bf366bd6ef 100644 --- a/data/assets/scene/solarsystem/planets/earth/earth.asset +++ b/data/assets/scene/solarsystem/planets/earth/earth.asset @@ -53,7 +53,7 @@ local EarthLabel = { Parent = Earth.Identifier, Renderable = { Enabled = false, - Type = "RenderableLabels", + Type = "RenderableLabel", Text = "Earth", FontSize = 70.0, Size = 8.77, diff --git a/data/assets/scene/solarsystem/planets/earth/lagrange_points/L1.asset b/data/assets/scene/solarsystem/planets/earth/lagrange_points/L1.asset index 290b9518de..82a0506fe3 100644 --- a/data/assets/scene/solarsystem/planets/earth/lagrange_points/L1.asset +++ b/data/assets/scene/solarsystem/planets/earth/lagrange_points/L1.asset @@ -56,7 +56,7 @@ local L1Label = { Identifier = "L1Label", Parent = L1Position.Identifier, Renderable = { - Type = "RenderableLabels", + Type = "RenderableLabel", Text = "L1", FontSize = 50, Size = 7.5, diff --git a/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset b/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset index 62a317284a..dc8eb59af8 100644 --- a/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset +++ b/data/assets/scene/solarsystem/planets/earth/lagrange_points/L2.asset @@ -74,7 +74,7 @@ local L2SmallLabel = { Identifier = "L2SmallLabel", Parent = L2Position.Identifier, Renderable = { - Type = "RenderableLabels", + Type = "RenderableLabel", Text = "L2", FontSize = 50.0, Size = 6.0, @@ -95,7 +95,7 @@ local L2Label = { Identifier = "L2Label", Parent = L2Position.Identifier, Renderable = { - Type = "RenderableLabels", + Type = "RenderableLabel", Text = "L2", FontSize = 50, Size = 7.5, diff --git a/data/assets/scene/solarsystem/planets/earth/lagrange_points/L4.asset b/data/assets/scene/solarsystem/planets/earth/lagrange_points/L4.asset index f1badc1ca5..4acaf26ebf 100644 --- a/data/assets/scene/solarsystem/planets/earth/lagrange_points/L4.asset +++ b/data/assets/scene/solarsystem/planets/earth/lagrange_points/L4.asset @@ -56,7 +56,7 @@ local L4Label = { Identifier = "L4Label", Parent = L4Position.Identifier, Renderable = { - Type = "RenderableLabels", + Type = "RenderableLabel", Text = "L4", FontSize = 50, Size = 8.5, diff --git a/data/assets/scene/solarsystem/planets/earth/lagrange_points/L5.asset b/data/assets/scene/solarsystem/planets/earth/lagrange_points/L5.asset index ef8486dec2..cd66f1bc15 100644 --- a/data/assets/scene/solarsystem/planets/earth/lagrange_points/L5.asset +++ b/data/assets/scene/solarsystem/planets/earth/lagrange_points/L5.asset @@ -56,7 +56,7 @@ local L5Label = { Identifier = "L5Label", Parent = L5Position.Identifier, Renderable = { - Type = "RenderableLabels", + Type = "RenderableLabel", Text = "L5", FontSize = 50, Size = 8.5, diff --git a/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset b/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset index 1e1b41dea0..65bd7b1e0e 100644 --- a/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset +++ b/data/assets/scene/solarsystem/planets/earth/satellites/misc/iss.asset @@ -99,7 +99,7 @@ local IssLabel = { Parent = iss.Identifier, Renderable = { Enabled = false, - Type = "RenderableLabels", + Type = "RenderableLabel", Text = "ISS", FontSize = 70.0, Size = 3.4, diff --git a/data/assets/scene/solarsystem/planets/earth/satellites/weather/aqua.asset b/data/assets/scene/solarsystem/planets/earth/satellites/weather/aqua.asset index ef88079ea2..e237bf578a 100644 --- a/data/assets/scene/solarsystem/planets/earth/satellites/weather/aqua.asset +++ b/data/assets/scene/solarsystem/planets/earth/satellites/weather/aqua.asset @@ -63,7 +63,7 @@ local AquaLabel = { Parent = Aqua.Identifier, Renderable = { Enabled = false, - Type = "RenderableLabels", + Type = "RenderableLabel", Text = "Aqua", FontSize = 70.0, Size = 4.0, diff --git a/data/assets/scene/solarsystem/planets/earth/satellites/weather/snpp.asset b/data/assets/scene/solarsystem/planets/earth/satellites/weather/snpp.asset index 6d53c08c0f..a1f28bfd33 100644 --- a/data/assets/scene/solarsystem/planets/earth/satellites/weather/snpp.asset +++ b/data/assets/scene/solarsystem/planets/earth/satellites/weather/snpp.asset @@ -61,7 +61,7 @@ local SNPPLabel = { Parent = SNPP.Identifier, Renderable = { Enabled = false, - Type = "RenderableLabels", + Type = "RenderableLabel", Text = "SNPP", FontSize = 70.0, Size = 4.0, diff --git a/data/assets/scene/solarsystem/planets/earth/satellites/weather/terra.asset b/data/assets/scene/solarsystem/planets/earth/satellites/weather/terra.asset index 4c256885b8..6e998f1116 100644 --- a/data/assets/scene/solarsystem/planets/earth/satellites/weather/terra.asset +++ b/data/assets/scene/solarsystem/planets/earth/satellites/weather/terra.asset @@ -64,7 +64,7 @@ local TerraLabel = { Parent = Terra.Identifier, Renderable = { Enabled = false, - Type = "RenderableLabels", + Type = "RenderableLabel", Text = "Terra", FontSize = 70.0, Size = 4.0, diff --git a/data/assets/scene/solarsystem/planets/jupiter/jupiter.asset b/data/assets/scene/solarsystem/planets/jupiter/jupiter.asset index ad55dbcd35..4ed9f02336 100644 --- a/data/assets/scene/solarsystem/planets/jupiter/jupiter.asset +++ b/data/assets/scene/solarsystem/planets/jupiter/jupiter.asset @@ -45,7 +45,7 @@ local JupiterLabel = { Parent = Jupiter.Identifier, Renderable = { Enabled = false, - Type = "RenderableLabels", + Type = "RenderableLabel", Text = "Jupiter", FontSize = 70.0, Size = 8.77, diff --git a/data/assets/scene/solarsystem/planets/mars/mars.asset b/data/assets/scene/solarsystem/planets/mars/mars.asset index 1734cb053a..f7c65dc58e 100644 --- a/data/assets/scene/solarsystem/planets/mars/mars.asset +++ b/data/assets/scene/solarsystem/planets/mars/mars.asset @@ -58,7 +58,7 @@ local MarsLabel = { Parent = Mars.Identifier, Renderable = { Enabled = false, - Type = "RenderableLabels", + Type = "RenderableLabel", Text = "Mars", FontSize = 70.0, Size = 8.66, diff --git a/data/assets/scene/solarsystem/planets/mercury/mercury.asset b/data/assets/scene/solarsystem/planets/mercury/mercury.asset index e8e0beee5f..9481feb37b 100644 --- a/data/assets/scene/solarsystem/planets/mercury/mercury.asset +++ b/data/assets/scene/solarsystem/planets/mercury/mercury.asset @@ -56,7 +56,7 @@ local MercuryLabel = { Parent = Mercury.Identifier, Renderable = { Enabled = false, - Type = "RenderableLabels", + Type = "RenderableLabel", Text = "Mercury", FontSize = 70.0, Size = 8.46, diff --git a/data/assets/scene/solarsystem/planets/neptune/neptune.asset b/data/assets/scene/solarsystem/planets/neptune/neptune.asset index 92360d16f6..7e5a991e51 100644 --- a/data/assets/scene/solarsystem/planets/neptune/neptune.asset +++ b/data/assets/scene/solarsystem/planets/neptune/neptune.asset @@ -36,7 +36,7 @@ local NeptuneLabel = { Parent = Neptune.Identifier, Renderable = { Enabled = false, - Type = "RenderableLabels", + Type = "RenderableLabel", Text = "Neptune", FontSize = 70.0, Size = 8.96, diff --git a/data/assets/scene/solarsystem/planets/saturn/saturn.asset b/data/assets/scene/solarsystem/planets/saturn/saturn.asset index e5b13c0b6a..7118460ce9 100644 --- a/data/assets/scene/solarsystem/planets/saturn/saturn.asset +++ b/data/assets/scene/solarsystem/planets/saturn/saturn.asset @@ -64,7 +64,7 @@ local SaturnLabel = { Parent = Saturn.Identifier, Renderable = { Enabled = false, - Type = "RenderableLabels", + Type = "RenderableLabel", Text = "Saturn", FontSize = 70.0, Size = 8.85, diff --git a/data/assets/scene/solarsystem/planets/uranus/uranus.asset b/data/assets/scene/solarsystem/planets/uranus/uranus.asset index 3b8581b479..f1d836bc62 100644 --- a/data/assets/scene/solarsystem/planets/uranus/uranus.asset +++ b/data/assets/scene/solarsystem/planets/uranus/uranus.asset @@ -36,7 +36,7 @@ local UranusLabel = { Parent = Uranus.Identifier, Renderable = { Enabled = false, - Type = "RenderableLabels", + Type = "RenderableLabel", Text = "Uranus", FontSize = 70.0, Size = 8.86, diff --git a/data/assets/scene/solarsystem/planets/venus/venus.asset b/data/assets/scene/solarsystem/planets/venus/venus.asset index b027f82d51..bc4f227572 100644 --- a/data/assets/scene/solarsystem/planets/venus/venus.asset +++ b/data/assets/scene/solarsystem/planets/venus/venus.asset @@ -61,7 +61,7 @@ local VenusLabel = { Parent = Venus.Identifier, Renderable = { Enabled = false, - Type = "RenderableLabels", + Type = "RenderableLabel", Text = "Venus", FontSize = 70.0, Size = 8.54, diff --git a/data/assets/scene/solarsystem/sun/sun.asset b/data/assets/scene/solarsystem/sun/sun.asset index 2fe5742c43..52c19866c7 100644 --- a/data/assets/scene/solarsystem/sun/sun.asset +++ b/data/assets/scene/solarsystem/sun/sun.asset @@ -25,7 +25,7 @@ local SunLabel = { Parent = Sun.Identifier, Renderable = { Enabled = false, - Type = "RenderableLabels", + Type = "RenderableLabel", Text = "Sun", FontSize = 70.0, Size = 14.17, From d76b3a902ec61af57a4413bb770c6865c4d8e40e Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 1 Sep 2022 14:15:20 +0200 Subject: [PATCH 49/79] Add generic Labels class --- modules/space/CMakeLists.txt | 2 + modules/space/spacemodule.cpp | 2 + modules/space/specklabels.cpp | 222 ++++++++++++++++++++++++++++++++++ modules/space/specklabels.h | 85 +++++++++++++ src/rendering/renderable.cpp | 6 +- 5 files changed, 314 insertions(+), 3 deletions(-) create mode 100644 modules/space/specklabels.cpp create mode 100644 modules/space/specklabels.h diff --git a/modules/space/CMakeLists.txt b/modules/space/CMakeLists.txt index 4a073ce284..5e653dd239 100644 --- a/modules/space/CMakeLists.txt +++ b/modules/space/CMakeLists.txt @@ -27,6 +27,7 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake) set(HEADER_FILES horizonsfile.h kepler.h + specklabels.h speckloader.h rendering/renderableconstellationbounds.h rendering/renderablefluxnodes.h @@ -47,6 +48,7 @@ set(SOURCE_FILES horizonsfile.cpp kepler.cpp spacemodule_lua.inl + specklabels.cpp speckloader.cpp rendering/renderableconstellationbounds.cpp rendering/renderablefluxnodes.cpp diff --git a/modules/space/spacemodule.cpp b/modules/space/spacemodule.cpp index 23ecd700f4..831ed2ed93 100644 --- a/modules/space/spacemodule.cpp +++ b/modules/space/spacemodule.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -123,6 +124,7 @@ std::vector SpaceModule::documentations() const { RenderableTravelSpeed::Documentation(), SpiceRotation::Documentation(), SpiceTranslation::Documentation(), + speck::SpeckLabels::Documentation(), GPTranslation::Documentation() }; } diff --git a/modules/space/specklabels.cpp b/modules/space/specklabels.cpp new file mode 100644 index 0000000000..e9a855789a --- /dev/null +++ b/modules/space/specklabels.cpp @@ -0,0 +1,222 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2022 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + constexpr int RenderOptionViewDirection = 0; + constexpr int RenderOptionPositionNormal = 1; + + constexpr openspace::properties::Property::PropertyInfo FileInfo = { + "File", + "File", + "The speck label file with tha data for the labels" + }; + + constexpr openspace::properties::Property::PropertyInfo UnitInfo = { + "Unit", + "Unit", + "Distance unit for the label data" + }; + + constexpr openspace::properties::Property::PropertyInfo OpacityInfo = { + "Opacity", + "Opacity", + "Determines the transparency of the labels, where 1 is completely opaque " + "and 0 fully transparent" + }; + constexpr openspace::properties::Property::PropertyInfo ColorInfo = { + "Color", + "Color", + "The color of the labels" + }; + constexpr openspace::properties::Property::PropertyInfo SizeInfo = { + "Size", + "Size", + "The size of the labels in pixels" + }; + constexpr openspace::properties::Property::PropertyInfo MinMaxInfo = { + "MinMaxSize", + "Min/Max Size", + "The minimum and maximum size (in pixels) of the labels" + }; + + constexpr openspace::properties::Property::PropertyInfo RenderOptionInfo = { + "RenderOption", + "Render Option", + "Debug option for rendering of billboards and texts" + }; + + struct [[codegen::Dictionary(SpeckLabels)]] Parameters { + // [[codegen::verbatim(FileInfo.description)]] + std::filesystem::path file; + + // [[codegen::verbatim(OpacityInfo.description)]] + std::optional opacity [[codegen::inrange(0.0, 1.0)]]; + + // [[codegen::verbatim(ColorInfo.description)]] + std::optional color [[codegen::color()]]; + + // [[codegen::verbatim(SizeInfo.description)]] + std::optional size; + + // [[codegen::verbatim(MinMaxInfo.description)]] + std::optional minMaxSize; + + enum class [[codegen::map(openspace::DistanceUnit)]] Unit { + Meter [[codegen::key("m")]], + Kilometer [[codegen::key("Km")]], + Parsec [[codegen::key("pc")]], + Kiloparsec [[codegen::key("Kpc")]], + Megaparsec [[codegen::key("Mpc")]], + Gigaparsec [[codegen::key("Gpc")]], + Gigalightyear [[codegen::key("Gly")]] + }; + std::optional unit; + }; +#include "specklabels_codegen.cpp" +} // namespace + +namespace openspace::speck { + +documentation::Documentation SpeckLabels::Documentation() { + return codegen::doc("space_specklabels"); +} + +SpeckLabels::SpeckLabels(const ghoul::Dictionary& dictionary) + : properties::PropertyOwner({ "SpeckLabels" }) + , _opacity(OpacityInfo, 1.f, 0.f, 1.f) + , _color(ColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f)) + , _size(SizeInfo, 8.f, 0.5f, 24.f) + , _minMaxSize( + MinMaxInfo, + glm::ivec2(8, 500), + glm::ivec2(0), + glm::ivec2(1000) + ) + , _renderOption(RenderOptionInfo, properties::OptionProperty::DisplayType::Dropdown) +{ + const Parameters p = codegen::bake(dictionary); + + //setRenderBin(RenderBin::Overlay); + + _labelFile = absPath(p.file); + + if (p.unit.has_value()) { + _unit = codegen::map(*p.unit); + } + else { + _unit = DistanceUnit::Meter; + } + + _opacity = p.opacity.value_or(_opacity); + addProperty(_opacity); + + _color = p.color.value_or(_color); + _color.setViewOption(properties::Property::ViewOptions::Color); + addProperty(_color); + + _size = p.size.value_or(_size); + addProperty(_size); + + _minMaxSize = p.minMaxSize.value_or(_minMaxSize); + _minMaxSize.setViewOption(properties::Property::ViewOptions::MinMaxRange); + addProperty(_minMaxSize); + + _renderOption.addOption(RenderOptionViewDirection, "Camera View Direction"); + _renderOption.addOption(RenderOptionPositionNormal, "Camera Position Normal"); + // @TODO (abock. 2021-01-31) In the other DU classes, this is done with an enum, and + // doing it based on the fisheye rendering seems a bit brittle? + if (global::windowDelegate->isFisheyeRendering()) { + _renderOption = RenderOptionPositionNormal; + } + else { + _renderOption = RenderOptionViewDirection; + } + addProperty(_renderOption); +} + +void SpeckLabels::initialize() { + if (!_font) { + constexpr int FontSize = 50; + _font = global::fontManager->font( + "Mono", + static_cast(FontSize), + ghoul::fontrendering::FontManager::Outline::Yes, + ghoul::fontrendering::FontManager::LoadGlyphs::No + ); + } +} + +void SpeckLabels::loadLabels() { + _labelset = speck::label::loadFileWithCache(_labelFile); +} + +bool SpeckLabels::isReady() const { + return !(_labelset.entries.empty()); +} + +void SpeckLabels::render(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix, + const glm::vec3& orthoRight, const glm::vec3& orthoUp) +{ + float scale = static_cast(toMeter(_unit)); + + ghoul::fontrendering::FontRenderer::ProjectedLabelsInformation labelInfo; + labelInfo.orthoRight = orthoRight; + labelInfo.orthoUp = orthoUp; + labelInfo.minSize = _minMaxSize.value().x; + labelInfo.maxSize = _minMaxSize.value().y; + labelInfo.cameraPos = data.camera.positionVec3(); + labelInfo.cameraLookUp = data.camera.lookUpVectorWorldSpace(); + labelInfo.renderType = _renderOption; + labelInfo.mvpMatrix = modelViewProjectionMatrix; + labelInfo.scale = pow(10.f, _size); + labelInfo.enableDepth = true; + labelInfo.enableFalseDepth = false; + + glm::vec4 textColor = glm::vec4(glm::vec3(_color), _opacity); + + for (const speck::Labelset::Entry& e : _labelset.entries) { + glm::vec3 scaledPos(e.position); + scaledPos *= scale; + ghoul::fontrendering::FontRenderer::defaultProjectionRenderer().render( + *_font, + scaledPos, + e.text, + textColor, + labelInfo + ); + } +} + +} // namespace openspace::speck diff --git a/modules/space/specklabels.h b/modules/space/specklabels.h new file mode 100644 index 0000000000..1699035fcd --- /dev/null +++ b/modules/space/specklabels.h @@ -0,0 +1,85 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2022 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_MODULE_SPACE___SPECKLABELS___H__ +#define __OPENSPACE_MODULE_SPACE___SPECKLABELS___H__ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace ghoul::fontrendering { class Font; } + +namespace openspace { + struct RenderData; + +namespace documentation { struct Documentation; } + +namespace speck { + +class SpeckLabels : public properties::PropertyOwner { +public: + explicit SpeckLabels(const ghoul::Dictionary& dictionary); + ~SpeckLabels() override = default; + + void initialize(); + + void loadLabels(); + + bool isReady() const; + + void render(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix, + const glm::vec3& orthoRight, const glm::vec3& orthoUp); + + static documentation::Documentation Documentation(); + +private: + std::filesystem::path _labelFile; + DistanceUnit _unit = DistanceUnit::Parsec; + speck::Labelset _labelset; + + std::shared_ptr _font = nullptr; + + // Properties + properties::FloatProperty _opacity; + properties::Vec3Property _color; + properties::FloatProperty _size; + properties::IVec2Property _minMaxSize; + + // DEBUG: + properties::OptionProperty _renderOption; +}; + +} // namespace speck + +} // namespace openspace + +#endif // __OPENSPACE_MODULE_SPACE___SPECKLABELS___H__ diff --git a/src/rendering/renderable.cpp b/src/rendering/renderable.cpp index 90db17c018..3b54240258 100644 --- a/src/rendering/renderable.cpp +++ b/src/rendering/renderable.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include #include @@ -207,7 +207,7 @@ Renderable::Renderable(const ghoul::Dictionary& dictionary) if (p.renderBinMode.has_value()) { setRenderBin(codegen::map(*p.renderBinMode)); } - + _dimInAtmosphere = p.dimInAtmosphere.value_or(_dimInAtmosphere); addProperty(_dimInAtmosphere); } @@ -313,7 +313,7 @@ void Renderable::registerUpdateRenderBinFromOpacity() { } float Renderable::opacity() const { - // Rendering should depend on if camera is in the atmosphere and if camera is at the + // Rendering should depend on if camera is in the atmosphere and if camera is at the // dark part of the globe return _dimInAtmosphere ? _opacity * _fade * global::navigationHandler->camera()->atmosphereDimmingFactor() : From 611bce55cd29a2daf97fcf0a8ce50176adc7b1a1 Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 1 Sep 2022 14:26:31 +0200 Subject: [PATCH 50/79] Fix capital letters in module define --- modules/base/rendering/renderablelabel.h | 6 +++--- modules/space/specklabels.cpp | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/modules/base/rendering/renderablelabel.h b/modules/base/rendering/renderablelabel.h index e56d6b45c6..312e93282e 100644 --- a/modules/base/rendering/renderablelabel.h +++ b/modules/base/rendering/renderablelabel.h @@ -22,8 +22,8 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef __OPENSPACE_MODULE_BASE___RenderableLabel___H__ -#define __OPENSPACE_MODULE_BASE___RenderableLabel___H__ +#ifndef __OPENSPACE_MODULE_BASE___RENDERABLELABEL___H__ +#define __OPENSPACE_MODULE_BASE___RENDERABLELABEL___H__ #include @@ -111,4 +111,4 @@ private: } // namespace openspace -#endif // __OPENSPACE_MODULE_BASE___RenderableLabel___H__ +#endif // __OPENSPACE_MODULE_BASE___RENDERABLELABEL___H__ diff --git a/modules/space/specklabels.cpp b/modules/space/specklabels.cpp index e9a855789a..f1ad88f0a1 100644 --- a/modules/space/specklabels.cpp +++ b/modules/space/specklabels.cpp @@ -128,8 +128,6 @@ SpeckLabels::SpeckLabels(const ghoul::Dictionary& dictionary) { const Parameters p = codegen::bake(dictionary); - //setRenderBin(RenderBin::Overlay); - _labelFile = absPath(p.file); if (p.unit.has_value()) { From 63bbd0d35d15d05d40198e4a6ae2d8d14815ea39 Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 2 Sep 2022 10:48:35 +0200 Subject: [PATCH 51/79] Remove extra commas in grid asset file --- data/assets/scene/digitaluniverse/grids.asset | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/data/assets/scene/digitaluniverse/grids.asset b/data/assets/scene/digitaluniverse/grids.asset index 3d4db8ccde..813553eb1d 100644 --- a/data/assets/scene/digitaluniverse/grids.asset +++ b/data/assets/scene/digitaluniverse/grids.asset @@ -243,7 +243,7 @@ local plane1ld = { Color = { 0.1, 0.5, 0.6 }, LineWidth = 2.0, Segments = { 20, 20 }, - Size = { 2*lightDay, 2*lightDay }, + Size = { 2*lightDay, 2*lightDay } }, GUI = { Name = "1ld Grid", @@ -267,7 +267,7 @@ local plane1lm = { Color = { 0.1, 0.5, 0.6 }, LineWidth = 2.0, Segments = { 20, 20 }, - Size = { 2*lightMonth, 2*lightMonth }, + Size = { 2*lightMonth, 2*lightMonth } }, GUI = { Name = "1lm Grid", @@ -291,7 +291,7 @@ local plane1ly = { Color = { 0.1, 0.5, 0.6 }, LineWidth = 2.0, Segments = { 20, 20 }, - Size = { 2*lightYear, 2*lightYear }, + Size = { 2*lightYear, 2*lightYear } }, GUI = { Name = "1ly Grid", @@ -306,7 +306,7 @@ local plane10ly = { Rotation = { Type = "StaticRotation", Rotation = eclipticRotationMatrix - }, + } }, Renderable = { Type = "RenderableGrid", @@ -315,7 +315,7 @@ local plane10ly = { Color = { 0.1, 0.5, 0.6 }, LineWidth = 2.0, Segments = { 20, 20 }, - Size = { 10*2*lightYear, 10*2*lightYear }, + Size = { 10*2*lightYear, 10*2*lightYear } }, GUI = { Name = "10ly Grid", @@ -330,7 +330,7 @@ local plane100ly = { Rotation = { Type = "StaticRotation", Rotation = eclipticRotationMatrix - }, + } }, Renderable = { Type = "RenderableGrid", @@ -339,7 +339,7 @@ local plane100ly = { Color = { 0.1, 0.5, 0.6 }, LineWidth = 2.0, Segments = { 20, 20 }, - Size = { 100*2*lightYear, 100*2*lightYear }, + Size = { 100*2*lightYear, 100*2*lightYear } }, GUI = { Name = "100ly Grid", @@ -354,7 +354,7 @@ local plane1kly = { Rotation = { Type = "StaticRotation", Rotation = eclipticRotationMatrix - }, + } }, Renderable = { Type = "RenderableGrid", @@ -363,7 +363,7 @@ local plane1kly = { Color = { 0.1, 0.5, 0.6 }, LineWidth = 2.0, Segments = { 20, 20 }, - Size = { 1E3*2*lightYear, 1E3*2*lightYear }, + Size = { 1E3*2*lightYear, 1E3*2*lightYear } }, GUI = { Name = "1kly Grid", @@ -378,7 +378,7 @@ local plane10kly = { Rotation = { Type = "StaticRotation", Rotation = eclipticRotationMatrix - }, + } }, Renderable = { Type = "RenderableGrid", @@ -387,7 +387,7 @@ local plane10kly = { Color = { 0.1, 0.5, 0.6 }, LineWidth = 2.0, Segments = { 20, 20 }, - Size = { 10E3*2*lightYear, 10E3*2*lightYear }, + Size = { 10E3*2*lightYear, 10E3*2*lightYear } }, GUI = { Name = "10kly Grid", @@ -406,7 +406,7 @@ local plane100kly = { LineWidth = 2.0, Segments = { 20, 20 }, HighlightRate = { 5, 5 }, - Size = { 100E3*2*lightYear, 100E3*2*lightYear }, + Size = { 100E3*2*lightYear, 100E3*2*lightYear } }, GUI = { Name = "100kly Grid", @@ -425,7 +425,7 @@ local plane1Mly = { LineWidth = 2.0, Segments = { 20, 20 }, HighlightRate = { 5, 5 }, - Size = { 1E6*2*lightYear, 1E6*2*lightYear }, + Size = { 1E6*2*lightYear, 1E6*2*lightYear } }, GUI = { Name = "1Mly Grid", @@ -444,7 +444,7 @@ local plane10Mly = { LineWidth = 2.0, Segments = { 20, 20 }, HighlightRate = { 5, 5 }, - Size = { 10E6*2*lightYear, 10E6*2*lightYear }, + Size = { 10E6*2*lightYear, 10E6*2*lightYear } }, GUI = { Name = "10Mly Grid", @@ -463,7 +463,7 @@ local plane100Mly = { LineWidth = 2.0, Segments = { 20, 20 }, HighlightRate = { 5, 5 }, - Size = { 100E6*2*lightYear, 100E6*2*lightYear }, + Size = { 100E6*2*lightYear, 100E6*2*lightYear } }, GUI = { Name = "100Mly Grid", @@ -482,7 +482,7 @@ local plane20Gly = { LineWidth = 2.0, Segments = { 40, 40 }, HighlightRate = { 5, 5 }, - Size = { 20E9*2*lightYear, 20E9*2*lightYear }, + Size = { 20E9*2*lightYear, 20E9*2*lightYear } }, GUI = { Name = "20Gly Grid", @@ -502,7 +502,7 @@ asset.onInitialize(function() openspace.addSceneGraphNode(node) end end) - + asset.onDeinitialize(function() for i = #nodes, 1, -1 do local node = nodes[i] From a28814117e4495054b60448be4bd36b2963c60ad Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 2 Sep 2022 14:15:02 +0200 Subject: [PATCH 52/79] Use the new labels for the Constellations --- .../digitaluniverse/constellations.asset | 32 +-- .../renderableconstellationbounds.cpp | 4 +- .../renderableconstellationlines.cpp | 18 +- .../renderableconstellationsbase.cpp | 210 +++--------------- .../rendering/renderableconstellationsbase.h | 23 +- modules/space/specklabels.cpp | 10 +- modules/space/specklabels.h | 3 + 7 files changed, 77 insertions(+), 223 deletions(-) diff --git a/data/assets/scene/digitaluniverse/constellations.asset b/data/assets/scene/digitaluniverse/constellations.asset index a5530f6eb1..8707c05e4a 100644 --- a/data/assets/scene/digitaluniverse/constellations.asset +++ b/data/assets/scene/digitaluniverse/constellations.asset @@ -15,17 +15,19 @@ local constellationsExtragalactic = { Renderable = { Type = "RenderableConstellationLines", Enabled = false, + Labels = { + File = speck .. "constellationsEXGAL.label", + Opacity = 0.4, + Color = { 0.8, 0.8, 0.8 }, + Size = 20.0, + MinMaxSize = { 20, 30 }, + Unit = "Mpc", + }, Opacity = 0.4, File = speck .. "constellationsEXGAL.speck", - LabelFile = speck .. "constellationsEXGAL.label", NamesFile = speck .. "constellations.dat", - TextColor = { 0.8, 0.8, 0.8 }, - TextOpacity = 0.4, - TextSize = 20.0, - TextMinMaxSize = { 20, 30 }, Colors = { { 0.6, 0.4, 0.4 }, { 0.8, 0.0, 0.0 }, { 0.0, 0.3, 0.8 } }, - LabelUnit = "Mpc", - LineUnit = "Mpc", + Unit = "Mpc", -- Selection = zodiacs }, GUI = { @@ -39,17 +41,19 @@ local constellations = { Renderable = { Type = "RenderableConstellationLines", Enabled = false, + Labels = { + File = speck .. "constellations.label", + Opacity = 0.3, + Color = { 0.8, 0.8, 0.8 }, + Size = 14.5, + MinMaxSize = { 8, 170 }, + Unit = "pc", + }, Opacity = 0.3, File = speck .. "constellations.speck", - LabelFile = speck .. "constellations.label", NamesFile = speck .. "constellations.dat", - TextColor = { 0.8, 0.8, 0.8 }, - TextOpacity = 0.3, - TextSize = 14.5, - TextMinMaxSize = { 8, 170 }, Colors = { { 0.6, 0.4, 0.4 }, { 0.8, 0.0, 0.0 }, { 0.0, 0.3, 0.8 } }, - LabelUnit = "pc", - LineUnit = "pc", + Unit = "pc", -- Selection = zodiacs }, GUI = { diff --git a/modules/space/rendering/renderableconstellationbounds.cpp b/modules/space/rendering/renderableconstellationbounds.cpp index db292afaab..4e11060b73 100644 --- a/modules/space/rendering/renderableconstellationbounds.cpp +++ b/modules/space/rendering/renderableconstellationbounds.cpp @@ -157,8 +157,8 @@ bool RenderableConstellationBounds::isReady() const { bool isReady = _program && _vao != 0 && _vbo != 0; // If we have labels, they also need to be loaded - if (_hasLabel) { - return isReady && !_labelset.entries.empty(); + if (_hasLabels) { + return isReady && RenderableConstellationsBase::isReady(); } return isReady; } diff --git a/modules/space/rendering/renderableconstellationlines.cpp b/modules/space/rendering/renderableconstellationlines.cpp index a0c6a1a23d..8ed5943dbf 100644 --- a/modules/space/rendering/renderableconstellationlines.cpp +++ b/modules/space/rendering/renderableconstellationlines.cpp @@ -59,9 +59,9 @@ namespace { "Enables/Disables the drawing of the constellations" }; - constexpr openspace::properties::Property::PropertyInfo LineUnitInfo = { - "LineUnit", - "Line Unit", + constexpr openspace::properties::Property::PropertyInfo UnitInfo = { + "Unit", + "Unit", "The distance unit used for the constellation lines data" }; @@ -85,8 +85,8 @@ namespace { Gigaparsec [[codegen::key("Gpc")]], Gigalightyear [[codegen::key("Gly")]] }; - // [[codegen::verbatim(LineUnitInfo.description)]] - std::optional lineUnit; + // [[codegen::verbatim(UnitInfo.description)]] + std::optional unit; // [[codegen::verbatim(ColorsInfo.description)]] std::optional> colors; @@ -115,8 +115,8 @@ RenderableConstellationLines::RenderableConstellationLines( addProperty(_drawElements); - if (p.lineUnit.has_value()) { - _constellationUnit = codegen::map(*p.lineUnit); + if (p.unit.has_value()) { + _constellationUnit = codegen::map(*p.unit); } else { _constellationUnit = DistanceUnit::Meter; @@ -153,8 +153,8 @@ bool RenderableConstellationLines::isReady() const { bool isReady = _program && !_renderingConstellationsMap.empty(); // If we have labels, they also need to be loaded - if (_hasLabel) { - return isReady && !_labelset.entries.empty(); + if (_hasLabels) { + return isReady && RenderableConstellationsBase::isReady(); } return isReady; } diff --git a/modules/space/rendering/renderableconstellationsbase.cpp b/modules/space/rendering/renderableconstellationsbase.cpp index 6d6ca5d06b..a715d17db3 100644 --- a/modules/space/rendering/renderableconstellationsbase.cpp +++ b/modules/space/rendering/renderableconstellationsbase.cpp @@ -30,8 +30,6 @@ #include #include #include -#include -#include #include #include #include @@ -39,41 +37,6 @@ #include namespace { - constexpr int RenderOptionViewDirection = 0; - constexpr int RenderOptionPositionNormal = 1; - - constexpr openspace::properties::Property::PropertyInfo TextColorInfo = { - "TextColor", - "Text Color", - "The text color of the labels for the constellations" - }; - - constexpr openspace::properties::Property::PropertyInfo TextOpacityInfo = { - "TextOpacity", - "Text Opacity", - "Determines the transparency of the text label, where 1 is completely opaque " - "and 0 fully transparent" - }; - - constexpr openspace::properties::Property::PropertyInfo TextSizeInfo = { - "TextSize", - "Text Size", - "The text size of the labels for the constellations" - }; - - constexpr openspace::properties::Property::PropertyInfo LabelFileInfo = { - "LabelFile", - "Label File", - "The path to the label file that contains information about the constellations" - }; - - constexpr openspace::properties::Property::PropertyInfo LabelMinMaxSizeInfo = { - "TextMinMaxSize", - "Text Min/Max Size", - "The minimum and maximum size (in pixels) for the text of the labels for the " - "constellations" - }; - constexpr openspace::properties::Property::PropertyInfo NamesFileInfo = { "NamesFile", "Constellation Names File Path", @@ -94,24 +57,19 @@ namespace { "Determines whether labels should be drawn or hidden" }; - constexpr openspace::properties::Property::PropertyInfo RenderOptionInfo = { - "RenderOption", - "Render Option", - "Debug option for rendering of billboards and texts" - }; - - constexpr openspace::properties::Property::PropertyInfo LabelUnitInfo = { - "LabelUnit", - "Label Unit", - "The unit used for the label data" - }; - constexpr openspace::properties::Property::PropertyInfo SelectionInfo = { "ConstellationSelection", "Constellation Selection", "The constellations that are selected are displayed on the celestial sphere" }; + static const openspace::properties::PropertyOwner::PropertyOwnerInfo LabelsInfo = + { + "Labels", + "Labels", + "The labels for the astronomical objects" + }; + struct [[codegen::Dictionary(RenderableConstellationsBase)]] Parameters { // [[codegen::verbatim(DrawLabelInfo.description)]] std::optional drawLabels; @@ -119,38 +77,15 @@ namespace { // [[codegen::verbatim(NamesFileInfo.description)]] std::optional namesFile; - // [[codegen::verbatim(TextColorInfo.description)]] - std::optional textColor [[codegen::color()]]; - - // [[codegen::verbatim(TextOpacityInfo.description)]] - std::optional textOpacity; - - // [[codegen::verbatim(TextSizeInfo.description)]] - std::optional textSize; - - // [[codegen::verbatim(LabelFileInfo.description)]] - std::optional labelFile; - - // [[codegen::verbatim(LabelMinMaxSizeInfo.description)]] - std::optional textMinMaxSize; - // [[codegen::verbatim(LineWidthInfo.description)]] std::optional lineWidth; - enum class [[codegen::map(openspace::DistanceUnit)]] Unit { - Meter [[codegen::key("m")]], - Kilometer [[codegen::key("Km")]], - Parsec [[codegen::key("pc")]], - Kiloparsec [[codegen::key("Kpc")]], - Megaparsec [[codegen::key("Mpc")]], - Gigaparsec [[codegen::key("Gpc")]], - Gigalightyear [[codegen::key("Gly")]] - }; - // [[codegen::verbatim(LabelUnitInfo.description)]] - std::optional labelUnit; - // [[codegen::verbatim(SelectionInfo.description)]] std::optional> selection; + + // [[codegen::verbatim(LabelsInfo.description)]] + std::optional labels + [[codegen::reference("space_specklabels")]]; }; #include "renderableconstellationsbase_codegen.cpp" } // namespace @@ -163,18 +98,8 @@ documentation::Documentation RenderableConstellationsBase::Documentation() { RenderableConstellationsBase::RenderableConstellationsBase(const ghoul::Dictionary& dictionary) : Renderable(dictionary) - , _textColor(TextColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f)) - , _textOpacity(TextOpacityInfo, 1.f, 0.f, 1.f) - , _textSize(TextSizeInfo, 8.f, 0.5f, 24.f) , _drawLabels(DrawLabelInfo, false) - , _textMinMaxSize( - LabelMinMaxSizeInfo, - glm::ivec2(8, 500), - glm::ivec2(0), - glm::ivec2(1000) - ) , _lineWidth(LineWidthInfo, 2.f, 1.f, 16.f) - , _renderOption(RenderOptionInfo, properties::OptionProperty::DisplayType::Dropdown) , _namesFilename(NamesFileInfo) , _selection(SelectionInfo) { @@ -183,18 +108,6 @@ RenderableConstellationsBase::RenderableConstellationsBase(const ghoul::Dictiona addProperty(_opacity); registerUpdateRenderBinFromOpacity(); - _renderOption.addOption(RenderOptionViewDirection, "Camera View Direction"); - _renderOption.addOption(RenderOptionPositionNormal, "Camera Position Normal"); - // @TODO (abock. 2021-01-31) In the other classes, this is done with an enum, and - // doing it based on the fisheye rendering seems a bit brittle? - if (global::windowDelegate->isFisheyeRendering()) { - _renderOption = RenderOptionPositionNormal; - } - else { - _renderOption = RenderOptionViewDirection; - } - addProperty(_renderOption); - // Avoid reading files here, instead do it in multithreaded initialize() if (p.namesFile.has_value()) { _namesFilename = absPath(p.namesFile.value().string()).string(); @@ -205,34 +118,13 @@ RenderableConstellationsBase::RenderableConstellationsBase(const ghoul::Dictiona _lineWidth = p.lineWidth.value_or(_lineWidth); addProperty(_lineWidth); - if (p.labelFile.has_value()) { - _labelFile = absPath(*p.labelFile).string(); - _hasLabel = true; - + if (p.labels.has_value()) { _drawLabels = p.drawLabels.value_or(_drawLabels); addProperty(_drawLabels); - _textColor = p.textColor.value_or(_textColor); - _hasLabel = p.textColor.has_value(); - _textColor.setViewOption(properties::Property::ViewOptions::Color); - addProperty(_textColor); - - _textOpacity = p.textOpacity.value_or(_textOpacity); - addProperty(_textOpacity); - - _textSize = p.textSize.value_or(_textSize); - addProperty(_textSize); - - _textMinMaxSize = p.textMinMaxSize.value_or(_textMinMaxSize); - _textMinMaxSize.setViewOption(properties::Property::ViewOptions::MinMaxRange); - addProperty(_textMinMaxSize); - - if (p.labelUnit.has_value()) { - _labelUnit = codegen::map(*p.labelUnit); - } - else { - _labelUnit = DistanceUnit::Meter; - } + _labels = std::make_unique(*p.labels); + _hasLabels = true; + addPropertySubOwner(_labels.get()); } _selection.onChange([this]() { selectionPropertyHasChanged(); }); @@ -270,6 +162,7 @@ void RenderableConstellationsBase::loadConstellationFile() { _selection.clearOptions(); _namesTranslation.clear(); + // Load the constellation names file std::ifstream file; file.exceptions(std::ifstream::goodbit); file.open(absPath(_namesFilename)); @@ -303,26 +196,14 @@ void RenderableConstellationsBase::fillSelectionProperty() { void RenderableConstellationsBase::initialize() { loadConstellationFile(); - if (!_hasLabel) { + if (!_hasLabels) { return; } - if (!_font) { - constexpr int FontSize = 50; - _font = global::fontManager->font( - "Mono", - static_cast(FontSize), - ghoul::fontrendering::FontManager::Outline::Yes, - ghoul::fontrendering::FontManager::LoadGlyphs::No - ); - } + _labels->initialize(); + _labels->loadLabels(); - std::string labelFile = _labelFile; - if (!labelFile.empty()) { - _labelset = speck::label::loadFileWithCache(_labelFile); - } - - for (speck::Labelset::Entry& entry : _labelset.entries) { + for (speck::Labelset::Entry& entry : _labels->labelSet().entries) { if (!entry.identifier.empty()) { std::string fullName = constellationFullName(entry.identifier); if (!fullName.empty()) { @@ -332,8 +213,16 @@ void RenderableConstellationsBase::initialize() { } } +bool RenderableConstellationsBase::isReady() const { + // If we have labels, they also need to be loaded + if (_hasLabels) { + return _labels->isReady(); + } + return true; +} + void RenderableConstellationsBase::render(const RenderData& data, RendererTasks&) { - if (!_hasLabel || !_drawLabels) { + if (!_hasLabels || !_drawLabels) { return; } @@ -367,46 +256,7 @@ void RenderableConstellationsBase::render(const RenderData& data, RendererTasks& const glm::vec3 orthoUp = glm::normalize( glm::vec3(worldToModelTransform * glm::dvec4(up, 0.f)) ); - renderLabels(data, modelViewProjectionMatrix, orthoRight, orthoUp); -} - -void RenderableConstellationsBase::renderLabels(const RenderData& data, - const glm::dmat4& modelViewProjectionMatrix, - const glm::vec3& orthoRight, - const glm::vec3& orthoUp) -{ - float scale = static_cast(toMeter(_labelUnit)); - - ghoul::fontrendering::FontRenderer::ProjectedLabelsInformation labelInfo; - labelInfo.orthoRight = orthoRight; - labelInfo.orthoUp = orthoUp; - labelInfo.minSize = _textMinMaxSize.value().x; - labelInfo.maxSize = _textMinMaxSize.value().y; - labelInfo.cameraPos = data.camera.positionVec3(); - labelInfo.cameraLookUp = data.camera.lookUpVectorWorldSpace(); - labelInfo.renderType = _renderOption; - labelInfo.mvpMatrix = modelViewProjectionMatrix; - labelInfo.scale = pow(10.f, _textSize); - labelInfo.enableDepth = true; - labelInfo.enableFalseDepth = false; - - glm::vec4 textColor = glm::vec4(glm::vec3(_textColor), _textOpacity); - - for (const speck::Labelset::Entry& e : _labelset.entries) { - if (_selection.hasSelected() && !_selection.isSelected(e.text)) { - continue; - } - - glm::vec3 scaledPos(e.position); - scaledPos *= scale; - ghoul::fontrendering::FontRenderer::defaultProjectionRenderer().render( - *_font, - scaledPos, - e.text, - textColor, - labelInfo - ); - } + _labels->render(data, modelViewProjectionMatrix, orthoRight, orthoUp); } } // namespace openspace diff --git a/modules/space/rendering/renderableconstellationsbase.h b/modules/space/rendering/renderableconstellationsbase.h index 3752201577..607747b88a 100644 --- a/modules/space/rendering/renderableconstellationsbase.h +++ b/modules/space/rendering/renderableconstellationsbase.h @@ -27,17 +27,17 @@ #include -#include +#include #include #include #include #include #include +#include #include #include #include -namespace ghoul::fontrendering { class Font; } namespace ghoul::opengl { class ProgramObject; } namespace openspace { @@ -55,11 +55,9 @@ public: virtual void initializeGL() override = 0; virtual void deinitializeGL() override = 0; - virtual bool isReady() const override = 0; + virtual bool isReady() const override; virtual void render(const RenderData& data, RendererTasks& rendererTask) override; - void renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix, - const glm::vec3& orthoRight, const glm::vec3& orthoUp); static documentation::Documentation Documentation(); @@ -87,8 +85,7 @@ protected: std::vector _assetSelection; // Label text settings - bool _hasLabel = false; - speck::Labelset _labelset; + bool _hasLabels = false; properties::BoolProperty _drawLabels; private: @@ -108,16 +105,8 @@ private: // The file containing constellation names and abbreviations properties::StringProperty _namesFilename; - // Label text settings - std::string _labelFile; - std::shared_ptr _font = nullptr; - DistanceUnit _labelUnit = DistanceUnit::Parsec; - properties::Vec3Property _textColor; - properties::FloatProperty _textOpacity; - properties::FloatProperty _textSize; - properties::IVec2Property _textMinMaxSize; - - properties::OptionProperty _renderOption; + // Everything related to the labels are handles by speck::SpeckLabels + std::unique_ptr _labels = nullptr; }; } // namespace openspace diff --git a/modules/space/specklabels.cpp b/modules/space/specklabels.cpp index f1ad88f0a1..c85518f94a 100644 --- a/modules/space/specklabels.cpp +++ b/modules/space/specklabels.cpp @@ -114,7 +114,7 @@ documentation::Documentation SpeckLabels::Documentation() { } SpeckLabels::SpeckLabels(const ghoul::Dictionary& dictionary) - : properties::PropertyOwner({ "SpeckLabels" }) + : properties::PropertyOwner({ "Labels" }) , _opacity(OpacityInfo, 1.f, 0.f, 1.f) , _color(ColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f)) , _size(SizeInfo, 8.f, 0.5f, 24.f) @@ -164,6 +164,14 @@ SpeckLabels::SpeckLabels(const ghoul::Dictionary& dictionary) addProperty(_renderOption); } +speck::Labelset& SpeckLabels::labelSet() { + return _labelset; +} + +const speck::Labelset& SpeckLabels::labelSet() const { + return _labelset; +} + void SpeckLabels::initialize() { if (!_font) { constexpr int FontSize = 50; diff --git a/modules/space/specklabels.h b/modules/space/specklabels.h index 1699035fcd..e4c0868d05 100644 --- a/modules/space/specklabels.h +++ b/modules/space/specklabels.h @@ -50,6 +50,9 @@ public: explicit SpeckLabels(const ghoul::Dictionary& dictionary); ~SpeckLabels() override = default; + speck::Labelset& labelSet(); + const speck::Labelset& labelSet() const; + void initialize(); void loadLabels(); From c04bc24db9172a00fc9859c87fbc4d3482389639 Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 2 Sep 2022 14:54:01 +0200 Subject: [PATCH 53/79] Use new labels for billboards clounds --- data/assets/scene/digitaluniverse/abell.asset | 12 +- .../rendering/renderablebillboardscloud.cpp | 152 ++++-------------- .../rendering/renderablebillboardscloud.h | 19 +-- .../renderableconstellationbounds.cpp | 2 +- .../rendering/renderableconstellationsbase.h | 2 +- modules/space/specklabels.cpp | 5 +- modules/space/specklabels.h | 3 +- 7 files changed, 48 insertions(+), 147 deletions(-) diff --git a/data/assets/scene/digitaluniverse/abell.asset b/data/assets/scene/digitaluniverse/abell.asset index d9339aa103..265824aa02 100644 --- a/data/assets/scene/digitaluniverse/abell.asset +++ b/data/assets/scene/digitaluniverse/abell.asset @@ -17,16 +17,20 @@ local object = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = speck .. "abell.label", + Opacity = 1.0, + Color = { 0.0, 0.8, 0.0 }, + Size = 22, + MinMaxSize = { 10, 12 }, + Unit = "Mpc", + }, Color = { 1.0, 0.4, 0.2 }, Opacity = 1.0, --ColorMap = speck .. "abell.cmap", File = speck .. "abell.speck", Texture = textures .. "point3A.png", - LabelFile = speck .. "abell.label", Unit = "Mpc", - TextColor = { 0.0, 0.8, 0.0 }, - TextSize = 22, - TextMinMaxSize = { 10, 12 }, TransformationMatrix = { -0.7357425748, 0.67726129641, 0.0, 0.0, -0.074553778365, -0.080991471307, 0.9939225904, 0.0, diff --git a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp index 33850c8bc3..c4e3131bca 100644 --- a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp +++ b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp @@ -102,32 +102,6 @@ namespace { "The path to the color map file of the astronomical object" }; - constexpr openspace::properties::Property::PropertyInfo TextColorInfo = { - "TextColor", - "Text Color", - "The text color for the astronomical object" - }; - - constexpr openspace::properties::Property::PropertyInfo TextOpacityInfo = { - "TextOpacity", - "Text Opacity", - "Determines the transparency of the text label, where 1 is completely opaque " - "and 0 fully transparent" - }; - - constexpr openspace::properties::Property::PropertyInfo TextSizeInfo = { - "TextSize", - "Text Size", - "The text size for the astronomical object labels" - }; - - constexpr openspace::properties::Property::PropertyInfo LabelMinMaxSizeInfo = { - "TextMinMaxSize", - "Text Min/Max Size", - "The minimal and maximal size (in pixels) of the text for the labels for the " - "astronomical objects being rendered" - }; - constexpr openspace::properties::Property::PropertyInfo DrawElementsInfo = { "DrawElements", "Draw Elements", @@ -140,6 +114,13 @@ namespace { "Determines whether labels should be drawn or hidden" }; + static const openspace::properties::PropertyOwner::PropertyOwnerInfo LabelsInfo = + { + "Labels", + "Labels", + "The labels for the astronomical objects" + }; + constexpr openspace::properties::Property::PropertyInfo ColorOptionInfo = { "ColorOption", "Color Option", @@ -163,7 +144,8 @@ namespace { constexpr openspace::properties::Property::PropertyInfo RenderOptionInfo = { "RenderOption", "Render Option", - "Debug option for rendering of billboards and texts" + "Option wether the billboards should face the camera or not. Used for " + "non-linear display envierments such as fisheye." }; constexpr openspace::properties::Property::PropertyInfo FadeInDistancesInfo = { @@ -274,21 +256,9 @@ namespace { // [[codegen::verbatim(DrawLabelInfo.description)]] std::optional drawLabels; - // [[codegen::verbatim(TextColorInfo.description)]] - std::optional textColor [[codegen::color()]]; - - // [[codegen::verbatim(TextOpacityInfo.description)]] - std::optional textOpacity; - - // [[codegen::verbatim(TextSizeInfo.description)]] - std::optional textSize; - - // The path to the label file that contains information about the astronomical - // objects being rendered - std::optional labelFile; - - // [[codegen::verbatim(LabelMinMaxSizeInfo.description)]] - std::optional textMinMaxSize; + // [[codegen::verbatim(LabelsInfo.description)]] + std::optional labels + [[codegen::reference("space_specklabels")]]; // [[codegen::verbatim(ColorOptionInfo.description)]] std::optional> colorOption; @@ -339,15 +309,6 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di , _useColorMap(UseColorMapInfo, true) , _pointColor(ColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f)) , _spriteTexturePath(SpriteTextureInfo) - , _textColor(TextColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f)) - , _textOpacity(TextOpacityInfo, 1.f, 0.f, 1.f) - , _textSize(TextSizeInfo, 8.f, 0.5f, 24.f) - , _textMinMaxSize( - LabelMinMaxSizeInfo, - glm::ivec2(8, 20), - glm::ivec2(0), - glm::ivec2(100) - ) , _drawElements(DrawElementsInfo, true) , _drawLabels(DrawLabelInfo, false) , _pixelSizeControl(PixelSizeControlInfo, false) @@ -481,28 +442,13 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di _polygonSides = p.polygonSides.value_or(_polygonSides); _hasPolygon = p.polygonSides.has_value(); - if (p.labelFile.has_value()) { + if (p.labels.has_value()) { _drawLabels = p.drawLabels.value_or(_drawLabels); addProperty(_drawLabels); - _labelFile = absPath(*p.labelFile).string(); - _hasLabel = true; - - _textColor = p.textColor.value_or(_textColor); - _hasLabel = p.textColor.has_value(); - _textColor.setViewOption(properties::Property::ViewOptions::Color); - addProperty(_textColor); - _textColor.onChange([&]() { _textColorIsDirty = true; }); - - _textOpacity = p.textOpacity.value_or(_textOpacity); - addProperty(_textOpacity); - - _textSize = p.textSize.value_or(_textSize); - addProperty(_textSize); - - _textMinMaxSize = p.textMinMaxSize.value_or(_textMinMaxSize); - _textMinMaxSize.setViewOption(properties::Property::ViewOptions::MinMaxRange); - addProperty(_textMinMaxSize); + _labels = std::make_unique(*p.labels); + _hasLabels = true; + addPropertySubOwner(_labels.get()); } _transformationMatrix = p.transformationMatrix.value_or(_transformationMatrix); @@ -557,7 +503,13 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di } bool RenderableBillboardsCloud::isReady() const { - return (_program && (!_dataset.entries.empty())) || (!_labelset.entries.empty()); + bool isReady = _program && !_dataset.entries.empty(); + + // If we have labels, they also need to be loaded + if (_hasLabels) { + isReady = isReady || _labels->isReady(); + } + return isReady; } void RenderableBillboardsCloud::initialize() { @@ -571,11 +523,9 @@ void RenderableBillboardsCloud::initialize() { _colorMap = speck::color::loadFileWithCache(_colorMapFile); } - if (!_labelFile.empty()) { - _labelset = speck::label::loadFileWithCache(_labelFile); - for (speck::Labelset::Entry& e : _labelset.entries) { - e.position = glm::vec3(_transformationMatrix * glm::dvec4(e.position, 1.0)); - } + if (_hasLabels) { + _labels->initialize(); + _labels->loadLabels(); } if (!_colorOptionString.empty() && (_colorRangeData.size() > 1)) { @@ -619,18 +569,6 @@ void RenderableBillboardsCloud::initializeGL() { if (_hasPolygon) { createPolygonTexture(); } - - if (_hasLabel) { - if (!_font) { - size_t _fontSize = 50; - _font = global::fontManager->font( - "Mono", - static_cast(_fontSize), - ghoul::fontrendering::FontManager::Outline::Yes, - ghoul::fontrendering::FontManager::LoadGlyphs::No - ); - } - } } void RenderableBillboardsCloud::deinitializeGL() { @@ -739,40 +677,6 @@ void RenderableBillboardsCloud::renderBillboards(const RenderData& data, global::renderEngine->openglStateCache().resetDepthState(); } -void RenderableBillboardsCloud::renderLabels(const RenderData& data, - const glm::dmat4& modelViewProjectionMatrix, - const glm::dvec3& orthoRight, - const glm::dvec3& orthoUp, - float fadeInVariable) -{ - glm::vec4 textColor = glm::vec4(glm::vec3(_textColor), _textOpacity * fadeInVariable); - - ghoul::fontrendering::FontRenderer::ProjectedLabelsInformation labelInfo; - labelInfo.orthoRight = orthoRight; - labelInfo.orthoUp = orthoUp; - labelInfo.minSize = _textMinMaxSize.value().x; - labelInfo.maxSize = _textMinMaxSize.value().y; - labelInfo.cameraPos = data.camera.positionVec3(); - labelInfo.cameraLookUp = data.camera.lookUpVectorWorldSpace(); - labelInfo.renderType = _renderOption; - labelInfo.mvpMatrix = modelViewProjectionMatrix; - labelInfo.scale = pow(10.f, _textSize); - labelInfo.enableDepth = true; - labelInfo.enableFalseDepth = false; - - for (const speck::Labelset::Entry& e : _labelset.entries) { - glm::vec3 scaledPos(e.position); - scaledPos *= toMeter(_unit); - ghoul::fontrendering::FontRenderer::defaultProjectionRenderer().render( - *_font, - scaledPos, - e.text, - textColor, - labelInfo - ); - } -} - void RenderableBillboardsCloud::render(const RenderData& data, RendererTasks&) { float fadeInVar = 1.f; if (!_disableFadeInDistance) { @@ -819,8 +723,8 @@ void RenderableBillboardsCloud::render(const RenderData& data, RendererTasks&) { renderBillboards(data, modelMatrix, orthoRight, orthoUp, fadeInVar); } - if (_drawLabels && _hasLabel) { - renderLabels(data, modelViewProjectionMatrix, orthoRight, orthoUp, fadeInVar); + if (_drawLabels && _hasLabels) { + _labels->render(data, modelViewProjectionMatrix, orthoRight, orthoUp, fadeInVar); } } diff --git a/modules/digitaluniverse/rendering/renderablebillboardscloud.h b/modules/digitaluniverse/rendering/renderablebillboardscloud.h index d944b2adb9..c70cff455b 100644 --- a/modules/digitaluniverse/rendering/renderablebillboardscloud.h +++ b/modules/digitaluniverse/rendering/renderablebillboardscloud.h @@ -27,7 +27,7 @@ #include -#include +#include #include #include #include @@ -43,7 +43,6 @@ #include namespace ghoul::filesystem { class File; } -namespace ghoul::fontrendering { class Font; } namespace ghoul::opengl { class ProgramObject; class Texture; @@ -79,19 +78,16 @@ private: void renderPolygonGeometry(GLuint vao); void renderBillboards(const RenderData& data, const glm::dmat4& modelMatrix, const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, float fadeInVariable); - void renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix, - const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, float fadeInVariable); bool _hasSpeckFile = false; bool _dataIsDirty = true; - bool _textColorIsDirty = true; bool _hasSpriteTexture = false; bool _spriteTextureIsDirty = true; bool _hasColorMapFile = false; bool _isColorMapExact = false; bool _hasDatavarSize = false; bool _hasPolygon = false; - bool _hasLabel = false; + bool _hasLabels = false; int _polygonSides = 0; @@ -101,10 +97,6 @@ private: properties::BoolProperty _useColorMap; properties::Vec3Property _pointColor; properties::StringProperty _spriteTexturePath; - properties::Vec3Property _textColor; - properties::FloatProperty _textOpacity; - properties::FloatProperty _textSize; - properties::IVec2Property _textMinMaxSize; properties::BoolProperty _drawElements; properties::BoolProperty _drawLabels; properties::BoolProperty _pixelSizeControl; @@ -133,20 +125,19 @@ private: hasDvarScaling ) _uniformCache; - std::shared_ptr _font; - std::string _speckFile; std::string _colorMapFile; - std::string _labelFile; std::string _colorOptionString; std::string _datavarSizeOptionString; DistanceUnit _unit = DistanceUnit::Parsec; speck::Dataset _dataset; - speck::Labelset _labelset; speck::ColorMap _colorMap; + // Everything related to the labels are handles by speck::SpeckLabels + std::unique_ptr _labels = nullptr; + std::vector _colorRangeData; std::unordered_map _optionConversionMap; std::unordered_map _optionConversionSizeMap; diff --git a/modules/space/rendering/renderableconstellationbounds.cpp b/modules/space/rendering/renderableconstellationbounds.cpp index 4e11060b73..e9e6890719 100644 --- a/modules/space/rendering/renderableconstellationbounds.cpp +++ b/modules/space/rendering/renderableconstellationbounds.cpp @@ -158,7 +158,7 @@ bool RenderableConstellationBounds::isReady() const { // If we have labels, they also need to be loaded if (_hasLabels) { - return isReady && RenderableConstellationsBase::isReady(); + isReady = isReady && RenderableConstellationsBase::isReady(); } return isReady; } diff --git a/modules/space/rendering/renderableconstellationsbase.h b/modules/space/rendering/renderableconstellationsbase.h index 607747b88a..a000a3fd7b 100644 --- a/modules/space/rendering/renderableconstellationsbase.h +++ b/modules/space/rendering/renderableconstellationsbase.h @@ -84,7 +84,7 @@ protected: // asset file std::vector _assetSelection; - // Label text settings + // Labels bool _hasLabels = false; properties::BoolProperty _drawLabels; diff --git a/modules/space/specklabels.cpp b/modules/space/specklabels.cpp index c85518f94a..b16bc6eb76 100644 --- a/modules/space/specklabels.cpp +++ b/modules/space/specklabels.cpp @@ -193,7 +193,8 @@ bool SpeckLabels::isReady() const { } void SpeckLabels::render(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix, - const glm::vec3& orthoRight, const glm::vec3& orthoUp) + const glm::vec3& orthoRight, const glm::vec3& orthoUp, + float fadeInVariable) { float scale = static_cast(toMeter(_unit)); @@ -210,7 +211,7 @@ void SpeckLabels::render(const RenderData& data, const glm::dmat4& modelViewProj labelInfo.enableDepth = true; labelInfo.enableFalseDepth = false; - glm::vec4 textColor = glm::vec4(glm::vec3(_color), _opacity); + glm::vec4 textColor = glm::vec4(glm::vec3(_color), _opacity * fadeInVariable); for (const speck::Labelset::Entry& e : _labelset.entries) { glm::vec3 scaledPos(e.position); diff --git a/modules/space/specklabels.h b/modules/space/specklabels.h index e4c0868d05..f59b9b806c 100644 --- a/modules/space/specklabels.h +++ b/modules/space/specklabels.h @@ -60,7 +60,8 @@ public: bool isReady() const; void render(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix, - const glm::vec3& orthoRight, const glm::vec3& orthoUp); + const glm::vec3& orthoRight, const glm::vec3& orthoUp, + float fadeInVariable = 1.f); static documentation::Documentation Documentation(); From 6478f0a92c65bde968c3c6c1cc848d1780e4b15e Mon Sep 17 00:00:00 2001 From: Malin E Date: Mon, 5 Sep 2022 10:43:55 +0200 Subject: [PATCH 54/79] Adjust asset files to use the new labels --- data/assets/scene/digitaluniverse/abell.asset | 2 +- .../digitaluniverse/alternatestarlabels.asset | 19 ++- .../scene/digitaluniverse/clusters.asset | 15 +- .../scene/digitaluniverse/deepsky.asset | 15 +- .../assets/scene/digitaluniverse/dwarfs.asset | 15 +- .../scene/digitaluniverse/exoplanets.asset | 15 +- .../digitaluniverse/globularclusters.asset | 17 +- .../assets/scene/digitaluniverse/groups.asset | 15 +- .../scene/digitaluniverse/h2regions.asset | 17 +- .../scene/digitaluniverse/localdwarfs.asset | 17 +- .../digitaluniverse/milkyway_label.asset | 17 +- .../digitaluniverse/obassociations.asset | 17 +- .../scene/digitaluniverse/openclusters.asset | 17 +- .../digitaluniverse/planetarynebulae.asset | 17 +- .../scene/digitaluniverse/pulsars.asset | 17 +- .../scene/digitaluniverse/starlabels.asset | 19 ++- .../scene/digitaluniverse/superclusters.asset | 17 +- .../digitaluniverse/supernovaremnants.asset | 17 +- data/assets/scene/digitaluniverse/tully.asset | 15 +- data/assets/scene/digitaluniverse/voids.asset | 17 +- .../rendering/renderablebillboardscloud.cpp | 2 - .../rendering/renderableplanescloud.cpp | 159 +++--------------- .../rendering/renderableplanescloud.h | 21 +-- modules/space/specklabels.cpp | 1 + 24 files changed, 217 insertions(+), 283 deletions(-) diff --git a/data/assets/scene/digitaluniverse/abell.asset b/data/assets/scene/digitaluniverse/abell.asset index 265824aa02..649fbf182a 100644 --- a/data/assets/scene/digitaluniverse/abell.asset +++ b/data/assets/scene/digitaluniverse/abell.asset @@ -23,7 +23,7 @@ local object = { Color = { 0.0, 0.8, 0.0 }, Size = 22, MinMaxSize = { 10, 12 }, - Unit = "Mpc", + Unit = "Mpc" }, Color = { 1.0, 0.4, 0.2 }, Opacity = 1.0, diff --git a/data/assets/scene/digitaluniverse/alternatestarlabels.asset b/data/assets/scene/digitaluniverse/alternatestarlabels.asset index a97cd3cbee..42776124b9 100644 --- a/data/assets/scene/digitaluniverse/alternatestarlabels.asset +++ b/data/assets/scene/digitaluniverse/alternatestarlabels.asset @@ -10,14 +10,17 @@ local object = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = speck .. "stars-altlbl.label", + Color = { 0.4, 0.4, 0.4 }, + Size = 14.7, + MinMaxSize = { 6, 20 }, + Unit = "pc" + }, Color = { 1.0, 1.0, 1.0 }, Opacity = 0.65, - LabelFile = speck .. "stars-altlbl.label", Unit = "pc", - TextColor = { 0.4, 0.4, 0.4 }, - DrawLabels = true, - TextSize = 14.7, - TextMinMaxSize = { 6, 20 } + DrawLabels = true }, GUI = { Name = "Stars Labels - Alternate", @@ -28,7 +31,7 @@ local object = { attempts over thousands of years to name all the visible stars have led to two main catalogs: Johann Bayer's Catalog from 1603 and John Flamsteed's Catalog published in 1725. (Description from URL)

Data Reference: Various - sources]], + sources]] } } @@ -36,11 +39,11 @@ local object = { asset.onInitialize(function() openspace.addSceneGraphNode(object) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(object) end) - + asset.export(object) diff --git a/data/assets/scene/digitaluniverse/clusters.asset b/data/assets/scene/digitaluniverse/clusters.asset index 1d97d63e72..57aa7a429c 100644 --- a/data/assets/scene/digitaluniverse/clusters.asset +++ b/data/assets/scene/digitaluniverse/clusters.asset @@ -10,14 +10,17 @@ local object = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = speck .. "galclust.label", + Color = { 1.0, 0.44, 0.0 }, + Size = 22, + MinMaxSize = { 8, 20 }, + Unit = "Mpc" + }, Color = { 1.0, 1.0, 1.0 }, Opacity = 0.65, - LabelFile = speck .. "galclust.label", Unit = "Mpc", - TextColor = { 1.0, 0.44, 0.0 }, DrawLabels = true, - TextSize = 22, - TextMinMaxSize = { 8, 20 }, TransformationMatrix = { -0.7357425748, 0.67726129641, 0.0, 0.0, -0.074553778365, -0.080991471307, 0.9939225904, 0.0, @@ -39,11 +42,11 @@ local object = { asset.onInitialize(function() openspace.addSceneGraphNode(object) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(object) end) - + asset.export(object) diff --git a/data/assets/scene/digitaluniverse/deepsky.asset b/data/assets/scene/digitaluniverse/deepsky.asset index eee9f485f8..d9fd9cad1b 100644 --- a/data/assets/scene/digitaluniverse/deepsky.asset +++ b/data/assets/scene/digitaluniverse/deepsky.asset @@ -17,6 +17,13 @@ local deepSkyPoints = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = speck .. "dso.label", + Color = { 0.1, 0.4, 0.6 }, + Size = 20.50, + MinMaxSize = { 16, 20 }, + Unit = "pc" + }, Color = { 1.0, 1.0, 0.0 }, Opacity = 0.99, ScaleFactor = 500.0, @@ -27,11 +34,7 @@ local deepSkyPoints = { --ColorOption = { "proximity" }, --ColorOption = { "prox5Mpc" }, --ColorRange = { { 1.0, 30.0 } }, - LabelFile = speck .. "dso.label", Unit = "pc", - TextColor = { 0.1, 0.4, 0.6 }, - TextSize = 20.50, - TextMinMaxSize = { 16, 20 }, --FadeInDistances = { 0.05, 1.0 }, -- Fade in value in the same unit as "Unit" BillboardMinMaxSize = { 0.0, 8.22 }, -- in pixels --CorrectionSizeEndDistance = 22.0, @@ -94,12 +97,12 @@ asset.onInitialize(function() openspace.addSceneGraphNode(deepSkyPoints) openspace.addSceneGraphNode(deepSkyImages) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(deepSkyImages) openspace.removeSceneGraphNode(deepSkyPoints) end) - + asset.export(deepSkyPoints) asset.export(deepSkyImages) diff --git a/data/assets/scene/digitaluniverse/dwarfs.asset b/data/assets/scene/digitaluniverse/dwarfs.asset index 64aa5d74bf..70db45410c 100644 --- a/data/assets/scene/digitaluniverse/dwarfs.asset +++ b/data/assets/scene/digitaluniverse/dwarfs.asset @@ -17,18 +17,21 @@ local object = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = speck .. "dwarfs.label", + Color = { 0.5, 0.1, 0.2 }, + Size = 14.6, + MinMaxSize = { 10, 20 }, + Unit = "pc" + }, Color = { 0.4, 0.0, 0.1 }, Opacity = 1.0, File = speck .. "dwarfs.speck", Texture = textures .. "point3.png", - LabelFile = speck .. "dwarfs.label", Unit = "pc", ColorMap = speck .. "dwarfs.cmap", ColorOption = { "typeindex" }, --ColorRange = { { 1.0, 4.0} }, - TextColor = { 0.5, 0.1, 0.2 }, - TextSize = 14.6, - TextMinMaxSize = { 10, 20 }, ScaleFactor = 372.1, --CorrectionSizeEndDistance = 16.1, --CorrectionSizeFactor = 7.75, @@ -61,11 +64,11 @@ local object = { asset.onInitialize(function() openspace.addSceneGraphNode(object) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(object) end) - + asset.export(object) diff --git a/data/assets/scene/digitaluniverse/exoplanets.asset b/data/assets/scene/digitaluniverse/exoplanets.asset index 60539b3fac..a863a257ee 100644 --- a/data/assets/scene/digitaluniverse/exoplanets.asset +++ b/data/assets/scene/digitaluniverse/exoplanets.asset @@ -17,17 +17,20 @@ local object = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = speck .. "expl.label", + Color = { 0.3, 0.3, 0.8 }, + Size = 14.8, + MinMaxSize = { 10, 100 }, + Unit = "pc" + }, Color = { 1.0, 1.0, 1.0 }, Opacity = 1.0, ScaleFactor = 10.0, Texture = textures .. "target-blue.png", File = speck .. "expl.speck", - LabelFile = speck .. "expl.label", Unit = "pc", ScaleFactor = 388.67923, - TextColor = { 0.3, 0.3, 0.8 }, - TextSize = 14.8, - TextMinMaxSize = { 10, 100 }, CorrectionSizeEndDistance = 15.23, CorrectionSizeFactor = 13.3, BillboardMinMaxSize = { 0.0, 75.0 }, @@ -49,11 +52,11 @@ local object = { asset.onInitialize(function() openspace.addSceneGraphNode(object) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(object) end) - + asset.export(object) diff --git a/data/assets/scene/digitaluniverse/globularclusters.asset b/data/assets/scene/digitaluniverse/globularclusters.asset index 30f0bb75b4..a4476dc6da 100644 --- a/data/assets/scene/digitaluniverse/globularclusters.asset +++ b/data/assets/scene/digitaluniverse/globularclusters.asset @@ -17,19 +17,22 @@ local object = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = speck .. "gc.label", + Color = { 0.5, 0.5, 0.0 }, + Size = 16.7, + MinMaxSize = { 4, 20 }, + Unit = "pc" + }, Color = { 0.8, 0.8, 0.0 }, Opacity = 0.4, File = speck .. "gc.speck", Texture = textures .. "point4.png", PolygonSides = 5, - LabelFile = speck .. "gc.label", Unit = "pc", - TextColor = { 0.5, 0.5, 0.0 }, ScaleFactor = 431.0, - TextSize = 16.7, - TextMinMaxSize = { 4, 20 }, BillboardMinMaxSize = { 0.0, 500.0 }, - EnablePixelSizeControl = true, + EnablePixelSizeControl = true }, GUI = { Name = "Globular Clusters", @@ -53,11 +56,11 @@ local object = { asset.onInitialize(function() openspace.addSceneGraphNode(object) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(object) end) - + asset.export(object) diff --git a/data/assets/scene/digitaluniverse/groups.asset b/data/assets/scene/digitaluniverse/groups.asset index e3a8904197..1cd3e928f8 100644 --- a/data/assets/scene/digitaluniverse/groups.asset +++ b/data/assets/scene/digitaluniverse/groups.asset @@ -10,14 +10,17 @@ local object = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = speck .. "groups.label", + Color = { 0.1, 0.6, 0.2 }, + Size = 21.5, + MinMaxSize = { 8, 20 }, + Unit = "Mpc" + }, Color = { 1.0, 1.0, 1.0 }, Opacity = 0.65, --ScaleFactor = 10.0, - LabelFile = speck .. "groups.label", Unit = "Mpc", - TextColor = { 0.1, 0.6, 0.2 }, - TextSize = 21.5, - TextMinMaxSize = { 8, 20 }, DrawLabels = true, TransformationMatrix = { -0.7357425748, 0.67726129641, 0.0, 0.0, @@ -39,11 +42,11 @@ local object = { asset.onInitialize(function() openspace.addSceneGraphNode(object) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(object) end) - + asset.export(object) diff --git a/data/assets/scene/digitaluniverse/h2regions.asset b/data/assets/scene/digitaluniverse/h2regions.asset index 480d0aaa3b..db4b036bca 100644 --- a/data/assets/scene/digitaluniverse/h2regions.asset +++ b/data/assets/scene/digitaluniverse/h2regions.asset @@ -17,17 +17,20 @@ local object = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = speck .. "h2.label", + Color = { 0.5, 0.5, 0.5 }, + Size = 16.24, + MinMaxSize = { 4, 20 }, + Unit = "pc" + }, Color = { 0.0, 0.5, 1.0 }, Opacity = 0.70, File = speck .. "h2.speck", Texture = textures .. "point4.png", PolygonSides = 6, - LabelFile = speck .. "h2.label", Unit = "pc", - TextColor = { 0.5, 0.5, 0.5 }, ScaleFactor = 420, - TextSize = 16.24, - TextMinMaxSize = { 4, 20 }, BillboardMinMaxSize = { 0.0, 300.0 }, EnablePixelSizeControl = false }, @@ -44,18 +47,18 @@ local object = { Because of this, they are great tracers of the spiral arms of the Galaxy, and were instrumental in our understanding of the Galaxy's overall structure (Description from URL)

Data Reference: The WISE catalog of Galactic - HII Regions (Anderson+, 2014)]], + HII Regions (Anderson+, 2014)]] } } asset.onInitialize(function() openspace.addSceneGraphNode(object) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(object) end) - + asset.export(object) diff --git a/data/assets/scene/digitaluniverse/localdwarfs.asset b/data/assets/scene/digitaluniverse/localdwarfs.asset index 9322874697..7d59c8275a 100644 --- a/data/assets/scene/digitaluniverse/localdwarfs.asset +++ b/data/assets/scene/digitaluniverse/localdwarfs.asset @@ -17,6 +17,13 @@ local object = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = speck .. "localgroup.label", + Color = { 0.3, 0.3, 1.0 }, + Size = 18.3, + MinMaxSize = { 7, 20 }, + Unit = "Mpc" + }, Color = { 0.5, 1.0, 0.2 }, ColorMap = speck .. "localgroup.cmap", ColorOption = { "association" }, @@ -24,12 +31,8 @@ local object = { File = speck .. "localgroup.speck", Texture = textures .. "point4.png", PolygonSides = 12, - LabelFile = speck .. "localgroup.label", Unit = "Mpc", - TextColor = { 0.3, 0.3, 1.0 }, ScaleFactor = 465, - TextSize = 18.3, - TextMinMaxSize = { 7, 20 }, BillboardMinMaxSize = { 0.0, 20.0 }, EnablePixelSizeControl = true }, @@ -46,18 +49,18 @@ local object = { bevy of dwarf galaxies-smaller, often irregular galaxies, that contain hundreds of millions to a few billion stars. (Description from URL)

Data Reference: Properties of dwarf galaxies in the Local Group - (McConnachie+, 2012)]], + (McConnachie+, 2012)]] } } asset.onInitialize(function() openspace.addSceneGraphNode(object) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(object) end) - + asset.export(object) diff --git a/data/assets/scene/digitaluniverse/milkyway_label.asset b/data/assets/scene/digitaluniverse/milkyway_label.asset index ae32435c2b..f6501a647f 100644 --- a/data/assets/scene/digitaluniverse/milkyway_label.asset +++ b/data/assets/scene/digitaluniverse/milkyway_label.asset @@ -10,15 +10,18 @@ local homeLabel = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = homespeck .. "home.label", + Color = { 0.8, 0.8, 0.8 }, + Size = 20.50, + MinMaxSize = { 16, 20 }, + Unit = "Mpc" + }, Color = { 1.0, 0.4, 0.2 }, Opacity = 0.99, ScaleFactor = 500.0, DrawLabels = true, - LabelFile = homespeck .. "home.label", Unit = "Mpc", - TextColor = { 0.8, 0.8, 0.8 }, - TextSize = 20.50, - TextMinMaxSize = { 16, 20 }, TransformationMatrix = { -0.7357425748, 0.67726129641, 0.0, 0.0, -0.074553778365, -0.080991471307, 0.9939225904, 0.0, @@ -32,18 +35,18 @@ local homeLabel = { GUI = { Name = "Home Label", Path = "/Universe/Galaxies", - Description = "Label for the Milky Way titled 'Home', sided for the galactic level", + Description = "Label for the Milky Way titled 'Home', sided for the galactic level" } } asset.onInitialize(function() openspace.addSceneGraphNode(homeLabel) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(homeLabel) end) - + asset.export(homeLabel) diff --git a/data/assets/scene/digitaluniverse/obassociations.asset b/data/assets/scene/digitaluniverse/obassociations.asset index 74e439360d..5d5afefd2a 100644 --- a/data/assets/scene/digitaluniverse/obassociations.asset +++ b/data/assets/scene/digitaluniverse/obassociations.asset @@ -17,6 +17,13 @@ local object = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = speck .. "ob.label", + Color = { 0.4, 0.5, 1.0 }, + Size = 16.24, + MinMaxSize = { 4, 25 }, + Unit = "pc" + }, Color = { 1.0, 1.0, 1.0 }, ColorMap = speck .. "ob.cmap", ColorOption = { "arm" }, @@ -27,11 +34,7 @@ local object = { Unit = "pc", Texture = textures .. "point4.png", PolygonSides = 7, - LabelFile = speck .. "ob.label", - TextColor = { 0.4, 0.5, 1.0 }, ScaleFactor = 390.0, - TextSize = 16.24, - TextMinMaxSize = { 4, 25 }, BillboardMinMaxSize = { 0.0, 450.0 }, EnablePixelSizeControl = true }, @@ -48,18 +51,18 @@ local object = { coded by their spiral arm membership. Blue associations trace the Sagittarius Arm. Purple associations are in the local Orion Spur. Orange associations are in the Perseus Arm (Description from URL)

Data Reference: New List of - OB Associations (Melnik+)]], + OB Associations (Melnik+)]] } } asset.onInitialize(function() openspace.addSceneGraphNode(object) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(object) end) - + asset.export(object) diff --git a/data/assets/scene/digitaluniverse/openclusters.asset b/data/assets/scene/digitaluniverse/openclusters.asset index bd025ed7a5..06dfbf3219 100644 --- a/data/assets/scene/digitaluniverse/openclusters.asset +++ b/data/assets/scene/digitaluniverse/openclusters.asset @@ -17,17 +17,20 @@ local object = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = speck .. "oc.label", + Color = { 0.05, 0.4, 0.2 }, + Size = 15.5, + MinMaxSize = { 4, 30 }, + Unit = "pc" + }, Color = { 0.1, 0.8, 0.4 }, Opacity = 0.5, File = speck .. "oc.speck", Unit = "pc", Texture = textures .. "point4.png", PolygonSides = 12, - TextColor = { 0.05, 0.4, 0.2 }, - LabelFile = speck .. "oc.label", ScaleFactor = 405.75, - TextSize = 15.5, - TextMinMaxSize = { 4, 30 }, BillboardMinMaxSize = { 0.0, 604.0 }, EnablePixelSizeControl = true }, @@ -48,18 +51,18 @@ local object = { as Galactic clusters, but this term fell out of favor once astronomers began to understand that the Galaxy includes objects beyond the Milky Way's disk.

Data Reference: Optically - visible open clusters and Candidates (Dias+ 2002-2015)]], + visible open clusters and Candidates (Dias+ 2002-2015)]] } } asset.onInitialize(function() openspace.addSceneGraphNode(object) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(object) end) - + asset.export(object) diff --git a/data/assets/scene/digitaluniverse/planetarynebulae.asset b/data/assets/scene/digitaluniverse/planetarynebulae.asset index 937a33043f..4670c4a6b1 100644 --- a/data/assets/scene/digitaluniverse/planetarynebulae.asset +++ b/data/assets/scene/digitaluniverse/planetarynebulae.asset @@ -17,17 +17,20 @@ local object = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = speck .. "pn.label", + Color = { 0.25, 0.25, 0.65 }, + Size = 16.24, + MinMaxSize = { 4, 25 }, + Unit = "pc" + }, Color = { 0.4, 0.4, 0.9 }, Opacity = 0.65, File = speck .. "pn.speck", Texture = textures .. "point4.png", PolygonSides = 3, - LabelFile = speck .. "pn.label", Unit = "pc", - TextColor = { 0.25, 0.25, 0.65 }, ScaleFactor = 425.0, - TextSize = 16.24, - TextMinMaxSize = { 4, 25 }, BillboardMinMaxSize = { 0.0, 500.0 }, EnablePixelSizeControl = true }, @@ -41,18 +44,18 @@ local object = { way are they related to planets, rather, they are products of dying stars. (Description from URL)

Data Reference: Planetary Nebulae distances in Gaia DR2 (Kimeswenger+, 2018), Strasbourg-ESO Catalog of Planetary Nebulae - (Acker+ 1992)]], + (Acker+ 1992)]] } } asset.onInitialize(function() openspace.addSceneGraphNode(object) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(object) end) - + asset.export(object) diff --git a/data/assets/scene/digitaluniverse/pulsars.asset b/data/assets/scene/digitaluniverse/pulsars.asset index 91f08b8a74..1bc18492ef 100644 --- a/data/assets/scene/digitaluniverse/pulsars.asset +++ b/data/assets/scene/digitaluniverse/pulsars.asset @@ -17,17 +17,20 @@ local object = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = speck .. "pulsar.label", + Color = { 0.7, 0.2, 0.2 }, + Size = 15.77, + MinMaxSize = { 4, 20 }, + Unit = "pc" + }, Color = { 0.7, 0.0, 0.0 }, Opacity = 1.0, File = speck .. "pulsar.speck", Texture = textures .. "point4.png", PolygonSides = 4, - LabelFile = speck .. "pulsar.label", Unit = "pc", - TextColor = { 0.7, 0.2, 0.2 }, ScaleFactor = 424, - TextSize = 15.77, - TextMinMaxSize = { 4, 20 }, BillboardMinMaxSize = { 0.0, 500.0 }, EnablePixelSizeControl = false }, @@ -45,18 +48,18 @@ local object = { cannot be packed any tighter. At this point, the star has a radius of about 10-15 kilometers. The density of this material is so high that a teaspoonful would weigh about 100 million tons on Earth. (Description from URL)

- Data Reference: ATNF Pulsar Catalogue, (Manchester+, 2005)]], + Data Reference: ATNF Pulsar Catalogue, (Manchester+, 2005)]] } } asset.onInitialize(function() openspace.addSceneGraphNode(object) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(object) end) - + asset.export(object) diff --git a/data/assets/scene/digitaluniverse/starlabels.asset b/data/assets/scene/digitaluniverse/starlabels.asset index b4efcfe6ea..8543b5a6d6 100644 --- a/data/assets/scene/digitaluniverse/starlabels.asset +++ b/data/assets/scene/digitaluniverse/starlabels.asset @@ -10,30 +10,33 @@ local object = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = speck .. "stars.label", + Color = { 0.4, 0.4, 0.4 }, + Size = 14.7, + MinMaxSize = { 6, 50 }, + Unit = "pc" + }, Color = { 1.0, 1.0, 1.0 }, Opacity = 0.65, - LabelFile = speck .. "stars.label", Unit = "pc", - TextColor = { 0.4, 0.4, 0.4 }, - DrawLabels = true, - TextSize = 14.7, - TextMinMaxSize = { 6, 50 } + DrawLabels = true }, GUI = { Name = "Stars Labels", Path = "/Milky Way/Stars", - Description = "Labels for stars in the Milky Way. See 'Stars' for more info", + Description = "Labels for stars in the Milky Way. See 'Stars' for more info" } } asset.onInitialize(function() openspace.addSceneGraphNode(object) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(object) end) - + asset.export(object) diff --git a/data/assets/scene/digitaluniverse/superclusters.asset b/data/assets/scene/digitaluniverse/superclusters.asset index cd7a4a649e..375128e9d1 100644 --- a/data/assets/scene/digitaluniverse/superclusters.asset +++ b/data/assets/scene/digitaluniverse/superclusters.asset @@ -17,19 +17,22 @@ local object = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = speck .. "superclust.label", + Color = { 0.9, 0.9, 0.9 }, + Size = 22.44, + MinMaxSize = { 8, 20 }, + Unit = "Mpc" + }, DrawElements = false, Color = { 1.0, 1.0, 1.0 }, Opacity = 0.65, File = speck .. "superclust.speck", Texture = textures .. "point3A.png", - LabelFile = speck .. "superclust.label", Unit = "Mpc", - TextColor = { 0.9, 0.9, 0.9 }, ScaleFactor = 531.0, - TextSize = 22.44, - TextMinMaxSize = { 8, 20 }, DrawLabels = true, - --BillboardMinMaxSize = { 0.0, 7.2 }, + -- BillboardMinMaxSize = { 0.0, 7.2 }, EnablePixelSizeControl = true }, GUI = { @@ -47,11 +50,11 @@ local object = { asset.onInitialize(function() openspace.addSceneGraphNode(object) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(object) end) - + asset.export(object) diff --git a/data/assets/scene/digitaluniverse/supernovaremnants.asset b/data/assets/scene/digitaluniverse/supernovaremnants.asset index 0f3fefa885..6d331cccb5 100644 --- a/data/assets/scene/digitaluniverse/supernovaremnants.asset +++ b/data/assets/scene/digitaluniverse/supernovaremnants.asset @@ -17,17 +17,20 @@ local object = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = speck .. "snr.label", + Color = { 0.6, 0.46, 0.0 }, + Size = 16.44, + MinMaxSize = { 4, 100 }, + Unit = "pc" + }, Color = { 1.0, 0.5, 0.0 }, Opacity = 0.32, File = speck .. "snr.speck", Texture = textures .. "point4.png", PolygonSides = 7, - LabelFile = speck .. "snr.label", Unit = "pc", - TextColor = { 0.6, 0.46, 0.0 }, ScaleFactor = 424, - TextSize = 16.44, - TextMinMaxSize = { 4, 100 }, --CorrectionSizeEndDistance = 17.5, --CorrectionSizeFactor = 13.96, BillboardMinMaxSize = { 0.0, 500.0 }, @@ -40,18 +43,18 @@ local object = { remnant is the ejected gas that results from a supernova. It glows for a cosmically short period of time before mixing with the interstellar medium. (Description from URL)

Data Reference: The First Fermi LAT SNR - Catalog (Acero+, 2016)]], + Catalog (Acero+, 2016)]] } } asset.onInitialize(function() openspace.addSceneGraphNode(object) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(object) end) - + asset.export(object) diff --git a/data/assets/scene/digitaluniverse/tully.asset b/data/assets/scene/digitaluniverse/tully.asset index cb488b17ff..96521ba5f2 100644 --- a/data/assets/scene/digitaluniverse/tully.asset +++ b/data/assets/scene/digitaluniverse/tully.asset @@ -17,6 +17,13 @@ local tullyPoints = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = true, + Labels = { + File = speck .. "tully.label", + Color = { 0.7, 0.7, 0.7 }, + Size = 19.36, + MinMaxSize = { 8, 20 }, + Unit = "Mpc" + }, Color = { 1.0, 0.4, 0.2 }, Opacity = 0.99, ScaleFactor = 504.0, @@ -27,12 +34,8 @@ local tullyPoints = { --ColorOption = { "proximity" }, ColorOption = { "prox5Mpc" }, ColorRange = { { 1.0, 30.0 } }, - LabelFile = speck .. "tully.label", DrawLabels = false, Unit = "Mpc", - TextColor = { 0.7, 0.7, 0.7 }, - TextSize = 19.36, - TextMinMaxSize = { 8, 20 }, TransformationMatrix = { -0.7357425748, 0.67726129641, 0.0, 0.0, -0.074553778365, -0.080991471307, 0.9939225904, 0.0, @@ -110,12 +113,12 @@ asset.onInitialize(function() openspace.addSceneGraphNode(tullyPoints) openspace.addSceneGraphNode(tullyImages) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(tullyImages) openspace.removeSceneGraphNode(tullyPoints) end) - + asset.export(tullyPoints) asset.export(tullyImages) diff --git a/data/assets/scene/digitaluniverse/voids.asset b/data/assets/scene/digitaluniverse/voids.asset index 02c0b964c9..f380b05e32 100644 --- a/data/assets/scene/digitaluniverse/voids.asset +++ b/data/assets/scene/digitaluniverse/voids.asset @@ -10,15 +10,18 @@ local object = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = speck .. "voids.label", + Color = { 0.296, 0.629, 1.0 }, + Size = 20.9, + MinMaxSize = { 8, 20 }, + Unit = "Mpc" + }, DrawElements = false, DrawLabels = true, Color = { 1.0, 1.0, 1.0 }, Opacity = 0.65, - LabelFile = speck .. "voids.label", - Unit = "Mpc", - TextColor = { 0.296, 0.629, 1.0 }, - TextSize = 20.9, - TextMinMaxSize = { 8, 20 } + Unit = "Mpc" }, GUI = { Name = "Voids", @@ -39,11 +42,11 @@ local object = { asset.onInitialize(function() openspace.addSceneGraphNode(object) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(object) end) - + asset.export(object) diff --git a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp index c4e3131bca..437e5e3fc6 100644 --- a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp +++ b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp @@ -32,8 +32,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.cpp b/modules/digitaluniverse/rendering/renderableplanescloud.cpp index 390a9d9733..17922c46df 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.cpp +++ b/modules/digitaluniverse/rendering/renderableplanescloud.cpp @@ -31,8 +31,6 @@ #include #include #include -#include -#include #include #include #include @@ -67,44 +65,11 @@ namespace { "size of each point" }; - constexpr openspace::properties::Property::PropertyInfo TextColorInfo = { - "TextColor", - "Text Color", - "The text color for the astronomical object" - }; - - constexpr openspace::properties::Property::PropertyInfo TextOpacityInfo = { - "TextOpacity", - "Text Opacity", - "Determines the transparency of the text label, where 1 is completely opaque " - "and 0 fully transparent" - }; - - constexpr openspace::properties::Property::PropertyInfo TextSizeInfo = { - "TextSize", - "Text Size", - "The text size for the astronomical object labels" - }; - - constexpr openspace::properties::Property::PropertyInfo LabelFileInfo = { - "LabelFile", - "Label File", - "The path to the label file that contains information about the astronomical " - "objects being rendered" - }; - - constexpr openspace::properties::Property::PropertyInfo LabelMinSizeInfo = { - "TextMinSize", - "Text Min Size", - "The minimal size (in pixels) of the text for the labels for the astronomical " - "objects being rendered" - }; - - constexpr openspace::properties::Property::PropertyInfo LabelMaxSizeInfo = { - "TextMaxSize", - "Text Max Size", - "The maximum size (in pixels) of the text for the labels for the astronomical " - "objects being rendered" + static const openspace::properties::PropertyOwner::PropertyOwnerInfo LabelsInfo = + { + "Labels", + "Labels", + "The labels for the astronomical objects" }; constexpr openspace::properties::Property::PropertyInfo DrawElementsInfo = { @@ -176,23 +141,9 @@ namespace { // [[codegen::verbatim(ScaleFactorInfo.description)]] std::optional scaleFactor; - // [[codegen::verbatim(TextColorInfo.description)]] - std::optional textColor [[codegen::color()]]; - - // [[codegen::verbatim(TextOpacityInfo.description)]] - std::optional textOpacity; - - // [[codegen::verbatim(TextSizeInfo.description)]] - std::optional textSize; - - // [[codegen::verbatim(LabelFileInfo.description)]] - std::optional labelFile; - - // [[codegen::verbatim(LabelMinSizeInfo.description)]] - std::optional textMinSize; - - // [[codegen::verbatim(LabelMaxSizeInfo.description)]] - std::optional textMaxSize; + // [[codegen::verbatim(LabelsInfo.description)]] + std::optional labels + [[codegen::reference("space_specklabels")]]; // [[codegen::verbatim(TransformationMatrixInfo.description)]] std::optional transformationMatrix; @@ -246,9 +197,6 @@ documentation::Documentation RenderablePlanesCloud::Documentation() { RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary) : Renderable(dictionary) , _scaleFactor(ScaleFactorInfo, 1.f, 0.f, 300000.f) - , _textColor(TextColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f)) - , _textOpacity(TextOpacityInfo, 1.f, 0.f, 1.f) - , _textSize(TextSizeInfo, 8.0, 0.5, 24.0) , _drawElements(DrawElementsInfo, true) , _blendMode(BlendModeInfo, properties::OptionProperty::DisplayType::Dropdown) , _fadeInDistances( @@ -290,23 +238,10 @@ RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary addProperty(_scaleFactor); _scaleFactor.onChange([&]() { _dataIsDirty = true; }); - if (p.labelFile.has_value()) { - _labelFile = absPath(*p.labelFile); - _hasLabel = true; - - _textColor = p.textColor.value_or(_textColor); - _textColor.setViewOption(properties::Property::ViewOptions::Color); - addProperty(_textColor); - _textColor.onChange([&]() { _textColorIsDirty = true; }); - - _textOpacity = p.textOpacity.value_or(_textOpacity); - addProperty(_textOpacity); - - _textSize = p.textSize.value_or(_textSize); - addProperty(_textSize); - - _textMinSize = p.textMinSize.value_or(_textMinSize); - _textMaxSize = p.textMaxSize.value_or(_textMaxSize); + if (p.labels.has_value()) { + _labels = std::make_unique(*p.labels); + _hasLabels = true; + addPropertySubOwner(_labels.get()); } _transformationMatrix = p.transformationMatrix.value_or(_transformationMatrix); @@ -360,7 +295,13 @@ RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary } bool RenderablePlanesCloud::isReady() const { - return (_program && (!_dataset.entries.empty())) || (!_labelset.entries.empty()); + bool isReady = _program && !_dataset.entries.empty(); + + // If we have labels, they also need to be loaded + if (_hasLabels) { + isReady = isReady || _labels->isReady(); + } + return isReady; } void RenderablePlanesCloud::initialize() { @@ -373,12 +314,9 @@ void RenderablePlanesCloud::initialize() { } } - if (!_labelFile.empty()) { - LINFO(fmt::format("Loading Label file {}", _labelFile)); - _labelset = speck::label::loadFileWithCache(_labelFile); - for (speck::Labelset::Entry& e : _labelset.entries) { - e.position = glm::vec3(_transformationMatrix * glm::dvec4(e.position, 1.0)); - } + if (_hasLabels) { + _labels->initialize(); + _labels->loadLabels(); } } @@ -400,18 +338,6 @@ void RenderablePlanesCloud::initializeGL() { createPlanes(); loadTextures(); - - if (_hasLabel) { - if (!_font) { - constexpr int FontSize = 30; - _font = global::fontManager->font( - "Mono", - static_cast(FontSize), - ghoul::fontrendering::FontManager::Outline::Yes, - ghoul::fontrendering::FontManager::LoadGlyphs::No - ); - } - } } void RenderablePlanesCloud::deleteDataGPUAndCPU() { @@ -488,39 +414,6 @@ void RenderablePlanesCloud::renderPlanes(const RenderData&, global::renderEngine->openglStateCache().resetPolygonAndClippingState(); } -void RenderablePlanesCloud::renderLabels(const RenderData& data, - const glm::dmat4& modelViewProjectionMatrix, - const glm::dvec3& orthoRight, - const glm::dvec3& orthoUp, float fadeInVariable) -{ - double scale = toMeter(_unit); - glm::vec4 textColor = glm::vec4(glm::vec3(_textColor), _textOpacity * fadeInVariable); - - ghoul::fontrendering::FontRenderer::ProjectedLabelsInformation labelInfo; - labelInfo.orthoRight = orthoRight; - labelInfo.orthoUp = orthoUp; - labelInfo.minSize = _textMinSize; - labelInfo.maxSize = _textMaxSize; - labelInfo.cameraPos = data.camera.positionVec3(); - labelInfo.cameraLookUp = data.camera.lookUpVectorWorldSpace(); - labelInfo.renderType = _renderOption; - labelInfo.mvpMatrix = modelViewProjectionMatrix; - labelInfo.scale = pow(10.f, _textSize); - labelInfo.enableDepth = true; - labelInfo.enableFalseDepth = false; - - for (const speck::Labelset::Entry& e : _labelset.entries) { - glm::dvec3 scaledPos = glm::dvec3(e.position) * scale; - ghoul::fontrendering::FontRenderer::defaultProjectionRenderer().render( - *_font, - scaledPos, - e.text, - textColor, - labelInfo - ); - } -} - void RenderablePlanesCloud::render(const RenderData& data, RendererTasks&) { const double scale = toMeter(_unit); @@ -563,8 +456,8 @@ void RenderablePlanesCloud::render(const RenderData& data, RendererTasks&) { renderPlanes(data, modelViewMatrix, projectionMatrix, fadeInVariable); } - if (_hasLabel) { - renderLabels(data, mvpMatrix, orthoRight, orthoUp, fadeInVariable); + if (_hasLabels) { + _labels->render(data, mvpMatrix, orthoRight, orthoUp, fadeInVariable); } } @@ -753,10 +646,6 @@ void RenderablePlanesCloud::createPlanes() { setBoundingSphere(maxRadius * _scaleFactor); _fadeInDistances.setMaxValue(glm::vec2(10.f * maxSize)); } - - if (_hasLabel && _labelDataIsDirty) { - _labelDataIsDirty = false; - } } } // namespace openspace diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.h b/modules/digitaluniverse/rendering/renderableplanescloud.h index d155556251..a931ef7fcd 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.h +++ b/modules/digitaluniverse/rendering/renderableplanescloud.h @@ -27,7 +27,7 @@ #include -#include +#include #include #include #include @@ -42,7 +42,6 @@ #include namespace ghoul::filesystem { class File; } -namespace ghoul::fontrendering { class Font; } namespace ghoul::opengl { class ProgramObject; class Texture; @@ -83,25 +82,15 @@ private: void createPlanes(); void renderPlanes(const RenderData& data, const glm::dmat4& modelViewMatrix, const glm::dmat4& projectionMatrix, float fadeInVariable); - void renderLabels(const RenderData& data, - const glm::dmat4& modelViewProjectionMatrix, const glm::dvec3& orthoRight, - const glm::dvec3& orthoUp, float fadeInVariable); void loadTextures(); bool _hasSpeckFile = false; bool _dataIsDirty = true; bool _textColorIsDirty = true; - bool _hasLabel = false; - bool _labelDataIsDirty = true; - - int _textMinSize = 0; - int _textMaxSize = 200; + bool _hasLabels = false; properties::FloatProperty _scaleFactor; - properties::Vec3Property _textColor; - properties::FloatProperty _textOpacity; - properties::FloatProperty _textSize; properties::BoolProperty _drawElements; properties::OptionProperty _blendMode; properties::Vec2Property _fadeInDistances; @@ -113,20 +102,20 @@ private: UniformCache( modelViewProjectionTransform, alphaValue, fadeInValue, galaxyTexture ) _uniformCache; - std::shared_ptr _font = nullptr; std::unordered_map> _textureMap; std::unordered_map _textureFileMap; std::unordered_map _planesMap; std::filesystem::path _speckFile; - std::filesystem::path _labelFile; std::filesystem::path _texturesPath; std::string _luminosityVar; DistanceUnit _unit = DistanceUnit::Parsec; speck::Dataset _dataset; - speck::Labelset _labelset; + + // Everything related to the labels are handles by speck::SpeckLabels + std::unique_ptr _labels = nullptr; float _sluminosity = 1.f; diff --git a/modules/space/specklabels.cpp b/modules/space/specklabels.cpp index b16bc6eb76..e6e8d06c60 100644 --- a/modules/space/specklabels.cpp +++ b/modules/space/specklabels.cpp @@ -185,6 +185,7 @@ void SpeckLabels::initialize() { } void SpeckLabels::loadLabels() { + LINFOC("SpeckLabels", fmt::format("Loading Label file {}", _labelFile)); _labelset = speck::label::loadFileWithCache(_labelFile); } From 0a2f39dbf081d89f32a1e932912a341f9dd8d5c2 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 7 Sep 2022 11:27:17 +0200 Subject: [PATCH 55/79] Make the argument in asset.localResource optional * If nothing is provided, then the path to the current directory that the asset is located in is returned --- src/scene/assetmanager.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/scene/assetmanager.cpp b/src/scene/assetmanager.cpp index b0c6409174..ddac86157b 100644 --- a/src/scene/assetmanager.cpp +++ b/src/scene/assetmanager.cpp @@ -489,10 +489,14 @@ void AssetManager::setUpAssetLuaTable(Asset* asset) { ZoneScoped Asset* thisAsset = ghoul::lua::userData(L, 1); - ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::localResourceLua"); + ghoul::lua::checkArgumentsAndThrow(L, { 0, 1 }, "lua::localResourceLua"); + + auto [name] = ghoul::lua::values>(L); + std::filesystem::path path = + name.has_value() ? + thisAsset->path().parent_path() / *name : + thisAsset->path().parent_path(); - std::string name = ghoul::lua::value(L); - std::filesystem::path path = thisAsset->path().parent_path() / name; ghoul::lua::push(L, path); return 1; }, @@ -514,7 +518,7 @@ void AssetManager::setUpAssetLuaTable(Asset* asset) { ghoul::Dictionary d = ghoul::lua::value(L); std::unique_ptr s = ResourceSynchronization::createFromDictionary(d); - + std::string uid = d.value("Type") + "/" + s->generateUid(); SyncItem* syncItem = nullptr; auto it = manager->_synchronizations.find(uid); From 75fd08246ca5cc22a35112c0d9a7971d8d65b574 Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 8 Sep 2022 09:41:00 +0200 Subject: [PATCH 56/79] Switch from floats to doubles for the grids * Avoids jittering problems when close to SSB --- .../base/rendering/grids/renderablegrid.cpp | 59 ++++++++++--------- modules/base/rendering/grids/renderablegrid.h | 2 +- modules/base/shaders/grid_vs.glsl | 6 +- 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/modules/base/rendering/grids/renderablegrid.cpp b/modules/base/rendering/grids/renderablegrid.cpp index bf03877e12..1c4e9b712b 100644 --- a/modules/base/rendering/grids/renderablegrid.cpp +++ b/modules/base/rendering/grids/renderablegrid.cpp @@ -213,7 +213,7 @@ void RenderableGrid::render(const RenderData& data, RendererTasks&){ glm::dmat4 modelTransform = glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation glm::dmat4(data.modelTransform.rotation) * // Spice rotation - glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)); + glm::scale(glm::dmat4(1.0), data.modelTransform.scale); glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform; @@ -264,9 +264,10 @@ void RenderableGrid::update(const UpdateData&) { return; } - const glm::vec2 halfSize = _size.value() / 2.f; + const glm::dvec2 halfSize = static_cast(_size.value()) / 2.0; const glm::uvec2 nSegments = _segments.value(); - const glm::vec2 step = _size.value() / static_cast(nSegments); + const glm::dvec2 step = + static_cast(_size.value()) / static_cast(nSegments); const int nLines = (2 * nSegments.x * nSegments.y) + nSegments.x + nSegments.y; const int nVertices = 2 * nLines; @@ -280,11 +281,11 @@ void RenderableGrid::update(const UpdateData&) { const glm::uvec2 center = glm::uvec2(nSegments.x / 2.f, nSegments.y / 2.f); for (unsigned int i = 0; i < nSegments.x; ++i) { for (unsigned int j = 0; j < nSegments.y; ++j) { - const float y0 = -halfSize.y + j * step.y; - const float y1 = y0 + step.y; + const double y0 = -halfSize.y + j * step.y; + const double y1 = y0 + step.y; - const float x0 = -halfSize.x + i * step.x; - const float x1 = x0 + step.x; + const double x0 = -halfSize.x + i * step.x; + const double x1 = x0 + step.x; // Line in y direction bool shouldHighlight = false; @@ -294,12 +295,12 @@ void RenderableGrid::update(const UpdateData&) { } if (shouldHighlight) { - _highlightArray.push_back({ x0, y0, 0.f }); - _highlightArray.push_back({ x0, y1, 0.f }); + _highlightArray.push_back({ x0, y0, 0.0 }); + _highlightArray.push_back({ x0, y1, 0.0 }); } else { - _varray.push_back({ x0, y0, 0.f }); - _varray.push_back({ x0, y1, 0.f }); + _varray.push_back({ x0, y0, 0.0 }); + _varray.push_back({ x0, y1, 0.0 }); } // Line in x direction @@ -310,20 +311,20 @@ void RenderableGrid::update(const UpdateData&) { } if (shouldHighlight) { - _highlightArray.push_back({ x0, y0, 0.f }); - _highlightArray.push_back({ x1, y0, 0.f }); + _highlightArray.push_back({ x0, y0, 0.0 }); + _highlightArray.push_back({ x1, y0, 0.0 }); } else { - _varray.push_back({ x0, y0, 0.f }); - _varray.push_back({ x1, y0, 0.f }); + _varray.push_back({ x0, y0, 0.0 }); + _varray.push_back({ x1, y0, 0.0 }); } } } // last x row for (unsigned int i = 0; i < nSegments.x; ++i) { - const float x0 = -halfSize.x + i * step.x; - const float x1 = x0 + step.x; + const double x0 = -halfSize.x + i * step.x; + const double x1 = x0 + step.x; bool shouldHighlight = false; if (_highlightRate.value().x != 0) { @@ -333,19 +334,19 @@ void RenderableGrid::update(const UpdateData&) { } if (shouldHighlight) { - _highlightArray.push_back({ x0, halfSize.y, 0.f }); - _highlightArray.push_back({ x1, halfSize.y, 0.f }); + _highlightArray.push_back({ x0, halfSize.y, 0.0 }); + _highlightArray.push_back({ x1, halfSize.y, 0.0 }); } else { - _varray.push_back({ x0, halfSize.y, 0.f }); - _varray.push_back({ x1, halfSize.y, 0.f }); + _varray.push_back({ x0, halfSize.y, 0.0 }); + _varray.push_back({ x1, halfSize.y, 0.0 }); } } // last y col for (unsigned int i = 0; i < nSegments.y; ++i) { - const float y0 = -halfSize.y + i * step.y; - const float y1 = y0 + step.y; + const double y0 = -halfSize.y + i * step.y; + const double y1 = y0 + step.y; bool shouldHighlight = false; if (_highlightRate.value().y != 0) { @@ -354,12 +355,12 @@ void RenderableGrid::update(const UpdateData&) { shouldHighlight = abs(rest) == 0; } if (shouldHighlight) { - _highlightArray.push_back({ halfSize.x, y0, 0.f }); - _highlightArray.push_back({ halfSize.x, y1, 0.f }); + _highlightArray.push_back({ halfSize.x, y0, 0.0 }); + _highlightArray.push_back({ halfSize.x, y1, 0.0 }); } else { - _varray.push_back({ halfSize.x, y0, 0.f }); - _varray.push_back({ halfSize.x, y1, 0.f }); + _varray.push_back({ halfSize.x, y0, 0.0 }); + _varray.push_back({ halfSize.x, y1, 0.0 }); } } @@ -375,7 +376,7 @@ void RenderableGrid::update(const UpdateData&) { GL_STATIC_DRAW ); glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), nullptr); + glVertexAttribPointer(0, 3, GL_DOUBLE, GL_FALSE, sizeof(Vertex), nullptr); // Major grid glBindVertexArray(_highlightVaoID); @@ -386,7 +387,7 @@ void RenderableGrid::update(const UpdateData&) { _highlightArray.data(), GL_STATIC_DRAW ); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), nullptr); + glVertexAttribPointer(0, 3, GL_DOUBLE, GL_FALSE, sizeof(Vertex), nullptr); glBindVertexArray(0); diff --git a/modules/base/rendering/grids/renderablegrid.h b/modules/base/rendering/grids/renderablegrid.h index 3ebfa0f589..afba0953d0 100644 --- a/modules/base/rendering/grids/renderablegrid.h +++ b/modules/base/rendering/grids/renderablegrid.h @@ -55,7 +55,7 @@ public: protected: struct Vertex { - float location[3]; + double location[3]; }; ghoul::opengl::ProgramObject* _gridProgram = nullptr; diff --git a/modules/base/shaders/grid_vs.glsl b/modules/base/shaders/grid_vs.glsl index e2528c3de4..027bc20032 100644 --- a/modules/base/shaders/grid_vs.glsl +++ b/modules/base/shaders/grid_vs.glsl @@ -37,11 +37,11 @@ void main() { dvec4 objPosDouble = dvec4(in_position, 1.0); dvec4 positionViewSpace = modelViewTransform * objPosDouble; dvec4 positionClipSpace = MVPTransform * objPosDouble; - + positionClipSpace.z = 0.0; - + vs_depthClipSpace = float(positionClipSpace.w); vs_positionViewSpace = vec4(positionViewSpace); - + gl_Position = vec4(positionClipSpace); } From 0d6f4ecac0f8dc7e8565408dfc00f58dc31ba4b7 Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 8 Sep 2022 10:08:39 +0200 Subject: [PATCH 57/79] Change name from SpeckLabels to LabelsComponent --- .../rendering/renderablebillboardscloud.cpp | 4 +-- .../rendering/renderablebillboardscloud.h | 4 +-- .../rendering/renderableplanescloud.cpp | 4 +-- .../rendering/renderableplanescloud.h | 4 +-- modules/space/CMakeLists.txt | 4 +-- .../{specklabels.cpp => labelscomponent.cpp} | 26 +++++++++---------- .../{specklabels.h => labelscomponent.h} | 12 ++++----- .../renderableconstellationsbase.cpp | 4 +-- .../rendering/renderableconstellationsbase.h | 4 +-- modules/space/spacemodule.cpp | 4 +-- 10 files changed, 35 insertions(+), 35 deletions(-) rename modules/space/{specklabels.cpp => labelscomponent.cpp} (91%) rename modules/space/{specklabels.h => labelscomponent.h} (91%) diff --git a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp index 437e5e3fc6..9c5557cc90 100644 --- a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp +++ b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp @@ -256,7 +256,7 @@ namespace { // [[codegen::verbatim(LabelsInfo.description)]] std::optional labels - [[codegen::reference("space_specklabels")]]; + [[codegen::reference("space_labelscomponent")]]; // [[codegen::verbatim(ColorOptionInfo.description)]] std::optional> colorOption; @@ -444,7 +444,7 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di _drawLabels = p.drawLabels.value_or(_drawLabels); addProperty(_drawLabels); - _labels = std::make_unique(*p.labels); + _labels = std::make_unique(*p.labels); _hasLabels = true; addPropertySubOwner(_labels.get()); } diff --git a/modules/digitaluniverse/rendering/renderablebillboardscloud.h b/modules/digitaluniverse/rendering/renderablebillboardscloud.h index c70cff455b..4625da4738 100644 --- a/modules/digitaluniverse/rendering/renderablebillboardscloud.h +++ b/modules/digitaluniverse/rendering/renderablebillboardscloud.h @@ -27,7 +27,7 @@ #include -#include +#include #include #include #include @@ -136,7 +136,7 @@ private: speck::ColorMap _colorMap; // Everything related to the labels are handles by speck::SpeckLabels - std::unique_ptr _labels = nullptr; + std::unique_ptr _labels = nullptr; std::vector _colorRangeData; std::unordered_map _optionConversionMap; diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.cpp b/modules/digitaluniverse/rendering/renderableplanescloud.cpp index 17922c46df..5f57993aec 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.cpp +++ b/modules/digitaluniverse/rendering/renderableplanescloud.cpp @@ -143,7 +143,7 @@ namespace { // [[codegen::verbatim(LabelsInfo.description)]] std::optional labels - [[codegen::reference("space_specklabels")]]; + [[codegen::reference("space_labelscomponent")]]; // [[codegen::verbatim(TransformationMatrixInfo.description)]] std::optional transformationMatrix; @@ -239,7 +239,7 @@ RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary _scaleFactor.onChange([&]() { _dataIsDirty = true; }); if (p.labels.has_value()) { - _labels = std::make_unique(*p.labels); + _labels = std::make_unique(*p.labels); _hasLabels = true; addPropertySubOwner(_labels.get()); } diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.h b/modules/digitaluniverse/rendering/renderableplanescloud.h index a931ef7fcd..45e6d6e5a4 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.h +++ b/modules/digitaluniverse/rendering/renderableplanescloud.h @@ -27,7 +27,7 @@ #include -#include +#include #include #include #include @@ -115,7 +115,7 @@ private: speck::Dataset _dataset; // Everything related to the labels are handles by speck::SpeckLabels - std::unique_ptr _labels = nullptr; + std::unique_ptr _labels = nullptr; float _sluminosity = 1.f; diff --git a/modules/space/CMakeLists.txt b/modules/space/CMakeLists.txt index 7c88d63ea9..73673fffd0 100644 --- a/modules/space/CMakeLists.txt +++ b/modules/space/CMakeLists.txt @@ -27,7 +27,7 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake) set(HEADER_FILES horizonsfile.h kepler.h - specklabels.h + labelscomponent.h speckloader.h rendering/renderableconstellationsbase.h rendering/renderableconstellationbounds.h @@ -50,7 +50,7 @@ set(SOURCE_FILES horizonsfile.cpp kepler.cpp spacemodule_lua.inl - specklabels.cpp + labelscomponent.cpp speckloader.cpp rendering/renderableconstellationsbase.cpp rendering/renderableconstellationbounds.cpp diff --git a/modules/space/specklabels.cpp b/modules/space/labelscomponent.cpp similarity index 91% rename from modules/space/specklabels.cpp rename to modules/space/labelscomponent.cpp index e6e8d06c60..d3316650d4 100644 --- a/modules/space/specklabels.cpp +++ b/modules/space/labelscomponent.cpp @@ -22,7 +22,7 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include +#include #include #include @@ -77,7 +77,7 @@ namespace { "Debug option for rendering of billboards and texts" }; - struct [[codegen::Dictionary(SpeckLabels)]] Parameters { + struct [[codegen::Dictionary(LabelsComponent)]] Parameters { // [[codegen::verbatim(FileInfo.description)]] std::filesystem::path file; @@ -104,16 +104,16 @@ namespace { }; std::optional unit; }; -#include "specklabels_codegen.cpp" +#include "labelscomponent_codegen.cpp" } // namespace namespace openspace::speck { -documentation::Documentation SpeckLabels::Documentation() { - return codegen::doc("space_specklabels"); +documentation::Documentation LabelsComponent::Documentation() { + return codegen::doc("space_labelscomponent"); } -SpeckLabels::SpeckLabels(const ghoul::Dictionary& dictionary) +LabelsComponent::LabelsComponent(const ghoul::Dictionary& dictionary) : properties::PropertyOwner({ "Labels" }) , _opacity(OpacityInfo, 1.f, 0.f, 1.f) , _color(ColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f)) @@ -164,15 +164,15 @@ SpeckLabels::SpeckLabels(const ghoul::Dictionary& dictionary) addProperty(_renderOption); } -speck::Labelset& SpeckLabels::labelSet() { +speck::Labelset& LabelsComponent::labelSet() { return _labelset; } -const speck::Labelset& SpeckLabels::labelSet() const { +const speck::Labelset& LabelsComponent::labelSet() const { return _labelset; } -void SpeckLabels::initialize() { +void LabelsComponent::initialize() { if (!_font) { constexpr int FontSize = 50; _font = global::fontManager->font( @@ -184,16 +184,16 @@ void SpeckLabels::initialize() { } } -void SpeckLabels::loadLabels() { - LINFOC("SpeckLabels", fmt::format("Loading Label file {}", _labelFile)); +void LabelsComponent::loadLabels() { + LINFOC("LabelsComponent", fmt::format("Loading Label file {}", _labelFile)); _labelset = speck::label::loadFileWithCache(_labelFile); } -bool SpeckLabels::isReady() const { +bool LabelsComponent::isReady() const { return !(_labelset.entries.empty()); } -void SpeckLabels::render(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix, +void LabelsComponent::render(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix, const glm::vec3& orthoRight, const glm::vec3& orthoUp, float fadeInVariable) { diff --git a/modules/space/specklabels.h b/modules/space/labelscomponent.h similarity index 91% rename from modules/space/specklabels.h rename to modules/space/labelscomponent.h index f59b9b806c..ed41c5c851 100644 --- a/modules/space/specklabels.h +++ b/modules/space/labelscomponent.h @@ -22,8 +22,8 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef __OPENSPACE_MODULE_SPACE___SPECKLABELS___H__ -#define __OPENSPACE_MODULE_SPACE___SPECKLABELS___H__ +#ifndef __OPENSPACE_MODULE_SPACE___LABELSCOMPONENT___H__ +#define __OPENSPACE_MODULE_SPACE___LABELSCOMPONENT___H__ #include @@ -45,10 +45,10 @@ namespace documentation { struct Documentation; } namespace speck { -class SpeckLabels : public properties::PropertyOwner { +class LabelsComponent : public properties::PropertyOwner { public: - explicit SpeckLabels(const ghoul::Dictionary& dictionary); - ~SpeckLabels() override = default; + explicit LabelsComponent(const ghoul::Dictionary& dictionary); + ~LabelsComponent() override = default; speck::Labelset& labelSet(); const speck::Labelset& labelSet() const; @@ -86,4 +86,4 @@ private: } // namespace openspace -#endif // __OPENSPACE_MODULE_SPACE___SPECKLABELS___H__ +#endif // __OPENSPACE_MODULE_SPACE___LABELSCOMPONENT___H__ diff --git a/modules/space/rendering/renderableconstellationsbase.cpp b/modules/space/rendering/renderableconstellationsbase.cpp index a715d17db3..0fea93bc6c 100644 --- a/modules/space/rendering/renderableconstellationsbase.cpp +++ b/modules/space/rendering/renderableconstellationsbase.cpp @@ -85,7 +85,7 @@ namespace { // [[codegen::verbatim(LabelsInfo.description)]] std::optional labels - [[codegen::reference("space_specklabels")]]; + [[codegen::reference("space_labelscomponent")]]; }; #include "renderableconstellationsbase_codegen.cpp" } // namespace @@ -122,7 +122,7 @@ RenderableConstellationsBase::RenderableConstellationsBase(const ghoul::Dictiona _drawLabels = p.drawLabels.value_or(_drawLabels); addProperty(_drawLabels); - _labels = std::make_unique(*p.labels); + _labels = std::make_unique(*p.labels); _hasLabels = true; addPropertySubOwner(_labels.get()); } diff --git a/modules/space/rendering/renderableconstellationsbase.h b/modules/space/rendering/renderableconstellationsbase.h index a000a3fd7b..67f24929f4 100644 --- a/modules/space/rendering/renderableconstellationsbase.h +++ b/modules/space/rendering/renderableconstellationsbase.h @@ -27,7 +27,7 @@ #include -#include +#include #include #include #include @@ -106,7 +106,7 @@ private: properties::StringProperty _namesFilename; // Everything related to the labels are handles by speck::SpeckLabels - std::unique_ptr _labels = nullptr; + std::unique_ptr _labels = nullptr; }; } // namespace openspace diff --git a/modules/space/spacemodule.cpp b/modules/space/spacemodule.cpp index 7cd75c0e56..62da19b9b8 100644 --- a/modules/space/spacemodule.cpp +++ b/modules/space/spacemodule.cpp @@ -24,6 +24,7 @@ #include +#include #include #include #include @@ -32,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -129,7 +129,7 @@ std::vector SpaceModule::documentations() const { RenderableTravelSpeed::Documentation(), SpiceRotation::Documentation(), SpiceTranslation::Documentation(), - speck::SpeckLabels::Documentation(), + speck::LabelsComponent::Documentation(), GPTranslation::Documentation() }; } From 91eb006d4e091b327d81f99c4008b472ece5fb4b Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 8 Sep 2022 11:28:12 +0200 Subject: [PATCH 58/79] Add labels to RenderableGrid class --- .../base/rendering/grids/renderablegrid.cpp | 73 +++++++++++++++++-- modules/base/rendering/grids/renderablegrid.h | 9 +++ .../rendering/renderableconstellationsbase.h | 2 +- 3 files changed, 78 insertions(+), 6 deletions(-) diff --git a/modules/base/rendering/grids/renderablegrid.cpp b/modules/base/rendering/grids/renderablegrid.cpp index eb472e597f..af89a932bd 100644 --- a/modules/base/rendering/grids/renderablegrid.cpp +++ b/modules/base/rendering/grids/renderablegrid.cpp @@ -61,6 +61,19 @@ namespace { "This value species the size of each dimensions of the grid" }; + constexpr openspace::properties::Property::PropertyInfo DrawLabelInfo = { + "DrawLabels", + "Draw Labels", + "Determines whether labels should be drawn or hidden" + }; + + static const openspace::properties::PropertyOwner::PropertyOwnerInfo LabelsInfo = + { + "Labels", + "Labels", + "The labels for the astronomical objects" + }; + struct [[codegen::Dictionary(RenderableGrid)]] Parameters { // [[codegen::verbatim(ColorInfo.description)]] std::optional color [[codegen::color()]]; @@ -73,6 +86,13 @@ namespace { // [[codegen::verbatim(SizeInfo.description)]] std::optional size; + + // [[codegen::verbatim(DrawLabelInfo.description)]] + std::optional drawLabels; + + // [[codegen::verbatim(LabelsInfo.description)]] + std::optional labels + [[codegen::reference("space_labelscomponent")]]; }; #include "renderablegrid_codegen.cpp" } // namespace @@ -89,6 +109,7 @@ RenderableGrid::RenderableGrid(const ghoul::Dictionary& dictionary) , _segments(SegmentsInfo, glm::uvec2(10), glm::uvec2(1), glm::uvec2(200)) , _lineWidth(LineWidthInfo, 0.5f, 1.f, 20.f) , _size(SizeInfo, glm::vec2(1.f), glm::vec2(1.f), glm::vec2(1e11f)) + , _drawLabels(DrawLabelInfo, false) { const Parameters p = codegen::bake(dictionary); @@ -110,10 +131,31 @@ RenderableGrid::RenderableGrid(const ghoul::Dictionary& dictionary) _size = p.size.value_or(_size); _size.onChange([&]() { _gridIsDirty = true; }); addProperty(_size); + + if (p.labels.has_value()) { + _drawLabels = p.drawLabels.value_or(_drawLabels); + addProperty(_drawLabels); + + _labels = std::make_unique(*p.labels); + _hasLabels = true; + addPropertySubOwner(_labels.get()); + } } bool RenderableGrid::isReady() const { - return _gridProgram != nullptr; + bool isReady = _gridProgram != nullptr; + + if (_hasLabels) { + isReady = isReady && _labels->isReady(); + } + return isReady; +} + +void RenderableGrid::initialize() { + if (_hasLabels) { + _labels->initialize(); + _labels->loadLabels(); + } } void RenderableGrid::initializeGL() { @@ -162,12 +204,13 @@ void RenderableGrid::render(const RenderData& data, RendererTasks&){ glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)); glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform; + glm::mat4 projectionMatrix = data.camera.projectionMatrix(); + + glm::dmat4 modelViewProjectionMatrix = + glm::dmat4(projectionMatrix) * modelViewTransform; _gridProgram->setUniform("modelViewTransform", modelViewTransform); - _gridProgram->setUniform( - "MVPTransform", - glm::dmat4(data.camera.projectionMatrix()) * modelViewTransform - ); + _gridProgram->setUniform("MVPTransform", modelViewProjectionMatrix); _gridProgram->setUniform("opacity", opacity()); _gridProgram->setUniform("gridColor", _color); @@ -192,6 +235,26 @@ void RenderableGrid::render(const RenderData& data, RendererTasks&){ global::renderEngine->openglStateCache().resetBlendState(); global::renderEngine->openglStateCache().resetLineState(); global::renderEngine->openglStateCache().resetDepthState(); + + // Draw labels + if (_drawLabels && _hasLabels) { + glm::dvec3 cameraViewDirectionWorld = -data.camera.viewDirectionWorldSpace(); + glm::dvec3 cameraUpDirectionWorld = data.camera.lookUpVectorWorldSpace(); + glm::dvec3 orthoRight = glm::normalize( + glm::cross(cameraUpDirectionWorld, cameraViewDirectionWorld) + ); + if (orthoRight == glm::dvec3(0.0)) { + glm::dvec3 otherVector( + cameraUpDirectionWorld.y, + cameraUpDirectionWorld.x, + cameraUpDirectionWorld.z + ); + orthoRight = glm::normalize(glm::cross(otherVector, cameraViewDirectionWorld)); + } + glm::dvec3 orthoUp = glm::normalize(glm::cross(cameraViewDirectionWorld, orthoRight)); + + _labels->render(data, modelViewProjectionMatrix, orthoRight, orthoUp); + } } void RenderableGrid::update(const UpdateData&) { diff --git a/modules/base/rendering/grids/renderablegrid.h b/modules/base/rendering/grids/renderablegrid.h index 4b9c71701e..7ba50aea88 100644 --- a/modules/base/rendering/grids/renderablegrid.h +++ b/modules/base/rendering/grids/renderablegrid.h @@ -27,6 +27,7 @@ #include +#include #include #include #include @@ -43,6 +44,7 @@ class RenderableGrid : public Renderable { public: RenderableGrid(const ghoul::Dictionary& dictionary); + void initialize() override; void initializeGL() override; void deinitializeGL() override; @@ -74,6 +76,13 @@ protected: GLenum _mode = GL_LINES; std::vector _varray; + + // Labels + bool _hasLabels = false; + properties::BoolProperty _drawLabels; + + // Everything related to the labels are handles by speck::LabelsComponent + std::unique_ptr _labels = nullptr; }; }// namespace openspace diff --git a/modules/space/rendering/renderableconstellationsbase.h b/modules/space/rendering/renderableconstellationsbase.h index 67f24929f4..74d92709a5 100644 --- a/modules/space/rendering/renderableconstellationsbase.h +++ b/modules/space/rendering/renderableconstellationsbase.h @@ -105,7 +105,7 @@ private: // The file containing constellation names and abbreviations properties::StringProperty _namesFilename; - // Everything related to the labels are handles by speck::SpeckLabels + // Everything related to the labels are handles by speck::LabelsComponent std::unique_ptr _labels = nullptr; }; From 4415e840a8b2f4c035223f5219fd15f62e994979 Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 8 Sep 2022 14:54:15 +0200 Subject: [PATCH 59/79] Use new label class for the new grids --- data/assets/scene/digitaluniverse/grids.asset | 119 ++++++++++++++++-- .../base/rendering/grids/renderablegrid.cpp | 47 +++---- modules/space/labelscomponent.cpp | 4 +- 3 files changed, 134 insertions(+), 36 deletions(-) diff --git a/data/assets/scene/digitaluniverse/grids.asset b/data/assets/scene/digitaluniverse/grids.asset index 813553eb1d..dccad41868 100644 --- a/data/assets/scene/digitaluniverse/grids.asset +++ b/data/assets/scene/digitaluniverse/grids.asset @@ -110,14 +110,17 @@ local eclipticLabels = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = speck .. "eclip.label", + Color = { 0.5, 0.5, 0.5 }, + Size = 14.75, + MinMaxSize = { 1, 50 }, + Unit = "pc" + }, Color = { 1.0, 1.0, 1.0 }, Opacity = 0.65, - LabelFile = speck .. "eclip.label", Unit = "pc", DrawLabels = true, - TextColor = { 0.5, 0.5, 0.5 }, - TextSize = 14.75, - TextMinMaxSize = { 1, 50 }, TransformationMatrix = { -0.05487554, 0.4941095, -0.8676661, 0.0, -0.9938214 , -0.1109906, -0.0003515167, 0.0, @@ -163,14 +166,17 @@ local equatorialLabels = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = speck .. "radec.label", + Color = { 0.5, 0.5, 0.5 }, + Size = 14.5, + MinMaxSize = { 2, 70 }, + Unit = "pc" + }, Color = { 1.0, 1.0, 1.0 }, Opacity = 0.65, - LabelFile = speck .. "radec.label", Unit = "pc", DrawLabels = true, - TextColor = { 0.5, 0.5, 0.5 }, - TextSize = 14.5, - TextMinMaxSize = { 2, 70 }, TransformationMatrix = { -0.05487554, 0.4941095, -0.8676661, 0.0, -0.8734371 , -0.4448296, -0.1980764, 0.0, @@ -212,14 +218,17 @@ local galacticLabels = { Renderable = { Type = "RenderableBillboardsCloud", Enabled = false, + Labels = { + File = speck .. "galac.label", + Color = { 0.5, 0.5, 0.5 }, + Size = 15.8, + MinMaxSize = { 1, 100 }, + Unit = "pc" + }, Color = { 1.0, 1.0, 1.0 }, Opacity = 0.65, - LabelFile = speck .. "galac.label", Unit = "pc", - DrawLabels = true, - TextColor = { 0.5, 0.5, 0.5 }, - TextSize = 15.8, - TextMinMaxSize = { 1, 100 } + DrawLabels = true }, GUI = { Name = "Galactic Sphere Labels", @@ -239,6 +248,13 @@ local plane1ld = { Renderable = { Type = "RenderableGrid", Enabled = false, + Labels = { + File = speck .. "1ld.label", + Color = { 0.0, 0.2, 0.5 }, + Size = 10.3, + MinMaxSize = { 0, 30 }, + Unit = "Km" + }, Opacity = 0.4, Color = { 0.1, 0.5, 0.6 }, LineWidth = 2.0, @@ -263,6 +279,13 @@ local plane1lm = { Renderable = { Type = "RenderableGrid", Enabled = false, + Labels = { + File = speck .. "1lm.label", + Color = { 0.0, 0.2, 0.5 }, + Size = 11.8, + MinMaxSize = { 0, 30 }, + Unit = "pc" + }, Opacity = 0.4, Color = { 0.1, 0.5, 0.6 }, LineWidth = 2.0, @@ -287,6 +310,13 @@ local plane1ly = { Renderable = { Type = "RenderableGrid", Enabled = false, + Labels = { + File = speck .. "1ly.label", + Color = { 0.0, 0.2, 0.5 }, + Size = 13.0, + MinMaxSize = { 0, 30 }, + Unit = "pc" + }, Opacity = 0.4, Color = { 0.1, 0.5, 0.6 }, LineWidth = 2.0, @@ -311,6 +341,13 @@ local plane10ly = { Renderable = { Type = "RenderableGrid", Enabled = false, + Labels = { + File = speck .. "10ly.label", + Color = { 0.0, 0.2, 0.5 }, + Size = 14.17, + MinMaxSize = { 0, 30 }, + Unit = "pc" + }, Opacity = 0.4, Color = { 0.1, 0.5, 0.6 }, LineWidth = 2.0, @@ -335,6 +372,13 @@ local plane100ly = { Renderable = { Type = "RenderableGrid", Enabled = false, + Labels = { + File = speck .. "100ly.label", + Color = { 0.0, 0.2, 0.5 }, + Size = 15.0, + MinMaxSize = { 0, 30 }, + Unit = "pc" + }, Opacity = 0.4, Color = { 0.1, 0.5, 0.6 }, LineWidth = 2.0, @@ -359,6 +403,13 @@ local plane1kly = { Renderable = { Type = "RenderableGrid", Enabled = false, + Labels = { + File = speck .. "1kly.label", + Color = { 0.0, 0.2, 0.5 }, + Size = 16.0, + MinMaxSize = { 0, 30 }, + Unit = "pc" + }, Opacity = 0.4, Color = { 0.1, 0.5, 0.6 }, LineWidth = 2.0, @@ -383,6 +434,13 @@ local plane10kly = { Renderable = { Type = "RenderableGrid", Enabled = false, + Labels = { + File = speck .. "10kly.label", + Color = { 0.0, 0.2, 0.5 }, + Size = 17.25, + MinMaxSize = { 0, 30 }, + Unit = "pc" + }, Opacity = 0.4, Color = { 0.1, 0.5, 0.6 }, LineWidth = 2.0, @@ -400,6 +458,13 @@ local plane100kly = { Renderable = { Type = "RenderableGrid", Enabled = false, + Labels = { + File = speck .. "100kly.label", + Color = { 0.0, 0.2, 0.5 }, + Size = 18.6, + MinMaxSize = { 0, 30 }, + Unit = "Mpc" + }, Opacity = 0.4, Color = { 0.1, 0.5, 0.6 }, HighlightColor = { 0.3, 0.7, 0.8 }, @@ -419,6 +484,13 @@ local plane1Mly = { Renderable = { Type = "RenderableGrid", Enabled = false, + Labels = { + File = speck .. "1Mly.label", + Color = { 0.0, 0.2, 0.5 }, + Size = 19.6, + MinMaxSize = { 0, 30 }, + Unit = "Mpc" + }, Opacity = 0.4, Color = { 0.1, 0.5, 0.6 }, HighlightColor = { 0.3, 0.7, 0.8 }, @@ -438,6 +510,13 @@ local plane10Mly = { Renderable = { Type = "RenderableGrid", Enabled = false, + Labels = { + File = speck .. "10Mly.label", + Color = { 0.0, 0.2, 0.5 }, + Size = 20.6, + MinMaxSize = { 0, 30 }, + Unit = "Mpc" + }, Opacity = 0.4, Color = { 0.1, 0.5, 0.6 }, HighlightColor = { 0.3, 0.7, 0.8 }, @@ -457,6 +536,13 @@ local plane100Mly = { Renderable = { Type = "RenderableGrid", Enabled = false, + Labels = { + File = speck .. "100Mly.label", + Color = { 0.0, 0.2, 0.5 }, + Size = 21.6, + MinMaxSize = { 0, 30 }, + Unit = "Mpc" + }, Opacity = 0.4, Color = { 0.1, 0.5, 0.6 }, HighlightColor = { 0.3, 0.7, 0.8 }, @@ -476,6 +562,13 @@ local plane20Gly = { Renderable = { Type = "RenderableGrid", Enabled = false, + Labels = { + File = speck .. "20Gly.label", + Color = { 0.0, 0.2, 0.5 }, + Size = 23.6, + MinMaxSize = { 0, 30 }, + Unit = "Mpc" + }, Opacity = 0.4, Color = { 0.1, 0.5, 0.6 }, HighlightColor = { 0.3, 0.7, 0.8 }, diff --git a/modules/base/rendering/grids/renderablegrid.cpp b/modules/base/rendering/grids/renderablegrid.cpp index 21ea9830ce..c475c702f9 100644 --- a/modules/base/rendering/grids/renderablegrid.cpp +++ b/modules/base/rendering/grids/renderablegrid.cpp @@ -252,16 +252,33 @@ void RenderableGrid::deinitializeGL() { void RenderableGrid::render(const RenderData& data, RendererTasks&){ _gridProgram->activate(); - glm::dmat4 modelTransform = + const glm::dmat4 modelMatrix = glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation glm::dmat4(data.modelTransform.rotation) * // Spice rotation - glm::scale(glm::dmat4(1.0), data.modelTransform.scale); + glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)); - glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform; - glm::mat4 projectionMatrix = data.camera.projectionMatrix(); + const glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelMatrix; + const glm::dmat4 projectionMatrix = data.camera.projectionMatrix(); - glm::dmat4 modelViewProjectionMatrix = - glm::dmat4(projectionMatrix) * modelViewTransform; + const glm::dmat4 modelViewProjectionMatrix = projectionMatrix * modelViewTransform; + + const glm::vec3 lookup = data.camera.lookUpVectorWorldSpace(); + const glm::vec3 viewDirection = data.camera.viewDirectionWorldSpace(); + glm::vec3 right = glm::cross(viewDirection, lookup); + const glm::vec3 up = glm::cross(right, viewDirection); + + const glm::dmat4 worldToModelTransform = glm::inverse(modelMatrix); + glm::vec3 orthoRight = glm::normalize( + glm::vec3(worldToModelTransform * glm::vec4(right, 0.0)) + ); + + if (orthoRight == glm::vec3(0.0)) { + glm::vec3 otherVector(lookup.y, lookup.x, lookup.z); + right = glm::cross(viewDirection, otherVector); + orthoRight = glm::normalize( + glm::vec3(worldToModelTransform * glm::vec4(right, 0.0)) + ); + } _gridProgram->setUniform("modelViewTransform", modelViewTransform); _gridProgram->setUniform("MVPTransform", modelViewProjectionMatrix); @@ -303,22 +320,10 @@ void RenderableGrid::render(const RenderData& data, RendererTasks&){ // Draw labels if (_drawLabels && _hasLabels) { - glm::dvec3 cameraViewDirectionWorld = -data.camera.viewDirectionWorldSpace(); - glm::dvec3 cameraUpDirectionWorld = data.camera.lookUpVectorWorldSpace(); - glm::dvec3 orthoRight = glm::normalize( - glm::cross(cameraUpDirectionWorld, cameraViewDirectionWorld) + const glm::vec3 orthoUp = glm::normalize( + glm::vec3(worldToModelTransform * glm::dvec4(up, 0.0)) ); - if (orthoRight == glm::dvec3(0.0)) { - glm::dvec3 otherVector( - cameraUpDirectionWorld.y, - cameraUpDirectionWorld.x, - cameraUpDirectionWorld.z - ); - orthoRight = glm::normalize(glm::cross(otherVector, cameraViewDirectionWorld)); - } - glm::dvec3 orthoUp = glm::normalize(glm::cross(cameraViewDirectionWorld, orthoRight)); - - _labels->render(data, modelViewProjectionMatrix, orthoRight, orthoUp); + _labels->render(data, modelViewProjectionMatrix, orthoRight, orthoUp); } } diff --git a/modules/space/labelscomponent.cpp b/modules/space/labelscomponent.cpp index d3316650d4..4a59d610e4 100644 --- a/modules/space/labelscomponent.cpp +++ b/modules/space/labelscomponent.cpp @@ -194,8 +194,8 @@ bool LabelsComponent::isReady() const { } void LabelsComponent::render(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix, - const glm::vec3& orthoRight, const glm::vec3& orthoUp, - float fadeInVariable) + const glm::vec3& orthoRight, const glm::vec3& orthoUp, + float fadeInVariable) { float scale = static_cast(toMeter(_unit)); From 9667db22c9f4c42bc9e44a3d3c51b76839cf9a9f Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 9 Sep 2022 10:27:17 +0200 Subject: [PATCH 60/79] Small fixes --- modules/base/rendering/grids/renderablegrid.cpp | 4 ++-- modules/base/rendering/grids/renderablegrid.h | 4 ++-- .../digitaluniverse/rendering/renderablebillboardscloud.cpp | 2 +- modules/digitaluniverse/rendering/renderablebillboardscloud.h | 4 ++-- modules/digitaluniverse/rendering/renderableplanescloud.cpp | 2 +- modules/digitaluniverse/rendering/renderableplanescloud.h | 4 ++-- modules/space/labelscomponent.cpp | 4 ++-- modules/space/labelscomponent.h | 4 ---- modules/space/rendering/renderableconstellationsbase.cpp | 4 ++-- modules/space/rendering/renderableconstellationsbase.h | 4 ++-- modules/space/spacemodule.cpp | 2 +- 11 files changed, 17 insertions(+), 21 deletions(-) diff --git a/modules/base/rendering/grids/renderablegrid.cpp b/modules/base/rendering/grids/renderablegrid.cpp index c475c702f9..0f4af9f5fe 100644 --- a/modules/base/rendering/grids/renderablegrid.cpp +++ b/modules/base/rendering/grids/renderablegrid.cpp @@ -91,7 +91,7 @@ namespace { { "Labels", "Labels", - "The labels for the astronomical objects" + "The labels for the grid" }; struct [[codegen::Dictionary(RenderableGrid)]] Parameters { @@ -181,7 +181,7 @@ RenderableGrid::RenderableGrid(const ghoul::Dictionary& dictionary) _drawLabels = p.drawLabels.value_or(_drawLabels); addProperty(_drawLabels); - _labels = std::make_unique(*p.labels); + _labels = std::make_unique(*p.labels); _hasLabels = true; addPropertySubOwner(_labels.get()); } diff --git a/modules/base/rendering/grids/renderablegrid.h b/modules/base/rendering/grids/renderablegrid.h index 61bc94c750..8d5db71ca1 100644 --- a/modules/base/rendering/grids/renderablegrid.h +++ b/modules/base/rendering/grids/renderablegrid.h @@ -87,8 +87,8 @@ protected: bool _hasLabels = false; properties::BoolProperty _drawLabels; - // Everything related to the labels are handles by speck::LabelsComponent - std::unique_ptr _labels = nullptr; + // Everything related to the labels are handled by LabelsComponent + std::unique_ptr _labels = nullptr; }; }// namespace openspace diff --git a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp index 9c5557cc90..c1ceb4040e 100644 --- a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp +++ b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp @@ -444,7 +444,7 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di _drawLabels = p.drawLabels.value_or(_drawLabels); addProperty(_drawLabels); - _labels = std::make_unique(*p.labels); + _labels = std::make_unique(*p.labels); _hasLabels = true; addPropertySubOwner(_labels.get()); } diff --git a/modules/digitaluniverse/rendering/renderablebillboardscloud.h b/modules/digitaluniverse/rendering/renderablebillboardscloud.h index 4625da4738..5ad76f1e5b 100644 --- a/modules/digitaluniverse/rendering/renderablebillboardscloud.h +++ b/modules/digitaluniverse/rendering/renderablebillboardscloud.h @@ -135,8 +135,8 @@ private: speck::Dataset _dataset; speck::ColorMap _colorMap; - // Everything related to the labels are handles by speck::SpeckLabels - std::unique_ptr _labels = nullptr; + // Everything related to the labels are handled by LabelsComponent + std::unique_ptr _labels = nullptr; std::vector _colorRangeData; std::unordered_map _optionConversionMap; diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.cpp b/modules/digitaluniverse/rendering/renderableplanescloud.cpp index 5f57993aec..29b0b7c388 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.cpp +++ b/modules/digitaluniverse/rendering/renderableplanescloud.cpp @@ -239,7 +239,7 @@ RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary _scaleFactor.onChange([&]() { _dataIsDirty = true; }); if (p.labels.has_value()) { - _labels = std::make_unique(*p.labels); + _labels = std::make_unique(*p.labels); _hasLabels = true; addPropertySubOwner(_labels.get()); } diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.h b/modules/digitaluniverse/rendering/renderableplanescloud.h index 45e6d6e5a4..66f7680033 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.h +++ b/modules/digitaluniverse/rendering/renderableplanescloud.h @@ -114,8 +114,8 @@ private: speck::Dataset _dataset; - // Everything related to the labels are handles by speck::SpeckLabels - std::unique_ptr _labels = nullptr; + // Everything related to the labels are handled by LabelsComponent + std::unique_ptr _labels = nullptr; float _sluminosity = 1.f; diff --git a/modules/space/labelscomponent.cpp b/modules/space/labelscomponent.cpp index 4a59d610e4..6151d232ad 100644 --- a/modules/space/labelscomponent.cpp +++ b/modules/space/labelscomponent.cpp @@ -107,7 +107,7 @@ namespace { #include "labelscomponent_codegen.cpp" } // namespace -namespace openspace::speck { +namespace openspace { documentation::Documentation LabelsComponent::Documentation() { return codegen::doc("space_labelscomponent"); @@ -227,4 +227,4 @@ void LabelsComponent::render(const RenderData& data, const glm::dmat4& modelView } } -} // namespace openspace::speck +} // namespace openspace diff --git a/modules/space/labelscomponent.h b/modules/space/labelscomponent.h index ed41c5c851..872ac8c263 100644 --- a/modules/space/labelscomponent.h +++ b/modules/space/labelscomponent.h @@ -43,8 +43,6 @@ namespace openspace { namespace documentation { struct Documentation; } -namespace speck { - class LabelsComponent : public properties::PropertyOwner { public: explicit LabelsComponent(const ghoul::Dictionary& dictionary); @@ -82,8 +80,6 @@ private: properties::OptionProperty _renderOption; }; -} // namespace speck - } // namespace openspace #endif // __OPENSPACE_MODULE_SPACE___LABELSCOMPONENT___H__ diff --git a/modules/space/rendering/renderableconstellationsbase.cpp b/modules/space/rendering/renderableconstellationsbase.cpp index 0fea93bc6c..cbd9298a4e 100644 --- a/modules/space/rendering/renderableconstellationsbase.cpp +++ b/modules/space/rendering/renderableconstellationsbase.cpp @@ -67,7 +67,7 @@ namespace { { "Labels", "Labels", - "The labels for the astronomical objects" + "The labels for the constellations" }; struct [[codegen::Dictionary(RenderableConstellationsBase)]] Parameters { @@ -122,7 +122,7 @@ RenderableConstellationsBase::RenderableConstellationsBase(const ghoul::Dictiona _drawLabels = p.drawLabels.value_or(_drawLabels); addProperty(_drawLabels); - _labels = std::make_unique(*p.labels); + _labels = std::make_unique(*p.labels); _hasLabels = true; addPropertySubOwner(_labels.get()); } diff --git a/modules/space/rendering/renderableconstellationsbase.h b/modules/space/rendering/renderableconstellationsbase.h index 74d92709a5..72dadb5b21 100644 --- a/modules/space/rendering/renderableconstellationsbase.h +++ b/modules/space/rendering/renderableconstellationsbase.h @@ -105,8 +105,8 @@ private: // The file containing constellation names and abbreviations properties::StringProperty _namesFilename; - // Everything related to the labels are handles by speck::LabelsComponent - std::unique_ptr _labels = nullptr; + // Everything related to the labels are handled by LabelsComponent + std::unique_ptr _labels = nullptr; }; } // namespace openspace diff --git a/modules/space/spacemodule.cpp b/modules/space/spacemodule.cpp index 62da19b9b8..72e479040d 100644 --- a/modules/space/spacemodule.cpp +++ b/modules/space/spacemodule.cpp @@ -129,7 +129,7 @@ std::vector SpaceModule::documentations() const { RenderableTravelSpeed::Documentation(), SpiceRotation::Documentation(), SpiceTranslation::Documentation(), - speck::LabelsComponent::Documentation(), + LabelsComponent::Documentation(), GPTranslation::Documentation() }; } From 877e0fb61f4d87c2f988049c071e0360c8867c32 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Fri, 9 Sep 2022 11:16:36 +0200 Subject: [PATCH 61/79] Replace tabs with spaces in Eiffeltower asset --- .../educational/scale/eiffeltower.asset | 123 +++++++++--------- 1 file changed, 62 insertions(+), 61 deletions(-) diff --git a/data/assets/educational/scale/eiffeltower.asset b/data/assets/educational/scale/eiffeltower.asset index dc91b4ed1d..226a41b6d5 100644 --- a/data/assets/educational/scale/eiffeltower.asset +++ b/data/assets/educational/scale/eiffeltower.asset @@ -2,76 +2,77 @@ local earthAsset = asset.require('scene/solarsystem/planets/earth/earth') local sunAsset = asset.require('scene/solarsystem/sun/sun') local modelFolder = asset.syncedResource({ - Name = "Eiffel Tower Model", - Type = "HttpSynchronization", - Identifier = "eiffel_tower_model", - Version = 1 + Name = "Eiffel Tower Model", + Type = "HttpSynchronization", + Identifier = "eiffel_tower_model", + Version = 1 }) - + local eiffelTower = { - Identifier = "eiffelTower", - Parent = earthAsset.Earth.Identifier, - --Note: Lat/Lon/Scale values comes from alignment with Esri World Imagery 2D layer - Transform = { - Translation = { - Type = "GlobeTranslation", - Globe = earthAsset.Earth.Identifier, - Longitude = 2.29448, - Latitude = 48.85824, - Altitude = 0.0, - UseHeightmap = true - }, - Rotation = { - Type = "GlobeRotation", - Globe = earthAsset.Earth.Identifier, - Longitude = 2.29448, - Latitude = 48.85824, - UseHeightmap = false - }, - Scale = { - Type = "StaticScale", - Scale = 4.38 - } - }, - Renderable = { - Type = "RenderableModel", - GeometryFile = modelFolder .. "eiffeltower.osmodel", - ModelScale = "Centimeter", - RotationVector = { 0.0, 45.0, 0.0 }, - LightSources = { sunAsset.LightSource } - }, - GUI = { - Name = "Eiffel Tower", - Path = "/Scale Objects" - } + Identifier = "eiffelTower", + Parent = earthAsset.Earth.Identifier, + --Note: Lat/Lon/Scale values comes from alignment with Esri World Imagery 2D layer + Transform = { + Translation = { + Type = "GlobeTranslation", + Globe = earthAsset.Earth.Identifier, + Longitude = 2.29448, + Latitude = 48.85824, + Altitude = 0.0, + UseHeightmap = true + }, + Rotation = { + Type = "GlobeRotation", + Globe = earthAsset.Earth.Identifier, + Longitude = 2.29448, + Latitude = 48.85824, + UseHeightmap = false + }, + Scale = { + Type = "StaticScale", + Scale = 4.38 + } + }, + Renderable = { + Type = "RenderableModel", + GeometryFile = modelFolder .. "eiffeltower.osmodel", + ModelScale = "Centimeter", + RotationVector = { 0.0, 45.0, 0.0 }, + LightSources = { sunAsset.LightSource } + }, + GUI = { + Name = "Eiffel Tower", + Path = "/Scale Objects" + } } local updatePositionAction = { - Identifier = "os.drop_eiffel_tower", - Name = "Drop Eiffel Tower under camera", - Command = [[local lat, lon, alt = openspace.globebrowsing.getGeoPositionForCamera(); - local camera = openspace.navigation.getNavigationState(); - openspace.setParent('eiffelTower', camera.Anchor) - openspace.setPropertyValueSingle('Scene.eiffelTower.Translation.Globe', camera.Anchor); - openspace.setPropertyValueSingle('Scene.eiffelTower.Translation.Latitude', lat); - openspace.setPropertyValueSingle('Scene.eiffelTower.Translation.Longitude', lon); - openspace.setPropertyValueSingle('Scene.eiffelTower.Rotation.Globe', camera.Anchor); - openspace.setPropertyValueSingle('Scene.eiffelTower.Rotation.Latitude', lat); - openspace.setPropertyValueSingle('Scene.eiffelTower.Rotation.Longitude', lon); - ]], - Documentation = "Updates the Eiffel Tower position based on the globe location of the camera", - GuiPath = "/Scale Objects", - IsLocal = false + Identifier = "os.drop_eiffel_tower", + Name = "Drop Eiffel Tower under camera", + Command = [[ + local lat, lon, alt = openspace.globebrowsing.getGeoPositionForCamera(); + local camera = openspace.navigation.getNavigationState(); + openspace.setParent('eiffelTower', camera.Anchor) + openspace.setPropertyValueSingle('Scene.eiffelTower.Translation.Globe', camera.Anchor); + openspace.setPropertyValueSingle('Scene.eiffelTower.Translation.Latitude', lat); + openspace.setPropertyValueSingle('Scene.eiffelTower.Translation.Longitude', lon); + openspace.setPropertyValueSingle('Scene.eiffelTower.Rotation.Globe', camera.Anchor); + openspace.setPropertyValueSingle('Scene.eiffelTower.Rotation.Latitude', lat); + openspace.setPropertyValueSingle('Scene.eiffelTower.Rotation.Longitude', lon); + ]], + Documentation = "Updates the Eiffel Tower position based on the globe location of the camera", + GuiPath = "/Scale Objects", + IsLocal = false } asset.onInitialize(function() - openspace.addSceneGraphNode(eiffelTower) - openspace.action.registerAction(updatePositionAction) + openspace.addSceneGraphNode(eiffelTower) + openspace.action.registerAction(updatePositionAction) end) - + asset.onDeinitialize(function() - openspace.action.removeAction(updatePositionAction) - openspace.removeSceneGraphNode(eiffelTower) + openspace.action.removeAction(updatePositionAction) + openspace.removeSceneGraphNode(eiffelTower) end) - + asset.export(eiffelTower) From ff89d7860c790afde193fcc49b419ba029d0dfaf Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Fri, 9 Sep 2022 11:34:56 +0200 Subject: [PATCH 62/79] Use Sun position instead of SSB in Sun light source (see #2223) --- data/assets/scene/solarsystem/sun/sun.asset | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data/assets/scene/solarsystem/sun/sun.asset b/data/assets/scene/solarsystem/sun/sun.asset index 2fe5742c43..93dda2e374 100644 --- a/data/assets/scene/solarsystem/sun/sun.asset +++ b/data/assets/scene/solarsystem/sun/sun.asset @@ -48,7 +48,7 @@ local SunLabel = { local LightSource = { Type = "SceneGraphLightSource", Identifier = "Sun", - Node = transforms.SolarSystemBarycenter.Identifier, + Node = Sun.Identifier, Intensity = 1.0 } @@ -56,12 +56,12 @@ asset.onInitialize(function() openspace.addSceneGraphNode(Sun) openspace.addSceneGraphNode(SunLabel) end) - + asset.onDeinitialize(function() openspace.removeSceneGraphNode(SunLabel) openspace.removeSceneGraphNode(Sun) end) - + asset.export(Sun) asset.export(SunLabel) asset.export("LightSource", LightSource) From acf45e858b6dc1df1c85e98d7b8b872f5d983c34 Mon Sep 17 00:00:00 2001 From: GPayne Date: Sun, 11 Sep 2022 19:42:56 -0600 Subject: [PATCH 63/79] Fixed file path bug with converting session recording version --- data/tasks/sessRecConvertVersion.task | 6 ++++++ .../openspace/interaction/sessionrecording.h | 11 ++++++++++- src/interaction/sessionrecording.cpp | 18 +++++------------- .../tasks/convertrecfileversiontask.cpp | 7 +------ 4 files changed, 22 insertions(+), 20 deletions(-) create mode 100644 data/tasks/sessRecConvertVersion.task diff --git a/data/tasks/sessRecConvertVersion.task b/data/tasks/sessRecConvertVersion.task new file mode 100644 index 0000000000..b854e5feac --- /dev/null +++ b/data/tasks/sessRecConvertVersion.task @@ -0,0 +1,6 @@ +return { + { + Type = "ConvertRecFileVersionTask", + InputFilePath = "../../user/recordings/input.osrec" + } +} diff --git a/include/openspace/interaction/sessionrecording.h b/include/openspace/interaction/sessionrecording.h index b1981a8e3a..b7bf00fb52 100644 --- a/include/openspace/interaction/sessionrecording.h +++ b/include/openspace/interaction/sessionrecording.h @@ -550,6 +550,16 @@ public: */ std::string convertFile(std::string filename, int depth = 0); + /** + * Converts file format of a session recording file to the current format version + * (will determine the file format conversion to convert from based on the file's + * header version number). Accepts a relative path (currently from task runner dir) + * rather than a path assumed to be relative to ${RECORDINGS}. + * + * \param filename name of the file to convert + */ + void convertFileRelativePath(std::string filenameRelative); + /** * Goes to legacy session recording inherited class, and calls its convertFile() * method, and then returns the resulting conversion filename. @@ -617,7 +627,6 @@ protected: bool handleRecordingFile(std::string filenameIn); static bool isPath(std::string& filename); void removeTrailingPathSlashes(std::string& filename); - void extractFilenameFromPath(std::string& filename); bool playbackCamera(); bool playbackTimeChange(); bool playbackScript(); diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index 0eadd4499e..cc9a375457 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -143,15 +143,6 @@ void SessionRecording::removeTrailingPathSlashes(std::string& filename) { } } -void SessionRecording::extractFilenameFromPath(std::string& filename) { - size_t unixDelimiter = filename.find_last_of("/"); - if (unixDelimiter != std::string::npos) - filename = filename.substr(unixDelimiter + 1); - size_t windowsDelimiter = filename.find_last_of("\\"); - if (windowsDelimiter != std::string::npos) - filename = filename.substr(windowsDelimiter + 1); -} - bool SessionRecording::handleRecordingFile(std::string filenameIn) { if (isPath(filenameIn)) { LERROR("Recording filename must not contain path (/) elements"); @@ -2303,6 +2294,10 @@ void SessionRecording::readFileIntoStringStream(std::string filename, inputFstream.close(); } +void SessionRecording::convertFileRelativePath(std::string filenameRelative) { + convertFile(absPath(filenameRelative).string()); +} + std::string SessionRecording::convertFile(std::string filename, int depth) { std::string conversionOutFilename = filename; std::ifstream conversionInFile; @@ -2331,9 +2326,6 @@ std::string SessionRecording::convertFile(std::string filename, int depth) { //conversionInStream.seekg(conversionInStream.beg); newFilename = getLegacyConversionResult(filename, depth + 1); removeTrailingPathSlashes(newFilename); - if (isPath(newFilename)) { - extractFilenameFromPath(newFilename); - } if (filename == newFilename) { return filename; } @@ -2572,7 +2564,7 @@ std::string SessionRecording::determineConversionOutFilename(const std::string f filenameSansExtension = filename.substr(0, filename.find_last_of(".")); } filenameSansExtension += "_" + fileFormatVersion() + "-" + targetFileFormatVersion(); - return absPath("${RECORDINGS}/" + filenameSansExtension + fileExtension).string(); + return filenameSansExtension + fileExtension; } bool SessionRecording_legacy_0085::convertScript(std::stringstream& inStream, diff --git a/src/interaction/tasks/convertrecfileversiontask.cpp b/src/interaction/tasks/convertrecfileversiontask.cpp index 1255d3ee0a..61f3e31c61 100644 --- a/src/interaction/tasks/convertrecfileversiontask.cpp +++ b/src/interaction/tasks/convertrecfileversiontask.cpp @@ -52,11 +52,6 @@ ConvertRecFileVersionTask::ConvertRecFileVersionTask(const ghoul::Dictionary& di _inFilename = dictionary.value(KeyInFilePath); _inFilePath = absPath(_inFilename); - std::string::size_type idx = _inFilename.find_last_of('/'); - if (idx != std::string::npos) { - _inFilename = _inFilename.substr(idx + 1); - } - ghoul_assert(std::filesystem::is_regular_file(_inFilePath), "The file must exist"); if (!std::filesystem::is_regular_file(_inFilePath)) { LERROR(fmt::format("Failed to load session recording file: {}", _inFilePath)); @@ -100,7 +95,7 @@ void ConvertRecFileVersionTask::convert() { )); return; } - sessRec->convertFile(_inFilename); + sessRec->convertFileRelativePath(_inFilename); } documentation::Documentation ConvertRecFileVersionTask::documentation() { From 31f859b5896af7e39814969951fea4dfc0889b97 Mon Sep 17 00:00:00 2001 From: Gene Payne Date: Sun, 11 Sep 2022 21:33:15 -0600 Subject: [PATCH 64/79] Fixed string_view conversion bug in TaskRunner --- apps/TaskRunner/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/TaskRunner/main.cpp b/apps/TaskRunner/main.cpp index 194b52e4de..663e27140d 100644 --- a/apps/TaskRunner/main.cpp +++ b/apps/TaskRunner/main.cpp @@ -113,7 +113,7 @@ int main(int argc, char** argv) { // Register the base path as the directory where the configuration file lives std::filesystem::path base = configFile.parent_path(); constexpr std::string_view BasePathToken = "${BASE}"; - FileSys.registerPathToken(BasePathToken, base); + FileSys.registerPathToken(BasePathToken.data(), base); // Using same configuration for size as in apps/OpenSpace/main.cpp glm::ivec2 size = glm::ivec2(1920, 1080); From 0ba064e14118ca5bb32ff393f61c9f2652f6f60c Mon Sep 17 00:00:00 2001 From: GPayne Date: Sun, 11 Sep 2022 21:42:46 -0600 Subject: [PATCH 65/79] Fix to account for possible empty string in session recording script --- src/interaction/sessionrecording.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index cc9a375457..365fd801f4 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -1615,7 +1615,7 @@ std::string SessionRecording::isolateTermFromQuotes(std::string s) { } //If no quotes found, remove other possible characters from end std::string unwantedChars = " );"; - while (unwantedChars.find(s.back()) != std::string::npos) { + while (!s.empty() && (unwantedChars.find(s.back()) != std::string::npos)) { s.pop_back(); } return s; From dbb973b0ec48fad056dfca1534a7dd0618af6b02 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Tue, 13 Sep 2022 10:53:30 +0200 Subject: [PATCH 66/79] Update GUI hash * Geo Location panel * Dependency updates * Getting started tour + some other changes/improvements --- data/assets/util/webgui.asset | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/assets/util/webgui.asset b/data/assets/util/webgui.asset index 440e8f6e93..046e87c494 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 = "aeffda7eef46f4eaddfebcb41389672d2c473b35" +local frontendHash = "9f0298993d738f487c93c559084593945b5e093e" local dataProvider = "data.openspaceproject.com/files/webgui" local frontend = asset.syncedResource({ From 7946a93ee593f47c55db8b3a6c112208c16b33c3 Mon Sep 17 00:00:00 2001 From: Gene Payne Date: Tue, 13 Sep 2022 16:10:03 -0600 Subject: [PATCH 67/79] Fix for linux crashing when reading OMM files Linux doesn't use the '\r' line ending, so it doesn't recognize a line with only '\r' as being empty. --- modules/space/kepler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/space/kepler.cpp b/modules/space/kepler.cpp index 32b2c67769..08a75b267b 100644 --- a/modules/space/kepler.cpp +++ b/modules/space/kepler.cpp @@ -499,7 +499,7 @@ std::vector readOmmFile(std::filesystem::path file) { std::optional current = std::nullopt; std::string line; while (std::getline(f, line)) { - if (line.empty()) { + if (line.empty() || line == "\r") { continue; } From 533b1965c76ac5ee43c8385abe0e1c94b39a1858 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 14 Sep 2022 11:18:39 +0200 Subject: [PATCH 68/79] Enable depth test for the grids --- modules/base/rendering/grids/renderablegrid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/base/rendering/grids/renderablegrid.cpp b/modules/base/rendering/grids/renderablegrid.cpp index 0f4af9f5fe..a2b85d7567 100644 --- a/modules/base/rendering/grids/renderablegrid.cpp +++ b/modules/base/rendering/grids/renderablegrid.cpp @@ -294,7 +294,7 @@ void RenderableGrid::render(const RenderData& data, RendererTasks&){ glEnablei(GL_BLEND, 0); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_LINE_SMOOTH); - glDepthMask(false); + glEnable(GL_DEPTH_TEST); // Render minor grid glBindVertexArray(_vaoID); From dcdfbf028fb21e9bc704c5410736e32f5dd5cec9 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 14 Sep 2022 13:25:45 +0200 Subject: [PATCH 69/79] Add font size and face camera property --- modules/space/labelscomponent.cpp | 74 +++++++++++++++++++++---------- modules/space/labelscomponent.h | 7 ++- 2 files changed, 53 insertions(+), 28 deletions(-) diff --git a/modules/space/labelscomponent.cpp b/modules/space/labelscomponent.cpp index 6151d232ad..56a31db433 100644 --- a/modules/space/labelscomponent.cpp +++ b/modules/space/labelscomponent.cpp @@ -34,7 +34,7 @@ #include namespace { - constexpr int RenderOptionViewDirection = 0; + constexpr int RenderOptionFaceCamera = 0; constexpr int RenderOptionPositionNormal = 1; constexpr openspace::properties::Property::PropertyInfo FileInfo = { @@ -55,26 +55,37 @@ namespace { "Determines the transparency of the labels, where 1 is completely opaque " "and 0 fully transparent" }; + constexpr openspace::properties::Property::PropertyInfo ColorInfo = { "Color", "Color", "The color of the labels" }; + constexpr openspace::properties::Property::PropertyInfo SizeInfo = { "Size", "Size", "The size of the labels in pixels" }; + + constexpr openspace::properties::Property::PropertyInfo FontSizeInfo = { + "FontSize", + "Font Size", + "Font size for the labels. This is different from the text size" + }; + constexpr openspace::properties::Property::PropertyInfo MinMaxInfo = { "MinMaxSize", "Min/Max Size", "The minimum and maximum size (in pixels) of the labels" }; - constexpr openspace::properties::Property::PropertyInfo RenderOptionInfo = { - "RenderOption", - "Render Option", - "Debug option for rendering of billboards and texts" + constexpr openspace::properties::Property::PropertyInfo FaceCameraInfo = { + "FaceCamera", + "Face Camera", + "If enabled, the labels will be rotated to face the camera. " + "For non-linear display rendering (for example fisheye) this should be set to " + "false." }; struct [[codegen::Dictionary(LabelsComponent)]] Parameters { @@ -90,6 +101,9 @@ namespace { // [[codegen::verbatim(SizeInfo.description)]] std::optional size; + // [[codegen::verbatim(FontSizeInfo.description)]] + std::optional fontSize; + // [[codegen::verbatim(MinMaxInfo.description)]] std::optional minMaxSize; @@ -103,6 +117,9 @@ namespace { Gigalightyear [[codegen::key("Gly")]] }; std::optional unit; + + // [[codegen::verbatim(FaceCameraInfo.description)]] + std::optional faceCamera; }; #include "labelscomponent_codegen.cpp" } // namespace @@ -118,13 +135,14 @@ LabelsComponent::LabelsComponent(const ghoul::Dictionary& dictionary) , _opacity(OpacityInfo, 1.f, 0.f, 1.f) , _color(ColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f)) , _size(SizeInfo, 8.f, 0.5f, 24.f) + , _fontSize(FontSizeInfo, 50.f, 1.f, 300.f) , _minMaxSize( MinMaxInfo, glm::ivec2(8, 500), glm::ivec2(0), glm::ivec2(1000) ) - , _renderOption(RenderOptionInfo, properties::OptionProperty::DisplayType::Dropdown) + , _faceCamera(FaceCameraInfo, true) { const Parameters p = codegen::bake(dictionary); @@ -147,21 +165,30 @@ LabelsComponent::LabelsComponent(const ghoul::Dictionary& dictionary) _size = p.size.value_or(_size); addProperty(_size); + _fontSize = p.fontSize.value_or(_fontSize); + _fontSize.onChange([this]() { initialize(); }); + addProperty(_fontSize); + // @TODO (emmbr, 2021-05-31): Temporarily set as read only, to avoid errors from font + // rendering (avoid filling font atlas) + _fontSize.setReadOnly(true); + _minMaxSize = p.minMaxSize.value_or(_minMaxSize); _minMaxSize.setViewOption(properties::Property::ViewOptions::MinMaxRange); addProperty(_minMaxSize); - _renderOption.addOption(RenderOptionViewDirection, "Camera View Direction"); - _renderOption.addOption(RenderOptionPositionNormal, "Camera Position Normal"); - // @TODO (abock. 2021-01-31) In the other DU classes, this is done with an enum, and - // doing it based on the fisheye rendering seems a bit brittle? - if (global::windowDelegate->isFisheyeRendering()) { - _renderOption = RenderOptionPositionNormal; + if (p.faceCamera.has_value()) { + _faceCamera = *p.faceCamera; } else { - _renderOption = RenderOptionViewDirection; + // @TODO (abock. 2021-01-31) In the other DU classes, this is done with an enum, and + // doing it based on the fisheye rendering seems a bit brittle? + + // (malej 2022-SEP-14) + // For non-linear display rendering (for example fisheye) _faceCamera should be false, + // otherwise true. + _faceCamera = !global::windowDelegate->isFisheyeRendering(); } - addProperty(_renderOption); + addProperty(_faceCamera); } speck::Labelset& LabelsComponent::labelSet() { @@ -173,15 +200,12 @@ const speck::Labelset& LabelsComponent::labelSet() const { } void LabelsComponent::initialize() { - if (!_font) { - constexpr int FontSize = 50; - _font = global::fontManager->font( - "Mono", - static_cast(FontSize), - ghoul::fontrendering::FontManager::Outline::Yes, - ghoul::fontrendering::FontManager::LoadGlyphs::No - ); - } + _font = global::fontManager->font( + "Mono", + _fontSize, + ghoul::fontrendering::FontManager::Outline::Yes, + ghoul::fontrendering::FontManager::LoadGlyphs::No + ); } void LabelsComponent::loadLabels() { @@ -199,6 +223,8 @@ void LabelsComponent::render(const RenderData& data, const glm::dmat4& modelView { float scale = static_cast(toMeter(_unit)); + int renderOption = _faceCamera ? RenderOptionFaceCamera : RenderOptionPositionNormal; + ghoul::fontrendering::FontRenderer::ProjectedLabelsInformation labelInfo; labelInfo.orthoRight = orthoRight; labelInfo.orthoUp = orthoUp; @@ -206,7 +232,7 @@ void LabelsComponent::render(const RenderData& data, const glm::dmat4& modelView labelInfo.maxSize = _minMaxSize.value().y; labelInfo.cameraPos = data.camera.positionVec3(); labelInfo.cameraLookUp = data.camera.lookUpVectorWorldSpace(); - labelInfo.renderType = _renderOption; + labelInfo.renderType = renderOption; labelInfo.mvpMatrix = modelViewProjectionMatrix; labelInfo.scale = pow(10.f, _size); labelInfo.enableDepth = true; diff --git a/modules/space/labelscomponent.h b/modules/space/labelscomponent.h index 872ac8c263..c63ac7e458 100644 --- a/modules/space/labelscomponent.h +++ b/modules/space/labelscomponent.h @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include #include @@ -74,10 +74,9 @@ private: properties::FloatProperty _opacity; properties::Vec3Property _color; properties::FloatProperty _size; + properties::FloatProperty _fontSize; properties::IVec2Property _minMaxSize; - - // DEBUG: - properties::OptionProperty _renderOption; + properties::BoolProperty _faceCamera; }; } // namespace openspace From 57dc7dd6b84ea1f3eb86ee5e7cbc18e76ccbd9b6 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Fri, 16 Sep 2022 08:18:47 +0200 Subject: [PATCH 70/79] Add some missing includes --- modules/exoplanets/exoplanetsmodule_lua.inl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index bb1fde8d1a..61e9604eed 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -22,6 +22,10 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ +#include +#include +#include + namespace { constexpr std::string_view _loggerCat = "ExoplanetsModule"; From e215e9f2a759c920ed2e26f7c24b8973d2e73c2d Mon Sep 17 00:00:00 2001 From: Malin E Date: Mon, 19 Sep 2022 12:07:59 +0200 Subject: [PATCH 71/79] Add labels to the other grid classes too --- .../rendering/grids/renderableboxgrid.cpp | 77 +++++++++++++++-- .../base/rendering/grids/renderableboxgrid.h | 7 ++ .../rendering/grids/renderableradialgrid.cpp | 81 ++++++++++++++++-- .../rendering/grids/renderableradialgrid.h | 7 ++ .../grids/renderablesphericalgrid.cpp | 83 +++++++++++++++++-- .../rendering/grids/renderablesphericalgrid.h | 7 ++ 6 files changed, 241 insertions(+), 21 deletions(-) diff --git a/modules/base/rendering/grids/renderableboxgrid.cpp b/modules/base/rendering/grids/renderableboxgrid.cpp index 35a173e45e..38482d98d8 100644 --- a/modules/base/rendering/grids/renderableboxgrid.cpp +++ b/modules/base/rendering/grids/renderableboxgrid.cpp @@ -54,6 +54,19 @@ namespace { "This value species the size of each dimensions of the box" }; + constexpr openspace::properties::Property::PropertyInfo DrawLabelInfo = { + "DrawLabels", + "Draw Labels", + "Determines whether labels should be drawn or hidden" + }; + + static const openspace::properties::PropertyOwner::PropertyOwnerInfo LabelsInfo = + { + "Labels", + "Labels", + "The labels for the grid" + }; + struct [[codegen::Dictionary(RenderableBoxGrid)]] Parameters { // [[codegen::verbatim(ColorInfo.description)]] std::optional color [[codegen::color()]]; @@ -63,6 +76,13 @@ namespace { // [[codegen::verbatim(SizeInfo.description)]] std::optional size; + + // [[codegen::verbatim(DrawLabelInfo.description)]] + std::optional drawLabels; + + // [[codegen::verbatim(LabelsInfo.description)]] + std::optional labels + [[codegen::reference("space_labelscomponent")]]; }; #include "renderableboxgrid_codegen.cpp" } // namespace @@ -78,6 +98,7 @@ RenderableBoxGrid::RenderableBoxGrid(const ghoul::Dictionary& dictionary) , _color(ColorInfo, glm::vec3(0.5f), glm::vec3(0.f), glm::vec3(1.f)) , _lineWidth(LineWidthInfo, 0.5f, 1.f, 20.f) , _size(SizeInfo, glm::vec3(1.f), glm::vec3(1.f), glm::vec3(100.f)) + , _drawLabels(DrawLabelInfo, false) { const Parameters p = codegen::bake(dictionary); @@ -94,10 +115,31 @@ RenderableBoxGrid::RenderableBoxGrid(const ghoul::Dictionary& dictionary) _size = p.size.value_or(_size); _size.onChange([&]() { _gridIsDirty = true; }); addProperty(_size); + + if (p.labels.has_value()) { + _drawLabels = p.drawLabels.value_or(_drawLabels); + addProperty(_drawLabels); + + _labels = std::make_unique(*p.labels); + _hasLabels = true; + addPropertySubOwner(_labels.get()); + } } bool RenderableBoxGrid::isReady() const { - return _gridProgram != nullptr; + bool isReady = _gridProgram != nullptr; + + if (_hasLabels) { + isReady = isReady && _labels->isReady(); + } + return isReady; +} + +void RenderableBoxGrid::initialize() { + if (_hasLabels) { + _labels->initialize(); + _labels->loadLabels(); + } } void RenderableBoxGrid::initializeGL() { @@ -146,12 +188,12 @@ void RenderableBoxGrid::render(const RenderData& data, RendererTasks&){ glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)); glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform; + const glm::dmat4 projectionMatrix = data.camera.projectionMatrix(); + + const glm::dmat4 modelViewProjectionMatrix = projectionMatrix * modelViewTransform; _gridProgram->setUniform("modelViewTransform", modelViewTransform); - _gridProgram->setUniform( - "MVPTransform", - glm::dmat4(data.camera.projectionMatrix()) * modelViewTransform - ); + _gridProgram->setUniform("MVPTransform", modelViewProjectionMatrix); _gridProgram->setUniform("opacity", opacity()); _gridProgram->setUniform("gridColor", _color); @@ -176,6 +218,31 @@ void RenderableBoxGrid::render(const RenderData& data, RendererTasks&){ global::renderEngine->openglStateCache().resetBlendState(); global::renderEngine->openglStateCache().resetLineState(); global::renderEngine->openglStateCache().resetDepthState(); + + // Draw labels + if (_drawLabels && _hasLabels) { + const glm::vec3 lookup = data.camera.lookUpVectorWorldSpace(); + const glm::vec3 viewDirection = data.camera.viewDirectionWorldSpace(); + glm::vec3 right = glm::cross(viewDirection, lookup); + const glm::vec3 up = glm::cross(right, viewDirection); + + const glm::dmat4 worldToModelTransform = glm::inverse(modelTransform); + glm::vec3 orthoRight = glm::normalize( + glm::vec3(worldToModelTransform * glm::vec4(right, 0.0)) + ); + + if (orthoRight == glm::vec3(0.0)) { + glm::vec3 otherVector(lookup.y, lookup.x, lookup.z); + right = glm::cross(viewDirection, otherVector); + orthoRight = glm::normalize( + glm::vec3(worldToModelTransform * glm::vec4(right, 0.0)) + ); + } + const glm::vec3 orthoUp = glm::normalize( + glm::vec3(worldToModelTransform * glm::dvec4(up, 0.0)) + ); + _labels->render(data, modelViewProjectionMatrix, orthoRight, orthoUp); + } } void RenderableBoxGrid::update(const UpdateData&) { diff --git a/modules/base/rendering/grids/renderableboxgrid.h b/modules/base/rendering/grids/renderableboxgrid.h index 3f4fbc0990..2c5e5d9dbf 100644 --- a/modules/base/rendering/grids/renderableboxgrid.h +++ b/modules/base/rendering/grids/renderableboxgrid.h @@ -27,6 +27,7 @@ #include +#include #include #include #include @@ -43,6 +44,7 @@ class RenderableBoxGrid : public Renderable { public: RenderableBoxGrid(const ghoul::Dictionary& dictionary); + void initialize() override; void initializeGL() override; void deinitializeGL() override; @@ -71,6 +73,11 @@ protected: GLenum _mode = GL_LINE_STRIP; std::vector _varray; + + // Labels + bool _hasLabels = false; + properties::BoolProperty _drawLabels; + std::unique_ptr _labels = nullptr; }; }// namespace openspace diff --git a/modules/base/rendering/grids/renderableradialgrid.cpp b/modules/base/rendering/grids/renderableradialgrid.cpp index aef8bc8609..9c9fe1f2df 100644 --- a/modules/base/rendering/grids/renderableradialgrid.cpp +++ b/modules/base/rendering/grids/renderableradialgrid.cpp @@ -71,6 +71,19 @@ namespace { "ring" }; + constexpr openspace::properties::Property::PropertyInfo DrawLabelInfo = { + "DrawLabels", + "Draw Labels", + "Determines whether labels should be drawn or hidden" + }; + + static const openspace::properties::PropertyOwner::PropertyOwnerInfo LabelsInfo = + { + "Labels", + "Labels", + "The labels for the grid" + }; + struct [[codegen::Dictionary(RenderableRadialGrid)]] Parameters { // [[codegen::verbatim(ColorInfo.description)]] std::optional color [[codegen::color()]]; @@ -86,6 +99,13 @@ namespace { // [[codegen::verbatim(RadiiInfo.description)]] std::optional radii; + + // [[codegen::verbatim(DrawLabelInfo.description)]] + std::optional drawLabels; + + // [[codegen::verbatim(LabelsInfo.description)]] + std::optional labels + [[codegen::reference("space_labelscomponent")]]; }; #include "renderableradialgrid_codegen.cpp" } // namespace @@ -103,6 +123,7 @@ RenderableRadialGrid::RenderableRadialGrid(const ghoul::Dictionary& dictionary) , _circleSegments(CircleSegmentsInfo, 36, 4, 200) , _lineWidth(LineWidthInfo, 0.5f, 1.f, 20.f) , _radii(RadiiInfo, glm::vec2(0.f, 1.f), glm::vec2(0.f), glm::vec2(20.f)) + , _drawLabels(DrawLabelInfo, false) { const Parameters p = codegen::bake(dictionary); @@ -134,10 +155,31 @@ RenderableRadialGrid::RenderableRadialGrid(const ghoul::Dictionary& dictionary) _radii.onChange([&]() { _gridIsDirty = true; }); addProperty(_radii); + + if (p.labels.has_value()) { + _drawLabels = p.drawLabels.value_or(_drawLabels); + addProperty(_drawLabels); + + _labels = std::make_unique(*p.labels); + _hasLabels = true; + addPropertySubOwner(_labels.get()); + } } bool RenderableRadialGrid::isReady() const { - return _gridProgram != nullptr; + bool isReady = _gridProgram != nullptr; + + if (_hasLabels) { + isReady = isReady && _labels->isReady(); + } + return isReady; +} + +void RenderableRadialGrid::initialize() { + if (_hasLabels) { + _labels->initialize(); + _labels->loadLabels(); + } } void RenderableRadialGrid::initializeGL() { @@ -171,14 +213,14 @@ void RenderableRadialGrid::render(const RenderData& data, RendererTasks&) { glm::dmat4(data.modelTransform.rotation) * // Spice rotation glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)); - const glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * - modelTransform; + const glm::dmat4 modelViewTransform = + data.camera.combinedViewMatrix() * modelTransform; + const glm::dmat4 projectionMatrix = data.camera.projectionMatrix(); + + const glm::dmat4 modelViewProjectionMatrix = projectionMatrix * modelViewTransform; _gridProgram->setUniform("modelViewTransform", modelViewTransform); - _gridProgram->setUniform( - "MVPTransform", - glm::dmat4(data.camera.projectionMatrix()) * modelViewTransform - ); + _gridProgram->setUniform("MVPTransform", modelViewProjectionMatrix); _gridProgram->setUniform("opacity", opacity()); _gridProgram->setUniform("gridColor", _color); @@ -205,6 +247,31 @@ void RenderableRadialGrid::render(const RenderData& data, RendererTasks&) { global::renderEngine->openglStateCache().resetBlendState(); global::renderEngine->openglStateCache().resetLineState(); global::renderEngine->openglStateCache().resetDepthState(); + + // Draw labels + if (_drawLabels && _hasLabels) { + const glm::vec3 lookup = data.camera.lookUpVectorWorldSpace(); + const glm::vec3 viewDirection = data.camera.viewDirectionWorldSpace(); + glm::vec3 right = glm::cross(viewDirection, lookup); + const glm::vec3 up = glm::cross(right, viewDirection); + + const glm::dmat4 worldToModelTransform = glm::inverse(modelTransform); + glm::vec3 orthoRight = glm::normalize( + glm::vec3(worldToModelTransform * glm::vec4(right, 0.0)) + ); + + if (orthoRight == glm::vec3(0.0)) { + glm::vec3 otherVector(lookup.y, lookup.x, lookup.z); + right = glm::cross(viewDirection, otherVector); + orthoRight = glm::normalize( + glm::vec3(worldToModelTransform * glm::vec4(right, 0.0)) + ); + } + const glm::vec3 orthoUp = glm::normalize( + glm::vec3(worldToModelTransform * glm::dvec4(up, 0.0)) + ); + _labels->render(data, modelViewProjectionMatrix, orthoRight, orthoUp); + } } void RenderableRadialGrid::update(const UpdateData&) { diff --git a/modules/base/rendering/grids/renderableradialgrid.h b/modules/base/rendering/grids/renderableradialgrid.h index 93187dfb9f..a80ad7cfcd 100644 --- a/modules/base/rendering/grids/renderableradialgrid.h +++ b/modules/base/rendering/grids/renderableradialgrid.h @@ -27,6 +27,7 @@ #include +#include #include #include #include @@ -46,6 +47,7 @@ public: RenderableRadialGrid(const ghoul::Dictionary& dictionary); ~RenderableRadialGrid() override = default; + void initialize() override; void initializeGL() override; void deinitializeGL() override; @@ -85,6 +87,11 @@ protected: std::vector _circles; GeometryData _lines{GL_LINES}; + + // Labels + bool _hasLabels = false; + properties::BoolProperty _drawLabels; + std::unique_ptr _labels = nullptr; }; }// namespace openspace diff --git a/modules/base/rendering/grids/renderablesphericalgrid.cpp b/modules/base/rendering/grids/renderablesphericalgrid.cpp index 4b58b488dd..82b6f8f2c8 100644 --- a/modules/base/rendering/grids/renderablesphericalgrid.cpp +++ b/modules/base/rendering/grids/renderablesphericalgrid.cpp @@ -55,6 +55,19 @@ namespace { "This value specifies the line width of the spherical grid" }; + constexpr openspace::properties::Property::PropertyInfo DrawLabelInfo = { + "DrawLabels", + "Draw Labels", + "Determines whether labels should be drawn or hidden" + }; + + static const openspace::properties::PropertyOwner::PropertyOwnerInfo LabelsInfo = + { + "Labels", + "Labels", + "The labels for the grid" + }; + struct [[codegen::Dictionary(RenderableSphericalGrid)]] Parameters { // [[codegen::verbatim(ColorInfo.description)]] std::optional color [[codegen::color()]]; @@ -64,6 +77,13 @@ namespace { // [[codegen::verbatim(LineWidthInfo.description)]] std::optional lineWidth; + + // [[codegen::verbatim(DrawLabelInfo.description)]] + std::optional drawLabels; + + // [[codegen::verbatim(LabelsInfo.description)]] + std::optional labels + [[codegen::reference("space_labelscomponent")]]; }; #include "renderablesphericalgrid_codegen.cpp" } // namespace @@ -80,6 +100,7 @@ RenderableSphericalGrid::RenderableSphericalGrid(const ghoul::Dictionary& dictio , _color(ColorInfo, glm::vec3(0.5f), glm::vec3(0.f), glm::vec3(1.f)) , _segments(SegmentsInfo, 36, 4, 200) , _lineWidth(LineWidthInfo, 0.5f, 1.f, 20.f) + , _drawLabels(DrawLabelInfo, false) { const Parameters p = codegen::bake(dictionary); @@ -104,12 +125,31 @@ RenderableSphericalGrid::RenderableSphericalGrid(const ghoul::Dictionary& dictio // Radius is always 1 setBoundingSphere(1.0); + + if (p.labels.has_value()) { + _drawLabels = p.drawLabels.value_or(_drawLabels); + addProperty(_drawLabels); + + _labels = std::make_unique(*p.labels); + _hasLabels = true; + addPropertySubOwner(_labels.get()); + } } bool RenderableSphericalGrid::isReady() const { - bool ready = true; - ready &= (_gridProgram != nullptr); - return ready; + bool isReady = _gridProgram != nullptr; + + if (_hasLabels) { + isReady = isReady && _labels->isReady(); + } + return isReady; +} + +void RenderableSphericalGrid::initialize() { + if (_hasLabels) { + _labels->initialize(); + _labels->loadLabels(); + } } void RenderableSphericalGrid::initializeGL() { @@ -162,14 +202,14 @@ void RenderableSphericalGrid::render(const RenderData& data, RendererTasks&){ glm::dmat4(data.modelTransform.rotation) * // Spice rotation glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)); - const glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * - modelTransform; + const glm::dmat4 modelViewTransform = + data.camera.combinedViewMatrix() * modelTransform; + const glm::dmat4 projectionMatrix = data.camera.projectionMatrix(); + + const glm::dmat4 modelViewProjectionMatrix = projectionMatrix * modelViewTransform; _gridProgram->setUniform("modelViewTransform", modelViewTransform); - _gridProgram->setUniform( - "MVPTransform", - glm::dmat4(data.camera.projectionMatrix()) * modelViewTransform - ); + _gridProgram->setUniform("MVPTransform", modelViewProjectionMatrix); _gridProgram->setUniform("opacity", opacity()); _gridProgram->setUniform("gridColor", _color); @@ -195,6 +235,31 @@ void RenderableSphericalGrid::render(const RenderData& data, RendererTasks&){ global::renderEngine->openglStateCache().resetBlendState(); global::renderEngine->openglStateCache().resetLineState(); global::renderEngine->openglStateCache().resetDepthState(); + + // Draw labels + if (_drawLabels && _hasLabels) { + const glm::vec3 lookup = data.camera.lookUpVectorWorldSpace(); + const glm::vec3 viewDirection = data.camera.viewDirectionWorldSpace(); + glm::vec3 right = glm::cross(viewDirection, lookup); + const glm::vec3 up = glm::cross(right, viewDirection); + + const glm::dmat4 worldToModelTransform = glm::inverse(modelTransform); + glm::vec3 orthoRight = glm::normalize( + glm::vec3(worldToModelTransform * glm::vec4(right, 0.0)) + ); + + if (orthoRight == glm::vec3(0.0)) { + glm::vec3 otherVector(lookup.y, lookup.x, lookup.z); + right = glm::cross(viewDirection, otherVector); + orthoRight = glm::normalize( + glm::vec3(worldToModelTransform * glm::vec4(right, 0.0)) + ); + } + const glm::vec3 orthoUp = glm::normalize( + glm::vec3(worldToModelTransform * glm::dvec4(up, 0.0)) + ); + _labels->render(data, modelViewProjectionMatrix, orthoRight, orthoUp); + } } void RenderableSphericalGrid::update(const UpdateData&) { diff --git a/modules/base/rendering/grids/renderablesphericalgrid.h b/modules/base/rendering/grids/renderablesphericalgrid.h index 8fbf77ea03..6fd3346259 100644 --- a/modules/base/rendering/grids/renderablesphericalgrid.h +++ b/modules/base/rendering/grids/renderablesphericalgrid.h @@ -27,6 +27,7 @@ #include +#include #include #include #include @@ -43,6 +44,7 @@ public: RenderableSphericalGrid(const ghoul::Dictionary& dictionary); ~RenderableSphericalGrid() override = default; + void initialize() override; void initializeGL() override; void deinitializeGL() override; @@ -75,6 +77,11 @@ protected: unsigned int _vsize = 0; std::vector _varray; std::vector _iarray; + + // Labels + bool _hasLabels = false; + properties::BoolProperty _drawLabels; + std::unique_ptr _labels = nullptr; }; }// namespace openspace From 34aa515f160494039f4893fe64eaf6c8695eb684 Mon Sep 17 00:00:00 2001 From: Malin E Date: Mon, 19 Sep 2022 14:37:42 +0200 Subject: [PATCH 72/79] Fix issue with grid for different x and y values * Also adjust grid example asset to showcase the highlight feature --- data/assets/examples/grids.asset | 7 +++-- .../base/rendering/grids/renderablegrid.cpp | 30 ++++++++++--------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/data/assets/examples/grids.asset b/data/assets/examples/grids.asset index 2fe816e3fb..6c32a1be5a 100644 --- a/data/assets/examples/grids.asset +++ b/data/assets/examples/grids.asset @@ -36,9 +36,12 @@ local planarGrid = { Type = "RenderableGrid", Color = { 0.0, 1.0, 0.8 }, LineWidth = 2.0, - Segments = { 5, 10 }, + Segments = { 6, 10 }, Size = { 1, 2 }, - Enabled = false + Enabled = false, + HighlightColor = {1.0, 0.8, 0.0 }, + HighlightLineWidth = 3.2, + HighlightRate = { 3, 3 } }, GUI = { Name = "Example Grid", diff --git a/modules/base/rendering/grids/renderablegrid.cpp b/modules/base/rendering/grids/renderablegrid.cpp index a2b85d7567..5b85ead0e8 100644 --- a/modules/base/rendering/grids/renderablegrid.cpp +++ b/modules/base/rendering/grids/renderablegrid.cpp @@ -71,7 +71,7 @@ namespace { constexpr openspace::properties::Property::PropertyInfo HighlightLineWidthInfo = { "HighlightLineWidth", - "HighlightLine Width", + "Highlight Line Width", "This value specifies the line width of the highlighted lines in the grid" }; @@ -357,9 +357,10 @@ void RenderableGrid::update(const UpdateData&) { // Line in y direction bool shouldHighlight = false; - if (_highlightRate.value().y != 0) { - int rest = static_cast(i - center.y) % _highlightRate.value().y; - shouldHighlight = abs(rest) == 0; + if (_highlightRate.value().x != 0) { + int dist = abs(static_cast(i) - static_cast(center.x)); + int rest = dist % _highlightRate.value().x; + shouldHighlight = rest == 0; } if (shouldHighlight) { @@ -373,8 +374,9 @@ void RenderableGrid::update(const UpdateData&) { // Line in x direction shouldHighlight = false; - if (_highlightRate.value().x != 0) { - int rest = static_cast(j - center.x) % _highlightRate.value().x; + if (_highlightRate.value().y != 0) { + int dist = abs(static_cast(j) - static_cast(center.y)); + int rest = dist % _highlightRate.value().y; shouldHighlight = abs(rest) == 0; } @@ -395,9 +397,9 @@ void RenderableGrid::update(const UpdateData&) { const double x1 = x0 + step.x; bool shouldHighlight = false; - if (_highlightRate.value().x != 0) { - int rest = - static_cast(nSegments.y - center.x) % _highlightRate.value().x; + if (_highlightRate.value().y != 0) { + int dist = abs(static_cast(nSegments.y) - static_cast(center.y)); + int rest = dist % _highlightRate.value().y; shouldHighlight = abs(rest) == 0; } @@ -412,14 +414,14 @@ void RenderableGrid::update(const UpdateData&) { } // last y col - for (unsigned int i = 0; i < nSegments.y; ++i) { - const double y0 = -halfSize.y + i * step.y; + for (unsigned int j = 0; j < nSegments.y; ++j) { + const double y0 = -halfSize.y + j * step.y; const double y1 = y0 + step.y; bool shouldHighlight = false; - if (_highlightRate.value().y != 0) { - int rest = - static_cast(nSegments.x - center.y) % _highlightRate.value().y; + if (_highlightRate.value().x != 0) { + int dist = abs(static_cast(nSegments.x) - static_cast(center.x)); + int rest = dist % _highlightRate.value().x; shouldHighlight = abs(rest) == 0; } if (shouldHighlight) { From ae84f1b1204a26765b4b620cf3b79db1bc53aebf Mon Sep 17 00:00:00 2001 From: Gene Payne Date: Tue, 20 Sep 2022 15:40:12 -0600 Subject: [PATCH 73/79] Renderable prop change updates buffers without reinitializing GL (#2241) --- modules/space/rendering/renderableorbitalkepler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/space/rendering/renderableorbitalkepler.cpp b/modules/space/rendering/renderableorbitalkepler.cpp index 0baecf37dd..95e7dc70e4 100644 --- a/modules/space/rendering/renderableorbitalkepler.cpp +++ b/modules/space/rendering/renderableorbitalkepler.cpp @@ -160,7 +160,7 @@ RenderableOrbitalKepler::RenderableOrbitalKepler(const ghoul::Dictionary& dict) addProperty(_opacity); _segmentQuality = static_cast(p.segmentQuality); - _segmentQuality.onChange([this]() { initializeGL(); }); + _segmentQuality.onChange([this]() { updateBuffers(); }); addProperty(_segmentQuality); _appearance.lineColor = p.color; @@ -169,7 +169,7 @@ RenderableOrbitalKepler::RenderableOrbitalKepler(const ghoul::Dictionary& dict) addPropertySubOwner(_appearance); _path = p.path.string(); - _path.onChange([this]() { initializeGL(); }); + _path.onChange([this]() { updateBuffers(); }); addProperty(_path); _format = codegen::map(p.format); From f502922338556e504c3dc3bde13d2d22e3b4d25a Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Wed, 21 Sep 2022 10:52:05 +0200 Subject: [PATCH 74/79] CMake cleanup (#2246) * Simplification of the DLL copying mechanism on Windows * Only deploy Qt on Windows * Use set_target_properties function --- CMakeLists.txt | 2 -- apps/OpenSpace-MinVR/CMakeLists.txt | 13 ++------- apps/OpenSpace/CMakeLists.txt | 22 +++++++++++++-- ext/CMakeLists.txt | 12 ++++++-- ext/ghoul | 2 +- ext/spice | 2 +- modules/globebrowsing/CMakeLists.txt | 8 ++++-- modules/spout/CMakeLists.txt | 11 ++++++-- modules/webbrowser/CMakeLists.txt | 17 +++--------- support/cmake/application_definition.cmake | 32 +--------------------- support/cmake/module_definition.cmake | 14 ---------- 11 files changed, 51 insertions(+), 84 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eabc169d1f..1694b170b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,6 @@ set(OPENSPACE_CMAKE_EXT_DIR "${OPENSPACE_BASE_DIR}/support/cmake") set(GHOUL_BASE_DIR "${OPENSPACE_BASE_DIR}/ext/ghoul") include(${OPENSPACE_CMAKE_EXT_DIR}/module_common.cmake) -include(${OPENSPACE_CMAKE_EXT_DIR}/global_variables.cmake) include(${GHOUL_BASE_DIR}/support/cmake/copy_shared_libraries.cmake) include(${GHOUL_BASE_DIR}/support/cmake/handle_external_library.cmake) include(${GHOUL_BASE_DIR}/support/cmake/message_macros.cmake) @@ -164,7 +163,6 @@ if (UNIX) endif () add_subdirectory(ext) - add_subdirectory(src) add_subdirectory(support/coding/codegen) diff --git a/apps/OpenSpace-MinVR/CMakeLists.txt b/apps/OpenSpace-MinVR/CMakeLists.txt index 8f799b8b37..ae592d8d42 100644 --- a/apps/OpenSpace-MinVR/CMakeLists.txt +++ b/apps/OpenSpace-MinVR/CMakeLists.txt @@ -50,7 +50,7 @@ target_include_directories(OpenSpace-MinVR PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/ex target_include_directories(OpenSpace-MinVR PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/ext/minvr/external/GLFW/src/include) -target_link_libraries(OpenSpace-MinVR openspace-core MinVR) +target_link_libraries(OpenSpace-MinVR PUBLIC openspace-core MinVR) # Web Browser and Web gui # Why not put these in the module's path? Because they do not have access to the @@ -71,16 +71,7 @@ elseif (OPENSPACE_MODULE_WEBBROWSER) message(WARNING "Web configured to be included, but no CEF_ROOT was found, please try configuring CMake again.") endif () -if (OPENSPACE_MODULE_WEBGUI AND WEBGUI_MODULE_PATH) - set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${WEBGUI_MODULE_PATH}/cmake") - include(webgui_helpers) - build_webgui_source(OpenSpace-MinVR) -elseif (OPENSPACE_MODULE_WEBGUI) - message(WARNING "WebGui is configured to be included, but the web source could not be found. Try configuring CMake again.") -endif () -# End Web Browser and Web gui - if (MSVC) # This library is used for being able to output the callstack if an exception escapes - target_link_libraries(OpenSpace-MinVR Dbghelp.lib) + target_link_libraries(OpenSpace-MinVR PUBLIC Dbghelp.lib) endif () diff --git a/apps/OpenSpace/CMakeLists.txt b/apps/OpenSpace/CMakeLists.txt index ba01953e86..b8677938df 100644 --- a/apps/OpenSpace/CMakeLists.txt +++ b/apps/OpenSpace/CMakeLists.txt @@ -25,7 +25,6 @@ include(${GHOUL_BASE_DIR}/support/cmake/copy_shared_libraries.cmake) include(${GHOUL_BASE_DIR}/support/cmake/message_macros.cmake) include(${OPENSPACE_CMAKE_EXT_DIR}/application_definition.cmake) -include(${OPENSPACE_CMAKE_EXT_DIR}/global_variables.cmake) # We are getting all_enabled_modules from the handle_applications.cmake file which gets # it from the main CMakeLists file @@ -141,6 +140,18 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/ext/launcher) target_link_libraries(OpenSpace PRIVATE openspace-ui-launcher) end_header("Dependency: Profile Editor") +if (WIN32) + # Find the windeployqt application + get_target_property(_qmake_executable Qt6::qmake IMPORTED_LOCATION) + get_filename_component(_qt_bin_dir "${_qmake_executable}" DIRECTORY) + find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${_qt_bin_dir}") + add_custom_command( + TARGET OpenSpace POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E env PATH="${_qt_bin_dir}" "${WINDEPLOYQT_EXECUTABLE}" --verbose 0 --no-compiler-runtime \"$\" + COMMENT "Deploying Qt libraries" + ) +endif () + # Web Browser and Web gui # Why not put these in the module's path? Because they do not have access to the @@ -161,7 +172,7 @@ if (OPENSPACE_MODULE_WEBBROWSER AND CEF_ROOT) set_cef_targets("${CEF_ROOT}" OpenSpace) run_cef_platform_config("${CEF_ROOT}" "${CEF_TARGET}" "${WEBBROWSER_MODULE_PATH}") elseif () - message(WARNING "Web configured to be included, but no CEF_ROOT was found, please try configuring CMake again.") + message(WARNING "Web configured to be included, but no CEF_ROOT was found, please try configuring CMake again") endif () if (MSVC) @@ -174,3 +185,10 @@ endif () if (OPENSPACE_NVTOOLS_ENABLED) target_link_libraries(OpenSpace PRIVATE "${OPENSPACE_NVTOOLS_PATH}/lib/x64/nvToolsExt64_1.lib") endif () + +if (WIN32) + add_custom_command(TARGET OpenSpace POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ + COMMAND_EXPAND_LISTS + ) +endif () diff --git a/ext/CMakeLists.txt b/ext/CMakeLists.txt index 079c95117b..3e17fac68d 100644 --- a/ext/CMakeLists.txt +++ b/ext/CMakeLists.txt @@ -62,13 +62,19 @@ end_dependency() # Curl begin_dependency("CURL") -add_library(external-curl INTERFACE) if (WIN32) - target_include_directories(external-curl INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/curl/include") - target_link_libraries(external-curl INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/curl/lib/libcurl.lib") + add_library(external-curl SHARED IMPORTED GLOBAL) + target_include_directories(external-curl INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/curl/include) + set_property(TARGET external-curl PROPERTY IMPORTED_IMPLIB ${CMAKE_CURRENT_SOURCE_DIR}/curl/lib/libcurl.lib) + set_property(TARGET external-curl PROPERTY IMPORTED_LOCATION + ${CMAKE_CURRENT_SOURCE_DIR}/curl/lib/libcurl.dll + ${CMAKE_CURRENT_SOURCE_DIR}/curl/lib/libeay32.dll + ${CMAKE_CURRENT_SOURCE_DIR}/curl/lib/ssleay32.dll + ) else () find_package(CURL) if (CURL_FOUND) + add_library(external-curl INTERFACE) target_include_directories(external-curl INTERFACE ${CURL_INCLUDE_DIRS}) target_link_libraries(external-curl INTERFACE ${CURL_LIBRARIES}) endif () diff --git a/ext/ghoul b/ext/ghoul index 1f420ed0f0..b676d66bc0 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 1f420ed0f03347ed3c8bb7550d58798f9a02cbc0 +Subproject commit b676d66bc028e26dbf2fa0a39c67e35667df13f9 diff --git a/ext/spice b/ext/spice index bb7eded3a4..5dba0f3269 160000 --- a/ext/spice +++ b/ext/spice @@ -1 +1 @@ -Subproject commit bb7eded3a4c45eff33cee41f4d24fffe5248d01a +Subproject commit 5dba0f32690dd49f29adbbf618a69e5709cdc405 diff --git a/modules/globebrowsing/CMakeLists.txt b/modules/globebrowsing/CMakeLists.txt index aa26ff6b6c..72598ce00b 100644 --- a/modules/globebrowsing/CMakeLists.txt +++ b/modules/globebrowsing/CMakeLists.txt @@ -149,9 +149,11 @@ target_precompile_headers(${globebrowsing_module} PRIVATE install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/gdal_data DESTINATION modules/globebrowsing) if (WIN32) - target_include_directories(openspace-module-globebrowsing SYSTEM PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/ext/gdal/include) - target_link_libraries(openspace-module-globebrowsing PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/ext/gdal/lib/gdal_i.lib) - register_external_libraries("${CMAKE_CURRENT_SOURCE_DIR}/ext/gdal/lib/gdal241.dll") + add_library(gdal SHARED IMPORTED) + target_include_directories(gdal SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/ext/gdal/include) + set_target_properties(gdal PROPERTIES IMPORTED_IMPLIB ${CMAKE_CURRENT_SOURCE_DIR}/ext/gdal/lib/gdal_i.lib) + set_target_properties(gdal PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/ext/gdal/lib/gdal241.dll) + target_link_libraries(openspace-module-globebrowsing PRIVATE gdal) else (WIN32) find_package(GDAL REQUIRED) diff --git a/modules/spout/CMakeLists.txt b/modules/spout/CMakeLists.txt index ae1cdfc329..e603a0fc57 100644 --- a/modules/spout/CMakeLists.txt +++ b/modules/spout/CMakeLists.txt @@ -50,8 +50,13 @@ create_new_module( ${HEADER_FILES} ${SOURCE_FILES} ) -target_include_directories(openspace-module-spout SYSTEM PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/ext/spout) -target_link_libraries(openspace-module-spout PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/ext/spout/SpoutLibrary.lib) -register_external_libraries("${CMAKE_CURRENT_SOURCE_DIR}/ext/spout/SpoutLibrary.dll") +add_library(spout SHARED IMPORTED) +target_include_directories(spout SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/ext/spout) +set_target_properties( + spout PROPERTIES + IMPORTED_IMPLIB ${CMAKE_CURRENT_SOURCE_DIR}/ext/spout/SpoutLibrary.lib + IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/ext/spout/SpoutLibrary.dll +) +target_link_libraries(openspace-module-spout PRIVATE spout) target_compile_definitions(openspace-module-spout PUBLIC "OPENSPACE_HAS_SPOUT") diff --git a/modules/webbrowser/CMakeLists.txt b/modules/webbrowser/CMakeLists.txt index bd01c449f9..dfd808aed5 100644 --- a/modules/webbrowser/CMakeLists.txt +++ b/modules/webbrowser/CMakeLists.txt @@ -202,8 +202,8 @@ if (OS_MACOSX) endif () endforeach() - set_property(TARGET ${CEF_HELPER_TARGET_GPU} PROPERTY FOLDER "Helper") - set_property(TARGET ${CEF_HELPER_TARGET_RENDERER} PROPERTY FOLDER "Helper") + set_target_properties(${CEF_HELPER_TARGET_GPU} PROPERTIES FOLDER "Helper") + set_target_properties(${CEF_HELPER_TARGET_RENDERER} PROPERTIES FOLDER "Helper") else() message(STATUS "Setting up WebBrowser CEF helper executable: ${CEF_HELPER_TARGET}") set_openspace_cef_target_out_dir() @@ -219,7 +219,7 @@ else() endif (OS_WINDOWS) endif () -set_property(TARGET ${CEF_HELPER_TARGET} PROPERTY FOLDER "Helper") +set_target_properties(${CEF_HELPER_TARGET} PROPERTIES FOLDER "Helper") ########################################################################################## # Create OpenSpace module. @@ -292,13 +292,4 @@ if (UNIX AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")) DESTINATION ${CEF_ROOT}/${CMAKE_BUILD_TYPE}/ FILES_MATCHING PATTERN * ) - endif () - -# Rename to "OpenSpace Helper" after build & link as spaces in targets are not allowed -# add_custom_command( -# TARGET ${CEF_HELPER_TARGET} POST_BUILD -# COMMAND ${CMAKE_COMMAND} -E rename -# "$/${CEF_HELPER_TARGET}" -# "$/OpenSpace Helper" -# COMMENT "Renaming ${CEF_HELPER_TARGET} to 'OpenSpace Helper'" -# ) +endif () diff --git a/support/cmake/application_definition.cmake b/support/cmake/application_definition.cmake index 100f51f740..6705639450 100644 --- a/support/cmake/application_definition.cmake +++ b/support/cmake/application_definition.cmake @@ -27,39 +27,9 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/global_variables.cmake) function (create_new_application application_name) add_executable(${application_name} MACOSX_BUNDLE ${ARGN}) set_openspace_compile_settings(${application_name}) - - # We currently can't reuse the precompiled header because that one has the Kameleon - # definition stuck into it - #target_precompile_headers(${library_name} REUSE_FROM openspace-core) - #target_precompile_headers(${application_name} PRIVATE - # [["ghoul/fmt.h"]] - # [["ghoul/glm.h"]] - # [["ghoul/misc/assert.h"]] - # [["ghoul/misc/boolean.h"]] - # [["ghoul/misc/exception.h"]] - # [["ghoul/misc/invariants.h"]] - # [["ghoul/misc/profiling.h"]] - # - # - # - # - # - # - # - # - # - #) - if (WIN32) get_external_library_dependencies(ext_lib) - ghl_copy_files( - ${application_name} - "${OPENSPACE_BASE_DIR}/ext/curl/lib/libcurl.dll" - "${OPENSPACE_BASE_DIR}/ext/curl/lib/libeay32.dll" - "${OPENSPACE_BASE_DIR}/ext/curl/lib/ssleay32.dll" - ${ext_lib} - ) - ghl_copy_shared_libraries(${application_name} ${OPENSPACE_BASE_DIR}/ext/ghoul) + ghl_copy_files(${application_name} ${ext_lib}) endif () target_link_libraries(${application_name} PUBLIC openspace-module-base) diff --git a/support/cmake/module_definition.cmake b/support/cmake/module_definition.cmake index 34dbd45be8..96cbeb1934 100644 --- a/support/cmake/module_definition.cmake +++ b/support/cmake/module_definition.cmake @@ -74,20 +74,6 @@ endfunction () -function (register_external_libraries libraries) - # This is an ugly hack as we can't inject a variable into a scope two parents above - # would love to: set(${module_external_librarys} "${libraries}" PARENT_PARENT_SCOPE) - # instead - set(libs "") - foreach (library ${libraries}) - get_filename_component(lib ${library} ABSOLUTE) - list(APPEND libs ${lib}) - endforeach() - - set_property(GLOBAL PROPERTY CurrentModuleExternalLibraries ${libs}) -endfunction () - - # Gets and returns the module.h and module.cpp files and provides them with a # source group function (get_module_files module_name module_files) From ac79e4dc07ab073333b269d59346a5b67ba1d064 Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 22 Sep 2022 12:01:01 +0200 Subject: [PATCH 75/79] Start addressing PR comments --- .../rendering/grids/renderableboxgrid.cpp | 9 ++------ .../base/rendering/grids/renderableboxgrid.h | 2 +- .../base/rendering/grids/renderablegrid.cpp | 9 ++------ modules/base/rendering/grids/renderablegrid.h | 4 +--- .../rendering/grids/renderableradialgrid.cpp | 9 ++------ .../rendering/grids/renderableradialgrid.h | 2 +- .../grids/renderablesphericalgrid.cpp | 9 ++------ .../rendering/grids/renderablesphericalgrid.h | 2 +- .../rendering/renderablebillboardscloud.cpp | 2 +- .../rendering/renderablebillboardscloud.h | 4 ++-- .../rendering/renderableplanescloud.cpp | 23 ++++++++++--------- .../rendering/renderableplanescloud.h | 4 ++-- modules/space/labelscomponent.h | 2 +- .../renderableconstellationsbase.cpp | 6 +---- 14 files changed, 31 insertions(+), 56 deletions(-) diff --git a/modules/base/rendering/grids/renderableboxgrid.cpp b/modules/base/rendering/grids/renderableboxgrid.cpp index 38482d98d8..7496c00467 100644 --- a/modules/base/rendering/grids/renderableboxgrid.cpp +++ b/modules/base/rendering/grids/renderableboxgrid.cpp @@ -127,12 +127,7 @@ RenderableBoxGrid::RenderableBoxGrid(const ghoul::Dictionary& dictionary) } bool RenderableBoxGrid::isReady() const { - bool isReady = _gridProgram != nullptr; - - if (_hasLabels) { - isReady = isReady && _labels->isReady(); - } - return isReady; + return _hasLabels ? _gridProgram && _labels->isReady() : _gridProgram != nullptr; } void RenderableBoxGrid::initialize() { @@ -232,7 +227,7 @@ void RenderableBoxGrid::render(const RenderData& data, RendererTasks&){ ); if (orthoRight == glm::vec3(0.0)) { - glm::vec3 otherVector(lookup.y, lookup.x, lookup.z); + glm::vec3 otherVector = glm::vec3(lookup.y, lookup.x, lookup.z); right = glm::cross(viewDirection, otherVector); orthoRight = glm::normalize( glm::vec3(worldToModelTransform * glm::vec4(right, 0.0)) diff --git a/modules/base/rendering/grids/renderableboxgrid.h b/modules/base/rendering/grids/renderableboxgrid.h index 2c5e5d9dbf..96e43fb73c 100644 --- a/modules/base/rendering/grids/renderableboxgrid.h +++ b/modules/base/rendering/grids/renderableboxgrid.h @@ -77,7 +77,7 @@ protected: // Labels bool _hasLabels = false; properties::BoolProperty _drawLabels; - std::unique_ptr _labels = nullptr; + std::unique_ptr _labels; }; }// namespace openspace diff --git a/modules/base/rendering/grids/renderablegrid.cpp b/modules/base/rendering/grids/renderablegrid.cpp index 5b85ead0e8..5cb75ed431 100644 --- a/modules/base/rendering/grids/renderablegrid.cpp +++ b/modules/base/rendering/grids/renderablegrid.cpp @@ -188,12 +188,7 @@ RenderableGrid::RenderableGrid(const ghoul::Dictionary& dictionary) } bool RenderableGrid::isReady() const { - bool isReady = _gridProgram != nullptr; - - if (_hasLabels) { - isReady = isReady && _labels->isReady(); - } - return isReady; + return _hasLabels ? _gridProgram && _labels->isReady() : _gridProgram != nullptr; } void RenderableGrid::initialize() { @@ -273,7 +268,7 @@ void RenderableGrid::render(const RenderData& data, RendererTasks&){ ); if (orthoRight == glm::vec3(0.0)) { - glm::vec3 otherVector(lookup.y, lookup.x, lookup.z); + glm::vec3 otherVector = glm::vec3(lookup.y, lookup.x, lookup.z); right = glm::cross(viewDirection, otherVector); orthoRight = glm::normalize( glm::vec3(worldToModelTransform * glm::vec4(right, 0.0)) diff --git a/modules/base/rendering/grids/renderablegrid.h b/modules/base/rendering/grids/renderablegrid.h index 8d5db71ca1..9b0eabc890 100644 --- a/modules/base/rendering/grids/renderablegrid.h +++ b/modules/base/rendering/grids/renderablegrid.h @@ -86,9 +86,7 @@ protected: // Labels bool _hasLabels = false; properties::BoolProperty _drawLabels; - - // Everything related to the labels are handled by LabelsComponent - std::unique_ptr _labels = nullptr; + std::unique_ptr _labels; }; }// namespace openspace diff --git a/modules/base/rendering/grids/renderableradialgrid.cpp b/modules/base/rendering/grids/renderableradialgrid.cpp index 9c9fe1f2df..1c42671fbc 100644 --- a/modules/base/rendering/grids/renderableradialgrid.cpp +++ b/modules/base/rendering/grids/renderableradialgrid.cpp @@ -167,12 +167,7 @@ RenderableRadialGrid::RenderableRadialGrid(const ghoul::Dictionary& dictionary) } bool RenderableRadialGrid::isReady() const { - bool isReady = _gridProgram != nullptr; - - if (_hasLabels) { - isReady = isReady && _labels->isReady(); - } - return isReady; + return _hasLabels ? _gridProgram && _labels->isReady() : _gridProgram != nullptr; } void RenderableRadialGrid::initialize() { @@ -261,7 +256,7 @@ void RenderableRadialGrid::render(const RenderData& data, RendererTasks&) { ); if (orthoRight == glm::vec3(0.0)) { - glm::vec3 otherVector(lookup.y, lookup.x, lookup.z); + glm::vec3 otherVector = glm::vec3(lookup.y, lookup.x, lookup.z); right = glm::cross(viewDirection, otherVector); orthoRight = glm::normalize( glm::vec3(worldToModelTransform * glm::vec4(right, 0.0)) diff --git a/modules/base/rendering/grids/renderableradialgrid.h b/modules/base/rendering/grids/renderableradialgrid.h index a80ad7cfcd..2a1545bb40 100644 --- a/modules/base/rendering/grids/renderableradialgrid.h +++ b/modules/base/rendering/grids/renderableradialgrid.h @@ -91,7 +91,7 @@ protected: // Labels bool _hasLabels = false; properties::BoolProperty _drawLabels; - std::unique_ptr _labels = nullptr; + std::unique_ptr _labels; }; }// namespace openspace diff --git a/modules/base/rendering/grids/renderablesphericalgrid.cpp b/modules/base/rendering/grids/renderablesphericalgrid.cpp index 82b6f8f2c8..e60c334bee 100644 --- a/modules/base/rendering/grids/renderablesphericalgrid.cpp +++ b/modules/base/rendering/grids/renderablesphericalgrid.cpp @@ -137,12 +137,7 @@ RenderableSphericalGrid::RenderableSphericalGrid(const ghoul::Dictionary& dictio } bool RenderableSphericalGrid::isReady() const { - bool isReady = _gridProgram != nullptr; - - if (_hasLabels) { - isReady = isReady && _labels->isReady(); - } - return isReady; + return _hasLabels ? _gridProgram && _labels->isReady() : _gridProgram != nullptr; } void RenderableSphericalGrid::initialize() { @@ -249,7 +244,7 @@ void RenderableSphericalGrid::render(const RenderData& data, RendererTasks&){ ); if (orthoRight == glm::vec3(0.0)) { - glm::vec3 otherVector(lookup.y, lookup.x, lookup.z); + glm::vec3 otherVector = glm::vec3(lookup.y, lookup.x, lookup.z); right = glm::cross(viewDirection, otherVector); orthoRight = glm::normalize( glm::vec3(worldToModelTransform * glm::vec4(right, 0.0)) diff --git a/modules/base/rendering/grids/renderablesphericalgrid.h b/modules/base/rendering/grids/renderablesphericalgrid.h index 6fd3346259..cbb4ffea63 100644 --- a/modules/base/rendering/grids/renderablesphericalgrid.h +++ b/modules/base/rendering/grids/renderablesphericalgrid.h @@ -81,7 +81,7 @@ protected: // Labels bool _hasLabels = false; properties::BoolProperty _drawLabels; - std::unique_ptr _labels = nullptr; + std::unique_ptr _labels; }; }// namespace openspace diff --git a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp index c1ceb4040e..b432c985ae 100644 --- a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp +++ b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp @@ -708,7 +708,7 @@ void RenderableBillboardsCloud::render(const RenderData& data, RendererTasks&) { glm::cross(cameraUpDirectionWorld, cameraViewDirectionWorld) ); if (orthoRight == glm::dvec3(0.0)) { - glm::dvec3 otherVector( + glm::dvec3 otherVector = glm::vec3( cameraUpDirectionWorld.y, cameraUpDirectionWorld.x, cameraUpDirectionWorld.z diff --git a/modules/digitaluniverse/rendering/renderablebillboardscloud.h b/modules/digitaluniverse/rendering/renderablebillboardscloud.h index 5ad76f1e5b..5639d4c303 100644 --- a/modules/digitaluniverse/rendering/renderablebillboardscloud.h +++ b/modules/digitaluniverse/rendering/renderablebillboardscloud.h @@ -135,8 +135,8 @@ private: speck::Dataset _dataset; speck::ColorMap _colorMap; - // Everything related to the labels are handled by LabelsComponent - std::unique_ptr _labels = nullptr; + // Everything related to the labels is handled by LabelsComponent + std::unique_ptr _labels; std::vector _colorRangeData; std::unordered_map _optionConversionMap; diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.cpp b/modules/digitaluniverse/rendering/renderableplanescloud.cpp index 29b0b7c388..82232f1773 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.cpp +++ b/modules/digitaluniverse/rendering/renderableplanescloud.cpp @@ -440,23 +440,24 @@ void RenderablePlanesCloud::render(const RenderData& data, RendererTasks&) { const glm::dmat4 modelViewMatrix = data.camera.combinedViewMatrix() * modelMatrix; const glm::mat4 projectionMatrix = data.camera.projectionMatrix(); - const glm::dmat4 mvpMatrix = glm::dmat4(projectionMatrix) * modelViewMatrix; - - const glm::dmat4 invMVPParts = glm::inverse(modelMatrix) * - glm::inverse(data.camera.combinedViewMatrix()) * - glm::inverse(glm::dmat4(projectionMatrix)); - const glm::dvec3 orthoRight = glm::normalize( - glm::dvec3(invMVPParts * glm::dvec4(1.0, 0.0, 0.0, 0.0)) - ); - const glm::dvec3 orthoUp = glm::normalize( - glm::dvec3(invMVPParts * glm::dvec4(0.0, 1.0, 0.0, 0.0)) - ); if (_hasSpeckFile) { renderPlanes(data, modelViewMatrix, projectionMatrix, fadeInVariable); } if (_hasLabels) { + const glm::dmat4 mvpMatrix = glm::dmat4(projectionMatrix) * modelViewMatrix; + + const glm::dmat4 invMVPParts = glm::inverse(modelMatrix) * + glm::inverse(data.camera.combinedViewMatrix()) * + glm::inverse(glm::dmat4(projectionMatrix)); + const glm::dvec3 orthoRight = glm::normalize( + glm::dvec3(invMVPParts * glm::dvec4(1.0, 0.0, 0.0, 0.0)) + ); + const glm::dvec3 orthoUp = glm::normalize( + glm::dvec3(invMVPParts * glm::dvec4(0.0, 1.0, 0.0, 0.0)) + ); + _labels->render(data, mvpMatrix, orthoRight, orthoUp, fadeInVariable); } } diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.h b/modules/digitaluniverse/rendering/renderableplanescloud.h index 66f7680033..417caa81bb 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.h +++ b/modules/digitaluniverse/rendering/renderableplanescloud.h @@ -114,8 +114,8 @@ private: speck::Dataset _dataset; - // Everything related to the labels are handled by LabelsComponent - std::unique_ptr _labels = nullptr; + // Everything related to the labels is handled by LabelsComponent + std::unique_ptr _labels; float _sluminosity = 1.f; diff --git a/modules/space/labelscomponent.h b/modules/space/labelscomponent.h index c63ac7e458..88443b570c 100644 --- a/modules/space/labelscomponent.h +++ b/modules/space/labelscomponent.h @@ -39,7 +39,7 @@ namespace ghoul::fontrendering { class Font; } namespace openspace { - struct RenderData; +struct RenderData; namespace documentation { struct Documentation; } diff --git a/modules/space/rendering/renderableconstellationsbase.cpp b/modules/space/rendering/renderableconstellationsbase.cpp index cbd9298a4e..bb8ca8f7c1 100644 --- a/modules/space/rendering/renderableconstellationsbase.cpp +++ b/modules/space/rendering/renderableconstellationsbase.cpp @@ -214,11 +214,7 @@ void RenderableConstellationsBase::initialize() { } bool RenderableConstellationsBase::isReady() const { - // If we have labels, they also need to be loaded - if (_hasLabels) { - return _labels->isReady(); - } - return true; + return _hasLabels ? _labels->isReady() : true; } void RenderableConstellationsBase::render(const RenderData& data, RendererTasks&) { From 71a2cf685af153286426094863025c050c993233 Mon Sep 17 00:00:00 2001 From: Malin E Date: Fri, 23 Sep 2022 15:35:29 +0200 Subject: [PATCH 76/79] Remove not needed initialization --- modules/space/rendering/renderableconstellationsbase.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/space/rendering/renderableconstellationsbase.h b/modules/space/rendering/renderableconstellationsbase.h index 72dadb5b21..1987750db0 100644 --- a/modules/space/rendering/renderableconstellationsbase.h +++ b/modules/space/rendering/renderableconstellationsbase.h @@ -105,8 +105,8 @@ private: // The file containing constellation names and abbreviations properties::StringProperty _namesFilename; - // Everything related to the labels are handled by LabelsComponent - std::unique_ptr _labels = nullptr; + // Everything related to the labels is handled by LabelsComponent + std::unique_ptr _labels; }; } // namespace openspace From 8129762524d572e9caf6699f030a58650c5a686f Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 28 Sep 2022 11:14:07 +0200 Subject: [PATCH 77/79] Add loggercat for labelscomponent --- modules/space/labelscomponent.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/space/labelscomponent.cpp b/modules/space/labelscomponent.cpp index 56a31db433..5d6a6572d6 100644 --- a/modules/space/labelscomponent.cpp +++ b/modules/space/labelscomponent.cpp @@ -34,6 +34,8 @@ #include namespace { + constexpr std::string_view _loggerCat = "LabelsComponent"; + constexpr int RenderOptionFaceCamera = 0; constexpr int RenderOptionPositionNormal = 1; @@ -209,7 +211,7 @@ void LabelsComponent::initialize() { } void LabelsComponent::loadLabels() { - LINFOC("LabelsComponent", fmt::format("Loading Label file {}", _labelFile)); + LINFO(fmt::format("Loading label file {}", _labelFile)); _labelset = speck::label::loadFileWithCache(_labelFile); } From 866b37fac3b575198d0cb11431e179e4628e9873 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 28 Sep 2022 12:03:41 +0200 Subject: [PATCH 78/79] Expose ambient intensity value for globes as a property --- modules/globebrowsing/shaders/renderer_fs.glsl | 4 +++- .../globebrowsing/shaders/texturetilemapping.glsl | 4 ++-- modules/globebrowsing/src/renderableglobe.cpp | 14 +++++++++++++- modules/globebrowsing/src/renderableglobe.h | 1 + 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/modules/globebrowsing/shaders/renderer_fs.glsl b/modules/globebrowsing/shaders/renderer_fs.glsl index a066251c90..63a81341f5 100644 --- a/modules/globebrowsing/shaders/renderer_fs.glsl +++ b/modules/globebrowsing/shaders/renderer_fs.glsl @@ -55,6 +55,7 @@ uniform vec3 lightDirectionCameraSpace; #if PERFORM_SHADING uniform float orenNayarRoughness; +uniform float ambientIntensity; #endif // PERFORM_SHADING #if SHADOW_MAPPING_ENABLED @@ -205,7 +206,8 @@ Fragment getFragment() { normal, lightDirectionCameraSpace, normalize(positionCameraSpace), - orenNayarRoughness + orenNayarRoughness, + ambientIntensity ); #endif // PERFORM_SHADING diff --git a/modules/globebrowsing/shaders/texturetilemapping.glsl b/modules/globebrowsing/shaders/texturetilemapping.glsl index 7995291c79..c591d38dcb 100644 --- a/modules/globebrowsing/shaders/texturetilemapping.glsl +++ b/modules/globebrowsing/shaders/texturetilemapping.glsl @@ -374,9 +374,9 @@ vec4 calculateNight(vec4 currentColor, vec2 uv, vec3 levelWeights, vec4 calculateShadedColor(vec4 currentColor, vec3 ellipsoidNormalCameraSpace, vec3 lightDirectionCameraSpace, vec3 viewDirectionCameraSpace, - float roughness) + float roughness, float ambientIntensity) { - vec3 shadedColor = currentColor.rgb * 0.05; + vec3 shadedColor = currentColor.rgb * ambientIntensity; vec3 n = normalize(ellipsoidNormalCameraSpace); diff --git a/modules/globebrowsing/src/renderableglobe.cpp b/modules/globebrowsing/src/renderableglobe.cpp index 2570f96c3c..2144d8739c 100644 --- a/modules/globebrowsing/src/renderableglobe.cpp +++ b/modules/globebrowsing/src/renderableglobe.cpp @@ -222,6 +222,12 @@ namespace { "The roughness factor that is used for the Oren-Nayar lighting mode" }; + constexpr openspace::properties::Property::PropertyInfo AmbientIntensityInfo = { + "AmbientIntensity", + "Ambient Intensity", + "The intensity factor for the ambient light used for light shading" + }; + constexpr openspace::properties::Property::PropertyInfo NActiveLayersInfo = { "NActiveLayers", "Number of active layers", @@ -524,6 +530,7 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary) FloatProperty(TargetLodScaleFactorInfo, 15.f, 1.f, 50.f), FloatProperty(CurrentLodScaleFactorInfo, 15.f, 1.f, 50.f), FloatProperty(OrenNayarRoughnessInfo, 0.f, 0.f, 1.f), + FloatProperty(AmbientIntensityInfo, 0.05f, 0.f, 1.f), IntProperty(NActiveLayersInfo, 0, 0, OpenGLCap.maxTextureUnits() / 3) }) , _debugPropertyOwner({ "Debug" }) @@ -607,6 +614,7 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary) addProperty(_generalProperties.targetLodScaleFactor); addProperty(_generalProperties.currentLodScaleFactor); addProperty(_generalProperties.orenNayarRoughness); + addProperty(_generalProperties.ambientIntensity); _generalProperties.nActiveLayers.setReadOnly(true); addProperty(_generalProperties.nActiveLayers); @@ -964,6 +972,10 @@ void RenderableGlobe::renderChunks(const RenderData& data, RendererTasks&, const float onr = _generalProperties.orenNayarRoughness; _localRenderer.program->setUniform("orenNayarRoughness", onr); _globalRenderer.program->setUniform("orenNayarRoughness", onr); + + const float amb = _generalProperties.ambientIntensity; + _localRenderer.program->setUniform("ambientIntensity", amb); + _globalRenderer.program->setUniform("ambientIntensity", amb); } _localRenderer.program->setUniform("opacity", opacity()); @@ -2271,7 +2283,7 @@ int RenderableGlobe::desiredLevelByAvailableTileData(const Chunk& chunk) const { ZoneScoped const int currLevel = chunk.tileIndex.level; - + for (const layers::Group& gi : layers::Groups) { const std::vector& lyrs = _layerManager.layerGroup(gi.id).activeLayers(); for (Layer* layer : lyrs) { diff --git a/modules/globebrowsing/src/renderableglobe.h b/modules/globebrowsing/src/renderableglobe.h index e25ecae39d..409b9a7441 100644 --- a/modules/globebrowsing/src/renderableglobe.h +++ b/modules/globebrowsing/src/renderableglobe.h @@ -141,6 +141,7 @@ private: properties::FloatProperty targetLodScaleFactor; properties::FloatProperty currentLodScaleFactor; properties::FloatProperty orenNayarRoughness; + properties::FloatProperty ambientIntensity; properties::IntProperty nActiveLayers; } _generalProperties; From ec3a765d1a9d772e8e9db3e6590ebfc76f8bdb8a Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Thu, 6 Oct 2022 17:16:53 +0200 Subject: [PATCH 79/79] Add an empty profile --- data/profiles/empty.profile | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 data/profiles/empty.profile diff --git a/data/profiles/empty.profile b/data/profiles/empty.profile new file mode 100644 index 0000000000..da68f0065a --- /dev/null +++ b/data/profiles/empty.profile @@ -0,0 +1,42 @@ +{ + "assets": [ + "base_blank" + ], + "camera": { + "aim": "", + "anchor": "Root", + "frame": "", + "position": { + "x": 20.0, + "y": 20.0, + "z": 20.0 + }, + "type": "setNavigationState", + "up": { + "x": 0.0, + "y": 1.0, + "z": 0.0 + }, + "yaw": 0.0 + }, + "delta_times": [ + 1.0 + ], + "mark_nodes": [], + "meta": { + "author": "OpenSpace Team", + "description": "An empty profile, without anything special at all.", + "license": "MIT License", + "name": "Empty", + "url": "https://www.openspaceproject.com", + "version": "1.0" + }, + "time": { + "type": "relative", + "value": "-1d" + }, + "version": { + "major": 1, + "minor": 0 + } +} \ No newline at end of file