MFC加载大型osg模型
MFC加载模型,发现打开 Navid 缓冲等选项后,加载大型模型的速度就快了很多。
#include "stdafx.h" #include "OSGObject.h" COSGObject::COSGObject(HWND hWnd) { m_hwnd = hWnd; } COSGObject::~COSGObject() { } void COSGObject::InitOSG() { InitSceneGraph(); InitCameraConfig(); } void COSGObject::InitSceneGraph() { mRoot = new osg::Group; //mRoot->addChild(osgDB::readNodeFile("D://library.OSGB")); //mRoot->addChild(osgDB::readNodeFile("I:\\BIM\\osg\\pzy20190722.OSGB")); //mRoot->addChild(osgDB::readNodeFile("D:\\参考手册\\BIM\\ive\\build20190628.ive")); mRoot->addChild(osgDB::readNodeFile("I:\\BIM\\osg\\wanluowang20190903.OSGB")); } void COSGObject::InitCameraConfig() { RECT rect1; mViewer = new osgViewer::Viewer; ::GetWindowRect(m_hwnd, &rect1); osg::ref_ptr<osg::GraphicsContext::Traits> traits1 = new osg::GraphicsContext::Traits; osg::ref_ptr<osg::Referenced> windata = new osgViewer::GraphicsWindowWin32::WindowData(m_hwnd); traits1->x = 0; traits1->y = 0; traits1->width = rect1.right - rect1.left; traits1->height = rect1.bottom - rect1.top; traits1->windowDecoration = false; traits1->doubleBuffer = true; traits1->sharedContext = 0; traits1->setInheritedWindowPixelFormat = true; traits1->inheritedWindowData = windata; osg::GraphicsContext* gc1 = osg::GraphicsContext::createGraphicsContext(traits1); osg::ref_ptr<osg::Camera> camera1 = new osg::Camera; camera1->setGraphicsContext(gc1); camera1->setViewport(new osg::Viewport(traits1->x, traits1->y,traits1->width,traits1->height)); camera1->setProjectionMatrixAsPerspective(30.3f, static_cast<double>(traits1->width) / static_cast<double>(traits1->height), 1.0, 1000.0); mViewer->setCamera(camera1); mViewer->setCameraManipulator(new osgGA::TrackballManipulator); mViewer->setSceneData(mRoot); mViewer->realize(); mViewer->getCamera()->setComputeNearFarMode(osg::CullSettings::COMPUTE_NEAR_USING_PRIMITIVES); mViewer->getCamera()->setNearFarRatio(0.000003f); } void COSGObject::PreFrameUpdate() { } void COSGObject::PostFrameUpdate() { } void COSGObject::Render(void* ptr) { COSGObject* osgObj = (COSGObject*)ptr; osgViewer::Viewer* viewer1 = osgObj->getOsgViewer(); while (!viewer1->done()) { osgObj->PreFrameUpdate(); viewer1->frame(); osgObj->PostFrameUpdate(); } _endthread(); } osgViewer::Viewer* COSGObject::getOsgViewer() { return mViewer; }
QQ 3087438119