From Wang Rui, reverted changes to osgPartcile that caused problems with osgparticleeffects.

This commit is contained in:
Robert Osfield 2010-09-20 11:50:24 +00:00
parent a8c8c70fb1
commit 5ecc2b9880
7 changed files with 73 additions and 70 deletions

View File

@ -166,12 +166,19 @@ int main( int argc, char** argv )
// The updater can receive particle systems as child drawables now. The addParticleSystem() method // The updater can receive particle systems as child drawables now. The addParticleSystem() method
// is still usable, with which we should define another geode to contain a particle system. // is still usable, with which we should define another geode to contain a particle system.
osg::ref_ptr<osgParticle::ParticleSystemUpdater> updater = new osgParticle::ParticleSystemUpdater; osg::ref_ptr<osgParticle::ParticleSystemUpdater> updater = new osgParticle::ParticleSystemUpdater;
updater->addDrawable( ps.get() ); //updater->addDrawable( ps.get() );
osg::ref_ptr<osg::Group> root = new osg::Group; osg::ref_ptr<osg::Group> root = new osg::Group;
root->addChild( parent.get() ); root->addChild( parent.get() );
root->addChild( updater.get() ); root->addChild( updater.get() );
// FIXME 2010.9.19: the updater can't be a drawable; otehrwise the ParticleEffect will not work properly. why?
updater->addParticleSystem( ps.get() );
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->addDrawable( ps.get() );
root->addChild( geode.get() );
/*** /***
Start the viewer Start the viewer
***/ ***/
@ -190,4 +197,8 @@ int main( int argc, char** argv )
// Now we make use of the getDeltaTime() of ParticleSystem to maintain and dispatch the delta time. But.. // Now we make use of the getDeltaTime() of ParticleSystem to maintain and dispatch the delta time. But..
// it is not the best solution so far, since there are still very few particles acting unexpectedly. // it is not the best solution so far, since there are still very few particles acting unexpectedly.
return viewer.run(); return viewer.run();
// FIXME 2010.9.19: At present, getDeltaTime() is not used and the implementations in the updater and processors still
// use a (t - _t0) as the delta time, which is of course causing floating errors. ParticleEffect will not work if we
// replace the delta time with getDeltaTime()... Need to find a solution.
} }

View File

@ -151,6 +151,7 @@ namespace osgParticle
private: private:
ReferenceFrame _rf; ReferenceFrame _rf;
bool _enabled; bool _enabled;
double _t0;
osg::ref_ptr<ParticleSystem> _ps; osg::ref_ptr<ParticleSystem> _ps;
bool _first_ltw_compute; bool _first_ltw_compute;
bool _need_ltw_matrix; bool _need_ltw_matrix;

View File

@ -36,19 +36,13 @@ namespace osgParticle
update() method on the specified particle systems. You should place this updater update() method on the specified particle systems. You should place this updater
AFTER other nodes like emitters and programs. AFTER other nodes like emitters and programs.
*/ */
class OSGPARTICLE_EXPORT ParticleSystemUpdater: public osg::Geode { class OSGPARTICLE_EXPORT ParticleSystemUpdater: public osg::Node {
public: public:
ParticleSystemUpdater(); ParticleSystemUpdater();
ParticleSystemUpdater(const ParticleSystemUpdater& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY); ParticleSystemUpdater(const ParticleSystemUpdater& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
META_Node(osgParticle,ParticleSystemUpdater); META_Node(osgParticle,ParticleSystemUpdater);
/// Add a Drawable and call addParticleSystem() if it is a particle system
virtual bool addDrawable(osg::Drawable* drawable);
/// Remove a Drawable and call removeParticleSystem() if it is a particle system
virtual bool removeDrawable(osg::Drawable* drawable);
/// Add a particle system to the list. /// Add a particle system to the list.
virtual bool addParticleSystem(ParticleSystem* ps); virtual bool addParticleSystem(ParticleSystem* ps);
@ -87,11 +81,11 @@ namespace osgParticle
virtual ~ParticleSystemUpdater() {} virtual ~ParticleSystemUpdater() {}
ParticleSystemUpdater &operator=(const ParticleSystemUpdater &) { return *this; } ParticleSystemUpdater &operator=(const ParticleSystemUpdater &) { return *this; }
private: private:
typedef std::vector<osg::ref_ptr<ParticleSystem> > ParticleSystem_Vector; typedef std::vector<osg::ref_ptr<ParticleSystem> > ParticleSystem_Vector;
ParticleSystem_Vector _psv; ParticleSystem_Vector _psv;
double _t0;
//added 1/17/06- bgandere@nps.edu //added 1/17/06- bgandere@nps.edu
//a var to keep from doing multiple updates per frame //a var to keep from doing multiple updates per frame

View File

@ -15,6 +15,7 @@ osgParticle::ParticleProcessor::ParticleProcessor()
: osg::Node(), : osg::Node(),
_rf(RELATIVE_RF), _rf(RELATIVE_RF),
_enabled(true), _enabled(true),
_t0(-1),
_ps(0), _ps(0),
_first_ltw_compute(true), _first_ltw_compute(true),
_need_ltw_matrix(false), _need_ltw_matrix(false),
@ -35,6 +36,7 @@ osgParticle::ParticleProcessor::ParticleProcessor(const ParticleProcessor& copy,
: osg::Node(copy, copyop), : osg::Node(copy, copyop),
_rf(copy._rf), _rf(copy._rf),
_enabled(copy._enabled), _enabled(copy._enabled),
_t0(copy._t0),
_ps(static_cast<ParticleSystem* >(copyop(copy._ps.get()))), _ps(static_cast<ParticleSystem* >(copyop(copy._ps.get()))),
_first_ltw_compute(copy._first_ltw_compute), _first_ltw_compute(copy._first_ltw_compute),
_need_ltw_matrix(copy._need_ltw_matrix), _need_ltw_matrix(copy._need_ltw_matrix),
@ -77,38 +79,45 @@ void osgParticle::ParticleProcessor::traverse(osg::NodeVisitor& nv)
if ((_currentTime >= _resetTime) && (_resetTime > 0)) if ((_currentTime >= _resetTime) && (_resetTime > 0))
{ {
_currentTime = 0; _currentTime = 0;
_t0 = -1;
} }
// check whether the processor is alive // skip if we haven't initialized _t0 yet
bool alive = false; if (_t0 != -1)
if (_currentTime >= _startTime)
{ {
if (_endless || (_currentTime < (_startTime + _lifeTime)))
alive = true; // check whether the processor is alive
} bool alive = false;
if (_currentTime >= _startTime)
// update current time {
_currentTime += _ps->getDeltaTime(t); if (_endless || (_currentTime < (_startTime + _lifeTime)))
alive = true;
// process only if the particle system is not frozen/culled }
if (alive &&
_enabled && // update current time
!_ps->isFrozen() && _currentTime += t - _t0;
(_ps->getLastFrameNumber() >= (nv.getFrameStamp()->getFrameNumber() - 1) || !_ps->getFreezeOnCull()))
{ // process only if the particle system is not frozen/culled
// initialize matrix flags if (alive &&
_need_ltw_matrix = true; _enabled &&
_need_wtl_matrix = true; !_ps->isFrozen() &&
_current_nodevisitor = &nv; (_ps->getLastFrameNumber() >= (nv.getFrameStamp()->getFrameNumber() - 1) || !_ps->getFreezeOnCull()))
{
// do some process (unimplemented in this base class) // initialize matrix flags
process( _ps->getDeltaTime(t) ); _need_ltw_matrix = true;
} else { _need_wtl_matrix = true;
//The values of _previous_wtl_matrix and _previous_ltw_matrix will be invalid _current_nodevisitor = &nv;
//since processing was skipped for this frame
_first_ltw_compute = true; // do some process (unimplemented in this base class)
_first_wtl_compute = true; process( t - _t0 );
} else {
//The values of _previous_wtl_matrix and _previous_ltw_matrix will be invalid
//since processing was skipped for this frame
_first_ltw_compute = true;
_first_wtl_compute = true;
}
} }
_t0 = t;
} }
//added- 1/17/06- bgandere@nps.edu //added- 1/17/06- bgandere@nps.edu

View File

@ -6,13 +6,13 @@
using namespace osg; using namespace osg;
osgParticle::ParticleSystemUpdater::ParticleSystemUpdater() osgParticle::ParticleSystemUpdater::ParticleSystemUpdater()
: osg::Geode(), _frameNumber(0) : osg::Node(), _t0(-1), _frameNumber(0)
{ {
setCullingActive(false); setCullingActive(false);
} }
osgParticle::ParticleSystemUpdater::ParticleSystemUpdater(const ParticleSystemUpdater& copy, const osg::CopyOp& copyop) osgParticle::ParticleSystemUpdater::ParticleSystemUpdater(const ParticleSystemUpdater& copy, const osg::CopyOp& copyop)
: osg::Geode(copy, copyop), _frameNumber(0) : osg::Node(copy, copyop), _t0(copy._t0), _frameNumber(0)
{ {
ParticleSystem_Vector::const_iterator i; ParticleSystem_Vector::const_iterator i;
for (i=copy._psv.begin(); i!=copy._psv.end(); ++i) { for (i=copy._psv.begin(); i!=copy._psv.end(); ++i) {
@ -27,24 +27,27 @@ void osgParticle::ParticleSystemUpdater::traverse(osg::NodeVisitor& nv)
{ {
if (nv.getFrameStamp()) if (nv.getFrameStamp())
{ {
if( _frameNumber < nv.getFrameStamp()->getFrameNumber()) if( _frameNumber < nv.getFrameStamp()->getFrameNumber())
{ {
_frameNumber = nv.getFrameStamp()->getFrameNumber(); _frameNumber = nv.getFrameStamp()->getFrameNumber();
double t = nv.getFrameStamp()->getSimulationTime(); double t = nv.getFrameStamp()->getSimulationTime();
ParticleSystem_Vector::iterator i; if (_t0 != -1.0)
for (i=_psv.begin(); i!=_psv.end(); ++i)
{ {
ParticleSystem* ps = i->get(); ParticleSystem_Vector::iterator i;
for (i=_psv.begin(); i!=_psv.end(); ++i)
ParticleSystem::ScopedWriteLock lock(*(ps->getReadWriteMutex()));
if (!ps->isFrozen() && (ps->getLastFrameNumber() >= (nv.getFrameStamp()->getFrameNumber() - 1) || !ps->getFreezeOnCull()))
{ {
ps->update(ps->getDeltaTime(t), nv); ParticleSystem* ps = i->get();
ParticleSystem::ScopedWriteLock lock(*(ps->getReadWriteMutex()));
if (!ps->isFrozen() && (ps->getLastFrameNumber() >= (nv.getFrameStamp()->getFrameNumber() - 1) || !ps->getFreezeOnCull()))
{
ps->update(t - _t0, nv);
}
} }
} }
_t0 = t;
} }
} }
@ -54,32 +57,17 @@ void osgParticle::ParticleSystemUpdater::traverse(osg::NodeVisitor& nv)
} }
} }
Geode::traverse(nv); Node::traverse(nv);
} }
osg::BoundingSphere osgParticle::ParticleSystemUpdater::computeBound() const osg::BoundingSphere osgParticle::ParticleSystemUpdater::computeBound() const
{ {
return Geode::computeBound(); return osg::BoundingSphere();
}
bool osgParticle::ParticleSystemUpdater::addDrawable(Drawable* drawable)
{
ParticleSystem* ps = dynamic_cast<ParticleSystem*>(drawable);
if (ps) addParticleSystem(ps);
return Geode::addDrawable(drawable);
}
bool osgParticle::ParticleSystemUpdater::removeDrawable(Drawable* drawable)
{
ParticleSystem* ps = dynamic_cast<ParticleSystem*>(drawable);
if (ps) removeParticleSystem(ps);
return Geode::removeDrawable(drawable);
} }
bool osgParticle::ParticleSystemUpdater::addParticleSystem(ParticleSystem* ps) bool osgParticle::ParticleSystemUpdater::addParticleSystem(ParticleSystem* ps)
{ {
unsigned int i = getParticleSystemIndex( ps ); _psv.push_back(ps);
if( i >= _psv.size() ) _psv.push_back(ps);
return true; return true;
} }

View File

@ -13,7 +13,7 @@ REGISTER_DOTOSGWRAPPER(PSU_Proxy)
( (
new osgParticle::ParticleSystemUpdater, new osgParticle::ParticleSystemUpdater,
"ParticleSystemUpdater", "ParticleSystemUpdater",
"Object Node Geode ParticleSystemUpdater", "Object Node ParticleSystemUpdater",
PSU_readLocalData, PSU_readLocalData,
PSU_writeLocalData PSU_writeLocalData
); );

View File

@ -35,7 +35,7 @@ static bool writeParticleSystems( osgDB::OutputStream& os, const osgParticle::Pa
REGISTER_OBJECT_WRAPPER( osgParticleParticleSystemUpdater, REGISTER_OBJECT_WRAPPER( osgParticleParticleSystemUpdater,
new osgParticle::ParticleSystemUpdater, new osgParticle::ParticleSystemUpdater,
osgParticle::ParticleSystemUpdater, osgParticle::ParticleSystemUpdater,
"osg::Object osg::Node osg::Geode osgParticle::ParticleSystemUpdater" ) "osg::Object osg::Node osgParticle::ParticleSystemUpdater" )
{ {
ADD_USER_SERIALIZER( ParticleSystems ); // _psv ADD_USER_SERIALIZER( ParticleSystems ); // _psv
} }