布料垂坠模拟

1、案例介绍

案例位置examples/Cuda/CodimensionalPD/CPD_ClothDrop

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

案例说明:该案例主要用于模拟布料。布料的上面两个点被固定,在重力作用逐渐落下的效果。

2、程序实现

  • 创建场景图和边界:
	std::shared_ptr<SceneGraph> scn = std::make_shared<SceneGraph>();
	scn->setLowerBound(Vec3f(-1.5, -1, -1.5));
	scn->setUpperBound(Vec3f(1.5, 3, 1.5));
	scn->setGravity(Vec3f(0,-200,0));
  • 创建CodimensionalPD节点,用于模拟布料:
	auto cloth = scn->addNode(std::make_shared<CodimensionalPD<DataType3f>>(0.15, 120, 0.001, 0.0001));
	//also try:
	//auto cloth = scn->addNode(std::make_shared<CodimensionalPD<DataType3f>>(0.15, 1200, 0.001, 0.0001));
	//auto cloth = scn->addNode(std::make_shared<CodimensionalPD<DataType3f>>(0.15, 12000, 0.001, 0.0001));
	cloth->loadSurface(getAssetPath() + "cloth_shell/mesh_drop.obj");

	auto custom = std::make_shared<ManualControl<DataType3f>>();
	cloth->statePosition()->connect(custom->inPosition());
	cloth->stateVelocity()->connect(custom->inVelocity());
	cloth->stateFrameNumber()->connect(custom->inFrameNumber());
	cloth->stateAttribute()->connect(custom->inAttribute());
	cloth->animationPipeline()->pushModule(custom);
	cloth->setSelfContact(false);
  • 创建渲染节点:
	auto surfaceRendererCloth = std::make_shared<GLSurfaceVisualModule>();
	surfaceRendererCloth->setColor(Color(1, 1, 1));

	cloth->stateTriangleSet()->connect(surfaceRendererCloth->inTriangleSet());
	cloth->graphicsPipeline()->pushModule(surfaceRendererCloth);
	cloth->setVisible(true);