Remove legacy geometry specification from RenderablePlanetProjection (closes 1967) (#2181)

* Remove planet geometry and simplespheregeometry
* Fix RenderablePlanetProjection specification
This commit is contained in:
Alexander Bock
2022-07-15 21:47:29 +02:00
committed by GitHub
parent 5f194b18eb
commit bbc20062db
10 changed files with 59 additions and 358 deletions
@@ -29,11 +29,8 @@ local CharonProjection = {
},
Renderable = {
Type = "RenderablePlanetProjection",
Geometry = {
Type = "SimpleSphere",
Radius = charonRadius,
Segments = 350
},
Radius = charonRadius,
Segments = 350,
ColorTexturePaths = {
textures .. "NH_Charon_mosaic.png",
textures .. "NH_Charon_mosaic_8192.png"
@@ -51,11 +51,7 @@ local PlutoProjection = {
Renderable = {
Type = "RenderablePlanetProjection",
Radius = plutoRadius,
Geometry = {
Type = "SimpleSphere",
Radius = plutoRadius,
Segments = 400
},
Segments = 400,
ColorTexturePaths = {
textures .. "pluto.png",
textures .. "NH_Pluto_mosaic_16384.png",
-4
View File
@@ -27,7 +27,6 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake)
set(HEADER_FILES
horizonsfile.h
speckloader.h
rendering/planetgeometry.h
rendering/renderableconstellationbounds.h
rendering/renderablefluxnodes.h
rendering/renderablehabitablezone.h
@@ -37,7 +36,6 @@ set(HEADER_FILES
rendering/renderablesmallbody.h
rendering/renderablestars.h
rendering/renderabletravelspeed.h
rendering/simplespheregeometry.h
translation/keplertranslation.h
translation/spicetranslation.h
translation/tletranslation.h
@@ -50,7 +48,6 @@ set(SOURCE_FILES
horizonsfile.cpp
spacemodule_lua.inl
speckloader.cpp
rendering/planetgeometry.cpp
rendering/renderableconstellationbounds.cpp
rendering/renderablefluxnodes.cpp
rendering/renderablehabitablezone.cpp
@@ -60,7 +57,6 @@ set(SOURCE_FILES
rendering/renderablesmallbody.cpp
rendering/renderablestars.cpp
rendering/renderabletravelspeed.cpp
rendering/simplespheregeometry.cpp
translation/keplertranslation.cpp
translation/spicetranslation.cpp
translation/tletranslation.cpp
@@ -1,64 +0,0 @@
/*****************************************************************************************
* *
* 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 <modules/space/rendering/planetgeometry.h>
#include <openspace/documentation/documentation.h>
#include <openspace/documentation/verifier.h>
#include <openspace/util/factorymanager.h>
#include <ghoul/misc/templatefactory.h>
namespace {
struct [[codegen::Dictionary(PlanetGeometry)]] Parameters {
// The type of the PlanetGeometry that will can be constructed
std::string type;
};
#include "planetgeometry_codegen.cpp"
} // namespace
namespace openspace::planetgeometry {
documentation::Documentation PlanetGeometry::Documentation() {
return codegen::doc<Parameters>("space_geometry_planet");
}
std::unique_ptr<PlanetGeometry> PlanetGeometry::createFromDictionary(
const ghoul::Dictionary& dictionary)
{
const Parameters p = codegen::bake<Parameters>(dictionary);
ghoul::TemplateFactory<PlanetGeometry>* factory =
FactoryManager::ref().factory<PlanetGeometry>();
PlanetGeometry* result = factory->create(p.type, dictionary);
return std::unique_ptr<PlanetGeometry>(result);
}
PlanetGeometry::PlanetGeometry() : properties::PropertyOwner({ "PlanetGeometry" }) {}
void PlanetGeometry::initialize() {}
void PlanetGeometry::deinitialize() {}
} // namespace openspace::planetgeometry
-58
View File
@@ -1,58 +0,0 @@
/*****************************************************************************************
* *
* 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___PLANETGEOMETRY___H__
#define __OPENSPACE_MODULE_SPACE___PLANETGEOMETRY___H__
#include <openspace/properties/propertyowner.h>
#include <ghoul/glm.h>
#include <memory>
namespace ghoul { class Dictionary; }
namespace openspace { class Renderable; }
namespace openspace::documentation { struct Documentation; }
namespace openspace::planetgeometry {
class PlanetGeometry : public properties::PropertyOwner {
public:
static std::unique_ptr<PlanetGeometry> createFromDictionary(
const ghoul::Dictionary& dictionary
);
PlanetGeometry();
~PlanetGeometry() override = default;
virtual void initialize();
virtual void deinitialize();
virtual void render() = 0;
virtual float boundingSphere() const = 0;
static documentation::Documentation Documentation();
};
} // namespace openspace::planetgeometry
#endif // __OPENSPACE_MODULE_SPACE___PLANETGEOMETRY___H__
@@ -1,116 +0,0 @@
/****************************************************************************************
* *
* 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 <modules/space/rendering/simplespheregeometry.h>
#include <openspace/documentation/verifier.h>
#include <openspace/rendering/renderable.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/util/sphere.h>
namespace {
constexpr openspace::properties::Property::PropertyInfo RadiusInfo = {
"Radius",
"Radius",
"This value specifies the radius of this sphere in meters."
};
constexpr openspace::properties::Property::PropertyInfo SegmentsInfo = {
"Segments",
"Segments",
"This value specifies the number of segments that this sphere is split into."
};
struct [[codegen::Dictionary(SimpleSphereGeometry)]] Parameters {
// [[codegen::verbatim(RadiusInfo.description)]]
std::variant<float, glm::vec3> radius;
// [[codegen::verbatim(SegmentsInfo.description)]]
int segments;
};
#include "simplespheregeometry_codegen.cpp"
} // namespace
namespace openspace::planetgeometry {
documentation::Documentation SimpleSphereGeometry::Documentation() {
return codegen::doc<Parameters>("space_geometry_simplesphere");
}
SimpleSphereGeometry::SimpleSphereGeometry(const ghoul::Dictionary& dictionary)
: _radius(RadiusInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(std::pow(10.f, 20.f)))
, _segments(SegmentsInfo, 20, 1, 5000)
, _sphere(nullptr)
{
const Parameters p = codegen::bake<Parameters>(dictionary);
if (std::holds_alternative<float>(p.radius)) {
const float radius = std::get<float>(p.radius);
_radius = glm::dvec3(radius, radius, radius);
}
else {
_radius = std::get<glm::vec3>(p.radius);
}
_segments = p.segments;
// The shader need the radii values but they are not changeable runtime
// TODO: Possibly add a scaling property @AA
// Changing the radius/scaling should affect the shader but not the geometry? @AA
_radius.onChange([&]() { createSphere(); });
addProperty(_radius);
_segments.onChange([&]() { createSphere(); });
addProperty(_segments);
}
SimpleSphereGeometry::~SimpleSphereGeometry() {} // NOLINT
void SimpleSphereGeometry::initialize() {
createSphere();
}
void SimpleSphereGeometry::deinitialize() {
delete _sphere;
_sphere = nullptr;
}
void SimpleSphereGeometry::render() {
_sphere->render();
}
float SimpleSphereGeometry::boundingSphere() const {
const glm::vec3 radius = _radius;
return std::max(std::max(radius[0], radius[1]), radius[2]);
}
void SimpleSphereGeometry::createSphere() {
const glm::vec3 radius = _radius.value();
delete _sphere;
_sphere = new Sphere(radius, _segments);
_sphere->initialize();
}
} // namespace openspace::planetgeometry
@@ -1,65 +0,0 @@
/*****************************************************************************************
* *
* 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___SIMPLESPHEREGEOMETRY___H__
#define __OPENSPACE_MODULE_SPACE___SIMPLESPHEREGEOMETRY___H__
#include <modules/space/rendering/planetgeometry.h>
#include <openspace/properties/scalar/intproperty.h>
#include <openspace/properties/vector/vec3property.h>
namespace openspace {
class Renderable;
class Sphere;
} // namespace openspace
namespace openspace::documentation { struct Documentation; }
namespace openspace::planetgeometry {
class SimpleSphereGeometry : public PlanetGeometry {
public:
SimpleSphereGeometry(const ghoul::Dictionary& dictionary);
~SimpleSphereGeometry() override;
void initialize() override;
void deinitialize() override;
void render() override;
float boundingSphere() const override;
static documentation::Documentation Documentation();
private:
void createSphere();
properties::Vec3Property _radius;
properties::IntProperty _segments;
Sphere* _sphere;
};
} // namespace openspace::planetgeometry
#endif // __OPENSPACE_MODULE_SPACE___SIMPLESPHEREGEOMETRY___H__
-10
View File
@@ -32,7 +32,6 @@
#include <modules/space/rendering/renderablesmallbody.h>
#include <modules/space/rendering/renderablestars.h>
#include <modules/space/rendering/renderabletravelspeed.h>
#include <modules/space/rendering/simplespheregeometry.h>
#include <modules/space/translation/keplertranslation.h>
#include <modules/space/translation/spicetranslation.h>
#include <modules/space/translation/tletranslation.h>
@@ -74,8 +73,6 @@ SpaceModule::SpaceModule()
}
void SpaceModule::internalInitialize(const ghoul::Dictionary& dictionary) {
FactoryManager::ref().addFactory<planetgeometry::PlanetGeometry>("PlanetGeometry");
ghoul::TemplateFactory<Renderable>* fRenderable =
FactoryManager::ref().factory<Renderable>();
ghoul_assert(fRenderable, "Renderable factory was not created");
@@ -106,11 +103,6 @@ void SpaceModule::internalInitialize(const ghoul::Dictionary& dictionary) {
fRotation->registerClass<SpiceRotation>("SpiceRotation");
ghoul::TemplateFactory<planetgeometry::PlanetGeometry>* fGeometry =
FactoryManager::ref().factory<planetgeometry::PlanetGeometry>();
ghoul_assert(fGeometry, "Planet geometry factory was not created");
fGeometry->registerClass<planetgeometry::SimpleSphereGeometry>("SimpleSphere");
if (dictionary.hasValue<bool>(SpiceExceptionInfo.identifier)) {
_showSpiceExceptions = dictionary.value<bool>(SpiceExceptionInfo.identifier);
}
@@ -124,7 +116,6 @@ std::vector<documentation::Documentation> SpaceModule::documentations() const {
return {
HorizonsTranslation::Documentation(),
KeplerTranslation::Documentation(),
planetgeometry::PlanetGeometry::Documentation(),
RenderableConstellationBounds::Documentation(),
RenderableFluxNodes::Documentation(),
RenderableHabitableZone::Documentation(),
@@ -133,7 +124,6 @@ std::vector<documentation::Documentation> SpaceModule::documentations() const {
RenderableSmallBody::Documentation(),
RenderableStars::Documentation(),
RenderableTravelSpeed::Documentation(),
planetgeometry::SimpleSphereGeometry::Documentation(),
SpiceRotation::Documentation(),
SpiceTranslation::Documentation(),
TLETranslation::Documentation()
@@ -24,13 +24,13 @@
#include <modules/spacecraftinstruments/rendering/renderableplanetprojection.h>
#include <modules/space/rendering/planetgeometry.h>
#include <modules/spacecraftinstruments/spacecraftinstrumentsmodule.h>
#include <modules/spacecraftinstruments/util/image.h>
#include <modules/spacecraftinstruments/util/imagesequencer.h>
#include <openspace/documentation/documentation.h>
#include <openspace/engine/globals.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/util/sphere.h>
#include <openspace/util/updatestructures.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/io/texture/texturereader.h>
@@ -130,10 +130,19 @@ namespace {
"Remove all pending projections from the buffer"
};
struct [[codegen::Dictionary(RenderablePlanetProjection)]] Parameters {
// The geometry that is used for rendering this planet
ghoul::Dictionary geometry [[codegen::reference("space_geometry_planet")]];
constexpr openspace::properties::Property::PropertyInfo RadiusInfo = {
"Radius",
"Radius",
"This value specifies the radius of this sphere in meters."
};
constexpr openspace::properties::Property::PropertyInfo SegmentsInfo = {
"Segments",
"Segments",
"This value specifies the number of segments that this sphere is split into."
};
struct [[codegen::Dictionary(RenderablePlanetProjection)]] Parameters {
// Contains information about projecting onto this planet
ghoul::Dictionary projection
[[codegen::reference("spacecraftinstruments_projectioncomponent")]];
@@ -155,6 +164,12 @@ namespace {
// [[codegen::verbatim(MaxProjectionsPerFrameInfo.description)]]
std::optional<int> maxProjectionsPerFrame;
// [[codegen::verbatim(RadiusInfo.description)]]
std::variant<float, glm::vec3> radius;
// [[codegen::verbatim(SegmentsInfo.description)]]
int segments;
};
#include "renderableplanetprojection_codegen.cpp"
} // namespace
@@ -177,10 +192,12 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary&
, _maxProjectionsPerFrame(MaxProjectionsPerFrameInfo, 3, 1, 64)
, _projectionsInBuffer(ProjectionsInBufferInfo, 0, 1, 32)
, _clearProjectionBuffer(ClearProjectionBufferInfo)
, _radius(RadiusInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(std::pow(10.f, 20.f)))
, _segments(SegmentsInfo, 20, 1, 5000)
, _sphere(nullptr)
{
const Parameters p = codegen::bake<Parameters>(dict);
_geometry = planetgeometry::PlanetGeometry::createFromDictionary(p.geometry);
_projectionComponent.initialize(identifier(), p.projection);
_colorTexturePaths.addOption(0, NoImageText);
@@ -251,7 +268,6 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary&
}
setBoundingSphere(radius);
addPropertySubOwner(_geometry.get());
addPropertySubOwner(_projectionComponent);
_heightExaggeration.setExponent(3.f);
@@ -270,6 +286,20 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary&
});
addProperty(_clearProjectionBuffer);
if (std::holds_alternative<float>(p.radius)) {
const float r = std::get<float>(p.radius);
_radius = glm::dvec3(r, r, r);
}
else {
_radius = std::get<glm::vec3>(p.radius);
}
_radius.onChange([&]() { createSphere(); });
addProperty(_radius);
_segments = p.segments;
_segments.onChange([&]() { createSphere(); });
addProperty(_segments);
}
RenderablePlanetProjection::~RenderablePlanetProjection() {} // NOLINT
@@ -322,8 +352,9 @@ void RenderablePlanetProjection::initializeGL() {
loadColorTexture();
loadHeightTexture();
_projectionComponent.initializeGL();
_geometry->initialize();
setBoundingSphere(_geometry->boundingSphere());
createSphere();
const glm::vec3 radius = _radius;
setBoundingSphere(std::max(std::max(radius[0], radius[1]), radius[2]));
// SCREEN-QUAD
const GLfloat vertexData[] = {
@@ -346,9 +377,10 @@ void RenderablePlanetProjection::initializeGL() {
}
void RenderablePlanetProjection::deinitializeGL() {
_sphere = nullptr;
_projectionComponent.deinitialize();
_baseTexture = nullptr;
_geometry = nullptr;
glDeleteVertexArrays(1, &_quad);
glDeleteBuffers(1, &_vertexPositionBuffer);
@@ -366,7 +398,7 @@ void RenderablePlanetProjection::deinitializeGL() {
}
bool RenderablePlanetProjection::isReady() const {
return _geometry && _programObject && _projectionComponent.isReady();
return _programObject && _projectionComponent.isReady();
}
void RenderablePlanetProjection::imageProjectGPU(
@@ -385,25 +417,8 @@ void RenderablePlanetProjection::imageProjectGPU(
_fboProgramObject->setUniform(_fboUniformCache.projectorMatrix, projectorMatrix);
_fboProgramObject->setUniform(_fboUniformCache.modelTransform, _transform);
_fboProgramObject->setUniform(_fboUniformCache.boresight, _boresight);
if (_geometry->hasProperty("Radius")) {
std::any r = _geometry->property("Radius")->get();
if (glm::vec3* radius = std::any_cast<glm::vec3>(&r)){
_fboProgramObject->setUniform(_fboUniformCache.radius, *radius);
}
}
else {
LERROR("Geometry object needs to provide radius");
}
if (_geometry->hasProperty("Segments")) {
std::any s = _geometry->property("Segments")->get();
if (int* segments = std::any_cast<int>(&s)) {
_fboProgramObject->setUniform(_fboUniformCache.segments, segments[0]);
}
}
else{
LERROR("Geometry object needs to provide segment count");
}
_fboProgramObject->setUniform(_fboUniformCache.radius, _radius);
_fboProgramObject->setUniform(_fboUniformCache.segments, _segments);
glBindVertexArray(_quad);
glDrawArrays(GL_TRIANGLES, 0, 6);
@@ -552,7 +567,7 @@ void RenderablePlanetProjection::render(const RenderData& data, RendererTasks&)
_programObject->setUniform(_mainUniformCache.heightTexture, unit[2]);
}
_geometry->render();
_sphere->render();
_programObject->deactivate();
}
@@ -674,4 +689,9 @@ void RenderablePlanetProjection::loadHeightTexture() {
}
}
void RenderablePlanetProjection::createSphere() {
_sphere = std::make_unique<Sphere>(_radius, _segments);
_sphere->initialize();
}
} // namespace openspace
@@ -31,6 +31,7 @@
#include <openspace/properties/optionproperty.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/triggerproperty.h>
#include <openspace/properties/vector/vec3property.h>
#include <ghoul/opengl/uniformcache.h>
namespace openspace {
@@ -38,6 +39,7 @@ namespace openspace {
namespace documentation { struct Documentation; }
struct Image;
class Sphere;
namespace planetgeometry { class PlanetGeometry; }
@@ -59,6 +61,7 @@ public:
private:
void loadColorTexture();
void loadHeightTexture();
void createSphere();
glm::mat4 attitudeParameters(double time, const glm::vec3& up);
void imageProjectGPU(const ghoul::opengl::Texture& projectionTexture,
@@ -94,7 +97,9 @@ private:
properties::IntProperty _projectionsInBuffer;
properties::TriggerProperty _clearProjectionBuffer;
std::unique_ptr<planetgeometry::PlanetGeometry> _geometry;
properties::Vec3Property _radius;
properties::IntProperty _segments;
std::unique_ptr<Sphere> _sphere;
glm::mat4 _transform = glm::mat4(1.f);
glm::mat4 _projectorMatrix = glm::mat4(1.f);