Form Wang Rui, "An initial GLSL shader support of rendering particles. Only the POINT
type is supported at present. The attached osgparticleshader.cpp will show how it works. It can also be placed in the examples folder. But I just wonder how this example co-exists with another two (osgparticle and osgparticleeffect)? Member variables in Particle, including _alive, _current_size and _current_alpha, are now merged into one Vec3 variable. Then we can make use of the set...Pointer() methods to treat them as vertex attribtues in GLSL. User interfaces are not changed. Additional methods of ParticleSystem are introduced, including setDefaultAttributesUsingShaders(), setSortMode() and setVisibilityDistance(). You can see how they work in osgparticleshader.cpp. Additional user-defined particle type is introduced. Set the particle type to USER and attach a drawable to the template. Be careful because of possible huge memory consumption. It is highly suggested to use display lists here. The ParticleSystemUpdater can accepts ParticleSystem objects as child drawables now. I myself think it is a little simpler in structure, than creating a new geode for each particle system. Of course, the latter is still compatible, and can be used to transform entire particles in the world. New particle operators: bounce, sink, damping, orbit and explosion. The bounce and sink opeartors both use a concept of domains, and can simulate a very basic collision of particles and objects. New composite placer. It contains a set of placers and emit particles from them randomly. The added virtual method size() of each placer will help determine the probability of generating. New virtual method operateParticles() for the Operator class. It actually calls operate() for each particle, but can be overrode to use speedup techniques like SSE, or even shaders in the future. Partly fix a floating error of 'delta time' in emitter, program and updaters. Previously they keep the _t0 variable seperately and compute different copies of dt by themseleves, which makes some operators, especially the BounceOperator, work incorrectly (because the dt in operators and updaters are slightly different). Now a getDeltaTime() method is maintained in ParticleSystem, and will return the unique dt value (passing by reference) for use. This makes thing better, but still very few unexpected behavours at present... All dotosg and serialzier wrappers for functionalities above are provided. ... According to some simple tests, the new shader support is slightly efficient than ordinary glBegin()/end(). That means, I haven't got a big improvement at present. I think the bottlenack here seems to be the cull traversal time. Because operators go through the particle list again and again (for example, the fountain in the shader example requires 4 operators working all the time). A really ideal solution here is to implement the particle operators in shaders, too, and copy the results back to particle attributes. The concept of GPGPU is good for implementing this. But in my opinion, the Camera class seems to be too heavy for realizing such functionality in a particle system. Myabe a light-weight ComputeDrawable class is enough for receiving data as textures and outputting the results to the FBO render buffer. What do you think then? The floating error of emitters (http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/2009-May/028435.html) is not solved this time. But what I think is worth testing is that we could directly compute the node path from the emitter to the particle system rather than multiplying the worldToLocal and LocalToWorld matrices. I'll try this idea later. "
This commit is contained in:
158
src/osgParticle/BounceOperator.cpp
Normal file
158
src/osgParticle/BounceOperator.cpp
Normal file
@@ -0,0 +1,158 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
// Written by Wang Rui, (C) 2010
|
||||
|
||||
#include <osg/Notify>
|
||||
#include <osgParticle/ModularProgram>
|
||||
#include <osgParticle/BounceOperator>
|
||||
|
||||
using namespace osgParticle;
|
||||
|
||||
void BounceOperator::handleTriangle( const Domain& domain, Particle* P, double dt )
|
||||
{
|
||||
osg::Vec3 nextpos = P->getPosition() + P->getVelocity() * dt;
|
||||
float distance = domain.plane.distance( P->getPosition() );
|
||||
if ( distance*domain.plane.distance(nextpos)>=0 ) return;
|
||||
|
||||
osg::Vec3 normal = domain.plane.getNormal();
|
||||
float nv = normal * P->getVelocity();
|
||||
osg::Vec3 hitPoint = P->getPosition() - P->getVelocity() * (distance / nv);
|
||||
|
||||
float upos = (hitPoint - domain.v1) * domain.s1;
|
||||
float vpos = (hitPoint - domain.v1) * domain.s2;
|
||||
if ( upos<0.0f || vpos<0.0f || (upos + vpos)>1.0f ) return;
|
||||
|
||||
// Compute tangential and normal components of velocity
|
||||
osg::Vec3 vn = normal * nv;
|
||||
osg::Vec3 vt = P->getVelocity() - vn;
|
||||
|
||||
// Compute new velocity
|
||||
if ( vt.length2()<=_cutoff ) P->setVelocity( vt - vn*_resilience );
|
||||
else P->setVelocity( vt*(1.0f-_friction) - vn*_resilience );
|
||||
}
|
||||
|
||||
void BounceOperator::handleRectangle( const Domain& domain, Particle* P, double dt )
|
||||
{
|
||||
osg::Vec3 nextpos = P->getPosition() + P->getVelocity() * dt;
|
||||
float distance = domain.plane.distance( P->getPosition() );
|
||||
if ( distance*domain.plane.distance(nextpos)>=0 ) return;
|
||||
|
||||
osg::Vec3 normal = domain.plane.getNormal();
|
||||
float nv = normal * P->getVelocity();
|
||||
osg::Vec3 hitPoint = P->getPosition() - P->getVelocity() * (distance / nv);
|
||||
|
||||
float upos = (hitPoint - domain.v1) * domain.s1;
|
||||
float vpos = (hitPoint - domain.v1) * domain.s2;
|
||||
if ( upos<0.0f || upos>1.0f || vpos<0.0f || vpos>1.0f ) return;
|
||||
|
||||
// Compute tangential and normal components of velocity
|
||||
osg::Vec3 vn = normal * nv;
|
||||
osg::Vec3 vt = P->getVelocity() - vn;
|
||||
|
||||
// Compute new velocity
|
||||
if ( vt.length2()<=_cutoff ) P->setVelocity( vt - vn*_resilience );
|
||||
else P->setVelocity( vt*(1.0f-_friction) - vn*_resilience );
|
||||
}
|
||||
|
||||
void BounceOperator::handlePlane( const Domain& domain, Particle* P, double dt )
|
||||
{
|
||||
osg::Vec3 nextpos = P->getPosition() + P->getVelocity() * dt;
|
||||
float distance = domain.plane.distance( P->getPosition() );
|
||||
if ( distance*domain.plane.distance(nextpos)>=0 ) return;
|
||||
|
||||
osg::Vec3 normal = domain.plane.getNormal();
|
||||
float nv = normal * P->getVelocity();
|
||||
|
||||
// Compute tangential and normal components of velocity
|
||||
osg::Vec3 vn = normal * nv;
|
||||
osg::Vec3 vt = P->getVelocity() - vn;
|
||||
|
||||
// Compute new velocity
|
||||
if ( vt.length2()<=_cutoff ) P->setVelocity( vt - vn*_resilience );
|
||||
else P->setVelocity( vt*(1.0f-_friction) - vn*_resilience );
|
||||
}
|
||||
|
||||
void BounceOperator::handleSphere( const Domain& domain, Particle* P, double dt )
|
||||
{
|
||||
osg::Vec3 nextpos = P->getPosition() + P->getVelocity() * dt;
|
||||
float distance1 = (P->getPosition() - domain.v1).length();
|
||||
if ( distance1<=domain.r1 ) // Within the sphere
|
||||
{
|
||||
float distance2 = (nextpos - domain.v1).length();
|
||||
if ( distance2<=domain.r1 ) return;
|
||||
|
||||
// Bounce back in if going outside
|
||||
osg::Vec3 normal = domain.v1 - P->getPosition(); normal.normalize();
|
||||
float nmag = P->getVelocity() * normal;
|
||||
|
||||
// Compute tangential and normal components of velocity
|
||||
osg::Vec3 vn = normal * nmag;
|
||||
osg::Vec3 vt = P->getVelocity() - vn;
|
||||
if ( nmag<0 ) vn = -vn;
|
||||
|
||||
// Compute new velocity
|
||||
float tanscale = (vt.length2()<=_cutoff) ? 1.0f : (1.0f - _friction);
|
||||
P->setVelocity( vt * tanscale + vn * _resilience );
|
||||
|
||||
// Make sure the particle is fixed to stay inside
|
||||
nextpos = P->getPosition() + P->getVelocity() * dt;
|
||||
distance2 = (nextpos - domain.v1).length();
|
||||
if ( distance2>domain.r1 )
|
||||
{
|
||||
normal = domain.v1 - nextpos; normal.normalize();
|
||||
|
||||
osg::Vec3 wishPoint = domain.v1 - normal * (0.999f * domain.r1);
|
||||
P->setVelocity( (wishPoint - P->getPosition()) / dt );
|
||||
}
|
||||
}
|
||||
else // Outside the sphere
|
||||
{
|
||||
float distance2 = (nextpos - domain.v1).length();
|
||||
if ( distance2>domain.r1 ) return;
|
||||
|
||||
// Bounce back out if going inside
|
||||
osg::Vec3 normal = P->getPosition() - domain.v1; normal.normalize();
|
||||
float nmag = P->getVelocity() * normal;
|
||||
|
||||
// Compute tangential and normal components of velocity
|
||||
osg::Vec3 vn = normal * nmag;
|
||||
osg::Vec3 vt = P->getVelocity() - vn;
|
||||
if ( nmag<0 ) vn = -vn;
|
||||
|
||||
// Compute new velocity
|
||||
float tanscale = (vt.length2()<=_cutoff) ? 1.0f : (1.0f - _friction);
|
||||
P->setVelocity( vt * tanscale + vn * _resilience );
|
||||
}
|
||||
}
|
||||
|
||||
void BounceOperator::handleDisk( const Domain& domain, Particle* P, double dt )
|
||||
{
|
||||
osg::Vec3 nextpos = P->getPosition() + P->getVelocity() * dt;
|
||||
float distance = domain.plane.distance( P->getPosition() );
|
||||
if ( distance*domain.plane.distance(nextpos)>=0 ) return;
|
||||
|
||||
osg::Vec3 normal = domain.plane.getNormal();
|
||||
float nv = normal * P->getVelocity();
|
||||
osg::Vec3 hitPoint = P->getPosition() - P->getVelocity() * (distance / nv);
|
||||
|
||||
float radius = (hitPoint - domain.v1).length();
|
||||
if ( radius>domain.r1 || radius<domain.r2 ) return;
|
||||
|
||||
// Compute tangential and normal components of velocity
|
||||
osg::Vec3 vn = normal * nv;
|
||||
osg::Vec3 vt = P->getVelocity() - vn;
|
||||
|
||||
// Compute new velocity
|
||||
if ( vt.length2()<=_cutoff ) P->setVelocity( vt - vn*_resilience );
|
||||
else P->setVelocity( vt*(1.0f-_friction) - vn*_resilience );
|
||||
}
|
||||
@@ -48,6 +48,15 @@ SET(LIB_PUBLIC_HEADERS
|
||||
${HEADER_PATH}/SmokeTrailEffect
|
||||
${HEADER_PATH}/VariableRateCounter
|
||||
${HEADER_PATH}/Version
|
||||
|
||||
${HEADER_PATH}/CompositePlacer
|
||||
${HEADER_PATH}/AngularDampingOperator
|
||||
${HEADER_PATH}/DampingOperator
|
||||
${HEADER_PATH}/ExplosionOperator
|
||||
${HEADER_PATH}/OrbitOperator
|
||||
${HEADER_PATH}/DomainOperator
|
||||
${HEADER_PATH}/BounceOperator
|
||||
${HEADER_PATH}/SinkOperator
|
||||
)
|
||||
|
||||
# FIXME: For OS X, need flag for Framework or dylib
|
||||
@@ -74,6 +83,10 @@ ADD_LIBRARY(${LIB_NAME}
|
||||
SmokeEffect.cpp
|
||||
SmokeTrailEffect.cpp
|
||||
Version.cpp
|
||||
|
||||
DomainOperator.cpp
|
||||
BounceOperator.cpp
|
||||
SinkOperator.cpp
|
||||
${OPENSCENEGRAPH_VERSIONINFO_RC}
|
||||
)
|
||||
|
||||
|
||||
115
src/osgParticle/DomainOperator.cpp
Normal file
115
src/osgParticle/DomainOperator.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
// Written by Wang Rui, (C) 2010
|
||||
|
||||
#include <osg/Notify>
|
||||
#include <osgParticle/ModularProgram>
|
||||
#include <osgParticle/DomainOperator>
|
||||
|
||||
using namespace osgParticle;
|
||||
|
||||
void DomainOperator::operate( Particle* P, double dt )
|
||||
{
|
||||
for ( std::vector<Domain>::iterator itr=_domains.begin(); itr!=_domains.end(); ++itr )
|
||||
{
|
||||
switch ( itr->type )
|
||||
{
|
||||
case Domain::POINT_DOMAIN:
|
||||
handlePoint( *itr, P, dt );
|
||||
break;
|
||||
case Domain::LINE_DOMAIN:
|
||||
handleLineSegment( *itr, P, dt );
|
||||
break;
|
||||
case Domain::TRI_DOMAIN:
|
||||
handleTriangle( *itr, P, dt );
|
||||
break;
|
||||
case Domain::RECT_DOMAIN:
|
||||
handleRectangle( *itr, P, dt );
|
||||
break;
|
||||
case Domain::PLANE_DOMAIN:
|
||||
handlePlane( *itr, P, dt );
|
||||
break;
|
||||
case Domain::SPHERE_DOMAIN:
|
||||
handleSphere( *itr, P, dt );
|
||||
break;
|
||||
case Domain::BOX_DOMAIN:
|
||||
handleBox( *itr, P, dt );
|
||||
break;
|
||||
case Domain::DISK_DOMAIN:
|
||||
handleDisk( *itr, P, dt );
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DomainOperator::beginOperate( Program* prg )
|
||||
{
|
||||
if ( prg->getReferenceFrame()==ModularProgram::RELATIVE_RF )
|
||||
{
|
||||
_backupDomains = _domains;
|
||||
for ( std::vector<Domain>::iterator itr=_domains.begin(); itr!=_domains.end(); ++itr )
|
||||
{
|
||||
Domain& domain = *itr;
|
||||
switch ( domain.type )
|
||||
{
|
||||
case Domain::POINT_DOMAIN:
|
||||
domain.v1 = prg->transformLocalToWorld(domain.v1);
|
||||
break;
|
||||
case Domain::LINE_DOMAIN:
|
||||
domain.v1 = prg->transformLocalToWorld(domain.v1);
|
||||
domain.v2 = prg->transformLocalToWorld(domain.v2);
|
||||
break;
|
||||
case Domain::TRI_DOMAIN:
|
||||
domain.v1 = prg->transformLocalToWorld(domain.v1);
|
||||
domain.v2 = prg->transformLocalToWorld(domain.v2);
|
||||
domain.v3 = prg->transformLocalToWorld(domain.v3);
|
||||
domain.plane.set(domain.v1, domain.v2, domain.v3);
|
||||
computeNewBasis( domain.v2-domain.v1, domain.v3-domain.v1, domain.s1, domain.s2 );
|
||||
break;
|
||||
case Domain::RECT_DOMAIN:
|
||||
domain.v1 = prg->transformLocalToWorld(domain.v1);
|
||||
domain.v2 = prg->rotateLocalToWorld(domain.v2); // Width vector
|
||||
domain.v3 = prg->rotateLocalToWorld(domain.v3); // Height vector
|
||||
domain.plane.set(domain.v1, domain.v1+domain.v2, domain.v1+domain.v3);
|
||||
computeNewBasis( domain.v2, domain.v3, domain.s1, domain.s2 );
|
||||
break;
|
||||
case Domain::PLANE_DOMAIN:
|
||||
domain.plane.transformProvidingInverse( prg->getLocalToWorldMatrix() );
|
||||
break;
|
||||
case Domain::SPHERE_DOMAIN:
|
||||
domain.v1 = prg->transformLocalToWorld(domain.v1);
|
||||
break;
|
||||
case Domain::BOX_DOMAIN:
|
||||
domain.v1 = prg->transformLocalToWorld(domain.v1);
|
||||
domain.v2 = prg->transformLocalToWorld(domain.v2);
|
||||
break;
|
||||
case Domain::DISK_DOMAIN:
|
||||
domain.v1 = prg->transformLocalToWorld(domain.v1);
|
||||
domain.v2 = prg->rotateLocalToWorld(domain.v2);
|
||||
domain.v2.normalize(); // Normal
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DomainOperator::endOperate()
|
||||
{
|
||||
if ( _backupDomains.size()>0 )
|
||||
{
|
||||
_domains = _backupDomains;
|
||||
_backupDomains.clear();
|
||||
}
|
||||
}
|
||||
@@ -25,13 +25,7 @@ void osgParticle::ModularProgram::execute(double dt)
|
||||
ParticleSystem* ps = getParticleSystem();
|
||||
for (ci=_operators.begin(); ci!=ci_end; ++ci) {
|
||||
(*ci)->beginOperate(this);
|
||||
int n = ps->numParticles();
|
||||
for (int i=0; i<n; ++i) {
|
||||
Particle* P = ps->getParticle(i);
|
||||
if (P->isAlive() && (*ci)->isEnabled()) {
|
||||
(*ci)->operate(P, dt);
|
||||
}
|
||||
}
|
||||
(*ci)->operateParticles(ps, dt);
|
||||
(*ci)->endOperate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ osgParticle::Particle::Particle()
|
||||
_si(new LinearInterpolator),
|
||||
_ai(new LinearInterpolator),
|
||||
_ci(new LinearInterpolator),
|
||||
_alive(true),
|
||||
//_alive(true),
|
||||
_mustdie(false),
|
||||
_lifeTime(2),
|
||||
_radius(0.2f),
|
||||
@@ -41,8 +41,8 @@ osgParticle::Particle::Particle()
|
||||
_angle(0, 0, 0),
|
||||
_angul_arvel(0, 0, 0),
|
||||
_t0(0),
|
||||
_current_size(0),
|
||||
_current_alpha(0),
|
||||
//_current_size(0),
|
||||
//_current_alpha(0),
|
||||
_s_tile(1.0f),
|
||||
_t_tile(1.0f),
|
||||
_start_tile(0),
|
||||
@@ -51,16 +51,18 @@ osgParticle::Particle::Particle()
|
||||
_s_coord(0.0f),
|
||||
_t_coord(0.0f),
|
||||
_previousParticle(INVALID_INDEX),
|
||||
_nextParticle(INVALID_INDEX)
|
||||
_nextParticle(INVALID_INDEX),
|
||||
_depth(0.0)
|
||||
{
|
||||
_base_prop.set(1.0f, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
bool osgParticle::Particle::update(double dt)
|
||||
bool osgParticle::Particle::update(double dt, bool onlyTimeStamp)
|
||||
{
|
||||
// this method should return false when the particle dies;
|
||||
// so, if we were instructed to die, do it now and return.
|
||||
if (_mustdie) {
|
||||
_alive = false;
|
||||
_base_prop.x() = -1.0;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -75,9 +77,30 @@ bool osgParticle::Particle::update(double dt)
|
||||
|
||||
// if our age is over the lifetime limit, then die and return.
|
||||
if (x > 1) {
|
||||
_alive = false;
|
||||
_base_prop.x() = -1.0;
|
||||
return false;
|
||||
}
|
||||
|
||||
// compute the current values for size, alpha and color.
|
||||
if (_lifeTime <= 0) {
|
||||
if (dt == _t0) {
|
||||
_base_prop.y() = _sr.get_random();
|
||||
_base_prop.z() = _ar.get_random();
|
||||
_current_color = _cr.get_random();
|
||||
}
|
||||
} else {
|
||||
_base_prop.y() = _si.get()->interpolate(x, _sr);
|
||||
_base_prop.z() = _ai.get()->interpolate(x, _ar);
|
||||
_current_color = _ci.get()->interpolate(x, _cr);
|
||||
}
|
||||
|
||||
// update position
|
||||
_prev_pos = _position;
|
||||
_position += _velocity * dt;
|
||||
|
||||
// return now if we indicate that only time stamp should be updated
|
||||
// the shader will handle remain properties in this case
|
||||
if (onlyTimeStamp) return true;
|
||||
|
||||
//Compute the current texture tile based on our normalized age
|
||||
int currentTile = _start_tile + static_cast<int>(x * getNumTiles());
|
||||
@@ -93,23 +116,6 @@ bool osgParticle::Particle::update(double dt)
|
||||
// OSG_NOTICE<<this<<" setting tex coords "<<_s_coord<<" "<<_t_coord<<std::endl;
|
||||
}
|
||||
|
||||
// compute the current values for size, alpha and color.
|
||||
if (_lifeTime <= 0) {
|
||||
if (dt == _t0) {
|
||||
_current_size = _sr.get_random();
|
||||
_current_alpha = _ar.get_random();
|
||||
_current_color = _cr.get_random();
|
||||
}
|
||||
} else {
|
||||
_current_size = _si.get()->interpolate(x, _sr);
|
||||
_current_alpha = _ai.get()->interpolate(x, _ar);
|
||||
_current_color = _ci.get()->interpolate(x, _cr);
|
||||
}
|
||||
|
||||
// update position
|
||||
_prev_pos = _position;
|
||||
_position += _velocity * dt;
|
||||
|
||||
// update angle
|
||||
_prev_angle = _angle;
|
||||
_angle += _angul_arvel * dt;
|
||||
@@ -129,10 +135,10 @@ void osgParticle::Particle::render(osg::GLBeginEndAdapter* gl, const osg::Vec3&
|
||||
gl->Color4f( _current_color.x(),
|
||||
_current_color.y(),
|
||||
_current_color.z(),
|
||||
_current_color.w() * _current_alpha);
|
||||
_current_color.w() * _base_prop.z());
|
||||
|
||||
osg::Vec3 p1(px * _current_size * scale);
|
||||
osg::Vec3 p2(py * _current_size * scale);
|
||||
osg::Vec3 p1(px * _base_prop.y() * scale);
|
||||
osg::Vec3 p2(py * _base_prop.y() * scale);
|
||||
|
||||
switch (_shape)
|
||||
{
|
||||
@@ -199,7 +205,7 @@ void osgParticle::Particle::render(osg::GLBeginEndAdapter* gl, const osg::Vec3&
|
||||
// calculation of one of the linesegment endpoints.
|
||||
float vl = _velocity.length();
|
||||
if (vl != 0) {
|
||||
osg::Vec3 v = _velocity * _current_size * scale / vl;
|
||||
osg::Vec3 v = _velocity * _base_prop.y() * scale / vl;
|
||||
|
||||
gl->TexCoord1f(0);
|
||||
gl->Vertex3f(xpos.x(), xpos.y(), xpos.z());
|
||||
@@ -214,11 +220,36 @@ void osgParticle::Particle::render(osg::GLBeginEndAdapter* gl, const osg::Vec3&
|
||||
}
|
||||
}
|
||||
|
||||
void osgParticle::Particle::render(osg::RenderInfo& renderInfo, const osg::Vec3& xpos, const osg::Vec3& xrot) const
|
||||
{
|
||||
#if defined(OSG_GL_MATRICES_AVAILABLE)
|
||||
if (_drawable.valid())
|
||||
{
|
||||
bool requiresRotation = (xrot.x()!=0.0f || xrot.y()!=0.0f || xrot.z()!=0.0f);
|
||||
glColor4f(_current_color.x(),
|
||||
_current_color.y(),
|
||||
_current_color.z(),
|
||||
_current_color.w() * _base_prop.z());
|
||||
glPushMatrix();
|
||||
glTranslatef(xpos.x(), xpos.y(), xpos.z());
|
||||
if (requiresRotation)
|
||||
{
|
||||
osg::Quat rotation(xrot.x(), osg::X_AXIS, xrot.y(), osg::Y_AXIS, xrot.z(), osg::Z_AXIS);
|
||||
glMultMatrixd(osg::Matrixd(rotation).ptr());
|
||||
}
|
||||
_drawable->draw(renderInfo);
|
||||
glPopMatrix();
|
||||
}
|
||||
#else
|
||||
OSG_NOTICE<<"Warning: Particle::render(..) not supported for user-defined shape."<<std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
void osgParticle::Particle::setUpTexCoordsAsPartOfConnectedParticleSystem(ParticleSystem* ps)
|
||||
{
|
||||
if (getPreviousParticle()!=Particle::INVALID_INDEX)
|
||||
{
|
||||
update(0.0);
|
||||
update(0.0, false);
|
||||
|
||||
Particle* previousParticle = ps->getParticle(getPreviousParticle());
|
||||
const osg::Vec3& previousPosition = previousParticle->getPosition();
|
||||
|
||||
@@ -15,7 +15,6 @@ osgParticle::ParticleProcessor::ParticleProcessor()
|
||||
: osg::Node(),
|
||||
_rf(RELATIVE_RF),
|
||||
_enabled(true),
|
||||
_t0(-1),
|
||||
_ps(0),
|
||||
_first_ltw_compute(true),
|
||||
_need_ltw_matrix(false),
|
||||
@@ -36,7 +35,6 @@ osgParticle::ParticleProcessor::ParticleProcessor(const ParticleProcessor& copy,
|
||||
: osg::Node(copy, copyop),
|
||||
_rf(copy._rf),
|
||||
_enabled(copy._enabled),
|
||||
_t0(copy._t0),
|
||||
_ps(static_cast<ParticleSystem* >(copyop(copy._ps.get()))),
|
||||
_first_ltw_compute(copy._first_ltw_compute),
|
||||
_need_ltw_matrix(copy._need_ltw_matrix),
|
||||
@@ -79,47 +77,38 @@ void osgParticle::ParticleProcessor::traverse(osg::NodeVisitor& nv)
|
||||
if ((_currentTime >= _resetTime) && (_resetTime > 0))
|
||||
{
|
||||
_currentTime = 0;
|
||||
_t0 = -1;
|
||||
}
|
||||
|
||||
// skip if we haven't initialized _t0 yet
|
||||
if (_t0 != -1)
|
||||
// check whether the processor is alive
|
||||
bool alive = false;
|
||||
if (_currentTime >= _startTime)
|
||||
{
|
||||
|
||||
// check whether the processor is alive
|
||||
bool alive = false;
|
||||
if (_currentTime >= _startTime)
|
||||
{
|
||||
if (_endless || (_currentTime < (_startTime + _lifeTime)))
|
||||
alive = true;
|
||||
}
|
||||
|
||||
// update current time
|
||||
_currentTime += t - _t0;
|
||||
|
||||
// process only if the particle system is not frozen/culled
|
||||
if (alive &&
|
||||
_enabled &&
|
||||
!_ps->isFrozen() &&
|
||||
(_ps->getLastFrameNumber() >= (nv.getFrameStamp()->getFrameNumber() - 1) || !_ps->getFreezeOnCull()))
|
||||
{
|
||||
// initialize matrix flags
|
||||
_need_ltw_matrix = true;
|
||||
_need_wtl_matrix = true;
|
||||
_current_nodevisitor = &nv;
|
||||
|
||||
// do some process (unimplemented in this base class)
|
||||
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;
|
||||
}
|
||||
if (_endless || (_currentTime < (_startTime + _lifeTime)))
|
||||
alive = true;
|
||||
}
|
||||
|
||||
// update _t0
|
||||
_t0 = t;
|
||||
// update current time
|
||||
_currentTime += _ps->getDeltaTime(t);
|
||||
|
||||
// process only if the particle system is not frozen/culled
|
||||
if (alive &&
|
||||
_enabled &&
|
||||
!_ps->isFrozen() &&
|
||||
(_ps->getLastFrameNumber() >= (nv.getFrameStamp()->getFrameNumber() - 1) || !_ps->getFreezeOnCull()))
|
||||
{
|
||||
// initialize matrix flags
|
||||
_need_ltw_matrix = true;
|
||||
_need_wtl_matrix = true;
|
||||
_current_nodevisitor = &nv;
|
||||
|
||||
// do some process (unimplemented in this base class)
|
||||
process( _ps->getDeltaTime(t) );
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
//added- 1/17/06- bgandere@nps.edu
|
||||
|
||||
@@ -12,10 +12,22 @@
|
||||
#include <osg/BlendFunc>
|
||||
#include <osg/TexEnv>
|
||||
#include <osg/Material>
|
||||
#include <osg/PointSprite>
|
||||
#include <osg/Program>
|
||||
#include <osg/Notify>
|
||||
#include <osg/io_utils>
|
||||
|
||||
#include <osgDB/FileUtils>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgUtil/CullVisitor>
|
||||
|
||||
#define USE_LOCAL_SHADERS
|
||||
|
||||
static double distance(const osg::Vec3& coord, const osg::Matrix& matrix)
|
||||
{
|
||||
// copied from CullVisitor.cpp
|
||||
return -(coord[0]*matrix(0,2)+coord[1]*matrix(1,2)+coord[2]*matrix(2,2)+matrix(3,2));
|
||||
}
|
||||
|
||||
osgParticle::ParticleSystem::ParticleSystem()
|
||||
: osg::Drawable(),
|
||||
@@ -24,6 +36,9 @@ osgParticle::ParticleSystem::ParticleSystem()
|
||||
_align_X_axis(1, 0, 0),
|
||||
_align_Y_axis(0, 1, 0),
|
||||
_particleScaleReferenceFrame(WORLD_COORDINATES),
|
||||
_useVertexArray(false),
|
||||
_useShaders(false),
|
||||
_dirty_uniforms(false),
|
||||
_doublepass(false),
|
||||
_frozen(false),
|
||||
_bmin(0, 0, 0),
|
||||
@@ -32,8 +47,13 @@ osgParticle::ParticleSystem::ParticleSystem()
|
||||
_bounds_computed(false),
|
||||
_def_ptemp(Particle()),
|
||||
_last_frame(0),
|
||||
_dirty_dt(true),
|
||||
_freeze_on_cull(false),
|
||||
_t0(0.0),
|
||||
_dt(0.0),
|
||||
_detail(1),
|
||||
_sortMode(NO_SORT),
|
||||
_visibilityDistance(-1.0),
|
||||
_draw_count(0)
|
||||
{
|
||||
// we don't support display lists because particle systems
|
||||
@@ -48,6 +68,9 @@ osgParticle::ParticleSystem::ParticleSystem(const ParticleSystem& copy, const os
|
||||
_align_X_axis(copy._align_X_axis),
|
||||
_align_Y_axis(copy._align_Y_axis),
|
||||
_particleScaleReferenceFrame(copy._particleScaleReferenceFrame),
|
||||
_useVertexArray(copy._useVertexArray),
|
||||
_useShaders(copy._useShaders),
|
||||
_dirty_uniforms(copy._dirty_uniforms),
|
||||
_doublepass(copy._doublepass),
|
||||
_frozen(copy._frozen),
|
||||
_bmin(copy._bmin),
|
||||
@@ -56,8 +79,13 @@ osgParticle::ParticleSystem::ParticleSystem(const ParticleSystem& copy, const os
|
||||
_bounds_computed(copy._bounds_computed),
|
||||
_def_ptemp(copy._def_ptemp),
|
||||
_last_frame(copy._last_frame),
|
||||
_dirty_dt(copy._dirty_dt),
|
||||
_freeze_on_cull(copy._freeze_on_cull),
|
||||
_t0(copy._t0),
|
||||
_dt(copy._dt),
|
||||
_detail(copy._detail),
|
||||
_sortMode(copy._sortMode),
|
||||
_visibilityDistance(copy._visibilityDistance),
|
||||
_draw_count(0)
|
||||
{
|
||||
}
|
||||
@@ -66,18 +94,34 @@ osgParticle::ParticleSystem::~ParticleSystem()
|
||||
{
|
||||
}
|
||||
|
||||
void osgParticle::ParticleSystem::update(double dt)
|
||||
void osgParticle::ParticleSystem::update(double dt, osg::NodeVisitor& nv)
|
||||
{
|
||||
// reset bounds
|
||||
_reset_bounds_flag = true;
|
||||
|
||||
|
||||
if (_useShaders)
|
||||
{
|
||||
// Update shader uniforms
|
||||
// This slightly reduces the consumption of traversing the particle vector, because we
|
||||
// don't compute tile and angle attributes that are useleff for shaders.
|
||||
// At present, our lcoal shader implementation will ignore these particle props:
|
||||
// _cur_tile, _s_coord, _t_coord, _prev_pos, _prev_angle and _angle
|
||||
osg::StateSet* stateset = getOrCreateStateSet();
|
||||
|
||||
if (_dirty_uniforms)
|
||||
{
|
||||
osg::Uniform* u_vd = stateset->getUniform("visibilityDistance");
|
||||
if (u_vd) u_vd->set((float)_visibilityDistance);
|
||||
_dirty_uniforms = false;
|
||||
}
|
||||
}
|
||||
|
||||
for(unsigned int i=0; i<_particles.size(); ++i)
|
||||
{
|
||||
Particle& particle = _particles[i];
|
||||
if (particle.isAlive())
|
||||
{
|
||||
if (particle.update(dt))
|
||||
if (particle.update(dt, _useShaders))
|
||||
{
|
||||
update_bounds(particle.getPosition(), particle.getCurrentSize());
|
||||
}
|
||||
@@ -87,7 +131,27 @@ void osgParticle::ParticleSystem::update(double dt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (_sortMode != NO_SORT)
|
||||
{
|
||||
// sort particles
|
||||
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv);
|
||||
if (cv)
|
||||
{
|
||||
osg::Matrixd modelview = *(cv->getModelViewMatrix());
|
||||
float scale = (_sortMode==SORT_FRONT_TO_BACK ? -1.0f : 1.0f);
|
||||
for (unsigned int i=0; i<_particles.size(); ++i)
|
||||
{
|
||||
Particle& particle = _particles[i];
|
||||
if (particle.isAlive())
|
||||
particle.setDepth(distance(particle.getPosition(), modelview) * scale);
|
||||
else
|
||||
particle.setDepth(0.0f);
|
||||
}
|
||||
std::sort<Particle_vector::iterator>(_particles.begin(), _particles.end());
|
||||
}
|
||||
}
|
||||
|
||||
// force recomputing of bounding box on next frame
|
||||
dirtyBound();
|
||||
}
|
||||
@@ -101,7 +165,11 @@ void osgParticle::ParticleSystem::drawImplementation(osg::RenderInfo& renderInfo
|
||||
// update the frame count, so other objects can detect when
|
||||
// this particle system is culled
|
||||
_last_frame = state.getFrameStamp()->getFrameNumber();
|
||||
|
||||
|
||||
// update the dirty flag of delta time, so next time a new request for delta time
|
||||
// will automatically cause recomputing
|
||||
_dirty_dt = true;
|
||||
|
||||
// get the current modelview matrix
|
||||
osg::Matrix modelview = state.getModelViewMatrix();
|
||||
|
||||
@@ -113,7 +181,10 @@ void osgParticle::ParticleSystem::drawImplementation(osg::RenderInfo& renderInfo
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
// render, first pass
|
||||
single_pass_render(state, modelview);
|
||||
if (_useVertexArray)
|
||||
render_vertex_array(renderInfo);
|
||||
else
|
||||
single_pass_render(renderInfo, modelview);
|
||||
|
||||
#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE)
|
||||
// restore depth mask settings
|
||||
@@ -129,7 +200,10 @@ void osgParticle::ParticleSystem::drawImplementation(osg::RenderInfo& renderInfo
|
||||
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
||||
|
||||
// render the particles onto the depth buffer
|
||||
single_pass_render(state, modelview);
|
||||
if (_useVertexArray)
|
||||
render_vertex_array(renderInfo);
|
||||
else
|
||||
single_pass_render(renderInfo, modelview);
|
||||
|
||||
#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE)
|
||||
// restore color mask settings
|
||||
@@ -179,21 +253,109 @@ void osgParticle::ParticleSystem::setDefaultAttributes(const std::string& textur
|
||||
stateset->setAttributeAndModes(blend, osg::StateAttribute::ON);
|
||||
|
||||
setStateSet(stateset);
|
||||
setUseVertexArray(false);
|
||||
setUseShaders(false);
|
||||
}
|
||||
|
||||
|
||||
void osgParticle::ParticleSystem::single_pass_render(osg::State& state, const osg::Matrix& modelview) const
|
||||
void osgParticle::ParticleSystem::setDefaultAttributesUsingShaders(const std::string& texturefile, bool emissive_particles, int texture_unit)
|
||||
{
|
||||
osg::StateSet *stateset = new osg::StateSet;
|
||||
stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
|
||||
|
||||
osg::PointSprite *sprite = new osg::PointSprite;
|
||||
stateset->setTextureAttributeAndModes(texture_unit, sprite, osg::StateAttribute::ON);
|
||||
|
||||
#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE)
|
||||
stateset->setMode(GL_VERTEX_PROGRAM_POINT_SIZE, osg::StateAttribute::ON);
|
||||
#else
|
||||
OSG_NOTICE<<"Warning: ParticleSystem::setDefaultAttributesUsingShaders(..) not fully implemented."<<std::endl;
|
||||
#endif
|
||||
|
||||
if (!texturefile.empty())
|
||||
{
|
||||
osg::Texture2D *texture = new osg::Texture2D;
|
||||
texture->setImage(osgDB::readImageFile(texturefile));
|
||||
texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
|
||||
texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
|
||||
texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::MIRROR);
|
||||
texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::MIRROR);
|
||||
stateset->setTextureAttributeAndModes(texture_unit, texture, osg::StateAttribute::ON);
|
||||
}
|
||||
|
||||
osg::BlendFunc *blend = new osg::BlendFunc;
|
||||
if (emissive_particles)
|
||||
{
|
||||
blend->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
blend->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
stateset->setAttributeAndModes(blend, osg::StateAttribute::ON);
|
||||
|
||||
osg::Program *program = new osg::Program;
|
||||
#ifdef USE_LOCAL_SHADERS
|
||||
char vertexShaderSource[] =
|
||||
"uniform float visibilityDistance;\n"
|
||||
"varying vec3 basic_prop;\n"
|
||||
"\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" basic_prop = gl_MultiTexCoord0.xyz;\n"
|
||||
" \n"
|
||||
" vec4 ecPos = gl_ModelViewMatrix * gl_Vertex;\n"
|
||||
" float ecDepth = -ecPos.z;\n"
|
||||
" \n"
|
||||
" if (visibilityDistance > 0.0)\n"
|
||||
" {\n"
|
||||
" if (ecDepth <= 0.0 || ecDepth >= visibilityDistance)\n"
|
||||
" basic_prop.x = -1.0;\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
" gl_Position = ftransform();\n"
|
||||
" gl_ClipVertex = ecPos;\n"
|
||||
" \n"
|
||||
" vec4 color = gl_Color;\n"
|
||||
" color.a *= basic_prop.z;\n"
|
||||
" gl_FrontColor = color;\n"
|
||||
" gl_BackColor = gl_FrontColor;\n"
|
||||
"}\n";
|
||||
char fragmentShaderSource[] =
|
||||
"uniform sampler2D baseTexture;\n"
|
||||
"varying vec3 basic_prop;\n"
|
||||
"\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" if (basic_prop.x < 0.0) discard;\n"
|
||||
" gl_FragColor = gl_Color * texture2D(baseTexture, gl_TexCoord[0].xy);\n"
|
||||
"}\n";
|
||||
program->addShader(new osg::Shader(osg::Shader::VERTEX, vertexShaderSource));
|
||||
program->addShader(new osg::Shader(osg::Shader::FRAGMENT, fragmentShaderSource));
|
||||
#else
|
||||
program->addShader(osg::Shader::readShaderFile(osg::Shader::VERTEX, osgDB::findDataFile("shaders/particle.vert")));
|
||||
program->addShader(osg::Shader::readShaderFile(osg::Shader::FRAGMENT, osgDB::findDataFile("shaders/particle.frag")));
|
||||
#endif
|
||||
stateset->setAttributeAndModes(program, osg::StateAttribute::ON);
|
||||
|
||||
stateset->addUniform(new osg::Uniform("visibilityDistance", (float)_visibilityDistance));
|
||||
stateset->addUniform(new osg::Uniform("baseTexture", texture_unit));
|
||||
setStateSet(stateset);
|
||||
|
||||
setUseVertexArray(true);
|
||||
setUseShaders(true);
|
||||
}
|
||||
|
||||
|
||||
void osgParticle::ParticleSystem::single_pass_render(osg::RenderInfo& renderInfo, const osg::Matrix& modelview) const
|
||||
{
|
||||
_draw_count = 0;
|
||||
if (_particles.size() <= 0) return;
|
||||
|
||||
osg::GLBeginEndAdapter* gl = &state.getGLBeginEndAdapter();
|
||||
osg::GLBeginEndAdapter* gl = &(renderInfo.getState()->getGLBeginEndAdapter());
|
||||
|
||||
float scale = sqrtf(static_cast<float>(_detail));
|
||||
|
||||
const Particle* startParticle = &_particles[0];
|
||||
startParticle->beginRender(gl);
|
||||
|
||||
osg::Vec3 xAxis = _align_X_axis;
|
||||
osg::Vec3 yAxis = _align_Y_axis;
|
||||
|
||||
@@ -229,19 +391,55 @@ void osgParticle::ParticleSystem::single_pass_render(osg::State& state, const o
|
||||
yAxis *= yScale;
|
||||
}
|
||||
|
||||
bool requiresEndRender = false;
|
||||
const Particle* startParticle = &_particles[0];
|
||||
if (startParticle->getShape() != Particle::USER)
|
||||
{
|
||||
startParticle->beginRender(gl);
|
||||
requiresEndRender = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Enable writing depth mask when drawing user-defined particles
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
|
||||
for(unsigned int i=0; i<_particles.size(); i+=_detail)
|
||||
{
|
||||
const Particle* currentParticle = &_particles[i];
|
||||
if (currentParticle->isAlive())
|
||||
|
||||
bool insideDistance = true;
|
||||
if (_sortMode != NO_SORT && _visibilityDistance>0.0)
|
||||
insideDistance = (currentParticle->getDepth()>=0.0 && currentParticle->getDepth()<=_visibilityDistance);
|
||||
|
||||
if (currentParticle->isAlive() && insideDistance)
|
||||
{
|
||||
if (currentParticle->getShape() != startParticle->getShape())
|
||||
{
|
||||
startParticle->endRender(gl);
|
||||
currentParticle->beginRender(gl);
|
||||
startParticle = currentParticle;
|
||||
if (currentParticle->getShape() != Particle::USER)
|
||||
{
|
||||
currentParticle->beginRender(gl);
|
||||
requiresEndRender = true;
|
||||
glDepthMask(GL_FALSE);
|
||||
}
|
||||
else
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
++_draw_count;
|
||||
|
||||
if (currentParticle->getShape() == Particle::USER)
|
||||
{
|
||||
if (requiresEndRender)
|
||||
{
|
||||
startParticle->endRender(gl);
|
||||
requiresEndRender = false;
|
||||
}
|
||||
currentParticle->render(renderInfo, currentParticle->getPosition(), currentParticle->getAngle());
|
||||
continue;
|
||||
}
|
||||
|
||||
const osg::Vec3& angle = currentParticle->getAngle();
|
||||
bool requiresRotation = (angle.x()!=0.0f || angle.y()!=0.0f || angle.z()!=0.0f);
|
||||
if (requiresRotation)
|
||||
@@ -277,8 +475,40 @@ void osgParticle::ParticleSystem::single_pass_render(osg::State& state, const o
|
||||
}
|
||||
}
|
||||
|
||||
startParticle->endRender(gl);
|
||||
if (requiresEndRender)
|
||||
startParticle->endRender(gl);
|
||||
}
|
||||
|
||||
void osgParticle::ParticleSystem::render_vertex_array(osg::RenderInfo& renderInfo) const
|
||||
{
|
||||
if (_particles.size() <= 0) return;
|
||||
|
||||
// Compute the pointer and offsets
|
||||
Particle_vector::const_iterator itr = _particles.begin();
|
||||
float* ptr = (float*)(&(*itr));
|
||||
GLsizei stride = 0;
|
||||
if (_particles.size() > 1)
|
||||
{
|
||||
float* ptr1 = (float*)(&(*(itr+1)));
|
||||
stride = ptr1 - ptr;
|
||||
}
|
||||
GLsizei posOffset = (float*)(&(itr->_position)) - ptr; // Position
|
||||
GLsizei colorOffset = (float*)(&(itr->_current_color)) - ptr; // Color
|
||||
GLsizei velOffset = (float*)(&(itr->_velocity)) - ptr; // Velocity
|
||||
GLsizei propOffset = (float*)(&(itr->_base_prop)) - ptr; // Alive, size & alpha
|
||||
|
||||
// Draw particles as arrays
|
||||
osg::State& state = *renderInfo.getState();
|
||||
state.lazyDisablingOfVertexAttributes();
|
||||
state.setColorPointer(4, GL_FLOAT, stride * sizeof(float), ptr + colorOffset);
|
||||
state.setVertexPointer(3, GL_FLOAT, stride * sizeof(float), ptr + posOffset);
|
||||
if (_useShaders)
|
||||
{
|
||||
state.setNormalPointer(GL_FLOAT, stride * sizeof(float), ptr + velOffset);
|
||||
state.setTexCoordPointer(0, 3, GL_FLOAT, stride * sizeof(float), ptr + propOffset);
|
||||
}
|
||||
state.applyDisablingOfVertexAttributes();
|
||||
glDrawArrays(GL_POINTS, 0, _particles.size());
|
||||
}
|
||||
|
||||
osg::BoundingBox osgParticle::ParticleSystem::computeBound() const
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
#include <osgParticle/ParticleSystemUpdater>
|
||||
|
||||
#include <osg/CopyOp>
|
||||
#include <osg/Node>
|
||||
#include <osg/Geode>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
osgParticle::ParticleSystemUpdater::ParticleSystemUpdater()
|
||||
: osg::Node(), _t0(-1), _frameNumber(0)
|
||||
: osg::Geode(), _frameNumber(0)
|
||||
{
|
||||
setCullingActive(false);
|
||||
}
|
||||
|
||||
osgParticle::ParticleSystemUpdater::ParticleSystemUpdater(const ParticleSystemUpdater& copy, const osg::CopyOp& copyop)
|
||||
: osg::Node(copy, copyop), _t0(copy._t0), _frameNumber(0)
|
||||
: osg::Geode(copy, copyop), _frameNumber(0)
|
||||
{
|
||||
ParticleSystem_Vector::const_iterator i;
|
||||
for (i=copy._psv.begin(); i!=copy._psv.end(); ++i) {
|
||||
@@ -33,22 +33,18 @@ void osgParticle::ParticleSystemUpdater::traverse(osg::NodeVisitor& nv)
|
||||
_frameNumber = nv.getFrameStamp()->getFrameNumber();
|
||||
|
||||
double t = nv.getFrameStamp()->getSimulationTime();
|
||||
if (_t0 != -1.0)
|
||||
ParticleSystem_Vector::iterator i;
|
||||
for (i=_psv.begin(); i!=_psv.end(); ++i)
|
||||
{
|
||||
ParticleSystem_Vector::iterator i;
|
||||
for (i=_psv.begin(); i!=_psv.end(); ++i)
|
||||
{
|
||||
ParticleSystem* ps = i->get();
|
||||
|
||||
ParticleSystem::ScopedWriteLock lock(*(ps->getReadWriteMutex()));
|
||||
ParticleSystem* ps = i->get();
|
||||
|
||||
ParticleSystem::ScopedWriteLock lock(*(ps->getReadWriteMutex()));
|
||||
|
||||
if (!ps->isFrozen() && (ps->getLastFrameNumber() >= (nv.getFrameStamp()->getFrameNumber() - 1) || !ps->getFreezeOnCull()))
|
||||
{
|
||||
ps->update(t - _t0);
|
||||
}
|
||||
if (!ps->isFrozen() && (ps->getLastFrameNumber() >= (nv.getFrameStamp()->getFrameNumber() - 1) || !ps->getFreezeOnCull()))
|
||||
{
|
||||
ps->update(ps->getDeltaTime(t), nv);
|
||||
}
|
||||
}
|
||||
_t0 = t;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -58,17 +54,32 @@ void osgParticle::ParticleSystemUpdater::traverse(osg::NodeVisitor& nv)
|
||||
}
|
||||
|
||||
}
|
||||
Node::traverse(nv);
|
||||
Geode::traverse(nv);
|
||||
}
|
||||
|
||||
osg::BoundingSphere osgParticle::ParticleSystemUpdater::computeBound() const
|
||||
{
|
||||
return osg::BoundingSphere();
|
||||
return Geode::computeBound();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
_psv.push_back(ps);
|
||||
unsigned int i = getParticleSystemIndex( ps );
|
||||
if( i >= _psv.size() ) _psv.push_back(ps);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
116
src/osgParticle/SinkOperator.cpp
Normal file
116
src/osgParticle/SinkOperator.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
// Written by Wang Rui, (C) 2010
|
||||
|
||||
#include <osg/Notify>
|
||||
#include <osgParticle/ModularProgram>
|
||||
#include <osgParticle/SinkOperator>
|
||||
|
||||
#define SINK_EPSILON 1e-3
|
||||
|
||||
using namespace osgParticle;
|
||||
|
||||
void SinkOperator::beginOperate( Program* prg )
|
||||
{
|
||||
// Don't transform domains if they are used for sinking velocities
|
||||
if ( _sinkTarget==SINK_POSITION )
|
||||
DomainOperator::beginOperate(prg );
|
||||
}
|
||||
|
||||
void SinkOperator::handlePoint( const Domain& domain, Particle* P, double dt )
|
||||
{
|
||||
const osg::Vec3& value = getValue(P);
|
||||
kill( P, (domain.v1==value) );
|
||||
}
|
||||
|
||||
void SinkOperator::handleLineSegment( const Domain& domain, Particle* P, double dt )
|
||||
{
|
||||
const osg::Vec3& value = getValue(P);
|
||||
osg::Vec3 offset = value - domain.v1, normal = domain.v2 - domain.v1;
|
||||
normal.normalize();
|
||||
|
||||
float diff = fabs(normal*offset - offset.length()) / domain.r1;
|
||||
kill( P, (diff<SINK_EPSILON) );
|
||||
}
|
||||
|
||||
void SinkOperator::handleTriangle( const Domain& domain, Particle* P, double dt )
|
||||
{
|
||||
bool insideDomain = false;
|
||||
const osg::Vec3& value = getValue(P);
|
||||
osg::Vec3 offset = value - domain.v1;
|
||||
if ( offset*domain.plane.getNormal()>SINK_EPSILON )
|
||||
insideDomain = false;
|
||||
else
|
||||
{
|
||||
float upos = offset * domain.s1;
|
||||
float vpos = offset * domain.s2;
|
||||
insideDomain = !(upos<0.0f || vpos<0.0f || (upos+vpos)>1.0f);
|
||||
}
|
||||
kill( P, insideDomain );
|
||||
}
|
||||
|
||||
void SinkOperator::handleRectangle( const Domain& domain, Particle* P, double dt )
|
||||
{
|
||||
bool insideDomain = false;
|
||||
const osg::Vec3& value = getValue(P);
|
||||
osg::Vec3 offset = value - domain.v1;
|
||||
if ( offset*domain.plane.getNormal()>SINK_EPSILON )
|
||||
insideDomain = false;
|
||||
else
|
||||
{
|
||||
float upos = offset * domain.s1;
|
||||
float vpos = offset * domain.s2;
|
||||
insideDomain = !(upos<0.0f || upos>1.0f || vpos<0.0f || vpos>1.0f);
|
||||
}
|
||||
kill( P, insideDomain );
|
||||
}
|
||||
|
||||
void SinkOperator::handlePlane( const Domain& domain, Particle* P, double dt )
|
||||
{
|
||||
const osg::Vec3& value = getValue(P);
|
||||
bool insideDomain = (domain.plane.getNormal()*value>=-domain.plane[3]);
|
||||
kill( P, insideDomain );
|
||||
}
|
||||
|
||||
void SinkOperator::handleSphere( const Domain& domain, Particle* P, double dt )
|
||||
{
|
||||
const osg::Vec3& value = getValue(P);
|
||||
float r = (value - domain.v1).length();
|
||||
kill( P, (r<=domain.r1) );
|
||||
}
|
||||
|
||||
void SinkOperator::handleBox( const Domain& domain, Particle* P, double dt )
|
||||
{
|
||||
const osg::Vec3& value = getValue(P);
|
||||
bool insideDomain = !(
|
||||
(value.x() < domain.v1.x()) || (value.x() > domain.v2.x()) ||
|
||||
(value.y() < domain.v1.y()) || (value.y() > domain.v2.y()) ||
|
||||
(value.z() < domain.v1.z()) || (value.z() > domain.v2.z())
|
||||
);
|
||||
kill( P, insideDomain );
|
||||
}
|
||||
|
||||
void SinkOperator::handleDisk( const Domain& domain, Particle* P, double dt )
|
||||
{
|
||||
bool insideDomain = false;
|
||||
const osg::Vec3& value = getValue(P);
|
||||
osg::Vec3 offset = value - domain.v1;
|
||||
if ( offset*domain.v2>SINK_EPSILON )
|
||||
insideDomain = false;
|
||||
else
|
||||
{
|
||||
float length = offset.length();
|
||||
insideDomain = (length<=domain.r1 && length>=domain.r2);
|
||||
}
|
||||
kill( P, insideDomain );
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
|
||||
#include <osgParticle/AngularDampingOperator>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/Input>
|
||||
#include <osgDB/Output>
|
||||
|
||||
#include <osg/Vec3>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
bool AngularDampingOperator_readLocalData(osg::Object &obj, osgDB::Input &fr);
|
||||
bool AngularDampingOperator_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
|
||||
|
||||
REGISTER_DOTOSGWRAPPER(AngularDampingOperator_Proxy)
|
||||
(
|
||||
new osgParticle::AngularDampingOperator,
|
||||
"AngularDampingOperator",
|
||||
"Object Operator AngularDampingOperator",
|
||||
AngularDampingOperator_readLocalData,
|
||||
AngularDampingOperator_writeLocalData
|
||||
);
|
||||
|
||||
bool AngularDampingOperator_readLocalData(osg::Object &obj, osgDB::Input &fr)
|
||||
{
|
||||
osgParticle::AngularDampingOperator &adp = static_cast<osgParticle::AngularDampingOperator &>(obj);
|
||||
bool itAdvanced = false;
|
||||
|
||||
osg::Vec3 a;
|
||||
if (fr[0].matchWord("damping")) {
|
||||
if (fr[1].getFloat(a.x()) && fr[2].getFloat(a.y()) && fr[3].getFloat(a.z())) {
|
||||
adp.setDamping(a);
|
||||
fr += 4;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
float low = 0.0f, high = FLT_MAX;
|
||||
if (fr[0].matchWord("cutoff")) {
|
||||
if (fr[1].getFloat(low) && fr[2].getFloat(high)) {
|
||||
adp.setCutoff(low, high);
|
||||
fr += 3;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
return itAdvanced;
|
||||
}
|
||||
|
||||
bool AngularDampingOperator_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
|
||||
{
|
||||
const osgParticle::AngularDampingOperator &adp = static_cast<const osgParticle::AngularDampingOperator &>(obj);
|
||||
osg::Vec3 a = adp.getDamping();
|
||||
fw.indent() << "damping " << a.x() << " " << a.y() << " " << a.z() << std::endl;
|
||||
|
||||
float low = adp.getCutoffLow(), high = adp.getCutoffHigh();
|
||||
fw.indent() << "cutoff " << low << " " << high << std::endl;
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
|
||||
#include <osgParticle/BounceOperator>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/Input>
|
||||
#include <osgDB/Output>
|
||||
|
||||
#include <osg/Vec3>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
bool BounceOperator_readLocalData(osg::Object &obj, osgDB::Input &fr);
|
||||
bool BounceOperator_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
|
||||
|
||||
REGISTER_DOTOSGWRAPPER(BounceOperator_Proxy)
|
||||
(
|
||||
new osgParticle::BounceOperator,
|
||||
"BounceOperator",
|
||||
"Object Operator DomainOperator BounceOperator",
|
||||
BounceOperator_readLocalData,
|
||||
BounceOperator_writeLocalData
|
||||
);
|
||||
|
||||
bool BounceOperator_readLocalData(osg::Object &obj, osgDB::Input &fr)
|
||||
{
|
||||
osgParticle::BounceOperator &bp = static_cast<osgParticle::BounceOperator &>(obj);
|
||||
bool itAdvanced = false;
|
||||
|
||||
float value = 0.0f;
|
||||
if (fr[0].matchWord("friction")) {
|
||||
if (fr[1].getFloat(value)) {
|
||||
bp.setFriction(value);
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("resilience")) {
|
||||
if (fr[1].getFloat(value)) {
|
||||
bp.setResilience(value);
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("cutoff")) {
|
||||
if (fr[1].getFloat(value)) {
|
||||
bp.setCutoff(value);
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
return itAdvanced;
|
||||
}
|
||||
|
||||
bool BounceOperator_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
|
||||
{
|
||||
const osgParticle::BounceOperator &bp = static_cast<const osgParticle::BounceOperator &>(obj);
|
||||
fw.indent() << "friction " << bp.getFriction() << std::endl;
|
||||
fw.indent() << "resilience " << bp.getResilience() << std::endl;
|
||||
fw.indent() << "cutoff " << bp.getCutoff() << std::endl;
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
|
||||
#include <osgParticle/DampingOperator>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/Input>
|
||||
#include <osgDB/Output>
|
||||
|
||||
#include <osg/Vec3>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
bool DampingOperator_readLocalData(osg::Object &obj, osgDB::Input &fr);
|
||||
bool DampingOperator_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
|
||||
|
||||
REGISTER_DOTOSGWRAPPER(DampingOperator_Proxy)
|
||||
(
|
||||
new osgParticle::DampingOperator,
|
||||
"DampingOperator",
|
||||
"Object Operator DampingOperator",
|
||||
DampingOperator_readLocalData,
|
||||
DampingOperator_writeLocalData
|
||||
);
|
||||
|
||||
bool DampingOperator_readLocalData(osg::Object &obj, osgDB::Input &fr)
|
||||
{
|
||||
osgParticle::DampingOperator &dp = static_cast<osgParticle::DampingOperator &>(obj);
|
||||
bool itAdvanced = false;
|
||||
|
||||
osg::Vec3 a;
|
||||
if (fr[0].matchWord("damping")) {
|
||||
if (fr[1].getFloat(a.x()) && fr[2].getFloat(a.y()) && fr[3].getFloat(a.z())) {
|
||||
dp.setDamping(a);
|
||||
fr += 4;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
float low = 0.0f, high = FLT_MAX;
|
||||
if (fr[0].matchWord("cutoff")) {
|
||||
if (fr[1].getFloat(low) && fr[2].getFloat(high)) {
|
||||
dp.setCutoff(low, high);
|
||||
fr += 3;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
return itAdvanced;
|
||||
}
|
||||
|
||||
bool DampingOperator_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
|
||||
{
|
||||
const osgParticle::DampingOperator &dp = static_cast<const osgParticle::DampingOperator &>(obj);
|
||||
osg::Vec3 a = dp.getDamping();
|
||||
fw.indent() << "damping " << a.x() << " " << a.y() << " " << a.z() << std::endl;
|
||||
|
||||
float low = dp.getCutoffLow(), high = dp.getCutoffHigh();
|
||||
fw.indent() << "cutoff " << low << " " << high << std::endl;
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
|
||||
#include <osgParticle/DomainOperator>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/Input>
|
||||
#include <osgDB/Output>
|
||||
|
||||
#include <osg/Vec3>
|
||||
#include <osg/io_utils>
|
||||
#include <iostream>
|
||||
|
||||
bool DomainOperator_readLocalData(osg::Object &obj, osgDB::Input &fr);
|
||||
bool DomainOperator_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
|
||||
|
||||
REGISTER_DOTOSGWRAPPER(DomainOperator_Proxy)
|
||||
(
|
||||
new osgParticle::DomainOperator,
|
||||
"DomainOperator",
|
||||
"Object Operator DomainOperator",
|
||||
DomainOperator_readLocalData,
|
||||
DomainOperator_writeLocalData
|
||||
);
|
||||
|
||||
bool DomainOperator_readLocalData(osg::Object &obj, osgDB::Input &fr)
|
||||
{
|
||||
osgParticle::DomainOperator &dp = static_cast<osgParticle::DomainOperator &>(obj);
|
||||
bool itAdvanced = false;
|
||||
|
||||
std::string typeName;
|
||||
while (fr.matchSequence("domain %s {"))
|
||||
{
|
||||
if (fr[1].getStr()) typeName = fr[1].getStr();
|
||||
fr += 3;
|
||||
|
||||
osgParticle::DomainOperator::Domain::Type type = osgParticle::DomainOperator::Domain::UNDEFINED_DOMAIN;
|
||||
if (typeName == "point") type = osgParticle::DomainOperator::Domain::POINT_DOMAIN;
|
||||
else if (typeName == "line") type = osgParticle::DomainOperator::Domain::LINE_DOMAIN;
|
||||
else if (typeName == "triangle") type = osgParticle::DomainOperator::Domain::TRI_DOMAIN;
|
||||
else if (typeName == "rectangle") type = osgParticle::DomainOperator::Domain::RECT_DOMAIN;
|
||||
else if (typeName == "plane") type = osgParticle::DomainOperator::Domain::PLANE_DOMAIN;
|
||||
else if (typeName == "sphere") type = osgParticle::DomainOperator::Domain::SPHERE_DOMAIN;
|
||||
else if (typeName == "box") type = osgParticle::DomainOperator::Domain::BOX_DOMAIN;
|
||||
else if (typeName == "disk") type = osgParticle::DomainOperator::Domain::DISK_DOMAIN;
|
||||
|
||||
osgParticle::DomainOperator::Domain domain(type);
|
||||
if (fr[0].matchWord("plane")) {
|
||||
if (fr[1].getFloat(domain.plane[0]) && fr[2].getFloat(domain.plane[1]) &&
|
||||
fr[3].getFloat(domain.plane[2]) && fr[4].getFloat(domain.plane[3]))
|
||||
{
|
||||
fr += 5;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("vertices1")) {
|
||||
if (fr[1].getFloat(domain.v1[0]) && fr[2].getFloat(domain.v1[1]) && fr[3].getFloat(domain.v1[2]))
|
||||
{
|
||||
fr += 4;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("vertices2")) {
|
||||
if (fr[1].getFloat(domain.v2[0]) && fr[2].getFloat(domain.v2[1]) && fr[3].getFloat(domain.v2[2]))
|
||||
{
|
||||
fr += 4;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("vertices3")) {
|
||||
if (fr[1].getFloat(domain.v3[0]) && fr[2].getFloat(domain.v3[1]) && fr[3].getFloat(domain.v3[2]))
|
||||
{
|
||||
fr += 4;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("basis1")) {
|
||||
if (fr[1].getFloat(domain.s1[0]) && fr[2].getFloat(domain.s1[1]) && fr[3].getFloat(domain.s1[2]))
|
||||
{
|
||||
fr += 4;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("basis2")) {
|
||||
if (fr[1].getFloat(domain.s2[0]) && fr[2].getFloat(domain.s2[1]) && fr[3].getFloat(domain.s2[2]))
|
||||
{
|
||||
fr += 4;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("factors")) {
|
||||
if (fr[1].getFloat(domain.r1) && fr[2].getFloat(domain.r2))
|
||||
{
|
||||
fr += 3;
|
||||
}
|
||||
}
|
||||
dp.addDomain(domain);
|
||||
|
||||
++fr;
|
||||
itAdvanced = true;
|
||||
}
|
||||
return itAdvanced;
|
||||
}
|
||||
|
||||
bool DomainOperator_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
|
||||
{
|
||||
const osgParticle::DomainOperator &dp = static_cast<const osgParticle::DomainOperator &>(obj);
|
||||
|
||||
for(unsigned int i=0;i<dp.getNumDomains();++i)
|
||||
{
|
||||
const osgParticle::DomainOperator::Domain& domain = dp.getDomain(i);
|
||||
|
||||
switch (domain.type)
|
||||
{
|
||||
case osgParticle::DomainOperator::Domain::POINT_DOMAIN:
|
||||
fw.indent() << "domain point {" << std::endl; break;
|
||||
case osgParticle::DomainOperator::Domain::LINE_DOMAIN:
|
||||
fw.indent() << "domain line {" << std::endl; break;
|
||||
case osgParticle::DomainOperator::Domain::TRI_DOMAIN:
|
||||
fw.indent() << "domain triangle {" << std::endl; break;
|
||||
case osgParticle::DomainOperator::Domain::RECT_DOMAIN:
|
||||
fw.indent() << "domain rectangle {" << std::endl; break;
|
||||
case osgParticle::DomainOperator::Domain::PLANE_DOMAIN:
|
||||
fw.indent() << "domain plane {" << std::endl; break;
|
||||
case osgParticle::DomainOperator::Domain::SPHERE_DOMAIN:
|
||||
fw.indent() << "domain sphere {" << std::endl; break;
|
||||
case osgParticle::DomainOperator::Domain::BOX_DOMAIN:
|
||||
fw.indent() << "domain box {" << std::endl; break;
|
||||
case osgParticle::DomainOperator::Domain::DISK_DOMAIN:
|
||||
fw.indent() << "domain disk {" << std::endl; break;
|
||||
default:
|
||||
fw.indent() << "domain undefined {" << std::endl; break;
|
||||
}
|
||||
|
||||
fw.moveIn();
|
||||
fw.indent() << "plane " << domain.plane << std::endl;
|
||||
fw.indent() << "vertices1 " << domain.v1 << std::endl;
|
||||
fw.indent() << "vertices2 " << domain.v2 << std::endl;
|
||||
fw.indent() << "vertices3 " << domain.v3 << std::endl;
|
||||
fw.indent() << "basis1 " << domain.s1 << std::endl;
|
||||
fw.indent() << "basis2 " << domain.s2 << std::endl;
|
||||
fw.indent() << "factors " << domain.r1 << " " << domain.r2 << std::endl;
|
||||
|
||||
fw.moveOut();
|
||||
fw.indent() << "}" << std::endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
|
||||
#include <osgParticle/ExplosionOperator>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/Input>
|
||||
#include <osgDB/Output>
|
||||
|
||||
#include <osg/Vec3>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
bool ExplosionOperator_readLocalData(osg::Object &obj, osgDB::Input &fr);
|
||||
bool ExplosionOperator_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
|
||||
|
||||
REGISTER_DOTOSGWRAPPER(ExplosionOperator_Proxy)
|
||||
(
|
||||
new osgParticle::ExplosionOperator,
|
||||
"ExplosionOperator",
|
||||
"Object Operator ExplosionOperator",
|
||||
ExplosionOperator_readLocalData,
|
||||
ExplosionOperator_writeLocalData
|
||||
);
|
||||
|
||||
bool ExplosionOperator_readLocalData(osg::Object &obj, osgDB::Input &fr)
|
||||
{
|
||||
osgParticle::ExplosionOperator &ep = static_cast<osgParticle::ExplosionOperator &>(obj);
|
||||
bool itAdvanced = false;
|
||||
|
||||
osg::Vec3 a;
|
||||
if (fr[0].matchWord("center")) {
|
||||
if (fr[1].getFloat(a.x()) && fr[2].getFloat(a.y()) && fr[3].getFloat(a.z())) {
|
||||
ep.setCenter(a);
|
||||
fr += 4;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
float value = 0.0f;
|
||||
if (fr[0].matchWord("radius")) {
|
||||
if (fr[1].getFloat(value)) {
|
||||
ep.setRadius(value);
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("magnitude")) {
|
||||
if (fr[1].getFloat(value)) {
|
||||
ep.setMagnitude(value);
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("epsilon")) {
|
||||
if (fr[1].getFloat(value)) {
|
||||
ep.setEpsilon(value);
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("sigma")) {
|
||||
if (fr[1].getFloat(value)) {
|
||||
ep.setSigma(value);
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
return itAdvanced;
|
||||
}
|
||||
|
||||
bool ExplosionOperator_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
|
||||
{
|
||||
const osgParticle::ExplosionOperator &ep = static_cast<const osgParticle::ExplosionOperator &>(obj);
|
||||
osg::Vec3 a = ep.getCenter();
|
||||
fw.indent() << "center " << a.x() << " " << a.y() << " " << a.z() << std::endl;
|
||||
|
||||
fw.indent() << "radius " << ep.getRadius() << std::endl;
|
||||
fw.indent() << "magnitude " << ep.getMagnitude() << std::endl;
|
||||
fw.indent() << "epsilon " << ep.getEpsilon() << std::endl;
|
||||
fw.indent() << "sigma " << ep.getSigma() << std::endl;
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
|
||||
#include <osgParticle/OrbitOperator>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/Input>
|
||||
#include <osgDB/Output>
|
||||
|
||||
#include <osg/Vec3>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
bool OrbitOperator_readLocalData(osg::Object &obj, osgDB::Input &fr);
|
||||
bool OrbitOperator_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
|
||||
|
||||
REGISTER_DOTOSGWRAPPER(OrbitOperator_Proxy)
|
||||
(
|
||||
new osgParticle::OrbitOperator,
|
||||
"OrbitOperator",
|
||||
"Object Operator OrbitOperator",
|
||||
OrbitOperator_readLocalData,
|
||||
OrbitOperator_writeLocalData
|
||||
);
|
||||
|
||||
bool OrbitOperator_readLocalData(osg::Object &obj, osgDB::Input &fr)
|
||||
{
|
||||
osgParticle::OrbitOperator &op = static_cast<osgParticle::OrbitOperator &>(obj);
|
||||
bool itAdvanced = false;
|
||||
|
||||
osg::Vec3 a;
|
||||
if (fr[0].matchWord("center")) {
|
||||
if (fr[1].getFloat(a.x()) && fr[2].getFloat(a.y()) && fr[3].getFloat(a.z())) {
|
||||
op.setCenter(a);
|
||||
fr += 4;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
float value = 0.0f;
|
||||
if (fr[0].matchWord("magnitude")) {
|
||||
if (fr[1].getFloat(value)) {
|
||||
op.setMagnitude(value);
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("epsilon")) {
|
||||
if (fr[1].getFloat(value)) {
|
||||
op.setEpsilon(value);
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("maxRadius")) {
|
||||
if (fr[1].getFloat(value)) {
|
||||
op.setMaxRadius(value);
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
return itAdvanced;
|
||||
}
|
||||
|
||||
bool OrbitOperator_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
|
||||
{
|
||||
const osgParticle::OrbitOperator &op = static_cast<const osgParticle::OrbitOperator &>(obj);
|
||||
osg::Vec3 a = op.getCenter();
|
||||
fw.indent() << "center " << a.x() << " " << a.y() << " " << a.z() << std::endl;
|
||||
|
||||
fw.indent() << "magnitude " << op.getMagnitude() << std::endl;
|
||||
fw.indent() << "epsilon " << op.getEpsilon() << std::endl;
|
||||
fw.indent() << "maxRadius " << op.getMaxRadius() << std::endl;
|
||||
return true;
|
||||
}
|
||||
@@ -34,6 +34,8 @@ bool read_particle(osgDB::Input &fr, osgParticle::Particle &P)
|
||||
P.setShape(osgParticle::Particle::QUAD_TRIANGLESTRIP);
|
||||
} else if (std::string(ptstr) == "LINE") {
|
||||
P.setShape(osgParticle::Particle::LINE);
|
||||
} else if (std::string(ptstr) == "USER") {
|
||||
P.setShape(osgParticle::Particle::USER);
|
||||
} else {
|
||||
osg::notify(osg::WARN) << "Particle reader warning: invalid shape: " << ptstr << std::endl;
|
||||
}
|
||||
@@ -163,6 +165,15 @@ bool read_particle(osgDB::Input &fr, osgParticle::Particle &P)
|
||||
}
|
||||
++fr;
|
||||
}
|
||||
if (fr[0].matchWord("drawable") && fr[1].matchString("{")) {
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
osg::Drawable *drawable = dynamic_cast<osg::Drawable *>(fr.readObject());
|
||||
if (drawable) {
|
||||
P.setDrawable(drawable);
|
||||
}
|
||||
++fr;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -181,8 +192,9 @@ void write_particle(const osgParticle::Particle &P, osgDB::Output &fw)
|
||||
case osgParticle::Particle::HEXAGON: fw << "HEXAGON" << std::endl; break;
|
||||
case osgParticle::Particle::QUAD_TRIANGLESTRIP: fw << "QUAD_TRIANGLESTRIP" << std::endl; break;
|
||||
case osgParticle::Particle::QUAD: fw << "QUAD" << std::endl; break;
|
||||
case osgParticle::Particle::LINE:
|
||||
default: fw << "LINE" << std::endl; break;
|
||||
case osgParticle::Particle::LINE: fw << "LINE" << std::endl; break;
|
||||
case osgParticle::Particle::USER:
|
||||
default: fw << "USER" << std::endl; break;
|
||||
}
|
||||
|
||||
fw.indent() << "lifeTime " << P.getLifeTime() << std::endl;
|
||||
@@ -237,6 +249,12 @@ void write_particle(const osgParticle::Particle &P, osgDB::Output &fw)
|
||||
fw.writeObject(*P.getColorInterpolator());
|
||||
fw.moveOut();
|
||||
fw.indent() << "}" << std::endl;
|
||||
|
||||
fw.indent() << "drawable {" << std::endl;
|
||||
fw.moveIn();
|
||||
fw.writeObject(*P.getDrawable());
|
||||
fw.moveOut();
|
||||
fw.indent() << "}" << std::endl;
|
||||
|
||||
fw.moveOut();
|
||||
fw.indent() << "}" << std::endl;
|
||||
|
||||
@@ -74,6 +74,30 @@ bool ParticleSystem_readLocalData(osg::Object &obj, osgDB::Input &fr)
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("useVertexArray")) {
|
||||
if (fr[1].matchWord("TRUE")) {
|
||||
myobj.setUseVertexArray(true);
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
} else if (fr[1].matchWord("FALSE")) {
|
||||
myobj.setUseVertexArray(false);
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("useShaders")) {
|
||||
if (fr[1].matchWord("TRUE")) {
|
||||
myobj.setUseShaders(true);
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
} else if (fr[1].matchWord("FALSE")) {
|
||||
myobj.setUseShaders(false);
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("doublePassRendering")) {
|
||||
if (fr[1].matchWord("TRUE")) {
|
||||
myobj.setDoublePassRendering(true);
|
||||
@@ -124,6 +148,33 @@ bool ParticleSystem_readLocalData(osg::Object &obj, osgDB::Input &fr)
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("sortMode")) {
|
||||
if (fr[1].matchWord("NO_SORT")) {
|
||||
myobj.setSortMode(osgParticle::ParticleSystem::NO_SORT);
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
}
|
||||
if (fr[1].matchWord("SORT_FRONT_TO_BACK")) {
|
||||
myobj.setSortMode(osgParticle::ParticleSystem::SORT_FRONT_TO_BACK);
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
}
|
||||
if (fr[1].matchWord("SORT_BACK_TO_FRONT")) {
|
||||
myobj.setSortMode(osgParticle::ParticleSystem::SORT_BACK_TO_FRONT);
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("visibilityDistance")) {
|
||||
double distance;
|
||||
if (fr[1].getFloat(distance)) {
|
||||
myobj.setVisibilityDistance(distance);
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("particleTemplate")) {
|
||||
++fr;
|
||||
itAdvanced = true;
|
||||
@@ -167,6 +218,18 @@ bool ParticleSystem_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
|
||||
v = myobj.getAlignVectorY();
|
||||
fw.indent() << "alignVectorY " << v.x() << " " << v.y() << " " << v.z() << std::endl;
|
||||
|
||||
fw.indent() << "useVertexArray ";
|
||||
if (myobj.getUseVertexArray())
|
||||
fw << "TRUE" << std::endl;
|
||||
else
|
||||
fw << "FALSE" << std::endl;
|
||||
|
||||
fw.indent() << "useShaders ";
|
||||
if (myobj.getUseShaders())
|
||||
fw << "TRUE" << std::endl;
|
||||
else
|
||||
fw << "FALSE" << std::endl;
|
||||
|
||||
fw.indent() << "doublePassRendering ";
|
||||
if (myobj.getDoublePassRendering())
|
||||
fw << "TRUE" << std::endl;
|
||||
@@ -190,8 +253,23 @@ bool ParticleSystem_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
|
||||
fw << bbox.xMin() << " " << bbox.yMin() << " " << bbox.zMin() << " ";
|
||||
fw << bbox.xMax() << " " << bbox.yMax() << " " << bbox.zMax() << std::endl;
|
||||
|
||||
fw.indent() << "sortMode ";
|
||||
switch (myobj.getSortMode()) {
|
||||
default:
|
||||
case osgParticle::ParticleSystem::NO_SORT:
|
||||
fw << "NO_SORT" << std::endl;
|
||||
break;
|
||||
case osgParticle::ParticleSystem::SORT_FRONT_TO_BACK:
|
||||
fw << "SORT_FRONT_TO_BACK" << std::endl;
|
||||
break;
|
||||
case osgParticle::ParticleSystem::SORT_BACK_TO_FRONT:
|
||||
fw << "SORT_BACK_TO_FRONT" << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
fw.indent() << "visibilityDistance " << myobj.getVisibilityDistance() << std::endl;
|
||||
|
||||
fw.indent() << "particleTemplate ";
|
||||
write_particle(myobj.getDefaultParticleTemplate(), fw);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ REGISTER_DOTOSGWRAPPER(PSU_Proxy)
|
||||
(
|
||||
new osgParticle::ParticleSystemUpdater,
|
||||
"ParticleSystemUpdater",
|
||||
"Object Node ParticleSystemUpdater",
|
||||
"Object Node Geode ParticleSystemUpdater",
|
||||
PSU_readLocalData,
|
||||
PSU_writeLocalData
|
||||
);
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
|
||||
#include <osgParticle/SinkOperator>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/Input>
|
||||
#include <osgDB/Output>
|
||||
|
||||
#include <osg/Vec3>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
bool SinkOperator_readLocalData(osg::Object &obj, osgDB::Input &fr);
|
||||
bool SinkOperator_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
|
||||
|
||||
REGISTER_DOTOSGWRAPPER(SinkOperator_Proxy)
|
||||
(
|
||||
new osgParticle::SinkOperator,
|
||||
"SinkOperator",
|
||||
"Object Operator DomainOperator SinkOperator",
|
||||
SinkOperator_readLocalData,
|
||||
SinkOperator_writeLocalData
|
||||
);
|
||||
|
||||
bool SinkOperator_readLocalData(osg::Object &obj, osgDB::Input &fr)
|
||||
{
|
||||
osgParticle::SinkOperator &sp = static_cast<osgParticle::SinkOperator &>(obj);
|
||||
bool itAdvanced = false;
|
||||
|
||||
if (fr[0].matchWord("sinkTarget")) {
|
||||
const char *ptstr = fr[1].getStr();
|
||||
if (ptstr) {
|
||||
std::string str(ptstr);
|
||||
if (str == "position")
|
||||
sp.setSinkTarget(osgParticle::SinkOperator::SINK_POSITION);
|
||||
else if (str == "velocity")
|
||||
sp.setSinkTarget(osgParticle::SinkOperator::SINK_VELOCITY);
|
||||
else if (str == "angular_velocity")
|
||||
sp.setSinkTarget(osgParticle::SinkOperator::SINK_ANGULAR_VELOCITY);
|
||||
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fr[0].matchWord("sinkStrategy")) {
|
||||
const char *ptstr = fr[1].getStr();
|
||||
if (ptstr) {
|
||||
std::string str(ptstr);
|
||||
if (str == "inside")
|
||||
sp.setSinkStrategy(osgParticle::SinkOperator::SINK_INSIDE);
|
||||
else if (str == "outside")
|
||||
sp.setSinkStrategy(osgParticle::SinkOperator::SINK_OUTSIDE);
|
||||
|
||||
fr += 2;
|
||||
itAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
return itAdvanced;
|
||||
}
|
||||
|
||||
bool SinkOperator_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
|
||||
{
|
||||
const osgParticle::SinkOperator &sp = static_cast<const osgParticle::SinkOperator &>(obj);
|
||||
|
||||
fw.indent() << "sinkTarget ";
|
||||
switch (sp.getSinkTarget())
|
||||
{
|
||||
case osgParticle::SinkOperator::SINK_POSITION:
|
||||
fw << "position" << std::endl; break;
|
||||
case osgParticle::SinkOperator::SINK_VELOCITY:
|
||||
fw << "velocity" << std::endl; break;
|
||||
case osgParticle::SinkOperator::SINK_ANGULAR_VELOCITY:
|
||||
fw << "angular_velocity" << std::endl; break;
|
||||
default:
|
||||
fw << "undefined" << std::endl; break;
|
||||
}
|
||||
|
||||
fw.indent() << "sinkStrategy ";
|
||||
switch (sp.getSinkStrategy())
|
||||
{
|
||||
case osgParticle::SinkOperator::SINK_INSIDE:
|
||||
fw << "inside" << std::endl; break;
|
||||
case osgParticle::SinkOperator::SINK_OUTSIDE:
|
||||
fw << "outside" << std::endl; break;
|
||||
default:
|
||||
fw << "undefined" << std::endl; break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#include <osgParticle/AngularDampingOperator>
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( osgParticleAngularDampingOperator,
|
||||
new osgParticle::AngularDampingOperator,
|
||||
osgParticle::AngularDampingOperator,
|
||||
"osg::Object osgParticle::Operator osgParticle::AngularDampingOperator" )
|
||||
{
|
||||
ADD_VEC3_SERIALIZER( Damping, osg::Vec3() ); // _damping
|
||||
ADD_FLOAT_SERIALIZER( CutoffLow, 0.0f ); // _cutoffLow
|
||||
ADD_FLOAT_SERIALIZER( CutoffHigh, FLT_MAX ); // _cutoffHigh
|
||||
}
|
||||
14
src/osgWrappers/serializers/osgParticle/BounceOperator.cpp
Normal file
14
src/osgWrappers/serializers/osgParticle/BounceOperator.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <osgParticle/BounceOperator>
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( osgParticleBounceOperator,
|
||||
new osgParticle::BounceOperator,
|
||||
osgParticle::BounceOperator,
|
||||
"osg::Object osgParticle::Operator osgParticle::DomainOperator osgParticle::BounceOperator" )
|
||||
{
|
||||
ADD_FLOAT_SERIALIZER( Friction, 1.0f ); // _friction
|
||||
ADD_FLOAT_SERIALIZER( Resilience, 0.0f ); // _resilience
|
||||
ADD_FLOAT_SERIALIZER( Cutoff, 0.0f ); // _cutoff
|
||||
}
|
||||
14
src/osgWrappers/serializers/osgParticle/DampingOperator.cpp
Normal file
14
src/osgWrappers/serializers/osgParticle/DampingOperator.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <osgParticle/DampingOperator>
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( osgParticleDampingOperator,
|
||||
new osgParticle::DampingOperator,
|
||||
osgParticle::DampingOperator,
|
||||
"osg::Object osgParticle::Operator osgParticle::DampingOperator" )
|
||||
{
|
||||
ADD_VEC3_SERIALIZER( Damping, osg::Vec3() ); // _damping
|
||||
ADD_FLOAT_SERIALIZER( CutoffLow, 0.0f ); // _cutoffLow
|
||||
ADD_FLOAT_SERIALIZER( CutoffHigh, FLT_MAX ); // _cutoffHigh
|
||||
}
|
||||
94
src/osgWrappers/serializers/osgParticle/DomainOperator.cpp
Normal file
94
src/osgWrappers/serializers/osgParticle/DomainOperator.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
#include <osgParticle/DomainOperator>
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
static bool checkDomains( const osgParticle::DomainOperator& dp )
|
||||
{
|
||||
return dp.getNumDomains()>0;
|
||||
}
|
||||
|
||||
static bool readDomains( osgDB::InputStream& is, osgParticle::DomainOperator& dp )
|
||||
{
|
||||
osgParticle::DomainOperator::Domain::Type type = osgParticle::DomainOperator::Domain::UNDEFINED_DOMAIN;
|
||||
unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET;
|
||||
for ( unsigned int i=0; i<size; ++i )
|
||||
{
|
||||
std::string typeName;
|
||||
is >> osgDB::PROPERTY("Domain") >> typeName >> osgDB::BEGIN_BRACKET;
|
||||
if (typeName=="POINT") type = osgParticle::DomainOperator::Domain::POINT_DOMAIN;
|
||||
else if (typeName=="LINE") type = osgParticle::DomainOperator::Domain::LINE_DOMAIN;
|
||||
else if (typeName=="TRIANGLE") type = osgParticle::DomainOperator::Domain::TRI_DOMAIN;
|
||||
else if (typeName=="RECTANGLE") type = osgParticle::DomainOperator::Domain::RECT_DOMAIN;
|
||||
else if (typeName=="PLANE") type = osgParticle::DomainOperator::Domain::PLANE_DOMAIN;
|
||||
else if (typeName=="SPHERE") type = osgParticle::DomainOperator::Domain::SPHERE_DOMAIN;
|
||||
else if (typeName=="BOX") type = osgParticle::DomainOperator::Domain::BOX_DOMAIN;
|
||||
else if (typeName=="DISK") type = osgParticle::DomainOperator::Domain::DISK_DOMAIN;
|
||||
|
||||
osgParticle::DomainOperator::Domain domain(type);
|
||||
is >> osgDB::PROPERTY("Plane") >> domain.plane;
|
||||
is >> osgDB::PROPERTY("Vertices1") >> domain.v1;
|
||||
is >> osgDB::PROPERTY("Vertices2") >> domain.v2;
|
||||
is >> osgDB::PROPERTY("Vertices3") >> domain.v3;
|
||||
is >> osgDB::PROPERTY("Basis1") >> domain.s1;
|
||||
is >> osgDB::PROPERTY("Basis2") >> domain.s2;
|
||||
is >> osgDB::PROPERTY("Factors") >> domain.r1 >> domain.r2;
|
||||
dp.addDomain(domain);
|
||||
|
||||
is >> osgDB::END_BRACKET;
|
||||
}
|
||||
is >> osgDB::END_BRACKET;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool writeDomains( osgDB::OutputStream& os, const osgParticle::DomainOperator& dp )
|
||||
{
|
||||
unsigned int size = dp.getNumDomains();
|
||||
os << size << osgDB::BEGIN_BRACKET << std::endl;
|
||||
for ( unsigned int i=0; i<size; ++i )
|
||||
{
|
||||
const osgParticle::DomainOperator::Domain& domain = dp.getDomain(i);
|
||||
|
||||
os << osgDB::PROPERTY("Domain");
|
||||
switch (domain.type)
|
||||
{
|
||||
case osgParticle::DomainOperator::Domain::POINT_DOMAIN:
|
||||
os << std::string("POINT") << osgDB::BEGIN_BRACKET << std::endl; break;
|
||||
case osgParticle::DomainOperator::Domain::LINE_DOMAIN:
|
||||
os << std::string("LINE") << osgDB::BEGIN_BRACKET << std::endl; break;
|
||||
case osgParticle::DomainOperator::Domain::TRI_DOMAIN:
|
||||
os << std::string("TRIANGLE") << osgDB::BEGIN_BRACKET << std::endl; break;
|
||||
case osgParticle::DomainOperator::Domain::RECT_DOMAIN:
|
||||
os << std::string("RECTANGLE") << osgDB::BEGIN_BRACKET << std::endl; break;
|
||||
case osgParticle::DomainOperator::Domain::PLANE_DOMAIN:
|
||||
os << std::string("PLANE") << osgDB::BEGIN_BRACKET << std::endl; break;
|
||||
case osgParticle::DomainOperator::Domain::SPHERE_DOMAIN:
|
||||
os << std::string("SPHERE") << osgDB::BEGIN_BRACKET << std::endl; break;
|
||||
case osgParticle::DomainOperator::Domain::BOX_DOMAIN:
|
||||
os << std::string("BOX") << osgDB::BEGIN_BRACKET << std::endl; break;
|
||||
case osgParticle::DomainOperator::Domain::DISK_DOMAIN:
|
||||
os << std::string("DISK") << osgDB::BEGIN_BRACKET << std::endl; break;
|
||||
default:
|
||||
os << std::string("UNDEFINED") << osgDB::BEGIN_BRACKET << std::endl; break;
|
||||
}
|
||||
|
||||
os << osgDB::PROPERTY("Plane") << domain.plane << std::endl;
|
||||
os << osgDB::PROPERTY("Vertices1") << domain.v1 << std::endl;
|
||||
os << osgDB::PROPERTY("Vertices2") << domain.v2 << std::endl;
|
||||
os << osgDB::PROPERTY("Vertices3") << domain.v3 << std::endl;
|
||||
os << osgDB::PROPERTY("Basis1") << domain.s1 << std::endl;
|
||||
os << osgDB::PROPERTY("Basis2") << domain.s2 << std::endl;
|
||||
os << osgDB::PROPERTY("Factors") << domain.r1 << domain.r2 << std::endl;
|
||||
os << osgDB::END_BRACKET << std::endl;
|
||||
}
|
||||
os << osgDB::END_BRACKET << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( osgParticleDomainOperator,
|
||||
new osgParticle::DomainOperator,
|
||||
osgParticle::DomainOperator,
|
||||
"osg::Object osgParticle::Operator osgParticle::DomainOperator" )
|
||||
{
|
||||
ADD_USER_SERIALIZER( Domains ); // _placers
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#include <osgParticle/ExplosionOperator>
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( osgParticleExplosionOperator,
|
||||
new osgParticle::ExplosionOperator,
|
||||
osgParticle::ExplosionOperator,
|
||||
"osg::Object osgParticle::Operator osgParticle::ExplosionOperator" )
|
||||
{
|
||||
ADD_VEC3_SERIALIZER( Center, osg::Vec3() ); // _center
|
||||
ADD_FLOAT_SERIALIZER( Radius, 1.0f ); // _radius
|
||||
ADD_FLOAT_SERIALIZER( Magnitude, 1.0f ); // _magnitude
|
||||
ADD_FLOAT_SERIALIZER( Epsilon, 1e-3 ); // _epsilon
|
||||
ADD_FLOAT_SERIALIZER( Sigma, 1.0f ); // _sigma
|
||||
}
|
||||
15
src/osgWrappers/serializers/osgParticle/OrbitOperator.cpp
Normal file
15
src/osgWrappers/serializers/osgParticle/OrbitOperator.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <osgParticle/OrbitOperator>
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( osgParticleOrbitOperator,
|
||||
new osgParticle::OrbitOperator,
|
||||
osgParticle::OrbitOperator,
|
||||
"osg::Object osgParticle::Operator osgParticle::OrbitOperator" )
|
||||
{
|
||||
ADD_VEC3_SERIALIZER( Center, osg::Vec3() ); // _center
|
||||
ADD_FLOAT_SERIALIZER( Magnitude, 1.0f ); // _magnitude
|
||||
ADD_FLOAT_SERIALIZER( Epsilon, 1e-3 ); // _epsilon
|
||||
ADD_FLOAT_SERIALIZER( MaxRadius, FLT_MAX ); // _maxRadius
|
||||
}
|
||||
@@ -9,6 +9,7 @@ BEGIN_USER_TABLE( Shape, osgParticle::Particle );
|
||||
ADD_USER_VALUE( QUAD_TRIANGLESTRIP );
|
||||
ADD_USER_VALUE( HEXAGON );
|
||||
ADD_USER_VALUE( LINE );
|
||||
ADD_USER_VALUE( USER );
|
||||
END_USER_TABLE()
|
||||
|
||||
USER_READ_FUNC( Shape, readShapeValue )
|
||||
@@ -68,6 +69,14 @@ bool readParticle( osgDB::InputStream& is, osgParticle::Particle& p )
|
||||
p.setAngularVelocity( angleV );
|
||||
p.setTextureTile( s, t, num );
|
||||
|
||||
bool hasObject = false; is >> osgDB::PROPERTY("Drawable") >> hasObject;
|
||||
if ( hasObject )
|
||||
{
|
||||
is >> osgDB::BEGIN_BRACKET;
|
||||
p.setDrawable( dynamic_cast<osg::Drawable*>(is.readObject()) );
|
||||
is >> osgDB::END_BRACKET;
|
||||
}
|
||||
|
||||
is >> osgDB::END_BRACKET;
|
||||
return true;
|
||||
}
|
||||
@@ -102,6 +111,15 @@ bool writeParticle( osgDB::OutputStream& os, const osgParticle::Particle& p )
|
||||
os << osgDB::PROPERTY("AngularVelocity") << osg::Vec3d(p.getAngularVelocity()) << std::endl;
|
||||
os << osgDB::PROPERTY("TextureTile") << p.getTileS() << p.getTileT() << p.getNumTiles() << std::endl;
|
||||
|
||||
os << osgDB::PROPERTY("Drawable") << (p.getDrawable()!=NULL);
|
||||
if ( p.getDrawable()!=NULL )
|
||||
{
|
||||
os << osgDB::BEGIN_BRACKET << std::endl;
|
||||
os.writeObject( p.getDrawable() );
|
||||
os << osgDB::END_BRACKET;
|
||||
}
|
||||
os << std::endl;
|
||||
|
||||
os << osgDB::END_BRACKET << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -75,8 +75,18 @@ REGISTER_OBJECT_WRAPPER( osgParticleParticleSystem,
|
||||
ADD_ENUM_VALUE( WORLD_COORDINATES );
|
||||
END_ENUM_SERIALIZER(); // _particleScaleReferenceFrame
|
||||
|
||||
ADD_BOOL_SERIALIZER( UseVertexArray, false ); // _useVertexArray
|
||||
ADD_BOOL_SERIALIZER( UseShaders, false ); // _useShaders
|
||||
ADD_BOOL_SERIALIZER( DoublePassRendering, false ); // _doublepass
|
||||
ADD_BOOL_SERIALIZER( Frozen, false ); // _frozen
|
||||
ADD_USER_SERIALIZER( DefaultParticleTemplate ); // _def_ptemp
|
||||
ADD_BOOL_SERIALIZER( FreezeOnCull, false ); // _freeze_on_cull
|
||||
|
||||
BEGIN_ENUM_SERIALIZER( SortMode, NO_SORT );
|
||||
ADD_ENUM_VALUE( NO_SORT );
|
||||
ADD_ENUM_VALUE( SORT_FRONT_TO_BACK );
|
||||
ADD_ENUM_VALUE( SORT_BACK_TO_FRONT );
|
||||
END_ENUM_SERIALIZER(); // _sortMode
|
||||
|
||||
ADD_DOUBLE_SERIALIZER( VisibilityDistance, -1.0 ); // _visibilityDistance
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ static bool writeParticleSystems( osgDB::OutputStream& os, const osgParticle::Pa
|
||||
REGISTER_OBJECT_WRAPPER( osgParticleParticleSystemUpdater,
|
||||
new osgParticle::ParticleSystemUpdater,
|
||||
osgParticle::ParticleSystemUpdater,
|
||||
"osg::Object osg::Node osgParticle::ParticleSystemUpdater" )
|
||||
"osg::Object osg::Node osg::Geode osgParticle::ParticleSystemUpdater" )
|
||||
{
|
||||
ADD_USER_SERIALIZER( ParticleSystems ); // _psv
|
||||
}
|
||||
|
||||
21
src/osgWrappers/serializers/osgParticle/SinkOperator.cpp
Normal file
21
src/osgWrappers/serializers/osgParticle/SinkOperator.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <osgParticle/SinkOperator>
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( osgParticleSinkOperator,
|
||||
new osgParticle::SinkOperator,
|
||||
osgParticle::SinkOperator,
|
||||
"osg::Object osgParticle::Operator osgParticle::DomainOperator osgParticle::SinkOperator" )
|
||||
{
|
||||
BEGIN_ENUM_SERIALIZER( SinkTarget, SINK_POSITION );
|
||||
ADD_ENUM_VALUE( SINK_POSITION );
|
||||
ADD_ENUM_VALUE( SINK_VELOCITY );
|
||||
ADD_ENUM_VALUE( SINK_ANGULAR_VELOCITY );
|
||||
END_ENUM_SERIALIZER(); // _sinkTarget
|
||||
|
||||
BEGIN_ENUM_SERIALIZER( SinkStrategy, SINK_INSIDE );
|
||||
ADD_ENUM_VALUE( SINK_INSIDE );
|
||||
ADD_ENUM_VALUE( SINK_OUTSIDE );
|
||||
END_ENUM_SERIALIZER(); // _sinkStrategy
|
||||
}
|
||||
Reference in New Issue
Block a user