使用产品:https://github.com/SuperMap/s3m-spec
操作系统:win10 x64
数据类型:.obj(S3M_SDK\SampleData\cyt_model)
问题详情描述:下载贵公司S3M_SDK源码,编译样例代码,运行样例3代码:
设置Altizure数据作为源路径,设置s3mb缓路径,将Altizure以Ro的方式写入到s3mb中。
执行到:UGFileParseModel* pFileParser = (UGFileParseModel*)UGFileParseManager::CreateFileParser(nFileType);
报错,pFileParser =null
int main(int argc, char* argv[])
{
UGString jsonFileName = _U("..\\SampleData\\cyt_model\\config.json");
UGString outputFolder = _U("..\\SampleData\\cyt_models3mb");
S3MBWriter m_S3MBWriter;
m_S3MBWriter.SetJsonFileName(jsonFileName);
m_S3MBWriter.SetOutPutFolder(outputFolder);
m_S3MBWriter.AltizureTOS3MB();
}
UGbool S3MBWriter::AltizureTOS3MB()
{
//使用 UGJsonUtils获取json信息
UGJsonUtils objJsonUtils;
objJsonUtils.SetFileName(m_jsonFileName);
objJsonUtils.ParseJson();
UGint lodNum = objJsonUtils.GetLodNum();
UGint tileLength = objJsonUtils.GetTileLength();
UGPoint3D postion = objJsonUtils.GetPostion();
EmPrjCoordSysType priCoordSysType = objJsonUtils.GetProjection();
//通过AltizureToS3MB生成 S3MB缓存文件
AltizureToS3MB altizureToS3MB;
altizureToS3MB.SetFileName(m_jsonFileName);
altizureToS3MB.SetOutputFilePath(m_outputFolder);
altizureToS3MB.SetLodNum(lodNum);
altizureToS3MB.SetTileLength(tileLength);
altizureToS3MB.SetPostion(postion);
altizureToS3MB.SetProjection(priCoordSysType);
altizureToS3MB.GenerateS3MB();
altizureToS3MB.GenerateScp();
return TRUE;
}
void AltizureToS3MB::GenerateS3MB()
{
UGStringEx strMessage;
strMessage.LoadResString(UGS_QUARTER_OBJ_TO_S3MB_EXPORT);
m_nTotalRecCount = pow(2, nLodNum * 2) - 1;
// 建立四分树
MakeQuarterTree();
// 生成S3M
strMessage.LoadResString(UGS_QUARTER_OBJ_TO_S3MB_TREE);
m_nCurrentIndex = 0;
m_nPrecent = 0;
Convert2RO(m_pTreeNode);
m_nTotalRecCount = 0;
m_nPrecent = 0;
m_nCurrentIndex = 0;
}
void AltizureToS3MB::WriteRO(UGRenderOperationGroup* pGroup, const UGString strDesFile)
{
// 四合一存S3M
UGFileParser* pFileParserS3M = UGFileParseManager::CreateFileParser(UGFileType::S3MB);
if(pFileParserS3M == NULL)
{
UGASSERT(FALSE);
return;
}
UGExportParams params;
params.SetFilePathName(strDesFile);
((UGFileParseModel*)pFileParserS3M)->Save(params, pGroup);
delete pFileParserS3M;
pFileParserS3M = NULL;
}
void AltizureToS3MB::Convert2RO(OBJLodQuarterTreeNode* pNode)
{
if(pNode == NULL)
{
return;
}
UGuint nSize = pNode->childs.size();
if(nSize == 0)
{
m_nCurrentIndex++;
m_nPrecent = (m_nCurrentIndex / m_nTotalRecCount)*100;
return;
}
UGBoundingBox bboxMerged;
UGRenderOperationGroup* pGroup = new UGRenderOperationGroup();
// 把四分的子节点,合并成一层
for(UGuint i=0; i<nSize; i++)
{
OBJLodQuarterTreeNode* pChildNode = pNode->childs[i];
//填充 pGeodeObj
UGString strObjFileName = pChildNode->strFileName;
UGString strFullPath = UGFile::GetAbsolutePath(UGFile::GetDir(strConfigJson), strObjFileName);
UGRenderOperationGroup* pGroupObj = GetRO(strFullPath);
if(pGroupObj == NULL)
{
continue;
}
UGRenderOperationPagedLOD* pPagedLOD = new UGRenderOperationPagedLOD();
UGRenderOperationGeode* pGeodeObj = new UGRenderOperationGeode();
pGroup->AddChild(pPagedLOD);
pPagedLOD->AddChild(pGeodeObj);
AppendRO(pGroupObj, pGroup, pGeodeObj);
// 包围盒
pGeodeObj->ComputerBoundingBox();
UGBoundingBox bboxObj = pGeodeObj->GetBoundingBox();
bboxMerged.Merge(bboxObj);
UGBoundingSphere bSphere(bboxObj);
pGeodeObj->SetBoudingSphere(bSphere.GetCenter(), bSphere.GetRadius());
//对应的切换文件
UGString strLodFile = UGFile::ChangeExt(pNode->childs[i]->strFileName, _U(".s3mb"));
pPagedLOD->GetFileNames().push_back(strLodFile);
pPagedLOD->SetRangeMode(UGRangeMode::PIXEL_SIZE_ON_SCREEN);
// 计算LOD变换的距离
UGdouble nLodDis = UGMIN(1024, bSphere.m_radius * pow(2.0, (nLodNum - pNode->nLod - 1)));
pPagedLOD->GetRanges().push_back(std::vector<std::pair<UGfloat, UGfloat> >::value_type(0, nLodDis));
pPagedLOD->SetBoudingSphere(bSphere.m_center, bSphere.m_radius);
}
if(pGroup->GetNumChildren() == 0)
{
return;
}
// 清空精细层的patch
pNode->boundBox = bboxMerged;
UGString strS3MFilePath = UGFile::GetAbsolutePath(strOutputFilePath, pNode->strFileName);
strS3MFilePath = UGFile::ChangeExt(strS3MFilePath, _U(".s3mb"));
WriteRO(pGroup, strS3MFilePath);
delete pGroup;
pGroup = NULL;
m_nCurrentIndex++;
m_nPrecent = (m_nCurrentIndex / m_nTotalRecCount)*100;
//处理子节点
for(UGuint i=0; i<nSize; i++)
{
Convert2RO(pNode->childs[i]);
}
}
UGRenderOperationGroup* AltizureToS3MB::GetRO(const UGString strObjFile)
{
UGModelImportParams params;
params.SetFilePathName(strObjFile);
params.SetImportMode(UGImportParams::ModeOnlyReadOSG);
UGint nFileType = params.GetFileType();
UGFileParseModel* pFileParser = (UGFileParseModel*)UGFileParseManager::CreateFileParser(nFileType);
pFileParser->SetParseModelNode(FALSE);
pFileParser->SetIgnoreLod(TRUE);
if(!pFileParser->Open(params))
{
delete pFileParser;
pFileParser = NULL;
return NULL;
}
UGRenderOperationGroup* pGroup = NULL;
pFileParser->GetRenderOperationGroup(pGroup);
delete pFileParser;
pFileParser = NULL;
return pGroup;
}
问题重现步骤: 1.编译源码2.运行代码3.报错