Showing the changes to libraries/render-utils/src/Model.cpp (1 of 13 files). Show all
Unified · Split
| @@ -1465,6 +1465,7 @@ void Model::createRenderItemSet() { · 1464 unmodified lines | |||
| 1465 | } | 1465 | } |
| 1466 | } | 1466 | } |
| 1467 | _blendshapeOffsetsInitialized = true; | 1467 | _blendshapeOffsetsInitialized = true; |
| 1468 | applyMaterialMapping(); | ||
| 1468 | } | 1469 | } |
| 1469 | 1470 | ||
| 1470 | bool Model::isRenderable() const { | 1471 | bool Model::isRenderable() const { |
| @@ -1519,17 +1520,60 @@ std::set<unsigned int> Model::getMeshIDsFromMaterialID(QString parentMaterialNam · 48 unmodified lines | |||
| 1519 | return toReturn; | 1520 | return toReturn; |
| 1520 | } | 1521 | } |
| 1521 | 1522 | ||
| 1523 | void Model::applyMaterialMapping() { | ||
| 1524 | auto renderItemsKey = _renderItemKeyGlobalFlags; | ||
| 1525 | PrimitiveMode primitiveMode = getPrimitiveMode(); | ||
| 1526 | bool useDualQuaternionSkinning = _useDualQuaternionSkinning; | ||
| 1527 | |||
| 1528 | render::Transaction transaction; | ||
| 1529 | std::unordered_map<unsigned int, quint16> priorityMap; | ||
| 1530 | auto& materialMapping = getMaterialMapping(); | ||
| 1531 | qDebug() << "boop" << materialMapping.size(); | ||
| 1532 | for (auto& mapping : materialMapping) { | ||
| 1533 | std::set<unsigned int> shapeIDs = getMeshIDsFromMaterialID(QString(mapping.first.c_str())); | ||
| 1534 | |||
| 1535 | qDebug() << "boop2" << mapping.first.c_str() << shapeIDs.size(); | ||
| 1536 | if (shapeIDs.size() == 0) { | ||
| 1537 | continue; | ||
| 1538 | } | ||
| 1539 | |||
| 1540 | auto networkMaterialResource = mapping.second; | ||
| 1541 | qDebug() << (bool)networkMaterialResource; | ||
| 1542 | if (networkMaterialResource && networkMaterialResource->isLoaded() && networkMaterialResource->parsedMaterials.names.size() > 0) { | ||
| 1543 | auto networkMaterial = networkMaterialResource->parsedMaterials.networkMaterials[networkMaterialResource->parsedMaterials.names[0]]; | ||
| 1544 | for (auto shapeID : shapeIDs) { | ||
| 1545 | if (shapeID < _modelMeshRenderItemIDs.size()) { | ||
| 1546 | auto itemID = _modelMeshRenderItemIDs[shapeID]; | ||
| 1547 | auto meshIndex = _modelMeshRenderItemShapes[shapeID].meshIndex; | ||
| 1548 | bool invalidatePayloadShapeKey = shouldInvalidatePayloadShapeKey(meshIndex); | ||
| 1549 | graphics::MaterialLayer material = graphics::MaterialLayer(networkMaterial, ++priorityMap[shapeID]); | ||
| 1550 | transaction.updateItem<ModelMeshPartPayload>(itemID, [material, renderItemsKey, | ||
| 1551 | invalidatePayloadShapeKey, primitiveMode, useDualQuaternionSkinning](ModelMeshPartPayload& data) { | ||
| 1552 | data.addMaterial(material); | ||
| 1553 | // if the material changed, we might need to update our item key or shape key | ||
| 1554 | data.updateKey(renderItemsKey); | ||
| 1555 | data.setShapeKey(invalidatePayloadShapeKey, primitiveMode, useDualQuaternionSkinning); | ||
| 1556 | }); | ||
| 1557 | } | ||
| 1558 | } | ||
| 1559 | } | ||
| 1560 | } | ||
| 1561 | AbstractViewStateInterface::instance()->getMain3DScene()->enqueueTransaction(transaction); | ||
| 1562 | } | ||
| 1563 | |||
| 1522 | void Model::addMaterial(graphics::MaterialLayer material, const std::string& parentMaterialName) { | 1564 | void Model::addMaterial(graphics::MaterialLayer material, const std::string& parentMaterialName) { |
| 1523 | std::set<unsigned int> shapeIDs = getMeshIDsFromMaterialID(QString(parentMaterialName.c_str())); | 1565 | std::set<unsigned int> shapeIDs = getMeshIDsFromMaterialID(QString(parentMaterialName.c_str())); |
| 1566 | |||
| 1567 | auto renderItemsKey = _renderItemKeyGlobalFlags; | ||
| 1568 | PrimitiveMode primitiveMode = getPrimitiveMode(); | ||
| 1569 | bool useDualQuaternionSkinning = _useDualQuaternionSkinning; | ||
| 1570 | |||
| 1524 | render::Transaction transaction; | 1571 | render::Transaction transaction; |
| 1525 | for (auto shapeID : shapeIDs) { | 1572 | for (auto shapeID : shapeIDs) { |
| 1526 | if (shapeID < _modelMeshRenderItemIDs.size()) { | 1573 | if (shapeID < _modelMeshRenderItemIDs.size()) { |
| 1527 | auto itemID = _modelMeshRenderItemIDs[shapeID]; | 1574 | auto itemID = _modelMeshRenderItemIDs[shapeID]; |
| 1528 | auto renderItemsKey = _renderItemKeyGlobalFlags; | ||
| 1529 | PrimitiveMode primitiveMode = getPrimitiveMode(); | ||
| 1530 | auto meshIndex = _modelMeshRenderItemShapes[shapeID].meshIndex; | 1575 | auto meshIndex = _modelMeshRenderItemShapes[shapeID].meshIndex; |
| 1531 | bool invalidatePayloadShapeKey = shouldInvalidatePayloadShapeKey(meshIndex); | 1576 | bool invalidatePayloadShapeKey = shouldInvalidatePayloadShapeKey(meshIndex); |
| 1532 | bool useDualQuaternionSkinning = _useDualQuaternionSkinning; | ||
| 1533 | transaction.updateItem<ModelMeshPartPayload>(itemID, [material, renderItemsKey, | 1577 | transaction.updateItem<ModelMeshPartPayload>(itemID, [material, renderItemsKey, |
| 1534 | invalidatePayloadShapeKey, primitiveMode, useDualQuaternionSkinning](ModelMeshPartPayload& data) { | 1578 | invalidatePayloadShapeKey, primitiveMode, useDualQuaternionSkinning](ModelMeshPartPayload& data) { |
| 1535 | data.addMaterial(material); | 1579 | data.addMaterial(material); |