Merge pull request #6838 from ctrlaltdavid/20763

Fix reading model's "textures" property
This commit is contained in:
Brad Hefta-Gaub 2016-01-15 17:02:14 -08:00
commit 29b9592c8c
3 changed files with 23 additions and 12 deletions

View file

@ -100,6 +100,21 @@ int RenderableModelEntityItem::readEntitySubclassDataFromBuffer(const unsigned c
return bytesRead; 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() { void RenderableModelEntityItem::remapTextures() {
if (!_model) { if (!_model) {
return; // nothing to do if we don't have a 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 // 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 // and any textures in the recently mapped texture, that is not in our desired
// textures, we need to "unset" // textures, we need to "unset"
QJsonDocument currentTexturesAsJson = QJsonDocument::fromJson(_currentTextures.toUtf8()); QVariantMap currentTextureMap = parseTexturesToMap(_currentTextures);
QJsonObject currentTexturesAsJsonObject = currentTexturesAsJson.object(); QVariantMap textureMap = parseTexturesToMap(_textures);
QVariantMap currentTextureMap = currentTexturesAsJsonObject.toVariantMap();
QJsonDocument texturesAsJson = QJsonDocument::fromJson(_textures.toUtf8());
QJsonObject texturesAsJsonObject = texturesAsJson.object();
QVariantMap textureMap = texturesAsJsonObject.toVariantMap();
foreach(const QString& key, currentTextureMap.keys()) { foreach(const QString& key, currentTextureMap.keys()) {
// if the desired texture map (what we're setting the textures to) doesn't // if the desired texture map (what we're setting the textures to) doesn't

View file

@ -80,6 +80,7 @@ public:
virtual void resizeJointArrays(int newSize = -1) override; virtual void resizeJointArrays(int newSize = -1) override;
private: private:
QVariantMap parseTexturesToMap(QString textures);
void remapTextures(); void remapTextures();
Model* _model = nullptr; Model* _model = nullptr;

View file

@ -70,7 +70,7 @@ void GeometryReader::run() {
} else if (_url.path().toLower().endsWith(".obj")) { } else if (_url.path().toLower().endsWith(".obj")) {
fbxgeo = OBJReader().readOBJ(_data, _mapping, _url); fbxgeo = OBJReader().readOBJ(_data, _mapping, _url);
} else { } else {
QString errorStr("usupported format"); QString errorStr("unsupported format");
emit onError(NetworkGeometry::ModelParseError, errorStr); emit onError(NetworkGeometry::ModelParseError, errorStr);
} }
emit onSuccess(fbxgeo); emit onSuccess(fbxgeo);
@ -168,22 +168,22 @@ QStringList NetworkGeometry::getTextureNames() const {
for (auto&& material : _materials) { for (auto&& material : _materials) {
if (!material->diffuseTextureName.isEmpty() && material->diffuseTexture) { if (!material->diffuseTextureName.isEmpty() && material->diffuseTexture) {
QString textureURL = material->diffuseTexture->getURL().toString(); QString textureURL = material->diffuseTexture->getURL().toString();
result << material->diffuseTextureName + ":" + textureURL; result << material->diffuseTextureName + ":\"" + textureURL + "\"";
} }
if (!material->normalTextureName.isEmpty() && material->normalTexture) { if (!material->normalTextureName.isEmpty() && material->normalTexture) {
QString textureURL = material->normalTexture->getURL().toString(); QString textureURL = material->normalTexture->getURL().toString();
result << material->normalTextureName + ":" + textureURL; result << material->normalTextureName + ":\"" + textureURL + "\"";
} }
if (!material->specularTextureName.isEmpty() && material->specularTexture) { if (!material->specularTextureName.isEmpty() && material->specularTexture) {
QString textureURL = material->specularTexture->getURL().toString(); QString textureURL = material->specularTexture->getURL().toString();
result << material->specularTextureName + ":" + textureURL; result << material->specularTextureName + ":\"" + textureURL + "\"";
} }
if (!material->emissiveTextureName.isEmpty() && material->emissiveTexture) { if (!material->emissiveTextureName.isEmpty() && material->emissiveTexture) {
QString textureURL = material->emissiveTexture->getURL().toString(); QString textureURL = material->emissiveTexture->getURL().toString();
result << material->emissiveTextureName + ":" + textureURL; result << material->emissiveTextureName + ":\"" + textureURL + "\"";
} }
} }