球与1块布碰撞模拟

1、案例介绍

案例位置examples/Cuda/CodimensionalPD/CPD_ClothOverBall_1

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

案例说明:该案例主要用于模拟布料。布料在重力作用下,从空中掉落到静态球体,并形成褶皱的过程。

2、程序实现

  • 创建场景图、边界以及静态球杆模型:
	std::shared_ptr<SceneGraph> scn = std::make_shared<SceneGraph>();
	scn->setLowerBound(Vec3f(-1.5, 0, -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/ball/ball_model.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/ball/ball_small_size_15.sdf", false);
  • 创建CodimensionalPD节点,用于模拟布料:
	auto cloth = scn->addNode(std::make_shared<CodimensionalPD<DataType3f>>(0.15, 500, 0.0005, 1e-3));
	cloth->setDt(0.001f);
	cloth->loadSurface(getAssetPath() + "cloth_shell/cloth_size_17_alt/cloth_40k_1.obj");
	cloth->connect(boundary->importTriangularSystems());
	cloth->setGrad_ite_eps(0);
	cloth->setMaxIteNumber(10);
	auto surfaceRendererCloth = std::make_shared<GLSurfaceVisualModule>();
	surfaceRendererCloth->setColor(Color(0.4, 0.4, 1.0));
  • 创建渲染节点:
	auto surfaceRenderer = std::make_shared<GLSurfaceVisualModule>();
	surfaceRenderer->setColor(Color(0.4, 0.4, 0.4));
	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);