Skip to content

Commit deddb6f

Browse files
nkoenigadlarkiniche033Nate Koenig
authored
Particle system - Part 1 (gazebosim#516)
* New ParticleEmitter component. Signed-off-by: Carlos Agüero <caguero@openrobotics.org> * Remove attribute name. Signed-off-by: Carlos Agüero <caguero@openrobotics.org> * Update particle emitter component to use ignition::msgs::ParticleEmitter. Signed-off-by: Carlos Agüero <caguero@openrobotics.org> * Simplify particle emitter component. Signed-off-by: Carlos Agüero <caguero@openrobotics.org> * Particle system - Part2 (gazebosim#562) Signed-off-by: Carlos Agüero <caguero@osrfoundation.org> Co-authored-by: Ashton Larkin <ashton@openrobotics.org> Co-authored-by: Ian Chen <ichen@osrfoundation.org> * bump msgs version to 6.3.0 Signed-off-by: Ian Chen <ichen@osrfoundation.org> * Remove extra main Signed-off-by: Nate Koenig <nate@openrobotics.org> * Added missing <set> Signed-off-by: Nate Koenig <nate@openrobotics.org> Co-authored-by: Ashton Larkin <42042756+adlarkin@users.noreply.github.com> Co-authored-by: Ian Chen <ichen@osrfoundation.org> Co-authored-by: Ashton Larkin <ashton@openrobotics.org> Co-authored-by: Nate Koenig <nate@openrobotics.org>
2 parents 44a6713 + 04721d3 commit deddb6f

15 files changed

Lines changed: 1331 additions & 17 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.5.1 FATAL_ERROR)
33
#============================================================================
44
# Initialize the project
55
#============================================================================
6-
project(ignition-gazebo4 VERSION 4.4.0)
6+
project(ignition-gazebo4 VERSION 4.5.0)
77

88
#============================================================================
99
# Find ignition-cmake
@@ -53,7 +53,7 @@ set(IGN_TRANSPORT_VER ${ignition-transport9_VERSION_MAJOR})
5353

5454
#--------------------------------------
5555
# Find ignition-msgs
56-
ign_find_package(ignition-msgs6 REQUIRED VERSION 6.2)
56+
ign_find_package(ignition-msgs6 REQUIRED VERSION 6.3)
5757
set(IGN_MSGS_VER ${ignition-msgs6_VERSION_MAJOR})
5858

5959
#--------------------------------------

Changelog.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
## Ignition Gazebo 4.x
22

3+
### Ignition Gazebo 4.5.0 (2020-02-17)
4+
5+
1. Added particle system.
6+
* [Pull Request 516](https://github.com/ignitionrobotics/ign-gazebo/pull/516)
7+
8+
1. Add Light Usercommand and include Light parameters in the componentInspector
9+
* [Pull Request 482](https://github.com/ignitionrobotics/ign-gazebo/pull/482)
10+
11+
1. Added link to HW-accelerated video recording.
12+
* [Pull Request 627](https://github.com/ignitionrobotics/ign-gazebo/pull/627)
13+
14+
1. Fix EntityComponentManager race condition.
15+
* [Pull Request 601](https://github.com/ignitionrobotics/ign-gazebo/pull/601)
16+
17+
1. Add SDF topic validity check.
18+
* [Pull Request 632](https://github.com/ignitionrobotics/ign-gazebo/pull/632)
19+
20+
1. Add JointTrajectoryController system plugin.
21+
* [Pull Request 473](https://github.com/ignitionrobotics/ign-gazebo/pull/473)
22+
323
### Ignition Gazebo 4.4.0 (2020-02-10)
424

525
1. Added issue and PR templates
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" ?>
2+
3+
<!--
4+
Launch this example with:
5+
6+
ign gazebo -r particle_emitter.sdf
7+
8+
Try modifying some parameters of the emitter:
9+
10+
To disable the particle emitter:
11+
12+
ign topic -t /model/smoke_generator/particle_emitter/smoke_generator -m ignition.msgs.ParticleEmitter -p 'name: "smoke_generator" pose { position { } orientation { w: 1 } } size { x: 1 y: 1 z: 1 } rate: 10 emitting: false particle_size { x: 1 y: 1 z: 1 } lifetime: 2 material { header { data { key: "double_sided" value: "0" } } ambient { a: 1 } diffuse { r: 0.7 g: 0.7 b: 0.7 a: 1 } specular { a: 1 } emissive { a: 1 } lighting: true pbr { type: METAL albedo_map: "/home/caguero/.ignition/fuel/fuel.ignitionrobotics.org/caguero/models/smoke_generator/2/materials/textures/smoke.png" metalness: 0.5 roughness: 0.5 } } min_velocity: 10 max_velocity: 20 color_start { r: 1 g: 1 b: 1 a: 1 } color_end { r: 1 g: 1 b: 1 a: 1 } scale_rate: 10 color_range_image: "/home/caguero/.ignition/fuel/fuel.ignitionrobotics.org/caguero/models/smoke_generator/2/materials/textures/smokecolors.png"'
13+
14+
Enable back the particle emitter:
15+
16+
ign topic -t /model/smoke_generator/particle_emitter/smoke_generator -m ignition.msgs.ParticleEmitter -p 'name: "smoke_generator" pose { position { } orientation { w: 1 } } size { x: 1 y: 1 z: 1 } rate: 10 emitting: true particle_size { x: 1 y: 1 z: 1 } lifetime: 2 material { header { data { key: "double_sided" value: "0" } } ambient { a: 1 } diffuse { r: 0.7 g: 0.7 b: 0.7 a: 1 } specular { a: 1 } emissive { a: 1 } lighting: true pbr { type: METAL albedo_map: "/home/caguero/.ignition/fuel/fuel.ignitionrobotics.org/caguero/models/smoke_generator/2/materials/textures/smoke.png" metalness: 0.5 roughness: 0.5 } } min_velocity: 10 max_velocity: 20 color_start { r: 1 g: 1 b: 1 a: 1 } color_end { r: 1 g: 1 b: 1 a: 1 } scale_rate: 10 color_range_image: "/home/caguero/.ignition/fuel/fuel.ignitionrobotics.org/caguero/models/smoke_generator/2/materials/textures/smokecolors.png"'
17+
18+
Then, change the particle rate:
19+
20+
ign topic -t /model/smoke_generator/particle_emitter/smoke_generator -m ignition.msgs.ParticleEmitter -p 'name: "smoke_generator" pose { position { } orientation { w: 1 } } size { x: 1 y: 1 z: 1 } rate: 100 emitting: true particle_size { x: 1 y: 1 z: 1 } lifetime: 2 material { header { data { key: "double_sided" value: "0" } } ambient { a: 1 } diffuse { r: 0.7 g: 0.7 b: 0.7 a: 1 } specular { a: 1 } emissive { a: 1 } lighting: true pbr { type: METAL albedo_map: "/home/caguero/.ignition/fuel/fuel.ignitionrobotics.org/caguero/models/smoke_generator/2/materials/textures/smoke.png" metalness: 0.5 roughness: 0.5 } } min_velocity: 10 max_velocity: 20 color_start { r: 1 g: 1 b: 1 a: 1 } color_end { r: 1 g: 1 b: 1 a: 1 } scale_rate: 10 color_range_image: "/home/caguero/.ignition/fuel/fuel.ignitionrobotics.org/caguero/models/smoke_generator/2/materials/textures/smokecolors.png"'
21+
-->
22+
23+
<sdf version="1.6">
24+
<world name="particle_emitters">
25+
26+
<physics name="1ms" type="ode">
27+
<max_step_size>0.001</max_step_size>
28+
<real_time_factor>1.0</real_time_factor>
29+
</physics>
30+
<plugin
31+
filename="ignition-gazebo-physics-system"
32+
name="ignition::gazebo::systems::Physics">
33+
</plugin>
34+
<plugin
35+
filename="ignition-gazebo-user-commands-system"
36+
name="ignition::gazebo::systems::UserCommands">
37+
</plugin>
38+
<plugin
39+
filename="ignition-gazebo-scene-broadcaster-system"
40+
name="ignition::gazebo::systems::SceneBroadcaster">
41+
</plugin>
42+
43+
<light type="directional" name="sun">
44+
<cast_shadows>true</cast_shadows>
45+
<pose>0 0 10 0 0 0</pose>
46+
<diffuse>1 1 1 1</diffuse>
47+
<specular>0.5 0.5 0.5 1</specular>
48+
<attenuation>
49+
<range>1000</range>
50+
<constant>0.9</constant>
51+
<linear>0.01</linear>
52+
<quadratic>0.001</quadratic>
53+
</attenuation>
54+
<direction>-0.5 0.1 -0.9</direction>
55+
</light>
56+
57+
<model name="ground_plane">
58+
<static>true</static>
59+
<link name="link">
60+
<collision name="collision">
61+
<geometry>
62+
<plane>
63+
<normal>0 0 1</normal>
64+
</plane>
65+
</geometry>
66+
</collision>
67+
<visual name="visual">
68+
<geometry>
69+
<plane>
70+
<normal>0 0 1</normal>
71+
<size>100 100</size>
72+
</plane>
73+
</geometry>
74+
<material>
75+
<ambient>0.8 0.8 0.8 1</ambient>
76+
<diffuse>0.8 0.8 0.8 1</diffuse>
77+
<specular>0.8 0.8 0.8 1</specular>
78+
</material>
79+
</visual>
80+
</link>
81+
</model>
82+
83+
<include>
84+
<uri>https://fuel.ignitionrobotics.org/1.0/caguero/models/smoke_generator</uri>
85+
</include>
86+
87+
</world>
88+
</sdf>
89+
90+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (C) 2021 Open Source Robotics Foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
#ifndef IGNITION_GAZEBO_COMPONENTS_PARTICLEEMITTER_HH_
18+
#define IGNITION_GAZEBO_COMPONENTS_PARTICLEEMITTER_HH_
19+
20+
#include <ignition/msgs/particle_emitter.pb.h>
21+
#include <ignition/gazebo/components/Component.hh>
22+
#include <ignition/gazebo/components/Factory.hh>
23+
#include <ignition/gazebo/components/Serialization.hh>
24+
#include <ignition/gazebo/config.hh>
25+
26+
namespace ignition
27+
{
28+
namespace gazebo
29+
{
30+
// Inline bracket to help doxygen filtering.
31+
inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
32+
namespace components
33+
{
34+
/// \brief A component that contains a particle emitter.
35+
using ParticleEmitter = Component<msgs::ParticleEmitter,
36+
class ParticleEmitterTag,
37+
serializers::MsgSerializer>;
38+
IGN_GAZEBO_REGISTER_COMPONENT("ign_gazebo_components.ParticleEmitter",
39+
ParticleEmitter)
40+
41+
/// \brief A component that contains a particle emitter command.
42+
using ParticleEmitterCmd = Component<msgs::ParticleEmitter,
43+
class ParticleEmitterCmdTag,
44+
serializers::MsgSerializer>;
45+
IGN_GAZEBO_REGISTER_COMPONENT("ign_gazebo_components.ParticleEmitterCmd",
46+
ParticleEmitterCmd)
47+
}
48+
}
49+
}
50+
}
51+
52+
#endif

include/ignition/gazebo/rendering/SceneManager.hh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include <ignition/common/Animation.hh>
3535
#include <ignition/common/graphics/Types.hh>
3636

37+
#include <ignition/msgs/particle_emitter.pb.h>
38+
3739
#include <ignition/rendering/RenderTypes.hh>
3840

3941
#include <ignition/gazebo/config.hh>
@@ -161,6 +163,21 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
161163
public: rendering::LightPtr CreateLight(Entity _id,
162164
const sdf::Light &_light, Entity _parentId);
163165

166+
/// \brief Create a particle emitter.
167+
/// \param[in] _id Unique particle emitter id
168+
/// \param[in] _emitter Particle emitter data
169+
/// \param[in] _parentId Parent id
170+
/// \return Default particle emitter object created
171+
public: rendering::ParticleEmitterPtr CreateParticleEmitter(
172+
Entity _id, const msgs::ParticleEmitter &_emitter, Entity _parentId);
173+
174+
/// \brief Update an existing particle emitter
175+
/// \brief _id Emitter id to update
176+
/// \brief _emitter Data to update the particle emitter
177+
/// \return Particle emitter updated
178+
public: rendering::ParticleEmitterPtr UpdateParticleEmitter(Entity _id,
179+
const msgs::ParticleEmitter &_emitter);
180+
164181
/// \brief Ignition sensors is the one responsible for adding sensors
165182
/// to the scene. Here we just keep track of it and make sure it has
166183
/// the correct parent.

src/rendering/RenderUtil.cc

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
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

Comments
 (0)