mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-02 01:30:34 -06:00
Use codegen in ModelProjection and make use of new dictionary
This commit is contained in:
@@ -372,14 +372,12 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
|
||||
_disableFaceCulling = *p.disableFaceCulling;
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(LightSourcesInfo.identifier)) {
|
||||
const ghoul::Dictionary& lsDictionary =
|
||||
dictionary.value<ghoul::Dictionary>(LightSourcesInfo.identifier);
|
||||
if (p.lightSources.has_value()) {
|
||||
std::vector<ghoul::Dictionary> lightsources = *p.lightSources;
|
||||
|
||||
for (std::string_view k : lsDictionary.keys()) {
|
||||
std::unique_ptr<LightSource> lightSource = LightSource::createFromDictionary(
|
||||
lsDictionary.value<ghoul::Dictionary>(k)
|
||||
);
|
||||
for (const ghoul::Dictionary& lsDictionary : lightsources) {
|
||||
std::unique_ptr<LightSource> lightSource =
|
||||
LightSource::createFromDictionary(lsDictionary);
|
||||
_lightSourcePropertyOwner.addPropertySubOwner(lightSource.get());
|
||||
_lightSources.push_back(std::move(lightSource));
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <modules/spacecraftinstruments/util/imagesequencer.h>
|
||||
#include <optional>
|
||||
|
||||
namespace {
|
||||
constexpr const char* _loggerCat = "RenderableModelProjection";
|
||||
@@ -73,131 +74,113 @@ namespace {
|
||||
"location to the Sun. If this value is disabled, shading is disabled and the "
|
||||
"entire model is rendered brightly."
|
||||
};
|
||||
|
||||
struct [[codegen::Dictionary(RenderableModelProjection)]] Parameters {
|
||||
// The file or files that should be loaded in this RenderableModel. The file can
|
||||
// contain filesystem tokens or can be specified relatively to the
|
||||
// location of the .mod file.
|
||||
// This specifies the model that is rendered by the Renderable.
|
||||
std::variant<std::string, std::vector<std::string>> geometryFile;
|
||||
|
||||
// Contains information about projecting onto this planet.
|
||||
ghoul::Dictionary projection [[codegen::reference("newhorizons_projectioncomponent")]];
|
||||
|
||||
// [[codegen::verbatim(PerformShadingInfo.description)]]
|
||||
std::optional<bool> performShading;
|
||||
|
||||
// The radius of the bounding sphere of this object. This has to be a
|
||||
// radius that is larger than anything that is rendered by it. It has to
|
||||
// be at least as big as the convex hull of the object. The default value
|
||||
// is 10e9 meters.
|
||||
std::optional<double> boundingSphereRadius;
|
||||
};
|
||||
#include "renderablemodelprojection_codegen.cpp"
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
|
||||
documentation::Documentation RenderableModelProjection::Documentation() {
|
||||
using namespace documentation;
|
||||
|
||||
return {
|
||||
"Renderable Model Projection",
|
||||
"newhorizons_renderable_modelprojection",
|
||||
{
|
||||
{
|
||||
KeyGeomModelFile,
|
||||
new OrVerifier({ new StringVerifier, new StringListVerifier }),
|
||||
Optional::No,
|
||||
"The file or files that are used for rendering of this model"
|
||||
},
|
||||
{
|
||||
keyProjection,
|
||||
new ReferencingVerifier("newhorizons_projectioncomponent"),
|
||||
Optional::No,
|
||||
"Contains information about projecting onto this planet."
|
||||
},
|
||||
{
|
||||
PerformShadingInfo.identifier,
|
||||
new BoolVerifier,
|
||||
Optional::Yes,
|
||||
PerformShadingInfo.description
|
||||
},
|
||||
{
|
||||
keyBoundingSphereRadius,
|
||||
new DoubleVerifier,
|
||||
Optional::Yes,
|
||||
"The radius of the bounding sphere of this object. This has to be a "
|
||||
"radius that is larger than anything that is rendered by it. It has to "
|
||||
"be at least as big as the convex hull of the object. The default value "
|
||||
"is 10e9 meters."
|
||||
}
|
||||
}
|
||||
};
|
||||
documentation::Documentation doc = codegen::doc<Parameters>();
|
||||
doc.id = "newhorizons_renderable_modelprojection";
|
||||
return doc;
|
||||
}
|
||||
|
||||
RenderableModelProjection::RenderableModelProjection(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _performShading(PerformShadingInfo, true)
|
||||
{
|
||||
documentation::testSpecificationAndThrow(
|
||||
Documentation(),
|
||||
dictionary,
|
||||
"RenderableModelProjection"
|
||||
);
|
||||
const Parameters p = codegen::bake<Parameters>(dictionary);
|
||||
|
||||
if (dictionary.hasKey(KeyGeomModelFile)) {
|
||||
if (std::holds_alternative<std::string>(p.geometryFile)) {
|
||||
// Handle single file
|
||||
std::string file;
|
||||
file = absPath(std::get<std::string>(p.geometryFile));
|
||||
_geometry = ghoul::io::ModelReader::ref().loadModel(
|
||||
file,
|
||||
ghoul::io::ModelReader::ForceRenderInvisible::No,
|
||||
ghoul::io::ModelReader::NotifyInvisibleDropped::Yes
|
||||
);
|
||||
}
|
||||
else if (std::holds_alternative<std::vector<std::string>>(p.geometryFile)) {
|
||||
LWARNING("Loading a model with several files is deprecated and will be "
|
||||
"removed in a future release, TESTING"
|
||||
);
|
||||
/*
|
||||
ghoul::Dictionary fileDictionary = dictionary.value<ghoul::Dictionary>(
|
||||
KeyGeomModelFile
|
||||
);
|
||||
std::vector<std::unique_ptr<ghoul::modelgeometry::ModelGeometry>> geometries;
|
||||
|
||||
if (dictionary.hasValue<std::string>(KeyGeomModelFile)) {
|
||||
// Handle single file
|
||||
file = absPath(dictionary.value<std::string>(KeyGeomModelFile));
|
||||
_geometry = ghoul::io::ModelReader::ref().loadModel(
|
||||
for (std::string_view k : fileDictionary.keys()) {
|
||||
// Handle each file
|
||||
file = absPath(fileDictionary.value<std::string>(k));
|
||||
geometries.push_back(ghoul::io::ModelReader::ref().loadModel(
|
||||
file,
|
||||
ghoul::io::ModelReader::ForceRenderInvisible::No,
|
||||
ghoul::io::ModelReader::NotifyInvisibleDropped::Yes
|
||||
);
|
||||
));
|
||||
}
|
||||
else if (dictionary.hasValue<ghoul::Dictionary>(KeyGeomModelFile)) {
|
||||
LWARNING("Loading a model with several files is deprecated and will be "
|
||||
"removed in a future release"
|
||||
);
|
||||
|
||||
ghoul::Dictionary fileDictionary = dictionary.value<ghoul::Dictionary>(
|
||||
KeyGeomModelFile
|
||||
);
|
||||
std::vector<std::unique_ptr<ghoul::modelgeometry::ModelGeometry>> geometries;
|
||||
if (!geometries.empty()) {
|
||||
std::unique_ptr<ghoul::modelgeometry::ModelGeometry> combinedGeometry =
|
||||
std::move(geometries[0]);
|
||||
|
||||
for (std::string_view k : fileDictionary.keys()) {
|
||||
// Handle each file
|
||||
file = absPath(fileDictionary.value<std::string>(k));
|
||||
geometries.push_back(ghoul::io::ModelReader::ref().loadModel(
|
||||
file,
|
||||
ghoul::io::ModelReader::ForceRenderInvisible::No,
|
||||
ghoul::io::ModelReader::NotifyInvisibleDropped::Yes
|
||||
));
|
||||
}
|
||||
|
||||
if (!geometries.empty()) {
|
||||
std::unique_ptr<ghoul::modelgeometry::ModelGeometry> combinedGeometry =
|
||||
std::move(geometries[0]);
|
||||
|
||||
// Combine all models into one ModelGeometry
|
||||
for (unsigned int i = 1; i < geometries.size(); ++i) {
|
||||
for (ghoul::io::ModelMesh& mesh : geometries[i]->meshes()) {
|
||||
combinedGeometry->meshes().push_back(
|
||||
std::move(mesh)
|
||||
);
|
||||
}
|
||||
|
||||
for (ghoul::modelgeometry::ModelGeometry::TextureEntry& texture :
|
||||
geometries[i]->textureStorage())
|
||||
{
|
||||
combinedGeometry->textureStorage().push_back(
|
||||
std::move(texture)
|
||||
);
|
||||
}
|
||||
// Combine all models into one ModelGeometry
|
||||
for (unsigned int i = 1; i < geometries.size(); ++i) {
|
||||
for (ghoul::io::ModelMesh& mesh : geometries[i]->meshes()) {
|
||||
combinedGeometry->meshes().push_back(
|
||||
std::move(mesh)
|
||||
);
|
||||
}
|
||||
|
||||
for (ghoul::modelgeometry::ModelGeometry::TextureEntry& texture :
|
||||
geometries[i]->textureStorage())
|
||||
{
|
||||
combinedGeometry->textureStorage().push_back(
|
||||
std::move(texture)
|
||||
);
|
||||
}
|
||||
_geometry = std::move(combinedGeometry);
|
||||
_geometry->calculateBoundingRadius();
|
||||
}
|
||||
}
|
||||
_geometry = std::move(combinedGeometry);
|
||||
_geometry->calculateBoundingRadius();
|
||||
}*/
|
||||
}
|
||||
|
||||
addPropertySubOwner(_projectionComponent);
|
||||
|
||||
_projectionComponent.initialize(
|
||||
identifier(),
|
||||
dictionary.value<ghoul::Dictionary>(keyProjection)
|
||||
p.projection
|
||||
);
|
||||
|
||||
double boundingSphereRadius = 1.0e9;
|
||||
if (dictionary.hasValue<double>(keyBoundingSphereRadius)) {
|
||||
boundingSphereRadius = dictionary.value<double>(keyBoundingSphereRadius);
|
||||
if (p.boundingSphereRadius.has_value()) {
|
||||
boundingSphereRadius = *p.boundingSphereRadius;
|
||||
}
|
||||
setBoundingSphere(boundingSphereRadius);
|
||||
|
||||
if (dictionary.hasValue<bool>(PerformShadingInfo.identifier)) {
|
||||
_performShading = dictionary.value<bool>(PerformShadingInfo.identifier);
|
||||
if (p.performShading.has_value()) {
|
||||
_performShading = *p.performShading;
|
||||
}
|
||||
|
||||
addProperty(_performShading);
|
||||
|
||||
Reference in New Issue
Block a user