How does .uvs method work?


#1

Is was just wondering if someone could explain to me how the PolygonMesh.uvs method works. It says the uvs method is used to retrieve an array of uv coordinates in the mesh. Do you have to use set_uv. Or can you just create a PolygonMesh and then use the method to retrieve the array. If I create a new mesh can I just use mesh.uvs to get the array. I tried using it like this but nothing happened:

          pm = Geom::PolygonMesh.new
    
          pm.add_point([ 0, 0, 0]) # 1
          pm.add_point([10, 0, 0]) # 2
          pm.add_point([10,10, 0]) # 3
          pm.add_point([ 0,10, 0]) # 4
          pm.add_point([20, 0, 5]) # 5
          pm.add_point([20,10, 5]) # 6
    
          pm.add_polygon(1,-2,3,4)
          pm.add_polygon(2,5,6,-3)
    
          # Create a new group that we will populate with the mesh.
          group = Sketchup.active_model.entities.add_group
          material = Sketchup.active_model.materials.add('green')
          smooth_flags = Geom::PolygonMesh::NO_SMOOTH_OR_HIDE
          group.entities.add_faces_from_mesh(pm, smooth_flags, material)

          uvs = pm.uvs

#2

I believe that the UVs refer to textures that have been mapped to the polygons. If you’re setting the material color to ‘green’, there shouldn’t be any UVs associated with the mesh. I haven’t personally used this feature in SketchUp, but the docs provide this indication of texture mapping:

"UVs" is a way of referring to the u,v texture coordinates (as opposed to the X, Y, and Z axis that you construct your meshes on), which are points defining 1-by-1 positions within an image. These coordinates connect to points in your 3D model, to position an image texture onto it's surface (similar to virtual "thumb tacks") 

These coordinates pin an exact spot on an image that you wish to use to texture your model to a specific point on an object's surface. Between these points, your software will stretch the image smoothly. This is what is referred to as UV mapping.