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
16531653 return !_meshStates.empty() || (isLoaded() && _renderGeometry->getMeshes().empty());
16541654 }
16551655
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;
16581658
16591659 const QString all("all");
16601660 if (parentMaterialName == all) {
16611661 for (unsigned int i = 0; i < (unsigned int)_modelMeshRenderItemIDs.size(); i++) {
1662− toReturn.insert(i);
1662+ toReturn.insert({ i, i < _modelMeshMaterialNames.size() ? _modelMeshMaterialNames[i] : "" });
16631663 }
16641664 } else if (!parentMaterialName.isEmpty()) {
16651665 auto parseFunc = [this, &toReturn] (QString& target) {
@@ -1673,12 +1673,14 @@ std::set<unsigned int> Model::getMeshIDsFromMaterialID(QString parentMaterialNam · 7 unmodified lines
16731673 std::string targetStdString = target.replace(0, MATERIAL_NAME_PREFIX.size(), "").toStdString();
16741674 for (unsigned int i = 0; i < (unsigned int)_modelMeshMaterialNames.size(); i++) {
16751675 if (_modelMeshMaterialNames[i] == targetStdString) {
1676− toReturn.insert(i);
1676+ toReturn.insert({ i, _modelMeshMaterialNames[i] });
16771677 }
16781678 }
16791679 return;
16801680 }
1681− toReturn.insert(target.toUInt());
1681+
1682+ uint result = target.toUInt();
1683+ toReturn.insert({ result, result < _modelMeshMaterialNames.size() ? _modelMeshMaterialNames[result] : "" });
16821684 };
16831685
16841686 if (parentMaterialName.length() > 2 && parentMaterialName.startsWith("[") && parentMaterialName.endsWith("]")) {
@@ -1720,15 +1722,15 @@ void Model::applyMaterialMapping() { · 35 unmodified lines
17201722 continue;
17211723 }
17221724
1723− std::set<unsigned int> shapeIDs = getMeshIDsFromMaterialID(QString(mapping.first.c_str()));
1725+ auto shapeIDs = getMeshIDsAndMaterialNamesFromMaterialID(QString(mapping.first.c_str()));
17241726 if (shapeIDs.size() == 0) {
17251727 continue;
17261728 }
17271729
17281730 // This needs to be precomputed before the lambda, since the lambdas could be called out of order
17291731 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];
17321734 }
17331735
17341736 std::weak_ptr<Model> weakSelf = shared_from_this();
@@ -1756,15 +1758,15 @@ void Model::applyMaterialMapping() { · 21 unmodified lines
17561758 networkMaterial = networkMaterialResource->parsedMaterials.networkMaterials[networkMaterialResource->parsedMaterials.names[0]];
17571759 }
17581760 }
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;
17631765 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));
17651767 {
17661768 std::unique_lock<std::mutex> lock(self->_materialMappingMutex);
1767− self->_materialMapping[shapeID].push_back(material);
1769+ self->_materialMapping[shapeID.first].push_back(material);
17681770 }
17691771 transaction.updateItem<ModelMeshPartPayload>(itemID, [material, renderItemsKey,
17701772 invalidatePayloadShapeKey, primitiveMode, useDualQuaternionSkinning](ModelMeshPartPayload& data) {
@@ -1787,17 +1789,17 @@ void Model::applyMaterialMapping() { · 16 unmodified lines
17871789 }
17881790
17891791 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()));
17911793
17921794 auto renderItemsKey = _renderItemKeyGlobalFlags;
17931795 PrimitiveMode primitiveMode = getPrimitiveMode();
17941796 bool useDualQuaternionSkinning = _useDualQuaternionSkinning;
17951797
17961798 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;
18011803 bool invalidatePayloadShapeKey = shouldInvalidatePayloadShapeKey(meshIndex);
18021804 transaction.updateItem<ModelMeshPartPayload>(itemID, [material, renderItemsKey,
18031805 invalidatePayloadShapeKey, primitiveMode, useDualQuaternionSkinning](ModelMeshPartPayload& data) {
@@ -1812,14 +1814,14 @@ void Model::addMaterial(graphics::MaterialLayer material, const std::string& par · 8 unmodified lines
18121814 }
18131815
18141816 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()));
18161818 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];
18201822 auto renderItemsKey = _renderItemKeyGlobalFlags;
18211823 PrimitiveMode primitiveMode = getPrimitiveMode();
1822− auto meshIndex = _modelMeshRenderItemShapes[shapeID].meshIndex;
1824+ auto meshIndex = _modelMeshRenderItemShapes[shapeID.first].meshIndex;
18231825 bool invalidatePayloadShapeKey = shouldInvalidatePayloadShapeKey(meshIndex);
18241826 bool useDualQuaternionSkinning = _useDualQuaternionSkinning;
18251827 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