osg::NodeVisitor example

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

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

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

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

        for (int i = 0; i < _indent; i++)  std::cout << "    ";
        std::cout << "[" << _indent << "] " << node.libraryName()
            << "::" << node.className() << std::endl;
    }

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

        _indent++;

        for (unsigned int n = 0; n < node.getNumDrawables(); n++)
        {
            osg::Drawable* draw = node.getDrawable(n);
            if (!draw)
                continue;
            for (int i = 0; i < _indent; i++)  std::cout << "    ";
            std::cout << "[" << _indent << "]" << draw->libraryName() << "::"
                << draw->className() << std::endl;
        }

        traverse(node);
        _indent--;

        for (int i = 0; i < _indent; i++)  std::cout << "    ";
        std::cout << "[" << _indent << "]" << node.libraryName()
            << "::" << node.className() << std::endl;
    }
private:
    int _indent;
};

 

该模型在unity3d中结构

该模型在3dmax中结构

原文地址:https://www.cnblogs.com/herd/p/11099518.html