mirror of
https://github.com/overte-org/overte.git
synced 2025-06-25 18:29:36 +02:00
Merge pull request #14835 from SamGondelman/textures
Case 20944: Fix Model textures property
This commit is contained in:
commit
dda310c0b9
5 changed files with 24 additions and 25 deletions
|
@ -1264,7 +1264,7 @@ bool ModelEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPoin
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_lastTextures != entity->getTextures()) {
|
if (_textures != entity->getTextures()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1418,15 +1418,14 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce
|
||||||
entity->_originalTexturesRead = true;
|
entity->_originalTexturesRead = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_lastTextures != entity->getTextures()) {
|
if (_textures != entity->getTextures()) {
|
||||||
|
QVariantMap newTextures;
|
||||||
withWriteLock([&] {
|
withWriteLock([&] {
|
||||||
_texturesLoaded = false;
|
_texturesLoaded = false;
|
||||||
_lastTextures = entity->getTextures();
|
_textures = entity->getTextures();
|
||||||
|
newTextures = parseTexturesToMap(_textures, entity->_originalTextures);
|
||||||
});
|
});
|
||||||
auto newTextures = parseTexturesToMap(_lastTextures, entity->_originalTextures);
|
model->setTextures(newTextures);
|
||||||
if (newTextures != model->getTextures()) {
|
|
||||||
model->setTextures(newTextures);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (entity->_needsJointSimulation) {
|
if (entity->_needsJointSimulation) {
|
||||||
entity->copyAnimationJointDataToModel();
|
entity->copyAnimationJointDataToModel();
|
||||||
|
|
|
@ -181,7 +181,7 @@ private:
|
||||||
|
|
||||||
bool _hasModel { false };
|
bool _hasModel { false };
|
||||||
ModelPointer _model;
|
ModelPointer _model;
|
||||||
QString _lastTextures;
|
QString _textures;
|
||||||
bool _texturesLoaded { false };
|
bool _texturesLoaded { false };
|
||||||
int _lastKnownCurrentFrame { -1 };
|
int _lastKnownCurrentFrame { -1 };
|
||||||
#ifdef MODEL_ENTITY_USE_FADE_EFFECT
|
#ifdef MODEL_ENTITY_USE_FADE_EFFECT
|
||||||
|
|
|
@ -43,14 +43,15 @@ ModelEntityItem::ModelEntityItem(const EntityItemID& entityItemID) : EntityItem(
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString ModelEntityItem::getTextures() const {
|
const QString ModelEntityItem::getTextures() const {
|
||||||
QReadLocker locker(&_texturesLock);
|
return resultWithReadLock<QString>([&] {
|
||||||
auto textures = _textures;
|
return _textures;
|
||||||
return textures;
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelEntityItem::setTextures(const QString& textures) {
|
void ModelEntityItem::setTextures(const QString& textures) {
|
||||||
QWriteLocker locker(&_texturesLock);
|
withWriteLock([&] {
|
||||||
_textures = textures;
|
_textures = textures;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityItemProperties ModelEntityItem::getProperties(const EntityPropertyFlags& desiredProperties, bool allowEmptyDesiredProperties) const {
|
EntityItemProperties ModelEntityItem::getProperties(const EntityPropertyFlags& desiredProperties, bool allowEmptyDesiredProperties) const {
|
||||||
|
|
|
@ -163,7 +163,6 @@ protected:
|
||||||
|
|
||||||
AnimationPropertyGroup _animationProperties;
|
AnimationPropertyGroup _animationProperties;
|
||||||
|
|
||||||
mutable QReadWriteLock _texturesLock;
|
|
||||||
QString _textures;
|
QString _textures;
|
||||||
|
|
||||||
ShapeType _shapeType = SHAPE_TYPE_NONE;
|
ShapeType _shapeType = SHAPE_TYPE_NONE;
|
||||||
|
|
|
@ -1247,30 +1247,30 @@ void qVectorMeshFaceFromScriptValue(const QScriptValue& array, QVector<MeshFace>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap parseTexturesToMap(QString textures, const QVariantMap& defaultTextures) {
|
QVariantMap parseTexturesToMap(QString newTextures, const QVariantMap& defaultTextures) {
|
||||||
// If textures are unset, revert to original textures
|
// If textures are unset, revert to original textures
|
||||||
if (textures.isEmpty()) {
|
if (newTextures.isEmpty()) {
|
||||||
return defaultTextures;
|
return defaultTextures;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Legacy: a ,\n-delimited list of filename:"texturepath"
|
// Legacy: a ,\n-delimited list of filename:"texturepath"
|
||||||
if (*textures.cbegin() != '{') {
|
if (*newTextures.cbegin() != '{') {
|
||||||
textures = "{\"" + textures.replace(":\"", "\":\"").replace(",\n", ",\"") + "}";
|
newTextures = "{\"" + newTextures.replace(":\"", "\":\"").replace(",\n", ",\"") + "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument texturesJson = QJsonDocument::fromJson(textures.toUtf8(), &error);
|
QJsonDocument newTexturesJson = QJsonDocument::fromJson(newTextures.toUtf8(), &error);
|
||||||
// If textures are invalid, revert to original textures
|
// If textures are invalid, revert to original textures
|
||||||
if (error.error != QJsonParseError::NoError) {
|
if (error.error != QJsonParseError::NoError) {
|
||||||
qWarning() << "Could not evaluate textures property value:" << textures;
|
qWarning() << "Could not evaluate textures property value:" << newTextures;
|
||||||
return defaultTextures;
|
return defaultTextures;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap texturesMap = texturesJson.toVariant().toMap();
|
QVariantMap newTexturesMap = newTexturesJson.toVariant().toMap();
|
||||||
// If textures are unset, revert to original textures
|
QVariantMap toReturn = defaultTextures;
|
||||||
if (texturesMap.isEmpty()) {
|
for (auto& texture : newTexturesMap.keys()) {
|
||||||
return defaultTextures;
|
toReturn[texture] = newTexturesMap[texture];
|
||||||
}
|
}
|
||||||
|
|
||||||
return texturesJson.toVariant().toMap();
|
return toReturn;
|
||||||
}
|
}
|
Loading…
Reference in a new issue