diff --git a/libs/yocto/yocto_diagram.cpp b/libs/yocto/yocto_diagram.cpp index 6127d8738..4d4c9b084 100644 --- a/libs/yocto/yocto_diagram.cpp +++ b/libs/yocto/yocto_diagram.cpp @@ -93,7 +93,7 @@ static shape_data make_dquads(vec2i steps, vec2f scale, vec2f uvscale) { shape.positions[j * (steps.x + 1) + i] = { (2 * uv.x - 1) * scale.x, (2 * uv.y - 1) * scale.y, 0}; shape.normals[j * (steps.x + 1) + i] = {0, 0, 1}; - shape.texcoords[j * (steps.x + 1) + i] = vec2f{uv.x, uv.y} * uvscale; + shape.texcoords[j * (steps.x + 1) + i] = vec2f{uv.x, 1 - uv.y} * uvscale; } } @@ -180,7 +180,7 @@ static shape_data make_duvsphere( auto shape = make_drect({steps.x, steps.y}, {1, 1}); for (auto i : range(shape.positions.size())) { auto uv = shape.texcoords[i]; - auto a = vec2f{2 * pif * uv.x, pif * (1 - uv.y)}; + auto a = vec2f{2 * pif * uv.x, pif * uv.y}; shape.positions[i] = vec3f{cos(a.x) * sin(a.y), sin(a.x) * sin(a.y), cos(a.y)} * scale; shape.normals[i] = normalize(shape.positions[i]); @@ -195,7 +195,7 @@ static shape_data make_duvhemisphere( auto shape = make_drect({steps.x, steps.y}, {1, 1}); for (auto i : range(shape.positions.size())) { auto uv = shape.texcoords[i]; - auto a = vec2f{pif * uv.x, pif * (1 - uv.y)}; + auto a = vec2f{pif * uv.x, pif * uv.y}; shape.positions[i] = vec3f{cos(a.x) * sin(a.y), sin(a.x) * sin(a.y), cos(a.y)} * scale; shape.normals[i] = normalize(shape.positions[i]); @@ -1762,7 +1762,7 @@ static shape_data make_text_shape(const string& text, vec3f offset, if (offset.y < 0) p.y += -height + offset_.y * offset.y; if (offset.z > 0) p.z += offset.z; } - shape.texcoords = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; + shape.texcoords = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; return shape; } diff --git a/libs/yocto/yocto_diagram.h b/libs/yocto/yocto_diagram.h index 42c2e7665..08fffaa1b 100644 --- a/libs/yocto/yocto_diagram.h +++ b/libs/yocto/yocto_diagram.h @@ -219,11 +219,11 @@ inline const auto quad_quads = vector{{0, 1, 2, 3}}; inline const auto quad_positions = vector{ {-1, -1, 0}, {+1, -1, 0}, {+1, +1, 0}, {-1, +1, 0}}; inline const auto quad_texcoords = vector{ - {0, 0}, {1, 0}, {1, 1}, {0, 1}}; + {0, 1}, {1, 1}, {1, 0}, {0, 0}}; inline const auto triangle_triangles = vector{{0, 1, 2}}; inline const auto triangle_positions = vector{ {-1, -1, 0}, {+1, -1, 0}, {0, +1, 0}}; -inline const auto triangle_texcoords = vector{{0, 0}, {1, 0}, {0.5, 1}}; +inline const auto triangle_texcoords = vector{{0, 1}, {1, 1}, {0.5, 0}}; inline const auto cube_quads = vector{{0, 3, 2, 1}, {4, 5, 6, 7}, {1, 2, 6, 5}, {0, 4, 7, 3}, {0, 1, 5, 4}, {2, 3, 7, 6}}; inline const auto cube_positions = vector{{-1, -1, +1}, {+1, -1, +1}, diff --git a/libs/yocto/yocto_shape.cpp b/libs/yocto/yocto_shape.cpp index 9cc93d0fc..6d4595e97 100644 --- a/libs/yocto/yocto_shape.cpp +++ b/libs/yocto/yocto_shape.cpp @@ -539,6 +539,22 @@ void split_facevarying(vector& split_quads, } else { split_texcoords.clear(); } + + // fill quad data + split_quads.resize(quadspos.size()); + for (auto fid : range(quadspos.size())) { + for (auto c : range(4)) { + auto vertex = vec3i{ + (&quadspos[fid].x)[c], + (!quadsnorm.empty()) ? (&quadsnorm[fid].x)[c] : -1, + (!quadstexcoord.empty()) ? (&quadstexcoord[fid].x)[c] : -1, + }; + split_quads[fid][c] = + (int)(std::lower_bound(vertices.begin(), vertices.end(), vertex, + compare_vertices) - + vertices.begin()); + } + } } // Conversions