Added support for setting the texture filename and more fine control over
the particle template used in ParticleEffects
This commit is contained in:
@@ -30,7 +30,6 @@ namespace osgParticle
|
||||
_intensity(1.0f),
|
||||
_startTime(0.0),
|
||||
_emitterDuration(1.0),
|
||||
_particleDuration(1.0),
|
||||
_wind(0.0f,0.0f,0.0f)
|
||||
{}
|
||||
|
||||
@@ -45,6 +44,12 @@ namespace osgParticle
|
||||
void setUseLocalParticleSystem(bool local);
|
||||
bool getUseLocalParticleSystem() const { return _useLocalParticleSystem; }
|
||||
|
||||
void setTextureFileName(const std::string& filename);
|
||||
const std::string& getTextureFileName() const { return _textureFileName; }
|
||||
|
||||
void setDefaultParticleTemplate(const Particle& p);
|
||||
const Particle& getDefaultParticleTemplate() const { return _defaultParticleTemplate; }
|
||||
|
||||
void setPosition(const osg::Vec3& position);
|
||||
const osg::Vec3& getPosition() const { return _position; }
|
||||
|
||||
@@ -61,7 +66,7 @@ namespace osgParticle
|
||||
double getEmitterDuration() const { return _emitterDuration; }
|
||||
|
||||
void setParticleDuration(double duration);
|
||||
double getParticleDuration() const { return _particleDuration; }
|
||||
double getParticleDuration() const { return _defaultParticleTemplate.getLifeTime(); }
|
||||
|
||||
void setWind(const osg::Vec3& wind);
|
||||
const osg::Vec3& getWind() const { return _wind; }
|
||||
@@ -90,12 +95,13 @@ namespace osgParticle
|
||||
osg::ref_ptr<ParticleSystem> _particleSystem;
|
||||
|
||||
bool _useLocalParticleSystem;
|
||||
std::string _textureFileName;
|
||||
Particle _defaultParticleTemplate;
|
||||
osg::Vec3 _position;
|
||||
float _scale;
|
||||
float _intensity;
|
||||
double _startTime;
|
||||
double _emitterDuration;
|
||||
double _particleDuration;
|
||||
osg::Vec3 _wind;
|
||||
};
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ ExplosionDebriEffect::ExplosionDebriEffect(const osg::Vec3& position, float scal
|
||||
_intensity = intensity;
|
||||
|
||||
_emitterDuration = 0.1;
|
||||
_particleDuration = 1.0+0.6*_scale;
|
||||
_defaultParticleTemplate.setLifeTime(1.0+0.6*_scale);
|
||||
|
||||
buildEffect();
|
||||
}
|
||||
@@ -50,8 +50,19 @@ void ExplosionDebriEffect::setDefaults()
|
||||
{
|
||||
ParticleEffect::setDefaults();
|
||||
|
||||
_textureFileName = "Images/particle.rgb";
|
||||
_emitterDuration = 0.1;
|
||||
_particleDuration = 1.0+0.6*_scale;
|
||||
|
||||
// set up unit particle.
|
||||
_defaultParticleTemplate.setLifeTime(1.0+0.6*_scale);
|
||||
_defaultParticleTemplate.setRadius(1.0f);
|
||||
_defaultParticleTemplate.setMass(osg::PI*4.0f/3.0f);
|
||||
_defaultParticleTemplate.setSizeRange(osgParticle::rangef(0.75f, 3.0f));
|
||||
_defaultParticleTemplate.setAlphaRange(osgParticle::rangef(0.0f, 1.0f));
|
||||
_defaultParticleTemplate.setColorRange(osgParticle::rangev4(
|
||||
osg::Vec4(0.5f, 0.5f, 0.0f, 1.0f),
|
||||
osg::Vec4(0.2f, 0.2f, 0.2f, 0.5f)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -65,25 +76,26 @@ void ExplosionDebriEffect::setUpEmitterAndProgram()
|
||||
|
||||
if (_particleSystem.valid())
|
||||
{
|
||||
_particleSystem->setDefaultAttributes("Images/particle.rgb", false, false);
|
||||
_particleSystem->setDefaultAttributes(_textureFileName, false, false);
|
||||
|
||||
osgParticle::Particle& ptemplate = _particleSystem->getDefaultParticleTemplate();
|
||||
ptemplate.setLifeTime(_particleDuration);
|
||||
|
||||
float radius = 0.05f*_scale;
|
||||
float density = 1000.0f; // 1000.0kg/m^3
|
||||
|
||||
ptemplate.setLifeTime(_defaultParticleTemplate.getLifeTime());
|
||||
|
||||
// the following ranges set the envelope of the respective
|
||||
// graphical properties in time.
|
||||
ptemplate.setSizeRange(osgParticle::rangef(radius*0.75f, radius*3.0f));
|
||||
ptemplate.setAlphaRange(osgParticle::rangef(0.0f, 1.0f));
|
||||
ptemplate.setColorRange(osgParticle::rangev4(
|
||||
osg::Vec4(0.5f, 0.5f, 0.0f, 1.0f),
|
||||
osg::Vec4(0.2f, 0.2f, 0.2f, 0.5f)));
|
||||
ptemplate.setSizeRange(osgParticle::rangef(radius*_defaultParticleTemplate.getSizeRange().minimum,
|
||||
radius*_defaultParticleTemplate.getSizeRange().maximum));
|
||||
ptemplate.setAlphaRange(_defaultParticleTemplate.getAlphaRange());
|
||||
ptemplate.setColorRange(_defaultParticleTemplate.getColorRange());
|
||||
|
||||
// these are physical properties of the particle
|
||||
ptemplate.setRadius(radius); // 5 cm wide particles
|
||||
ptemplate.setMass(density*osg::PI*4.0f*radius*radius*radius/3.0f);
|
||||
float r = _defaultParticleTemplate.getRadius()*radius;
|
||||
ptemplate.setRadius(r);
|
||||
ptemplate.setMass(density*r*r*r*_defaultParticleTemplate.getMass());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ ExplosionEffect::ExplosionEffect(const osg::Vec3& position, float scale, float i
|
||||
_intensity = intensity;
|
||||
|
||||
_emitterDuration = 1.0;
|
||||
_particleDuration = 0.5+0.1*_scale;
|
||||
|
||||
buildEffect();
|
||||
}
|
||||
@@ -50,8 +49,19 @@ void ExplosionEffect::setDefaults()
|
||||
{
|
||||
ParticleEffect::setDefaults();
|
||||
|
||||
_textureFileName = "Images/smoke.rgb";
|
||||
_emitterDuration = 1.0;
|
||||
_particleDuration = 0.5+0.1*_scale;
|
||||
|
||||
// set up unit particle.
|
||||
_defaultParticleTemplate.setLifeTime(0.5+0.1*_scale);
|
||||
_defaultParticleTemplate.setRadius(1.0f);
|
||||
_defaultParticleTemplate.setMass(osg::PI*4.0f/3.0f);
|
||||
_defaultParticleTemplate.setSizeRange(osgParticle::rangef(0.75f, 3.0f));
|
||||
_defaultParticleTemplate.setAlphaRange(osgParticle::rangef(0.1f, 1.0f));
|
||||
_defaultParticleTemplate.setColorRange(osgParticle::rangev4(
|
||||
osg::Vec4(1.0f, 0.8f, 0.2f, 1.0f),
|
||||
osg::Vec4(1.0f, 0.4f, 0.1f, 0.0f)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -65,26 +75,26 @@ void ExplosionEffect::setUpEmitterAndProgram()
|
||||
|
||||
if (_particleSystem.valid())
|
||||
{
|
||||
_particleSystem->setDefaultAttributes("Images/smoke.rgb", false, false);
|
||||
_particleSystem->setDefaultAttributes(_textureFileName, false, false);
|
||||
|
||||
osgParticle::Particle& ptemplate = _particleSystem->getDefaultParticleTemplate();
|
||||
|
||||
ptemplate.setLifeTime(_particleDuration);
|
||||
|
||||
float radius = 0.4f*_scale;
|
||||
float density = 1.2f; // 1.0kg/m^3
|
||||
|
||||
ptemplate.setLifeTime(_defaultParticleTemplate.getLifeTime());
|
||||
|
||||
// the following ranges set the envelope of the respective
|
||||
// graphical properties in time.
|
||||
ptemplate.setSizeRange(osgParticle::rangef(radius*0.75f, radius*3.0f));
|
||||
ptemplate.setAlphaRange(osgParticle::rangef(0.1f, 1.0f));
|
||||
ptemplate.setColorRange(osgParticle::rangev4(
|
||||
osg::Vec4(1.0f, 0.8f, 0.2f, 1.0f),
|
||||
osg::Vec4(1.0f, 0.4f, 0.1f, 0.0f)));
|
||||
ptemplate.setSizeRange(osgParticle::rangef(radius*_defaultParticleTemplate.getSizeRange().minimum,
|
||||
radius*_defaultParticleTemplate.getSizeRange().maximum));
|
||||
ptemplate.setAlphaRange(_defaultParticleTemplate.getAlphaRange());
|
||||
ptemplate.setColorRange(_defaultParticleTemplate.getColorRange());
|
||||
|
||||
// these are physical properties of the particle
|
||||
ptemplate.setRadius(radius); // 5 cm wide particles
|
||||
ptemplate.setMass(density*osg::PI*4.0f*radius*radius*radius/3.0f);
|
||||
float r = _defaultParticleTemplate.getRadius()*radius;
|
||||
ptemplate.setRadius(r);
|
||||
ptemplate.setMass(density*r*r*r*_defaultParticleTemplate.getMass());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ FireEffect::FireEffect(const osg::Vec3& position, float scale, float intensity)
|
||||
_intensity = intensity;
|
||||
|
||||
_emitterDuration = 60.0;
|
||||
_particleDuration = 0.5+0.1*_scale;
|
||||
_defaultParticleTemplate.setLifeTime(0.5+0.1*_scale);
|
||||
|
||||
buildEffect();
|
||||
}
|
||||
@@ -49,8 +49,18 @@ void FireEffect::setDefaults()
|
||||
{
|
||||
ParticleEffect::setDefaults();
|
||||
|
||||
_textureFileName = "Images/smoke.rgb";
|
||||
_emitterDuration = 60.0;
|
||||
_particleDuration = 0.5+0.1*_scale;
|
||||
|
||||
// set up unit particle.
|
||||
_defaultParticleTemplate.setLifeTime(0.5+0.1*_scale);
|
||||
_defaultParticleTemplate.setRadius(1.0f);
|
||||
_defaultParticleTemplate.setMass(osg::PI*4.0f/3.0f);
|
||||
_defaultParticleTemplate.setSizeRange(osgParticle::rangef(0.75f, 3.0f));
|
||||
_defaultParticleTemplate.setAlphaRange(osgParticle::rangef(0.1f, 1.0f));
|
||||
_defaultParticleTemplate.setColorRange(osgParticle::rangev4(
|
||||
osg::Vec4(1, 0.8f, 0.2f, 1.0f),
|
||||
osg::Vec4(1, 0.3f, 0.2f, 0.0f)));
|
||||
}
|
||||
|
||||
void FireEffect::setUpEmitterAndProgram()
|
||||
@@ -64,26 +74,26 @@ void FireEffect::setUpEmitterAndProgram()
|
||||
|
||||
if (_particleSystem.valid())
|
||||
{
|
||||
_particleSystem->setDefaultAttributes("Images/smoke.rgb", false, false);
|
||||
_particleSystem->setDefaultAttributes(_textureFileName, false, false);
|
||||
|
||||
osgParticle::Particle& ptemplate = _particleSystem->getDefaultParticleTemplate();
|
||||
|
||||
ptemplate.setLifeTime(_particleDuration);
|
||||
|
||||
float radius = 0.25f*_scale;
|
||||
float density = 0.5f; // 1.0kg/m^3
|
||||
float density = 0.5f; // 0.5kg/m^3
|
||||
|
||||
ptemplate.setLifeTime(_defaultParticleTemplate.getLifeTime());
|
||||
|
||||
// the following ranges set the envelope of the respective
|
||||
// graphical properties in time.
|
||||
ptemplate.setSizeRange(osgParticle::rangef(radius*0.75f, radius*3.0f));
|
||||
ptemplate.setAlphaRange(osgParticle::rangef(0.1f, 1.0f));
|
||||
ptemplate.setColorRange(osgParticle::rangev4(
|
||||
osg::Vec4(1, 1.0f, 0.2f, 1.0f),
|
||||
osg::Vec4(1, 0.0f, 0.f, 0.0f)));
|
||||
ptemplate.setSizeRange(osgParticle::rangef(radius*_defaultParticleTemplate.getSizeRange().minimum,
|
||||
radius*_defaultParticleTemplate.getSizeRange().maximum));
|
||||
ptemplate.setAlphaRange(_defaultParticleTemplate.getAlphaRange());
|
||||
ptemplate.setColorRange(_defaultParticleTemplate.getColorRange());
|
||||
|
||||
// these are physical properties of the particle
|
||||
ptemplate.setRadius(radius); // 5 cm wide particles
|
||||
ptemplate.setMass(density*osg::PI*4.0f*radius*radius*radius/3.0f);
|
||||
float r = _defaultParticleTemplate.getRadius()*radius;
|
||||
ptemplate.setRadius(r);
|
||||
ptemplate.setMass(density*r*r*r*_defaultParticleTemplate.getMass());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,12 @@ ParticleEffect::ParticleEffect(const ParticleEffect& copy, const osg::CopyOp& co
|
||||
osg::Group(copy,copyop),/*,
|
||||
_particleSystem(copy._particleSystem.valid()?copy._particleSystem->clone():0)*/
|
||||
_useLocalParticleSystem(copy._useLocalParticleSystem),
|
||||
_defaultParticleTemplate(copy._defaultParticleTemplate),
|
||||
_position(copy._position),
|
||||
_scale(copy._scale),
|
||||
_intensity(copy._intensity),
|
||||
_startTime(copy._startTime),
|
||||
_emitterDuration(copy._emitterDuration),
|
||||
_particleDuration(copy._particleDuration),
|
||||
_wind(copy._wind)
|
||||
{
|
||||
}
|
||||
@@ -38,6 +39,12 @@ void ParticleEffect::setUseLocalParticleSystem(bool local)
|
||||
buildEffect();
|
||||
}
|
||||
|
||||
void ParticleEffect::setDefaultParticleTemplate(const Particle& p)
|
||||
{
|
||||
_defaultParticleTemplate = p;
|
||||
setUpEmitterAndProgram();
|
||||
}
|
||||
|
||||
void ParticleEffect::setPosition(const osg::Vec3& position)
|
||||
{
|
||||
if (_position==position) return;
|
||||
@@ -80,9 +87,10 @@ void ParticleEffect::setEmitterDuration(double duration)
|
||||
|
||||
void ParticleEffect::setParticleDuration(double duration)
|
||||
{
|
||||
if (_particleDuration==duration) return;
|
||||
if (_defaultParticleTemplate.getLifeTime()==duration) return;
|
||||
|
||||
_particleDuration = duration;
|
||||
_defaultParticleTemplate.setLifeTime(duration);
|
||||
|
||||
setUpEmitterAndProgram();
|
||||
}
|
||||
|
||||
@@ -109,7 +117,6 @@ void ParticleEffect::setDefaults()
|
||||
_intensity = 1.0f;
|
||||
_startTime = 0.0;
|
||||
_emitterDuration = 1.0;
|
||||
_particleDuration = 1.0;
|
||||
_wind.set(0.0f,0.0f,0.0f);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ SmokeEffect::SmokeEffect(const osg::Vec3& position, float scale, float intensity
|
||||
_intensity = intensity;
|
||||
|
||||
_emitterDuration = 65.0;
|
||||
_particleDuration = 5.0*_scale;
|
||||
_defaultParticleTemplate.setLifeTime(5.0*_scale);
|
||||
|
||||
buildEffect();
|
||||
}
|
||||
@@ -45,8 +45,20 @@ void SmokeEffect::setDefaults()
|
||||
{
|
||||
ParticleEffect::setDefaults();
|
||||
|
||||
_textureFileName = "Images/smoke.rgb";
|
||||
_emitterDuration = 65.0;
|
||||
_particleDuration = 5.0*_scale;
|
||||
|
||||
// set up unit particle.
|
||||
_defaultParticleTemplate.setLifeTime(5.0*_scale);
|
||||
_defaultParticleTemplate.setRadius(1.0f);
|
||||
_defaultParticleTemplate.setMass(osg::PI*4.0f/3.0f);
|
||||
_defaultParticleTemplate.setSizeRange(osgParticle::rangef(0.75f, 3.0f));
|
||||
_defaultParticleTemplate.setAlphaRange(osgParticle::rangef(0.1f, 1.0f));
|
||||
_defaultParticleTemplate.setColorRange(osgParticle::rangev4(
|
||||
osg::Vec4(1, 1.0f, 1.0f, 1.0f),
|
||||
osg::Vec4(1, 1.0f, 1.f, 0.0f)));
|
||||
|
||||
|
||||
}
|
||||
|
||||
void SmokeEffect::setUpEmitterAndProgram()
|
||||
@@ -59,25 +71,26 @@ void SmokeEffect::setUpEmitterAndProgram()
|
||||
|
||||
if (_particleSystem.valid())
|
||||
{
|
||||
_particleSystem->setDefaultAttributes("Images/smoke.rgb", false, false);
|
||||
_particleSystem->setDefaultAttributes(_textureFileName, false, false);
|
||||
|
||||
osgParticle::Particle& ptemplate = _particleSystem->getDefaultParticleTemplate();
|
||||
ptemplate.setLifeTime(5*_scale);
|
||||
|
||||
float radius = 0.5f*_scale;
|
||||
float density = 1.0f; // 1.0kg/m^3
|
||||
|
||||
ptemplate.setLifeTime(_defaultParticleTemplate.getLifeTime());
|
||||
|
||||
// the following ranges set the envelope of the respective
|
||||
// graphical properties in time.
|
||||
ptemplate.setSizeRange(osgParticle::rangef(radius*0.75f, radius*3.0f));
|
||||
ptemplate.setAlphaRange(osgParticle::rangef(0.1f, 1.0f));
|
||||
ptemplate.setColorRange(osgParticle::rangev4(
|
||||
osg::Vec4(1, 1.0f, 1.0f, 1.0f),
|
||||
osg::Vec4(1, 1.0f, 1.f, 0.0f)));
|
||||
ptemplate.setSizeRange(osgParticle::rangef(radius*_defaultParticleTemplate.getSizeRange().minimum,
|
||||
radius*_defaultParticleTemplate.getSizeRange().maximum));
|
||||
ptemplate.setAlphaRange(_defaultParticleTemplate.getAlphaRange());
|
||||
ptemplate.setColorRange(_defaultParticleTemplate.getColorRange());
|
||||
|
||||
// these are physical properties of the particle
|
||||
ptemplate.setRadius(radius); // 5 cm wide particles
|
||||
ptemplate.setMass(density*osg::PI*4.0f*radius*radius*radius/3.0f);
|
||||
float r = _defaultParticleTemplate.getRadius()*radius;
|
||||
ptemplate.setRadius(r);
|
||||
ptemplate.setMass(density*r*r*r*_defaultParticleTemplate.getMass());
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user