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

Expose particle scatter ratio parameter #269

Merged
merged 9 commits into from
Mar 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
44 changes: 23 additions & 21 deletions ogre2/src/Ogre2ParticleNoiseListener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void Ogre2ParticleNoiseListener::preRenderTargetUpdate(
static_cast<float>(particleStddev));

// get particle scatter ratio value from particle emitter user data
// set pass that to the shaders
// and pass that to the shaders
Ogre::Any userAny = ps->getUserObjectBindings().getUserAny();
if (!userAny.isEmpty() && userAny.getType() == typeid(unsigned int))
{
Expand All @@ -103,39 +103,41 @@ void Ogre2ParticleNoiseListener::preRenderTargetUpdate(
}
Ogre2VisualPtr ogreVisual =
std::dynamic_pointer_cast<Ogre2Visual>(result);

std::string particleScatterRatioKey = "particle_scatter_ratio";
Variant particleScatterRatioAny =
ogreVisual->UserData(particleScatterRatioKey);
if (particleScatterRatioAny.index() != std::variant_npos)
if (ogreVisual)
{
float ratio = -1.0;
try
{
ratio = std::get<float>(particleScatterRatioAny);
}
catch(...)
const std::string particleScatterRatioKey = "particle_scatter_ratio";
Variant particleScatterRatioAny =
ogreVisual->UserData(particleScatterRatioKey);
if (particleScatterRatioAny.index() != std::variant_npos)
{
float ratio = -1.0;
try
{
ratio = std::get<double>(particleScatterRatioAny);
ratio = std::get<float>(particleScatterRatioAny);
}
catch(...)
{
try
{
ratio = std::get<int>(particleScatterRatioAny);
ratio = std::get<double>(particleScatterRatioAny);
}
catch(std::bad_variant_access &e)
catch(...)
{
ignerr << "Error casting user data: " << e.what() << "\n";
ratio = -1.0;
try
{
ratio = std::get<int>(particleScatterRatioAny);
}
catch(std::bad_variant_access &e)
{
ignerr << "Error casting user data: " << e.what() << "\n";
ratio = -1.0;
}
}
}
}
if (ratio > 0)
{
this->particleScatterRatio = ratio;
if (ratio > 0)
{
this->particleScatterRatio = ratio;
}
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions ogre2/src/Ogre2ParticleNoiseListener.hh
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ namespace ignition
private: Ogre::MaterialPtr ogreMaterial;

/// \brief Particle scatter ratio. This is used to determine the ratio of
/// particles that will detected by sensors
private: double particleScatterRatio = 0.65;
/// particles that will detected by sensors. Increasing the ratio
adlarkin marked this conversation as resolved.
Show resolved Hide resolved
/// increases the scatter of the particles, which means there is a higher
/// chance of particles reflecting and interfering with depth sensing,
/// making the emitter appear more dense. Decreasing the ratio decreases
/// the scatter of the particles, making it appear less dense. This value
/// should be > 0.
private: float particleScatterRatio = 0.65f;
};
}
}
Expand Down