布料小游戏

1、案例介绍

案例位置examples/Cuda/CodimensionalPD/CPD_ShootingCloth

功能介绍:案例中展示了 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));
	
	auto cloth = scn->addNode(std::make_shared<CodimensionalPD<DataType3f>>(0.15, 120, 0.001, 0.0005));
	cloth->loadSurface(getAssetPath() + "cloth_shell/cylinder400.obj");
  • 创建CodimensionalPD节点,用于模拟布料:
	cloth->loadSurface(getAssetPath() + "cloth_shell/shootingCloth.obj");
	cloth->connect(boundary->importTriangularSystems()); 

	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);

  • 创建渲染节点:
	auto surfaceRendererCloth = std::make_shared<GLSurfaceVisualModule>();
	surfaceRendererCloth->setColor(Color(1,1,1));
	cloth->stateTriangleSet()->connect(surfaceRendererCloth->inTriangleSet());
	cloth->graphicsPipeline()->pushModule(surfaceRendererCloth);
	cloth->setVisible(true);