mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 04:07:11 +02:00
Merge pull request #6838 from ctrlaltdavid/20763
Fix reading model's "textures" property
This commit is contained in:
commit
29b9592c8c
3 changed files with 23 additions and 12 deletions
|
@ -100,6 +100,21 @@ int RenderableModelEntityItem::readEntitySubclassDataFromBuffer(const unsigned c
|
|||
return bytesRead;
|
||||
}
|
||||
|
||||
QVariantMap RenderableModelEntityItem::parseTexturesToMap(QString textures) {
|
||||
if (textures == "") {
|
||||
return QVariantMap();
|
||||
}
|
||||
|
||||
QString jsonTextures = "{\"" + textures.replace(":\"", "\":\"").replace(",\n", ",\"") + "}";
|
||||
QJsonParseError error;
|
||||
QJsonDocument texturesAsJson = QJsonDocument::fromJson(jsonTextures.toUtf8(), &error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
qCWarning(entitiesrenderer) << "Could not evaluate textures property value:" << _textures;
|
||||
}
|
||||
QJsonObject texturesAsJsonObject = texturesAsJson.object();
|
||||
return texturesAsJsonObject.toVariantMap();
|
||||
}
|
||||
|
||||
void RenderableModelEntityItem::remapTextures() {
|
||||
if (!_model) {
|
||||
return; // nothing to do if we don't have a model
|
||||
|
@ -124,13 +139,8 @@ void RenderableModelEntityItem::remapTextures() {
|
|||
// since we're changing here, we need to run through our current texture map
|
||||
// and any textures in the recently mapped texture, that is not in our desired
|
||||
// textures, we need to "unset"
|
||||
QJsonDocument currentTexturesAsJson = QJsonDocument::fromJson(_currentTextures.toUtf8());
|
||||
QJsonObject currentTexturesAsJsonObject = currentTexturesAsJson.object();
|
||||
QVariantMap currentTextureMap = currentTexturesAsJsonObject.toVariantMap();
|
||||
|
||||
QJsonDocument texturesAsJson = QJsonDocument::fromJson(_textures.toUtf8());
|
||||
QJsonObject texturesAsJsonObject = texturesAsJson.object();
|
||||
QVariantMap textureMap = texturesAsJsonObject.toVariantMap();
|
||||
QVariantMap currentTextureMap = parseTexturesToMap(_currentTextures);
|
||||
QVariantMap textureMap = parseTexturesToMap(_textures);
|
||||
|
||||
foreach(const QString& key, currentTextureMap.keys()) {
|
||||
// if the desired texture map (what we're setting the textures to) doesn't
|
||||
|
|
|
@ -80,6 +80,7 @@ public:
|
|||
virtual void resizeJointArrays(int newSize = -1) override;
|
||||
|
||||
private:
|
||||
QVariantMap parseTexturesToMap(QString textures);
|
||||
void remapTextures();
|
||||
|
||||
Model* _model = nullptr;
|
||||
|
|
|
@ -70,7 +70,7 @@ void GeometryReader::run() {
|
|||
} else if (_url.path().toLower().endsWith(".obj")) {
|
||||
fbxgeo = OBJReader().readOBJ(_data, _mapping, _url);
|
||||
} else {
|
||||
QString errorStr("usupported format");
|
||||
QString errorStr("unsupported format");
|
||||
emit onError(NetworkGeometry::ModelParseError, errorStr);
|
||||
}
|
||||
emit onSuccess(fbxgeo);
|
||||
|
@ -168,22 +168,22 @@ QStringList NetworkGeometry::getTextureNames() const {
|
|||
for (auto&& material : _materials) {
|
||||
if (!material->diffuseTextureName.isEmpty() && material->diffuseTexture) {
|
||||
QString textureURL = material->diffuseTexture->getURL().toString();
|
||||
result << material->diffuseTextureName + ":" + textureURL;
|
||||
result << material->diffuseTextureName + ":\"" + textureURL + "\"";
|
||||
}
|
||||
|
||||
if (!material->normalTextureName.isEmpty() && material->normalTexture) {
|
||||
QString textureURL = material->normalTexture->getURL().toString();
|
||||
result << material->normalTextureName + ":" + textureURL;
|
||||
result << material->normalTextureName + ":\"" + textureURL + "\"";
|
||||
}
|
||||
|
||||
if (!material->specularTextureName.isEmpty() && material->specularTexture) {
|
||||
QString textureURL = material->specularTexture->getURL().toString();
|
||||
result << material->specularTextureName + ":" + textureURL;
|
||||
result << material->specularTextureName + ":\"" + textureURL + "\"";
|
||||
}
|
||||
|
||||
if (!material->emissiveTextureName.isEmpty() && material->emissiveTexture) {
|
||||
QString textureURL = material->emissiveTexture->getURL().toString();
|
||||
result << material->emissiveTextureName + ":" + textureURL;
|
||||
result << material->emissiveTextureName + ":\"" + textureURL + "\"";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue