Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Particle system - Part 1 #516

Merged
merged 18 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions include/ignition/gazebo/components/ParticleEmitter.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef IGNITION_GAZEBO_COMPONENTS_PARTICLEEMITTER_HH_
#define IGNITION_GAZEBO_COMPONENTS_PARTICLEEMITTER_HH_

#include <ignition/msgs/particle_emitter.pb.h>
#include <ignition/gazebo/components/Component.hh>
#include <ignition/gazebo/components/Factory.hh>
#include <ignition/gazebo/components/Serialization.hh>
#include <ignition/gazebo/config.hh>

namespace ignition
{
namespace gazebo
{
// Inline bracket to help doxygen filtering.
inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
namespace components
{
/// \brief A component that contains a particle emitter.
using ParticleEmitter = Component<msgs::ParticleEmitter,
class ParticleEmitterTag,
serializers::MsgSerializer>;
IGN_GAZEBO_REGISTER_COMPONENT("ign_gazebo_components.ParticleEmitter",
ParticleEmitter)
}
}
}
}

#endif
74 changes: 74 additions & 0 deletions test/integration/components.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include <gtest/gtest.h>

#include <ignition/msgs/particle_emitter.pb.h>

#include <chrono>

#include <sdf/Cylinder.hh>
Expand Down Expand Up @@ -62,6 +64,7 @@
#include "ignition/gazebo/components/Name.hh"
#include "ignition/gazebo/components/ParentEntity.hh"
#include "ignition/gazebo/components/ParentLinkName.hh"
#include "ignition/gazebo/components/ParticleEmitter.hh"
#include "ignition/gazebo/components/Performer.hh"
#include "ignition/gazebo/components/PerformerAffinity.hh"
#include "ignition/gazebo/components/PerformerLevels.hh"
Expand Down Expand Up @@ -1466,3 +1469,74 @@ TEST_F(ComponentsTest, Scene)
EXPECT_FALSE(comp3.Data().Grid());
EXPECT_TRUE(comp3.Data().OriginVisual());
}

//////////////////////////////////////////////////
TEST_F(ComponentsTest, ParticleEmitter)
{
msgs::ParticleEmitter emitter1;
emitter1.set_name("emitter1");
emitter1.set_id(0);
emitter1.set_type(ignition::msgs::ParticleEmitter_EmitterType_BOX);
emitter1.mutable_size()->set_x(1);
emitter1.mutable_size()->set_y(2);
emitter1.mutable_size()->set_z(3);
emitter1.set_rate(4.0);
emitter1.set_duration(5.0);
emitter1.set_emitting(false);
emitter1.mutable_particle_size()->set_x(0.1);
emitter1.mutable_particle_size()->set_y(0.2);
emitter1.mutable_particle_size()->set_z(0.3);
emitter1.set_lifetime(6.0);
emitter1.set_min_velocity(7.0);
emitter1.set_max_velocity(8.0);
emitter1.mutable_color_start()->set_r(1.0);
emitter1.mutable_color_start()->set_g(0);
emitter1.mutable_color_start()->set_b(0);
emitter1.mutable_color_start()->set_a(0);
emitter1.mutable_color_end()->set_r(1.0);
emitter1.mutable_color_end()->set_g(1.0);
emitter1.mutable_color_end()->set_b(1.0);
emitter1.mutable_color_end()->set_a(0);
emitter1.set_scale_rate(9.0);
emitter1.set_color_range_image("path_to_texture");

msgs::ParticleEmitter emitter2;
emitter2.set_name("emitter2");
emitter2.set_id(1);
emitter2.set_type(ignition::msgs::ParticleEmitter_EmitterType_BOX);
emitter2.mutable_size()->set_x(1);
emitter2.mutable_size()->set_y(2);
emitter2.mutable_size()->set_z(3);
emitter2.set_rate(4.0);
emitter2.set_duration(5.0);
emitter2.set_emitting(false);
emitter2.mutable_particle_size()->set_x(0.1);
emitter2.mutable_particle_size()->set_y(0.2);
emitter2.mutable_particle_size()->set_z(0.3);
emitter2.set_lifetime(6.0);
emitter2.set_min_velocity(7.0);
emitter2.set_max_velocity(8.0);
emitter2.mutable_color_start()->set_r(1.0);
emitter2.mutable_color_start()->set_g(0);
emitter2.mutable_color_start()->set_b(0);
emitter2.mutable_color_start()->set_a(0);
emitter2.mutable_color_end()->set_r(1.0);
emitter2.mutable_color_end()->set_g(1.0);
emitter2.mutable_color_end()->set_b(1.0);
emitter2.mutable_color_end()->set_a(0);
emitter2.set_scale_rate(9.0);
emitter2.set_color_range_image("path_to_texture");

// Create components.
auto comp1 = components::ParticleEmitter(emitter1);
auto comp2 = components::ParticleEmitter(emitter2);

// Stream operators.
std::ostringstream ostr;
comp1.Serialize(ostr);

std::istringstream istr(ostr.str());
components::ParticleEmitter comp3;
comp3.Deserialize(istr);
EXPECT_EQ(comp1.Data().id(), comp3.Data().id());
}