OGRE为我们提供了自动生成LOD模型的工具,请参看我的另外一篇文章。但有时候由于该工具生成的自动LOD模型有问题(其原理就是模型简化,比如树模型有很多叶子面片,基本上无论如何简化,面片数都不会有明显的减少,而且将枝干简化后模型会严重形变),针对这种情况,我们可以在建模的时候手工进行模型简化,即导出多个不同精细度模型,然后通过下面的代码加入到OGRE里,程序在判断你指定的摄像机距离的时候就会自动将模型替换。
出处:http://blog.sina.com.cn/s/blog_6250d5a101015yrh.html
Levels ofDetail,意为多细节层次,LOD技术指根据物体模型的节点在显示环境中所处的位置和重要度,决定物体渲染的资源分配,降低非重要物体的面数和细节度,从而获得高效率的渲染运算。
Ogre的网格可以在建模软件中设置LOD,也可以在程序中自定义,注意如果一个mesh文件的LOD等级大于1的话就不能被自定义LOD
在Ogre中可以通过Mesh接口来自定义LOD级别,Ogre会根据用户定义的LOD级别以及摄像机与模型的距离自动给出相应的LOD模型
//载入初始网格
MeshPtrmesh=MeshManager::getSingleton().load("athene.mesh",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
//创建LOD模型,第一个参数是和摄像机的距离,第二个是LOD模型资源
mesh->createManualLodLevel(250,"athene_LOD1.mesh");
mesh->createManualLodLevel(500,"athene_LOD2.mesh");
//创建实体
m_entity=render->m_sm->createEntity(mesh->getName());
m_node=render->m_sm->getRootSceneNode()->createChildSceneNode();
m_node->attachObject(m_entity);
m_node->scale(0.1f,0.1f,0.1f);
m_node->setPosition(0.0f,500.0f,0.0f);