7.OsgEarth加载Obj模型

愿你出走半生,归来仍是少年!

        除了大面积的倾斜摄影的加载,同时还存在单个模型的加载。常用的obj模型作为单体在三维场景中的呈现。

        原理类似于6.OsgEarth加载倾斜摄影-CSDN博客中的倾斜加载。

1.代码

        通过osg读取文件作为节点添加到GeoTransform节点中,然后将节点添加到ModelLayer中进行加载。

        osgDB::Options("noRotation")可保证obj模型加载到场景中后不会被自动旋转90°。

        osgEarth::Registry::shaderGenerator().run(node)保证纹理。

osg::ref_ptr<osgEarth::ModelLayer> Cv::LayerFactory::CreateObjModelLayer(std::string fileFullName, const  SpatialReference* srs, double x, double y, double z)
{
	osg::ref_ptr<osgEarth::GeoTransform> xform = new osgEarth::GeoTransform();
	 

	bool exist = FileUtility::exist(fileFullName);

	osgEarth::GeoPoint position(srs, x, y, z);

	auto pos4326 = position.transform(SpatialReference::get("wgs84"));

	//设置文件读取不旋转
	osg::ref_ptr<osgDB::Options> options = new osgDB::Options("noRotation");


	auto node = osgDB::readNodeFile(fileFullName, options);
	 
	osgEarth::Registry::shaderGenerator().run(node);

	xform->addChild(node);

	xform->setPosition(pos4326);


	ref_ptr<osgEarth::ModelLayer> modelLayer = new osgEarth::ModelLayer();


	string lyName = Utilitys::FileUtility::getNameWithoutType(fileFullName);

	modelLayer->setLocation(pos4326);

	modelLayer->setNode(xform);

	modelLayer->setName(lyName);
	  
	 
	return modelLayer;
}



2.效果

obj单体加载

        

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

就是那个帕吉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值