布料模拟

1、布料模拟

案例位置examples/Cuda/Tutorials/GL_Cloth

功能介绍:主要用于测试布料仿真功能。该案例展示了 Cloth 类的的基本使用。

案例说明:场景由两个模型组成,一个是上方的布料模型,一个是下方的静态球体。案例展示了布料从空中掉落,并与静态球体发生碰撞,最后掉落到地面的仿真过程。

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(getAssetPath() + "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->statePointSet()->connect(pointRenderer->inPointSet());
	cloth->stateVelocity()->connect(pointRenderer->inColor());

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

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