How do i calculate the bottom / top of a surface by uvs

Hello everyone,

I have custom buffer geometries that always define an flat area in space. The surfaces can be inclined at any angle. I only know the vertex positions and uvs. Is it possible to use the uvs to determine a direction vector that points from the center of the geometry down along the surface to determine what is up / down? Has anyone got a good idea or ever done something like this?

thanks for your time :slight_smile:

a

1 Like

Uvs don’t have a fixed relationship to the vertex positions. They are only predictable within a given triangle. You can convert a point to uv space by first converting it to a barycentric coordinate within a triangle, then then convert that barycentric coordinate into a uv through the uvs of the original coordinate frame.

1 Like

hey manthrax, thanks for your answer. is it also not possible to find out a direction vector for the uv for a single face? it is always a normal “simple” image that is placed on the geometry… :face_with_spiral_eyes: :boom:

or is there perhaps another approach to understanding the orientation of the texture on the surface?

Hard to say. I don’t know what “orientation of the texture on the surface” means.
the texture can be oriented different for any set of 3 uvs.
What is the orientation if all 3 uvs are 0,0 ?
What if they are 0,0, 1,1, 1,0 ?
What’s the overall goal you’re trying to achieve?

i’m having a hard time putting this into words, but i’ll try as follows: at the top of the sketch i have the texture (black). the image is not distorted when it is placed on the geometry. the uvs for each vertex of the geometry could theoretically be read off at the top in the same way (linear). an example of how it works when a condition i can’t always rely on applies:


for (let i = 1; i < vertices.length; i++) {
      const v1 = vertices[0];
      const v2 = vertices[i];
      if (v1.uv.y !== v2.uv.y && v1.uv.x === v2.uv.x) {
        const vYMin = v1.uv.y < v2.uv.y ? v1 : v2;
        const vYMax = v1.uv.y > v2.uv.y ? v1 : v2;
        return new THREE.Vector3().subVectors(vYMin.position, vYMax.position).normalize();
      }
    }

V: 0 is the bottom
V: 1 is the top

Are you trying to solve the shirt + decal texture configurator problem?

unfortunately i can’t find anything about a shirt + decal texture configurator problem and i haven’t heard anything about it yet. But if I have understood you correctly, there is probably no possibility to derive a uv direction from the vertex points.

thank you for your time :slight_smile:

Your question seems semantically equivalent to:
“If I have an apple, can I tell what direction its facing based on its skin color?”

can you explain to me like I’m 5 what you’re trying to achieve on a higher level?

1 Like

I’m afraid the answer in the most general case is “NO” (actually, the answer is "I don’t know’). It could be “YES” only if all UVs in the custom geometries are defined in some predictable and convenient way, and the object is oriented in specific way. Otherwise, they could be anything, and unrelated to any specific direction.

Unfortunatelly, even if you can extract direction from UV, it will be wrong if you rotate the object’s mesh. The UVs will stay the same, but directions will change.

One possible way is to also check the highest and lowest positions of vertices. This may give some clue of up and down directions. And then, you could try to match them with the UVs.

But this will also fail in some cases. Consider this example of custom UVs on a circle – U runs along the perimeter, V runs radially from the outer boundary towards the center. Knowing specific values for (U,V) give no precise information about directions.

So, in the most general case, UV is not sufficient, but in some specific cases, it could be sufficient. My expectation is that your case is some specific case, so, please, examine all properties that affect directions, and all properties that are fixed (constrained), and craft your UVs in a way, that they also give information about directions.

Good luck with your project.

Sometimes, this is possible – the red side of the apple points to the midpoint of the visual ecliptic. The green part is the opposite direction.

2 Likes