osg::NodeVisitor

[1]osg::Group
        [2]osg::PositionAttitudeTransform
        [2]osg::MatrixTransform
                [3]osg::Geode
        [2]osg::MatrixTransform
        [2]osg::MatrixTransform
        [2]osg::MatrixTransform
        [2]osg::MatrixTransform
                [3]osg::Geode
                osg::Geometry
                        [4]osg::Geometry

 

class BoundVisitor :public osg::NodeVisitor
{
public:
    //BoundVisitor():osg::NodeVisitor(TRAVERSE_ALL_CHILDREN), _indent(0)
    //{
        
    //}

    BoundVisitor() :osg::NodeVisitor(TRAVERSE_ALL_CHILDREN), _indent(0) 
    {
        std::cout << "--" << std::endl;
    }

    virtual void apply(osg::Node &node)
    {
        for (int i = 0; i < _indent; ++i)
        {
            std::cout << "\t";
        }
        std::cout << "[" << _indent + 1 << "]" << node.libraryName()<< "::" << node.className() << std::endl;

        _indent++;
        traverse(node);
        _indent--;
    }

    virtual void apply(osg::Geode &geode)
    {
        for (int i = 0; i < _indent; ++i)
        {
            std::cout << "\t";
        }
        std::cout << "[" << _indent + 1 << "]" << geode.libraryName()<< "::" << geode.className() << std::endl;


        //osg::Drawable *drawable1=  geode.getDrawable(0);
        unsigned int count = geode.getNumDrawables();
        for (int i = 0; i < count; i++)
        {
            osg::Drawable *drawable = geode.getDrawable(i);
            if (!drawable)
            {
                continue;
            }

            osg::Geometry *geometry = geode.getDrawable(i)->asGeometry();
            if (!geometry)
            {
                continue;
            }

            // 顶点数据
            osg::Vec3Array* vertices = dynamic_cast<osg::Vec3Array*>(geometry->getVertexArray());
            //osg::Vec3Array vertices = geometry->getVertexArray();
            int vertexlNum = vertices->size();
            //std::cout << "size:"<<vertexlNum <<"     "<< geometry->libraryName() <<"  "<< geometry->getNumChildrenRequiringEventTraversal() << std::endl;
            //geometry->libraryName();
            
            //for (int j = 0; j<100; j++) {
                //dstSubset.vertexs.push_back(vertices->at(j).x());
                //dstSubset.vertexs.push_back(vertices->at(j).y());
                //dstSubset.vertexs.push_back(vertices->at(j).z());
                //std::cout << "x:" << vertices->at(j).x() << "  y:" << vertices->at(j).y() << "  z:" << vertices->at(j).z() << std::endl;
            //}

            for (int i = 0; i < _indent; ++i)
            {
                std::cout << "\t";
            }
            std::cout << drawable->libraryName()
                << "::" << drawable->className() << std::endl;
        }
    
        _indent++;
        traverse(geode);
        _indent--;
    }

protected:
    int _indent;
};

 

上一篇:基于osgQt将OSG嵌入到Qt窗口中(有错误)


下一篇:探索未知种族之osg类生物---渲染遍历之裁剪一