• osg::NodeVisitor osg3.4.0


    x:-89.4588 y:-12.1245 z:-11.7807
    x:-89.4588 y:-6.44823 z:-11.7807
    x:-89.2164 y:-9.07239 z:-11.811
    x:-89.4588 y:-12.1245 z:-11.7807
    x:-89.2164 y:-9.07239 z:-11.811
    x:-89.2164 y:-15.9458 z:-11.811
    x:-89.4588 y:-6.44823 z:-11.7807
    x:-89.2164 y:-2.19896 z:-11.811
    x:-89.2164 y:-9.07239 z:-11.811
    x:-89.4588 y:-6.44823 z:-11.7807
    x:-89.4959 y:-2.57999 z:-11.7705
    x:-89.2164 y:-2.19896 z:-11.811
    x:-89.6451 y:-4.75968 z:-11.7127
    x:-89.4959 y:-2.57999 z:-11.7705
    x:-89.4588 y:-6.44823 z:-11.7807
    x:-89.6451 y:-4.75968 z:-11.7127
    x:-89.7325 y:1.15286 z:-11.6649
    x:-89.4959 y:-2.57999 z:-11.7705
    x:-89.7325 y:1.15286 z:-11.6649
    x:-89.6451 y:-4.75968 z:-11.7127
    x:-89.8026 y:-2.48957 z:-11.6174
    x:-89.8026 y:-2.48957 z:-11.6174
    x:-89.8883 y:1.02162 z:-11.5459

    #ifdef _WIN32
    #include <Windows.h>
    #endif // _WIN32
    #include<iostream>
    
    #include <osgViewer/Viewer>
    #include <osgViewer/ViewerEventHandlers> 
    #include <osgViewer/CompositeViewer> 
    #include <osgDB/ReadFile>
    #include <osg/Geode>
    #include <osg/Node>
    #include <osg/Geometry>
    #include <osgGA/TrackballManipulator>
    #include <osg/GraphicsContext>
    #include <osg/ShapeDrawable>
    #include <osg/Material>
    #include <osg/Image>
    #include <osg/Texture2D>
    #include <osg/TexEnv>
    #include <osg/TexGen>
    #include <osg/NodeVisitor>
    #include <osg/MatrixTransform>
    #include <osg/PositionAttitudeTransform>
    #include <osg/AnimationPath>
    #include <osg/Matrixd>
    
    #include <osgGA/GUIEventHandler>
    #include <osgGA/CameraManipulator>
    #include <osgGA/StandardManipulator>
    #include <osgGA/OrbitManipulator>
    #include <osgGA/TrackballManipulator>
    #include <osgUtil/IntersectionVisitor>
    #include <osgUtil/LineSegmentIntersector>
    
    class BoundVisitor :public osg::NodeVisitor
    {
    public:
        BoundVisitor() :osg::NodeVisitor(TRAVERSE_ALL_CHILDREN), _indent(0) 
        {
            std::cout << "--" << std::endl;
        }
    
    
        virtual void apply(osg::Geode &geode)
        {
            //osg::Drawable *drawable1=  geode.getDrawable(0);
            unsigned int count = geode.getNumDrawables();
            for (int i = 0; i < count; i++)
            {
                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();
                for (int j = 0; j<vertexlNum; 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;
                }
            }
        }
    
    protected:
        int _indent;
    };
    
    
    int main()
    {
        osg::ref_ptr<osgViewer::Viewer> viewer1 = new osgViewer::Viewer;
        osg::ref_ptr<osg::Node> node1 = osgDB::readNodeFile("D:\参考手册\BIM\osg\build1.OSGB");
        BoundVisitor bv;
    
        node1->accept(bv);
        viewer1->setSceneData(node1);
        
    
        viewer1->setUpViewInWindow(200, 200, 800, 600, 0);
    
        return viewer1->run();
    }

  • 相关阅读:
    笔试题 易错题目解析
    SqlServer 函数 大全
    视频上传到自己的服务器打不开
    sql 计算生日提请日期
    Web API 异常处理(转)
    微软源代码管理工具TFS2013安装与使用详细图文教程(Vs2013)
    关于枚举的用法和类型转换
    html title换行方法 如a链接标签内title属性鼠标悬停提示内容换行
    JS的parent、opener、self对象
    uploadfiy
  • 原文地址:https://www.cnblogs.com/herd/p/11099269.html
Copyright © 2020-2023  润新知