History

fix material inspector not grabbing correct material sometimes

HifiExperiments committed 2 years ago

Commit b482c4a1 parent b38237c5 files · +59 −30Browse files

Showing the changes to libraries/render-utils/src/Model.cpp (1 of 5 files). Show all

Unified · Split

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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t