mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-18 01:41:29 -06:00
Adding static Settings to Renderable (#2578)
* Add settings to Renderable to control whether the renderbin is updated based on Opacity * Remove duplicate RenderBin specification for RenderableSphere * Remove unnecessary RenderBin specifications of Lagrange points * Don't automatically update the renderbin for RenderableLabel and RenderablePlane * Remove extra `setRenderBinFromOpacity` from RenderableSpheres * Move information about whether a renderable should be updated when disabled * Some cleanup of Renderable class * Don't update the renderbin automatically if the user specified the renderbin manually
This commit is contained in:
@@ -135,20 +135,29 @@ ghoul::mm_unique_ptr<Renderable> Renderable::createFromDictionary(
|
||||
|
||||
|
||||
|
||||
Renderable::Renderable(const ghoul::Dictionary& dictionary)
|
||||
Renderable::Renderable(const ghoul::Dictionary& dictionary, Settings settings)
|
||||
: properties::PropertyOwner({ "Renderable" })
|
||||
, Fadeable()
|
||||
, _enabled(EnabledInfo, true)
|
||||
, _renderableType(RenderableTypeInfo, "Renderable")
|
||||
, _dimInAtmosphere(DimInAtmosphereInfo, false)
|
||||
, _shouldUpdateIfDisabled(settings.shouldUpdateIfDisabled)
|
||||
, _automaticallyUpdateRenderBin(settings.automaticallyUpdateRenderBin)
|
||||
{
|
||||
ZoneScoped;
|
||||
|
||||
// I can't come up with a good reason not to do this for all renderables
|
||||
registerUpdateRenderBinFromOpacity();
|
||||
|
||||
const Parameters p = codegen::bake<Parameters>(dictionary);
|
||||
|
||||
if (p.renderBinMode.has_value()) {
|
||||
_automaticallyUpdateRenderBin = false;
|
||||
setRenderBin(codegen::map<Renderable::RenderBin>(*p.renderBinMode));
|
||||
}
|
||||
|
||||
if (_automaticallyUpdateRenderBin) {
|
||||
ghoul_assert(!p.renderBinMode.has_value(), "Something misfired in constructor");
|
||||
registerUpdateRenderBinFromOpacity();
|
||||
}
|
||||
|
||||
if (p.tag.has_value()) {
|
||||
if (std::holds_alternative<std::string>(*p.tag)) {
|
||||
if (!std::get<std::string>(*p.tag).empty()) {
|
||||
@@ -184,11 +193,6 @@ Renderable::Renderable(const ghoul::Dictionary& dictionary)
|
||||
_renderableType = p.type.value_or(_renderableType);
|
||||
addProperty(_renderableType);
|
||||
|
||||
// only used by a few classes such as RenderableTrail and RenderableSphere
|
||||
if (p.renderBinMode.has_value()) {
|
||||
setRenderBin(codegen::map<Renderable::RenderBin>(*p.renderBinMode));
|
||||
}
|
||||
|
||||
_dimInAtmosphere = p.dimInAtmosphere.value_or(_dimInAtmosphere);
|
||||
addProperty(_dimInAtmosphere);
|
||||
}
|
||||
@@ -211,7 +215,7 @@ void Renderable::setBoundingSphere(double boundingSphere) {
|
||||
_boundingSphere = boundingSphere;
|
||||
}
|
||||
|
||||
double Renderable::boundingSphere() const {
|
||||
double Renderable::boundingSphere() const noexcept {
|
||||
return _boundingSphere;
|
||||
}
|
||||
|
||||
@@ -219,11 +223,11 @@ void Renderable::setInteractionSphere(double interactionSphere) {
|
||||
_interactionSphere = interactionSphere;
|
||||
}
|
||||
|
||||
double Renderable::interactionSphere() const {
|
||||
double Renderable::interactionSphere() const noexcept {
|
||||
return _interactionSphere;
|
||||
}
|
||||
|
||||
std::string_view Renderable::typeAsString() const {
|
||||
std::string_view Renderable::typeAsString() const noexcept {
|
||||
return _renderableType;
|
||||
}
|
||||
|
||||
@@ -273,7 +277,7 @@ bool Renderable::isEnabled() const {
|
||||
return _enabled;
|
||||
}
|
||||
|
||||
bool Renderable::shouldUpdateIfDisabled() const {
|
||||
bool Renderable::shouldUpdateIfDisabled() const noexcept {
|
||||
return _shouldUpdateIfDisabled;
|
||||
}
|
||||
|
||||
@@ -300,9 +304,11 @@ void Renderable::setRenderBinFromOpacity() {
|
||||
void Renderable::registerUpdateRenderBinFromOpacity() {
|
||||
_opacity.onChange([this]() { setRenderBinFromOpacity(); });
|
||||
_fade.onChange([this]() { setRenderBinFromOpacity(); });
|
||||
|
||||
_automaticallyUpdateRenderBin = true;
|
||||
}
|
||||
|
||||
float Renderable::opacity() const {
|
||||
float Renderable::opacity() const noexcept {
|
||||
// Rendering should depend on if camera is in the atmosphere and if camera is at the
|
||||
// dark part of the globe
|
||||
const float dimming = _dimInAtmosphere ?
|
||||
@@ -311,4 +317,13 @@ float Renderable::opacity() const {
|
||||
return dimming * Fadeable::opacity();
|
||||
}
|
||||
|
||||
SceneGraphNode* Renderable::parent() const noexcept {
|
||||
ghoul_assert(dynamic_cast<SceneGraphNode*>(owner()), "Owner is not a SceneGraphNode");
|
||||
return static_cast<SceneGraphNode*>(owner());
|
||||
}
|
||||
|
||||
bool Renderable::automaticallyUpdatesRenderBin() const noexcept {
|
||||
return _automaticallyUpdateRenderBin;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user