osgParticle.ModularEmitter是OpenSceneGraph中的一个粒子系统发射器,它允许用户通过添加模块来自定义粒子的发射。
osgParticle.ModularEmitter可以添加多个模块,包括:
每个模块可以根据需要添加并配置,以实现需要的粒子效果。
下面是一个示例代码,展示了如何使用osgParticle.ModularEmitter创建一个粒子效果,并添加若干个发射器模块来自定义效果:
// 创建粒子发射器
osgParticle::ModularEmitter* emitter = new osgParticle::ModularEmitter();
// 创建数量、速度和方向发射器模块
osgParticle::RandomRateCounter* counter = new osgParticle::RandomRateCounter();
counter->setRateRange(50, 100);
emitter->setCounter(counter);
osgParticle::RadialShooter* shooter = new osgParticle::RadialShooter();
shooter->setThetaRange(0, osg::PI_2);
shooter->setPhiRange(0, osg::PI_2);
emitter->setShooter(shooter);
osgParticle::RandomRateCounter* speedCounter = new osgParticle::RandomRateCounter();
speedCounter->setRateRange(50, 100);
emitter->setSpeedRange(0.2, 0.5);
// 创建位置、颜色和生命周期发射器模块
osgParticle::SectorPlacer* placer = new osgParticle::SectorPlacer();
placer->setCenter(osg::Vec3(0, 0, 0));
emitter->setPlacer(placer);
osgParticle::ColorRange* color = new osgParticle::ColorRange();
color->setColorRange(osg::Vec4(1,0,0,1), osg::Vec4(1,1,0,1));
emitter->setColorRange(color);
osgParticle::SegmentedLifeTime* lifetime = new osgParticle::SegmentedLifeTime();
lifetime->addSegment(0.0f, 0.0f);
lifetime->addSegment(0.2f, 0.8f);
lifetime->addSegment(1.0f, 0.0f);
emitter->setLifeTime(lifetime);
osgParticle.ModularEmitter类定义了如下类型:
class ModularEmitter : public ParticleEmitter
{
public:
typedef std::vector<osg::ref_ptr<ParticleEmitter>> EmitterList;
typedef std::vector<osg::ref_ptr<ParticleProcessor>> ProcessorList;
typedef std::vector<osg::ref_ptr<osgParticle::Particle>> ParticleList;
typedef std::vector<osg::Vec4> ColorList;
// ...
};
osgParticle.ModularEmitter类在OpenSceneGraph 3.4.0及以上版本中可用。