|
本帖最后由 abc-osg 于 2014-10-23 08:45 编辑
一共有5个区域 每个区域分别有80个模型(2级)经过合并后 给plod调度:
1 该显示的模型不显示
2 近距离显示的模型应带有贴图,而没有
下面是模型合并代码:
void cOSG::combineModel(CString strFilepath,CString strNodeName)
{
osg::ref_ptr<osg::Group> result=new osg::Group;
CString szDir = strFilepath;
double x,y,z;
if(szDir.Right(1) != "\\")
szDir += "\\";
szDir += "*.osg";
CFileFind Finder;
BOOL res = Finder.FindFile(szDir);
try
{
while(res)
{
res = Finder.FindNextFile();
CString strPath = Finder.GetFilePath(); //得到全路径名
CString strTitle = Finder.GetFileTitle(); //得到不带后缀文件名
CString str3dsName=strPath.Left(strPath.GetLength()-4);
str3dsName+=".3ds";
osg::ref_ptr<osg::Group> group=new osg::Group;
osg::ref_ptr<osg::Node> mModel= osgDB::readNodeFile(strPath.GetBuffer(0));
osg::ref_ptr<osg::Node> mModel3dx= osgDB::readNodeFile(str3dsName.GetBuffer(0));
osg::ref_ptr<osg:: PagedLOD> page = new osg:: PagedLOD();
page->setCenterMode( osg:: PagedLOD::USER_DEFINED_CENTER );
if(mModel&&mModel3dx)
{
osg::BoundingSphere bs=mModel->computeBound();
osg::Vec3 newCenter=bs.center();
double radius=bs.radius();
x=newCenter.x();
y=newCenter.y();
page->setCenter(osg::Vec3(x,y,0));
page->setName(strTitle.GetBuffer(0));
page->setRadius(radius);
page->addChild(mModel,0,500);
page->addChild(mModel3dx,500,1000);
}
if(mModel&&!mModel3dx)
{
osg::BoundingSphere bs=mModel->computeBound();
osg::Vec3 newCenter=bs.center();
double radius=bs.radius();
x=newCenter.x();
y=newCenter.y();
page->setCenter(osg::Vec3(x,y,0));
page->setName(strTitle.GetBuffer(0));
page->setRadius(radius);
page->addChild(mModel,0,500);
}
if(!mModel&&mModel3dx)
{
osg::BoundingSphere bs=mModel3dx->computeBound();
osg::Vec3 newCenter=bs.center();
double radius=bs.radius();
x=newCenter.x();
y=newCenter.y();
page->setCenter(osg::Vec3(x,y,0));
page->setName(strTitle.GetBuffer(0));
page->setRadius(radius);
//page->addChild(mModel,0,500);
page->addChild(mModel3dx,500,1000);
}
if(page->getNumChildren()>0)
{
group->addChild(page);
result->addChild(group);
}
}
}
catch(...)
{
return;
}
if(result->getNumChildren()>0)
{
CString strosgfile,strdbfile;
strosgfile=strFilepath;
strosgfile+=strNodeName;
strosgfile+=".osg";
strdbfile=strFilepath;
strdbfile+=strNodeName;
strdbfile+=".db";
osgDB::writeNodeFile(*(result.get()),strosgfile.GetBuffer(0));
x=result->getBound().center().x();
y=result->getBound().center().y();
z=result->getBound().center().z();
double radius=result->getBound().radius();
CFile file(strdbfile, CFile::modeCreate|CFile::modeWrite);
file.Write(&x,sizeof(double));
file.Write(&y,sizeof(double));
file.Write(&z,sizeof(double));
file.Write(&radius,sizeof(double));
file.Close();
}
}
外面调度的代码:
x y radius从文件里面读取过,正确
osg::ref_ptr<osg:: PagedLOD> page = new osg:: PagedLOD();
page->setName(strTitle.GetBuffer(0));
page->setCenterMode(osg:: PagedLOD::USER_DEFINED_CENTER );
//设置中心位置
page->setCenter(osg::Vec3(x,y,0));
//添加节点,设置0级的内容为cow.osg
page->setFileName(0,strPath.GetBuffer(0));//cow.osg");
//设置可视setCenter变化范围为0.0f-50.0f
page->setRange(0,0.0f,4000.0f);
page->setRadius(distance);
other->addChild(page);
测试环境:cpu i3 显卡 geoforce GTX 750显存2g 内存 4g
这样就出现描述的问题
是文件合并有问题 还是外面调度有问题?
高手 请指示 |
|