mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 18:06:57 +02:00
Merge b482c4a8a9
into b38237cb8d
This commit is contained in:
commit
9f827705cb
5 changed files with 59 additions and 30 deletions
|
@ -1957,10 +1957,23 @@ scriptable::ScriptableModelBase Avatar::getScriptableModel() {
|
||||||
}
|
}
|
||||||
auto result = _skeletonModel->getScriptableModel();
|
auto result = _skeletonModel->getScriptableModel();
|
||||||
result.objectID = getSessionUUID().isNull() ? AVATAR_SELF_ID : getSessionUUID();
|
result.objectID = getSessionUUID().isNull() ? AVATAR_SELF_ID : getSessionUUID();
|
||||||
|
|
||||||
|
std::unordered_map<std::string, graphics::MultiMaterial> materials;
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(_materialsLock);
|
std::lock_guard<std::mutex> lock(_materialsLock);
|
||||||
result.appendMaterials(_materials);
|
materials = _materials;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto& multiMaterial : materials) {
|
||||||
|
while (!multiMaterial.second.empty()) {
|
||||||
|
auto shapeIDs = _skeletonModel->getMeshIDsAndMaterialNamesFromMaterialID(multiMaterial.first.c_str());
|
||||||
|
for (const auto& shapeID : shapeIDs) {
|
||||||
|
result.appendMaterial(multiMaterial.second.top(), shapeID.first, shapeID.second);
|
||||||
|
}
|
||||||
|
multiMaterial.second.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -987,10 +987,23 @@ scriptable::ScriptableModelBase render::entities::ModelEntityRenderer::getScript
|
||||||
|
|
||||||
auto result = model->getScriptableModel();
|
auto result = model->getScriptableModel();
|
||||||
result.objectID = getEntity()->getID();
|
result.objectID = getEntity()->getID();
|
||||||
|
|
||||||
|
std::unordered_map<std::string, graphics::MultiMaterial> materials;
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(_materialsLock);
|
std::lock_guard<std::mutex> lock(_materialsLock);
|
||||||
result.appendMaterials(_materials);
|
materials = _materials;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto& multiMaterial : materials) {
|
||||||
|
while (!multiMaterial.second.empty()) {
|
||||||
|
auto shapeIDs = model->getMeshIDsAndMaterialNamesFromMaterialID(multiMaterial.first.c_str());
|
||||||
|
for (const auto& shapeID : shapeIDs) {
|
||||||
|
result.appendMaterial(multiMaterial.second.top(), shapeID.first, shapeID.second);
|
||||||
|
}
|
||||||
|
multiMaterial.second.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -257,8 +257,9 @@ void scriptable::ScriptableModelBase::append(const ScriptableMeshBase& mesh) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void scriptable::ScriptableModelBase::appendMaterial(const graphics::MaterialLayer& materialLayer, int shapeID, std::string materialName) {
|
void scriptable::ScriptableModelBase::appendMaterial(const graphics::MaterialLayer& materialLayer, int shapeID, std::string materialName) {
|
||||||
materialLayers[QString::number(shapeID)].push_back(ScriptableMaterialLayer(materialLayer));
|
ScriptableMaterialLayer layer = ScriptableMaterialLayer(materialLayer);
|
||||||
materialLayers["mat::" + QString::fromStdString(materialName)].push_back(ScriptableMaterialLayer(materialLayer));
|
materialLayers[QString::number(shapeID)].push_back(layer);
|
||||||
|
materialLayers["mat::" + QString::fromStdString(materialName)].push_back(layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void scriptable::ScriptableModelBase::appendMaterials(const std::unordered_map<std::string, graphics::MultiMaterial>& materialsToAppend) {
|
void scriptable::ScriptableModelBase::appendMaterials(const std::unordered_map<std::string, graphics::MultiMaterial>& materialsToAppend) {
|
||||||
|
|
|
@ -1653,13 +1653,13 @@ bool Model::isRenderable() const {
|
||||||
return !_meshStates.empty() || (isLoaded() && _renderGeometry->getMeshes().empty());
|
return !_meshStates.empty() || (isLoaded() && _renderGeometry->getMeshes().empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<unsigned int> Model::getMeshIDsFromMaterialID(QString parentMaterialName) {
|
std::set<std::pair<uint, std::string>> Model::getMeshIDsAndMaterialNamesFromMaterialID(QString parentMaterialName) {
|
||||||
std::set<unsigned int> toReturn;
|
std::set<std::pair<uint, std::string>> toReturn;
|
||||||
|
|
||||||
const QString all("all");
|
const QString all("all");
|
||||||
if (parentMaterialName == all) {
|
if (parentMaterialName == all) {
|
||||||
for (unsigned int i = 0; i < (unsigned int)_modelMeshRenderItemIDs.size(); i++) {
|
for (unsigned int i = 0; i < (unsigned int)_modelMeshRenderItemIDs.size(); i++) {
|
||||||
toReturn.insert(i);
|
toReturn.insert({ i, i < _modelMeshMaterialNames.size() ? _modelMeshMaterialNames[i] : "" });
|
||||||
}
|
}
|
||||||
} else if (!parentMaterialName.isEmpty()) {
|
} else if (!parentMaterialName.isEmpty()) {
|
||||||
auto parseFunc = [this, &toReturn] (QString& target) {
|
auto parseFunc = [this, &toReturn] (QString& target) {
|
||||||
|
@ -1673,12 +1673,14 @@ std::set<unsigned int> Model::getMeshIDsFromMaterialID(QString parentMaterialNam
|
||||||
std::string targetStdString = target.replace(0, MATERIAL_NAME_PREFIX.size(), "").toStdString();
|
std::string targetStdString = target.replace(0, MATERIAL_NAME_PREFIX.size(), "").toStdString();
|
||||||
for (unsigned int i = 0; i < (unsigned int)_modelMeshMaterialNames.size(); i++) {
|
for (unsigned int i = 0; i < (unsigned int)_modelMeshMaterialNames.size(); i++) {
|
||||||
if (_modelMeshMaterialNames[i] == targetStdString) {
|
if (_modelMeshMaterialNames[i] == targetStdString) {
|
||||||
toReturn.insert(i);
|
toReturn.insert({ i, _modelMeshMaterialNames[i] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
toReturn.insert(target.toUInt());
|
|
||||||
|
uint result = target.toUInt();
|
||||||
|
toReturn.insert({ result, result < _modelMeshMaterialNames.size() ? _modelMeshMaterialNames[result] : "" });
|
||||||
};
|
};
|
||||||
|
|
||||||
if (parentMaterialName.length() > 2 && parentMaterialName.startsWith("[") && parentMaterialName.endsWith("]")) {
|
if (parentMaterialName.length() > 2 && parentMaterialName.startsWith("[") && parentMaterialName.endsWith("]")) {
|
||||||
|
@ -1720,15 +1722,15 @@ void Model::applyMaterialMapping() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<unsigned int> shapeIDs = getMeshIDsFromMaterialID(QString(mapping.first.c_str()));
|
auto shapeIDs = getMeshIDsAndMaterialNamesFromMaterialID(QString(mapping.first.c_str()));
|
||||||
if (shapeIDs.size() == 0) {
|
if (shapeIDs.size() == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This needs to be precomputed before the lambda, since the lambdas could be called out of order
|
// This needs to be precomputed before the lambda, since the lambdas could be called out of order
|
||||||
std::unordered_map<unsigned int, quint16> priorityMapPerResource;
|
std::unordered_map<unsigned int, quint16> priorityMapPerResource;
|
||||||
for (auto shapeID : shapeIDs) {
|
for (const auto& shapeID : shapeIDs) {
|
||||||
priorityMapPerResource[shapeID] = ++_priorityMap[shapeID];
|
priorityMapPerResource[shapeID.first] = ++_priorityMap[shapeID.first];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::weak_ptr<Model> weakSelf = shared_from_this();
|
std::weak_ptr<Model> weakSelf = shared_from_this();
|
||||||
|
@ -1756,15 +1758,15 @@ void Model::applyMaterialMapping() {
|
||||||
networkMaterial = networkMaterialResource->parsedMaterials.networkMaterials[networkMaterialResource->parsedMaterials.names[0]];
|
networkMaterial = networkMaterialResource->parsedMaterials.networkMaterials[networkMaterialResource->parsedMaterials.names[0]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto shapeID : shapeIDs) {
|
for (const auto& shapeID : shapeIDs) {
|
||||||
if (shapeID < modelMeshRenderItemIDs.size()) {
|
if (shapeID.first < modelMeshRenderItemIDs.size()) {
|
||||||
auto itemID = modelMeshRenderItemIDs[shapeID];
|
auto itemID = modelMeshRenderItemIDs[shapeID.first];
|
||||||
auto meshIndex = modelMeshRenderItemShapes[shapeID].meshIndex;
|
auto meshIndex = modelMeshRenderItemShapes[shapeID.first].meshIndex;
|
||||||
bool invalidatePayloadShapeKey = shouldInvalidatePayloadShapeKeyMap.at(meshIndex);
|
bool invalidatePayloadShapeKey = shouldInvalidatePayloadShapeKeyMap.at(meshIndex);
|
||||||
graphics::MaterialLayer material = graphics::MaterialLayer(networkMaterial, priorityMapPerResource.at(shapeID));
|
graphics::MaterialLayer material = graphics::MaterialLayer(networkMaterial, priorityMapPerResource.at(shapeID.first));
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(self->_materialMappingMutex);
|
std::unique_lock<std::mutex> lock(self->_materialMappingMutex);
|
||||||
self->_materialMapping[shapeID].push_back(material);
|
self->_materialMapping[shapeID.first].push_back(material);
|
||||||
}
|
}
|
||||||
transaction.updateItem<ModelMeshPartPayload>(itemID, [material, renderItemsKey,
|
transaction.updateItem<ModelMeshPartPayload>(itemID, [material, renderItemsKey,
|
||||||
invalidatePayloadShapeKey, primitiveMode, useDualQuaternionSkinning](ModelMeshPartPayload& data) {
|
invalidatePayloadShapeKey, primitiveMode, useDualQuaternionSkinning](ModelMeshPartPayload& data) {
|
||||||
|
@ -1787,17 +1789,17 @@ void Model::applyMaterialMapping() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::addMaterial(graphics::MaterialLayer material, const std::string& parentMaterialName) {
|
void Model::addMaterial(graphics::MaterialLayer material, const std::string& parentMaterialName) {
|
||||||
std::set<unsigned int> shapeIDs = getMeshIDsFromMaterialID(QString(parentMaterialName.c_str()));
|
auto shapeIDs = getMeshIDsAndMaterialNamesFromMaterialID(QString(parentMaterialName.c_str()));
|
||||||
|
|
||||||
auto renderItemsKey = _renderItemKeyGlobalFlags;
|
auto renderItemsKey = _renderItemKeyGlobalFlags;
|
||||||
PrimitiveMode primitiveMode = getPrimitiveMode();
|
PrimitiveMode primitiveMode = getPrimitiveMode();
|
||||||
bool useDualQuaternionSkinning = _useDualQuaternionSkinning;
|
bool useDualQuaternionSkinning = _useDualQuaternionSkinning;
|
||||||
|
|
||||||
render::Transaction transaction;
|
render::Transaction transaction;
|
||||||
for (auto shapeID : shapeIDs) {
|
for (const auto& shapeID : shapeIDs) {
|
||||||
if (shapeID < _modelMeshRenderItemIDs.size()) {
|
if (shapeID.first < _modelMeshRenderItemIDs.size()) {
|
||||||
auto itemID = _modelMeshRenderItemIDs[shapeID];
|
auto itemID = _modelMeshRenderItemIDs[shapeID.first];
|
||||||
auto meshIndex = _modelMeshRenderItemShapes[shapeID].meshIndex;
|
auto meshIndex = _modelMeshRenderItemShapes[shapeID.first].meshIndex;
|
||||||
bool invalidatePayloadShapeKey = shouldInvalidatePayloadShapeKey(meshIndex);
|
bool invalidatePayloadShapeKey = shouldInvalidatePayloadShapeKey(meshIndex);
|
||||||
transaction.updateItem<ModelMeshPartPayload>(itemID, [material, renderItemsKey,
|
transaction.updateItem<ModelMeshPartPayload>(itemID, [material, renderItemsKey,
|
||||||
invalidatePayloadShapeKey, primitiveMode, useDualQuaternionSkinning](ModelMeshPartPayload& data) {
|
invalidatePayloadShapeKey, primitiveMode, useDualQuaternionSkinning](ModelMeshPartPayload& data) {
|
||||||
|
@ -1812,14 +1814,14 @@ void Model::addMaterial(graphics::MaterialLayer material, const std::string& par
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::removeMaterial(graphics::MaterialPointer material, const std::string& parentMaterialName) {
|
void Model::removeMaterial(graphics::MaterialPointer material, const std::string& parentMaterialName) {
|
||||||
std::set<unsigned int> shapeIDs = getMeshIDsFromMaterialID(QString(parentMaterialName.c_str()));
|
auto shapeIDs = getMeshIDsAndMaterialNamesFromMaterialID(QString(parentMaterialName.c_str()));
|
||||||
render::Transaction transaction;
|
render::Transaction transaction;
|
||||||
for (auto shapeID : shapeIDs) {
|
for (const auto& shapeID : shapeIDs) {
|
||||||
if (shapeID < _modelMeshRenderItemIDs.size()) {
|
if (shapeID.first < _modelMeshRenderItemIDs.size()) {
|
||||||
auto itemID = _modelMeshRenderItemIDs[shapeID];
|
auto itemID = _modelMeshRenderItemIDs[shapeID.first];
|
||||||
auto renderItemsKey = _renderItemKeyGlobalFlags;
|
auto renderItemsKey = _renderItemKeyGlobalFlags;
|
||||||
PrimitiveMode primitiveMode = getPrimitiveMode();
|
PrimitiveMode primitiveMode = getPrimitiveMode();
|
||||||
auto meshIndex = _modelMeshRenderItemShapes[shapeID].meshIndex;
|
auto meshIndex = _modelMeshRenderItemShapes[shapeID.first].meshIndex;
|
||||||
bool invalidatePayloadShapeKey = shouldInvalidatePayloadShapeKey(meshIndex);
|
bool invalidatePayloadShapeKey = shouldInvalidatePayloadShapeKey(meshIndex);
|
||||||
bool useDualQuaternionSkinning = _useDualQuaternionSkinning;
|
bool useDualQuaternionSkinning = _useDualQuaternionSkinning;
|
||||||
transaction.updateItem<ModelMeshPartPayload>(itemID, [material, renderItemsKey,
|
transaction.updateItem<ModelMeshPartPayload>(itemID, [material, renderItemsKey,
|
||||||
|
|
|
@ -371,6 +371,8 @@ public:
|
||||||
|
|
||||||
void setBlendshapeCoefficients(const QVector<float>& coefficients) { _blendshapeCoefficients = coefficients; }
|
void setBlendshapeCoefficients(const QVector<float>& coefficients) { _blendshapeCoefficients = coefficients; }
|
||||||
|
|
||||||
|
std::set<std::pair<uint, std::string>> getMeshIDsAndMaterialNamesFromMaterialID(QString parentMaterialName);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void loadURLFinished(bool success);
|
void loadURLFinished(bool success);
|
||||||
|
|
||||||
|
@ -521,8 +523,6 @@ private:
|
||||||
std::function<float()> _loadingPriorityOperator { []() { return 0.0f; } };
|
std::function<float()> _loadingPriorityOperator { []() { return 0.0f; } };
|
||||||
|
|
||||||
void calculateTextureInfo();
|
void calculateTextureInfo();
|
||||||
|
|
||||||
std::set<unsigned int> getMeshIDsFromMaterialID(QString parentMaterialName);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(ModelPointer)
|
Q_DECLARE_METATYPE(ModelPointer)
|
||||||
|
|
Loading…
Reference in a new issue