From f349e48a2510fddea45cafb344a733d6a90bcf88 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Wed, 9 Jan 2019 13:30:49 -0800 Subject: [PATCH 1/7] Fix support for FBX texture scaling using ModelUVTranslation/ModelUVScaling --- libraries/fbx/src/FBXSerializer_Material.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libraries/fbx/src/FBXSerializer_Material.cpp b/libraries/fbx/src/FBXSerializer_Material.cpp index 7713b36e57..530f39b736 100644 --- a/libraries/fbx/src/FBXSerializer_Material.cpp +++ b/libraries/fbx/src/FBXSerializer_Material.cpp @@ -45,10 +45,11 @@ HFMTexture FBXSerializer::getTexture(const QString& textureID) { if (_textureParams.contains(textureID)) { auto p = _textureParams.value(textureID); - texture.transform.setTranslation(p.translation); + texture.transform.setTranslation(p.translation + glm::vec3(p.UVTranslation.x, p.UVTranslation.y, 0.0f)); texture.transform.setRotation(glm::quat(glm::radians(p.rotation))); auto scaling = p.scaling; + auto uvScaling = glm::vec3(p.UVScaling.x, p.UVScaling.y, 1.0f); // Protect from bad scaling which should never happen if (scaling.x == 0.0f) { scaling.x = 1.0f; @@ -59,7 +60,13 @@ HFMTexture FBXSerializer::getTexture(const QString& textureID) { if (scaling.z == 0.0f) { scaling.z = 1.0f; } - texture.transform.setScale(scaling); + if (uvScaling.x == 0.0f) { + uvScaling.x = 1.0f; + } + if (uvScaling.y == 0.0f) { + uvScaling.y = 1.0f; + } + texture.transform.setScale(scaling * uvScaling); if ((p.UVSet != "map1") && (p.UVSet != "UVSet0")) { texture.texcoordSet = 1; From 5b207775e7df426d1d55986c5855928a44b3bb66 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Fri, 11 Jan 2019 17:12:09 -0800 Subject: [PATCH 2/7] Remove redundant TextureParam transform variables --- libraries/fbx/src/FBXSerializer.cpp | 33 ++++++++++---------- libraries/fbx/src/FBXSerializer.h | 6 ---- libraries/fbx/src/FBXSerializer_Material.cpp | 13 ++------ 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/libraries/fbx/src/FBXSerializer.cpp b/libraries/fbx/src/FBXSerializer.cpp index a9887cde15..e51e6a3615 100644 --- a/libraries/fbx/src/FBXSerializer.cpp +++ b/libraries/fbx/src/FBXSerializer.cpp @@ -833,17 +833,17 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr } else if (subobject.name == "Texture_Alpha_Source" && subobject.properties.length() >= TEXTURE_ALPHA_SOURCE_MIN_SIZE) { tex.assign(tex.alphaSource, subobject.properties.at(0).value()); } else if (subobject.name == "ModelUVTranslation" && subobject.properties.length() >= MODEL_UV_TRANSLATION_MIN_SIZE) { - tex.assign(tex.UVTranslation, glm::vec2(subobject.properties.at(0).value(), - subobject.properties.at(1).value())); + auto newTranslation = glm::vec3(subobject.properties.at(0).value(), subobject.properties.at(1).value(), 0.0); + tex.assign(tex.translation, tex.translation + newTranslation); } else if (subobject.name == "ModelUVScaling" && subobject.properties.length() >= MODEL_UV_SCALING_MIN_SIZE) { - tex.assign(tex.UVScaling, glm::vec2(subobject.properties.at(0).value(), - subobject.properties.at(1).value())); - if (tex.UVScaling.x == 0.0f) { - tex.UVScaling.x = 1.0f; + auto newScaling = glm::vec3(subobject.properties.at(0).value(), subobject.properties.at(1).value(), 1.0); + if (newScaling.x == 0.0f) { + newScaling.x = 0.0f; } - if (tex.UVScaling.y == 0.0f) { - tex.UVScaling.y = 1.0f; + if (newScaling.y == 0.0f) { + newScaling.y = 0.0f; } + tex.assign(tex.scaling, tex.scaling * newScaling); } else if (subobject.name == "Cropping" && subobject.properties.length() >= CROPPING_MIN_SIZE) { tex.assign(tex.cropping, glm::vec4(subobject.properties.at(0).value(), subobject.properties.at(1).value(), @@ -871,20 +871,21 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr } else if (property.properties.at(0) == USE_MATERIAL) { tex.assign(tex.useMaterial, property.properties.at(index).value()); } else if (property.properties.at(0) == TRANSLATION) { - tex.assign(tex.translation, getVec3(property.properties, index)); + tex.assign(tex.translation, tex.translation + getVec3(property.properties, index)); } else if (property.properties.at(0) == ROTATION) { tex.assign(tex.rotation, getVec3(property.properties, index)); } else if (property.properties.at(0) == SCALING) { - tex.assign(tex.scaling, getVec3(property.properties, index)); - if (tex.scaling.x == 0.0f) { - tex.scaling.x = 1.0f; + auto newScaling = getVec3(property.properties, index); + if (newScaling.x == 0.0f) { + newScaling.x == 1.0f; } - if (tex.scaling.y == 0.0f) { - tex.scaling.y = 1.0f; + if (newScaling.y == 0.0f) { + newScaling.y == 1.0f; } - if (tex.scaling.z == 0.0f) { - tex.scaling.z = 1.0f; + if (newScaling.z == 0.0f) { + newScaling.z == 1.0f; } + tex.assign(tex.scaling, tex.scaling * newScaling); } #if defined(DEBUG_FBXSERIALIZER) else { diff --git a/libraries/fbx/src/FBXSerializer.h b/libraries/fbx/src/FBXSerializer.h index c69f75cc5c..0a07bacc54 100644 --- a/libraries/fbx/src/FBXSerializer.h +++ b/libraries/fbx/src/FBXSerializer.h @@ -37,8 +37,6 @@ class FBXNode; class TextureParam { public: - glm::vec2 UVTranslation; - glm::vec2 UVScaling; glm::vec4 cropping; QString UVSet; @@ -63,8 +61,6 @@ public: bool isDefault; TextureParam() : - UVTranslation(0.0f), - UVScaling(1.0f), cropping(0.0f), UVSet("map1"), translation(0.0f), @@ -77,8 +73,6 @@ public: {} TextureParam(const TextureParam& src) : - UVTranslation(src.UVTranslation), - UVScaling(src.UVScaling), cropping(src.cropping), UVSet(src.UVSet), translation(src.translation), diff --git a/libraries/fbx/src/FBXSerializer_Material.cpp b/libraries/fbx/src/FBXSerializer_Material.cpp index 530f39b736..0ba7972752 100644 --- a/libraries/fbx/src/FBXSerializer_Material.cpp +++ b/libraries/fbx/src/FBXSerializer_Material.cpp @@ -45,11 +45,10 @@ HFMTexture FBXSerializer::getTexture(const QString& textureID) { if (_textureParams.contains(textureID)) { auto p = _textureParams.value(textureID); - texture.transform.setTranslation(p.translation + glm::vec3(p.UVTranslation.x, p.UVTranslation.y, 0.0f)); - texture.transform.setRotation(glm::quat(glm::radians(p.rotation))); + texture.transform.postTranslate(p.translation); + texture.transform.postRotate(glm::quat(glm::radians(p.rotation))); auto scaling = p.scaling; - auto uvScaling = glm::vec3(p.UVScaling.x, p.UVScaling.y, 1.0f); // Protect from bad scaling which should never happen if (scaling.x == 0.0f) { scaling.x = 1.0f; @@ -60,13 +59,7 @@ HFMTexture FBXSerializer::getTexture(const QString& textureID) { if (scaling.z == 0.0f) { scaling.z = 1.0f; } - if (uvScaling.x == 0.0f) { - uvScaling.x = 1.0f; - } - if (uvScaling.y == 0.0f) { - uvScaling.y = 1.0f; - } - texture.transform.setScale(scaling * uvScaling); + texture.transform.postScale(scaling); if ((p.UVSet != "map1") && (p.UVSet != "UVSet0")) { texture.texcoordSet = 1; From 00a9e9e92f768828ebdbafe3f23fa266c3d0334f Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Fri, 11 Jan 2019 17:14:10 -0800 Subject: [PATCH 3/7] Add support for Maya material uv scale/translation --- libraries/fbx/src/FBXSerializer.cpp | 37 +++++++++++++++++++- libraries/fbx/src/FBXSerializer.h | 19 +++++++++- libraries/fbx/src/FBXSerializer_Material.cpp | 31 +++++++++------- 3 files changed, 72 insertions(+), 15 deletions(-) diff --git a/libraries/fbx/src/FBXSerializer.cpp b/libraries/fbx/src/FBXSerializer.cpp index e51e6a3615..adf722bfb2 100644 --- a/libraries/fbx/src/FBXSerializer.cpp +++ b/libraries/fbx/src/FBXSerializer.cpp @@ -930,6 +930,7 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr } } else if (object.name == "Material") { HFMMaterial material; + MaterialParam materialParam; material.name = (object.properties.at(1).toString()); foreach (const FBXNode& subobject, object.children) { bool properties = false; @@ -974,6 +975,8 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr static const QVariant MAYA_EMISSIVE_INTENSITY = QByteArray("Maya|emissive_intensity"); static const QVariant MAYA_USE_EMISSIVE_MAP = QByteArray("Maya|use_emissive_map"); static const QVariant MAYA_USE_AO_MAP = QByteArray("Maya|use_ao_map"); + static const QVariant MAYA_UV_SCALE = QByteArray("Maya|uv_scale"); + static const QVariant MAYA_UV_OFFSET = QByteArray("Maya|uv_offset"); @@ -1062,6 +1065,35 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr material.isPBSMaterial = true; material.useOcclusionMap = (bool)property.properties.at(index).value(); + } else if (property.properties.at(0) == MAYA_UV_SCALE) { + if (property.properties.size() == 6) { + glm::vec3 scale; + if (property.properties.at(2).value() == "Vector2") { + scale = glm::vec3(property.properties.at(4).value(), property.properties.at(5).value(), 1.0); + } else { // Vector (3d) + scale = glm::vec3(property.properties.at(3).value(), property.properties.at(4).value(), property.properties.at(5).value()); + } + if (scale.x == 0.0) { + scale.x = 1.0; + } + if (scale.y == 0.0) { + scale.y = 1.0; + } + if (scale.z == 0.0) { + scale.z = 1.0; + } + materialParam.scaling *= scale; + } + } else if (property.properties.at(0) == MAYA_UV_OFFSET) { + if (property.properties.size() == 6) { + glm::vec3 translation; + if (property.properties.at(2).value() == "Vector2") { + translation = glm::vec3(property.properties.at(4).value(), property.properties.at(5).value(), 1.0); + } else { // Vector (3d) + translation = glm::vec3(property.properties.at(3).value(), property.properties.at(4).value(), property.properties.at(5).value()); + } + materialParam.translation += translation; + } } else { const QString propname = property.properties.at(0).toString(); unknowns.push_back(propname.toStdString()); @@ -1083,6 +1115,7 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr } material.materialID = getID(object.properties); _hfmMaterials.insert(material.materialID, material); + _materialParams.insert(material.materialID, materialParam); } else if (object.name == "NodeAttribute") { @@ -1540,7 +1573,9 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr materialIndex++; } else if (_textureFilenames.contains(childID)) { - HFMTexture texture = getTexture(childID); + // NOTE (Sabrina 2019/01/11): getTextures now takes in the materialID as a second parameter, because FBX material nodes can sometimes have uv transform information (ex: "Maya|uv_scale") + // I'm leaving the second parameter blank right now as this code may never be used. + HFMTexture texture = getTexture(childID, ""); for (int j = 0; j < extracted.partMaterialTextures.size(); j++) { int partTexture = extracted.partMaterialTextures.at(j).second; if (partTexture == textureIndex && !(partTexture == 0 && materialsHaveTextures)) { diff --git a/libraries/fbx/src/FBXSerializer.h b/libraries/fbx/src/FBXSerializer.h index 0a07bacc54..568793789a 100644 --- a/libraries/fbx/src/FBXSerializer.h +++ b/libraries/fbx/src/FBXSerializer.h @@ -86,6 +86,22 @@ public: }; +class MaterialParam { +public: + glm::vec3 translation; + glm::vec3 scaling; + + MaterialParam() : + translation(0.0), + scaling(1.0) + {} + + MaterialParam(const MaterialParam& src) : + translation(src.translation), + scaling(src.scaling) + {} +}; + class ExtractedMesh; class FBXSerializer : public HFMSerializer { @@ -106,7 +122,7 @@ public: static glm::vec3 normalizeDirForPacking(const glm::vec3& dir); - HFMTexture getTexture(const QString& textureID); + HFMTexture getTexture(const QString& textureID, const QString& materialID); QHash _textureNames; // Hashes the original RelativeFilename of textures @@ -133,6 +149,7 @@ public: QHash occlusionTextures; QHash _hfmMaterials; + QHash _materialParams; void consolidateHFMMaterials(const QVariantHash& mapping); diff --git a/libraries/fbx/src/FBXSerializer_Material.cpp b/libraries/fbx/src/FBXSerializer_Material.cpp index 0ba7972752..3db7861180 100644 --- a/libraries/fbx/src/FBXSerializer_Material.cpp +++ b/libraries/fbx/src/FBXSerializer_Material.cpp @@ -27,7 +27,7 @@ #include -HFMTexture FBXSerializer::getTexture(const QString& textureID) { +HFMTexture FBXSerializer::getTexture(const QString& textureID, const QString& materialID) { HFMTexture texture; const QByteArray& filepath = _textureFilepaths.value(textureID); texture.content = _textureContent.value(filepath); @@ -66,6 +66,11 @@ HFMTexture FBXSerializer::getTexture(const QString& textureID) { } texture.texcoordSetName = p.UVSet; } + if (_materialParams.contains(materialID)) { + auto materialParam = _materialParams[materialID]; + texture.transform.postTranslate(materialParam.translation); + texture.transform.postScale(materialParam.scaling); + } return texture; } @@ -102,12 +107,12 @@ void FBXSerializer::consolidateHFMMaterials(const QVariantHash& mapping) { material.diffuseFactor = 1.0; } - diffuseTexture = getTexture(diffuseTextureID); + diffuseTexture = getTexture(diffuseTextureID, material.materialID); // FBX files generated by 3DSMax have an intermediate texture parent, apparently foreach(const QString& childTextureID, _connectionChildMap.values(diffuseTextureID)) { if (_textureFilenames.contains(childTextureID)) { - diffuseTexture = getTexture(diffuseTextureID); + diffuseTexture = getTexture(diffuseTextureID, material.materialID); } } @@ -122,7 +127,7 @@ void FBXSerializer::consolidateHFMMaterials(const QVariantHash& mapping) { transparentTextureID = diffuseTextureID; } if (!transparentTextureID.isNull()) { - transparentTexture = getTexture(transparentTextureID); + transparentTexture = getTexture(transparentTextureID, material.materialID); material.opacityTexture = transparentTexture; detectDifferentUVs |= (transparentTexture.texcoordSet != 0) || (!transparentTexture.transform.isIdentity()); } @@ -131,13 +136,13 @@ void FBXSerializer::consolidateHFMMaterials(const QVariantHash& mapping) { QString bumpTextureID = bumpTextures.value(material.materialID); QString normalTextureID = normalTextures.value(material.materialID); if (!normalTextureID.isNull()) { - normalTexture = getTexture(normalTextureID); + normalTexture = getTexture(normalTextureID, material.materialID); normalTexture.isBumpmap = false; material.normalTexture = normalTexture; detectDifferentUVs |= (normalTexture.texcoordSet != 0) || (!normalTexture.transform.isIdentity()); } else if (!bumpTextureID.isNull()) { - normalTexture = getTexture(bumpTextureID); + normalTexture = getTexture(bumpTextureID, material.materialID); normalTexture.isBumpmap = true; material.normalTexture = normalTexture; @@ -147,7 +152,7 @@ void FBXSerializer::consolidateHFMMaterials(const QVariantHash& mapping) { HFMTexture specularTexture; QString specularTextureID = specularTextures.value(material.materialID); if (!specularTextureID.isNull()) { - specularTexture = getTexture(specularTextureID); + specularTexture = getTexture(specularTextureID, material.materialID); detectDifferentUVs |= (specularTexture.texcoordSet != 0) || (!specularTexture.transform.isIdentity()); material.specularTexture = specularTexture; } @@ -155,7 +160,7 @@ void FBXSerializer::consolidateHFMMaterials(const QVariantHash& mapping) { HFMTexture metallicTexture; QString metallicTextureID = metallicTextures.value(material.materialID); if (!metallicTextureID.isNull()) { - metallicTexture = getTexture(metallicTextureID); + metallicTexture = getTexture(metallicTextureID, material.materialID); detectDifferentUVs |= (metallicTexture.texcoordSet != 0) || (!metallicTexture.transform.isIdentity()); material.metallicTexture = metallicTexture; } @@ -163,7 +168,7 @@ void FBXSerializer::consolidateHFMMaterials(const QVariantHash& mapping) { HFMTexture roughnessTexture; QString roughnessTextureID = roughnessTextures.value(material.materialID); if (!roughnessTextureID.isNull()) { - roughnessTexture = getTexture(roughnessTextureID); + roughnessTexture = getTexture(roughnessTextureID, material.materialID); material.roughnessTexture = roughnessTexture; detectDifferentUVs |= (roughnessTexture.texcoordSet != 0) || (!roughnessTexture.transform.isIdentity()); } @@ -171,7 +176,7 @@ void FBXSerializer::consolidateHFMMaterials(const QVariantHash& mapping) { HFMTexture shininessTexture; QString shininessTextureID = shininessTextures.value(material.materialID); if (!shininessTextureID.isNull()) { - shininessTexture = getTexture(shininessTextureID); + shininessTexture = getTexture(shininessTextureID, material.materialID); material.glossTexture = shininessTexture; detectDifferentUVs |= (shininessTexture.texcoordSet != 0) || (!shininessTexture.transform.isIdentity()); } @@ -179,7 +184,7 @@ void FBXSerializer::consolidateHFMMaterials(const QVariantHash& mapping) { HFMTexture emissiveTexture; QString emissiveTextureID = emissiveTextures.value(material.materialID); if (!emissiveTextureID.isNull()) { - emissiveTexture = getTexture(emissiveTextureID); + emissiveTexture = getTexture(emissiveTextureID, material.materialID); detectDifferentUVs |= (emissiveTexture.texcoordSet != 0) || (!emissiveTexture.transform.isIdentity()); material.emissiveTexture = emissiveTexture; @@ -202,7 +207,7 @@ void FBXSerializer::consolidateHFMMaterials(const QVariantHash& mapping) { } if (!occlusionTextureID.isNull()) { - occlusionTexture = getTexture(occlusionTextureID); + occlusionTexture = getTexture(occlusionTextureID, material.materialID); detectDifferentUVs |= (occlusionTexture.texcoordSet != 0) || (!emissiveTexture.transform.isIdentity()); material.occlusionTexture = occlusionTexture; } @@ -222,7 +227,7 @@ void FBXSerializer::consolidateHFMMaterials(const QVariantHash& mapping) { } if (_loadLightmaps && !ambientTextureID.isNull()) { - ambientTexture = getTexture(ambientTextureID); + ambientTexture = getTexture(ambientTextureID, material.materialID); detectDifferentUVs |= (ambientTexture.texcoordSet != 0) || (!ambientTexture.transform.isIdentity()); material.lightmapTexture = ambientTexture; material.lightmapParams = lightmapParams; From 5173577a928ed8f36c4c14b74195c2f1cb7f9bbd Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Mon, 14 Jan 2019 10:11:21 -0800 Subject: [PATCH 4/7] Fix issues with uv scale checking --- libraries/fbx/src/FBXSerializer.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/libraries/fbx/src/FBXSerializer.cpp b/libraries/fbx/src/FBXSerializer.cpp index adf722bfb2..99528b544c 100644 --- a/libraries/fbx/src/FBXSerializer.cpp +++ b/libraries/fbx/src/FBXSerializer.cpp @@ -838,10 +838,10 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr } else if (subobject.name == "ModelUVScaling" && subobject.properties.length() >= MODEL_UV_SCALING_MIN_SIZE) { auto newScaling = glm::vec3(subobject.properties.at(0).value(), subobject.properties.at(1).value(), 1.0); if (newScaling.x == 0.0f) { - newScaling.x = 0.0f; + newScaling.x = 1.0f; } if (newScaling.y == 0.0f) { - newScaling.y = 0.0f; + newScaling.y = 1.0f; } tex.assign(tex.scaling, tex.scaling * newScaling); } else if (subobject.name == "Cropping" && subobject.properties.length() >= CROPPING_MIN_SIZE) { @@ -877,13 +877,13 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr } else if (property.properties.at(0) == SCALING) { auto newScaling = getVec3(property.properties, index); if (newScaling.x == 0.0f) { - newScaling.x == 1.0f; + newScaling.x = 1.0f; } if (newScaling.y == 0.0f) { - newScaling.y == 1.0f; + newScaling.y = 1.0f; } if (newScaling.z == 0.0f) { - newScaling.z == 1.0f; + newScaling.z = 1.0f; } tex.assign(tex.scaling, tex.scaling * newScaling); } @@ -1073,14 +1073,14 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr } else { // Vector (3d) scale = glm::vec3(property.properties.at(3).value(), property.properties.at(4).value(), property.properties.at(5).value()); } - if (scale.x == 0.0) { - scale.x = 1.0; + if (scale.x == 0.0f) { + scale.x = 1.0f; } - if (scale.y == 0.0) { - scale.y = 1.0; + if (scale.y == 0.0f) { + scale.y = 1.0f; } - if (scale.z == 0.0) { - scale.z = 1.0; + if (scale.z == 0.0f) { + scale.z = 1.0f; } materialParam.scaling *= scale; } From c875492d50957206b5031d92cec95a0549f00a29 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Tue, 15 Jan 2019 10:29:12 -0800 Subject: [PATCH 5/7] Be more efficient with MaterialParam in FBXSerializer::getTexture --- libraries/fbx/src/FBXSerializer_Material.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/fbx/src/FBXSerializer_Material.cpp b/libraries/fbx/src/FBXSerializer_Material.cpp index 3db7861180..0a1d15b72a 100644 --- a/libraries/fbx/src/FBXSerializer_Material.cpp +++ b/libraries/fbx/src/FBXSerializer_Material.cpp @@ -66,8 +66,9 @@ HFMTexture FBXSerializer::getTexture(const QString& textureID, const QString& ma } texture.texcoordSetName = p.UVSet; } - if (_materialParams.contains(materialID)) { - auto materialParam = _materialParams[materialID]; + auto materialParamItr = _materialParams.find(materialID); + if (materialParamItr != _materialParams.end()) { + auto& materialParam = materialParamItr.value(); texture.transform.postTranslate(materialParam.translation); texture.transform.postScale(materialParam.scaling); } From f02d6433e3709072d61cc0195483d57727977ddd Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Tue, 15 Jan 2019 11:09:16 -0800 Subject: [PATCH 6/7] Be more descriptive about Maya uv scale/translation property, and better guess for 3d vector case --- libraries/fbx/src/FBXSerializer.cpp | 58 ++++++++++++++++------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/libraries/fbx/src/FBXSerializer.cpp b/libraries/fbx/src/FBXSerializer.cpp index 99528b544c..cfa1420224 100644 --- a/libraries/fbx/src/FBXSerializer.cpp +++ b/libraries/fbx/src/FBXSerializer.cpp @@ -1066,34 +1066,42 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr material.useOcclusionMap = (bool)property.properties.at(index).value(); } else if (property.properties.at(0) == MAYA_UV_SCALE) { - if (property.properties.size() == 6) { - glm::vec3 scale; - if (property.properties.at(2).value() == "Vector2") { - scale = glm::vec3(property.properties.at(4).value(), property.properties.at(5).value(), 1.0); - } else { // Vector (3d) - scale = glm::vec3(property.properties.at(3).value(), property.properties.at(4).value(), property.properties.at(5).value()); - } - if (scale.x == 0.0f) { - scale.x = 1.0f; - } - if (scale.y == 0.0f) { - scale.y = 1.0f; - } - if (scale.z == 0.0f) { - scale.z = 1.0f; - } - materialParam.scaling *= scale; + static const int MAYA_UV_SCALE_PROPERTY_LENGTH_2D = 6; + static const int MAYA_UV_SCALE_PROPERTY_LENGTH_3D = 7; + glm::vec3 scale; + if (property.properties.size() == MAYA_UV_SCALE_PROPERTY_LENGTH_2D) { // Vector2D + // properties: { "Maya|uv_scale", "Vector2D", "Vector2", nothing, double, double } + scale = glm::vec3(property.properties.at(4).value(), property.properties.at(5).value(), 1.0); + } else if (property.properties.size() == MAYA_UV_SCALE_PROPERTY_LENGTH_3D) { // Vector (3d) + // properties: { "Maya|uv_scale", "Vector3D", "Vector", nothing, double, double, double } + // (in principle, given how Vector3D is used for other Maya properties in the same area) + scale = glm::vec3(property.properties.at(4).value(), property.properties.at(5).value(), property.properties.at(6).value()); + } else { + scale = glm::vec3(1.0, 1.0, 1.0); } + if (scale.x == 0.0f) { + scale.x = 1.0f; + } + if (scale.y == 0.0f) { + scale.y = 1.0f; + } + if (scale.z == 0.0f) { + scale.z = 1.0f; + } + materialParam.scaling *= scale; } else if (property.properties.at(0) == MAYA_UV_OFFSET) { - if (property.properties.size() == 6) { - glm::vec3 translation; - if (property.properties.at(2).value() == "Vector2") { - translation = glm::vec3(property.properties.at(4).value(), property.properties.at(5).value(), 1.0); - } else { // Vector (3d) - translation = glm::vec3(property.properties.at(3).value(), property.properties.at(4).value(), property.properties.at(5).value()); - } - materialParam.translation += translation; + static const int MAYA_UV_OFFSET_PROPERTY_LENGTH_2D = 6; + static const int MAYA_UV_OFFSET_PROPERTY_LENGTH_3D = 7; + glm::vec3 translation; + if (property.properties.size() == MAYA_UV_OFFSET_PROPERTY_LENGTH_2D) { // Vector2 + // properties: { "Maya|uv_offset", "Vector2D", "Vector2", nothing, double, double } + translation = glm::vec3(property.properties.at(4).value(), property.properties.at(5).value(), 1.0); + } else if (property.properties.size() == MAYA_UV_OFFSET_PROPERTY_LENGTH_3D) { // Vector (3d) + // properties: { "Maya|uv_offset", "Vector3D", "Vector", nothing, double, double, double } + // (in principle, given how Vector3D is used for other Maya properties in the same area) + translation = glm::vec3(property.properties.at(4).value(), property.properties.at(5).value(), property.properties.at(6).value()); } + materialParam.translation += translation; } else { const QString propname = property.properties.at(0).toString(); unknowns.push_back(propname.toStdString()); From df17614fc3f7ac48dece75fec85ad23c053e9c8a Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Tue, 15 Jan 2019 11:16:22 -0800 Subject: [PATCH 7/7] Actually, don't support 3d vectors for Maya uv scale/offset --- libraries/fbx/src/FBXSerializer.cpp | 48 ++++++++++------------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/libraries/fbx/src/FBXSerializer.cpp b/libraries/fbx/src/FBXSerializer.cpp index cfa1420224..a25ef2acf5 100644 --- a/libraries/fbx/src/FBXSerializer.cpp +++ b/libraries/fbx/src/FBXSerializer.cpp @@ -977,6 +977,8 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr static const QVariant MAYA_USE_AO_MAP = QByteArray("Maya|use_ao_map"); static const QVariant MAYA_UV_SCALE = QByteArray("Maya|uv_scale"); static const QVariant MAYA_UV_OFFSET = QByteArray("Maya|uv_offset"); + static const int MAYA_UV_OFFSET_PROPERTY_LENGTH = 6; + static const int MAYA_UV_SCALE_PROPERTY_LENGTH = 6; @@ -1066,42 +1068,26 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr material.useOcclusionMap = (bool)property.properties.at(index).value(); } else if (property.properties.at(0) == MAYA_UV_SCALE) { - static const int MAYA_UV_SCALE_PROPERTY_LENGTH_2D = 6; - static const int MAYA_UV_SCALE_PROPERTY_LENGTH_3D = 7; - glm::vec3 scale; - if (property.properties.size() == MAYA_UV_SCALE_PROPERTY_LENGTH_2D) { // Vector2D + if (property.properties.size() == MAYA_UV_SCALE_PROPERTY_LENGTH) { // properties: { "Maya|uv_scale", "Vector2D", "Vector2", nothing, double, double } - scale = glm::vec3(property.properties.at(4).value(), property.properties.at(5).value(), 1.0); - } else if (property.properties.size() == MAYA_UV_SCALE_PROPERTY_LENGTH_3D) { // Vector (3d) - // properties: { "Maya|uv_scale", "Vector3D", "Vector", nothing, double, double, double } - // (in principle, given how Vector3D is used for other Maya properties in the same area) - scale = glm::vec3(property.properties.at(4).value(), property.properties.at(5).value(), property.properties.at(6).value()); - } else { - scale = glm::vec3(1.0, 1.0, 1.0); + glm::vec3 scale = glm::vec3(property.properties.at(4).value(), property.properties.at(5).value(), 1.0); + if (scale.x == 0.0f) { + scale.x = 1.0f; + } + if (scale.y == 0.0f) { + scale.y = 1.0f; + } + if (scale.z == 0.0f) { + scale.z = 1.0f; + } + materialParam.scaling *= scale; } - if (scale.x == 0.0f) { - scale.x = 1.0f; - } - if (scale.y == 0.0f) { - scale.y = 1.0f; - } - if (scale.z == 0.0f) { - scale.z = 1.0f; - } - materialParam.scaling *= scale; } else if (property.properties.at(0) == MAYA_UV_OFFSET) { - static const int MAYA_UV_OFFSET_PROPERTY_LENGTH_2D = 6; - static const int MAYA_UV_OFFSET_PROPERTY_LENGTH_3D = 7; - glm::vec3 translation; - if (property.properties.size() == MAYA_UV_OFFSET_PROPERTY_LENGTH_2D) { // Vector2 + if (property.properties.size() == MAYA_UV_OFFSET_PROPERTY_LENGTH) { // properties: { "Maya|uv_offset", "Vector2D", "Vector2", nothing, double, double } - translation = glm::vec3(property.properties.at(4).value(), property.properties.at(5).value(), 1.0); - } else if (property.properties.size() == MAYA_UV_OFFSET_PROPERTY_LENGTH_3D) { // Vector (3d) - // properties: { "Maya|uv_offset", "Vector3D", "Vector", nothing, double, double, double } - // (in principle, given how Vector3D is used for other Maya properties in the same area) - translation = glm::vec3(property.properties.at(4).value(), property.properties.at(5).value(), property.properties.at(6).value()); + glm::vec3 translation = glm::vec3(property.properties.at(4).value(), property.properties.at(5).value(), 1.0); + materialParam.translation += translation; } - materialParam.translation += translation; } else { const QString propname = property.properties.at(0).toString(); unknowns.push_back(propname.toStdString());