在计算机图形学领域,基于物理方法的三维弹性体变形仿真有着广泛的应用需求。弹性体仿真采用粒子法,示例中模拟兔子模型的弹性运动。
std::shared_ptr<SceneGraph> scn = std::make_shared<SceneGraph>();
auto root = scn->addNode(std::make_shared<StaticBoundary<DataType3f>>());
root->loadCube(Vec3f(0), Vec3f(1), 0.005f, true);
auto bunny = scn->addNode(std::make_shared<ElasticBody<DataType3f>>());
bunny->connect(root->importParticleSystems());
bunny->loadParticles("../../data/bunny/bunny_points.obj");
bunny->loadSurface("../../data/bunny/bunny_mesh.obj");
bunny->scale(1.0f);
bunny->translate(Vec3f(0.5f, 0.1f, 0.5f));
bunny->setVisible(true);
auto pointRenderer = std::make_shared<GLPointVisualModule>();
pointRenderer->setColor(Vec3f(1, 0.2, 1));
pointRenderer->setColorMapMode(GLPointVisualModule::PER_OBJECT_SHADER);
bunny->currentTopology()->connect(pointRenderer->inPointSet());
bunny->stateVelocity()->connect(pointRenderer->inColor());
bunny->graphicsPipeline()->pushModule(pointRenderer);
代码参考example/GL_Elasticity/main.h: