sketchucation logo sketchucation
    • Login
    ๐Ÿค‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    [Tutorial] uvq coordinates, or: The Magic Q

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 2.6k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A Offline
      Aerilius
      last edited by Aerilius

      I'm not sure if this is common knowledge (and only I missed it), but I'd like to share what enlightened me yesterday:

      Texture coordinates are not so obvious to understand, especially because SketchUp gives us a third " Q" coordinate but it doesn't allow us to set the third coordinate (correct me if I'm wrong). The U and V coordinates alone didn't match to the start/end of the image. We then used to divide U/Q and V/Q and Q/Q=1 and got values that made sense.
      However further calculations/transformations are difficult since a projected texture appears as a quadrilateral (which would need 4ร—4 matrix calculation) and it's hard to keep projectively distorted textures aligned if they where not projected from the same plane.
      Image showing the relation between 3d model space, 2d texture space and 3d texture space.
      While a projectively distorted texture appears as a quadrilateral (unregular quad) on a face in model space, when we change into texture space it's all the opposite and the texture image is a square (for texturing it doesn't matter how many pixels wide/high an image actually is). In fact, texture coordinates with Q=1 are the projection of 3 dimensional texture coordinates into the plane of the face. And Q relates to the distance how far a texture coordinate is "behind" the face, in texture space.
      Every quadrilateral can be seen as a projection of a perfect rectangle of some unknown rotation in 3d space. As long as we know the Q coordinate (= the distance how far a texture coordinate is in texture space), we do not necessarily need to calculate with quadrilaterals.

      That gives us three conclusions:

      1. We have access to the projective distortion of a texture and can even calculate the transformation matrix (by using SketchUp's own Geom::Transformation with a 3ร—3 matrix, see here). This allows us even to find where features/pixels of a texture are in model space!
      2. To quickly find out whether a texture is projectively distorted (not whether it has the "projected" property set for copy-painting), we can check whether the Q coordinate is different from %(#000000)[1]. SketchUp's TextureWriter then bakes the distortion into an image because other softwares would maybe only support UV without Q. All other sorts of skewing/scaling (=affine transformations) produce a Q=1 and export all fine as one image file.
      3. (As long as the Face.position_material method ignores the third value) Depending on the use case, we should only divide the U, V, Q values by Q at the very end before applying the texture to a face.
      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘

        Very interesting read!

        @aerilius said:

        And Q relates to the distance how far a texture coordinate is "behind" the face, in texture space.

        By what unit? For U and V 0.0 to 1.0 relates to the width and height of the texture, but what does Z represent?

        @aerilius said:

        (As long as the Face.position_material method ignores the third value)

        So you tried this?

        @aerilius said:

        We should only divide the U, V, Q values by Q at the very end before applying the texture to a face.

        So if you are going to rotate a texture, apply the rotation to the raw UVQ data, then divide by Q?

        Thomas Thomassen โ€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • A Offline
          Aerilius
          last edited by

          @thomthom said:

          @aerilius said:

          (As long as the Face.position_material method ignores the third value)

          So you tried this?

          I had tried it some time ago, but didn't observe an effect. I have to try it again with this new knowledge later this evening. It's possible that I just did it wrong (like giving for point/uvq pairs where the q value don't give a planar face in uvq space). So no offense to the Ruby API in the case it works indeed.

          @thomthom said:

          So if you are going to rotate a texture, apply the rotation to the raw UVQ data, then divide by Q??

          Probably depends on what you want to rotate, (more likely) the projection as it is, or the texture image "before" it is projectively distorted (I updated my description to be more relative).

          1 Reply Last reply Reply Quote 0
          • mitcorbM Offline
            mitcorb
            last edited by

            Hi. I have a question. Heretofore I have seen stuff on UV coordinates, and somewhere I thought I saw the term W used. Is this Q in Sketchup the equivalent of the W from wherever?

            I take the slow, deliberate approach in my aimless wandering.

            1 Reply Last reply Reply Quote 0
            • A Offline
              Aerilius
              last edited by

              I've read UVW somewhere as well. We have to find out more.

              For UVW mapping Wikipedia says no more than: "the third dimension allows texture maps to wrap in complex ways onto irregular surfaces"

              A Google search shows UVQ is mostly related with SketchUp, and that the names of these coordinates are not very standardized (just letters in the alphabet before x,y,z), for example there are also Q,R,S,T.

              There's an interesting explanation on gamedev.stackexchange, that the W allows to optionally apply a transformation matrix before rendering a texture to screen (for example for animating textures without expensive moving of the texture on every entity).

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement