diff --git a/interface/src/scripting/SelectionScriptingInterface.cpp b/interface/src/scripting/SelectionScriptingInterface.cpp index 651edf4501..9af0ed8c82 100644 --- a/interface/src/scripting/SelectionScriptingInterface.cpp +++ b/interface/src/scripting/SelectionScriptingInterface.cpp @@ -73,12 +73,11 @@ bool SelectionScriptingInterface::removeFromSelectedItemsList(const QString& lis bool SelectionScriptingInterface::clearSelectedItemsList(const QString& listName) { _selectedItemsListMap.insert(listName, GameplayObjects()); - emit selectedItemsListChanged(listName); + onSelectedItemsListChanged(listName); return true; } bool SelectionScriptingInterface::enableListHighlight(const QString& listName, const QVariantMap& highlightStyleValues) { - bool doSetupHandler = false; auto highlightStyle = _highlightedListMap.find(listName); if (highlightStyle == _highlightedListMap.end()) { @@ -90,18 +89,14 @@ bool SelectionScriptingInterface::enableListHighlight(const QString& listName, c auto currentList = _selectedItemsListMap.find(listName); if (currentList == _selectedItemsListMap.end()) { _selectedItemsListMap.insert(listName, GameplayObjects()); - setupHandler(listName); - // doSetupHandler = true; } + setupHandler(listName); + (*highlightStyle).setBoundToList(true); } (*highlightStyle).fromVariantMap(highlightStyleValues); -/* if (doSetupHandler) { - setupHandler(listName); - }*/ - auto mainScene = qApp->getMain3DScene(); if (mainScene) { render::Transaction transaction; @@ -139,7 +134,12 @@ bool SelectionScriptingInterface::disableListHighlight(const QString& listName) } QVariantMap SelectionScriptingInterface::getListHighlightStyle(const QString& listName) const { - return QVariantMap(); + auto highlightStyle = _highlightedListMap.find(listName); + if (highlightStyle == _highlightedListMap.end()) { + return QVariantMap(); + } else { + return (*highlightStyle).toVariantMap(); + } } render::HighlightStyle SelectionScriptingInterface::getHighlightStyle(const QString& listName) const { @@ -156,7 +156,7 @@ template bool SelectionScriptingInterface::addToGameplayObjects(const currentList.addToGameplayObjects(idToAdd); _selectedItemsListMap.insert(listName, currentList); - emit selectedItemsListChanged(listName); + onSelectedItemsListChanged(listName); return true; } template bool SelectionScriptingInterface::removeFromGameplayObjects(const QString& listName, T idToRemove) { @@ -165,7 +165,7 @@ template bool SelectionScriptingInterface::removeFromGameplayObjects(c currentList.removeFromGameplayObjects(idToRemove); _selectedItemsListMap.insert(listName, currentList); - emit selectedItemsListChanged(listName); + onSelectedItemsListChanged(listName); return true; } else { return false; @@ -180,34 +180,40 @@ GameplayObjects SelectionScriptingInterface::getList(const QString& listName) { } void SelectionScriptingInterface::printList(const QString& listName) { - GameplayObjects currentList = _selectedItemsListMap.value(listName); - if (currentList.getContainsData()) { + auto currentList = _selectedItemsListMap.find(listName); + if (currentList != _selectedItemsListMap.end()) { + if ((*currentList).getContainsData()) { - qDebug() << "Avatar IDs:"; - for (auto i : currentList.getAvatarIDs()) { - qDebug() << i << ';'; - } - qDebug() << ""; + qDebug() << "List named " << listName << ":"; + qDebug() << "Avatar IDs:"; + for (auto i : (*currentList).getAvatarIDs()) { + qDebug() << i << ';'; + } + qDebug() << ""; - qDebug() << "Entity IDs:"; - for (auto j : currentList.getEntityIDs()) { - qDebug() << j << ';'; - } - qDebug() << ""; + qDebug() << "Entity IDs:"; + for (auto j : (*currentList).getEntityIDs()) { + qDebug() << j << ';'; + } + qDebug() << ""; - qDebug() << "Overlay IDs:"; - for (auto k : currentList.getOverlayIDs()) { - qDebug() << k << ';'; + qDebug() << "Overlay IDs:"; + for (auto k : (*currentList).getOverlayIDs()) { + qDebug() << k << ';'; + } + qDebug() << ""; + } + else { + qDebug() << "List named " << listName << " empty"; } - qDebug() << ""; } else { - qDebug() << "List named" << listName << "doesn't exist."; + qDebug() << "List named " << listName << " doesn't exist."; } } bool SelectionScriptingInterface::removeListFromMap(const QString& listName) { if (_selectedItemsListMap.remove(listName)) { - emit selectedItemsListChanged(listName); + onSelectedItemsListChanged(listName); return true; } else { return false; @@ -222,9 +228,17 @@ void SelectionScriptingInterface::setupHandler(const QString& selectionName) { (*handler)->initialize(selectionName); + // connect(this, &SelectionScriptingInterface::selectedItemsListChanged, handler.value(), &SelectionToSceneHandler::selectedItemsListChanged); } +void SelectionScriptingInterface::onSelectedItemsListChanged(const QString& listName) { + auto handler = _handlerMap.find(listName); + if (handler != _handlerMap.end()) { + (*handler)->updateSceneFromSelectedList(); + } +} + SelectionToSceneHandler::SelectionToSceneHandler() { } @@ -232,10 +246,8 @@ SelectionToSceneHandler::SelectionToSceneHandler() { void SelectionToSceneHandler::initialize(const QString& listName) { _listName = listName; - connect(&(*DependencyManager::get()), &SelectionScriptingInterface::selectedItemsListChanged, this, &SelectionToSceneHandler::selectedItemsListChanged); - // connect(&(*DependencyManager::get()), &SelectionScriptingInterface::highlightStyleChanged, this, &SelectionToSceneHandler::highlightStyleChanged); - // connect(&(*DependencyManager::get()), &SelectionScriptingInterface::highlightStyleRemoved, this, &SelectionToSceneHandler::highlightStyleRemoved); + updateSceneFromSelectedList(); } void SelectionToSceneHandler::selectedItemsListChanged(const QString& listName) { diff --git a/interface/src/scripting/SelectionScriptingInterface.h b/interface/src/scripting/SelectionScriptingInterface.h index 96cc71906f..7d84443085 100644 --- a/interface/src/scripting/SelectionScriptingInterface.h +++ b/interface/src/scripting/SelectionScriptingInterface.h @@ -138,6 +138,8 @@ public: render::HighlightStyle getHighlightStyle(const QString& listName) const; + void onSelectedItemsListChanged(const QString& listName); + signals: void selectedItemsListChanged(const QString& listName); // void highlightStyleChanged(const QString& listName); diff --git a/libraries/render-utils/src/HighlightEffect.cpp b/libraries/render-utils/src/HighlightEffect.cpp index 7c58e5ba66..79ae96c07c 100644 --- a/libraries/render-utils/src/HighlightEffect.cpp +++ b/libraries/render-utils/src/HighlightEffect.cpp @@ -432,6 +432,24 @@ void SelectionToHighlight::run(const render::RenderContextPointer& renderContext outputs.clear(); _sharedParameters->_highlightIds.fill(render::HighlightStage::INVALID_INDEX); + int numLayers = 0; + auto highlightList = highlightStage->getActiveHighlightIds(); + + for (auto styleId : highlightList) { + auto highlight = highlightStage->getHighlight(styleId); + + if (!scene->isSelectionEmpty(highlight._selectionName)) { + auto highlightId = highlightStage->getHighlightIdBySelection(highlight._selectionName); + _sharedParameters->_highlightIds[outputs.size()] = highlightId; + outputs.emplace_back(highlight._selectionName); + numLayers++; + + if (numLayers == HighlightSharedParameters::MAX_PASS_COUNT) { + break; + } + } + } + /* for (auto i = 0; i < HighlightSharedParameters::MAX_PASS_COUNT; i++) { std::ostringstream stream; if (i > 0) { @@ -447,7 +465,7 @@ void SelectionToHighlight::run(const render::RenderContextPointer& renderContext outputs.emplace_back(selectionName); } } - } + }*/ } void ExtractSelectionName::run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs) { diff --git a/libraries/render/src/render/HighlightStage.h b/libraries/render/src/render/HighlightStage.h index b35fff654c..94c6e3ca69 100644 --- a/libraries/render/src/render/HighlightStage.h +++ b/libraries/render/src/render/HighlightStage.h @@ -51,6 +51,7 @@ namespace render { HighlightIdList::iterator begin() { return _activeHighlightIds.begin(); } HighlightIdList::iterator end() { return _activeHighlightIds.end(); } + const HighlightIdList& getActiveHighlightIds() const { return _activeHighlightIds; } private: diff --git a/libraries/render/src/render/Scene.cpp b/libraries/render/src/render/Scene.cpp index 88e25b6d27..dc1c6a0e49 100644 --- a/libraries/render/src/render/Scene.cpp +++ b/libraries/render/src/render/Scene.cpp @@ -442,7 +442,7 @@ bool Scene::isSelectionEmpty(const Selection::Name& name) const { std::unique_lock lock(_selectionsMutex); auto found = _selections.find(name); if (found == _selections.end()) { - return false; + return true; } else { return (*found).second.isEmpty(); }