bool reloadShaders(std_srvs::Empty::Request&, std_srvs::Empty::Response&) { ROS_INFO("Reloading materials."); { Ogre::ResourceManager::ResourceMapIterator it = Ogre::MaterialManager::getSingleton().getResourceIterator(); while (it.hasMoreElements()) { Ogre::ResourcePtr resource = it.getNext(); resource->reload(); } } ROS_INFO("Reloading high-level gpu shaders."); { Ogre::ResourceManager::ResourceMapIterator it = Ogre::HighLevelGpuProgramManager::getSingleton().getResourceIterator(); while (it.hasMoreElements()) { Ogre::ResourcePtr resource = it.getNext(); resource->reload(); } } ROS_INFO("Reloading gpu shaders."); { Ogre::ResourceManager::ResourceMapIterator it = Ogre::GpuProgramManager::getSingleton().getResourceIterator(); while (it.hasMoreElements()) { Ogre::ResourcePtr resource = it.getNext(); resource->reload(); } } return true; }
void test_loadPlayWithFade() { xtime xt; Ogre::ResourceManager::ResourceMapIterator it = SoundManager::getSingleton().getResourceIterator(); while (it.hasMoreElements()) { SoundResourcePtr soundres = it.getNext(); SoundStream *sound = new SoundStream(soundres); SoundChannel *channel = new SoundChannel(sound, soundres->getName()); if (channel) { channel->play(); xtime_get(&xt, boost::TIME_UTC); xt.sec += 10; thread::sleep(xt); channel->stop(); xtime_get(&xt, boost::TIME_UTC); xt.sec += 5; thread::sleep(xt); } } CPPUNIT_ASSERT(true); }
World::World(Ogre::SceneManager *sceneManager, InputHandler *input) : mSceneManager(sceneManager), mInputHandler(input) { /* Necessary booleans for computing physics */ start = true; hitTopWall = false; hitBottomWall = false; hitByAI = false; hitByUser = false; userScored = false; AIScored = false; ballSpeed = 35; // Global illumination for now. Adding individual light sources will make you scene look more realistic mSceneManager->setAmbientLight(Ogre::ColourValue(1,1,1)); createModels(); // Yeah, this should be done automatically for all fonts referenced in an overlay file. // But there is a bug in the OGRE code so we need to do it manually. Ogre::ResourceManager::ResourceMapIterator iter = Ogre::FontManager::getSingleton().getResourceIterator(); while (iter.hasMoreElements()) { iter.getNext()->load(); } // Display scoreboard Scoreboard(); }
void MaterialSelector::Reload(void) { if (!Ogre::ResourceGroupManager::getSingletonPtr()) return; wxBusyInfo* busyInfo = new wxBusyInfo(_("正在读取材质数据 ..."), this); mMaterialList->Freeze(); mMaterialList->ClearAll(); Ogre::ResourceManager::ResourceMapIterator resourceMapIterator = Ogre::MaterialManager::getSingleton().getResourceIterator(); while ( resourceMapIterator.hasMoreElements() ) { long index = mMaterialList->GetItemCount(); mMaterialList->InsertItem( index, AS_STRING( resourceMapIterator.peekNextValue()->getName())); resourceMapIterator.moveNext(); } mMaterialList->Thaw(); delete busyInfo; }
//------------------------------------------------------------------------------------- void BaseApplication::loadResources(void) { Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); Ogre::ResourceManager::ResourceMapIterator iter = Ogre::FontManager::getSingleton().getResourceIterator(); while ( iter.hasMoreElements() ) { iter.getNext()->load(); } }
void ResourcesManager::loadResources() { Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); // Load the system fonts Ogre::ResourceManager::ResourceMapIterator iter = Ogre::FontManager::getSingleton().getResourceIterator(); while (iter.hasMoreElements()) { iter.getNext()->load(); } }
//------------------------------------------------------------------------------------- void SpaceLogin::setupResources(void) { // ogre²»ÏÔʾÎÄ×Öbug // http://www.ogre3d.org/forums/viewtopic.php?f=4&t=59197 Ogre::ResourceManager::ResourceMapIterator iter = Ogre::FontManager::getSingleton().getResourceIterator(); while (iter.hasMoreElements()) { iter.getNext()->load(); } }
void SkinManager::getMaterialAlternatives(Ogre::String materialName, std::vector<Skin *> &skinVector) { Ogre::ResourceManager::ResourceMapIterator it = getResourceIterator(); while (it.hasMoreElements()) { Skin *skin = (Skin *)it.getNext().getPointer(); if (skin->hasReplacementForMaterial(materialName)) { skinVector.push_back(skin); } } }
//Initial UI void World::showInitUI(){ Ogre::ResourceManager::ResourceMapIterator iter = Ogre::FontManager::getSingleton().getResourceIterator(); while (iter.hasMoreElements()) { iter.getNext()->load(); } mShowInitialUI = true; mInitialUIOverlay->show(); }
bool SkinManager::hasSkinForGUID(Ogre::String guid) { Ogre::ResourceManager::ResourceMapIterator it = getResourceIterator(); while (it.hasMoreElements()) { Skin *skin = (Skin *)it.getNext().getPointer(); if (skin->guid == guid) { return true; } } return false; }
/**************************************************************************** ** ** Copyright (C) 2016 ** ** This file is generated by the Magus toolkit ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ****************************************************************************/ // Include #include "constants.h" #include <QString> #include <QFile> #include <QTextStream> #include <QMenuBar> #include "mainwindow.h" #include "OgreItem.h" #include "OgreHlmsPbs.h" #include "OgreHlmsUnlit.h" #include "OgreHlmsPbsDatablock.h" #include "OgreHlmsUnlitDatablock.h" #include "OgreHlmsManager.h" //****************************************************************************/ MainWindow::MainWindow(void) : mIsClosing(false), mFirst(true) { installEventFilter(this); // Create the Ogre Manager mOgreManager = new Magus::OgreManager(); mHlmsName = QString(""); mTempString = QString(""); // Perform standard functions createActions(); createMenus(); createToolBars(); createStatusBar(); createDockWindows(); mMaterialBrowser = new MaterialBrowserDialog(this); loadMaterialBrowserCfg(); mOgreManager->initialize(); // Set the title setWindowTitle(QString("HLMS editor")); // Set the stylesheet of the application QFile File(QString("dark.qss")); File.open(QFile::ReadOnly); QString styleSheet = QLatin1String(File.readAll()); setStyleSheet(styleSheet); showMaximized(); } //****************************************************************************/ MainWindow::~MainWindow(void) { delete mOgreManager; } //****************************************************************************/ bool MainWindow::eventFilter(QObject* object, QEvent* event) { if (event->type()==QEvent::KeyPress) { QKeyEvent* key = static_cast<QKeyEvent*>(event); if (key->key() == Qt::Key_F5) { // F5 was pressed mNodeEditorDockWidget->generateDatablock(); } if (key->key() == Qt::Key_S && (QApplication::keyboardModifiers() & Qt::ControlModifier)) { // CTRL+S was pressed doSaveDatablockMenuAction(); } } return QObject::eventFilter(object, event); } //****************************************************************************/ void MainWindow::closeEvent(QCloseEvent* event) { mIsClosing = true; } //****************************************************************************/ void MainWindow::createActions(void) { // File menu mNewHlmsPbsAction = new QAction(QString("Pbs"), this); connect(mNewHlmsPbsAction, SIGNAL(triggered()), this, SLOT(doNewHlmsPbsAction())); mNewHlmsUnlitAction = new QAction(QString("Unlit"), this); connect(mNewHlmsUnlitAction, SIGNAL(triggered()), this, SLOT(doNewHlmsUnlitAction())); mOpenDatablockMenuAction = new QAction(QString("Open Hlms"), this); connect(mOpenDatablockMenuAction, SIGNAL(triggered()), this, SLOT(doOpenDatablockMenuAction())); mSaveDatablockMenuAction = new QAction(QString("Save Hlms"), this); connect(mSaveDatablockMenuAction, SIGNAL(triggered()), this, SLOT(doSaveDatablockMenuAction())); mSaveAsDatablockMenuAction = new QAction(QString("Save Hlms as"), this); connect(mSaveAsDatablockMenuAction, SIGNAL(triggered()), this, SLOT(doSaveAsDatablockMenuAction())); mQuitMenuAction = new QAction(QString("Quit"), this); connect(mQuitMenuAction, SIGNAL(triggered()), this, SLOT(doQuitMenuAction())); // Materials menu mMaterialBrowserOpenMenuAction = new QAction(QString("Open browser"), this); connect(mMaterialBrowserOpenMenuAction, SIGNAL(triggered()), this, SLOT(doMaterialBrowserOpenMenuAction())); mMaterialBrowserAddMenuAction = new QAction(QString("Add Hlms to browser"), this); connect(mMaterialBrowserAddMenuAction, SIGNAL(triggered()), this, SLOT(doMaterialBrowserAddMenuAction())); // Window menu mResetWindowLayoutMenuAction = new QAction(QString("Reset Window Layout"), this); connect(mResetWindowLayoutMenuAction, SIGNAL(triggered()), this, SLOT(doResetWindowLayoutMenuAction())); } //****************************************************************************/ void MainWindow::createMenus(void) { mFileMenu = menuBar()->addMenu(QString("&File")); mMaterialBrowserMenu = menuBar()->addMenu(QString("&Materials")); QMenu* fileMenuAction = mFileMenu->addMenu("New Hlms"); fileMenuAction->addAction(mNewHlmsPbsAction); fileMenuAction->addAction(mNewHlmsUnlitAction); mFileMenu->addAction(mOpenDatablockMenuAction); mFileMenu->addAction(mSaveDatablockMenuAction); mFileMenu->addAction(mSaveAsDatablockMenuAction); mFileMenu->addAction(mQuitMenuAction); mMaterialBrowserMenu->addAction(mMaterialBrowserOpenMenuAction); mMaterialBrowserMenu->addAction(mMaterialBrowserAddMenuAction); mWindowMenu = menuBar()->addMenu(QString("&Window")); mWindowMenu->addAction(mResetWindowLayoutMenuAction); } //****************************************************************************/ void MainWindow::createToolBars(void) { } //****************************************************************************/ void MainWindow::createStatusBar(void) { } //****************************************************************************/ void MainWindow::createDockWindows(void) { mRenderwindowDockWidget = new RenderwindowDockWidget("Renderwindow", this); addDockWidget(Qt::LeftDockWidgetArea, mRenderwindowDockWidget); mPropertiesDockWidget = new PropertiesDockWidget("Properties", this); addDockWidget(Qt::LeftDockWidgetArea, mPropertiesDockWidget); mNodeEditorDockWidget = new NodeEditorDockWidget("NodeEditor", this); setCentralWidget(mNodeEditorDockWidget); } //****************************************************************************/ void MainWindow::doNewHlmsPbsAction(void) { initDatablocks(); mPropertiesDockWidget->clear(); mNodeEditorDockWidget->newHlmsPbsAndSampler(); } //****************************************************************************/ void MainWindow::doNewHlmsUnlitAction(void) { initDatablocks(); mPropertiesDockWidget->clear(); mNodeEditorDockWidget->newHlmsUnlitAndSampler(); } //****************************************************************************/ void MainWindow::doOpenDatablockMenuAction(void) { // Load the materials QString fileName; fileName = QFileDialog::getOpenFileName(this, QString("Open Hlms file"), QString(""), QString("Json material (*.json)")); loadDatablock(fileName); } //****************************************************************************/ void MainWindow::loadDatablock(const QString jsonFileName) { // Load the materials if (!jsonFileName.isEmpty()) { // Read the json file as text file and feed it to the HlmsManager::loadMaterials() function // Note, that the resources (textures, etc.) must be present // First, delete all datablocks before loading the new ones initDatablocks(); mPropertiesDockWidget->clear(); // Read the json file Ogre::HlmsManager* hlmsManager = mOgreManager->getOgreRoot()->getHlmsManager(); QFile file(jsonFileName); file.open(QFile::ReadOnly | QFile::Text); QTextStream readFile(&file); QString jsonString = readFile.readAll(); QByteArray ba = jsonString.toLatin1(); char* jsonChar = ba.data(); Ogre::String fname = jsonFileName.toStdString(); Ogre::HlmsJson hlmsJson(hlmsManager); try { // Load the datablocks (which also creates them) hlmsJson.loadMaterials(fname, jsonChar); } catch (Ogre::Exception e) { Ogre::LogManager::getSingleton().logMessage("MainWindow::doOpenDatablockMenuAction(); Could not load the materials\n"); } file.close(); mHlmsName = jsonFileName; // Get the (list of) datablocks and assign the first one to the current 'item' to be rendered getAndSetFirstDatablock(); } } //****************************************************************************/ void MainWindow::destroyAllDatablocks(void) { // Get the datablock from the item and remove it mOgreManager->getOgreWidget(OGRE_WIDGET_RENDERWINDOW)->setDefaultDatablockItem(); Ogre::HlmsManager* hlmsManager = mOgreManager->getOgreRoot()->getHlmsManager(); Ogre::HlmsPbs* hlmsPbs = static_cast<Ogre::HlmsPbs*>( hlmsManager->getHlms(Ogre::HLMS_PBS)); Ogre::HlmsUnlit* hlmsUnlit = static_cast<Ogre::HlmsUnlit*>( hlmsManager->getHlms(Ogre::HLMS_UNLIT)); // Iterate through all pbs datablocks and remove them Ogre::Hlms::HlmsDatablockMap::const_iterator itorPbs = hlmsPbs->getDatablockMap().begin(); Ogre::Hlms::HlmsDatablockMap::const_iterator endPbs = hlmsPbs->getDatablockMap().end(); Ogre::HlmsPbsDatablock* pbsDatablock; while( itorPbs != endPbs) { pbsDatablock = static_cast<Ogre::HlmsPbsDatablock*>(itorPbs->second.datablock); if (pbsDatablock != hlmsPbs->getDefaultDatablock() && pbsDatablock != hlmsUnlit->getDefaultDatablock()) { hlmsPbs->destroyDatablock(pbsDatablock->getName()); itorPbs = hlmsPbs->getDatablockMap().begin(); // Start from the beginning again } else ++itorPbs; } // Iterate through all unlit datablocks and remove them Ogre::Hlms::HlmsDatablockMap::const_iterator itorUnlit = hlmsUnlit->getDatablockMap().begin(); Ogre::Hlms::HlmsDatablockMap::const_iterator endUnlit = hlmsUnlit->getDatablockMap().end(); Ogre::HlmsUnlitDatablock* unlitDatablock; while( itorUnlit != endUnlit) { unlitDatablock = static_cast<Ogre::HlmsUnlitDatablock*>(itorUnlit->second.datablock); if (unlitDatablock != hlmsPbs->getDefaultDatablock() && unlitDatablock != hlmsUnlit->getDefaultDatablock()) { hlmsUnlit->destroyDatablock(unlitDatablock->getName()); itorUnlit = hlmsUnlit->getDatablockMap().begin(); // Start from the beginning again } else ++itorUnlit; } } //****************************************************************************/ void MainWindow::getAndSetFirstDatablock(void) { // Get the name/fullname from the current item in the renderwindow Ogre::Item* item = mOgreManager->getOgreWidget(OGRE_WIDGET_RENDERWINDOW)->getItem(); Ogre::HlmsDatablock* oldDatablock = item->getSubItem(0)->getDatablock(); Ogre::String oldDatablockName = *oldDatablock->getFullName(); Ogre::IdString oldDatablockId = oldDatablock->getName(); // Determine whether the HlmsManager contains a HLMS_PBS datablock or a HLMS_UNLIT datablock. // Depending on the result, the datablock of that type is retrieved and set in the mesh (item). Ogre::HlmsManager* hlmsManager = mOgreManager->getOgreRoot()->getHlmsManager(); Ogre::HlmsPbs* hlmsPbs = static_cast<Ogre::HlmsPbs*>( hlmsManager->getHlms(Ogre::HLMS_PBS)); Ogre::HlmsUnlit* hlmsUnlit = static_cast<Ogre::HlmsUnlit*>( hlmsManager->getHlms(Ogre::HLMS_UNLIT)); if (hlmsPbs) { int size = hlmsPbs->getDatablockMap().size(); //QMessageBox::information(0, QString("info"), QVariant(size).toString()); if (size> 1) { // It is a PBS; Note, that there is also a default (so always 1) Ogre::Hlms::HlmsDatablockMap::const_iterator itor = hlmsPbs->getDatablockMap().begin(); Ogre::Hlms::HlmsDatablockMap::const_iterator end = hlmsPbs->getDatablockMap().end(); Ogre::HlmsPbsDatablock* newDatablock; Ogre::String newDatablockName; while( itor != end ) { newDatablock = static_cast<Ogre::HlmsPbsDatablock*>(itor->second.datablock); if (newDatablock != hlmsPbs->getDefaultDatablock() && newDatablock != hlmsUnlit->getDefaultDatablock()) { // Get the first datablock newDatablockName = *newDatablock->getFullName(); if (oldDatablockName != newDatablockName) { // Assign the datablock to the item (and destroy the items' old datablock, if still available) item->setDatablock(newDatablock); if (oldDatablock != hlmsPbs->getDefaultDatablock() && oldDatablock != hlmsUnlit->getDefaultDatablock()) { if (oldDatablock->getCreator()->getType() == Ogre::HLMS_PBS) hlmsPbs->destroyDatablock(oldDatablockId); else if (hlmsUnlit && oldDatablock->getCreator()->getType() == Ogre::HLMS_UNLIT) hlmsUnlit->destroyDatablock(oldDatablockId); } // Create the node structure QString s = newDatablockName.c_str(); mNodeEditorDockWidget->createPbsNodeStructure(s); mPropertiesDockWidget->setTextureTypePropertyVisible(true); mPropertiesDockWidget->setMapWeightPropertyVisible(true); break; } } ++itor; } return; } } if (hlmsUnlit) { int size = hlmsUnlit->getDatablockMap().size(); //QMessageBox::information(0, QString("info"), QVariant(size).toString()); if (size > 1) { // It is an Unlit; Note, that there is also a default (so always 1) Ogre::Hlms::HlmsDatablockMap::const_iterator itor = hlmsUnlit->getDatablockMap().begin(); Ogre::Hlms::HlmsDatablockMap::const_iterator end = hlmsUnlit->getDatablockMap().end(); Ogre::HlmsUnlitDatablock* newDatablock; Ogre::String newDatablockName; while( itor != end ) { newDatablock = static_cast<Ogre::HlmsUnlitDatablock*>(itor->second.datablock); if (newDatablock != hlmsPbs->getDefaultDatablock() && newDatablock != hlmsUnlit->getDefaultDatablock()) { // Get the first datablock newDatablockName = *newDatablock->getFullName(); if (oldDatablockName != newDatablockName) { // Assign the datablock to the item (and destroy the items' old datablock, if still available) item->setDatablock(newDatablock); if (oldDatablock != hlmsPbs->getDefaultDatablock() && oldDatablock != hlmsUnlit->getDefaultDatablock()) { if (oldDatablock->getCreator()->getType() == Ogre::HLMS_UNLIT) hlmsUnlit->destroyDatablock(oldDatablockId); else if (hlmsPbs && oldDatablock->getCreator()->getType() == Ogre::HLMS_PBS) hlmsPbs->destroyDatablock(oldDatablockId); } // Create the node structure QString s = newDatablockName.c_str(); mNodeEditorDockWidget->createUnlitNodeStructure(s); mPropertiesDockWidget->setTextureTypePropertyVisible(false); mPropertiesDockWidget->setMapWeightPropertyVisible(false); break; } } ++itor; } return; } } } //****************************************************************************/ void MainWindow::getListOfResources(void) { Ogre::ResourceGroupManager::ResourceManagerIterator it = Ogre::ResourceGroupManager::getSingletonPtr()->getResourceManagerIterator(); while (it.hasMoreElements()) { Ogre::ResourceManager* man = it.getNext(); Ogre::LogManager::getSingleton().logMessage("Resource Type = " + man->getResourceType()); Ogre::ResourceManager::ResourceMapIterator mapit = man->getResourceIterator() ; while (mapit.hasMoreElements()) { Ogre::ResourcePtr ptr = mapit.getNext(); Ogre::LogManager::getSingleton().logMessage("Resource Name = " + ptr->getName()); } } }
void LiquidCreatorDialog::OnInitDialog(wxInitDialogEvent &e) { wxDialog::OnInitDialog(e); wxSizer* sizer = LiquidCreator(this, true, true); /// 获取各控件的引用 mComboBox = wxDynamicCast(this->FindWindow(ID_MATERIALCOMBO),wxComboBox); assert (mComboBox); Ogre::ResourceManager::ResourceMapIterator resourceMapIterator = Ogre::MaterialManager::getSingleton().getResourceIterator(); while ( resourceMapIterator.hasMoreElements() ) { if ( resourceMapIterator.peekNextValue()->getGroup() == Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ) { Ogre::String matName = resourceMapIterator.peekNextValue()->getName(); // 只有材质名称中包含“水”才加入到combobox中 if (matName.find("water") != Ogre::String::npos || matName.find("Water") != Ogre::String::npos || matName.find("水01") != Ogre::String::npos) mComboBox->AppendString( matName.c_str() ); } resourceMapIterator.moveNext(); } resourceMapIterator = Ogre::MaterialManager::getSingleton().getResourceIterator(); mComboBox->SetValue( resourceMapIterator.peekNextValue()->getName().c_str() ); mSubDivideTextCtrl = wxDynamicCast(this->FindWindow(ID_SUBDIVISIONTEXTCTRL),wxTextCtrl); assert (mSubDivideTextCtrl); mTexScaleTextCtrl = wxDynamicCast(this->FindWindow(ID_TEXCOORDSCALETEXTCTRL),wxTextCtrl); assert (mTexScaleTextCtrl); mDiffuseTextCtrl = wxDynamicCast(this->FindWindow(ID_DIFFUSETEXTCTRL),wxTextCtrl); assert (mDiffuseTextCtrl); mDepthTextCtrl = wxDynamicCast(this->FindWindow(ID_DEPTHTEXTCTRL),wxTextCtrl); assert (mDepthTextCtrl); }
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(); } }
void test_playWith3D() { xtime xt; Ogre::ResourceManager::ResourceMapIterator it = SoundManager::getSingleton().getResourceIterator(); while (it.hasMoreElements()) { SoundResourcePtr soundres = it.getNext(); SoundStream *sound = new SoundStream(soundres); SoundChannel *channel = new SoundChannel(sound, soundres->getName()); if (channel) { channel->play(); float angle = 0.0f; xtime_get(&xt, TIME_UTC); xt.sec++; thread::sleep(xt); while (channel->isPlaying()) { xtime_get(&xt, TIME_UTC); xt.nsec+=100000; thread::sleep(xt); Vector3 pos(1.0f*sinf(angle), 20.0f*cosf(angle), 0.0f); channel->setPosition(pos); angle += 0.005; if (angle > 2 * M_PI) { angle = 0.0f; } FSOUND_Update(); } delete channel; } } }
void SkinManager::GetUsableSkins(String guid, std::vector<Skin *> &skins) { Ogre::ResourceManager::ResourceMapIterator it = getResourceIterator(); while (it.hasMoreElements()) { Skin *skin = (Skin *)it.getNext().getPointer(); // fix some possible problems String g1 = guid; String g2 = skin->guid; StringUtil::trim(g1); StringUtil::trim(g2); StringUtil::toLowerCase(g1); StringUtil::toLowerCase(g2); // then compare if (g1 == g2) { skins.push_back(skin); } } }
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; }
void OgreInfo::diagnose(std::ostream& outputStream) { Ogre::SceneManagerEnumerator::SceneManagerIterator sceneManagerI = Ogre::Root::getSingleton().getSceneManagerIterator(); while (sceneManagerI.hasMoreElements()) { Ogre::SceneManager* sceneManager = sceneManagerI.getNext(); outputStream << "Scenemanager(" << sceneManager->getTypeName() << ") " << sceneManager->getName() << std::endl; outputStream << " Number of scene nodes: " << countNodes(sceneManager->getRootSceneNode()) << std::endl; outputStream << " Movable objects:" << std::endl; unsigned int movableObjectCounter = 0; Ogre::Root::MovableObjectFactoryIterator movableObjectFactoryI = Ogre::Root::getSingleton().getMovableObjectFactoryIterator(); while (movableObjectFactoryI.hasMoreElements()) { Ogre::MovableObjectFactory* factory = movableObjectFactoryI.getNext(); std::string type(factory->getType()); { Ogre::SceneManager::MovableObjectIterator I = sceneManager->getMovableObjectIterator(type); while (I.hasMoreElements()) { movableObjectCounter++; Ogre::MovableObject* movable = I.getNext(); if (movable->getMovableType() == "Light") { Ogre::Light* light = static_cast<Ogre::Light*> (movable); outputStream << " * Light " << light->getName() << "(" << (light->isInScene() ? "in scene" : "not in scene") << ")" << std::endl; outputStream << " Pos: " << light->getDerivedPosition() << std::endl; outputStream << " Direction: " << light->getDerivedDirection() << std::endl; } else { std::stringstream ssPosAndOrientation; if (movable->getParentSceneNode() && movable->isInScene()) { ssPosAndOrientation << " pos: " << movable->getParentSceneNode()->getPosition() << " orientation: " << movable->getParentSceneNode()->getOrientation(); } outputStream << " * " << type << " " << movable->getName() << "(" << (movable->isInScene() ? "in scene" : "not in scene") << ")" << ssPosAndOrientation.str() << std::endl; // outputStream << " Pos: " << light->getDerivedPosition() << std::endl; // outputStream << " Direction: " << light->getDerivedDirection() << std::endl; } } } } outputStream << " Number of movable objects: " << movableObjectCounter << std::endl; outputStream << " Cameras:" << std::endl; { Ogre::SceneManager::CameraIterator I = sceneManager->getCameraIterator(); while (I.hasMoreElements()) { Ogre::Camera* camera = I.getNext(); outputStream << " Camera " << camera->getName() << "(" << (camera->isInScene() ? "in scene" : "not in scene") << ")" << std::endl; outputStream << " Pos: " << camera->getDerivedPosition() << std::endl; outputStream << " Direction: " << camera->getDerivedDirection() << std::endl; outputStream << " Clip distances: " << camera->getNearClipDistance() << " - " << camera->getFarClipDistance() << std::endl; } } } size_t resourceMemoryUsage = 0; outputStream << "Resource Managers:" << std::endl; Ogre::ResourceGroupManager::ResourceManagerIterator I = Ogre::ResourceGroupManager::getSingleton().getResourceManagerIterator(); while (I.hasMoreElements()) { std::string name = I.peekNextKey(); Ogre::ResourceManager* manager = I.getNext(); outputStream << " Resource Manager: " << name << std::endl; if (manager->getMemoryBudget() == std::numeric_limits<size_t>::max()) { outputStream << " Memory budget: not set" << std::endl; } else { outputStream << " Memory budget: " << manager->getMemoryBudget() << " bytes" << std::endl; } outputStream << " Memory usage: " << manager->getMemoryUsage() << " bytes" << std::endl; resourceMemoryUsage += manager->getMemoryUsage(); Ogre::ResourceManager::ResourceMapIterator resourceI = manager->getResourceIterator(); if (resourceI.hasMoreElements()) { outputStream << " Resources: " << std::endl; int resourceCount = 0; int loadedResourceCount = 0; while (resourceI.hasMoreElements()) { Ogre::ResourcePtr resource = resourceI.getNext(); if (resource->isLoaded()) { std::string reloadable = resource->isReloadable() ? " reloadable" : ""; outputStream << " " << resource->getName() << " ( " << resource->getSize() << " bytes)" << reloadable; Ogre::Texture* texture = dynamic_cast<Ogre::Texture*>(resource.get()); if (texture) { outputStream << texture->getWidth() << "x" << texture->getHeight() << " "; } outputStream << std::endl; loadedResourceCount++; } resourceCount++; } outputStream << " Total number of resources: " << resourceCount << std::endl; outputStream << " Number of loaded resources: " << loadedResourceCount << std::endl; } } outputStream << "Total memory usage for all resource manager: " << resourceMemoryUsage << " bytes" << std::endl; outputStream << std::flush; }
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; }