void EngineExhaustNode::addNozzle( irr::core::vector3df offset ) { auto fire = SceneManager->addParticleSystemSceneNode(false, this, 0); fire->setParticleBehavior( EPB_EMITTER_VECTOR_IGNORE_ROTATION | EPB_EMITTER_FRAME_INTERPOLATION); fire->setParticlesAreGlobal(true); //Emitter auto emitter = fire->createSphereEmitter( offset, mRadius, vector3df(0,0,-1), 20, 20, SColor(255,255,255,255), SColor(255,255,255,255), mParticleLifetime - 100, mParticleLifetime, 5, dimension2df(mParticleSize, mParticleSize), dimension2df( mParticleSize * 1.5, mParticleSize * 1.5)); fire->setEmitter(emitter); fire->addAffector(mFadeOutAffector); fire->addAffector(mScaleAffector); fire->setMaterialFlag(EMF_LIGHTING, false); fire->setMaterialTexture(0, mFireTexture); fire->setMaterialType(EMT_TRANSPARENT_ADD_COLOR); //fire->setMaterialType( EMT_TRANSPARENT_ALPHA_CHANNEL ); mFireEmitters.push_back( fire ); }
void Main::onInitialize() { auto scene = addScene(new dt::Scene("testscene")); dt::ResourceManager::get()->addResourceLocation("sinbad.zip","Zip", true); dt::ResourceManager::get()->addResourceLocation("particle/","FileSystem", true); Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); // make a scene auto camnode = scene->addChildNode(new dt::Node("camnode")); camnode->setPosition(Ogre::Vector3(0, 2, 10)); camnode->addComponent(new dt::CameraComponent("cam"))->lookAt(Ogre::Vector3(0, 2, 0));; auto p = scene->addChildNode(new dt::Node("p")); p->setScale(0.2); auto mesh = p->addComponent(new dt::MeshComponent("Sinbad.mesh")); mesh->setAnimation("RunBase"); mesh->setLoopAnimation(true); mesh->playAnimation(); auto path = p->addComponent(new dt::FollowPathComponent(dt::FollowPathComponent::LOOP)); path->addPoint(Ogre::Vector3(-10, 0, 0)); path->addPoint(Ogre::Vector3(10, 0, 0)); path->setDuration(2.f); path->setFollowRotation(true); // create the particle system auto p_sys = p->addComponent(new dt::ParticleSystemComponent("p_sys")); p_sys->setMaterialName("Test/Particle"); p_sys->setParticleCountLimit(1000); p_sys->getOgreParticleSystem()->setDefaultDimensions(0.03, 0.03); Ogre::ParticleEmitter* e = p_sys->addEmitter("emit1", "Point"); e->setAngle(Ogre::Degree(10)); e->setColour(Ogre::ColourValue(1.f, 0.6f, 0.f), Ogre::ColourValue(0.2f, 0.8f, 0.2f)); e->setEmissionRate(100); e->setParticleVelocity(3.f, 4.f); e->setTimeToLive(1.f, 2.f); p_sys->addScalerAffector("scaler", 1.05); p_sys->addLinearForceAffector("force", Ogre::Vector3(0, 5, 0)); Ogre::ParticleAffector* a = p_sys->addAffector("colour_interpolator", "ColourInterpolator"); a->setParameter("time0", "0"); a->setParameter("colour0", "1 1 0 1"); a->setParameter("time1", "0.5"); a->setParameter("colour1", "1 0.3 0 1"); a->setParameter("time2", "1"); a->setParameter("colour2", "1 0 0 0"); }
//! Reads attributes of the scene node. void CParticleSystemSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) { IParticleSystemSceneNode::deserializeAttributes(in, options); ParticlesAreGlobal = in->getAttributeAsBool("GlobalParticles"); ParticleSize.Width = in->getAttributeAsFloat("ParticleWidth"); ParticleSize.Height = in->getAttributeAsFloat("ParticleHeight"); // read emitter int emitterIdx = in->findAttribute("Emitter"); if (emitterIdx == -1) return; if (Emitter) Emitter->drop(); Emitter = 0; E_PARTICLE_EMITTER_TYPE type = (E_PARTICLE_EMITTER_TYPE) in->getAttributeAsEnumeration("Emitter", ParticleEmitterTypeNames); switch(type) { case EPET_POINT: Emitter = createPointEmitter(); break; case EPET_ANIMATED_MESH: Emitter = createAnimatedMeshSceneNodeEmitter(NULL); // we can't set the node - the user will have to do this break; case EPET_BOX: Emitter = createBoxEmitter(); break; case EPET_CYLINDER: Emitter = createCylinderEmitter(core::vector3df(0,0,0), 10.f, core::vector3df(0,1,0), 10.f); // (values here don't matter) break; case EPET_MESH: Emitter = createMeshEmitter(NULL); // we can't set the mesh - the user will have to do this break; case EPET_RING: Emitter = createRingEmitter(core::vector3df(0,0,0), 10.f, 10.f); // (values here don't matter) break; case EPET_SPHERE: Emitter = createSphereEmitter(core::vector3df(0,0,0), 10.f); // (values here don't matter) break; default: break; } u32 idx = 0; #if 0 if (Emitter) idx = Emitter->deserializeAttributes(idx, in); ++idx; #else if (Emitter) Emitter->deserializeAttributes(in); #endif // read affectors removeAllAffectors(); u32 cnt = in->getAttributeCount(); while(idx < cnt) { const char* name = in->getAttributeName(idx); if (!name || strcmp("Affector", name)) return; E_PARTICLE_AFFECTOR_TYPE atype = (E_PARTICLE_AFFECTOR_TYPE)in->getAttributeAsEnumeration(idx, ParticleAffectorTypeNames); IParticleAffector* aff = 0; switch(atype) { case EPAT_ATTRACT: aff = createAttractionAffector(core::vector3df(0,0,0)); break; case EPAT_FADE_OUT: aff = createFadeOutParticleAffector(); break; case EPAT_GRAVITY: aff = createGravityAffector(); break; case EPAT_ROTATE: aff = createRotationAffector(); break; case EPAT_SCALE: aff = createScaleParticleAffector(); break; case EPAT_NONE: default: break; } ++idx; if (aff) { #if 0 idx = aff->deserializeAttributes(idx, in, options); ++idx; #else aff->deserializeAttributes(in, options); #endif addAffector(aff); aff->drop(); } } }
ParticleSystem::Ptr ParticleSystem::create(Particle::Type type, MessageBus& mb) { auto ps = std::make_unique<ParticleSystem>(mb); switch (type) { case Particle::Type::Trail: { const float scale = Util::Random::value(2.f, 4.f); ScaleAffector sa({ scale, scale }); ps->addAffector<ScaleAffector>(sa); ForceAffector fa({ 0.f, -190.f }); ps->addAffector<ForceAffector>(fa); ps->setEmitRate(Util::Random::value(0.5f, 2.5f)); ps->setBlendMode(sf::BlendAdd); ps->setEmitRate(3.f); ps->setRandomInitialVelocity(trailVelocities); ps->start(1u, Util::Random::value(0.2f, 1.f)); } break; case Particle::Type::Echo: { ScaleAffector sa({ 1.6f, 1.6f }); ps->addAffector<ScaleAffector>(sa); ps->setBlendMode(sf::BlendAdd); ps->setParticleLifetime(0.95f); ps->followParent(true); } break; case Particle::Type::Sparkle: { sparkPositions = createPoints(sf::Vector2f(), 20, 18.f); ps->setParticleLifetime(0.6f); ps->setParticleSize({ 10.f, 10.f }); ps->setRandomInitialVelocity(sparkVelocities); ps->setRandomInitialPosition(sparkPositions); ps->setBlendMode(sf::BlendAdd); ScaleAffector sa({ 2.f, 2.f }); ps->addAffector(sa); RotateAffector ra(140.f); ps->addAffector(ra); } break; case Particle::Type::Ident: { identPositions = createPoints({}, 20, 20.f); ps->setParticleLifetime(0.6f); ps->setParticleSize({ 20.f, 20.f }); ps->setInitialVelocity({ 0.f, 0.f }); ps->setRandomInitialPosition(identPositions); ps->setBlendMode(sf::BlendAdd); ps->followParent(true); ps->setEmitRate(7.f); ps->start(); } default: break; } return std::move(ps); }
//! Reads attributes of the scene node. void CParticleSystemSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) { IParticleSystemSceneNode::deserializeAttributes(in, options); ParticlesAreGlobal = in->getAttributeAsBool("GlobalParticles"); ParticleSize.Width = in->getAttributeAsFloat("ParticleWidth"); ParticleSize.Height = in->getAttributeAsFloat("ParticleHeight"); // read emitter int emitterIdx = in->findAttribute("Emitter"); if (emitterIdx == -1) return; if (Emitter) Emitter->drop(); Emitter = 0; E_PARTICLE_EMITTER_TYPE type = (E_PARTICLE_EMITTER_TYPE) in->getAttributeAsEnumeration("Emitter", ParticleEmitterTypeNames); switch(type) { case EPET_POINT: Emitter = createPointEmitter(); break; case EPET_BOX: Emitter = createBoxEmitter(); break; } s32 idx = 0; if (Emitter) idx = Emitter->deserializeAttributes(idx, in); ++idx; // read affectors removeAllAffectors(); s32 cnt = in->getAttributeCount(); while(idx < cnt) { const char* name = in->getAttributeName(idx); if (!name || strcmp("Affector", name)) return; E_PARTICLE_AFFECTOR_TYPE atype = (E_PARTICLE_AFFECTOR_TYPE)in->getAttributeAsEnumeration(idx, ParticleAffectorTypeNames); IParticleAffector* aff = 0; switch(atype) { case EPAT_FADE_OUT: aff = createFadeOutParticleAffector(); break; case EPAT_GRAVITY: aff = createGravityAffector(); break; } ++idx; if (aff) { idx = aff->deserializeAttributes(idx, in, options); ++idx; addAffector(aff); aff->drop(); } } }