Added the ability for osgParticle::ParticleEffect to switch off the automatic setup.

Normally the automatic setup is useful, but in the case of the .osg support this automatic
update was forcing premature loading of imagery that wasn't necessarily, and can lead to
reports of looking for files that arn't present.
This commit is contained in:
Robert Osfield 2005-11-18 17:04:55 +00:00
parent b0869a6f60
commit d0c9ef1e14
24 changed files with 163 additions and 46 deletions

View File

@ -25,7 +25,9 @@ namespace osgParticle
{
public:
ExplosionDebrisEffect(const osg::Vec3& position=osg::Vec3(0.0f,0.0f,0.0f), float scale=1.0f, float intensity=1.0f);
ExplosionDebrisEffect(bool automaticSetup=true);
ExplosionDebrisEffect(const osg::Vec3& position, float scale=1.0f, float intensity=1.0f);
ExplosionDebrisEffect(const ExplosionDebrisEffect& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);

View File

@ -25,7 +25,9 @@ namespace osgParticle
{
public:
ExplosionEffect(const osg::Vec3& position=osg::Vec3(0.0f,0.0f,0.0f), float scale=1.0f, float intensity=1.0f);
ExplosionEffect(bool automaticSetup=true);
ExplosionEffect(const osg::Vec3& position, float scale=1.0f, float intensity=1.0f);
ExplosionEffect(const ExplosionEffect& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);

View File

@ -25,7 +25,9 @@ namespace osgParticle
{
public:
FireEffect(const osg::Vec3& position=osg::Vec3(0.0f,0.0f,0.0f), float scale=1.0f, float intensity=1.0f);
FireEffect(bool automaticSetup=true);
FireEffect(const osg::Vec3& position, float scale=1.0f, float intensity=1.0f);
FireEffect(const FireEffect& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);

View File

@ -24,7 +24,8 @@ namespace osgParticle
{
public:
ParticleEffect():
ParticleEffect(bool automaticSetup=true):
_automaticSetup(automaticSetup),
_useLocalParticleSystem(true),
_scale(1.0f),
_intensity(1.0f),
@ -41,6 +42,9 @@ namespace osgParticle
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const ParticleEffect*>(obj) != 0; }
virtual void accept(osg::NodeVisitor& nv) { if (nv.validNodeMask(*this)) { nv.pushOntoNodePath(this); nv.apply(*this); nv.popFromNodePath(); } }
void setAutomaticSetup(bool flag) { _automaticSetup = flag; }
bool getAutomaticSetup() const { return _automaticSetup; }
void setUseLocalParticleSystem(bool local);
bool getUseLocalParticleSystem() const { return _useLocalParticleSystem; }
@ -93,6 +97,8 @@ namespace osgParticle
protected:
virtual ~ParticleEffect() {}
bool _automaticSetup;
osg::ref_ptr<ParticleSystem> _particleSystem;

View File

@ -25,7 +25,9 @@ namespace osgParticle
{
public:
SmokeEffect(const osg::Vec3& position=osg::Vec3(0.0f,0.0f,0.0f), float scale=1.0f, float intensity=1.0f);
SmokeEffect(bool automaticSetup=true);
SmokeEffect(const osg::Vec3& position, float scale=1.0f, float intensity=1.0f);
SmokeEffect(const SmokeEffect& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);

View File

@ -25,7 +25,9 @@ namespace osgParticle
{
public:
SmokeTrailEffect(const osg::Vec3& position=osg::Vec3(0.0f,0.0f,0.0f), float scale=1.0f, float intensity=1.0f);
SmokeTrailEffect(bool automaticSetup=true);
SmokeTrailEffect(const osg::Vec3& position, float scale=1.0f, float intensity=1.0f);
SmokeTrailEffect(const SmokeTrailEffect& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);

View File

@ -25,6 +25,21 @@
using namespace osgParticle;
ExplosionDebrisEffect::ExplosionDebrisEffect(bool automaticSetup):
ParticleEffect(automaticSetup)
{
setDefaults();
_position.set(0.0f,0.0f,0.0f);
_scale = 1.0f;
_intensity = 1.0f;
_emitterDuration = 0.1;
_defaultParticleTemplate.setLifeTime(1.0+0.6*_scale);
if (_automaticSetup) buildEffect();
}
ExplosionDebrisEffect::ExplosionDebrisEffect(const osg::Vec3& position, float scale, float intensity)
{
setDefaults();
@ -36,7 +51,7 @@ ExplosionDebrisEffect::ExplosionDebrisEffect(const osg::Vec3& position, float sc
_emitterDuration = 0.1;
_defaultParticleTemplate.setLifeTime(1.0+0.6*_scale);
buildEffect();
if (_automaticSetup) buildEffect();
}
ExplosionDebrisEffect::ExplosionDebrisEffect(const ExplosionDebrisEffect& copy, const osg::CopyOp& copyop):

View File

@ -27,6 +27,20 @@
using namespace osgParticle;
ExplosionEffect::ExplosionEffect(bool automaticSetup):
ParticleEffect(automaticSetup)
{
setDefaults();
_position.set(0.0f,0.0f,0.0f);
_scale = 1.0f;
_intensity = 1.0f;
_emitterDuration = 1.0;
if (_automaticSetup) buildEffect();
}
ExplosionEffect::ExplosionEffect(const osg::Vec3& position, float scale, float intensity)
{
setDefaults();
@ -37,7 +51,7 @@ ExplosionEffect::ExplosionEffect(const osg::Vec3& position, float scale, float i
_emitterDuration = 1.0;
buildEffect();
if (_automaticSetup) buildEffect();
}
ExplosionEffect::ExplosionEffect(const ExplosionEffect& copy, const osg::CopyOp& copyop):

View File

@ -26,6 +26,21 @@
using namespace osgParticle;
FireEffect::FireEffect(bool automaticSetup):
ParticleEffect(automaticSetup)
{
setDefaults();
_position.set(0.0f,0.0f,0.0f);
_scale = 1.0f;
_intensity = 1.0f;
_emitterDuration = 60.0;
_defaultParticleTemplate.setLifeTime(0.5+0.1*_scale);
if (_automaticSetup) buildEffect();
}
FireEffect::FireEffect(const osg::Vec3& position, float scale, float intensity)
{
setDefaults();
@ -37,7 +52,7 @@ FireEffect::FireEffect(const osg::Vec3& position, float scale, float intensity)
_emitterDuration = 60.0;
_defaultParticleTemplate.setLifeTime(0.5+0.1*_scale);
buildEffect();
if (_automaticSetup) buildEffect();
}
FireEffect::FireEffect(const FireEffect& copy, const osg::CopyOp& copyop):

View File

@ -18,9 +18,10 @@
using namespace osgParticle;
ParticleEffect::ParticleEffect(const ParticleEffect& copy, const osg::CopyOp& copyop):
osg::Group(copy,copyop),/*,
_particleSystem(copy._particleSystem.valid()?copy._particleSystem->clone():0)*/
osg::Group(copy,copyop),
_automaticSetup(copy._automaticSetup),
_useLocalParticleSystem(copy._useLocalParticleSystem),
_textureFileName(copy._textureFileName),
_defaultParticleTemplate(copy._defaultParticleTemplate),
_position(copy._position),
_scale(copy._scale),
@ -29,6 +30,7 @@ ParticleEffect::ParticleEffect(const ParticleEffect& copy, const osg::CopyOp& co
_emitterDuration(copy._emitterDuration),
_wind(copy._wind)
{
if (_automaticSetup) buildEffect();
}
void ParticleEffect::setUseLocalParticleSystem(bool local)
@ -36,19 +38,22 @@ void ParticleEffect::setUseLocalParticleSystem(bool local)
if (_useLocalParticleSystem==local) return;
_useLocalParticleSystem = local;
buildEffect();
if (_automaticSetup) buildEffect();
}
void ParticleEffect::setTextureFileName(const std::string& filename)
{
_textureFileName = filename;
setUpEmitterAndProgram();
if (_automaticSetup) setUpEmitterAndProgram();
}
void ParticleEffect::setDefaultParticleTemplate(const Particle& p)
{
_defaultParticleTemplate = p;
setUpEmitterAndProgram();
if (_automaticSetup) setUpEmitterAndProgram();
}
void ParticleEffect::setPosition(const osg::Vec3& position)
@ -56,7 +61,8 @@ void ParticleEffect::setPosition(const osg::Vec3& position)
if (_position==position) return;
_position = position;
setUpEmitterAndProgram();
if (_automaticSetup) setUpEmitterAndProgram();
}
void ParticleEffect::setScale(float scale)
@ -64,7 +70,8 @@ void ParticleEffect::setScale(float scale)
if (_scale==scale) return;
_scale = scale;
setUpEmitterAndProgram();
if (_automaticSetup) setUpEmitterAndProgram();
}
void ParticleEffect::setIntensity(float intensity)
@ -72,7 +79,8 @@ void ParticleEffect::setIntensity(float intensity)
if (_intensity==intensity) return;
_intensity = intensity;
setUpEmitterAndProgram();
if (_automaticSetup) setUpEmitterAndProgram();
}
void ParticleEffect::setStartTime(double startTime)
@ -80,7 +88,8 @@ void ParticleEffect::setStartTime(double startTime)
if (_startTime==startTime) return;
_startTime =startTime;
setUpEmitterAndProgram();
if (_automaticSetup) setUpEmitterAndProgram();
}
void ParticleEffect::setEmitterDuration(double duration)
@ -88,7 +97,8 @@ void ParticleEffect::setEmitterDuration(double duration)
if (_emitterDuration==duration) return;
_emitterDuration = duration;
setUpEmitterAndProgram();
if (_automaticSetup) setUpEmitterAndProgram();
}
void ParticleEffect::setParticleDuration(double duration)
@ -97,7 +107,7 @@ void ParticleEffect::setParticleDuration(double duration)
_defaultParticleTemplate.setLifeTime(duration);
setUpEmitterAndProgram();
if (_automaticSetup) setUpEmitterAndProgram();
}
void ParticleEffect::setWind(const osg::Vec3& wind)
@ -105,7 +115,8 @@ void ParticleEffect::setWind(const osg::Vec3& wind)
if (_wind==wind) return;
_wind = wind;
setUpEmitterAndProgram();
if (_automaticSetup) setUpEmitterAndProgram();
}
void ParticleEffect::setParticleSystem(ParticleSystem* ps)
@ -113,7 +124,8 @@ void ParticleEffect::setParticleSystem(ParticleSystem* ps)
if (_particleSystem==ps) return;
_particleSystem = ps;
buildEffect();
if (_automaticSetup) buildEffect();
}
void ParticleEffect::setDefaults()
@ -130,9 +142,9 @@ void ParticleEffect::buildEffect()
{
setUpEmitterAndProgram();
Emitter* emitter = getEmitter();
Program* program = getProgram();
ParticleSystem* particleSystem = getParticleSystem();
osg::ref_ptr<Emitter> emitter = getEmitter();
osg::ref_ptr<Program> program = getProgram();
osg::ref_ptr<ParticleSystem> particleSystem = getParticleSystem();
if (!emitter || !particleSystem || !program) return;
@ -141,21 +153,21 @@ void ParticleEffect::buildEffect()
removeChild(0,getNumChildren());
// add the emitter
addChild(emitter);
addChild(emitter.get());
// add the program to update the particles
addChild(program);
addChild(program.get());
// add the particle system updater.
osgParticle::ParticleSystemUpdater *psu = new osgParticle::ParticleSystemUpdater;
psu->addParticleSystem(particleSystem);
addChild(psu);
osg::ref_ptr<osgParticle::ParticleSystemUpdater> psu = new osgParticle::ParticleSystemUpdater;
psu->addParticleSystem(particleSystem.get());
addChild(psu.get());
if (_useLocalParticleSystem)
{
// add the geode to the scene graph
osg::Geode *geode = new osg::Geode;
geode->addDrawable(particleSystem);
osg::Geode* geode = new osg::Geode;
geode->addDrawable(particleSystem.get());
addChild(geode);
}
}

View File

@ -22,6 +22,21 @@
using namespace osgParticle;
SmokeEffect::SmokeEffect(bool automaticSetup):
ParticleEffect(automaticSetup)
{
setDefaults();
_position.set(0.0f,0.0f,0.0f);
_scale = 1.0f;
_intensity = 1.0f;
_emitterDuration = 65.0;
_defaultParticleTemplate.setLifeTime(5.0*_scale);
if (_automaticSetup) buildEffect();
}
SmokeEffect::SmokeEffect(const osg::Vec3& position, float scale, float intensity)
{
setDefaults();
@ -33,7 +48,7 @@ SmokeEffect::SmokeEffect(const osg::Vec3& position, float scale, float intensity
_emitterDuration = 65.0;
_defaultParticleTemplate.setLifeTime(5.0*_scale);
buildEffect();
if (_automaticSetup) buildEffect();
}
SmokeEffect::SmokeEffect(const SmokeEffect& copy, const osg::CopyOp& copyop):

View File

@ -23,6 +23,21 @@
using namespace osgParticle;
SmokeTrailEffect::SmokeTrailEffect(bool automaticSetup):
ParticleEffect(automaticSetup)
{
setDefaults();
_position.set(0.0f,0.0f,0.0f);
_scale = 1.0f;
_intensity = 1.0f;
_emitterDuration = 65.0;
_defaultParticleTemplate.setLifeTime(5.0*_scale);
if (_automaticSetup) buildEffect();
}
SmokeTrailEffect::SmokeTrailEffect(const osg::Vec3& position, float scale, float intensity)
{
setDefaults();
@ -34,7 +49,7 @@ SmokeTrailEffect::SmokeTrailEffect(const osg::Vec3& position, float scale, float
_emitterDuration = 65.0;
_defaultParticleTemplate.setLifeTime(5.0*_scale);
buildEffect();
if (_automaticSetup) buildEffect();
}
SmokeTrailEffect::SmokeTrailEffect(const SmokeTrailEffect& copy, const osg::CopyOp& copyop):

View File

@ -10,7 +10,7 @@ bool ExplosionDebrisEffect_writeLocalData(const osg::Object &obj, osgDB::Output
osgDB::RegisterDotOsgWrapperProxy ExplosionDebrisEffect_Proxy
(
new osgParticle::ExplosionDebrisEffect,
new osgParticle::ExplosionDebrisEffect(false),
"ExplosionDebrisEffect",
"Object Node ParticleEffect ExplosionDebrisEffect",
ExplosionDebrisEffect_readLocalData,

View File

@ -10,7 +10,7 @@ bool ExplosionEffect_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
osgDB::RegisterDotOsgWrapperProxy ExplosionEffect_Proxy
(
new osgParticle::ExplosionEffect,
new osgParticle::ExplosionEffect(false),
"ExplosionEffect",
"Object Node ParticleEffect ExplosionEffect",
ExplosionEffect_readLocalData,

View File

@ -10,7 +10,7 @@ bool FireEffect_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
osgDB::RegisterDotOsgWrapperProxy FireEffect_Proxy
(
new osgParticle::FireEffect,
new osgParticle::FireEffect(false),
"FireEffect",
"Object Node ParticleEffect FireEffect",
FireEffect_readLocalData,

View File

@ -177,7 +177,14 @@ bool ParticleEffect_readLocalData(osg::Object& object, osgDB::Input& fr)
}
}
if (!effect.getAutomaticSetup())
{
// since by default the clone of the ParticleEffect is done with automatic setup off to prevent premature loading of
// imagery, we still want to make sure the ParticleEffect is properly built so we'll now mannually enable the automatic setup
// run the buildEffect().
effect.setAutomaticSetup(true);
effect.buildEffect();
}
return itrAdvanced;
}

View File

@ -10,7 +10,7 @@ bool SmokeEffect_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
osgDB::RegisterDotOsgWrapperProxy SmokeEffect_Proxy
(
new osgParticle::SmokeEffect,
new osgParticle::SmokeEffect(false),
"SmokeEffect",
"Object Node ParticleEffect SmokeEffect",
SmokeEffect_readLocalData,

View File

@ -10,7 +10,7 @@ bool SmokeTrailEffect_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
osgDB::RegisterDotOsgWrapperProxy SmokeTrailEffect_Proxy
(
new osgParticle::SmokeTrailEffect,
new osgParticle::SmokeTrailEffect(false),
"SmokeTrailEffect",
"Object Node ParticleEffect SmokeTrailEffect",
SmokeTrailEffect_readLocalData,

View File

@ -27,7 +27,8 @@
BEGIN_OBJECT_REFLECTOR(osgParticle::ExplosionDebrisEffect)
I_BaseType(osgParticle::ParticleEffect);
I_ConstructorWithDefaults3(IN, const osg::Vec3 &, position, osg::Vec3(0.0f, 0.0f, 0.0f), IN, float, scale, 1.0f, IN, float, intensity, 1.0f);
I_ConstructorWithDefaults1(IN, bool, automaticSetup, true);
I_ConstructorWithDefaults3(IN, const osg::Vec3 &, position, , IN, float, scale, 1.0f, IN, float, intensity, 1.0f);
I_ConstructorWithDefaults2(IN, const osgParticle::ExplosionDebrisEffect &, copy, , IN, const osg::CopyOp &, copyop, osg::CopyOp::SHALLOW_COPY);
I_Method0(osg::Object *, cloneType);
I_Method1(osg::Object *, clone, IN, const osg::CopyOp &, copyop);

View File

@ -27,7 +27,8 @@
BEGIN_OBJECT_REFLECTOR(osgParticle::ExplosionEffect)
I_BaseType(osgParticle::ParticleEffect);
I_ConstructorWithDefaults3(IN, const osg::Vec3 &, position, osg::Vec3(0.0f, 0.0f, 0.0f), IN, float, scale, 1.0f, IN, float, intensity, 1.0f);
I_ConstructorWithDefaults1(IN, bool, automaticSetup, true);
I_ConstructorWithDefaults3(IN, const osg::Vec3 &, position, , IN, float, scale, 1.0f, IN, float, intensity, 1.0f);
I_ConstructorWithDefaults2(IN, const osgParticle::ExplosionEffect &, copy, , IN, const osg::CopyOp &, copyop, osg::CopyOp::SHALLOW_COPY);
I_Method0(osg::Object *, cloneType);
I_Method1(osg::Object *, clone, IN, const osg::CopyOp &, copyop);

View File

@ -27,7 +27,8 @@
BEGIN_OBJECT_REFLECTOR(osgParticle::FireEffect)
I_BaseType(osgParticle::ParticleEffect);
I_ConstructorWithDefaults3(IN, const osg::Vec3 &, position, osg::Vec3(0.0f, 0.0f, 0.0f), IN, float, scale, 1.0f, IN, float, intensity, 1.0f);
I_ConstructorWithDefaults1(IN, bool, automaticSetup, true);
I_ConstructorWithDefaults3(IN, const osg::Vec3 &, position, , IN, float, scale, 1.0f, IN, float, intensity, 1.0f);
I_ConstructorWithDefaults2(IN, const osgParticle::FireEffect &, copy, , IN, const osg::CopyOp &, copyop, osg::CopyOp::SHALLOW_COPY);
I_Method0(osg::Object *, cloneType);
I_Method1(osg::Object *, clone, IN, const osg::CopyOp &, copyop);

View File

@ -29,12 +29,14 @@
BEGIN_ABSTRACT_OBJECT_REFLECTOR(osgParticle::ParticleEffect)
I_BaseType(osg::Group);
I_Constructor0();
I_ConstructorWithDefaults1(IN, bool, automaticSetup, true);
I_ConstructorWithDefaults2(IN, const osgParticle::ParticleEffect &, copy, , IN, const osg::CopyOp &, copyop, osg::CopyOp::SHALLOW_COPY);
I_Method0(const char *, libraryName);
I_Method0(const char *, className);
I_Method1(bool, isSameKindAs, IN, const osg::Object *, obj);
I_Method1(void, accept, IN, osg::NodeVisitor &, nv);
I_Method1(void, setAutomaticSetup, IN, bool, flag);
I_Method0(bool, getAutomaticSetup);
I_Method1(void, setUseLocalParticleSystem, IN, bool, local);
I_Method0(bool, getUseLocalParticleSystem);
I_Method1(void, setTextureFileName, IN, const std::string &, filename);
@ -66,6 +68,7 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osgParticle::ParticleEffect)
I_Method0(void, setDefaults);
I_Method0(void, setUpEmitterAndProgram);
I_Method0(void, buildEffect);
I_Property(bool, AutomaticSetup);
I_Property(const osgParticle::Particle &, DefaultParticleTemplate);
I_ReadOnlyProperty(osgParticle::Emitter *, Emitter);
I_Property(double, EmitterDuration);

View File

@ -27,7 +27,8 @@
BEGIN_OBJECT_REFLECTOR(osgParticle::SmokeEffect)
I_BaseType(osgParticle::ParticleEffect);
I_ConstructorWithDefaults3(IN, const osg::Vec3 &, position, osg::Vec3(0.0f, 0.0f, 0.0f), IN, float, scale, 1.0f, IN, float, intensity, 1.0f);
I_ConstructorWithDefaults1(IN, bool, automaticSetup, true);
I_ConstructorWithDefaults3(IN, const osg::Vec3 &, position, , IN, float, scale, 1.0f, IN, float, intensity, 1.0f);
I_ConstructorWithDefaults2(IN, const osgParticle::SmokeEffect &, copy, , IN, const osg::CopyOp &, copyop, osg::CopyOp::SHALLOW_COPY);
I_Method0(osg::Object *, cloneType);
I_Method1(osg::Object *, clone, IN, const osg::CopyOp &, copyop);

View File

@ -27,7 +27,8 @@
BEGIN_OBJECT_REFLECTOR(osgParticle::SmokeTrailEffect)
I_BaseType(osgParticle::ParticleEffect);
I_ConstructorWithDefaults3(IN, const osg::Vec3 &, position, osg::Vec3(0.0f, 0.0f, 0.0f), IN, float, scale, 1.0f, IN, float, intensity, 1.0f);
I_ConstructorWithDefaults1(IN, bool, automaticSetup, true);
I_ConstructorWithDefaults3(IN, const osg::Vec3 &, position, , IN, float, scale, 1.0f, IN, float, intensity, 1.0f);
I_ConstructorWithDefaults2(IN, const osgParticle::SmokeTrailEffect &, copy, , IN, const osg::CopyOp &, copyop, osg::CopyOp::SHALLOW_COPY);
I_Method0(osg::Object *, cloneType);
I_Method1(osg::Object *, clone, IN, const osg::CopyOp &, copyop);