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

Support configuring particle scatter ratio in particle emitter system #674

Merged
merged 7 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
15 changes: 15 additions & 0 deletions src/rendering/SceneManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,21 @@ rendering::ParticleEmitterPtr SceneManager::UpdateParticleEmitter(Entity _id,
if (_emitter.has_pose())
emitter->SetLocalPose(msgs::Convert(_emitter.pose()));

// particle scatter ratio
if (_emitter.has_header())
{
for (int i = 0; i < _emitter.header().data_size(); ++i)
{
const auto &data = _emitter.header().data(i);
const std::string key = "particle_scatter_ratio";
if (data.key() == "particle_scatter_ratio" && data.value_size() > 0)
{
emitter->SetUserData(key, math::parseFloat(data.value(0)));
break;
}
}
}

return emitter;
}

Expand Down
11 changes: 11 additions & 0 deletions src/systems/particle_emitter/ParticleEmitter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@ void ParticleEmitter::Configure(const Entity &_entity,
absolutePath);
}

// particle scatter ratio
const std::string scatterRatioKey = "particle_scatter_ratio";
if (_sdf->HasElement(scatterRatioKey))
{
// todo(anyone) add particle_scatter_ratio field in next release of ign-msgs
auto data = this->dataPtr->emitter.mutable_header()->add_data();
adlarkin marked this conversation as resolved.
Show resolved Hide resolved
data->set_key(scatterRatioKey);
std::string *value = data->add_value();
*value = _sdf->Get<std::string>(scatterRatioKey);
}

igndbg << "Loading particle emitter:" << std::endl
<< this->dataPtr->emitter.DebugString() << std::endl;

Expand Down
18 changes: 18 additions & 0 deletions test/integration/particle_emitter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,24 @@ TEST_F(ParticleEmitterTest, SDFLoad)
// and let rendering do the findFile instead
EXPECT_EQ(std::string(),
_emitter->Data().color_range_image().data());

// particle scatter ratio is temporarily stored in header
bool hasParticleScatterRatio = false;
for (int i = 0; i < _emitter->Data().header().data_size(); ++i)
{
for (int j = 0;
j < _emitter->Data().header().data(i).value_size(); ++j)
{
if (_emitter->Data().header().data(i).key() ==
"particle_scatter_ratio")
{
EXPECT_DOUBLE_EQ(0.01, math::parseFloat(
_emitter->Data().header().data(i).value(0)));
hasParticleScatterRatio = true;
}
}
}
EXPECT_TRUE(hasParticleScatterRatio);
}
else
{
Expand Down
1 change: 1 addition & 0 deletions test/worlds/particle_emitter.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
<color_end>0 1 0</color_end>
<scale_rate>10</scale_rate>
<color_range_image>/path/to/dummy_image.png</color_range_image>
<particle_scatter_ratio>0.01</particle_scatter_ratio>
</plugin>
</model>

Expand Down