Understanding texture coordinates


please have a look at the following files:

  • toto.skp contains just a textured rectangle in a XZ plane.

  • model.jpg shows what toto.skp looks like in SketchUp. I name the 4 extremity points of the rectangle “0”, “x”, “z” and “xz”.

  • texture.jpg is the image used to texture the front face of the rectangle. I reported the 4 extremity points of the rectangle in this image.

  • params.xlsx and params.jpg show the different coordinates of the 4 rectangle vertices and the parameters given by SUTextureGetDimensions.
    The x,z (and y) coordinates are given by SUVertexGetPosition.
    The u,v,q ones are given by SUUVHelperGetFrontUVQ.
    The s,t ones are the coordinates in the texture image I estimated by watching the rendering in SketchUp.

Please what is the relation between these coordinates and parameters ?

Thank you.

attachment.zip (400.5 KB)

For reference, the images in the ZIP files:

I’m not entirely sure what the question is. Can you elaborate a bit more on what you are looking for?

I want to import SketchUp models in a CAD software with the texture images rightly positioned on the faces. Given a geometric point on a textured face, which texture pixel is used to color this point ?

I suggest getting 2 of Thomas’ SketchUp extensions …

Since the user can reposition, rotate or stretch the texture as described in the User Guide …

… therefore the two APIs have UV (texture space) coordinate getter methods / functions that return the texel coordinates for the given geometric position (SUPoint3D in the case of the C API) on a face.

SketchUp uses OpenGL. So there are tutorials out there on texture mapping with OpenGL …

I am sorry, I do not own a SketchUp license. So I think I cannot use the extensions you suggested. But I had a look at their source code. They use an UVHelper like I did to get the (u,v,q) coordinates.

In my example, we see that the (u,v,q) coordinates do not vary much compared to the expected texel coordinates (s,t). So what do I miss ? Giving a SUTextureWriterRef or not to SUFaceGetUVHelper do not seem to change the (u,v,q).

You can run one of the Pro editions for a trial period, or you can use Make 2017 for testing.

Thomas explain in this topic …

I installed SketchUp Pro 2020, the two extensions Probes and UV Toolkit, and opened toto.skp. Here are 3 screenshots :

On the first one, I think we see the texture is applied on the front face.

On the second and the third one, we see the real UV coordinates from the font face, displayed by the extension Probes. These values are the ones in my xlsx.

So why do these (u,v) coordinates not vary much compared to the expected texel coordinates ?

What do you expect ?

Why do you think they should vary and how ?

On this face, the texture is mapped from the texel (80,77) to the texel (365,327) whereas the face (u,v) box is (119.203,7.116)-(119.789,7.48). Isn’t there a relation between the (u,v) coordinates and the texel coordinates ? How to get or compute the values (80,77) and (365,327) with the SketchUp C API ?

Go to SketchUcation and create a free account (so you can see the images in topic threads,) and then read and bookmark this tutorial …

You needing the ST ? In the C API, you go through a MeshHelper object.

Have you looked at the export examples included with the SDK ?

Did you read the linked topic (above) or the thread I linked from StackOverflow ?

With my example, SUMeshHelperGetFrontSTQCoords() returns the same values as SUUVHelperGetFrontUVQ.

I have read, registered, downloaded all what yout told me to. Yet I am still asking the same simple question since the beginning of this thread : on my simple example, how to get or compute the correct texel coordinates that should look like the rectangle [(80,77),(365,327)]. Please would you be so kind as to show us ?

I am sorry, no. I am not an expert at Texture application and I’m not a C programmer.
(I can read it, but try to avoid coding in it as it doesn’t “agree with me”.)

It seems to me a very general question how all “these” things are related. A famous person said:

I interprete the question as how the t, s coordinates of pixels in the image are related to u, v coordinates.

In SketchUp, texture images are tiled and repeated over the surface of a face. UV coordinates specify the “repetition step” at a given XYZ point, considering the image origin as 0 and the end as 1 (not the pixel dimensions). Since it is repeated, it does not matter whether the origin is shifted by a full step.

So let’s ignore the potential shift and say the UVs at the face corners are:

uvs = [
  [0.2026007, 0.11568341 ],
  [0.7890774, 0.11568341 ],
  [0.2026007, 0.479615441],
  [0.7890774, 0.479615441]

Then multiplied by the image dimensions in pixels [446, 672] you should get the pixel coordinates of the pixels in the face corners:

pxs = [
  [ 90.3599122,  77.73925152],
  [351.9285204,  77.73925152],
  [ 90.3599122, 322.30157635],
  [351.9285204, 322.30157635]

Is this what you estimated?


They look like the right values, thank you.

Should I sell my soul or anything more expensive to know whether u and v can be negative ? And if they can, what happens when the sign of u or v changes ? Is there a symmetry or does the periodicity just go on ?

The UVs can be negative, yes. The texture coordinates for each face has an origin. And when you query the UV for a point they will be relative to that origin.