Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
xelatihy committed Jan 31, 2024
1 parent fb7a878 commit 809b78e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
8 changes: 4 additions & 4 deletions libs/yocto/yocto_diagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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]);
Expand All @@ -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]);
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions libs/yocto/yocto_diagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ inline const auto quad_quads = vector<vec4i>{{0, 1, 2, 3}};
inline const auto quad_positions = vector<vec3f>{
{-1, -1, 0}, {+1, -1, 0}, {+1, +1, 0}, {-1, +1, 0}};
inline const auto quad_texcoords = vector<vec2f>{
{0, 0}, {1, 0}, {1, 1}, {0, 1}};
{0, 1}, {1, 1}, {1, 0}, {0, 0}};
inline const auto triangle_triangles = vector<vec3i>{{0, 1, 2}};
inline const auto triangle_positions = vector<vec3f>{
{-1, -1, 0}, {+1, -1, 0}, {0, +1, 0}};
inline const auto triangle_texcoords = vector<vec2f>{{0, 0}, {1, 0}, {0.5, 1}};
inline const auto triangle_texcoords = vector<vec2f>{{0, 1}, {1, 1}, {0.5, 0}};
inline const auto cube_quads = vector<vec4i>{{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<vec3f>{{-1, -1, +1}, {+1, -1, +1},
Expand Down
16 changes: 16 additions & 0 deletions libs/yocto/yocto_shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,22 @@ void split_facevarying(vector<vec4i>& 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
Expand Down

0 comments on commit 809b78e

Please sign in to comment.