拓扑结构

1、拓扑结构

案例位置examples/Cuda/Tutorials/GL_Topology

功能介绍:该案例主要向用户展示如何使用渲染模块对模型进行渲染。

案例说明:案例中创建了一个SurfaceMesh类,将一个标准球体的点、线以及三角面片进行渲染可视化。

2、程序实现

接下来介绍案例的实现过程:

  • 创建一个SurfaceMesh节点:
class SurfaceMesh : public Node
{
public:
	SurfaceMesh() {

		// geometry
		std::shared_ptr<TriangleSet<DataType3f>> triSet = std::make_shared<TriangleSet<DataType3f>>();
		triSet->loadObjFile(getAssetPath() + "standard/standard_sphere.obj");
		triSet->update();
		this->stateTriangles()->setDataPtr(triSet);

		//Point visualizer
		auto pointRender = std::make_shared<GLPointVisualModule>();
		pointRender->varBaseColor()->setValue(Vec3f(1.0f, 0.0f, 0.0));
		pointRender->varPointSize()->setValue(0.02f);
		this->stateTriangles()->connect(pointRender->inPointSet());
		this->graphicsPipeline()->pushModule(pointRender);

		//Wireframe visualizer
		auto edgeRender = std::make_shared<GLWireframeVisualModule>();
		edgeRender->varBaseColor()->setValue(Vec3f(0, 1, 0));
		edgeRender->varRenderMode()->getDataPtr()->setCurrentKey(GLWireframeVisualModule::LINE);
		edgeRender->varLineWidth()->setValue(3.f);
		this->stateTriangles()->connect(edgeRender->inEdgeSet());
		this->graphicsPipeline()->pushModule(edgeRender);

		//Triangle visualizer
		auto triRender = std::make_shared<GLSurfaceVisualModule>();
		triRender->varBaseColor()->setValue(Vec3f(0, 0, 1));
		this->stateTriangles()->connect(triRender->inTriangleSet());
		this->graphicsPipeline()->pushModule(triRender);
	};

public:
	DEF_INSTANCE_STATE(TriangleSet<DataType3f>, Triangles, "Topology");
};

  • 创建场景:
std::shared_ptr<SceneGraph> createScene()
{
	std::shared_ptr<SceneGraph> scn = std::make_shared<SceneGraph>();

	auto mesh = scn->addNode(std::make_shared<SurfaceMesh>());

	return scn;
}