sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ«› Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    Face.position_material and uvh.get_front_UVQ

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 4 Posters 484 Views 4 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.
    • fredo6F Offline
      fredo6
      last edited by fredo6

      While working on the ThruPaint plugin, I encountered two issues with the API related to face texturing with FOUR UV specifications

      1) face.position_material

      When you pass a point set of 4 UV points, it seems that SU distorts the texture to match a perspective view, and does not really do a tapering of the texture image.

      In the picture below, the UV specs for the 4 corners are (0, 0), (1, 0), (1, 1), (0, 1) for all three faces. This corresponds to a distorted texture which remains aligned with the 4 edges.
      Position_material.png

      It works fine with a rectangular face (left) and with a sheared face (right)

      When the face is tapered (middle case), it looks like SU is using a perspective distortion instead of tapering the texture along the edges. As a result, the texture patterns are not equally spread, here in the V axis. When you texture a full mesh, based on quads but with each face having its own shape, it results in non-alignment of pattens.

      I did not find a way to change this behaviour with the method position_material and did not see any other API doing that.

      2) uvh.get_front_UVQ

      When you specify 4 points to position_material (say at the corners of a quad) and then you get the UV of these corners by get_front_UVQ, you get different values. The values which are different are usually 'strange'. This seems to corresponds to the perspective distortion that SU has applied.

      I found out that you can retrieve the original UV, by dividing the U and V values by the 3rd coordinate (i.e. .z) of the UV point returned (so I guess the 'Q' value). This Q value is 1.0 when the texture is not distorted.

      
      uvh = face.get_UVHelper(true, true, tw)
      uv = uvh.get_front_UVQ(pt)
      uv.x /= uv.z
      uv.y /= uv.z
      uv.z = 1.0
      
      

      In conclusion, I am not sure there is any way to change the behavior of texture distortion of SU, but just in case someone has an idea, this would be really useful

      Fredo

      PS: I guess specialized UV mapping applications handle distortion properly.

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        Can't you add the final step uv.z=1.0 to normalize things again...

        TIG

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          This is two issues I encountered myself. In addition, There is not way to find out if a texture is projected or not. Nor set the Projected property. Nor is it possible to detect if a texture is Positioned or not.

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

          1 Reply Last reply Reply Quote 0
          • fredo6F Offline
            fredo6
            last edited by

            @tig said:

            Can't you add the final step uv.z=1.0 to normalize things again...

            You're perfectly right. Good remark.
            I updated the post.

            Stangely, Position.material ignores the Q value when applying the texture (you can set it to whatever value you wish with no effect).

            Fredo

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              Google claimed the Q value was not used - which in a way it isn't, when you apply a texture. But it sure is used when retrieving it. Really wish we could get some clarification to how the UV mapping system works.

              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

                I absolutely agree about the missing method to get/set the projected property.

                Fredo,
                as for the problem with tapered textures, I think this is a question of bilinear texture mapping versus projective (http://www.cs.cmu.edu/~ph/texfund/texfund.pdf p. 14 & p.17), but isn't projective mapping default in most other applications?
                I can't think of any better solution than splitting the face into smaller quads.

                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