const String EntityModelRendererManager::modelRendererKey(const Model::ModelDefinition& modelDefinition, const StringList& searchPaths) { StringStream key; for (size_t i = 0; i < searchPaths.size(); i++) key << searchPaths[i] << " "; key << modelDefinition.name() << " " << modelDefinition.skinIndex() << " " << modelDefinition.frameIndex(); return Utility::toLower(key.str()); }
Icon* IconManager::getIcon(int, EmberEntity* entity) { std::string key = "entity_" + entity->getId(); if (mIconStore.hasIcon(key)) { return mIconStore.getIcon(key); } else { IconActionCreator actionCreator(*entity); std::unique_ptr<EntityMapping::EntityMapping> modelMapping(Mapping::EmberEntityMappingManager::getSingleton().getManager().createMapping(*entity, actionCreator, &EmberOgre::getSingleton().getWorld()->getView())); std::string modelName; if (modelMapping.get()) { modelMapping->initialize(); modelName = actionCreator.getModelName(); } //if there's no model defined for this use the placeholder model if (modelName == "") { modelName = "placeholder"; } Ogre::ResourcePtr modelDefPtr = Model::ModelDefinitionManager::getSingleton().getByName(modelName); if (!modelDefPtr.isNull()) { Model::ModelDefinition* modelDef = static_cast<Model::ModelDefinition*> (modelDefPtr.get()); const std::string& iconPath(modelDef->getIconPath()); if (iconPath != "") { Ogre::TexturePtr texPtr; try { if (Ogre::TextureManager::getSingleton().resourceExists(iconPath)) { texPtr = static_cast<Ogre::TexturePtr> (Ogre::TextureManager::getSingleton().getByName(iconPath)); //try to load it to make sure that's it a working image texPtr->load(); } if (texPtr.isNull()) { texPtr = Ogre::TextureManager::getSingleton().load(iconPath, "Gui"); } } catch (...) { S_LOG_WARNING("Error when trying to load the icon " << iconPath <<". The icon will be rendered dynamically."); texPtr.setNull(); } if (!texPtr.isNull()) { Icon* icon = mIconStore.createIcon(key, texPtr); return icon; } } } Icon* icon = mIconStore.createIcon(key); if (icon) { //update the model preview window // Model::Model* model = Model::Model::createModel(mIconRenderer.getRenderContext()->getSceneManager(), modelName); render(*icon, modelName); // mIconRenderer.getRenderContext()->getSceneManager()->destroyMovableObject(model); } return icon; } return 0; }
Icon* IconManager::getIcon(int, EmberEntity* entity) { std::string key = "entity_" + entity->getId(); if (mIconStore.hasIcon(key)) { return mIconStore.getIcon(key); } else { std::string modelName; Mapping::ModelActionCreator actionCreator(*entity, [&](std::string newModelName){ modelName = newModelName; }, [&](std::string partName){ //Ignore parts }); std::unique_ptr<EntityMapping::EntityMapping> modelMapping(Mapping::EmberEntityMappingManager::getSingleton().getManager().createMapping(*entity, actionCreator, &EmberOgre::getSingleton().getWorld()->getView())); if (modelMapping) { modelMapping->initialize(); } //if there's no model defined for this use the placeholder model if (modelName.empty()) { modelName = "common/primitives/placeholder.modeldef"; } auto modelDefPtr = Model::ModelDefinitionManager::getSingleton().getByName(modelName); if (modelDefPtr) { Model::ModelDefinition* modelDef = modelDefPtr.get(); const std::string& iconPath(modelDef->getIconPath()); if (!iconPath.empty()) { Ogre::TexturePtr texPtr; try { if (Ogre::TextureManager::getSingleton().resourceExists(iconPath, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME)) { texPtr = static_cast<Ogre::TexturePtr> (Ogre::TextureManager::getSingleton().getByName(iconPath, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME)); //try to load it to make sure that's it a working image texPtr->load(); } if (!texPtr) { texPtr = Ogre::TextureManager::getSingleton().load(iconPath, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); } } catch (...) { S_LOG_WARNING("Error when trying to load the icon " << iconPath << ". The icon will be rendered dynamically."); texPtr.reset(); } if (texPtr) { Icon* icon = mIconStore.createIcon(key, texPtr); return icon; } } } Icon* icon = mIconStore.createIcon(key); if (icon) { //update the model preview window // Model::Model* model = Model::Model::createModel(mIconRenderer.getRenderContext()->getSceneManager(), modelName); render(*icon, modelName); // mIconRenderer.getRenderContext()->getSceneManager()->destroyMovableObject(model); } return icon; } }