示例#1
0
文件: SoundTrack.cpp 项目: angulo/ogf
void
SoundTrack::loadImpl()
{
	Log *errorLog = OGF::LogFactory::getSingletonPtr()->get(OGF::LOG_ERR);

	Ogre::FileInfoListPtr resourceInfo = Ogre::ResourceGroupManager::getSingletonPtr()->findResourceFileInfo(mGroup, mName);

	for(Ogre::FileInfoList::iterator it = resourceInfo->begin(); it != resourceInfo->end(); it++)
		_path = it->archive->getName() + "/" + it->filename;
	
	if (_path == "") {
		std::string errorMessage = "Impossible to find sound resource: " + mName;
		errorLog->log("SoundTrack", "loadImpl", errorMessage, OGF::LOG_SEVERITY_ERROR);
		throw errorMessage;
	}

	if ((_playableSource = Mix_LoadMUS(_path.c_str())) == NULL) {
		std::string errorMessage = "Impossible to load sound resource: " + _path;
		errorLog->log("SoundTrack", "loadImpl", errorMessage, OGF::LOG_SEVERITY_ERROR);
		throw errorMessage;
	}

	// Calculate size
	std::ifstream stream;
	stream.open(_path.c_str(), std::ios_base::binary);
	char temp;

	while (stream >> temp)
		_size++;

	stream.close();
}
	const VectorString& OgreDataManager::getDataListNames(const std::string& _pattern, bool _fullpath)
	{
		static VectorString result;
		result.clear();

		Ogre::FileInfoListPtr pFileInfo = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(mGroup, _pattern);

		result.reserve(pFileInfo->size());

		for (Ogre::FileInfoList::iterator fi = pFileInfo->begin(); fi != pFileInfo->end(); ++fi )
		{
			if (fi->path.empty())
			{
				bool found = false;
				for (VectorString::iterator iter = result.begin(); iter != result.end(); ++iter)
				{
					if (*iter == fi->filename)
					{
						found = true;
						break;
					}
				}
				if (!found)
				{
					result.push_back(_fullpath ? fi->archive->getName() + "/" + fi->filename : fi->filename);
				}

			}
		}

		pFileInfo.setNull();

		return result;
	}
示例#3
0
void SoundFX::loadImpl() {
  Ogre::LogManager* pLogManager = Ogre::LogManager::getSingletonPtr();

  // Ruta al archivo.
  Ogre::FileInfoListPtr info;
  info = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(mGroup, mName);
  for (Ogre::FileInfoList::iterator i = info->begin(); i != info->end(); ++i) {
    _path = i->archive->getName() + "/" + i->filename;
  }
  
  // Archivo no encontrado...
  if (_path == "") {
    pLogManager->logMessage("SoundFX::loadImpl() Imposible encontrar el recurso.");
    throw (Ogre::Exception(Ogre::Exception::ERR_FILE_NOT_FOUND,
			   "Imposible encontrar el recurso", "SoundFX::loadImpl()"));
  }
  
  // Cargar el efecto de sonido.
  if ((_pSound = Mix_LoadWAV(_path.c_str())) == NULL) {
    pLogManager->logMessage("SoundFX::loadImpl() Imposible cargar el efecto.");
    throw (Ogre::Exception(Ogre::Exception::ERR_INTERNAL_ERROR,
			   "Imposible cargar el efecto", "SoundFX::loadImpl()"));
  }
  
  // Cálculo del tamaño del recurso de sonido.
  std::ifstream stream;
  char byteBuffer;
  stream.open(_path.c_str(), std::ios_base::binary);
  
  while (stream >> byteBuffer) {
    ++_size;
  }
  
  stream.close();
}
示例#4
0
	const VectorString& Ogre2DataManager::getDataListNames(const std::string& _pattern, bool _fullpath)
	{
		static VectorString result;
		result.clear();

		VectorString search;
		if (mAllGroups)
		{
			Ogre::StringVector sp = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
			search.reserve(sp.size());
			for (size_t i = 0; i < sp.size(); i++)
				search.push_back(sp[i]);
		}
		else
			search.push_back(mGroup);

		std::vector<Ogre::FileInfoListPtr> pFileInfos;

		int resultSize = 0;
		for (size_t i = 0; i < search.size(); i++)
		{
			Ogre::FileInfoListPtr pFileInfo = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(search[i], _pattern);
			resultSize += pFileInfo->size();
			if (!pFileInfo->empty())
				pFileInfos.push_back(pFileInfo);
			else
				pFileInfo.setNull();
		}

		result.reserve(resultSize);

		for (size_t i = 0; i < pFileInfos.size(); i++)
		{
			Ogre::FileInfoListPtr pFileInfo = pFileInfos[i];
			for (Ogre::FileInfoList::iterator fi = pFileInfo->begin(); fi != pFileInfo->end(); ++fi )
			{
				if (fi->path.empty())
				{
					bool found = false;
					for (VectorString::iterator iter = result.begin(); iter != result.end(); ++iter)
					{
						if (*iter == fi->filename)
						{
							found = true;
							break;
						}
					}
					if (!found)
					{
						result.push_back(_fullpath ? fi->archive->getName() + "/" + fi->filename : fi->filename);
					}
				}
			}

			pFileInfo.setNull();
		}

		return result;
	}
示例#5
0
//-----------------------------------------------------------------------------------------
void CTerrainGroupEditorFactory::addEditorResources(bool changeDefaultNames)
{
    OgitorsRoot* ogitorsRoot = OgitorsRoot::getSingletonPtr();
    Ogre::String terrainDir = ogitorsRoot->GetProjectOptions()->TerrainDirectory;
    // create Terrain project folder and folder to hold the terrain
    ogitorsRoot->GetProjectFile()->createDirectory(terrainDir.c_str());
    ogitorsRoot->GetProjectFile()->createDirectory((terrainDir+"/terrain/").c_str());

    // copy default plant textures
    ogitorsRoot->GetProjectFile()->createDirectory((terrainDir+"/plants/").c_str());
    Ogre::String copydir = Ogitors::Globals::MEDIA_PATH + "/plants/";
    OgitorsUtils::CopyDirOfs(copydir, (terrainDir+"/plants/").c_str());

    // copy default terrain textures sorting them into two different folders
    ogitorsRoot->GetProjectFile()->createDirectory((terrainDir+"/textures/").c_str());
    ogitorsRoot->GetProjectFile()->createDirectory((terrainDir+"/textures/diffusespecular").c_str());
    ogitorsRoot->GetProjectFile()->createDirectory((terrainDir+"/textures/normalheight").c_str());

    Ogre::ResourceGroupManager *mngr = Ogre::ResourceGroupManager::getSingletonPtr();
    copydir = Ogitors::Globals::MEDIA_PATH + "/terrainTextures/";
    mngr->addResourceLocation(copydir,"FileSystem","CopyTerrain");

    Ogre::FileInfoListPtr resList = mngr->listResourceFileInfo("CopyTerrain");

    // copy the files to the different directories
    OFS::OfsPtr& file = ogitorsRoot->GetProjectFile();
    for (Ogre::FileInfoList::const_iterator it = resList->begin(); it != resList->end(); ++it)
    {
        Ogre::FileInfo fInfo = (*it);
        Ogre::String loc = copydir + fInfo.path + fInfo.filename;
        Ogre::String newName = fInfo.filename;
        
        if(fInfo.archive->getType() == "FileSystem")
        {
            if(fInfo.filename.find("diffusespecular") != -1)
            {
                /* since we're using different resource groups for the terrain lets
                remove the naming scheme from the filenames except if the project
                is being upgraded, in which case leave the name alone. */
                if (changeDefaultNames) {
                    newName = Ogre::StringUtil::replaceAll(newName, "_diffusespecular", "");
                }
                OgitorsUtils::CopyFileOfs(loc, terrainDir+"/textures/diffusespecular/"+newName);
            }
            
            if(fInfo.filename.find("normalheight") != -1)
            {
                if (changeDefaultNames) {
                    newName = Ogre::StringUtil::replaceAll(newName, "_normalheight", "");
                }
                OgitorsUtils::CopyFileOfs(loc, terrainDir+"/textures/normalheight/"+newName);
            }
        }
    }
    resList.setNull();
    
    ogitorsRoot->DestroyResourceGroup("CopyTerrain");
}
void
ObjectPropertyEditor::onSelectObject(const Fairy::ObjectPtr& object)
{
    mPropertiesViewer->GetGrid()->Clear();
    mCurrentObject = object;

	if (mObjNameList.GetCount()<=0)
	{
		Ogre::FileInfoListPtr fileInfoList =
			Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(
			Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			"*.obj");

		for(Ogre::FileInfoList::const_iterator it = fileInfoList->begin(); it != fileInfoList->end(); ++it)
		{	
			const Ogre::String name = it->filename;
			mObjNameList.AddString(name.c_str());
		}
	}

    const Fairy::PropertyList& properties = object->getProperties();
    for (Fairy::PropertyList::const_iterator it = properties.begin(); it != properties.end(); ++it)
    {
        const Fairy::PropertyDef& propertyDef = *it;
        Fairy::uint propertyFlags = object->getPropertyFlags(propertyDef.name);	
		wxPGId id;
		if (propertyDef.name == "actor name")
		{
			wxPGProperty* property = NULL;
			wxString name = propertyDef.name.c_str();
			property = wxEnumProperty(name, name, mObjNameList);
			property->SetValueFromString(propertyDef.defaultValue.c_str(),0);
			id = AddPropertyRecursive(property);
		}
		else
		{
			id = AddPropertyRecursive(mPropertyManager->CreateProperty(propertyDef));
		}
			
		wxPGIdToPtr(id)->SetValueFromString(AS_STRING(object->getPropertyAsString(propertyDef.name)), wxPG_FULL_VALUE);
		
		if (propertyFlags & Fairy::PF_READONLY)
        {
            mPropertiesViewer->DisableProperty(id);
        }
    }

    mPropertiesViewer->Refresh();
}
示例#7
0
std::vector<std::wstring> ManipulatorEffect::GetAttachEffectMeshNames()
{
	std::vector<std::wstring> ret;

	Ogre::FileInfoListPtr fileinfo = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(
		"Effect", "*.mesh");

	for(auto iter=fileinfo->begin(); iter!=fileinfo->end(); ++iter)
	{
		const Ogre::FileInfo& info = *iter;
		ret.push_back(Utility::EngineToUnicode(info.basename));
	}

	return std::move(ret);
}
示例#8
0
    /* Always get the actual pointers, because they may change. That is the reason why the datablock pointer cannot be cached.
     * The same seems to apply to the texture pointer.
     */
    Ogre::HlmsDatablock* datablock;
    Ogre::HlmsPbsDatablock* datablockPbs;
    Ogre::TexturePtr texture;
    Ogre::HlmsManager* hlmsManager = Ogre::Root::getSingletonPtr()->getHlmsManager();
    Ogre::HlmsPbs* hlmsPbs = static_cast<Ogre::HlmsPbs*>(hlmsManager->getHlms(Ogre::HLMS_PBS));
    datablock = hlmsPbs->getDatablock(mDatablockId);
    if (!datablock)
        return;

    datablockPbs = static_cast<Ogre::HlmsPbsDatablock*>(datablock);
    try
    {
        // Get texture on GPU
        if (!datablockPbs->getTexture(mTextureType).isNull())
        {
            texture = datablockPbs->getTexture(mTextureType); // TextureType MUST exist, otherwise the application crashes
            mNumMipMaps = texture->getNumMipmaps();
        }
    }
    catch (Ogre::Exception e){}

    if (texture.isNull())
        return;

    Ogre::uint8 maxMipMaps = mNumMipMaps + 1; // Increase with one, because there is always one image to blit
    maxMipMaps = maxMipMaps > PAINT_MAX_MIP_MAPS ? PAINT_MAX_MIP_MAPS : maxMipMaps; // Just paint a few mipmaps (not all)
    Ogre::Image textureOnWhichIsPaintedScaled = mTextureOnWhichIsPainted; // Temporary image must be used, otherwise painting doesn't work
    size_t w = mTextureOnWhichIsPaintedWidth;
    size_t h = mTextureOnWhichIsPaintedHeight;
    Ogre::v1::HardwarePixelBuffer* buffer;
    for (Ogre::uint8 i = 0; i < maxMipMaps; ++i)
    {
        buffer = texture->getBuffer(0, i).getPointer();
        buffer->blitFromMemory(textureOnWhichIsPaintedScaled.getPixelBox(0, 0), Ogre::Box(0, 0, 0, w, h, 1));
        w*=0.5f; // Mipmaps always are half of the previous one
        h*=0.5f;
        if (w < 1.0f || h < 1.0f)
            break; // Stop when the mipmaps are too small

        textureOnWhichIsPaintedScaled.resize(w, h);

    }
    textureOnWhichIsPaintedScaled.freeMemory();
}

//****************************************************************************/
void TextureLayer::setFirstTextureGeneration (void)
{
    // Don't check on existence mTextureFileName, because it does exist
    loadTextureGeneration(mTextureFileName);
}

//****************************************************************************/
void TextureLayer::setLastTextureGeneration (void)
{
    Ogre::String textureFileNameGeneration = getTextureFileNameGeneration (mMaxSequence); // returns full qualified filename
    if (textureFileExists(textureFileNameGeneration))
        loadTextureGeneration(textureFileNameGeneration);
}

//****************************************************************************/
void TextureLayer::loadTextureGeneration (Ogre::ushort sequence)
{
    Ogre::String textureFileNameGeneration = getTextureFileNameGeneration (sequence); // returns full qualified filename
    if (sequence == 0)
        loadTextureGeneration(textureFileNameGeneration); // Don't check the filename if sequence is 0, because it is without path
    else if (textureFileExists(textureFileNameGeneration))
        loadTextureGeneration(textureFileNameGeneration);
}

//****************************************************************************/
void TextureLayer::loadTextureGeneration (const Ogre::String& filename)
{
    // Assume the filename exists
    mTextureOnWhichIsPainted.load(filename, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    mPixelboxTextureOnWhichIsPainted = mTextureOnWhichIsPainted.getPixelBox(0, 0);
    mTextureOnWhichIsPaintedHasAlpha = mTextureOnWhichIsPainted.getHasAlpha();
    mTextureOnWhichIsPaintedWidth = mPixelboxTextureOnWhichIsPainted.getWidth();
    mTextureOnWhichIsPaintedHeight = mPixelboxTextureOnWhichIsPainted.getHeight();
    // In theory, createCarbonCopyTexture() of all related paintlayers should be called,
    // but the texture size doesn't change in practice.

    blitTexture();
}

//****************************************************************************/
void TextureLayer::saveTextureGeneration (void)
{
    // Increase the sequence
    ++mMaxSequence;
    Ogre::String textureFileNameGeneration = getTextureFileNameGeneration (mMaxSequence); // returns full qualified filename

    // Saving the Image must be done in the background, otherwise the painting stutters
    QThread* thread = new QThread;
    TextureSaveWorker* textureSaveWorker = new TextureSaveWorker (mTextureOnWhichIsPainted, textureFileNameGeneration);
    textureSaveWorker->moveToThread(thread);
    connect(thread, SIGNAL(started()), textureSaveWorker, SLOT(saveImage()));
    connect(textureSaveWorker, SIGNAL(finished()), thread, SLOT(quit()));
    connect(textureSaveWorker, SIGNAL(finished()), textureSaveWorker, SLOT(deleteLater()));
    connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
    thread->start();
}

//****************************************************************************/
const Ogre::String& TextureLayer::saveTextureWithTimeStampToImportDir (void)
{
    Ogre::String strippedTextureFileName = mTextureFileName;
    Ogre::String extension = mTextureFileName;
    strippedTextureFileName.erase(strippedTextureFileName.find_last_of("."), Ogre::String::npos); // Remove extension
    if (strippedTextureFileName.find("_hlms") != Ogre::String::npos)
        strippedTextureFileName.erase(strippedTextureFileName.find("_hlms"), Ogre::String::npos); // Remove earlier hlms editor additions
    extension.erase(0, extension.find_last_of("."));
    mHelperString = strippedTextureFileName +
            "_hlms" +
            Ogre::StringConverter::toString((size_t)time(0)) +
            extension;

    mTextureOnWhichIsPainted.save(DEFAULT_IMPORT_PATH.toStdString() + mHelperString); // Saving to the import dir doesn't have to be in the background
    return mHelperString; // Return the basename
}

//****************************************************************************/
const Ogre::String& TextureLayer::getTextureFileNameGeneration (int sequence, bool fullQualified)
{
    mHelperString = mTextureFileName;

    // Do not go beyond the max sequence number
    sequence = sequence > mMaxSequence ? mMaxSequence : sequence;
    if (sequence > 0)
    {
        // Do not go below sequence number 1 (otherwise the original mTextureFileName (without path) is returned)
        Ogre::String strippedTextureFileName = mTextureFileName;
        Ogre::String extension = mTextureFileName;
        strippedTextureFileName.erase(strippedTextureFileName.find_last_of("."), Ogre::String::npos);
        extension.erase(0, extension.find_last_of("."));
        mHelperString = strippedTextureFileName +
                Ogre::StringConverter::toString(sequence) +
                extension;

        if (fullQualified)
            mHelperString = TEMP_PATH + mHelperString;
    }

    return mHelperString;
}

//****************************************************************************/
bool TextureLayer::isTextureFileNameDefinedAsResource (const Ogre::String& filename)
{
    Ogre::String path;
    Ogre::FileInfoListPtr list = Ogre::ResourceGroupManager::getSingleton().listResourceFileInfo(Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME) ;
    Ogre::FileInfoList::iterator it;
    Ogre::FileInfoList::iterator itStart = list->begin();
    Ogre::FileInfoList::iterator itEnd = list->end();
    for(it = itStart; it != itEnd; ++it)
    {
        Ogre::FileInfo& fileInfo = (*it);
        if (fileInfo.basename == filename || fileInfo.filename == filename)
            return true;
    }

    return false;
}
示例#9
0
void
ReshapeDialog::ReloadTextureList(void)
{

	if (!Ogre::ResourceGroupManager::getSingletonPtr())
		return;

	Ogre::Codec::CodecIterator it = Ogre::Codec::getCodecIterator();
	while (it.hasMoreElements())
	{
		const Ogre::String& ext = it.peekNextKey();
		Ogre::Codec* codec = it.getNext();
		if (codec->getDataType() != "ImageData")
			continue;

		Ogre::FileInfoListPtr fileInfoList =
			Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(
			AS_STRING(mResourceGroup),
			"*." + ext);
		for (Ogre::FileInfoList::const_iterator it = fileInfoList->begin(); it != fileInfoList->end(); ++it)
		{
			Ogre::String path, baseName;
			Ogre::StringUtil::splitFilename(it->filename, baseName, path);




			// 把相对路径的最后一个/去掉
			if (!path.empty() && path[path.length()-1] == '/')
				path.erase(path.length() - 1);

			Ogre::String value;
			if(path.empty())
			{
				value = baseName;
			}
			else
			{
				value = path + "/" + baseName;
			}

			mCmbTexture->AppendString( wxT(baseName) );

			pathNameMap.insert(make_pair(baseName,value));
		}
	}
}
示例#10
0
const Ogre::StringVector& ManipulatorTerrain::GetAllLayerTexThumbnailNames()
{
	m_vecLayerTex.clear();

	Ogre::FileInfoListPtr fileinfo = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(
		"TerrainTextures", "*.png");

	int i = 0;
	m_vecLayerTex.resize(fileinfo->size());
	for (auto iter=fileinfo->begin(); iter!=fileinfo->end(); ++iter)
	{
		const Ogre::FileInfo& info = (*iter);
		m_vecLayerTex[i++] = info.archive->getName() + "/" + info.filename;
	}

	return m_vecLayerTex;
}
示例#11
0
std::vector<std::wstring> ManipulatorEffect::GetParticleTmpNames() const
{
	std::vector<std::wstring> ret;

	Ogre::FileInfoListPtr fileinfo = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(
		"ParticleUniverse", "*.pu");

	for(auto iter=fileinfo->begin(); iter!=fileinfo->end(); ++iter)
	{
		const Ogre::FileInfo& info = *iter;
		STRING obasename, oextname;
		Ogre::StringUtil::splitBaseFilename(info.basename, obasename, oextname);
		ret.push_back(Utility::EngineToUnicode(obasename));
	}

	return std::move(ret);
}
示例#12
0
std::string AssetsManager::resolveFilePathForMesh(Ogre::MeshPtr meshPtr)
{
	Ogre::ResourceGroupManager& manager = Ogre::ResourceGroupManager::getSingleton();
	const std::multimap<std::string, std::string>& locations = EmberOgre::getSingleton().getResourceLocations();

	for (std::multimap<std::string, std::string>::const_iterator I = locations.begin(); I != locations.end(); ++I) {
		std::string group = I->first;
		std::string fileName = meshPtr->getName();
		Ogre::FileInfoListPtr files = manager.findResourceFileInfo(group, fileName, false);
		for (Ogre::FileInfoList::const_iterator J = files->begin(); J != files->end(); ++J) {
			if (J->filename == fileName) {
				return I->second + J->filename;
			}
		}
	}
	return "";

}
示例#13
0
void SoundBank::openFile(std::string path, std::string id, int index)
{
	std::string foundPath = path;
	Ogre::ResourceGroupManager* groupManager = Ogre::ResourceGroupManager::getSingletonPtr() ;
	Ogre::String group = groupManager->findGroupContainingResource(path) ;
	Ogre::FileInfoListPtr fileInfos = groupManager->findResourceFileInfo(group,foundPath);
	Ogre::FileInfoList::iterator it = fileInfos->begin();
	if(it != fileInfos->end())
	{
		foundPath = it->archive->getName() + "/" + foundPath;
	}
	else
	{
		foundPath = "";
	}

	this->addSound(new SoundChunk(foundPath), id, index);
}
        std::string findFilePath(const std::string& filename)
        {
          // on demand init
          Model::initRessources() ;
          
          std::string foundPath = filename;
          Ogre::ResourceGroupManager* groupManager = Ogre::ResourceGroupManager::getSingletonPtr() ;
          Ogre::String group = groupManager->findGroupContainingResource(filename) ;
          Ogre::FileInfoListPtr fileInfos = groupManager->findResourceFileInfo(group,foundPath);
          Ogre::FileInfoList::iterator it = fileInfos->begin();
          if(it != fileInfos->end())
          {
            foundPath = it->archive->getName() + "/" + foundPath;
            foundPath;
          }
          else
            foundPath = "";

          return foundPath;
        }
void MaterialEditorDialog::InitMaterialCombo(void)
{
	typedef std::list<Ogre::String> MaterialFileNameList;
	MaterialFileNameList materialFileNameList;

	Ogre::FileInfoListPtr fileInfoList =
		Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(
		Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		"*.material");
	for (Ogre::FileInfoList::const_iterator it = fileInfoList->begin(); it != fileInfoList->end(); ++it)
	{
		if ( it->archive->getName() == EFFECT_PATH)
		{
			materialFileNameList.push_back(it->filename);
		}
	}

	Ogre::ResourceManager::ResourceMapIterator resourceMapIterator = Ogre::MaterialManager::getSingleton().getResourceIterator();

	while ( resourceMapIterator.hasMoreElements() )
	{				
		Ogre::String matName = resourceMapIterator.peekNextValue()->getName();

		for ( MaterialFileNameList::iterator i = materialFileNameList.begin();
			i != materialFileNameList.end(); ++i )
		{
			if ( *i == resourceMapIterator.peekNextValue()->getOrigin() )
			{
				mMaterialComboBox->Append(matName);

				break;

			}
		}

		resourceMapIterator.moveNext();
	}

}
示例#16
0
// Carga del recurso.
void Track::loadImpl() {
  Ogre::LogManager* pLogManager = Ogre::LogManager::getSingletonPtr();

  // Ruta al archivo.
  Ogre::FileInfoListPtr info;
  info = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(mGroup, mName);

  for (Ogre::FileInfoList::const_iterator i = info->begin(); i != info->end(); ++i) {
    _path = i->archive->getName() + "/" + i->filename;
  }
 
  // Archivo no encontrado...
  if (_path == "") {
    pLogManager->logMessage("Track::loadImpl() Imposible cargar el recurso de sonido.");
    throw (Ogre::Exception(Ogre::Exception::ERR_FILE_NOT_FOUND,
			   "Archivo no encontrado", "Track::loadImpl()"));
  }
    cout << "\n\nPath: " << _path << "\n\n" << endl;
    // Cargar el recurso de sonido.
    if ((_pTrack = Mix_LoadMUS(_path.c_str())) == NULL) {
      pLogManager->logMessage("Track::loadI() Imposible cargar el recurso de sonido.");
      throw (Ogre::Exception(Ogre::Exception::ERR_FILE_NOT_FOUND,
			     "Archivo no encontrado", "Track::loadI()"));
    }
    
    // Cálculo del tamaño del recurso de sonido.
    std::ifstream stream;
    char byteBuffer;
    stream.open(_path.c_str(), std::ios_base::binary);
 
    while (stream >> byteBuffer) {
      _size++;
    }
    
    stream.close();
}
示例#17
0
void gkDebugScreen::initialize()
{
	if (m_isInit)
		return;

	try
	{

		m_font = new gkBuiltinFont;
		Ogre::FontPtr fp = Ogre::FontManager::getSingleton().create("<gkBuiltin/Font>", GK_BUILTIN_GROUP, true, m_font);
		fp->load();

#define  FONT_MATERIAL 1
#if FONT_MATERIAL

#ifndef OGREKIT_USE_OLD
		gkString ShareMaterail = "Examples/BumpMapping/MultiLight";
		static int Use_Init_Once = 0;
		if(Use_Init_Once < 2)
		{
			Ogre::FileInfoListPtr fileInfoList =
				Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(
				"",
				"*.material");

			for (Ogre::FileInfoList::const_iterator cit=fileInfoList->begin();
				cit != fileInfoList->end();
				++cit) {
					const Ogre::String& name = cit->filename;
					const Ogre::String& basename = cit->basename;
					Ogre::String sType = cit->archive->getType();
					Ogre::String sPath = cit->archive->getName();
					if (sType=="Zip" || sType=="FileSystem") { 
						Ogre::DataStreamPtr pData=
							Ogre::ResourceGroupManager::getSingleton().openResource(
							basename,"");
						Ogre::MaterialManager::getSingleton().parseScript(
							pData, "");
						Ogre::MaterialManager::getSingleton().load(basename,"");
					}
			}
			Use_Init_Once++;
		}	
#endif

		Ogre::MaterialPtr ShareMaterailPtr = Ogre::MaterialManager::getSingleton().getByName(ShareMaterail, "");
		if (!ShareMaterailPtr.isNull())
		{
			ShareMaterailPtr->load();
			//ShareMaterailPtr->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("textureCount",1);
		}

		Ogre::MaterialPtr oma = Ogre::MaterialManager::getSingleton().getByName("Fonts/<gkBuiltin/Font>");

		if (!oma.isNull())
		{
			Ogre::Pass* pass1 = oma->getTechnique(0)->getPass(0);

			Ogre::GpuProgramPtr vsPtr = Ogre::HighLevelGpuProgramManager::getSingleton().getByName("FixVs");

			if (vsPtr.isNull())
			{
				LogManager::getSingleton().logMessage("GpuProgramPtr NULL");
			}

			gkString VertexProgramName = "FixVs";
			gkString FragmentProgramName ="FixPs";

			if (pass1)
			{
				pass1->setVertexProgram(VertexProgramName);
				pass1->setFragmentProgram(FragmentProgramName);
				Ogre::GpuProgramParametersSharedPtr vsParams = pass1->getVertexProgramParameters();
				vsParams->copyMatchingNamedConstantsFrom(*ShareMaterailPtr->getTechnique(0)->getPass(0)->getVertexProgramParameters().get());
				Ogre::GpuProgramParametersSharedPtr psParams = pass1->getFragmentProgramParameters();
				psParams->copyMatchingNamedConstantsFrom(*ShareMaterailPtr->getTechnique(0)->getPass(0)->getFragmentProgramParameters().get());
				//psParams->setNamedConstant("textureCount",1);
				//psParams->setNamedConstant("AlphaValue",0.0f);
				//vsParams->setNamedConstant("lightOpen",0);
				LogManager::getSingleton().logMessage("set font es2.0");
			}
		}
#endif

		Ogre::OverlayManager& mgr = Ogre::OverlayManager::getSingleton();
		m_over  = mgr.create("<gkBuiltin/gkDebugScreen>");
		m_ele   = mgr.createOverlayElement("TextArea", "<gkBuiltin/gkDebugScreen/TextArea>");

		Ogre::OverlayContainer* cont = (Ogre::OverlayContainer*)mgr.createOverlayElement("BorderPanel", "<gkBuiltin/gkDebugScreen/Containter>");
		cont->setMetricsMode(Ogre::GMM_PIXELS);
		cont->setVerticalAlignment(Ogre::GVA_TOP);

		const gkVector2& dims = gkWindowSystem::getSingleton().getMouse()->winsize;

		m_ele->setMetricsMode(Ogre::GMM_PIXELS);
		m_ele->setVerticalAlignment(Ogre::GVA_TOP);
		m_ele->setPosition(0, 0);
		m_ele->setDimensions(dims.x, dims.y);

		Ogre::TextAreaOverlayElement* textArea = static_cast<Ogre::TextAreaOverlayElement*>(m_ele);
		textArea->setFontName("<gkBuiltin/Font>");
		textArea->setCharHeight(SCREEN_SIZE);
		textArea->setColour(Ogre::ColourValue::White);

		m_over->setZOrder(500);
		cont->addChild(m_ele);
		m_over->add2D(cont);
	}
	catch (Ogre::Exception& e)
	{
		gkPrintf("%s", e.getDescription().c_str());
		return;
	}


	m_isInit = true;
	gConsole = this;
}
示例#18
0
wxPGConstants * WXEffectEditDialog::PopulateConstants(const Ogre::String& type)
{
	size_t id = reinterpret_cast<size_t>(&type);
	wxPGConstants* constants = wxPropertyGrid::GetConstantsArray(id);

	if (constants)
	{
		for (std::list<wxPGConstants*>::iterator it = mConstantList.begin(); it != mConstantList.end(); ++it)
		{
			if (constants == *it)
			{
				if (constants->UnRef())
					delete constants;

				mConstantList.erase(it);

				break;
			}
		}
	}
//	if (!constants)
//	{
		constants = wxPropertyGrid::CreateConstantsArray(id);

		if ( type == "Material" )
		{
			typedef std::list<Ogre::String> MaterialFileNameList;
			MaterialFileNameList materialFileNameList;

			Ogre::FileInfoListPtr fileInfoList =
				Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(
				Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
				"*.material");
			for (Ogre::FileInfoList::const_iterator it = fileInfoList->begin(); it != fileInfoList->end(); ++it)
			{
				if ( it->archive->getName() == EFFECT_PATH)
				{
					materialFileNameList.push_back(it->filename);
				}
			}
			// 第一个为空,表示设置这个元素的材质是用原mesh的材质
			constants->Add("none");

			Ogre::ResourceManager::ResourceMapIterator resourceMapIterator = Ogre::MaterialManager::getSingleton().getResourceIterator();

			while ( resourceMapIterator.hasMoreElements() )
			{				
				Ogre::String matName = resourceMapIterator.peekNextValue()->getName();

				for ( MaterialFileNameList::iterator i = materialFileNameList.begin();
					i != materialFileNameList.end(); ++i )
				{
					if ( *i == resourceMapIterator.peekNextValue()->getOrigin() )
					{
						constants->Add(matName.c_str());
						break;
					}
				}

				resourceMapIterator.moveNext();
			}
		}
		else if ( type == "MeshName" )
		{			
			constants->Add("none");

			Ogre::FileInfoListPtr fileInfoList =
				Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(
				Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
				"*.mesh");
			for (Ogre::FileInfoList::const_iterator it = fileInfoList->begin(); it != fileInfoList->end(); ++it)
			{
				if ( it->archive->getName() == EFFECT_PATH)
				{
					const Fairy::String& name = it->filename;
					constants->Add(name.c_str());
				}
			}
		}	
		else if ( type == "ParticleSystem" )
		{
			Ogre::ParticleSystemManager::ParticleSystemTemplateIterator iterator = Ogre::ParticleSystemManager::getSingleton().getTemplateIterator();

			while ( iterator.hasMoreElements() )
			{
				// 获取到粒子系统的名称
				Ogre::String parName = iterator.peekNextKey();

				constants->Add(parName.c_str());

				// 使iterator往后移
				iterator.moveNext();
			}
		}

		registerConstants(constants);
//	}

	return constants;
}
void 
MaterialPreviewDialog::InitPreviewGrids(void)
{

	wxFlexGridSizer *item0 = new wxFlexGridSizer( 6, 0, 0 );

	typedef std::list<Ogre::String> MaterialFileNameList;
	MaterialFileNameList materialFileNameList;

	Ogre::FileInfoListPtr fileInfoList =
		Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(
		Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		"*.material");
	for (Ogre::FileInfoList::const_iterator it = fileInfoList->begin(); it != fileInfoList->end(); ++it)
	{
		if ( it->archive->getName() == EFFECT_PATH)
		{
			materialFileNameList.push_back(it->filename);
		}
	}

	wxComboBox *matCombo = mParentDialog->mMaterialComboBox;
	assert (matCombo);

	for ( int i=0; i<matCombo->GetCount(); ++i )
	{
		Ogre::String matName = matCombo->GetString(i);

		Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(matName);			

		if (mat.isNull())
		{
		}
		else
		{
			size_t numOfTex = mat->getTechnique(0)->getPass(0)->getNumTextureUnitStates();
			if (numOfTex > 0)
			{
				Ogre::String texName = mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->getTextureName();
				if (texName.empty() == false)
				{
					wxBoxSizer *item1 = new wxBoxSizer( wxVERTICAL );

					wxStaticBitmap *item2 = new wxStaticBitmap( this, ID_STATICBITMAP, TexturePreview( 0 ), wxDefaultPosition, wxSize(64,64) );
					item1->Add( item2, 0, wxALIGN_CENTER|wxALL, 5 );

					wxStaticText *item3 = new wxStaticText( this, ID_TEXT_MATERIAL_NAME, _("text"), wxDefaultPosition, wxDefaultSize, 0 );
					item1->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );

					wxButton *item4 = new wxButton( this, ID_BUTTON_USE, _("Use"), wxDefaultPosition, wxDefaultSize, 0 );
					item1->Add( item4, 0, wxALIGN_CENTER|wxALL, 5 );

					item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );

					buildPreviewBitmap( texName );
					item2->SetBitmap(mCurrentPreviewImage);
					item3->SetLabel(texName.c_str());
					item4->SetLabel(matName.c_str());
				}
			}
		}
	}

	this->SetSizer( item0 );
	item0->SetSizeHints( this );
}
wxPGConstants * FairySkillEditDialog::PopulateConstants(const Ogre::String& name)
{
	size_t id = reinterpret_cast<size_t>(&name);
	wxPGConstants* constants = wxPropertyGrid::GetConstantsArray(id);

	if (constants)
	{
		for (std::list<wxPGConstants*>::iterator it = mConstantList.begin(); it != mConstantList.end(); ++it)
		{
			if (constants == *it)
			{
				if (constants->UnRef())
					delete constants;

				mConstantList.erase(it);

				break;
			}
		}
	}

//	if (!constants)
//	{
		constants = wxPropertyGrid::CreateConstantsArray(id);

		if ( name == "Animation" )
		{
			// 第一个为空,表示设置这个元素的材质是用原mesh的材质
			for ( unsigned short i = 0; i < mDObject->getSkeletonAnimationCount(); ++i )
			{
				Ogre::Animation *anim = mDObject->getSkeletonAnimation(i);

				if ( anim )
				{
					constants->Add(anim->getName().c_str());
				}
			}			
		}
		else if ( name == "EffectTemplateName" )
		{
			WX::EffectManager::EffectTemplateIterator it = 
				WX::EffectManager::getSingleton().getEffectTemplateIterator();

			while ( it.hasMoreElements() )
			{
				constants->Add(it.peekNextKey().c_str());

				it.moveNext();
			}
		}
		else if ( name == "AttachPoint" )
		{
			for ( unsigned short i=0; i<mDObject->getNumBones(); ++i )
			{
				constants->Add(mDObject->getBoneName(i).c_str());
			}	

			Ogre::StringVector locatorNames;
			mDObject->getLocatorNames(locatorNames);

			for ( size_t i=0; i<locatorNames.size(); ++i )
			{
				constants->Add(locatorNames[i].c_str());
			}			
		}
		else if ( name == "Material" )
		{
			typedef std::list<Ogre::String> MaterialFileNameList;
			MaterialFileNameList materialFileNameList;

			Ogre::FileInfoListPtr fileInfoList =
				Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(
				Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
				"*.material");
			for (Ogre::FileInfoList::const_iterator it = fileInfoList->begin(); it != fileInfoList->end(); ++it)
			{
				if ( it->archive->getName() == MATERIAL_PATH)
				{
					materialFileNameList.push_back(it->filename);
				}
			}

			Ogre::ResourceManager::ResourceMapIterator resourceMapIterator = Ogre::MaterialManager::getSingleton().getResourceIterator();

			while ( resourceMapIterator.hasMoreElements() )
			{				
				Ogre::String matName = resourceMapIterator.peekNextValue()->getName();

				for ( MaterialFileNameList::iterator i = materialFileNameList.begin();
					i != materialFileNameList.end(); ++i )
				{
					if ( *i == resourceMapIterator.peekNextValue()->getOrigin() )
					{
						constants->Add(matName.c_str());
						break;
					}
				}

				resourceMapIterator.moveNext();
			}
		}	
		else if ( name == "SoundName" )
		{
            constants->Add("NULL");
			//-----------------------------------
			//得到所有文件名
            if (wxGetApp().funcEnumSoundFile)
            {
			    int nIndex = 0;
			    do
			    {
				    char szTemp[100];

                    int id;

				    bool bHave = wxGetApp().funcEnumSoundFile(nIndex++, szTemp, 100, id);
				    if(!bHave) break;

				    constants->Add(szTemp);
			    }while(true);
            }
		}

		registerConstants(constants);
	//}

	return constants;
}
示例#21
0
void
BrushSelector::ReloadTextureList(void)
{
	CatalogMap catalogMap;
	mCatalogMap.clear();

    if (!Ogre::ResourceGroupManager::getSingletonPtr())
        return;

    mBrushesTree->Freeze();

    mBrushesTree->DeleteAllItems();

	wxTreeItemId rootId = mBrushesTree->AddRoot(/*_("Brushes")*/wxT("画刷列表"));
 
    // 重新解析定义文件
    GetSceneManipulator()->reloadPaintInfo();

    const Fairy::TerrainPaintInfoContainer *paintInfoContainer = GetSceneManipulator()->getTerrainPaintInfoContainer();

    assert (paintInfoContainer);

    const Fairy::TextureInfoMap &textureInfoMap = paintInfoContainer->getTextureInfoMap();

	OwnerTexs ownerTextures;

	Fairy::TextureInfoMap::const_iterator it = textureInfoMap.begin();	

    // 遍历画刷数组
    while ( it != textureInfoMap.end() )
    {
        const Fairy::TextureInfos &textureInfos = it->second;
        
        // 遍历该画刷下的所有纹理
        for ( size_t i=0; i<textureInfos.size(); ++i )
        {
            // 取出所属的大纹理的名称
            Ogre::String ownerTexName = textureInfos[i].ownerTextureName;

			// 记录大纹理的名称
			ownerTextures.insert(OwnerTexs::value_type(ownerTexName, ownerTexName));

            // 如果该纹理名称中包含了/,说明它是在一个文件夹中的
            size_t pos = ownerTexName.find_last_of('/');

            // 在文件夹中
            if (pos != Ogre::String::npos)
            {
                // 先去除纹理文件名,剩下路径名
                ownerTexName.erase(pos+1);
                // 加上画刷的名称
                ownerTexName.append(textureInfos[i].brushName);
                wxTreeItemId id = mBrushesTree->AppendItem( GetParentId(ownerTexName, catalogMap), wxT(textureInfos[i].textureName) );
				
				mCatalogMap.insert(CatalogMap::value_type( textureInfos[i].textureName, id ));
            }
            else
            {
                Ogre::String brushName = textureInfos[i].brushName;
                // 如果是在根目录下,就直接用画刷名称来作为路径名
                wxTreeItemId id = mBrushesTree->AppendItem( GetParentId(brushName, catalogMap), wxT(textureInfos[i].textureName) );
				mCatalogMap.insert(CatalogMap::value_type( textureInfos[i].textureName, id ));
			}				
        }
        ++it;
    }

	wxString lostTexNames = wxEmptyString;
	for (OwnerTexs::iterator ownerIt = ownerTextures.begin(); ownerIt != ownerTextures.end(); ++ownerIt)
	{
		Ogre::String texName = ownerIt->first;

		Ogre::FileInfoListPtr fileInfoList =
			Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo("Brushes",texName);
		
		Ogre::FileInfoList::const_iterator itBegin = fileInfoList->begin();
		Ogre::FileInfoList::const_iterator itEnd = fileInfoList->end(); 
		if (itBegin == itEnd)
		{
			lostTexNames+=wxT("\n");
			lostTexNames+=texName.c_str();
			 continue;
		}

		Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName(texName);

		if (!texture.isNull())
		{
			Ogre::TextureManager::getSingleton().remove(texName);
			Ogre::Image image;
			image.load(texName, Fairy::BRUSH_RESOURCE_GROUP_NAME);
			texture = Ogre::TextureManager::getSingleton()
				.loadImage(texName, Fairy::BRUSH_RESOURCE_GROUP_NAME, image);
		}
	}	

	if (!lostTexNames.empty())
	{
		wxMessageBox(wxT("以下贴图无法找到:")+lostTexNames);
	}

    mBrushesTree->Thaw();
}