案例位置:examples/Cuda/Tutorials/GL_ParticleEmitter
功能介绍:该案例主要用于测试流体发射器的仿真功能。案例展示了 SquareEmitter 类的的基本使用。粒子发射器通过限定粒子活动范围的,并给定随机产生的粒子一个初始位移和速度,来模拟流体发射。
案例说明:案例中展示了流体粒子从空中发射,与地面的流体发生碰撞的过程。
接下来介绍案例的实现过程:
std::shared_ptr<SceneGraph> scn = std::make_shared<SceneGraph>();
//Create a particle emitter
auto emitter = scn->addNode(std::make_shared<ParticleEmitterSquare<DataType3f>>());
emitter->varLocation()->setValue(Vec3f(0.5f));
//Create a particle-based fluid solver
auto fluid = scn->addNode(std::make_shared<ParticleFluid<DataType3f>>());
fluid->loadParticles(Vec3f(0.0f), Vec3f(0.2f), 0.005f);
emitter->connect(fluid->importParticleEmitters());
auto calculateNorm = std::make_shared<CalculateNorm<DataType3f>>();
fluid->stateVelocity()->connect(calculateNorm->inVec());
fluid->graphicsPipeline()->pushModule(calculateNorm);
auto ptRender = std::make_shared<GLPointVisualModule>();
ptRender->setColor(Vec3f(1, 0, 0));
ptRender->setColorMapMode(GLPointVisualModule::PER_VERTEX_SHADER);
ptRender->setColorMapRange(0, 5);
fluid->stateVelocity()->connect(calculateNorm->inVec());
fluid->currentTopology()->connect(ptRender->inPointSet());
calculateNorm->outNorm()->connect(colorMapper->inScalar());
colorMapper->outColor()->connect(ptRender->inColor());
fluid->graphicsPipeline()->pushModule(calculateNorm);
fluid->graphicsPipeline()->pushModule(colorMapper);
fluid->graphicsPipeline()->pushModule(ptRender);
auto container = scn->addNode(std::make_shared<StaticBoundary<DataType3f>>());
container->loadCube(Vec3f(0.0f), Vec3f(1.0), 0.02, true);
fluid->connect(container->importParticleSystems());