mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-04 10:28:37 -06:00
Merge branch 'thesis/2018/dsn' of github.com:OpenSpace/OpenSpace into thesis/2018/dsn
This commit is contained in:
@@ -15,7 +15,7 @@ asset.require('scene/solarsystem/dsn/testRADEC')
|
||||
asset.require('scene/solarsystem/missions/dsn/spacecrafts')
|
||||
|
||||
--labels
|
||||
asset.request('scene/digitaluniverse/starlabels')
|
||||
--asset.require('scene/digitaluniverse/starlabels')
|
||||
asset.require('scene/solarsystem/dsn/spacecraftslabels')
|
||||
|
||||
-- Stations
|
||||
@@ -100,7 +100,7 @@ asset.onInitialize(function ()
|
||||
openspace.setDefaultGuiSorting()
|
||||
|
||||
openspace.setPropertyValue('Scene.*Trail.Renderable.Enabled', false)
|
||||
--openspace.setPropertyValue('Scene.StarsLabels.Renderable.Enabled', true)
|
||||
|
||||
|
||||
openspace.globebrowsing.loadWMSServersFromFile(
|
||||
openspace.absPath("${DATA}/globebrowsing_servers.lua")
|
||||
|
||||
@@ -4,17 +4,14 @@ local spacecrafts = asset.require('scene/solarsystem/missions/dsn/spacecrafts')
|
||||
local OuterSpaceLabels = {
|
||||
Identifier = "OuterSpaceLabels",
|
||||
Renderable = {
|
||||
Type = "RenderableBillboardsCloud",
|
||||
Enabled = false,
|
||||
--Color = { 1.0, 1.0, 1.0 },
|
||||
Transparency = 1.0,
|
||||
Type = "RenderableLabel",
|
||||
Enabled = true,
|
||||
LabelIdentifierMap = spacecrafts.labelMapVoyagers,
|
||||
TextColor = { 1.0, 0.6, 0.2, 1.0 },
|
||||
DrawLabels = true,
|
||||
TextSize = 10.0,
|
||||
TextMinSize = 1.0,
|
||||
TextMaxSize = 80.0,
|
||||
Unit = "m"
|
||||
},
|
||||
GUI = {
|
||||
Name = "Outer Space Labels",
|
||||
@@ -25,17 +22,14 @@ local OuterSpaceLabels = {
|
||||
local MarsLabels = {
|
||||
Identifier = "MarsLabels",
|
||||
Renderable = {
|
||||
Type = "RenderableBillboardsCloud",
|
||||
Enabled = false,
|
||||
--Color = { 1.0, 1.0, 1.0 },
|
||||
Transparency = 1.0,
|
||||
Type = "RenderableLabel",
|
||||
Enabled = true,
|
||||
LabelIdentifierMap = spacecrafts.labelMapMars,
|
||||
TextColor = { 0.4, 0.4, 0.4, 1.0 },
|
||||
DrawLabels = true,
|
||||
TextSize = 5.0,
|
||||
TextMinSize = 1.0,
|
||||
TextMaxSize = 80.0,
|
||||
Unit = "m"
|
||||
TextMaxSize = 80.0,
|
||||
},
|
||||
GUI = {
|
||||
Name = "Mars Labels",
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#include <openspace/engine/windowdelegate.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <ghoul/filesystem/cachemanager.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/misc/crc32.h>
|
||||
@@ -129,13 +128,6 @@ namespace {
|
||||
"objects being rendered."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo LabelIdentifierMapInfo = {
|
||||
"LabelIdentifierMap",
|
||||
"Label Identifier Map",
|
||||
"The mapping of identifiers to text if we want to attach labels to scenegraphnodes "
|
||||
"instead of reading positions from file. "
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo LabelMinSizeInfo = {
|
||||
"TextMinSize",
|
||||
"Text Min Size",
|
||||
@@ -259,7 +251,7 @@ documentation::Documentation RenderableBillboardsCloud::Documentation() {
|
||||
{
|
||||
keyColor,
|
||||
new Vector3Verifier<float>,
|
||||
Optional::Yes,
|
||||
Optional::No,
|
||||
"Astronomical Object Color (r,g,b)."
|
||||
},
|
||||
{
|
||||
@@ -310,12 +302,6 @@ documentation::Documentation RenderableBillboardsCloud::Documentation() {
|
||||
Optional::Yes,
|
||||
LabelFileInfo.description
|
||||
},
|
||||
{
|
||||
LabelIdentifierMapInfo.identifier,
|
||||
new TableVerifier,
|
||||
Optional::Yes,
|
||||
LabelIdentifierMapInfo.description
|
||||
},
|
||||
{
|
||||
LabelMinSizeInfo.identifier,
|
||||
new DoubleVerifier,
|
||||
@@ -551,42 +537,26 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di
|
||||
_hasPolygon = true;
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(LabelFileInfo.identifier) || dictionary.hasKey(LabelIdentifierMapInfo.identifier)) {
|
||||
|
||||
if (dictionary.hasKey(LabelFileInfo.identifier)) {
|
||||
|
||||
_labelFile = absPath(dictionary.value<std::string>(
|
||||
LabelFileInfo.identifier
|
||||
));
|
||||
_hasLabel = true;
|
||||
_hasLabelFile = true;
|
||||
|
||||
}
|
||||
else if (dictionary.hasKey(LabelIdentifierMapInfo.identifier)) {
|
||||
|
||||
_labelIdMap = dictionary.value<ghoul::Dictionary>(LabelIdentifierMapInfo.identifier);
|
||||
|
||||
_hasLabel = true;
|
||||
_hasLabelIdMap = true;
|
||||
}
|
||||
else {
|
||||
LERROR(fmt::format("Needs a valid {} or {}", LabelIdentifierMapInfo.identifier, LabelFileInfo.identifier));
|
||||
_hasLabel = false;
|
||||
}
|
||||
|
||||
|
||||
if (dictionary.hasKey(LabelFileInfo.identifier)) {
|
||||
if (dictionary.hasKey(DrawLabelInfo.identifier)) {
|
||||
_drawLabels = dictionary.value<bool>(DrawLabelInfo.identifier);
|
||||
}
|
||||
addProperty(_drawLabels);
|
||||
|
||||
_labelFile = absPath(dictionary.value<std::string>(
|
||||
LabelFileInfo.identifier
|
||||
));
|
||||
_hasLabel = true;
|
||||
|
||||
if (dictionary.hasKey(TextColorInfo.identifier)) {
|
||||
_textColor = dictionary.value<glm::vec4>(TextColorInfo.identifier);
|
||||
_hasLabel = true;
|
||||
}
|
||||
_textColor.setViewOption(properties::Property::ViewOptions::Color);
|
||||
addProperty(_textColor);
|
||||
_textColor.onChange([&]() { _textColorIsDirty = true; });
|
||||
|
||||
|
||||
if (dictionary.hasKey(TextSizeInfo.identifier)) {
|
||||
_textSize = dictionary.value<float>(TextSizeInfo.identifier);
|
||||
}
|
||||
@@ -872,14 +842,10 @@ void RenderableBillboardsCloud::renderLabels(const RenderData& data,
|
||||
break;
|
||||
}
|
||||
|
||||
if (_hasLabelIdMap) {
|
||||
_labelData.clear();
|
||||
loadLabelDataFromId();
|
||||
}
|
||||
glm::vec4 textColor = _textColor;
|
||||
textColor.a *= fadeInVariable;
|
||||
textColor.a *= _opacity;
|
||||
for (const std::pair<glm::dvec3, std::string>& pair : _labelData) {
|
||||
for (const std::pair<glm::vec3, std::string>& pair : _labelData) {
|
||||
//glm::vec3 scaledPos(_transformationMatrix * glm::dvec4(pair.first, 1.0));
|
||||
glm::vec3 scaledPos(pair.first);
|
||||
scaledPos *= scale;
|
||||
@@ -1090,25 +1056,17 @@ void RenderableBillboardsCloud::update(const UpdateData&) {
|
||||
bool RenderableBillboardsCloud::loadData() {
|
||||
bool success = true;
|
||||
|
||||
if (_hasLabelFile) {
|
||||
|
||||
success &= loadSpeckData();
|
||||
success &= loadSpeckData();
|
||||
|
||||
if (_hasColorMapFile) {
|
||||
if (!_hasSpeckFile) {
|
||||
success = true;
|
||||
}
|
||||
success &= readColorMapFile();
|
||||
if (_hasColorMapFile) {
|
||||
if (!_hasSpeckFile) {
|
||||
success = true;
|
||||
}
|
||||
|
||||
success &= loadLabelDataFromFile();
|
||||
|
||||
success &= readColorMapFile();
|
||||
}
|
||||
|
||||
if (_hasLabelIdMap) {
|
||||
success &= loadLabelData();
|
||||
|
||||
success &= loadLabelDataFromId();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -1153,7 +1111,7 @@ bool RenderableBillboardsCloud::loadSpeckData() {
|
||||
return success;
|
||||
}
|
||||
|
||||
bool RenderableBillboardsCloud::loadLabelDataFromFile() {
|
||||
bool RenderableBillboardsCloud::loadLabelData() {
|
||||
bool success = true;
|
||||
if (!_labelFile.empty()) {
|
||||
// I disabled the cache as it didn't work on Mac --- abock
|
||||
@@ -1330,36 +1288,6 @@ bool RenderableBillboardsCloud::readColorMapFile() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderableBillboardsCloud::loadLabelDataFromId() {
|
||||
|
||||
std::vector<std::string> keys = _labelIdMap.keys();
|
||||
|
||||
std::string id = "";
|
||||
|
||||
for (int i = 0; i < keys.size(); i++)
|
||||
{
|
||||
id = keys.at(i);
|
||||
std::string label = _labelIdMap.value<std::string>(keys.at(i));
|
||||
|
||||
if (global::renderEngine.scene()->sceneGraphNode(id)) {
|
||||
glm::dvec3 position = global::renderEngine.scene()->sceneGraphNode(id)->worldPosition();
|
||||
|
||||
glm::dvec3 transformedPos = glm::dvec3(
|
||||
_transformationMatrix * glm::dvec4(position, 1.0)
|
||||
);
|
||||
_labelData.emplace_back(std::make_pair(transformedPos, label));
|
||||
|
||||
}
|
||||
else {
|
||||
LERROR(fmt::format("No SceneGraphNode found with identifier {}", id));
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderableBillboardsCloud::readLabelFile() {
|
||||
std::string _file = _labelFile;
|
||||
std::ifstream file(_file);
|
||||
|
||||
@@ -90,8 +90,7 @@ private:
|
||||
|
||||
bool loadData();
|
||||
bool loadSpeckData();
|
||||
bool loadLabelDataFromFile();
|
||||
bool loadLabelDataFromId();
|
||||
bool loadLabelData();
|
||||
bool readSpeckFile();
|
||||
bool readColorMapFile();
|
||||
bool readLabelFile();
|
||||
@@ -106,8 +105,6 @@ private:
|
||||
bool _hasColorMapFile = false;
|
||||
bool _hasPolygon = false;
|
||||
bool _hasLabel = false;
|
||||
bool _hasLabelFile = false;
|
||||
bool _hasLabelIdMap = false;
|
||||
|
||||
int _polygonSides = 0;
|
||||
|
||||
@@ -127,7 +124,7 @@ private:
|
||||
properties::Vec2Property _fadeInDistance;
|
||||
properties::BoolProperty _disableFadeInDistance;
|
||||
properties::FloatProperty _billboardMaxSize;
|
||||
properties::FloatProperty _billboardMinSize;
|
||||
properties::FloatProperty _billboardMinSize;
|
||||
properties::FloatProperty _correctionSizeEndDistance;
|
||||
properties::FloatProperty _correctionSizeFactor;
|
||||
|
||||
@@ -150,7 +147,6 @@ private:
|
||||
std::string _colorMapFile;
|
||||
std::string _labelFile;
|
||||
std::string _colorOptionString;
|
||||
ghoul::Dictionary _labelIdMap;
|
||||
|
||||
Unit _unit = Parsec;
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake)
|
||||
|
||||
set(HEADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablesignals.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablelabel.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/translation/radectranslation.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/managers/signalmanager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/managers/radecmanager.h
|
||||
@@ -35,6 +36,7 @@ source_group("Header Files" FILES ${HEADER_FILES})
|
||||
|
||||
set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablesignals.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablelabel.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/translation/radectranslation.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/managers/signalmanager.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/managers/radecmanager.cpp
|
||||
|
||||
@@ -31,15 +31,16 @@ namespace openspace {
|
||||
}
|
||||
|
||||
void DsnModule::internalInitialize(const ghoul::Dictionary&) {
|
||||
auto factory = FactoryManager::ref().factory<Renderable>();
|
||||
ghoul_assert(factory, "No renderable factory existed");
|
||||
auto renderableFactory = FactoryManager::ref().factory<Renderable>();
|
||||
ghoul_assert(renderableFactory, "No renderable factory existed");
|
||||
|
||||
factory->registerClass<RenderableSignals>("RenderableSignals");
|
||||
renderableFactory->registerClass<RenderableSignals>("RenderableSignals");
|
||||
renderableFactory->registerClass<RenderableLabel>("RenderableLabel");
|
||||
|
||||
auto fTranslation = FactoryManager::ref().factory<Translation>();
|
||||
ghoul_assert(fTranslation, "Translation factory was not created");
|
||||
auto translationFactory = FactoryManager::ref().factory<Translation>();
|
||||
ghoul_assert(translationFactory, "Translation factory was not created");
|
||||
|
||||
fTranslation->registerClass<RadecTranslation>("RadecTranslation");
|
||||
translationFactory->registerClass<RadecTranslation>("RadecTranslation");
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
|
||||
#include <modules/dsn/translation/radectranslation.h>
|
||||
#include <modules/dsn/rendering/renderablesignals.h>
|
||||
#include <modules/dsn/rendering/renderablelabel.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace openspace {
|
||||
mutable std::vector<Position> positions;
|
||||
mutable std::vector<double> minuteTimes;
|
||||
mutable Position position;
|
||||
|
||||
mutable double updateFrequency = 1;
|
||||
mutable double activeMinute = -1;
|
||||
/* Identifier for object using the translation, used for logging */
|
||||
@@ -81,4 +82,4 @@ namespace openspace {
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // __OPENSPACE_MODULE_DSN___RADECMANAGER___H__
|
||||
|
||||
457
modules/dsn/rendering/renderablelabel.cpp
Normal file
457
modules/dsn/rendering/renderablelabel.cpp
Normal file
@@ -0,0 +1,457 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2018 *
|
||||
* *
|
||||
* 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 <modules/dsn/rendering/renderablelabel.h>
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/engine/windowdelegate.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/font/fontmanager.h>
|
||||
#include <ghoul/font/fontrenderer.h>
|
||||
#include <ghoul/glm.h>
|
||||
|
||||
namespace {
|
||||
constexpr const char* _loggerCat = "RenderableLabel";
|
||||
constexpr const char* ProgramObjectName = "RenderableLabel";
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo LabelIdentifierMapInfo = {
|
||||
"LabelIdentifierMap",
|
||||
"Label Identifier Map",
|
||||
"The mapping of identifiers to text if we want to attach labels to scenegraphnodes "
|
||||
"instead of reading positions from file. "
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo ScaleFactorInfo = {
|
||||
"ScaleFactor",
|
||||
"Scale Factor",
|
||||
"This value is used as a multiplicative factor that is applied to the apparent "
|
||||
"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 TextSizeInfo = {
|
||||
"TextSize",
|
||||
"Text Size",
|
||||
"The text size for the astronomical object labels."
|
||||
};
|
||||
|
||||
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."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo DrawLabelInfo = {
|
||||
"DrawLabels",
|
||||
"Draw Labels",
|
||||
"Determines whether labels should be drawn or hidden."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo TransformationMatrixInfo = {
|
||||
"TransformationMatrix",
|
||||
"Transformation Matrix",
|
||||
"Transformation matrix to be applied to each astronomical object."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo RenderOptionInfo = {
|
||||
"RenderOption",
|
||||
"Render Option",
|
||||
"Debug option for rendering of billboards and texts."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo FadeInDistancesInfo = {
|
||||
"FadeInDistances",
|
||||
"Fade-In Start and End Distances",
|
||||
"These values determine the initial and final distances from the center of "
|
||||
"our galaxy from which the astronomical object will start and end "
|
||||
"fading-in."
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo DisableFadeInInfo = {
|
||||
"DisableFadeIn",
|
||||
"Disable Fade-in effect",
|
||||
"Enables/Disables the Fade-in effect."
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
|
||||
documentation::Documentation RenderableLabel::Documentation() {
|
||||
using namespace documentation;
|
||||
return {
|
||||
"RenderableLabel",
|
||||
"dsn_renderable_renderablelabel",
|
||||
{
|
||||
{
|
||||
"Type",
|
||||
new StringEqualVerifier("RenderableLabel"),
|
||||
Optional::No
|
||||
},
|
||||
{
|
||||
LabelIdentifierMapInfo.identifier,
|
||||
new TableVerifier,
|
||||
Optional::No,
|
||||
LabelIdentifierMapInfo.description
|
||||
},
|
||||
{
|
||||
ScaleFactorInfo.identifier,
|
||||
new DoubleVerifier,
|
||||
Optional::Yes,
|
||||
ScaleFactorInfo.description
|
||||
},
|
||||
{
|
||||
DrawLabelInfo.identifier,
|
||||
new BoolVerifier,
|
||||
Optional::Yes,
|
||||
DrawLabelInfo.description
|
||||
},
|
||||
{
|
||||
TextColorInfo.identifier,
|
||||
new DoubleVector4Verifier,
|
||||
Optional::Yes,
|
||||
TextColorInfo.description
|
||||
},
|
||||
{
|
||||
TextSizeInfo.identifier,
|
||||
new DoubleVerifier,
|
||||
Optional::Yes,
|
||||
TextSizeInfo.description
|
||||
},
|
||||
{
|
||||
LabelMinSizeInfo.identifier,
|
||||
new DoubleVerifier,
|
||||
Optional::Yes,
|
||||
LabelMinSizeInfo.description
|
||||
},
|
||||
{
|
||||
LabelMaxSizeInfo.identifier,
|
||||
new DoubleVerifier,
|
||||
Optional::Yes,
|
||||
LabelMaxSizeInfo.description
|
||||
},
|
||||
{
|
||||
FadeInDistancesInfo.identifier,
|
||||
new Vector2Verifier<double>,
|
||||
Optional::Yes,
|
||||
FadeInDistancesInfo.description
|
||||
},
|
||||
{
|
||||
DisableFadeInInfo.identifier,
|
||||
new BoolVerifier,
|
||||
Optional::Yes,
|
||||
DisableFadeInInfo.description
|
||||
},
|
||||
{
|
||||
TransformationMatrixInfo.identifier,
|
||||
new Matrix4x4Verifier<double>,
|
||||
Optional::Yes,
|
||||
TransformationMatrixInfo.description
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
RenderableLabel::RenderableLabel(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _scaleFactor(ScaleFactorInfo, 10.f, 0.f, 600.f)
|
||||
, _textColor(
|
||||
TextColorInfo,
|
||||
glm::vec4(1.0f, 1.0, 1.0f, 1.f),
|
||||
glm::vec4(0.f),
|
||||
glm::vec4(1.f)
|
||||
)
|
||||
, _textSize(TextSizeInfo, 8.0, 0.5, 24.0)
|
||||
, _textMinSize(LabelMinSizeInfo, 8.f, 0.5f, 24.f)
|
||||
, _textMaxSize(LabelMaxSizeInfo, 20.f, 0.5f, 100.f)
|
||||
, _drawLabels(DrawLabelInfo, false)
|
||||
, _fadeInDistance(
|
||||
FadeInDistancesInfo,
|
||||
glm::vec2(0.0f),
|
||||
glm::vec2(0.0),
|
||||
glm::vec2(100.0)
|
||||
)
|
||||
, _disableFadeInDistance(DisableFadeInInfo, true)
|
||||
, _renderOption(RenderOptionInfo, properties::OptionProperty::DisplayType::Dropdown)
|
||||
{
|
||||
documentation::testSpecificationAndThrow(
|
||||
Documentation(),
|
||||
dictionary,
|
||||
"RenderableLabel"
|
||||
);
|
||||
|
||||
// DEBUG:
|
||||
_renderOption.addOption(0, "Camera View Direction");
|
||||
_renderOption.addOption(1, "Camera Position Normal");
|
||||
_renderOption.set(1);
|
||||
if (global::windowDelegate.isFisheyeRendering()) {
|
||||
_renderOption.set(1);
|
||||
}
|
||||
else {
|
||||
_renderOption.set(0);
|
||||
}
|
||||
addProperty(_renderOption);
|
||||
|
||||
if (dictionary.hasKey(ScaleFactorInfo.identifier)) {
|
||||
_scaleFactor = static_cast<float>(
|
||||
dictionary.value<double>(ScaleFactorInfo.identifier)
|
||||
);
|
||||
}
|
||||
addProperty(_scaleFactor);
|
||||
|
||||
if (dictionary.hasKey(LabelIdentifierMapInfo.identifier)) {
|
||||
|
||||
_labelIdMap = dictionary.value<ghoul::Dictionary>(LabelIdentifierMapInfo.identifier);
|
||||
|
||||
_hasLabel = true;
|
||||
_hasLabelIdMap = true;
|
||||
|
||||
if (dictionary.hasKey(DrawLabelInfo.identifier)) {
|
||||
_drawLabels = dictionary.value<bool>(DrawLabelInfo.identifier);
|
||||
}
|
||||
addProperty(_drawLabels);
|
||||
|
||||
if (dictionary.hasKey(TextColorInfo.identifier)) {
|
||||
_textColor = dictionary.value<glm::vec4>(TextColorInfo.identifier);
|
||||
}
|
||||
_textColor.setViewOption(properties::Property::ViewOptions::Color);
|
||||
addProperty(_textColor);
|
||||
_textColor.onChange([&]() { _textColorIsDirty = true; });
|
||||
|
||||
if (dictionary.hasKey(TextSizeInfo.identifier)) {
|
||||
_textSize = dictionary.value<float>(TextSizeInfo.identifier);
|
||||
}
|
||||
addProperty(_textSize);
|
||||
|
||||
if (dictionary.hasKey(LabelMinSizeInfo.identifier)) {
|
||||
_textMinSize = dictionary.value<float>(LabelMinSizeInfo.identifier);
|
||||
}
|
||||
addProperty(_textMinSize);
|
||||
|
||||
if (dictionary.hasKey(LabelMaxSizeInfo.identifier)) {
|
||||
_textMaxSize = dictionary.value<float>(LabelMaxSizeInfo.identifier);
|
||||
}
|
||||
addProperty(_textMaxSize);
|
||||
}
|
||||
else {
|
||||
LERROR(fmt::format("Needs a valid {}", LabelIdentifierMapInfo.identifier));
|
||||
_hasLabel = false;
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(TransformationMatrixInfo.identifier)) {
|
||||
_transformationMatrix = dictionary.value<glm::dmat4>(
|
||||
TransformationMatrixInfo.identifier
|
||||
);
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(FadeInDistancesInfo.identifier)) {
|
||||
glm::vec2 fadeInValue = dictionary.value<glm::vec2>(
|
||||
FadeInDistancesInfo.identifier
|
||||
);
|
||||
_fadeInDistance.set(fadeInValue);
|
||||
_disableFadeInDistance.set(false);
|
||||
}
|
||||
addProperty(_fadeInDistance);
|
||||
addProperty(_disableFadeInDistance);
|
||||
}
|
||||
|
||||
bool RenderableLabel::isReady() const {
|
||||
return ( !_labelData.empty() );
|
||||
}
|
||||
|
||||
void RenderableLabel::initialize() {
|
||||
bool success = loadData();
|
||||
if (!success) {
|
||||
throw ghoul::RuntimeError("Error loading data");
|
||||
}
|
||||
}
|
||||
|
||||
void RenderableLabel::initializeGL() {
|
||||
|
||||
if (_hasLabel) {
|
||||
if (_font == nullptr) {
|
||||
size_t _fontSize = 50;
|
||||
_font = global::fontManager.font(
|
||||
"Mono",
|
||||
static_cast<float>(_fontSize),
|
||||
ghoul::fontrendering::FontManager::Outline::Yes,
|
||||
ghoul::fontrendering::FontManager::LoadGlyphs::No
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RenderableLabel::renderLabels(const RenderData& data,
|
||||
const glm::dmat4& modelViewProjectionMatrix,
|
||||
const glm::dvec3& orthoRight,
|
||||
const glm::dvec3& orthoUp,
|
||||
float fadeInVariable)
|
||||
{
|
||||
float scale = 1.f;
|
||||
|
||||
if (_hasLabelIdMap) {
|
||||
_labelData.clear();
|
||||
loadLabelDataFromId();
|
||||
}
|
||||
glm::vec4 textColor = _textColor;
|
||||
textColor.a *= fadeInVariable;
|
||||
|
||||
for (const std::pair<glm::dvec3, std::string>& pair : _labelData) {
|
||||
//glm::vec3 scaledPos(_transformationMatrix * glm::dvec4(pair.first, 1.0));
|
||||
glm::vec3 scaledPos(pair.first);
|
||||
scaledPos *= scale;
|
||||
ghoul::fontrendering::FontRenderer::defaultProjectionRenderer().render(
|
||||
*_font,
|
||||
scaledPos,
|
||||
pair.second,
|
||||
textColor,
|
||||
pow(_scaleFactor, _textSize.value()),
|
||||
static_cast<int>(_textMinSize),
|
||||
static_cast<int>(_textMaxSize),
|
||||
modelViewProjectionMatrix,
|
||||
orthoRight,
|
||||
orthoUp,
|
||||
data.camera.positionVec3(),
|
||||
data.camera.lookUpVectorWorldSpace(),
|
||||
_renderOption.value()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderableLabel::render(const RenderData& data, RendererTasks&) {
|
||||
|
||||
float scale = 1.f;
|
||||
|
||||
float fadeInVariable = 1.f;
|
||||
if (!_disableFadeInDistance) {
|
||||
float distCamera = static_cast<float>(glm::length(data.camera.positionVec3()));
|
||||
const glm::vec2 fadeRange = _fadeInDistance;
|
||||
const float a = 1.f / ((fadeRange.y - fadeRange.x) * scale);
|
||||
const float b = -(fadeRange.x / (fadeRange.y - fadeRange.x));
|
||||
const float funcValue = a * distCamera + b;
|
||||
fadeInVariable *= funcValue > 1.f ? 1.f : funcValue;
|
||||
|
||||
if (funcValue < 0.01f) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
glm::dmat4 modelViewMatrix = data.camera.combinedViewMatrix() * modelMatrix;
|
||||
glm::mat4 projectionMatrix = data.camera.projectionMatrix();
|
||||
|
||||
glm::dmat4 modelViewProjectionMatrix = glm::dmat4(projectionMatrix) * modelViewMatrix;
|
||||
|
||||
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)
|
||||
);
|
||||
|
||||
if (_drawLabels && _hasLabel) {
|
||||
renderLabels(
|
||||
data,
|
||||
modelViewProjectionMatrix,
|
||||
orthoRight,
|
||||
orthoUp,
|
||||
fadeInVariable
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
bool RenderableLabel::loadData() {
|
||||
bool success = true;
|
||||
|
||||
if (_hasLabelIdMap) {
|
||||
|
||||
success &= loadLabelDataFromId();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
bool RenderableLabel::loadLabelDataFromId() {
|
||||
|
||||
std::vector<std::string> keys = _labelIdMap.keys();
|
||||
|
||||
std::string id = "";
|
||||
|
||||
for (int i = 0; i < keys.size(); i++)
|
||||
{
|
||||
id = keys.at(i);
|
||||
std::string label = _labelIdMap.value<std::string>(keys.at(i));
|
||||
|
||||
if (global::renderEngine.scene()->sceneGraphNode(id)) {
|
||||
glm::dvec3 position = global::renderEngine.scene()->sceneGraphNode(id)->worldPosition();
|
||||
|
||||
glm::dvec3 transformedPos = glm::dvec3(
|
||||
_transformationMatrix * glm::dvec4(position, 1.0)
|
||||
);
|
||||
_labelData.emplace_back(std::make_pair(transformedPos, label));
|
||||
|
||||
}
|
||||
else {
|
||||
LERROR(fmt::format("No SceneGraphNode found with identifier {}", id));
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
101
modules/dsn/rendering/renderablelabel.h
Normal file
101
modules/dsn/rendering/renderablelabel.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2018 *
|
||||
* *
|
||||
* 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_DSN___RENDERABLELABEL___H__
|
||||
#define __OPENSPACE_MODULE_DSN___RENDERABLELABEL___H__
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
#include <openspace/properties/vector/vec2property.h>
|
||||
#include <openspace/properties/vector/vec3property.h>
|
||||
#include <openspace/properties/vector/vec4property.h>
|
||||
|
||||
namespace ghoul::fontrendering { class Font; }
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace documentation { struct Documentation; }
|
||||
|
||||
class RenderableLabel: public Renderable {
|
||||
public:
|
||||
explicit RenderableLabel(const ghoul::Dictionary& dictionary);
|
||||
~RenderableLabel() = default;
|
||||
|
||||
void initialize() override;
|
||||
void initializeGL() 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 Unit {
|
||||
// Meter = 0,
|
||||
// Kilometer = 1,
|
||||
// Parsec = 2,
|
||||
// Kiloparsec = 3,
|
||||
// Megaparsec = 4,
|
||||
// Gigaparsec = 5,
|
||||
// GigalightYears = 6
|
||||
//};
|
||||
|
||||
void renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix,
|
||||
const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, float fadeInVariable);
|
||||
|
||||
bool loadData();
|
||||
bool loadLabelDataFromId();
|
||||
|
||||
bool _dataIsDirty = true;
|
||||
bool _textColorIsDirty = true;
|
||||
bool _hasLabel = false;
|
||||
bool _hasLabelIdMap = false;
|
||||
|
||||
properties::FloatProperty _scaleFactor;
|
||||
properties::Vec4Property _textColor;
|
||||
properties::FloatProperty _textSize;
|
||||
properties::FloatProperty _textMinSize;
|
||||
properties::FloatProperty _textMaxSize;
|
||||
properties::BoolProperty _drawLabels;
|
||||
properties::Vec2Property _fadeInDistance;
|
||||
properties::BoolProperty _disableFadeInDistance;
|
||||
|
||||
// DEBUG:
|
||||
properties::OptionProperty _renderOption;
|
||||
|
||||
std::shared_ptr<ghoul::fontrendering::Font> _font;
|
||||
ghoul::Dictionary _labelIdMap;
|
||||
std::vector<std::pair<glm::vec3, std::string>> _labelData;
|
||||
glm::dmat4 _transformationMatrix = glm::dmat4(1.0);
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_DSN___RENDERABLELABEL___H__s
|
||||
Reference in New Issue
Block a user