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();
				}
			}
		}
	}
}
展开阅读全文
©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客
应支付0元
点击重新获取
扫码支付

支付成功即可阅读