diff --git a/include/ignition/gazebo/rendering/SceneManager.hh b/include/ignition/gazebo/rendering/SceneManager.hh index 1ea41fb348..60aefb24d3 100644 --- a/include/ignition/gazebo/rendering/SceneManager.hh +++ b/include/ignition/gazebo/rendering/SceneManager.hh @@ -200,6 +200,13 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { /// \return Pointer to requested visual public: rendering::VisualPtr VisualById(Entity _id); + /// \brief Sequences Trajectories + /// \param[in] _trajectories Actor trajectories + /// \param[in] _time Actor trajectory delay start time (miliseconds) + public: void SequenceTrajectories( + std::vector& _trajectories, + std::chrono::steady_clock::time_point _time); + /// \brief Create an actor /// \param[in] _id Unique actor id /// \param[in] _actor Actor sdf dom diff --git a/src/rendering/SceneManager.cc b/src/rendering/SceneManager.cc index 3caf84c4ed..7924bc61f2 100644 --- a/src/rendering/SceneManager.cc +++ b/src/rendering/SceneManager.cc @@ -910,6 +910,20 @@ rendering::MaterialPtr SceneManager::LoadMaterial( return material; } +void SceneManager::SequenceTrajectories( + std::vector& _trajectories, + TP _time) +{ + // sequencing all trajectories + for (auto &trajectory : _trajectories) + { + auto duration = trajectory.Duration(); + trajectory.SetStartTime(_time); + _time += duration; + trajectory.SetEndTime(_time); + } +} + ///////////////////////////////////////////////// rendering::VisualPtr SceneManager::CreateActor(Entity _id, const sdf::Actor &_actor, const std::string &_name, Entity _parentId) @@ -1164,13 +1178,8 @@ rendering::VisualPtr SceneManager::CreateActor(Entity _id, auto delayStartTime = std::chrono::milliseconds( static_cast(_actor.ScriptDelayStart() * 1000)); TP time(delayStartTime); - for (auto &trajectory : trajectories) - { - auto dura = trajectory.Duration(); - trajectory.SetStartTime(time); - time += dura; - trajectory.SetEndTime(time); - } + this->SequenceTrajectories(trajectories, time); + // loop flag: add a placeholder trajectory to indicate no loop if (!_actor.ScriptLoop())