diff --git a/data/assets/scene/solarsystem/missions/apollo/11/apollo11.asset b/data/assets/scene/solarsystem/missions/apollo/11/apollo11.asset index dc49085193..2a620933ab 100644 --- a/data/assets/scene/solarsystem/missions/apollo/11/apollo11.asset +++ b/data/assets/scene/solarsystem/missions/apollo/11/apollo11.asset @@ -93,7 +93,7 @@ local Apollo11MoonTrail = { Observer = coreKernels.ID.Moon, Frame = coreKernels.Frame.Moon }, - Color = { 0.180000,0.510000,0.750000 }, + Color = { 0.18, 0.51, 0.75 }, StartTime = "1969 JUL 19 19:38:29.183", EndTime = "1969 JUL 22 04:55:35.183", SampleInterval = 60, @@ -137,7 +137,7 @@ local Apollo11LemTrail = { Type = "RenderableTrailTrajectory", Enabled = false, Translation = lemTranslation, - Color = { 0.780000,0.940000,0.340000 }, + Color = { 0.78, 0.94, 0.34 }, StartTime = "1969 JUL 20 19:10:25.183", EndTime = "1969 JUL 20 20:17:46.183", SampleInterval = 2, diff --git a/data/assets/scene/solarsystem/missions/apollo/11/lem_descent_rotation.asset b/data/assets/scene/solarsystem/missions/apollo/11/lem_descent_rotation.asset index cfef924a62..b01fa75349 100644 --- a/data/assets/scene/solarsystem/missions/apollo/11/lem_descent_rotation.asset +++ b/data/assets/scene/solarsystem/missions/apollo/11/lem_descent_rotation.asset @@ -1,4 +1,4 @@ -asset.export("keyframes", { +local keyframes = { -- ["1969-7-20T20:9:53"] = { -- Type = "StaticRotation", -- Rotation = { -1.3815, -0.0048, -0.4891 } @@ -1583,7 +1583,9 @@ asset.export("keyframes", { Type = "StaticRotation", Rotation = { -0.0794, -0.0088, -0.2447 } } -}) +} + +asset.export("keyframes", keyframes) diff --git a/include/openspace/scene/rotation.h b/include/openspace/scene/rotation.h index f95481a504..7db4d7ea9c 100644 --- a/include/openspace/scene/rotation.h +++ b/include/openspace/scene/rotation.h @@ -64,7 +64,7 @@ public: explicit Rotation(const ghoul::Dictionary& dictionary); virtual ~Rotation() override = default; - virtual bool initialize(); + virtual void initialize(); virtual void update(const UpdateData& data); const glm::dmat3& matrix() const; diff --git a/include/openspace/scene/scale.h b/include/openspace/scene/scale.h index 55f22458f6..188a18e6f4 100644 --- a/include/openspace/scene/scale.h +++ b/include/openspace/scene/scale.h @@ -47,7 +47,7 @@ public: Scale(const ghoul::Dictionary& dictionary); virtual ~Scale() override = default; - virtual bool initialize(); + virtual void initialize(); virtual void update(const UpdateData& data); glm::dvec3 scaleValue() const; diff --git a/include/openspace/scene/translation.h b/include/openspace/scene/translation.h index cdb5d05443..9096e9a1af 100644 --- a/include/openspace/scene/translation.h +++ b/include/openspace/scene/translation.h @@ -48,7 +48,7 @@ public: explicit Translation(const ghoul::Dictionary& dictionary); virtual ~Translation() override = default; - virtual bool initialize(); + virtual void initialize(); virtual void update(const UpdateData& data); glm::dvec3 position() const; diff --git a/modules/base/rendering/renderabletrail.cpp b/modules/base/rendering/renderabletrail.cpp index 939d7c043c..a666b68f44 100644 --- a/modules/base/rendering/renderabletrail.cpp +++ b/modules/base/rendering/renderabletrail.cpp @@ -244,7 +244,11 @@ RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary) } addPropertySubOwner(_appearance); +} +void RenderableTrail::initialize() { + Renderable::initialize(); + _translation->initialize(); } void RenderableTrail::initializeGL() { @@ -291,6 +295,18 @@ bool RenderableTrail::isReady() const { return _programObject != nullptr; } +glm::dvec3 RenderableTrail::translationPosition(Time time) const { + // Use empty modelTransform (local coordinates) and time 0; previous frame time + // doesn't matter + const UpdateData data = { {}, time, Time(0.0) }; + // (2025-06-09, emmbr) No need to call update here, since it's only for caching + // the position and kills the trail performance. If behavior changes or we add + // a translation type that needs pre-update, we need add the update and address + // performance + //_translation->update(data); + return _translation->position(data); +} + void RenderableTrail::internalRender(bool renderLines, bool renderPoints, const RenderData& data, const glm::dmat4& modelTransform, @@ -486,7 +502,7 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) { _primaryRenderInformation.count, _primaryRenderInformation.first, _useSplitRenderMode, - _numberOfUniqueVertices + _nUniqueVertices ); const int floatingOffset = std::max(0, _primaryRenderInformation.count - 1); @@ -499,7 +515,7 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) { _floatingRenderInformation.count, _floatingRenderInformation.first, _useSplitRenderMode, - _numberOfUniqueVertices, + _nUniqueVertices, floatingOffset ); @@ -513,7 +529,7 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) { _secondaryRenderInformation.count, _secondaryRenderInformation.first, _useSplitRenderMode, - _numberOfUniqueVertices, + _nUniqueVertices, offset ); @@ -547,8 +563,6 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) { } - - if (renderPoints) { glDisable(GL_PROGRAM_POINT_SIZE); } diff --git a/modules/base/rendering/renderabletrail.h b/modules/base/rendering/renderabletrail.h index cf8f7e7273..a9683b4c8b 100644 --- a/modules/base/rendering/renderabletrail.h +++ b/modules/base/rendering/renderabletrail.h @@ -97,6 +97,7 @@ public: virtual ~RenderableTrail() override = default; + void initialize() override; void initializeGL() override; void deinitializeGL() override; @@ -115,6 +116,15 @@ public: protected: explicit RenderableTrail(const ghoul::Dictionary& dictionary); + /** + * Get the trail position for a given time from the Translation object. The position + * will be in the local coordinate system of the renderable. + * + * \param time The time for which to get the position + * \return The position of the trail at the given time, in the local coordinate system + */ + glm::dvec3 translationPosition(Time time) const; + static documentation::Documentation Documentation(); /// The layout of the VBOs (use float if sending as positions to shader) @@ -179,7 +189,7 @@ protected: /// Flag used to determine if we use a split trail or not during rendering bool _useSplitRenderMode = false; /// Number of unique vertices used when rendering segmented trails - int _numberOfUniqueVertices = 0; + int _nUniqueVertices = 0; private: void internalRender(bool renderLines, bool renderPoints, diff --git a/modules/base/rendering/renderabletrailorbit.cpp b/modules/base/rendering/renderabletrailorbit.cpp index c8d6aedf1e..7b3c9e3a5b 100644 --- a/modules/base/rendering/renderabletrailorbit.cpp +++ b/modules/base/rendering/renderabletrailorbit.cpp @@ -185,11 +185,7 @@ void RenderableTrailOrbit::update(const UpdateData& data) { // 2 // Write the current location into the floating position - const glm::vec3 p = _translation->position({ - {}, - data.time, - Time(0.0) - }); + const glm::vec3 p = translationPosition(data.time); _vertexArray[_primaryRenderInformation.first] = { p.x, p.y, p.z }; glBindVertexArray(_primaryRenderInformation._vaoID); @@ -365,11 +361,7 @@ RenderableTrailOrbit::UpdateReport RenderableTrailOrbit::updateTrails( // Get the new permanent point and write it into the (previously) floating // location - const glm::vec3 p = _translation->position({ - {}, - Time(_lastPointTime), - Time(0.0) - }); + const glm::vec3 p = translationPosition(Time(_lastPointTime)); _vertexArray[_primaryRenderInformation.first] = { p.x, p.y, p.z }; // Move the current pointer back one step to be used as the new floating @@ -405,11 +397,7 @@ RenderableTrailOrbit::UpdateReport RenderableTrailOrbit::updateTrails( // Get the new permanent point and write it into the (previously) floating // location - const glm::vec3 p = _translation->position({ - {}, - Time(_firstPointTime), - Time(0.0) - }); + const glm::vec3 p = translationPosition(Time(_firstPointTime)); _vertexArray[_primaryRenderInformation.first] = { p.x, p.y, p.z }; // if we are on the upper bounds of the array, we start at 0 @@ -452,7 +440,7 @@ void RenderableTrailOrbit::fullSweep(double time) { const double secondsPerPoint = periodSeconds / (_resolution - 1); // starting at 1 because the first position is a floating current one for (int i = 1; i < _resolution; i++) { - const glm::vec3 p = _translation->position({ {}, Time(time), Time(0.0) }); + const glm::vec3 p = translationPosition(Time(time)); _vertexArray[i] = { p.x, p.y, p.z }; time -= secondsPerPoint; diff --git a/modules/base/rendering/renderabletrailtrajectory.cpp b/modules/base/rendering/renderabletrailtrajectory.cpp index f0ae0f03e2..5adc2d00c6 100644 --- a/modules/base/rendering/renderabletrailtrajectory.cpp +++ b/modules/base/rendering/renderabletrailtrajectory.cpp @@ -169,7 +169,7 @@ RenderableTrailTrajectory::RenderableTrailTrajectory(const ghoul::Dictionary& di , _sampleInterval(SampleIntervalInfo, 2.0, 2.0, 1e6) , _timeStampSubsamplingFactor(TimeSubSampleInfo, 1, 1, 1000000000) , _renderFullTrail(RenderFullPathInfo, false) - , _numberOfReplacementPoints(AccurateTrailPositionsInfo, 100, 0, 1000) + , _nReplacementPoints(AccurateTrailPositionsInfo, 100, 0, 1000) , _maxVertex(glm::vec3(-std::numeric_limits::max())) , _minVertex(glm::vec3(std::numeric_limits::max())) { @@ -203,10 +203,8 @@ RenderableTrailTrajectory::RenderableTrailTrajectory(const ghoul::Dictionary& di _timeStampSubsamplingFactor.onChange([this] { _subsamplingIsDirty = true; }); addProperty(_timeStampSubsamplingFactor); - _numberOfReplacementPoints = p.accurateTrailPositions.value_or( - _numberOfReplacementPoints - ); - addProperty(_numberOfReplacementPoints); + _nReplacementPoints = p.accurateTrailPositions.value_or(_nReplacementPoints); + addProperty(_nReplacementPoints); _enableSweepChunking = p.enableSweepChunking.value_or(_enableSweepChunking); addProperty(_enableSweepChunking); @@ -258,10 +256,8 @@ void RenderableTrailTrajectory::reset() { void RenderableTrailTrajectory::update(const UpdateData& data) { if (_needsFullSweep) { - if (_sweepIteration == 0) { - // Max number of vertices - constexpr unsigned int maxNumberOfVertices = 1000000; + constexpr unsigned int MaxVertices = 1000000; // Convert the start and end time from string representations to J2000 seconds _start = SpiceManager::ref().ephemerisTimeFromDate(_startTime); @@ -270,45 +266,43 @@ void RenderableTrailTrajectory::update(const UpdateData& data) { _totalSampleInterval = _sampleInterval / _timeStampSubsamplingFactor; - // Cap _numberOfVertices in order to prevent overflow and extreme performance + // Cap _nVertices in order to prevent overflow and extreme performance // degredation/RAM usage - _numberOfVertices = std::min( + _nVertices = std::min( static_cast(std::ceil(timespan / _totalSampleInterval)), - maxNumberOfVertices + MaxVertices ); - // We need to recalcuate the _totalSampleInterval if _numberOfVertices eqals - // maxNumberOfVertices. If we don't do this the position for each vertex + // We need to recalcuate the _totalSampleInterval if _nVertices equals + // MaxVertices. If we don't do this the position for each vertex // will not be correct for the number of vertices we are doing along the trail - _totalSampleInterval = (_numberOfVertices == maxNumberOfVertices) ? - (timespan / _numberOfVertices) : _totalSampleInterval; + _totalSampleInterval = (_nVertices == MaxVertices) ? + (timespan / _nVertices) : _totalSampleInterval; // Make space for the vertices _vertexArray.clear(); _dVertexArray.clear(); _timeVector.clear(); - _vertexArray.resize(_numberOfVertices + 1); - _dVertexArray.resize(_numberOfVertices + 1); - _timeVector.resize(_numberOfVertices + 1); + _vertexArray.resize(_nVertices + 1); + _dVertexArray.resize(_nVertices + 1); + _timeVector.resize(_nVertices + 1); } // Calculate sweeping range for this iteration const unsigned int startIndex = _sweepIteration * _sweepChunkSize; const unsigned int nextIndex = (_sweepIteration + 1) * _sweepChunkSize; - unsigned int stopIndex = std::min(nextIndex, _numberOfVertices); + unsigned int stopIndex = std::min(nextIndex, _nVertices); // If iterative calculations are disabled if (!_enableSweepChunking) { - stopIndex = _numberOfVertices; + stopIndex = _nVertices; } // Calculate all vertex positions for (unsigned int i = startIndex; i < stopIndex; i++) { - const glm::dvec3 dp = _translation->position({ - {}, - Time(_start + i * _totalSampleInterval), - Time(0.0) - }); + const glm::dvec3 dp = translationPosition( + Time(_start + i * _totalSampleInterval) + ); const glm::vec3 p(dp.x, dp.y, dp.z); _vertexArray[i] = { p.x, p.y, p.z }; _timeVector[i] = Time(_start + i * _totalSampleInterval).j2000Seconds(); @@ -323,12 +317,8 @@ void RenderableTrailTrajectory::update(const UpdateData& data) { // Full sweep is complete here. // Adds the last point in time to the _vertexArray so that we // ensure that points for _start and _end always exists - if (stopIndex == _numberOfVertices) { - const glm::dvec3 dp = _translation->position({ - {}, - Time(_end), - Time(0.0) - }); + if (stopIndex == _nVertices) { + const glm::dvec3 dp = translationPosition(Time(_end)); const glm::vec3 p(dp.x, dp.y, dp.z); _vertexArray[stopIndex] = { p.x, p.y, p.z }; _timeVector[stopIndex] = Time(_end).j2000Seconds(); @@ -386,7 +376,7 @@ void RenderableTrailTrajectory::update(const UpdateData& data) { ); // Calculate number of vertices in the trail - _numberOfUniqueVertices = static_cast( + _nUniqueVertices = static_cast( std::distance(_timeVector.begin(), _timeVector.end()) ); } @@ -396,12 +386,12 @@ void RenderableTrailTrajectory::update(const UpdateData& data) { _secondaryRenderInformation.count = 0; // Set number of vertices in the trail - _numberOfUniqueVertices = _primaryRenderInformation.count; + _nUniqueVertices = _primaryRenderInformation.count; } // Determine the number of points to be recalculated int prePaddingDelta = 0; - if (!_renderFullTrail && _numberOfReplacementPoints == 0) { + if (!_renderFullTrail && _nReplacementPoints == 0) { // Enables trail from last point to current position // if we don't do any replacement points prePaddingDelta = 1; @@ -409,16 +399,16 @@ void RenderableTrailTrajectory::update(const UpdateData& data) { else { prePaddingDelta = std::min( static_cast(_primaryRenderInformation.count), - static_cast(_numberOfReplacementPoints) + static_cast(_nReplacementPoints) ); } int postPaddingDelta = std::min( static_cast(_secondaryRenderInformation.count), - static_cast(_numberOfReplacementPoints) + static_cast(_nReplacementPoints) ); // Get current position of the object - const glm::dvec3 p = _translation->position(data); + const glm::dvec3 p = translationPosition(data.time); // Calculates all replacement points before the object glm::dvec3 v = p; @@ -460,7 +450,7 @@ void RenderableTrailTrajectory::update(const UpdateData& data) { } // Mid-point (model-space position for the object) - if (_numberOfReplacementPoints > 0 || !_renderFullTrail) { + if (_nReplacementPoints > 0 || !_renderFullTrail) { _replacementPoints.push_back({ 0.f, 0.f, 0.f }); } @@ -503,14 +493,11 @@ void RenderableTrailTrajectory::update(const UpdateData& data) { _floatingRenderInformation.count = static_cast(_replacementPoints.size()); - _floatingRenderInformation._localTransform = glm::translate( - glm::dmat4(1.0), - p - ); + _floatingRenderInformation._localTransform = glm::translate(glm::dmat4(1.0), p); // Adjusts number of unique vertices if we have inserted a new mid point if (_floatingRenderInformation.count > 0 && _renderFullTrail) { - _numberOfUniqueVertices++; + _nUniqueVertices++; } // Recalculate .count and .first based on the recalculated (floating) vertices @@ -520,11 +507,10 @@ void RenderableTrailTrajectory::update(const UpdateData& data) { // Adjusts count such that it takes into account if we don't have any line // connecting with the object - if (_renderFullTrail && _numberOfReplacementPoints == 0) { + if (_renderFullTrail && _nReplacementPoints == 0) { _primaryRenderInformation.count += 1; } - glBindVertexArray(_floatingRenderInformation._vaoID); glBindBuffer(GL_ARRAY_BUFFER, _floatingRenderInformation._vBufferID); glBufferData( @@ -540,7 +526,7 @@ void RenderableTrailTrajectory::update(const UpdateData& data) { // Renders the whole trail if time has passed the end time _primaryRenderInformation.first = 0; _primaryRenderInformation.count = static_cast(_vertexArray.size()); - _numberOfUniqueVertices = _primaryRenderInformation.count; + _nUniqueVertices = _primaryRenderInformation.count; _secondaryRenderInformation.first = 0; _secondaryRenderInformation.count = 0; _floatingRenderInformation.first = 0; @@ -567,7 +553,6 @@ void RenderableTrailTrajectory::update(const UpdateData& data) { } glBindVertexArray(0); - } } // namespace openspace diff --git a/modules/base/rendering/renderabletrailtrajectory.h b/modules/base/rendering/renderabletrailtrajectory.h index 3e4efdd2eb..f6ce580f8e 100644 --- a/modules/base/rendering/renderabletrailtrajectory.h +++ b/modules/base/rendering/renderabletrailtrajectory.h @@ -84,7 +84,7 @@ private: properties::BoolProperty _renderFullTrail; /// Determines how many vertices around the object that will be /// replaced during full trail rendering - properties::IntProperty _numberOfReplacementPoints; + properties::IntProperty _nReplacementPoints; /// Dirty flag that determines whether the full vertex buffer needs to be resampled bool _needsFullSweep = true; @@ -102,7 +102,7 @@ private: /// How many points do we need to compute given the distance between the /// start and end date and the desired sample interval - unsigned int _numberOfVertices = 0; + unsigned int _nVertices = 0; double _totalSampleInterval = 0.0; diff --git a/modules/base/rendering/screenspacerenderablerenderable.cpp b/modules/base/rendering/screenspacerenderablerenderable.cpp index 98b2f482cc..b9032ed8ae 100644 --- a/modules/base/rendering/screenspacerenderablerenderable.cpp +++ b/modules/base/rendering/screenspacerenderablerenderable.cpp @@ -187,7 +187,6 @@ ScreenSpaceRenderableRenderable::ScreenSpaceRenderableRenderable( addProperty(_cameraFov); _renderable = Renderable::createFromDictionary(p.renderable); - _renderable->initialize(); addPropertySubOwner(_renderable.get()); _transform = ghoul::mm_unique_ptr( @@ -204,7 +203,6 @@ ScreenSpaceRenderableRenderable::ScreenSpaceRenderableRenderable( translation.setValue("Position", glm::dvec3(0.0)); _translation = Translation::createFromDictionary(translation); } - _translation->initialize(); _transform->addPropertySubOwner(_translation.get()); if (p.transform.has_value() && p.transform->rotation.has_value()) { @@ -216,7 +214,6 @@ ScreenSpaceRenderableRenderable::ScreenSpaceRenderableRenderable( rotation.setValue("Rotation", glm::dvec3(0.0)); _rotation = Rotation::createFromDictionary(rotation); } - _rotation->initialize(); _transform->addPropertySubOwner(_rotation.get()); if (p.transform.has_value() && p.transform->scale.has_value()) { @@ -228,12 +225,19 @@ ScreenSpaceRenderableRenderable::ScreenSpaceRenderableRenderable( scale.setValue("Scale", 1.0); _scale = Scale::createFromDictionary(scale); } - _scale->initialize(); _transform->addPropertySubOwner(_scale.get()); } ScreenSpaceRenderableRenderable::~ScreenSpaceRenderableRenderable() {} +void ScreenSpaceRenderableRenderable::initialize() { + ScreenSpaceFramebuffer::initialize(); + _translation->initialize(); + _rotation->initialize(); + _scale->initialize(); + _renderable->initialize(); +} + void ScreenSpaceRenderableRenderable::initializeGL() { ScreenSpaceFramebuffer::initializeGL(); diff --git a/modules/base/rendering/screenspacerenderablerenderable.h b/modules/base/rendering/screenspacerenderablerenderable.h index 83f373cd1a..4ebed2c6e2 100644 --- a/modules/base/rendering/screenspacerenderablerenderable.h +++ b/modules/base/rendering/screenspacerenderablerenderable.h @@ -50,6 +50,7 @@ public: explicit ScreenSpaceRenderableRenderable(const ghoul::Dictionary& dictionary); virtual ~ScreenSpaceRenderableRenderable() override; + void initialize() override; void initializeGL() override; void deinitializeGL() override; void update() override; diff --git a/modules/base/rotation/fixedrotation.cpp b/modules/base/rotation/fixedrotation.cpp index f84de4bb1e..711d996e03 100644 --- a/modules/base/rotation/fixedrotation.cpp +++ b/modules/base/rotation/fixedrotation.cpp @@ -444,7 +444,7 @@ FixedRotation::FixedRotation(const ghoul::Dictionary& dictionary) setPropertyVisibility(_zAxis); } -bool FixedRotation::initialize() { +void FixedRotation::initialize() { ZoneScoped; // We have already checked this before, but still @@ -454,7 +454,7 @@ bool FixedRotation::initialize() { // nodes referenced in the dictionary might not exist yet at construction time. At // initialization time, however, we know that they already have been created - const bool res = Rotation::initialize(); + Rotation::initialize(); _attachedObject = p.attached.value_or(_attachedObject); @@ -525,7 +525,6 @@ bool FixedRotation::initialize() { // No need to hold on to the data _constructorDictionary = ghoul::Dictionary(); - return res; } void FixedRotation::update(const UpdateData& data) { diff --git a/modules/base/rotation/fixedrotation.h b/modules/base/rotation/fixedrotation.h index dece6a8b4c..9875fb4096 100644 --- a/modules/base/rotation/fixedrotation.h +++ b/modules/base/rotation/fixedrotation.h @@ -43,7 +43,7 @@ class FixedRotation : public Rotation { public: explicit FixedRotation(const ghoul::Dictionary& dictionary); - bool initialize() override; + void initialize() override; void update(const UpdateData& data) override; glm::dmat3 matrix(const UpdateData& data) const override; diff --git a/modules/base/rotation/globerotation.cpp b/modules/base/rotation/globerotation.cpp index 0b37d213ee..9857cd0913 100644 --- a/modules/base/rotation/globerotation.cpp +++ b/modules/base/rotation/globerotation.cpp @@ -37,6 +37,8 @@ #include namespace { + constexpr std::string_view _loggerCat = "GlobeRotation"; + constexpr openspace::properties::Property::PropertyInfo GlobeInfo = { "Globe", "Attached Globe", @@ -136,7 +138,7 @@ GlobeRotation::GlobeRotation(const ghoul::Dictionary& dictionary) _sceneGraphNode = p.globe; _sceneGraphNode.onChange([this]() { - findNode(); + fillAttachedNode(); setUpdateVariables(); }); addProperty(_sceneGraphNode); @@ -162,13 +164,10 @@ GlobeRotation::GlobeRotation(const ghoul::Dictionary& dictionary) addProperty(_useCamera); } -void GlobeRotation::findNode() { +void GlobeRotation::fillAttachedNode() { SceneGraphNode* n = sceneGraphNode(_sceneGraphNode); - if (!n || !n->renderable()) { - LERRORC( - "GlobeRotation", - "Could not set attached node as it does not have a Renderable" - ); + if (!n) { + LERROR(std::format("Could not find attached node '{}'", _sceneGraphNode.value())); return; } _attachedNode = n; @@ -180,7 +179,7 @@ void GlobeRotation::setUpdateVariables() { } glm::vec3 GlobeRotation::computeSurfacePosition(double latitude, double longitude) const { - ghoul_assert(_attachedNode, "Renderable cannot be nullptr"); + ghoul_assert(_attachedNode, "Attached node cannot be nullptr"); const Geodetic3 pos = { { .lat = glm::radians(latitude), .lon = glm::radians(longitude) }, @@ -206,12 +205,12 @@ glm::vec3 GlobeRotation::computeSurfacePosition(double latitude, double longitud ); } -void GlobeRotation::update(const UpdateData& data) { - if (!_attachedNode) [[unlikely]] { - findNode(); - _matrixIsDirty = true; - } +void GlobeRotation::initialize() { + Rotation::initialize(); + fillAttachedNode(); +} +void GlobeRotation::update(const UpdateData& data) { if (_useHeightmap || _useCamera) { // If we use the heightmap, we have to compute the height every frame setUpdateVariables(); @@ -225,11 +224,7 @@ glm::dmat3 GlobeRotation::matrix(const UpdateData&) const { return _matrix; } - if (!_attachedNode) { - LERRORC( - "GlobeRotation", - std::format("Could not find globe '{}'", _sceneGraphNode.value()) - ); + if (!_attachedNode) [[unlikely]] { return _matrix; } diff --git a/modules/base/rotation/globerotation.h b/modules/base/rotation/globerotation.h index 753741c884..d6f6a09117 100644 --- a/modules/base/rotation/globerotation.h +++ b/modules/base/rotation/globerotation.h @@ -39,13 +39,15 @@ class GlobeRotation : public Rotation { public: explicit GlobeRotation(const ghoul::Dictionary& dictionary); + void initialize() override; + void update(const UpdateData& data) override; glm::dmat3 matrix(const UpdateData& data) const override; static documentation::Documentation Documentation(); private: - void findNode(); + void fillAttachedNode(); void setUpdateVariables(); /** diff --git a/modules/base/rotation/multirotation.cpp b/modules/base/rotation/multirotation.cpp index 0e727c3038..b2c7e7374f 100644 --- a/modules/base/rotation/multirotation.cpp +++ b/modules/base/rotation/multirotation.cpp @@ -64,6 +64,13 @@ MultiRotation::MultiRotation(const ghoul::Dictionary& dictionary) } } +void MultiRotation::initialize() { + Rotation::initialize(); + for (const ghoul::mm_unique_ptr& rot : _rotations) { + rot->initialize(); + } +} + void MultiRotation::update(const UpdateData& data) { for (const ghoul::mm_unique_ptr& rot : _rotations) { rot->update(data); diff --git a/modules/base/rotation/multirotation.h b/modules/base/rotation/multirotation.h index dea7363d16..8a03d7ce7d 100644 --- a/modules/base/rotation/multirotation.h +++ b/modules/base/rotation/multirotation.h @@ -39,6 +39,8 @@ class MultiRotation : public Rotation { public: explicit MultiRotation(const ghoul::Dictionary& dictionary); + void initialize() override; + void update(const UpdateData& data) override; glm::dmat3 matrix(const UpdateData& data) const override; diff --git a/modules/base/rotation/timelinerotation.cpp b/modules/base/rotation/timelinerotation.cpp index b40b4ebbcc..27d3630f15 100644 --- a/modules/base/rotation/timelinerotation.cpp +++ b/modules/base/rotation/timelinerotation.cpp @@ -83,6 +83,13 @@ TimelineRotation::TimelineRotation(const ghoul::Dictionary& dictionary) addProperty(_shouldInterpolate); } +void TimelineRotation::initialize() { + Rotation::initialize(); + for (const Keyframe>& kf : _timeline.keyframes()) { + kf.data->initialize(); + } +} + void TimelineRotation::update(const UpdateData& data) { const double now = data.time.j2000Seconds(); using KeyframePointer = const Keyframe>*; diff --git a/modules/base/rotation/timelinerotation.h b/modules/base/rotation/timelinerotation.h index 189fb5de6d..6dc5ff9021 100644 --- a/modules/base/rotation/timelinerotation.h +++ b/modules/base/rotation/timelinerotation.h @@ -40,6 +40,8 @@ class TimelineRotation : public Rotation { public: explicit TimelineRotation(const ghoul::Dictionary& dictionary); + void initialize() override; + void update(const UpdateData& data) override; glm::dmat3 matrix(const UpdateData& data) const override; static documentation::Documentation Documentation(); diff --git a/modules/base/scale/multiscale.cpp b/modules/base/scale/multiscale.cpp index c734d45a6c..9d683e4ac6 100644 --- a/modules/base/scale/multiscale.cpp +++ b/modules/base/scale/multiscale.cpp @@ -63,6 +63,13 @@ MultiScale::MultiScale(const ghoul::Dictionary& dictionary) } } +void MultiScale::initialize() { + Scale::initialize(); + for (const ghoul::mm_unique_ptr& scale : _scales) { + scale->initialize(); + } +} + void MultiScale::update(const UpdateData& data) { for (const ghoul::mm_unique_ptr& scale : _scales) { scale->update(data); diff --git a/modules/base/scale/multiscale.h b/modules/base/scale/multiscale.h index e0f75e576e..e1b6afec43 100644 --- a/modules/base/scale/multiscale.h +++ b/modules/base/scale/multiscale.h @@ -35,6 +35,8 @@ class MultiScale : public Scale { public: explicit MultiScale(const ghoul::Dictionary& dictionary); + void initialize() override; + void update(const UpdateData& data) override; glm::dvec3 scaleValue(const UpdateData& data) const override; diff --git a/modules/base/scale/timelinescale.cpp b/modules/base/scale/timelinescale.cpp index 2d4c6938ec..e2ef6f2a1c 100644 --- a/modules/base/scale/timelinescale.cpp +++ b/modules/base/scale/timelinescale.cpp @@ -81,6 +81,13 @@ TimelineScale::TimelineScale(const ghoul::Dictionary& dictionary) addProperty(_shouldInterpolate); } +void TimelineScale::initialize() { + Scale::initialize(); + for (const Keyframe>& kf : _timeline.keyframes()) { + kf.data->initialize(); + } +} + void TimelineScale::update(const UpdateData& data) { const double now = data.time.j2000Seconds(); using KeyframePointer = const Keyframe>*; diff --git a/modules/base/scale/timelinescale.h b/modules/base/scale/timelinescale.h index f264281118..a298627311 100644 --- a/modules/base/scale/timelinescale.h +++ b/modules/base/scale/timelinescale.h @@ -41,6 +41,8 @@ class TimelineScale : public Scale { public: explicit TimelineScale(const ghoul::Dictionary& dictionary); + void initialize() override; + void update(const UpdateData& data) override; glm::dvec3 scaleValue(const UpdateData& data) const override; static documentation::Documentation Documentation(); diff --git a/modules/base/translation/globetranslation.cpp b/modules/base/translation/globetranslation.cpp index 1576c2c6bb..f6060d6b11 100644 --- a/modules/base/translation/globetranslation.cpp +++ b/modules/base/translation/globetranslation.cpp @@ -37,6 +37,8 @@ #include namespace { + constexpr std::string_view _loggerCat = "GlobeTranslation"; + constexpr openspace::properties::Property::PropertyInfo GlobeInfo = { "Globe", "Attached Globe", @@ -188,14 +190,10 @@ GlobeTranslation::GlobeTranslation(const ghoul::Dictionary& dictionary) void GlobeTranslation::fillAttachedNode() { SceneGraphNode* n = sceneGraphNode(_sceneGraphNode); - if (!n || !n->renderable()) { - LERRORC( - "GlobeTranslation", - "Could not set attached node as it does not have a renderable" - ); + if (!n) { + LERROR(std::format("Could not find attached node '{}'", _sceneGraphNode.value())); return; } - _attachedNode = n; } @@ -204,12 +202,12 @@ void GlobeTranslation::setUpdateVariables() { requireUpdate(); } -void GlobeTranslation::update(const UpdateData& data) { - if (!_attachedNode) [[unlikely]] { - fillAttachedNode(); - _positionIsDirty = true; - } +void GlobeTranslation::initialize() { + Translation::initialize(); + fillAttachedNode(); +} +void GlobeTranslation::update(const UpdateData& data) { if (_useHeightmap || _useCamera) { // If we use the heightmap, we have to compute the height every frame setUpdateVariables(); @@ -223,11 +221,7 @@ glm::dvec3 GlobeTranslation::position(const UpdateData&) const { return _position; } - if (!_attachedNode) { - LERRORC( - "GlobeRotation", - std::format("Could not find attached node '{}'", _sceneGraphNode.value()) - ); + if (!_attachedNode) [[unlikely]] { return _position; } diff --git a/modules/base/translation/globetranslation.h b/modules/base/translation/globetranslation.h index 675692b44b..6a8d9c7b1d 100644 --- a/modules/base/translation/globetranslation.h +++ b/modules/base/translation/globetranslation.h @@ -39,6 +39,8 @@ class GlobeTranslation : public Translation { public: explicit GlobeTranslation(const ghoul::Dictionary& dictionary); + void initialize() override; + void update(const UpdateData& data) override; glm::dvec3 position(const UpdateData& data) const override; diff --git a/modules/base/translation/multitranslation.cpp b/modules/base/translation/multitranslation.cpp index 2742acff10..c368d915c8 100644 --- a/modules/base/translation/multitranslation.cpp +++ b/modules/base/translation/multitranslation.cpp @@ -64,6 +64,13 @@ MultiTranslation::MultiTranslation(const ghoul::Dictionary& dictionary) } } +void MultiTranslation::initialize() { + Translation::initialize(); + for (const ghoul::mm_unique_ptr& translation : _translations) { + translation->initialize(); + } +} + void MultiTranslation::update(const UpdateData& data) { for (const ghoul::mm_unique_ptr& translation : _translations) { translation->update(data); diff --git a/modules/base/translation/multitranslation.h b/modules/base/translation/multitranslation.h index 7a5f3c3e86..4a69d65d82 100644 --- a/modules/base/translation/multitranslation.h +++ b/modules/base/translation/multitranslation.h @@ -37,6 +37,8 @@ class MultiTranslation : public Translation { public: explicit MultiTranslation(const ghoul::Dictionary& dictionary); + void initialize() override; + void update(const UpdateData& data) override; glm::dvec3 position(const UpdateData& data) const override; static documentation::Documentation Documentation(); diff --git a/modules/base/translation/timelinetranslation.cpp b/modules/base/translation/timelinetranslation.cpp index bcf417fbe9..9bed9ab2ce 100644 --- a/modules/base/translation/timelinetranslation.cpp +++ b/modules/base/translation/timelinetranslation.cpp @@ -83,6 +83,13 @@ TimelineTranslation::TimelineTranslation(const ghoul::Dictionary& dictionary) addProperty(_shouldInterpolate); } +void TimelineTranslation::initialize() { + Translation::initialize(); + for (const Keyframe>& kf : _timeline.keyframes()) { + kf.data->initialize(); + } +} + void TimelineTranslation::update(const UpdateData& data) { const double now = data.time.j2000Seconds(); using KeyframePointer = const Keyframe>*; diff --git a/modules/base/translation/timelinetranslation.h b/modules/base/translation/timelinetranslation.h index 04bf958ac3..17059ddc30 100644 --- a/modules/base/translation/timelinetranslation.h +++ b/modules/base/translation/timelinetranslation.h @@ -41,6 +41,8 @@ class TimelineTranslation : public Translation { public: explicit TimelineTranslation(const ghoul::Dictionary& dictionary); + void initialize() override; + void update(const UpdateData& data) override; glm::dvec3 position(const UpdateData& data) const override; static documentation::Documentation Documentation(); diff --git a/src/scene/rotation.cpp b/src/scene/rotation.cpp index 1268c28d6c..8ef010c9b5 100644 --- a/src/scene/rotation.cpp +++ b/src/scene/rotation.cpp @@ -90,8 +90,10 @@ void Rotation::requireUpdate() { _needsUpdate = true; } -bool Rotation::initialize() { - return true; +void Rotation::initialize() { + if (_timeFrame) { + _timeFrame->initialize(); + } } const glm::dmat3& Rotation::matrix() const { diff --git a/src/scene/scale.cpp b/src/scene/scale.cpp index a1b7752510..aec649c5c6 100644 --- a/src/scene/scale.cpp +++ b/src/scene/scale.cpp @@ -88,8 +88,10 @@ void Scale::requireUpdate() { _needsUpdate = true; } -bool Scale::initialize() { - return true; +void Scale::initialize() { + if (_timeFrame) { + _timeFrame->initialize(); + } } glm::dvec3 Scale::scaleValue() const { diff --git a/src/scene/translation.cpp b/src/scene/translation.cpp index da441f1b89..b203161ceb 100644 --- a/src/scene/translation.cpp +++ b/src/scene/translation.cpp @@ -81,8 +81,10 @@ Translation::Translation(const ghoul::Dictionary& dictionary) } } -bool Translation::initialize() { - return true; +void Translation::initialize() { + if (_timeFrame) { + _timeFrame->initialize(); + } } void Translation::update(const UpdateData& data) {