# 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?

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â€¦

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.

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.