弹性体仿真

1、弹性体仿真

在计算机图形学领域,基于物理方法的三维弹性体变形仿真有着广泛的应用需求。弹性体仿真采用粒子法,示例中模拟兔子模型的弹性运动。

2、程序实现

  • 创建场景图:
	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);

3、仿真效果

代码参考example/GL_Elasticity/main.h: