Texture Transformation matrix

It is possible to get the [U, V] from a point [X, Y, Z] on the face (by the way, vertices or not). This is done via the UVHelper.

I did not find a way to do the reverse, that is, given an [U, V], retrieve the corresponding point [X, Y, Z] on the face plane.

There should be a texture transformation matrix between UV and model coordinates under the cover, but apparently, there is no method to get it.


PS: Actually, I can do it when the texture is not distorted (even if rotated or sheared), but not when it is distorted in perspective.

quantum physics meets extension?

Below details

Do not unhide the details below

Above details

Unhide the details above

Not currently exposed in the API but I’ve also been interested in this. There should be a perspective transformation matrix somewhere hiding under the hood.

If you can get the [U, V] from [X, Y, Z] you can query enough information to reconstruct the matrix and its inverse.

I have an old code sample for the full matrix (that includes perspectivic distortion), but it is very slow in Ruby. Maybe it is faster when reimplemented as C extension. SketchUp’s API should have something like UVHelper.get_XYZ(uvq)


I am not sure that a scaling transformation can match the actual distortion.

Here are two situations:

  • left: rotated, scaled, sheared --> NO problem
  • right: distorted (kind of perspective)

Distorted versus shared texture

I tried bilinear interpolation, but obviously, it does not work either.

This is why a perspective transformation is needed. SketchUp’s affine transformations won’t get there.

SketchUp actually has the transformations that we need.

SketchUp’s Geom::Transformation contains a rotation matrix (to be precise, an “augmented matrix” with translation vector appended). Such a 3×3 rotation matrix in 3-dimensional space can not represent more than rotation/scale/shear. It would require a larger matrix to allow SketchUp’s Scale Tool to skew a box component into something like an asymmetric pyramid frustum.

But textures are on a 2-dimensional plane where the rotation matrix is only 2Ă—2 for affine transformations. And one additional dimension would allow for perspectivic transformation. So we can abuse the affine 3D Geom::Transformation to do non-affine 2D transformations.

That’s very analogous, just like SketchUp projects the 3D model onto the view plane, we can project the texture image perspectivically onto the face’s plane.


Good explanation. I replied too early (without trying your code) and your mathematical justification is perfectly valid.

I took the time to make some test, and this works perfect

Here in the case where the texture transformation is affine:

TextureMatrix affine .

And here where the texture is distorted along a perspective projection.

TextureMatrix perspective

The construction lines are constructed at integer values of u and v. And they cross at the centers of the white crosses, which is what is expected.

Thank you very much. Very helpful.



Filed a feature request for native API for this.

(Including a setter as well)

Thanks a lot Christina…

…though I am not sure this will be high in the list…!

In the meantime, I have adapted Aerilius code and it works like a charm.

I was exploring the concept of contouring a texture image (i.e. transforming it into edges and faces), and applying it on the faces where the texture is applied, based on their UV maps. I got it to work even if the texture is distorted on the faces. Not sure this is terribly useful, but was worth the check…