码迷,mamicode.com
首页 > 其他好文 > 详细

osg 渲染ifc数据-测试

时间:2019-11-01 22:42:51      阅读:307      评论:0      收藏:0      [点我收藏+]

标签:loop   jpg   mit   stat   cat   图片   bsp   src   amp   

直接使用osg渲染ifc数据,提高渲染速度。

#include "teslamanage.h"
#include <QtWidgets/QApplication>
#include <QtGui/QIcon>

#include <osgViewer/Viewer>

osg::ref_ptr<osg::Node> createLand(int widthParam, int heightParam, int zParam);
void loadIFCFile(osg::ref_ptr<osgViewer::Viewer> &viewer1,std::wstring &fileNmae);

int main(int argc, char *argv[])
{
    
    std::wstring fileName = L"D://ck1.ifc";
    osg::ref_ptr<osgViewer::Viewer> viewer1 = new osgViewer::Viewer;

    loadIFCFile(viewer1, fileName);
    viewer1->setUpViewInWindow(200, 200, 800, 600, 0);
    return viewer1->run();
}


osg::ref_ptr<osg::Node> createLand(int widthParam, int heightParam, int zParam)
{
    osg::ref_ptr<osg::Geode> geode = new osg::Geode;
    osg::ref_ptr<osg::Geometry> geo = new osg::Geometry;

    //申请一些顶点
    osg::ref_ptr<osg::Vec3Array> vers = new osg::Vec3Array;
    geo->setVertexArray(vers.get());
    //#if 1
    //    geo->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, 0, 4));//创建一个线圈
    //#else
    geo->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, 4));//创建一个正方形
    //#endif


    //设置顶点
    //vers->push_back(osg::Vec3(-15, 3.0, -15));
    //vers->push_back(osg::Vec3(15, 3.0, -15));
    //vers->push_back(osg::Vec3(15, 3.0, 15));
    //vers->push_back(osg::Vec3(-15, 3.0, 15));

    vers->push_back(osg::Vec3(widthParam*(-1.0), heightParam*(-1.0), zParam*(1.0)));
    vers->push_back(osg::Vec3(widthParam*(1.0), heightParam*(-1.0), zParam*(1.0)));
    vers->push_back(osg::Vec3(widthParam*(1.0), heightParam*(1.0), zParam*(1.0)));
    vers->push_back(osg::Vec3(widthParam*(-1.0), heightParam*(1.0), zParam*(1.0)));

    //申请颜色
    osg::ref_ptr<osg::Vec4Array> color = new osg::Vec4Array();
    color->push_back(osg::Vec4(1.0, 0.0, 0.0, 0.5));
    color->push_back(osg::Vec4(0.0, 1.0, 0.0, 0.5));
    color->push_back(osg::Vec4(0.0, 0.0, 1.0, 0.5));
    color->push_back(osg::Vec4(1.0, 1.0, 0.0, 0.5));

    //设置颜色
    geo->setColorArray(color.get());
    geo->setColorBinding(osg::Geometry::AttributeBinding::BIND_PER_VERTEX);//设置颜色绑定

                                                                           //设置法线,正对屏幕的时候最亮
    osg::ref_ptr<osg::Vec3Array> norm = new osg::Vec3Array;
    geo->setNormalArray(norm);
    geo->setNormalBinding(osg::Geometry::AttributeBinding::BIND_OVERALL);
    norm->push_back(osg::Vec3(0.0, -1.0, 0.0));

    //打开透明度
    geo->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);

    //设置线宽
    osg::ref_ptr<osg::LineWidth> w = new osg::LineWidth;
    w->setWidth(5.0);
    geo->getOrCreateStateSet()->setAttributeAndModes(w.get(), osg::StateAttribute::ON);

    geode->addDrawable(geo.get());

    return geode;
}

技术图片

技术图片

技术图片

 

osg 渲染ifc数据-测试

标签:loop   jpg   mit   stat   cat   图片   bsp   src   amp   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!