布料仿真

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);
    root->loadShpere(Vec3f(0.5, 0.7f, 0.5), 0.08f, 0.005f, false, true);

    auto cloth = scn->addNode(std::make_shared<Cloth<DataType3f>>());
    cloth->loadParticles("../../data/cloth/cloth.obj");
    cloth->loadSurface("../../data/cloth/cloth.obj");

    root->addParticleSystem(cloth);
  • 创建渲染节点:
	auto pointRenderer = std::make_shared<GLPointVisualModule>();
	pointRenderer->setColor(Vec3f(1, 0.2, 1));
	pointRenderer->setColorMapMode(GLPointVisualModule::PER_OBJECT_SHADER);
	cloth->currentTopology()->connect(pointRenderer->inPointSet());
	cloth->stateVelocity()->connect(pointRenderer->inColor());

	cloth->graphicsPipeline()->pushModule(pointRenderer);
	cloth->setVisible(true);

	auto surfaceRenderer = std::make_shared<GLSurfaceVisualModule>();
	cloth->currentTopology()->connect(surfaceRenderer->inTriangleSet());
	cloth->graphicsPipeline()->pushModule(surfaceRenderer);

3、仿真效果

代码参考examples/GL_Cloth/main.h: