案例位置:examples/Cuda/RigidBody/GL_Wireframe
功能介绍:该案例展示将模型表面绘制成线框。
案例说明:该案例主要展示如何使用渲染节点,并以GLWireframeVisualModulel节点为例,将仿真物体以线框的形式展示。线条的形式有两种,一种是线段模式,一种是圆柱模式(加粗的线段)。
接下来介绍案例的实现过程:
std::shared_ptr<SceneGraph> scn = std::make_shared<SceneGraph>();
auto rigid = scn->addNode(std::make_shared<RigidBodySystem<DataType3f>>());
RigidBodyInfo rigidBody;
rigidBody.linearVelocity = Vec3f(0.5, 0, 0);
BoxInfo box;
for (int i = 8; i > 1; i--)
for (int j = 0; j < i + 1; j++)
{
box.center = 0.5f * Vec3f(0.5f, 1.1 - 0.13 * i, 0.12f + 0.21 * j + 0.1 * (8 - i));
box.halfLength = 0.5f * Vec3f(0.065, 0.065, 0.1);
rigid->addBox(box, rigidBody);
}
SphereInfo sphere;
sphere.center = Vec3f(0.5f, 0.75f, 0.5f);
sphere.radius = 0.025f;
RigidBodyInfo rigidSphere;
rigid->addSphere(sphere, rigidSphere);
sphere.center = Vec3f(0.5f, 0.95f, 0.5f);
sphere.radius = 0.025f;
rigid->addSphere(sphere, rigidSphere);
sphere.center = Vec3f(0.5f, 0.65f, 0.5f);
sphere.radius = 0.05f;
rigid->addSphere(sphere, rigidSphere);
TetInfo tet;
tet.v[0] = Vec3f(0.5f, 1.1f, 0.5f);
tet.v[1] = Vec3f(0.5f, 1.2f, 0.5f);
tet.v[2] = Vec3f(0.6f, 1.1f, 0.5f);
tet.v[3] = Vec3f(0.5f, 1.1f, 0.6f);
rigid->addTet(tet, rigidSphere);
auto mapper = std::make_shared<DiscreteElementsToTriangleSet<DataType3f>>();
rigid->stateTopology()->connect(mapper->inDiscreteElements());
rigid->graphicsPipeline()->pushModule(mapper);
auto sRender = std::make_shared<GLWireframeVisualModule>();
sRender->setColor(Vec3f(1, 1, 0));
sRender->varRenderMode()->getDataPtr()->setCurrentKey(GLWireframeVisualModule::LINE);
mapper->outTriangleSet()->connect(sRender->inEdgeSet());
rigid->graphicsPipeline()->pushModule(sRender);