实时衬衫模拟

1、案例介绍

案例位置examples/Cuda/CodimensionalPD/CPD_RealTimeCloth_v2

功能介绍:案例中展示了 CodimensionalPD 类的的基本使用。

案例说明:该案例主要用于模拟布料。人体模型穿上衣服后的仿真情况。

2、程序实现

  • 创建场景图:
	std::shared_ptr<SceneGraph> scn = std::make_shared<SceneGraph>();
	scn->setLowerBound(Vec3f(-1.5, -0.1, -1.5));
	scn->setUpperBound(Vec3f(1.5, 3, 1.5));
	auto object = scn->addNode(std::make_shared<StaticTriangularMesh<DataType3f>>());
	object->varFileName()->setValue(getAssetPath() + "cloth_shell/v2/woman_model_smaller.obj");
	

	auto boundary = scn->addNode(std::make_shared<VolumeBoundary<DataType3f>>());
	boundary->loadCube(Vec3f(-1.5,0,-1.5), Vec3f(1.5,3,1.5), 0.005f, true);
	boundary->loadSDF(getAssetPath() + "cloth_shell/v2/woman_v2.sdf", false);
  • 创建CodimensionalPD节点,用于模拟布料:
	auto cloth = scn->addNode(std::make_shared<CodimensionalPD<DataType3f>>());
	cloth->loadSurface(getAssetPath() + "cloth_shell/v2/cloth_v2.obj");
	cloth->connect(boundary->importTriangularSystems()); 
	cloth->setMaxIteNumber(10);
	cloth->setContactMaxIte(20);
  • 创建渲染节点:
	auto surfaceRendererCloth = std::make_shared<GLSurfaceVisualModule>();
	surfaceRendererCloth->setColor(Color(0.08,0.021,0.0));
	surfaceRendererCloth->varUseVertexNormal()->setValue(true);
	auto surfaceRenderer = std::make_shared<GLSurfaceVisualModule>();
	
	surfaceRenderer->setColor(Color(1,1,0.6));
	surfaceRenderer->varUseVertexNormal()->setValue(true);
	cloth->stateTriangleSet()->connect(surfaceRendererCloth->inTriangleSet());
	object->stateTriangleSet()->connect(surfaceRenderer->inTriangleSet());
	cloth->graphicsPipeline()->pushModule(surfaceRendererCloth);
	object->graphicsPipeline()->pushModule(surfaceRenderer);
	cloth->setVisible(true);
	object->setVisible(true);