6363#include " ignition/gazebo/components/Model.hh"
6464#include " ignition/gazebo/components/Name.hh"
6565#include " ignition/gazebo/components/ParentEntity.hh"
66+ #include " ignition/gazebo/components/ParticleEmitter.hh"
6667#include " ignition/gazebo/components/Pose.hh"
6768#include " ignition/gazebo/components/RgbdCamera.hh"
6869#include " ignition/gazebo/components/Scene.hh"
@@ -166,6 +167,17 @@ class ignition::gazebo::RenderUtilPrivate
166167 public: std::vector<std::tuple<Entity, sdf::Sensor, Entity>>
167168 newSensors;
168169
170+ // / \brief New particle emitter to be created. The elements in the tuple are:
171+ // / [0] entity id, [1], particle emitter, [2] parent entity id
172+ public: std::vector<std::tuple<Entity, msgs::ParticleEmitter, Entity>>
173+ newParticleEmitters;
174+
175+ // / \brief New particle emitter commands to be requested.
176+ // / The map key and value are: entity id of the particle emitter to
177+ // / update, and particle emitter msg
178+ public: std::unordered_map<Entity, msgs::ParticleEmitter>
179+ newParticleEmittersCmds;
180+
169181 // / \brief Map of ids of entites to be removed and sim iteration when the
170182 // / remove request is received
171183 public: std::unordered_map<Entity, uint64_t > removeEntities;
@@ -329,6 +341,27 @@ void RenderUtil::UpdateECM(const UpdateInfo &/*_info*/,
329341{
330342 std::lock_guard<std::mutex> lock (this ->dataPtr ->updateMutex );
331343
344+ // particle emitters commands
345+ _ecm.Each <components::ParticleEmitterCmd>(
346+ [&](const Entity &_entity,
347+ const components::ParticleEmitterCmd *_emitterCmd) -> bool
348+ {
349+ // store emitter properties and update them in rendering thread
350+ this ->dataPtr ->newParticleEmittersCmds [_entity] =
351+ _emitterCmd->Data ();
352+
353+ // update pose comp here
354+ if (_emitterCmd->Data ().has_pose ())
355+ {
356+ auto poseComp = _ecm.Component <components::Pose>(_entity);
357+ if (poseComp)
358+ poseComp->Data () = msgs::Convert (_emitterCmd->Data ().pose ());
359+ }
360+ _ecm.RemoveComponent <components::ParticleEmitterCmd>(_entity);
361+
362+ return true ;
363+ });
364+
332365 // Update lights
333366 auto olderEntitiesLightsCmdToDelete =
334367 std::move (this ->dataPtr ->entityLightsCmdToDelete );
@@ -483,6 +516,9 @@ void RenderUtil::Update()
483516 auto newVisuals = std::move (this ->dataPtr ->newVisuals );
484517 auto newActors = std::move (this ->dataPtr ->newActors );
485518 auto newLights = std::move (this ->dataPtr ->newLights );
519+ auto newParticleEmitters = std::move (this ->dataPtr ->newParticleEmitters );
520+ auto newParticleEmittersCmds =
521+ std::move (this ->dataPtr ->newParticleEmittersCmds );
486522 auto removeEntities = std::move (this ->dataPtr ->removeEntities );
487523 auto entityPoses = std::move (this ->dataPtr ->entityPoses );
488524 auto entityLights = std::move (this ->dataPtr ->entityLights );
@@ -499,6 +535,8 @@ void RenderUtil::Update()
499535 this ->dataPtr ->newVisuals .clear ();
500536 this ->dataPtr ->newActors .clear ();
501537 this ->dataPtr ->newLights .clear ();
538+ this ->dataPtr ->newParticleEmitters .clear ();
539+ this ->dataPtr ->newParticleEmittersCmds .clear ();
502540 this ->dataPtr ->removeEntities .clear ();
503541 this ->dataPtr ->entityPoses .clear ();
504542 this ->dataPtr ->entityLights .clear ();
@@ -601,6 +639,18 @@ void RenderUtil::Update()
601639 std::get<0 >(light), std::get<1 >(light), std::get<2 >(light));
602640 }
603641
642+ for (const auto &emitter : newParticleEmitters)
643+ {
644+ this ->dataPtr ->sceneManager .CreateParticleEmitter (
645+ std::get<0 >(emitter), std::get<1 >(emitter), std::get<2 >(emitter));
646+ }
647+
648+ for (const auto &emitterCmd : newParticleEmittersCmds)
649+ {
650+ this ->dataPtr ->sceneManager .UpdateParticleEmitter (
651+ emitterCmd.first , emitterCmd.second );
652+ }
653+
604654 if (this ->dataPtr ->enableSensors && this ->dataPtr ->createSensorCb )
605655 {
606656 for (const auto &sensor : newSensors)
@@ -1174,6 +1224,17 @@ void RenderUtilPrivate::CreateRenderingEntities(
11741224 return true ;
11751225 });
11761226
1227+ // particle emitters
1228+ _ecm.Each <components::ParticleEmitter, components::ParentEntity>(
1229+ [&](const Entity &_entity,
1230+ const components::ParticleEmitter *_emitter,
1231+ const components::ParentEntity *_parent) -> bool
1232+ {
1233+ this ->newParticleEmitters .push_back (
1234+ std::make_tuple (_entity, _emitter->Data (), _parent->Data ()));
1235+ return true ;
1236+ });
1237+
11771238 if (this ->enableSensors )
11781239 {
11791240 // Create cameras
@@ -1385,6 +1446,17 @@ void RenderUtilPrivate::CreateRenderingEntities(
13851446 return true ;
13861447 });
13871448
1449+ // particle emitters
1450+ _ecm.EachNew <components::ParticleEmitter, components::ParentEntity>(
1451+ [&](const Entity &_entity,
1452+ const components::ParticleEmitter *_emitter,
1453+ const components::ParentEntity *_parent) -> bool
1454+ {
1455+ this ->newParticleEmitters .push_back (
1456+ std::make_tuple (_entity, _emitter->Data (), _parent->Data ()));
1457+ return true ;
1458+ });
1459+
13881460 if (this ->enableSensors )
13891461 {
13901462 // Create cameras
@@ -1626,6 +1698,14 @@ void RenderUtilPrivate::RemoveRenderingEntities(
16261698 return true ;
16271699 });
16281700
1701+ // particle emitters
1702+ _ecm.EachRemoved <components::ParticleEmitter>(
1703+ [&](const Entity &_entity, const components::ParticleEmitter *)->bool
1704+ {
1705+ this ->removeEntities [_entity] = _info.iterations ;
1706+ return true ;
1707+ });
1708+
16291709 // cameras
16301710 _ecm.EachRemoved <components::Camera>(
16311711 [&](const Entity &_entity, const components::Camera *)->bool
0 commit comments