Ogre實現已有的組中動態添加資源

 在Ogre已有的組中動態添加資源,發現添加後顯示不出效果,後來查了原因發現需要重新解析一下material。

實現的代碼:

void addRes(std::string groupName, std::string path)
{
   bool ret = Ogre::ResourceGroupManager::getSingleton().resourceGroupExists(groupName);
   if (!ret)
	{
		Ogre::ResourceGroupManager::getSingleton().createResourceGroup(groupName);
		Ogre::ResourceGroupManager::getSingleton().addResourceLocation(path, "Zip", groupName);
		Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup(groupName);

	}
	else
	{
		//是否已存在組中
		ret = Ogre::ResourceGroupManager::getSingleton().resourceLocationExists(path, groupName);
		if (!ret)
		{
			Ogre::ResourceGroupManager::getSingleton().addResourceLocation(path, "Zip", groupName);
			Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup(groupName);

			//解析material
			Ogre::FileInfoListPtr fiList = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(groupName, "*.material");
			for (Ogre::FileInfoList::const_iterator iter = fiList->begin(); iter != fiList->end(); ++iter)
			{
				const Ogre::String& basename = iter->basename;
				Ogre::String type = iter->archive->getType();
				Ogre::String path_ = iter->archive->getName();
				if (type == "Zip" && path_ == path)
				{
					Ogre::DataStreamPtr pData =
							Ogre::ResourceGroupManager::getSingleton().openResource(basename,groupName);
					Ogre::MaterialManager::getSingleton().parseScript(pData, groupName);
					pData->close();
				}
			}
		}
	}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章