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)
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.
…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…