案例位置:examples/Cuda/Tutorials/GL_Elasticity
功能介绍:该案例主要用于测试弹性体仿真功能。案例展示了 ElasticBody 类的基本使用。在计算机图形学领域,基于物理方法的三维弹性体变形仿真有着广泛的应用需求。弹性体能在除去外力后恢复原状。弹性体只在弱应力下形变显著,应力松弛后能迅速恢复到接近原有状态和尺寸。
案例说明:案例中展示了弹性体兔子模型从空中掉落后,与地面发生碰撞的弹性运动过程。
接下来介绍案例的实现过程:
std::shared_ptr<SceneGraph> scn = std::make_shared<SceneGraph>();
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);
auto bunny = scn->addNode(std::make_shared<ElasticBody<DataType3f>>());
bunny->connect(root->importParticleSystems());
bunny->loadParticles(getAssetPath() + "bunny/bunny_points.obj");
bunny->scale(1.0f);
bunny->translate(Vec3f(0.5f, 0.1f, 0.5f));
bunny->setVisible(true);
auto pointRenderer = std::make_shared<GLPointVisualModule>();
pointRenderer->setColor(Vec3f(1, 0.2, 1));
pointRenderer->setColorMapMode(GLPointVisualModule::PER_OBJECT_SHADER);
bunny->statePointSet()->connect(pointRenderer->inPointSet());
bunny->stateVelocity()->connect(pointRenderer->inColor());
bunny->graphicsPipeline()->pushModule(pointRenderer);