From a90cb184739efc86b5cfd8b40cfd90085323653d Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Tue, 9 Feb 2021 18:31:25 -0800 Subject: [PATCH 1/5] fix particle size Signed-off-by: Ian Chen --- examples/particles_demo/Main.cc | 25 +++- .../rendering/ogre2/Ogre2ParticleEmitter.hh | 6 + ogre2/src/Ogre2ParticleEmitter.cc | 128 ++++++++++++++---- 3 files changed, 130 insertions(+), 29 deletions(-) diff --git a/examples/particles_demo/Main.cc b/examples/particles_demo/Main.cc index 75efbd1f8..5b0b743c4 100644 --- a/examples/particles_demo/Main.cc +++ b/examples/particles_demo/Main.cc @@ -106,17 +106,34 @@ void buildScene(ScenePtr _scene) particleMaterial->SetDepthWriteEnabled(false); //! [create particle emitter] + //ParticleEmitterPtr emitter = _scene->CreateParticleEmitter(); + //emitter->SetType(EM_POINT); + //emitter->SetEmitterSize({1.0, 1.0, 1.0}); + //emitter->SetLocalPose({2, 1.10, 1.25, 1.5708, 0, 2.3}); + //emitter->SetRate(10); + //emitter->SetParticleSize({0.1, 0.1, 0.1}); + //emitter->SetLifetime(2); + //emitter->SetVelocityRange(10, 20); + //emitter->SetMaterial(particleMaterial); + //emitter->SetColorRangeImage(RESOURCE_PATH + "/smokecolors.png"); + //emitter->SetScaleRate(10); + //emitter->SetEmitting(true); + //root->AddChild(emitter); + ParticleEmitterPtr emitter = _scene->CreateParticleEmitter(); + emitter->SetType(EM_POINT); + emitter->SetEmitterSize({50.0, 50.0, 50.0}); emitter->SetLocalPose({2, 1.10, 1.25, 1.5708, 0, 2.3}); emitter->SetRate(10); - emitter->SetParticleSize({1, 1, 1}); - emitter->SetLifetime(2); - emitter->SetVelocityRange(10, 20); + emitter->SetParticleSize({0.1, 0.1, 0.1}); + emitter->SetLifetime(5); + emitter->SetVelocityRange(1, 2); emitter->SetMaterial(particleMaterial); emitter->SetColorRangeImage(RESOURCE_PATH + "/smokecolors.png"); - emitter->SetScaleRate(10); + emitter->SetScaleRate(2); emitter->SetEmitting(true); root->AddChild(emitter); + //! [create particle emitter] } diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2ParticleEmitter.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2ParticleEmitter.hh index dc9eb7ba5..9469095f7 100644 --- a/ogre2/include/ignition/rendering/ogre2/Ogre2ParticleEmitter.hh +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2ParticleEmitter.hh @@ -86,9 +86,15 @@ namespace ignition public: virtual void SetColorRangeImage(const std::string &_image) override; + // Documentation inherited. + public: void PreRender() override; + // Documentation inherited. protected: virtual void Init() override; + /// \brief Create the particle system + private: void CreateParticleSystem(); + /// \brief Only the ogre scene can instanstiate this class private: friend class Ogre2Scene; diff --git a/ogre2/src/Ogre2ParticleEmitter.cc b/ogre2/src/Ogre2ParticleEmitter.cc index 7e0e36f08..8d16a861c 100644 --- a/ogre2/src/Ogre2ParticleEmitter.cc +++ b/ogre2/src/Ogre2ParticleEmitter.cc @@ -45,8 +45,10 @@ class ignition::rendering::Ogre2ParticleEmitterPrivate public: Ogre::ParticleSystem *ps = nullptr; /// \brief Ogre particle emitter. - public: std::array emitters; + //public: std::array emitters; + + public: Ogre::ParticleEmitter *emitter = nullptr; // \brief Ogre color image affector. public: Ogre::ParticleAffector *colorImageAffector = nullptr; @@ -62,6 +64,10 @@ class ignition::rendering::Ogre2ParticleEmitterPrivate /// \brief Pointer to the unlit material used by particle emitter. public: MaterialPtr materialUnlit; + + /// \brief Flag to indicate that the emitter is dirty and needs to be + /// recreated + public: bool emitterDirty = false; }; // Names used in Ogre for the supported emitters. @@ -91,6 +97,11 @@ void Ogre2ParticleEmitter::Destroy() { if (this->dataPtr->ps) { + this->dataPtr->ps->removeAllAffectors(); + this->dataPtr->colorInterpolatorAffector = nullptr; + this->dataPtr->colorImageAffector = nullptr; + this->dataPtr->scalerAffector = nullptr; + this->scene->OgreSceneManager()->destroyParticleSystem( this->dataPtr->ps); this->dataPtr->ps = nullptr; @@ -115,11 +126,18 @@ void Ogre2ParticleEmitter::Ogre2ParticleEmitter::SetType( return; } - for (auto i = 0; i < EmitterType::EM_NUM_EMITTERS; ++i) - this->dataPtr->emitters[i]->setEnabled(false); +// for (auto i = 0; i < EmitterType::EM_NUM_EMITTERS; ++i) +// this->dataPtr->emitters[i]->setEnabled(false); + +// this->dataPtr->emitters[_type]->setEnabled(true); +// this->dataPtr->emitter->setEnabled(true); + + if (this->type == _type) + return; - this->dataPtr->emitters[_type]->setEnabled(true); this->type = _type; + + this->dataPtr->emitterDirty = true; } ////////////////////////////////////////////////// @@ -160,7 +178,8 @@ void Ogre2ParticleEmitter::SetEmitterSize(const ignition::math::Vector3d &_size) // We skip EM_POINT. for (auto i = 1; i < EmitterType::EM_NUM_EMITTERS; ++i) { - if (!this->dataPtr->emitters[i]->setParameter(param, value)) + // if (!this->dataPtr->emitters[i]->setParameter(param, value)) + if (!this->dataPtr->emitter->setParameter(param, value)) { ignerr << "SetEmitterSize() error for " << kOgreEmitterTypes[i] << " emitter because SetParameter(" << param << " " << value @@ -193,8 +212,9 @@ void Ogre2ParticleEmitter::SetRate(double _rate) return; } - for (auto i = 0; i < EmitterType::EM_NUM_EMITTERS; ++i) - this->dataPtr->emitters[i]->setEmissionRate(_rate); + // for (auto i = 0; i < EmitterType::EM_NUM_EMITTERS; ++i) + // this->dataPtr->emitters[i]->setEmissionRate(_rate); + this->dataPtr->emitter->setEmissionRate(_rate); this->rate = _rate; } @@ -202,8 +222,11 @@ void Ogre2ParticleEmitter::SetRate(double _rate) ////////////////////////////////////////////////// void Ogre2ParticleEmitter::SetDuration(double _duration) { - for (auto i = 0; i < EmitterType::EM_NUM_EMITTERS; ++i) - this->dataPtr->emitters[i]->setDuration(_duration); +// for (auto i = 0; i < EmitterType::EM_NUM_EMITTERS; ++i) +// this->dataPtr->emitters[i]->setDuration(_duration); + + this->dataPtr->emitter->setDuration(_duration); + this->duration = _duration; } @@ -211,7 +234,8 @@ void Ogre2ParticleEmitter::SetDuration(double _duration) ////////////////////////////////////////////////// void Ogre2ParticleEmitter::SetEmitting(bool _enable) { - this->dataPtr->emitters[this->type]->setEnabled(_enable); + // this->dataPtr->emitters[this->type]->setEnabled(_enable); + this->dataPtr->emitter->setEnabled(_enable); this->dataPtr->ps->setEmitting(_enable); this->emitting = _enable; } @@ -227,8 +251,12 @@ void Ogre2ParticleEmitter::SetParticleSize( << "Particle size values should be non-negative." << std::endl; return; } - this->dataPtr->ps->setDefaultDimensions(_size[0], _size[1]); + + std::cerr << "setting default dimension " << _size << std::endl; + this->particleSize = _size; + + this->dataPtr->emitterDirty = true; } ////////////////////////////////////////////////// @@ -242,8 +270,11 @@ void Ogre2ParticleEmitter::SetLifetime(double _lifetime) return; } - for (auto i = 0; i < EmitterType::EM_NUM_EMITTERS; ++i) - this->dataPtr->emitters[i]->setTimeToLive(_lifetime); +// for (auto i = 0; i < EmitterType::EM_NUM_EMITTERS; ++i) +// this->dataPtr->emitters[i]->setTimeToLive(_lifetime); + this->dataPtr->emitter->setTimeToLive(_lifetime); + + this->lifetime = _lifetime; } @@ -267,8 +298,10 @@ void Ogre2ParticleEmitter::SetMaterial(const MaterialPtr &_material) void Ogre2ParticleEmitter::SetVelocityRange(double _minVelocity, double _maxVelocity) { - for (auto i = 0; i < EmitterType::EM_NUM_EMITTERS; ++i) - this->dataPtr->emitters[i]->setParticleVelocity(_minVelocity, _maxVelocity); +// for (auto i = 0; i < EmitterType::EM_NUM_EMITTERS; ++i) +// this->dataPtr->emitters[i]->setParticleVelocity(_minVelocity, _maxVelocity); + this->dataPtr->emitter->setParticleVelocity(_minVelocity, _maxVelocity); + this->minVelocity = _minVelocity; this->maxVelocity = _maxVelocity; @@ -413,7 +446,48 @@ void Ogre2ParticleEmitter::SetColorRangeImage(const std::string &_image) void Ogre2ParticleEmitter::Init() { Ogre2Visual::Init(); + this->CreateParticleSystem(); +} +////////////////////////////////////////////////// +void Ogre2ParticleEmitter::PreRender() +{ + // recreate the particle system if needed + // currently this is needed when user changes type or particle size + if (this->dataPtr->emitterDirty) + { + this->Destroy(); + this->CreateParticleSystem(); + + // make direct ogre calls here so we don't mark emitter as dirty again + this->dataPtr->ps->setDefaultDimensions( + this->particleSize[0], this->particleSize[1]); + + this->SetEmitterSize(this->emitterSize); + + // set other properties + this->SetLifetime(this->lifetime); + this->SetRate(this->rate); + this->SetVelocityRange(this->minVelocity, this->maxVelocity); + + if (this->material) + this->SetMaterial(this->material); + + if (!this->colorRangeImage.empty()) + this->SetColorRangeImage(this->colorRangeImage); + else + this->SetColorRange(this->colorStart, this->colorEnd); + + std::cerr << "setting scale rate " << this->scaleRate << std::endl; + this->SetScaleRate(this->scaleRate); + + this->dataPtr->emitterDirty = false; + } +} + +////////////////////////////////////////////////// +void Ogre2ParticleEmitter::CreateParticleSystem() +{ // Instantiate the particle system and default parameters. this->dataPtr->ps = this->scene->OgreSceneManager()->createParticleSystem(); this->dataPtr->ps->setCullIndividually(true); @@ -426,14 +500,18 @@ void Ogre2ParticleEmitter::Init() // Instantiate all particle emitters and their default parameters. // Note that we enable the point emitter by default. - for (auto i = 0; i < EmitterType::EM_NUM_EMITTERS; ++i) - { - this->dataPtr->emitters[i] = - this->dataPtr->ps->addEmitter(kOgreEmitterTypes[i]); - this->dataPtr->emitters[i]->setEnabled(false); - this->dataPtr->emitters[i]->setDirection(Ogre::Vector3::UNIT_X); - } - this->dataPtr->emitters[EmitterType::EM_POINT]->setEnabled(true); +// for (auto i = 0; i < EmitterType::EM_NUM_EMITTERS; ++i) +// { +// this->dataPtr->emitters[i] = +// this->dataPtr->ps->addEmitter(kOgreEmitterTypes[i]); +// this->dataPtr->emitters[i]->setEnabled(false); +// this->dataPtr->emitters[i]->setDirection(Ogre::Vector3::UNIT_X); +// } + + this->dataPtr->emitter = + this->dataPtr->ps->addEmitter(kOgreEmitterTypes[this->type]); + this->dataPtr->emitter->setDirection(Ogre::Vector3::UNIT_X); + this->dataPtr->emitter->setEnabled(true); // Instantiate the default material. this->dataPtr->materialUnlit = this->scene->CreateMaterial(); @@ -444,7 +522,7 @@ void Ogre2ParticleEmitter::Init() *(this->dataPtr->ogreDatablock->getNameStr())); // Default emitter parameters. - this->SetParticleSize({1, 1, 1}); + // this->SetParticleSize({1, 1, 1}); this->ogreNode->attachObject(this->dataPtr->ps); igndbg << "Particle emitter initialized" << std::endl; From d58deef4de27616b1879083ee6a1a8c02a1f66ab Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Tue, 9 Feb 2021 20:49:15 -0800 Subject: [PATCH 2/5] remove comments Signed-off-by: Ian Chen --- ogre2/src/Ogre2ParticleEmitter.cc | 37 ++----------------------------- 1 file changed, 2 insertions(+), 35 deletions(-) diff --git a/ogre2/src/Ogre2ParticleEmitter.cc b/ogre2/src/Ogre2ParticleEmitter.cc index 8d16a861c..dc08adfde 100644 --- a/ogre2/src/Ogre2ParticleEmitter.cc +++ b/ogre2/src/Ogre2ParticleEmitter.cc @@ -45,9 +45,6 @@ class ignition::rendering::Ogre2ParticleEmitterPrivate public: Ogre::ParticleSystem *ps = nullptr; /// \brief Ogre particle emitter. - //public: std::array emitters; - public: Ogre::ParticleEmitter *emitter = nullptr; // \brief Ogre color image affector. @@ -126,12 +123,6 @@ void Ogre2ParticleEmitter::Ogre2ParticleEmitter::SetType( return; } -// for (auto i = 0; i < EmitterType::EM_NUM_EMITTERS; ++i) -// this->dataPtr->emitters[i]->setEnabled(false); - -// this->dataPtr->emitters[_type]->setEnabled(true); -// this->dataPtr->emitter->setEnabled(true); - if (this->type == _type) return; @@ -178,7 +169,6 @@ void Ogre2ParticleEmitter::SetEmitterSize(const ignition::math::Vector3d &_size) // We skip EM_POINT. for (auto i = 1; i < EmitterType::EM_NUM_EMITTERS; ++i) { - // if (!this->dataPtr->emitters[i]->setParameter(param, value)) if (!this->dataPtr->emitter->setParameter(param, value)) { ignerr << "SetEmitterSize() error for " << kOgreEmitterTypes[i] @@ -212,8 +202,6 @@ void Ogre2ParticleEmitter::SetRate(double _rate) return; } - // for (auto i = 0; i < EmitterType::EM_NUM_EMITTERS; ++i) - // this->dataPtr->emitters[i]->setEmissionRate(_rate); this->dataPtr->emitter->setEmissionRate(_rate); this->rate = _rate; @@ -222,9 +210,6 @@ void Ogre2ParticleEmitter::SetRate(double _rate) ////////////////////////////////////////////////// void Ogre2ParticleEmitter::SetDuration(double _duration) { -// for (auto i = 0; i < EmitterType::EM_NUM_EMITTERS; ++i) -// this->dataPtr->emitters[i]->setDuration(_duration); - this->dataPtr->emitter->setDuration(_duration); @@ -234,7 +219,6 @@ void Ogre2ParticleEmitter::SetDuration(double _duration) ////////////////////////////////////////////////// void Ogre2ParticleEmitter::SetEmitting(bool _enable) { - // this->dataPtr->emitters[this->type]->setEnabled(_enable); this->dataPtr->emitter->setEnabled(_enable); this->dataPtr->ps->setEmitting(_enable); this->emitting = _enable; @@ -270,12 +254,8 @@ void Ogre2ParticleEmitter::SetLifetime(double _lifetime) return; } -// for (auto i = 0; i < EmitterType::EM_NUM_EMITTERS; ++i) -// this->dataPtr->emitters[i]->setTimeToLive(_lifetime); this->dataPtr->emitter->setTimeToLive(_lifetime); - - this->lifetime = _lifetime; } @@ -298,8 +278,6 @@ void Ogre2ParticleEmitter::SetMaterial(const MaterialPtr &_material) void Ogre2ParticleEmitter::SetVelocityRange(double _minVelocity, double _maxVelocity) { -// for (auto i = 0; i < EmitterType::EM_NUM_EMITTERS; ++i) -// this->dataPtr->emitters[i]->setParticleVelocity(_minVelocity, _maxVelocity); this->dataPtr->emitter->setParticleVelocity(_minVelocity, _maxVelocity); @@ -498,16 +476,8 @@ void Ogre2ParticleEmitter::CreateParticleSystem() "The nummer of supported emitters does not match the number of " "Ogre emitter types."); - // Instantiate all particle emitters and their default parameters. - // Note that we enable the point emitter by default. -// for (auto i = 0; i < EmitterType::EM_NUM_EMITTERS; ++i) -// { -// this->dataPtr->emitters[i] = -// this->dataPtr->ps->addEmitter(kOgreEmitterTypes[i]); -// this->dataPtr->emitters[i]->setEnabled(false); -// this->dataPtr->emitters[i]->setDirection(Ogre::Vector3::UNIT_X); -// } - + // Instantiate particle emitter and their default parameters. + // default in point emitter this->dataPtr->emitter = this->dataPtr->ps->addEmitter(kOgreEmitterTypes[this->type]); this->dataPtr->emitter->setDirection(Ogre::Vector3::UNIT_X); @@ -521,9 +491,6 @@ void Ogre2ParticleEmitter::CreateParticleSystem() this->dataPtr->ps->setMaterialName( *(this->dataPtr->ogreDatablock->getNameStr())); - // Default emitter parameters. - // this->SetParticleSize({1, 1, 1}); - this->ogreNode->attachObject(this->dataPtr->ps); igndbg << "Particle emitter initialized" << std::endl; } From 4afde4e832b78372041388cf3bb9a520d39bfa1f Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Tue, 9 Feb 2021 20:56:58 -0800 Subject: [PATCH 3/5] update example Signed-off-by: Ian Chen --- examples/particles_demo/Main.cc | 25 +++++-------------------- ogre2/src/Ogre2ParticleEmitter.cc | 2 ++ 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/examples/particles_demo/Main.cc b/examples/particles_demo/Main.cc index 5b0b743c4..efec68706 100644 --- a/examples/particles_demo/Main.cc +++ b/examples/particles_demo/Main.cc @@ -106,34 +106,19 @@ void buildScene(ScenePtr _scene) particleMaterial->SetDepthWriteEnabled(false); //! [create particle emitter] - //ParticleEmitterPtr emitter = _scene->CreateParticleEmitter(); - //emitter->SetType(EM_POINT); - //emitter->SetEmitterSize({1.0, 1.0, 1.0}); - //emitter->SetLocalPose({2, 1.10, 1.25, 1.5708, 0, 2.3}); - //emitter->SetRate(10); - //emitter->SetParticleSize({0.1, 0.1, 0.1}); - //emitter->SetLifetime(2); - //emitter->SetVelocityRange(10, 20); - //emitter->SetMaterial(particleMaterial); - //emitter->SetColorRangeImage(RESOURCE_PATH + "/smokecolors.png"); - //emitter->SetScaleRate(10); - //emitter->SetEmitting(true); - //root->AddChild(emitter); - ParticleEmitterPtr emitter = _scene->CreateParticleEmitter(); emitter->SetType(EM_POINT); - emitter->SetEmitterSize({50.0, 50.0, 50.0}); + emitter->SetEmitterSize({1.0, 1.0, 1.0}); emitter->SetLocalPose({2, 1.10, 1.25, 1.5708, 0, 2.3}); emitter->SetRate(10); - emitter->SetParticleSize({0.1, 0.1, 0.1}); - emitter->SetLifetime(5); - emitter->SetVelocityRange(1, 2); + emitter->SetParticleSize({0.01, 0.1, 0.1}); + emitter->SetLifetime(2); + emitter->SetVelocityRange(10, 20); emitter->SetMaterial(particleMaterial); emitter->SetColorRangeImage(RESOURCE_PATH + "/smokecolors.png"); - emitter->SetScaleRate(2); + emitter->SetScaleRate(10); emitter->SetEmitting(true); root->AddChild(emitter); - //! [create particle emitter] } diff --git a/ogre2/src/Ogre2ParticleEmitter.cc b/ogre2/src/Ogre2ParticleEmitter.cc index dc08adfde..d394c41b7 100644 --- a/ogre2/src/Ogre2ParticleEmitter.cc +++ b/ogre2/src/Ogre2ParticleEmitter.cc @@ -491,6 +491,8 @@ void Ogre2ParticleEmitter::CreateParticleSystem() this->dataPtr->ps->setMaterialName( *(this->dataPtr->ogreDatablock->getNameStr())); + this->dataPtr->ps->setDefaultDimensions(1, 1); + this->ogreNode->attachObject(this->dataPtr->ps); igndbg << "Particle emitter initialized" << std::endl; } From 7b38ed18878295ec67cecd9b57cb847443b28f86 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Thu, 11 Feb 2021 23:05:31 -0800 Subject: [PATCH 4/5] update fix Signed-off-by: Ian Chen --- examples/particles_demo/Main.cc | 18 +++++++++-- .../rendering/ogre2/Ogre2ParticleEmitter.hh | 7 +++-- ogre2/src/Ogre2ParticleEmitter.cc | 30 +++++++++++-------- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/examples/particles_demo/Main.cc b/examples/particles_demo/Main.cc index efec68706..69de0e15d 100644 --- a/examples/particles_demo/Main.cc +++ b/examples/particles_demo/Main.cc @@ -108,10 +108,9 @@ void buildScene(ScenePtr _scene) //! [create particle emitter] ParticleEmitterPtr emitter = _scene->CreateParticleEmitter(); emitter->SetType(EM_POINT); - emitter->SetEmitterSize({1.0, 1.0, 1.0}); emitter->SetLocalPose({2, 1.10, 1.25, 1.5708, 0, 2.3}); emitter->SetRate(10); - emitter->SetParticleSize({0.01, 0.1, 0.1}); + emitter->SetParticleSize({1, 1, 1}); emitter->SetLifetime(2); emitter->SetVelocityRange(10, 20); emitter->SetMaterial(particleMaterial); @@ -120,6 +119,21 @@ void buildScene(ScenePtr _scene) emitter->SetEmitting(true); root->AddChild(emitter); //! [create particle emitter] + + // area emitter + ParticleEmitterPtr areaEmitter = _scene->CreateParticleEmitter(); + areaEmitter->SetType(EM_BOX); + areaEmitter->SetEmitterSize({3.0, 3.0, 3.0}); + areaEmitter->SetLocalPose({3, 0, 0, 0, -1.5707, 0}); + areaEmitter->SetRate(10); + areaEmitter->SetParticleSize({0.01, 0.01, 0.01}); + areaEmitter->SetLifetime(1); + areaEmitter->SetVelocityRange(0.5, 1); + areaEmitter->SetMaterial(particleMaterial); + areaEmitter->SetColorRangeImage(RESOURCE_PATH + "/smokecolors.png"); + areaEmitter->SetScaleRate(1); + areaEmitter->SetEmitting(true); + root->AddChild(areaEmitter); } ////////////////////////////////////////////////// diff --git a/ogre2/include/ignition/rendering/ogre2/Ogre2ParticleEmitter.hh b/ogre2/include/ignition/rendering/ogre2/Ogre2ParticleEmitter.hh index 9469095f7..7356d7c39 100644 --- a/ogre2/include/ignition/rendering/ogre2/Ogre2ParticleEmitter.hh +++ b/ogre2/include/ignition/rendering/ogre2/Ogre2ParticleEmitter.hh @@ -86,12 +86,13 @@ namespace ignition public: virtual void SetColorRangeImage(const std::string &_image) override; - // Documentation inherited. - public: void PreRender() override; - // Documentation inherited. protected: virtual void Init() override; + /// \brief Internal pre-render function added to avoid breaking ABI + /// compatibility + private: void PreRenderImpl(); + /// \brief Create the particle system private: void CreateParticleSystem(); diff --git a/ogre2/src/Ogre2ParticleEmitter.cc b/ogre2/src/Ogre2ParticleEmitter.cc index d394c41b7..c1e432e11 100644 --- a/ogre2/src/Ogre2ParticleEmitter.cc +++ b/ogre2/src/Ogre2ParticleEmitter.cc @@ -129,6 +129,10 @@ void Ogre2ParticleEmitter::Ogre2ParticleEmitter::SetType( this->type = _type; this->dataPtr->emitterDirty = true; + // todo(anyone) remove this call. We had to do this since we can't override + // PreRender() as it breaks ABI. We should rename PreRenderImp to PreRender() + // in next release. + this->PreRenderImpl(); } ////////////////////////////////////////////////// @@ -167,15 +171,13 @@ void Ogre2ParticleEmitter::SetEmitterSize(const ignition::math::Vector3d &_size) for (auto[param, value] : allParamsToSet) { // We skip EM_POINT. - for (auto i = 1; i < EmitterType::EM_NUM_EMITTERS; ++i) + if (!this->dataPtr->emitter->setParameter(param, value)) { - if (!this->dataPtr->emitter->setParameter(param, value)) - { - ignerr << "SetEmitterSize() error for " << kOgreEmitterTypes[i] - << " emitter because SetParameter(" << param << " " << value - << ") failed." << std::endl; - return; - } + ignerr << "SetEmitterSize() error for " + << this->dataPtr->emitter->getType() + << " emitter because SetParameter(" << param << " " << value + << ") failed." << std::endl; + return; } } break; @@ -236,11 +238,13 @@ void Ogre2ParticleEmitter::SetParticleSize( return; } - std::cerr << "setting default dimension " << _size << std::endl; - this->particleSize = _size; this->dataPtr->emitterDirty = true; + // todo(anyone) remove this call. We had to do this since we can't override + // PreRender() as it breaks ABI. We should rename PreRenderImp to PreRender() + // in next release. + this->PreRenderImpl(); } ////////////////////////////////////////////////// @@ -428,8 +432,11 @@ void Ogre2ParticleEmitter::Init() } ////////////////////////////////////////////////// -void Ogre2ParticleEmitter::PreRender() +void Ogre2ParticleEmitter::PreRenderImpl() { + // \todo(anyone) rename this function to PreRender() so it overrides function + // from base class + // recreate the particle system if needed // currently this is needed when user changes type or particle size if (this->dataPtr->emitterDirty) @@ -456,7 +463,6 @@ void Ogre2ParticleEmitter::PreRender() else this->SetColorRange(this->colorStart, this->colorEnd); - std::cerr << "setting scale rate " << this->scaleRate << std::endl; this->SetScaleRate(this->scaleRate); this->dataPtr->emitterDirty = false; From a19125e60dafbc01f48f882465cda6b3b5615919 Mon Sep 17 00:00:00 2001 From: Ashton Larkin Date: Fri, 12 Feb 2021 15:49:58 -0500 Subject: [PATCH 5/5] review feedback Signed-off-by: Ashton Larkin --- ogre2/src/Ogre2ParticleEmitter.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ogre2/src/Ogre2ParticleEmitter.cc b/ogre2/src/Ogre2ParticleEmitter.cc index c1e432e11..acaa57860 100644 --- a/ogre2/src/Ogre2ParticleEmitter.cc +++ b/ogre2/src/Ogre2ParticleEmitter.cc @@ -112,7 +112,7 @@ void Ogre2ParticleEmitter::Destroy() } ////////////////////////////////////////////////// -void Ogre2ParticleEmitter::Ogre2ParticleEmitter::SetType( +void Ogre2ParticleEmitter::SetType( const EmitterType _type) { // Sanity check: Make sure that the emitter type is valid. @@ -130,7 +130,7 @@ void Ogre2ParticleEmitter::Ogre2ParticleEmitter::SetType( this->dataPtr->emitterDirty = true; // todo(anyone) remove this call. We had to do this since we can't override - // PreRender() as it breaks ABI. We should rename PreRenderImp to PreRender() + // PreRender() as it breaks ABI. We should rename PreRenderImpl to PreRender() // in next release. this->PreRenderImpl(); } @@ -242,7 +242,7 @@ void Ogre2ParticleEmitter::SetParticleSize( this->dataPtr->emitterDirty = true; // todo(anyone) remove this call. We had to do this since we can't override - // PreRender() as it breaks ABI. We should rename PreRenderImp to PreRender() + // PreRender() as it breaks ABI. We should rename PreRenderImpl to PreRender() // in next release. this->PreRenderImpl(); } @@ -434,8 +434,9 @@ void Ogre2ParticleEmitter::Init() ////////////////////////////////////////////////// void Ogre2ParticleEmitter::PreRenderImpl() { - // \todo(anyone) rename this function to PreRender() so it overrides function - // from base class + // todo(anyone) rename this function to PreRender() so it overrides function + // from base class. Since this rename breaks ABI, we should rename this + // function in the next release // recreate the particle system if needed // currently this is needed when user changes type or particle size @@ -451,6 +452,8 @@ void Ogre2ParticleEmitter::PreRenderImpl() this->SetEmitterSize(this->emitterSize); // set other properties + this->SetDuration(this->duration); + this->SetEmitting(this->emitting); this->SetLifetime(this->lifetime); this->SetRate(this->rate); this->SetVelocityRange(this->minVelocity, this->maxVelocity); @@ -483,7 +486,7 @@ void Ogre2ParticleEmitter::CreateParticleSystem() "Ogre emitter types."); // Instantiate particle emitter and their default parameters. - // default in point emitter + // Emitter type is point unless otherwise specified. this->dataPtr->emitter = this->dataPtr->ps->addEmitter(kOgreEmitterTypes[this->type]); this->dataPtr->emitter->setDirection(Ogre::Vector3::UNIT_X);