日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

osg模型调整

發(fā)布時間:2024/1/1 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 osg模型调整 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

osg模型調(diào)整光照以及模型閃爍問題[z-lighting]

0 模型閃爍原因推測

  • 1 關(guān)于模型閃爍的問題,很可能是由于坐標(biāo)的值的有效位數(shù)超過了7位,目前的opengl的gpu渲染(老一點的顯卡以及gl)都是以單精度來渲染點的位置的,所以如果坐標(biāo)很大,很可能導(dǎo)致單精度無法精確表示有效位數(shù)超過7位的數(shù)據(jù),然后發(fā)生截斷。
  • 2 關(guān)于z-lighting的問題,嘗試了網(wǎng)上大多數(shù)的方法:可以使用osg封裝的polygonOffset來避免重疊面片交替出現(xiàn)的問題,當(dāng)然最好的方案是找的模型本身重疊面片就少

1 meshlab手動調(diào)模型

filters->Normals,curve,orientations->transform…

2 使用osg降低模型的點的坐標(biāo)大小

osg::Vec3f center1 = TerrainM1->getBound().center();float radius1 = TerrainM1->getBound().radius();osg::Vec3f center2 = TerrainM2->getBound().center();float radius2 = TerrainM2->getBound().radius();TerrainM1->setMatrix(osg::Matrix::translate(-center1.x(), -center1.y(), -center1.z()) *osg::Matrix::rotate(osg::DegreesToRadians(180.0), 1, 0, 0) *osg::Matrix::translate(center1.x(), center1.y(), center1.z()) *osg::Matrix::translate(0, 0, radius2 * 0.80 + radius1));// to modify the model's points render valuemRoot->getChild(0)->asTransform()->asMatrixTransform()->setMatrix(osg::Matrix::translate(-center1.x(), -center1.y(), -center1.z()));osgDB::writeNodeFile(*(mRoot->getChild(0)->asNode()), "sc.obj");

3 關(guān)于材質(zhì),光照,以及模型讀寫旋轉(zhuǎn)平移的例子

關(guān)于材料的顏色光照等可以參考https://learnopengl-cn.readthedocs.io/zh/latest/02%20Lighting/03%20Materials/

// mRoot是一個osg::ref_ptr<osg::Group>auto TerrainM1 = new osg::MatrixTransform;auto terrain1 = new osg::PositionAttitudeTransform;auto TerrainM2 = new osg::MatrixTransform;auto terrain2 = new osg::PositionAttitudeTransform;osgDB::Options *a = new osgDB::Options(std::string("noRotation")); // 關(guān)掉模型優(yōu)化繪制(OSG在加載obj模型的時候,會默認(rèn)將模型繞x軸逆時針旋轉(zhuǎn)90度,此處設(shè)置不旋轉(zhuǎn))// setting materialosg::Material *material = new osg::Material;material->setDiffuse(osg::Material::FRONT, osg::Vec4(0.75, 0.80, 0.75, 1.0));material->setAmbient(osg::Material::FRONT, osg::Vec4(0.75, 0.80, 0.75, 1.0));// material->setShininess(osg::Material::FRONT, 90.0);// turn off light effectauto Model1 = osgDB::readNodeFile(part1Path, a);auto pState1 = Model1->getOrCreateStateSet();pState1->setMode(GL_LIGHTING, osg::StateAttribute::ON);pState1->setAttribute(material);// pState1->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);// pState1->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);// set polygon offsetosg::ref_ptr<osg::PolygonOffset> polyOff = new osg::PolygonOffset();float mFactor = 1.0, mUnits = 1.0;polyOff->setFactor(mFactor);polyOff->setUnits(mUnits);pState1->setAttributeAndModes(new osg::PolygonOffset(-1.0f,-1.0f),osg::StateAttribute::ON);material->setEmission(osg::Material::FRONT, osg::Vec4(0.75, 0.80, 0.75, 1.0));// pState1->setAttributeAndModes(polyOff.get(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);// auto pGeom1 = Model1->asGeode()->asGeometry();// pGeom1->getOrCreateStateSet()->setMode(GL_NV_framebuffer_multisample_coverage, osg::StateAttribute::ON | osg::StateAttribute::PROTECTED | osg::StateAttribute::OVERRIDE);TerrainM1->addChild(Model1);TerrainM1->setName(modelPrefix + "1");auto Model2 = osgDB::readNodeFile(part2Path, a);auto pState2 = Model2->getOrCreateStateSet();pState2->setMode(GL_LIGHTING, osg::StateAttribute::ON);pState2->setAttribute(material);pState2->setMode(GL_BLEND, osg::StateAttribute::ON);TerrainM2->addChild(Model2);TerrainM2->setName(modelPrefix + "2");// rotate to make sure the building is standing on the groundosg::Vec3f center1 = TerrainM1->getBound().center();float radius1 = TerrainM1->getBound().radius();osg::Vec3f center2 = TerrainM2->getBound().center();float radius2 = TerrainM2->getBound().radius();TerrainM1->setMatrix(osg::Matrix::translate(-center1.x(), -center1.y(), -center1.z()) *osg::Matrix::rotate(osg::DegreesToRadians(180.0), 1, 0, 0) *osg::Matrix::translate(center1.x(), center1.y(), center1.z()) *osg::Matrix::translate(0, 0, radius2 * 0.80 + radius1));mRoot->addChild(TerrainM1);TerrainM2->setMatrix(osg::Matrix::translate(-center2.x(), -center2.y(), -center2.z()) *osg::Matrix::rotate(osg::DegreesToRadians(180.0), 1, 0, 0) *osg::Matrix::translate(center2.x(), center2.y(), center2.z()) *osg::Matrix::translate(0, 0, 0.5 * radius2));mRoot->addChild(TerrainM2);// to modify the model's points render valuemRoot->getChild(0)->asTransform()->asMatrixTransform()->setMatrix(osg::Matrix::translate(-center1.x(), -center1.y(), -center1.z()));mRoot->getChild(1)->asTransform()->asMatrixTransform()->setMatrix(osg::Matrix::translate(-center1.x(), -center1.y(), -center1.z()));mRoot->getChild(4)->asTransform()->asMatrixTransform()->setMatrix(osg::Matrix::translate(-center1.x(), -center1.y(), -center1.z()));mRoot->getChild(5)->asTransform()->asMatrixTransform()->setMatrix(osg::Matrix::translate(-center1.x(), -center1.y(), -center1.z()));osgDB::writeNodeFile(*(mRoot->getChild(0)->asNode()), "sc.obj");osgDB::writeNodeFile(*(mRoot->getChild(1)->asNode()), "de.obj");osgDB::writeNodeFile(*(mRoot->getChild(4)->asNode()), "par1.obj");osgDB::writeNodeFile(*(mRoot->getChild(5)->asNode()), "par2.obj");

總結(jié)

以上是生活随笔為你收集整理的osg模型调整的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。