Merge pull request #14835 from SamGondelman/textures

Case 20944: Fix Model textures property
This commit is contained in:
John Conklin II 2019-02-07 14:19:01 -08:00 committed by GitHub
commit dda310c0b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 25 deletions

View file

@ -1264,7 +1264,7 @@ bool ModelEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPoin
return false;
}
if (_lastTextures != entity->getTextures()) {
if (_textures != entity->getTextures()) {
return true;
}
@ -1418,15 +1418,14 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce
entity->_originalTexturesRead = true;
}
if (_lastTextures != entity->getTextures()) {
if (_textures != entity->getTextures()) {
QVariantMap newTextures;
withWriteLock([&] {
_texturesLoaded = false;
_lastTextures = entity->getTextures();
_textures = entity->getTextures();
newTextures = parseTexturesToMap(_textures, entity->_originalTextures);
});
auto newTextures = parseTexturesToMap(_lastTextures, entity->_originalTextures);
if (newTextures != model->getTextures()) {
model->setTextures(newTextures);
}
model->setTextures(newTextures);
}
if (entity->_needsJointSimulation) {
entity->copyAnimationJointDataToModel();

View file

@ -181,7 +181,7 @@ private:
bool _hasModel { false };
ModelPointer _model;
QString _lastTextures;
QString _textures;
bool _texturesLoaded { false };
int _lastKnownCurrentFrame { -1 };
#ifdef MODEL_ENTITY_USE_FADE_EFFECT

View file

@ -43,14 +43,15 @@ ModelEntityItem::ModelEntityItem(const EntityItemID& entityItemID) : EntityItem(
}
const QString ModelEntityItem::getTextures() const {
QReadLocker locker(&_texturesLock);
auto textures = _textures;
return textures;
return resultWithReadLock<QString>([&] {
return _textures;
});
}
void ModelEntityItem::setTextures(const QString& textures) {
QWriteLocker locker(&_texturesLock);
_textures = textures;
withWriteLock([&] {
_textures = textures;
});
}
EntityItemProperties ModelEntityItem::getProperties(const EntityPropertyFlags& desiredProperties, bool allowEmptyDesiredProperties) const {

View file

@ -163,7 +163,6 @@ protected:
AnimationPropertyGroup _animationProperties;
mutable QReadWriteLock _texturesLock;
QString _textures;
ShapeType _shapeType = SHAPE_TYPE_NONE;

View file

@ -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.isEmpty()) {
if (newTextures.isEmpty()) {
return defaultTextures;
}
// Legacy: a ,\n-delimited list of filename:"texturepath"
if (*textures.cbegin() != '{') {
textures = "{\"" + textures.replace(":\"", "\":\"").replace(",\n", ",\"") + "}";
if (*newTextures.cbegin() != '{') {
newTextures = "{\"" + newTextures.replace(":\"", "\":\"").replace(",\n", ",\"") + "}";
}
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 (error.error != QJsonParseError::NoError) {
qWarning() << "Could not evaluate textures property value:" << textures;
qWarning() << "Could not evaluate textures property value:" << newTextures;
return defaultTextures;
}
QVariantMap texturesMap = texturesJson.toVariant().toMap();
// If textures are unset, revert to original textures
if (texturesMap.isEmpty()) {
return defaultTextures;
QVariantMap newTexturesMap = newTexturesJson.toVariant().toMap();
QVariantMap toReturn = defaultTextures;
for (auto& texture : newTexturesMap.keys()) {
toReturn[texture] = newTexturesMap[texture];
}
return texturesJson.toVariant().toMap();
return toReturn;
}