Cylindrical UV mapping
I'm trying to compute UV coordinates in cylindrical coordinates from a set of vertices from a mesh but it's not wrapping properly.
So here what I have so far. Assuming the variable height
and minY
are already computed outside the for loop.
for (int i = 0; i < mesh.numVertices; ++i)
{
float x = mesh.vertexBuffer[i].pos.x;
float y = mesh.vertexBuffer[i].pos.z;
float v = (mesh.vertexBuffer[i].pos.y - minY) / height; // get the ratio
Vec2 circle = glm::normalize(Vec2(x, y));
x = circle.x;
y = circle.y;
float theta = atan2(y, x); // its range is -pi < theta < pi
theta += PI; // make it such that its 0 < theta < 2pi
float u = theta / TWO_PI; // Get ratio;
mesh.vertexBuffer[i].uv = Vec2(u, v);
}
As you can see, the texture image is not wrapping properly as there's this weird strip on it.
Can anyone tell if my derivation for cylinder is correct?
opengl graphics mapping textures
add a comment |
I'm trying to compute UV coordinates in cylindrical coordinates from a set of vertices from a mesh but it's not wrapping properly.
So here what I have so far. Assuming the variable height
and minY
are already computed outside the for loop.
for (int i = 0; i < mesh.numVertices; ++i)
{
float x = mesh.vertexBuffer[i].pos.x;
float y = mesh.vertexBuffer[i].pos.z;
float v = (mesh.vertexBuffer[i].pos.y - minY) / height; // get the ratio
Vec2 circle = glm::normalize(Vec2(x, y));
x = circle.x;
y = circle.y;
float theta = atan2(y, x); // its range is -pi < theta < pi
theta += PI; // make it such that its 0 < theta < 2pi
float u = theta / TWO_PI; // Get ratio;
mesh.vertexBuffer[i].uv = Vec2(u, v);
}
As you can see, the texture image is not wrapping properly as there's this weird strip on it.
Can anyone tell if my derivation for cylinder is correct?
opengl graphics mapping textures
1
This is why you need multiple UVs per vertex. The line where the texture wraps around has U = 1 on one side and U = 0 on the other. Also a simple loop might not work because there is no way to differentiate between the above two cases. Consider processing each triangle instead – you can make use of a triangle's spacial continuity to ensure the same in UV space.
– meowgoesthedog
Nov 21 '18 at 9:25
add a comment |
I'm trying to compute UV coordinates in cylindrical coordinates from a set of vertices from a mesh but it's not wrapping properly.
So here what I have so far. Assuming the variable height
and minY
are already computed outside the for loop.
for (int i = 0; i < mesh.numVertices; ++i)
{
float x = mesh.vertexBuffer[i].pos.x;
float y = mesh.vertexBuffer[i].pos.z;
float v = (mesh.vertexBuffer[i].pos.y - minY) / height; // get the ratio
Vec2 circle = glm::normalize(Vec2(x, y));
x = circle.x;
y = circle.y;
float theta = atan2(y, x); // its range is -pi < theta < pi
theta += PI; // make it such that its 0 < theta < 2pi
float u = theta / TWO_PI; // Get ratio;
mesh.vertexBuffer[i].uv = Vec2(u, v);
}
As you can see, the texture image is not wrapping properly as there's this weird strip on it.
Can anyone tell if my derivation for cylinder is correct?
opengl graphics mapping textures
I'm trying to compute UV coordinates in cylindrical coordinates from a set of vertices from a mesh but it's not wrapping properly.
So here what I have so far. Assuming the variable height
and minY
are already computed outside the for loop.
for (int i = 0; i < mesh.numVertices; ++i)
{
float x = mesh.vertexBuffer[i].pos.x;
float y = mesh.vertexBuffer[i].pos.z;
float v = (mesh.vertexBuffer[i].pos.y - minY) / height; // get the ratio
Vec2 circle = glm::normalize(Vec2(x, y));
x = circle.x;
y = circle.y;
float theta = atan2(y, x); // its range is -pi < theta < pi
theta += PI; // make it such that its 0 < theta < 2pi
float u = theta / TWO_PI; // Get ratio;
mesh.vertexBuffer[i].uv = Vec2(u, v);
}
As you can see, the texture image is not wrapping properly as there's this weird strip on it.
Can anyone tell if my derivation for cylinder is correct?
opengl graphics mapping textures
opengl graphics mapping textures
edited Nov 21 '18 at 8:59
shinichi
asked Nov 21 '18 at 8:42
shinichishinichi
285
285
1
This is why you need multiple UVs per vertex. The line where the texture wraps around has U = 1 on one side and U = 0 on the other. Also a simple loop might not work because there is no way to differentiate between the above two cases. Consider processing each triangle instead – you can make use of a triangle's spacial continuity to ensure the same in UV space.
– meowgoesthedog
Nov 21 '18 at 9:25
add a comment |
1
This is why you need multiple UVs per vertex. The line where the texture wraps around has U = 1 on one side and U = 0 on the other. Also a simple loop might not work because there is no way to differentiate between the above two cases. Consider processing each triangle instead – you can make use of a triangle's spacial continuity to ensure the same in UV space.
– meowgoesthedog
Nov 21 '18 at 9:25
1
1
This is why you need multiple UVs per vertex. The line where the texture wraps around has U = 1 on one side and U = 0 on the other. Also a simple loop might not work because there is no way to differentiate between the above two cases. Consider processing each triangle instead – you can make use of a triangle's spacial continuity to ensure the same in UV space.
– meowgoesthedog
Nov 21 '18 at 9:25
This is why you need multiple UVs per vertex. The line where the texture wraps around has U = 1 on one side and U = 0 on the other. Also a simple loop might not work because there is no way to differentiate between the above two cases. Consider processing each triangle instead – you can make use of a triangle's spacial continuity to ensure the same in UV space.
– meowgoesthedog
Nov 21 '18 at 9:25
add a comment |
1 Answer
1
active
oldest
votes
The vertex coordinates at the seam of the texture, where the u component of the texture coordinate is 0, has to be duplicated, because it has to be associated to a texture coordinate where u==1, too.
At the seam of the texture which is wrapped around the circumference of the rotation body, the u coordinate starts with the value 0, but it ends on the same point with the value 1.
If you don`t do so, a transition from the last point on the circumference to the first point is generated. There is no clear seam where the texture ends and starts again, but there is linear transition from somewhere near the end of the texture to its begin. The entire texture is squeezed in this small transition area (flipped along the y axis). This is the "weird strip" you can see on your image.
Create one vertex at the end of the circumference which is equal the start - focus on <=
:
for (int i = 0; i <= mesh.numVertices; ++i)
{
....
}
I don't think it's quite as simple as that - there is no guarantee that the vertices will be in any cyclic order, and the above approach only works for a single line loop.
– meowgoesthedog
Nov 21 '18 at 10:06
@meowgoesthedog Of course I can't see the indices. The indices would have to be adapted. But the principle is as simple as that. This exactly points out the issue. I did this mistake myself, more than once.
– Rabbid76
Nov 21 '18 at 10:09
I meant that your suggestion of a loop likefor (int i = 0; i <= mesh.numVertices; ++i)
might be misleading for OP; although the intention of the example is clear, handling a real 3D mesh like the vase above is somewhat more complex, especially since OP did not specify that the mesh is divided into simple horizontal discs.
– meowgoesthedog
Nov 21 '18 at 10:14
@meowgoesthedog Yes, I agree. But I tried to point out the issue and to give a hint for a possible solution, based on the code I can see in the question.
– Rabbid76
Nov 21 '18 at 10:22
I found an alternative solution. Thx people.
– shinichi
Nov 22 '18 at 12:51
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408154%2fcylindrical-uv-mapping%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The vertex coordinates at the seam of the texture, where the u component of the texture coordinate is 0, has to be duplicated, because it has to be associated to a texture coordinate where u==1, too.
At the seam of the texture which is wrapped around the circumference of the rotation body, the u coordinate starts with the value 0, but it ends on the same point with the value 1.
If you don`t do so, a transition from the last point on the circumference to the first point is generated. There is no clear seam where the texture ends and starts again, but there is linear transition from somewhere near the end of the texture to its begin. The entire texture is squeezed in this small transition area (flipped along the y axis). This is the "weird strip" you can see on your image.
Create one vertex at the end of the circumference which is equal the start - focus on <=
:
for (int i = 0; i <= mesh.numVertices; ++i)
{
....
}
I don't think it's quite as simple as that - there is no guarantee that the vertices will be in any cyclic order, and the above approach only works for a single line loop.
– meowgoesthedog
Nov 21 '18 at 10:06
@meowgoesthedog Of course I can't see the indices. The indices would have to be adapted. But the principle is as simple as that. This exactly points out the issue. I did this mistake myself, more than once.
– Rabbid76
Nov 21 '18 at 10:09
I meant that your suggestion of a loop likefor (int i = 0; i <= mesh.numVertices; ++i)
might be misleading for OP; although the intention of the example is clear, handling a real 3D mesh like the vase above is somewhat more complex, especially since OP did not specify that the mesh is divided into simple horizontal discs.
– meowgoesthedog
Nov 21 '18 at 10:14
@meowgoesthedog Yes, I agree. But I tried to point out the issue and to give a hint for a possible solution, based on the code I can see in the question.
– Rabbid76
Nov 21 '18 at 10:22
I found an alternative solution. Thx people.
– shinichi
Nov 22 '18 at 12:51
add a comment |
The vertex coordinates at the seam of the texture, where the u component of the texture coordinate is 0, has to be duplicated, because it has to be associated to a texture coordinate where u==1, too.
At the seam of the texture which is wrapped around the circumference of the rotation body, the u coordinate starts with the value 0, but it ends on the same point with the value 1.
If you don`t do so, a transition from the last point on the circumference to the first point is generated. There is no clear seam where the texture ends and starts again, but there is linear transition from somewhere near the end of the texture to its begin. The entire texture is squeezed in this small transition area (flipped along the y axis). This is the "weird strip" you can see on your image.
Create one vertex at the end of the circumference which is equal the start - focus on <=
:
for (int i = 0; i <= mesh.numVertices; ++i)
{
....
}
I don't think it's quite as simple as that - there is no guarantee that the vertices will be in any cyclic order, and the above approach only works for a single line loop.
– meowgoesthedog
Nov 21 '18 at 10:06
@meowgoesthedog Of course I can't see the indices. The indices would have to be adapted. But the principle is as simple as that. This exactly points out the issue. I did this mistake myself, more than once.
– Rabbid76
Nov 21 '18 at 10:09
I meant that your suggestion of a loop likefor (int i = 0; i <= mesh.numVertices; ++i)
might be misleading for OP; although the intention of the example is clear, handling a real 3D mesh like the vase above is somewhat more complex, especially since OP did not specify that the mesh is divided into simple horizontal discs.
– meowgoesthedog
Nov 21 '18 at 10:14
@meowgoesthedog Yes, I agree. But I tried to point out the issue and to give a hint for a possible solution, based on the code I can see in the question.
– Rabbid76
Nov 21 '18 at 10:22
I found an alternative solution. Thx people.
– shinichi
Nov 22 '18 at 12:51
add a comment |
The vertex coordinates at the seam of the texture, where the u component of the texture coordinate is 0, has to be duplicated, because it has to be associated to a texture coordinate where u==1, too.
At the seam of the texture which is wrapped around the circumference of the rotation body, the u coordinate starts with the value 0, but it ends on the same point with the value 1.
If you don`t do so, a transition from the last point on the circumference to the first point is generated. There is no clear seam where the texture ends and starts again, but there is linear transition from somewhere near the end of the texture to its begin. The entire texture is squeezed in this small transition area (flipped along the y axis). This is the "weird strip" you can see on your image.
Create one vertex at the end of the circumference which is equal the start - focus on <=
:
for (int i = 0; i <= mesh.numVertices; ++i)
{
....
}
The vertex coordinates at the seam of the texture, where the u component of the texture coordinate is 0, has to be duplicated, because it has to be associated to a texture coordinate where u==1, too.
At the seam of the texture which is wrapped around the circumference of the rotation body, the u coordinate starts with the value 0, but it ends on the same point with the value 1.
If you don`t do so, a transition from the last point on the circumference to the first point is generated. There is no clear seam where the texture ends and starts again, but there is linear transition from somewhere near the end of the texture to its begin. The entire texture is squeezed in this small transition area (flipped along the y axis). This is the "weird strip" you can see on your image.
Create one vertex at the end of the circumference which is equal the start - focus on <=
:
for (int i = 0; i <= mesh.numVertices; ++i)
{
....
}
edited Jan 4 at 17:55
answered Nov 21 '18 at 9:46
Rabbid76Rabbid76
36.2k113247
36.2k113247
I don't think it's quite as simple as that - there is no guarantee that the vertices will be in any cyclic order, and the above approach only works for a single line loop.
– meowgoesthedog
Nov 21 '18 at 10:06
@meowgoesthedog Of course I can't see the indices. The indices would have to be adapted. But the principle is as simple as that. This exactly points out the issue. I did this mistake myself, more than once.
– Rabbid76
Nov 21 '18 at 10:09
I meant that your suggestion of a loop likefor (int i = 0; i <= mesh.numVertices; ++i)
might be misleading for OP; although the intention of the example is clear, handling a real 3D mesh like the vase above is somewhat more complex, especially since OP did not specify that the mesh is divided into simple horizontal discs.
– meowgoesthedog
Nov 21 '18 at 10:14
@meowgoesthedog Yes, I agree. But I tried to point out the issue and to give a hint for a possible solution, based on the code I can see in the question.
– Rabbid76
Nov 21 '18 at 10:22
I found an alternative solution. Thx people.
– shinichi
Nov 22 '18 at 12:51
add a comment |
I don't think it's quite as simple as that - there is no guarantee that the vertices will be in any cyclic order, and the above approach only works for a single line loop.
– meowgoesthedog
Nov 21 '18 at 10:06
@meowgoesthedog Of course I can't see the indices. The indices would have to be adapted. But the principle is as simple as that. This exactly points out the issue. I did this mistake myself, more than once.
– Rabbid76
Nov 21 '18 at 10:09
I meant that your suggestion of a loop likefor (int i = 0; i <= mesh.numVertices; ++i)
might be misleading for OP; although the intention of the example is clear, handling a real 3D mesh like the vase above is somewhat more complex, especially since OP did not specify that the mesh is divided into simple horizontal discs.
– meowgoesthedog
Nov 21 '18 at 10:14
@meowgoesthedog Yes, I agree. But I tried to point out the issue and to give a hint for a possible solution, based on the code I can see in the question.
– Rabbid76
Nov 21 '18 at 10:22
I found an alternative solution. Thx people.
– shinichi
Nov 22 '18 at 12:51
I don't think it's quite as simple as that - there is no guarantee that the vertices will be in any cyclic order, and the above approach only works for a single line loop.
– meowgoesthedog
Nov 21 '18 at 10:06
I don't think it's quite as simple as that - there is no guarantee that the vertices will be in any cyclic order, and the above approach only works for a single line loop.
– meowgoesthedog
Nov 21 '18 at 10:06
@meowgoesthedog Of course I can't see the indices. The indices would have to be adapted. But the principle is as simple as that. This exactly points out the issue. I did this mistake myself, more than once.
– Rabbid76
Nov 21 '18 at 10:09
@meowgoesthedog Of course I can't see the indices. The indices would have to be adapted. But the principle is as simple as that. This exactly points out the issue. I did this mistake myself, more than once.
– Rabbid76
Nov 21 '18 at 10:09
I meant that your suggestion of a loop like
for (int i = 0; i <= mesh.numVertices; ++i)
might be misleading for OP; although the intention of the example is clear, handling a real 3D mesh like the vase above is somewhat more complex, especially since OP did not specify that the mesh is divided into simple horizontal discs.– meowgoesthedog
Nov 21 '18 at 10:14
I meant that your suggestion of a loop like
for (int i = 0; i <= mesh.numVertices; ++i)
might be misleading for OP; although the intention of the example is clear, handling a real 3D mesh like the vase above is somewhat more complex, especially since OP did not specify that the mesh is divided into simple horizontal discs.– meowgoesthedog
Nov 21 '18 at 10:14
@meowgoesthedog Yes, I agree. But I tried to point out the issue and to give a hint for a possible solution, based on the code I can see in the question.
– Rabbid76
Nov 21 '18 at 10:22
@meowgoesthedog Yes, I agree. But I tried to point out the issue and to give a hint for a possible solution, based on the code I can see in the question.
– Rabbid76
Nov 21 '18 at 10:22
I found an alternative solution. Thx people.
– shinichi
Nov 22 '18 at 12:51
I found an alternative solution. Thx people.
– shinichi
Nov 22 '18 at 12:51
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408154%2fcylindrical-uv-mapping%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
This is why you need multiple UVs per vertex. The line where the texture wraps around has U = 1 on one side and U = 0 on the other. Also a simple loop might not work because there is no way to differentiate between the above two cases. Consider processing each triangle instead – you can make use of a triangle's spacial continuity to ensure the same in UV space.
– meowgoesthedog
Nov 21 '18 at 9:25