Propertly transform UV coordinates.
We were mapping v to -v rather than 1-v, with fairly catastrophic results. While fixing, take the trouble to introduce a more general transformation mechanism than just an affine matrix.
This commit is contained in:
parent
c028d38f71
commit
8ade9b49b7
|
@ -336,14 +336,18 @@ void RawModel::Condense()
|
|||
}
|
||||
}
|
||||
|
||||
void RawModel::TransformTextures(const Mat2f &transform)
|
||||
void RawModel::TransformTextures(const std::vector<std::function<Vec2f(Vec2f)>> &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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<std::function<Vec2f(Vec2f)>> &transforms);
|
||||
|
||||
// Get the attributes stored per vertex.
|
||||
int GetVertexAttributes() const { return vertexAttributes; }
|
||||
|
|
19
src/main.cpp
19
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<std::function<Vec2f(Vec2f)>> 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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue