void IconManager::render(Icon& icon, Eris::TypeInfo& erisType) { //we need to get the model mapping definition for this type //once we have that, we will check for the first action of the first case of the first match (since that's guaranteed to be a show-model action Eris::Connection* conn = EmberServices::getSingleton().getServerService().getConnection(); if (conn) { Eris::TypeService* typeService = conn->getTypeService(); if (typeService) { DummyEntity dummyEntity("-1", &erisType, typeService); std::string modelName; Mapping::ModelActionCreator actionCreator(dummyEntity, [&](std::string newModelName){ modelName = newModelName; }, [&](std::string partName){ //Ignore parts }); std::unique_ptr<EntityMapping::EntityMapping> modelMapping(Mapping::EmberEntityMappingManager::getSingleton().getManager().createMapping(dummyEntity, 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"; } //update the model preview window // Model::Model* model = Model::Model::createModel(mIconRenderer.getRenderContext()->getSceneManager(), modelName); render(icon, modelName); // mIconRenderer.getRenderContext()->getSceneManager()->destroyMovableObject(model); dummyEntity.shutdown(); } } }
ModelPreviewWorker::ModelPreviewWorker(World& world, Eris::ViewEntity* entity) : mWorld(world), mEntity(0), mEntityNode(0), mModel(0), mModelMount(0), mMovement(0) { mOrientation.identity(); Eris::TypeInfo* erisType = entity->getType(); mPos = WFMath::Point<3>::ZERO(); mEntityMessage = entity->getInstanceAttributes(); // Temporary entity mEntity = new Authoring::DetachedEntity("-1", erisType, entity->getView()->getAvatar()->getConnection()->getTypeService()); mEntity->setFromMessage(mEntityMessage); // Creating scene node mEntityNode = mWorld.getSceneManager().getRootSceneNode()->createChildSceneNode(); // Making model from temporary entity ModelPreviewWorkerActionCreator actionCreator(*this); std::auto_ptr<EntityMapping::EntityMapping> modelMapping(Mapping::EmberEntityMappingManager::getSingleton().getManager().createMapping(*mEntity, &actionCreator, 0)); if (modelMapping.get()) { modelMapping->initialize(); } // Registering move adapter to track mouse movements mMovement = new ModelPreviewWorkerMovement(*this, mWorld.getMainCamera(), *mEntity, mEntityNode); //mMoveAdapter->addAdapter(); }
void IconManager::render(Icon& icon, Eris::TypeInfo& erisType) { //we need to get the model mapping definition for this type //once we have that, we will check for the first action of the first case of the first match (since that's guaranteed to be a show-model action Eris::Connection* conn = EmberServices::getSingleton().getServerService().getConnection(); if (conn) { Eris::TypeService* typeService = conn->getTypeService(); if (typeService) { DummyEntity dummyEntity("-1", &erisType, typeService); IconActionCreator actionCreator(dummyEntity); std::auto_ptr<EntityMapping::EntityMapping> modelMapping(Mapping::EmberEntityMappingManager::getSingleton().getManager().createMapping(dummyEntity, &actionCreator, Application::getSingleton().getMainView())); 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"; } //update the model preview window // Model::Model* model = Model::Model::createModel(mIconRenderer.getRenderContext()->getSceneManager(), modelName); render(icon, modelName); // mIconRenderer.getRenderContext()->getSceneManager()->destroyMovableObject(model); dummyEntity.shutdown(); } } }
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; }
void IconManager::render(Icon& icon, EmberEntity& entity) { 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"; } render(icon, modelName); }
void EntityCreatorCreationInstance::createEntity() { // Creating entity data mEntityMessage = mRecipe.createEntity(mTypeService); Eris::TypeInfo* erisType = mTypeService.getTypeByName(mRecipe.getEntityType()); if (!erisType) { S_LOG_FAILURE("Type " << mRecipe.getEntityType() << " not found in recipe " << mRecipe.getName()); return; } EmberEntity& avatar = mWorld.getAvatar()->getEmberEntity(); mEntityMessage["loc"] = avatar.getLocation()->getId(); mEntityMessage["parents"] = Atlas::Message::ListType(1, erisType->getName()); // Temporary entity mEntity = new Authoring::DetachedEntity("-1", erisType, &mTypeService); Atlas::Objects::Entity::RootEntity rootEntity; mEntity->doInit(rootEntity); mEntity->setFromMessage(mEntityMessage); // Creating scene node mEntityNode = mWorld.getSceneManager().getRootSceneNode()->createChildSceneNode(); if (!mAxisMarker) { try { mAxisMarker = mEntityNode->getCreator()->createEntity(OgreInfo::createUniqueResourceName("EntityCreator_axisMarker"), "axes.mesh"); mEntityNode->attachObject(mAxisMarker); } catch (const std::exception& ex) { S_LOG_WARNING("Error when loading axes mesh." << ex); } } // Making model from temporary entity EntityCreatorActionCreator actionCreator(*this); std::unique_ptr<EntityMapping::EntityMapping> modelMapping(Mapping::EmberEntityMappingManager::getSingleton().getManager().createMapping(*mEntity, actionCreator, 0)); if (modelMapping.get()) { modelMapping->initialize(); } // Registering move adapter to track mouse movements // mInputAdapter->addAdapter(); mMovement = new EntityCreatorMovement(*this, mWorld.getMainCamera(), *mEntity, mEntityNode); }
void IconManager::render(Icon& icon, EmberEntity& entity) { 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"; } render(icon, modelName); }
void EntityCreatorTypeHelper::showPreview(Ember::OgreView::Authoring::DetachedEntity& entity) { Mapping::ModelActionCreator actionCreator(entity, [&](std::string model) { mModelPreviewRenderer->showModel(model); mModelPreviewRenderer->showFull(); //we want to zoom in a little mModelPreviewRenderer->setCameraDistance(0.7); }, [&](std::string part) { if (mModelPreviewRenderer->getModel()) { mModelPreviewRenderer->getModel()->showPart(part); } }); auto mapping = Mapping::EmberEntityMappingManager::getSingleton().getManager().createMapping(entity, actionCreator, nullptr); entity.shutdown(); if (mapping) { mapping->initialize(); } }
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; } }