|
楼主 |
发表于 2015-5-13 23:32:35
|
显示全部楼层
终于找到办法了,原来使用osg的TriangleFunctor就可以,代码如下:
- class My_visitor
- {
- public:
- My_visitor():tri_point_num_(0){}
- void operator()(const osg::Vec3 & a, const osg::Vec3 & b, const osg::Vec3 & c, bool ){
- tri_.push_back(tri_point_num_++);
- tri_.push_back(tri_point_num_++);
- tri_.push_back(tri_point_num_++);
- push_node(nodes_, a);
- push_node(nodes_, b);
- push_node(nodes_, c);
- }
- const std::vector<unsigned int> & get_tris()const{return tri_;}
- const std::vector<double> & get_nodes()const{return nodes_;}
- protected:
- void push_node(std::vector<double> & node,
- const osg::Vec3 &a)
- {
- node.push_back(a.x());
- node.push_back(a.y());
- node.push_back(a.z());
- }
- std::vector<unsigned int> tri_;
- std::vector<double> nodes_;
- size_t tri_point_num_;
- };
- typedef osg::TriangleFunctor<My_visitor> my_functor;
- my_functor mf;
- text3d_->accept(mf);
- const std::vector<unsigned int> &triangles = mf.get_tris();
- const std::vector<double> & nodes = mf.get_nodes();
复制代码
现在唯一的问题是,该方法是按照绘制图元的顺序来获取顶点,因而存在大量冗余顶点。
相应的解决方法,要么直接进行顶点合并,或者看看有没有其他的functor。 |
|