Showing the changes to libraries/render-utils/src/Model.cpp (1 of 5 files). Show all
Unified · Split
| @@ -1653,13 +1653,13 @@ bool Model::isRenderable() const { · 1652 unmodified lines | ||
| 1653 | 1653 | return !_meshStates.empty() || (isLoaded() && _renderGeometry->getMeshes().empty()); |
| 1654 | 1654 | } |
| 1655 | 1655 | |
| 1656 | −std::set<unsigned int> Model::getMeshIDsFromMaterialID(QString parentMaterialName) { | |
| 1657 | − std::set<unsigned int> toReturn; | |
| 1656 | +std::set<std::pair<uint, std::string>> Model::getMeshIDsAndMaterialNamesFromMaterialID(QString parentMaterialName) { | |
| 1657 | + std::set<std::pair<uint, std::string>> toReturn; | |
| 1658 | 1658 | |
| 1659 | 1659 | const QString all("all"); |
| 1660 | 1660 | if (parentMaterialName == all) { |
| 1661 | 1661 | for (unsigned int i = 0; i < (unsigned int)_modelMeshRenderItemIDs.size(); i++) { |
| 1662 | − toReturn.insert(i); | |
| 1662 | + toReturn.insert({ i, i < _modelMeshMaterialNames.size() ? _modelMeshMaterialNames[i] : "" }); | |
| 1663 | 1663 | } |
| 1664 | 1664 | } else if (!parentMaterialName.isEmpty()) { |
| 1665 | 1665 | auto parseFunc = [this, &toReturn] (QString& target) { |
| @@ -1673,12 +1673,14 @@ std::set<unsigned int> Model::getMeshIDsFromMaterialID(QString parentMaterialNam · 7 unmodified lines | ||
| 1673 | 1673 | std::string targetStdString = target.replace(0, MATERIAL_NAME_PREFIX.size(), "").toStdString(); |
| 1674 | 1674 | for (unsigned int i = 0; i < (unsigned int)_modelMeshMaterialNames.size(); i++) { |
| 1675 | 1675 | if (_modelMeshMaterialNames[i] == targetStdString) { |
| 1676 | − toReturn.insert(i); | |
| 1676 | + toReturn.insert({ i, _modelMeshMaterialNames[i] }); | |
| 1677 | 1677 | } |
| 1678 | 1678 | } |
| 1679 | 1679 | return; |
| 1680 | 1680 | } |
| 1681 | − toReturn.insert(target.toUInt()); | |
| 1681 | + | |
| 1682 | + uint result = target.toUInt(); | |
| 1683 | + toReturn.insert({ result, result < _modelMeshMaterialNames.size() ? _modelMeshMaterialNames[result] : "" }); | |
| 1682 | 1684 | }; |
| 1683 | 1685 | |
| 1684 | 1686 | if (parentMaterialName.length() > 2 && parentMaterialName.startsWith("[") && parentMaterialName.endsWith("]")) { |
| @@ -1720,15 +1722,15 @@ void Model::applyMaterialMapping() { · 35 unmodified lines | ||
| 1720 | 1722 | continue; |
| 1721 | 1723 | } |
| 1722 | 1724 | |
| 1723 | − std::set<unsigned int> shapeIDs = getMeshIDsFromMaterialID(QString(mapping.first.c_str())); | |
| 1725 | + auto shapeIDs = getMeshIDsAndMaterialNamesFromMaterialID(QString(mapping.first.c_str())); | |
| 1724 | 1726 | if (shapeIDs.size() == 0) { |
| 1725 | 1727 | continue; |
| 1726 | 1728 | } |
| 1727 | 1729 | |
| 1728 | 1730 | // This needs to be precomputed before the lambda, since the lambdas could be called out of order |
| 1729 | 1731 | std::unordered_map<unsigned int, quint16> priorityMapPerResource; |
| 1730 | − for (auto shapeID : shapeIDs) { | |
| 1731 | − priorityMapPerResource[shapeID] = ++_priorityMap[shapeID]; | |
| 1732 | + for (const auto& shapeID : shapeIDs) { | |
| 1733 | + priorityMapPerResource[shapeID.first] = ++_priorityMap[shapeID.first]; | |
| 1732 | 1734 | } |
| 1733 | 1735 | |
| 1734 | 1736 | std::weak_ptr<Model> weakSelf = shared_from_this(); |
| @@ -1756,15 +1758,15 @@ void Model::applyMaterialMapping() { · 21 unmodified lines | ||
| 1756 | 1758 | networkMaterial = networkMaterialResource->parsedMaterials.networkMaterials[networkMaterialResource->parsedMaterials.names[0]]; |
| 1757 | 1759 | } |
| 1758 | 1760 | } |
| 1759 | − for (auto shapeID : shapeIDs) { | |
| 1760 | − if (shapeID < modelMeshRenderItemIDs.size()) { | |
| 1761 | − auto itemID = modelMeshRenderItemIDs[shapeID]; | |
| 1762 | − auto meshIndex = modelMeshRenderItemShapes[shapeID].meshIndex; | |
| 1761 | + for (const auto& shapeID : shapeIDs) { | |
| 1762 | + if (shapeID.first < modelMeshRenderItemIDs.size()) { | |
| 1763 | + auto itemID = modelMeshRenderItemIDs[shapeID.first]; | |
| 1764 | + auto meshIndex = modelMeshRenderItemShapes[shapeID.first].meshIndex; | |
| 1763 | 1765 | bool invalidatePayloadShapeKey = shouldInvalidatePayloadShapeKeyMap.at(meshIndex); |
| 1764 | − graphics::MaterialLayer material = graphics::MaterialLayer(networkMaterial, priorityMapPerResource.at(shapeID)); | |
| 1766 | + graphics::MaterialLayer material = graphics::MaterialLayer(networkMaterial, priorityMapPerResource.at(shapeID.first)); | |
| 1765 | 1767 | { |
| 1766 | 1768 | std::unique_lock<std::mutex> lock(self->_materialMappingMutex); |
| 1767 | − self->_materialMapping[shapeID].push_back(material); | |
| 1769 | + self->_materialMapping[shapeID.first].push_back(material); | |
| 1768 | 1770 | } |
| 1769 | 1771 | transaction.updateItem<ModelMeshPartPayload>(itemID, [material, renderItemsKey, |
| 1770 | 1772 | invalidatePayloadShapeKey, primitiveMode, useDualQuaternionSkinning](ModelMeshPartPayload& data) { |
| @@ -1787,17 +1789,17 @@ void Model::applyMaterialMapping() { · 16 unmodified lines | ||
| 1787 | 1789 | } |
| 1788 | 1790 | |
| 1789 | 1791 | void Model::addMaterial(graphics::MaterialLayer material, const std::string& parentMaterialName) { |
| 1790 | − std::set<unsigned int> shapeIDs = getMeshIDsFromMaterialID(QString(parentMaterialName.c_str())); | |
| 1792 | + auto shapeIDs = getMeshIDsAndMaterialNamesFromMaterialID(QString(parentMaterialName.c_str())); | |
| 1791 | 1793 | |
| 1792 | 1794 | auto renderItemsKey = _renderItemKeyGlobalFlags; |
| 1793 | 1795 | PrimitiveMode primitiveMode = getPrimitiveMode(); |
| 1794 | 1796 | bool useDualQuaternionSkinning = _useDualQuaternionSkinning; |
| 1795 | 1797 | |
| 1796 | 1798 | render::Transaction transaction; |
| 1797 | − for (auto shapeID : shapeIDs) { | |
| 1798 | − if (shapeID < _modelMeshRenderItemIDs.size()) { | |
| 1799 | − auto itemID = _modelMeshRenderItemIDs[shapeID]; | |
| 1800 | − auto meshIndex = _modelMeshRenderItemShapes[shapeID].meshIndex; | |
| 1799 | + for (const auto& shapeID : shapeIDs) { | |
| 1800 | + if (shapeID.first < _modelMeshRenderItemIDs.size()) { | |
| 1801 | + auto itemID = _modelMeshRenderItemIDs[shapeID.first]; | |
| 1802 | + auto meshIndex = _modelMeshRenderItemShapes[shapeID.first].meshIndex; | |
| 1801 | 1803 | bool invalidatePayloadShapeKey = shouldInvalidatePayloadShapeKey(meshIndex); |
| 1802 | 1804 | transaction.updateItem<ModelMeshPartPayload>(itemID, [material, renderItemsKey, |
| 1803 | 1805 | invalidatePayloadShapeKey, primitiveMode, useDualQuaternionSkinning](ModelMeshPartPayload& data) { |
| @@ -1812,14 +1814,14 @@ void Model::addMaterial(graphics::MaterialLayer material, const std::string& par · 8 unmodified lines | ||
| 1812 | 1814 | } |
| 1813 | 1815 | |
| 1814 | 1816 | void Model::removeMaterial(graphics::MaterialPointer material, const std::string& parentMaterialName) { |
| 1815 | − std::set<unsigned int> shapeIDs = getMeshIDsFromMaterialID(QString(parentMaterialName.c_str())); | |
| 1817 | + auto shapeIDs = getMeshIDsAndMaterialNamesFromMaterialID(QString(parentMaterialName.c_str())); | |
| 1816 | 1818 | render::Transaction transaction; |
| 1817 | − for (auto shapeID : shapeIDs) { | |
| 1818 | − if (shapeID < _modelMeshRenderItemIDs.size()) { | |
| 1819 | − auto itemID = _modelMeshRenderItemIDs[shapeID]; | |
| 1819 | + for (const auto& shapeID : shapeIDs) { | |
| 1820 | + if (shapeID.first < _modelMeshRenderItemIDs.size()) { | |
| 1821 | + auto itemID = _modelMeshRenderItemIDs[shapeID.first]; | |
| 1820 | 1822 | auto renderItemsKey = _renderItemKeyGlobalFlags; |
| 1821 | 1823 | PrimitiveMode primitiveMode = getPrimitiveMode(); |
| 1822 | − auto meshIndex = _modelMeshRenderItemShapes[shapeID].meshIndex; | |
| 1824 | + auto meshIndex = _modelMeshRenderItemShapes[shapeID.first].meshIndex; | |
| 1823 | 1825 | bool invalidatePayloadShapeKey = shouldInvalidatePayloadShapeKey(meshIndex); |
| 1824 | 1826 | bool useDualQuaternionSkinning = _useDualQuaternionSkinning; |
| 1825 | 1827 | transaction.updateItem<ModelMeshPartPayload>(itemID, [material, renderItemsKey, |