mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 03:29:44 -06:00
Support relative paths in GeoJSON SpriteTexture (#3761)
This commit is contained in:
@@ -496,8 +496,8 @@ bool GlobeBrowsingModule::hasDefaultGeoPointTexture() const {
|
||||
return _hasDefaultGeoPointTexture;
|
||||
}
|
||||
|
||||
std::string_view GlobeBrowsingModule::defaultGeoPointTexture() const {
|
||||
return _defaultGeoPointTexturePath;
|
||||
std::filesystem::path GlobeBrowsingModule::defaultGeoPointTexture() const {
|
||||
return _defaultGeoPointTexturePath.value();
|
||||
}
|
||||
|
||||
scripting::LuaLibrary GlobeBrowsingModule::luaLibrary() const {
|
||||
|
||||
@@ -90,7 +90,7 @@ public:
|
||||
std::string mrfCacheLocation() const;
|
||||
|
||||
bool hasDefaultGeoPointTexture() const;
|
||||
std::string_view defaultGeoPointTexture() const;
|
||||
std::filesystem::path defaultGeoPointTexture() const;
|
||||
|
||||
protected:
|
||||
void internalInitialize(const ghoul::Dictionary&) override;
|
||||
|
||||
@@ -587,7 +587,7 @@ void GeoJsonComponent::update() {
|
||||
}
|
||||
|
||||
void GeoJsonComponent::readFile() {
|
||||
std::ifstream file(_geoJsonFile);
|
||||
std::ifstream file = std::ifstream(_geoJsonFile);
|
||||
|
||||
if (!file.good()) {
|
||||
LERROR(std::format("Failed to open GeoJSON file: {}", _geoJsonFile.value()));
|
||||
@@ -601,6 +601,14 @@ void GeoJsonComponent::readFile() {
|
||||
std::istreambuf_iterator<char>()
|
||||
);
|
||||
|
||||
// For the loading, we want to assume that the current working directory is where the
|
||||
// GeoJSON file is located
|
||||
const std::filesystem::path cwd = std::filesystem::current_path();
|
||||
std::filesystem::path jsonDir =
|
||||
std::filesystem::path(_geoJsonFile.value()).parent_path();
|
||||
std::filesystem::current_path(jsonDir);
|
||||
defer { std::filesystem::current_path(cwd); };
|
||||
|
||||
// Parse GeoJSON string into GeoJSON objects
|
||||
try {
|
||||
const geos::io::GeoJSONReader reader;
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <modules/globebrowsing/src/renderableglobe.h>
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <geos/io/GeoJSON.h>
|
||||
#include <scn/scan.h>
|
||||
@@ -527,7 +528,8 @@ GeoJsonOverrideProperties propsFromGeoJson(const geos::io::GeoJSONFeature& featu
|
||||
result.pointSize = static_cast<float>(value.getNumber());
|
||||
}
|
||||
else if (keyMatches(key, propertykeys::Texture, PointTextureInfo)) {
|
||||
result.pointTexture = value.getString();
|
||||
std::string texture = value.getString();
|
||||
result.pointTexture = absPath(texture);
|
||||
}
|
||||
else if (keyMatches(key, propertykeys::PointTextureAnchor, PointAnchorOptionInfo))
|
||||
{
|
||||
@@ -628,8 +630,8 @@ float PropertySet::pointSize() const {
|
||||
return overrideValues.pointSize.value_or(defaultValues.pointSize);
|
||||
}
|
||||
|
||||
std::string PropertySet::pointTexture() const {
|
||||
return overrideValues.pointTexture.value_or(defaultValues.pointTexture);
|
||||
std::filesystem::path PropertySet::pointTexture() const {
|
||||
return overrideValues.pointTexture.value_or(defaultValues.pointTexture.value());
|
||||
}
|
||||
|
||||
GeoJsonProperties::PointTextureAnchor PropertySet::pointTextureAnchor() const {
|
||||
|
||||
@@ -107,7 +107,7 @@ struct GeoJsonOverrideProperties {
|
||||
std::optional<float> lineWidth;
|
||||
|
||||
std::optional<float> pointSize;
|
||||
std::optional<std::string> pointTexture;
|
||||
std::optional<std::filesystem::path> pointTexture;
|
||||
std::optional<GeoJsonProperties::PointTextureAnchor> pointTextureAnchor;
|
||||
|
||||
std::optional<bool> extrude;
|
||||
@@ -135,7 +135,7 @@ struct PropertySet {
|
||||
float lineWidth() const;
|
||||
|
||||
float pointSize() const;
|
||||
std::string pointTexture() const;
|
||||
std::filesystem::path pointTexture() const;
|
||||
GeoJsonProperties::PointTextureAnchor pointTextureAnchor() const;
|
||||
|
||||
bool extrude() const;
|
||||
|
||||
@@ -115,7 +115,7 @@ bool GlobeGeometryFeature::useHeightMap() const {
|
||||
}
|
||||
|
||||
void GlobeGeometryFeature::updateTexture(bool isInitializeStep) {
|
||||
std::string texture;
|
||||
std::filesystem::path texture;
|
||||
GlobeBrowsingModule* m = global::moduleEngine->module<GlobeBrowsingModule>();
|
||||
|
||||
if (!isInitializeStep && _properties.hasOverrideTexture()) {
|
||||
@@ -144,15 +144,14 @@ void GlobeGeometryFeature::updateTexture(bool isInitializeStep) {
|
||||
_pointTexture->setWrapping(ghoul::opengl::Texture::WrappingMode::ClampToEdge);
|
||||
}
|
||||
|
||||
std::filesystem::path texturePath = absPath(texture);
|
||||
if (std::filesystem::is_regular_file(texturePath)) {
|
||||
if (std::filesystem::is_regular_file(texture)) {
|
||||
_hasTexture = true;
|
||||
_pointTexture->loadFromFile(texture);
|
||||
_pointTexture->uploadToGpu();
|
||||
}
|
||||
else {
|
||||
LERROR(std::format(
|
||||
"Trying to use texture file that does not exist: {}", texturePath
|
||||
"Trying to use texture file that does not exist: {}", texture
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user