diff --git a/src/RawModel.cpp b/src/RawModel.cpp index d38cb47..71737fa 100644 --- a/src/RawModel.cpp +++ b/src/RawModel.cpp @@ -336,14 +336,18 @@ void RawModel::Condense() } } -void RawModel::TransformTextures(const Mat2f &transform) +void RawModel::TransformTextures(const std::vector> &transforms) { - for (size_t i = 0; i < vertices.size(); i++) { + for (auto &vertice : vertices) { if ((vertexAttributes & RAW_VERTEX_ATTRIBUTE_UV0) != 0) { - vertices[i].uv0 = transform * vertices[i].uv0; + for (const auto &fun : transforms) { + vertice.uv0 = fun(vertice.uv0); + } } if ((vertexAttributes & RAW_VERTEX_ATTRIBUTE_UV1) != 0) { - vertices[i].uv1 = transform * vertices[i].uv1; + for (const auto &fun : transforms) { + vertice.uv1 = fun(vertice.uv1); + } } } } diff --git a/src/RawModel.h b/src/RawModel.h index 83bf4fd..35f5a62 100644 --- a/src/RawModel.h +++ b/src/RawModel.h @@ -255,7 +255,7 @@ public: // Remove unused vertices, textures or materials after removing vertex attributes, textures, materials or surfaces. void Condense(); - void TransformTextures(const Mat2f &transform); + void TransformTextures(const std::vector> &transforms); // Get the attributes stored per vertex. int GetVertexAttributes() const { return vertexAttributes; } diff --git a/src/main.cpp b/src/main.cpp index ef1fb6e..79e41ac 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,8 +40,7 @@ int main(int argc, char *argv[]) std::string inputPath; std::string outputPath; - Mat2f texturesTransform(0.0f); - bool doTransformTextures = false; + std::vector> texturesTransforms; GltfOptions gltfOptions{ -1, // keepAttribs @@ -123,20 +122,16 @@ Copyright (c) 2016-2017 Oculus VR, LLC. if (!gltfOptions.useKHRMatCom && !gltfOptions.usePBRSpecGloss && !gltfOptions.usePBRMetRough) { if (verboseOutput) { - fmt::printf("Defaulting to KHR_materials_common material support.\n"); + fmt::printf("Defaulting to --pbr-metallic-roughness material support.\n"); } - gltfOptions.useKHRMatCom = true; + gltfOptions.usePBRMetRough = true; } if (options.count("flip-u") > 0) { - texturesTransform(0, 0) = -1.0f; - texturesTransform(1, 1) = 1.0f; - doTransformTextures = true; + texturesTransforms.emplace_back([](Vec2f uv) { return Vec2f(1.0f - uv[0], uv[1]); }); } if (options.count("flip-v") > 0) { - texturesTransform(0, 0) = 1.0f; - texturesTransform(1, 1) = -1.0f; - doTransformTextures = true; + texturesTransforms.emplace_back([](Vec2f uv) { return Vec2f(uv[0], 1.0f - uv[1]); }); } if (options.count("keepAttribute")) { @@ -192,8 +187,8 @@ Copyright (c) 2016-2017 Oculus VR, LLC. return 1; } - if (doTransformTextures) { - raw.TransformTextures(texturesTransform); + if (!texturesTransforms.empty()) { + raw.TransformTextures(texturesTransforms); } raw.Condense();