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();
				}
			}
		}
	}
}

你可能感兴趣的:(Ogre)