# Position\_material & UV mapping need help

**URL:** <https://forums.sketchup.com/t/position-material-uv-mapping-need-help/125670>\
**Category:** Ruby API\
**Created:** [May 17, 2020, 5:34am UTC](https://forums.sketchup.com/t/position-material-uv-mapping-need-help/125670 "2020-05-17T05:34:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhou\_si\_fu](https://avatars.discourse-cdn.com/v4/letter/z/f19dbf/32.png) [@Zhou\_si\_fu](https://forums.sketchup.com/u/Zhou_si_fu)\
**Post date:** [May 17, 2020, 5:34am UTC](https://forums.sketchup.com/t/position-material-uv-mapping-need-help/125670/1 "2020-05-17T05:34:04Z")

</div>

i did a lot of test about “position\_material”, searched internet about UV mapping

> The pt\_array must contain 2, 4, 6 or 8 points. The points are used in pairs to tell where a point in the texture image is positioned on the Face. The first point in each pair is a 3D point in the model. It should be a point on the Face. The second point in each pair of points is a 2D point that gives the (u,v) coordinates of a point in the image to match up with the 3D point.

still uncertain and confused of this API , is there any other documents can tell me more?  
i know vector as array works the same, but what does each number of array mean?  
please help me

---

<div class="post-metadata">

**Author:** ![eneroth3](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/eneroth3/32/1222_2.png) [@eneroth3](https://forums.sketchup.com/u/eneroth3)\
**Post date:** [May 17, 2020, 8:05am UTC](https://forums.sketchup.com/t/position-material-uv-mapping-need-help/125670/2 "2020-05-17T08:05:45Z")

</div>

The array is  
`[model coordinates, texture coordinates]`  
or  
`[model coordinates, texture coordinates, model coordinates, texture coordinates]`  
or  
`[model coordinates, texture coordinates, model coordinates, texture coordinates, model coordinates, texture coordinates]`  
or  
`[model coordinates, texture coordinates, model coordinates, texture coordinates, model coordinates, texture coordinates, model coordinates, texture coordinates]`.

All coordinates are expressed as Geom::Point3d objects, although the Z coordinate isn’t used for the UV coordinates. Each pair links up a position on the texture with a position in 3d space. One pair just translates the texture into place. Two pairs can also rotate and scale it. 3 pairs allow for shearing and non-uniform scaling and 4 pairs allow for “perspective” or non-affine material palcement.

---

<div class="post-metadata">

**Author:** ![Zhou\_si\_fu](https://avatars.discourse-cdn.com/v4/letter/z/f19dbf/32.png) [@Zhou\_si\_fu](https://forums.sketchup.com/u/Zhou_si_fu)\
**Post date:** [May 17, 2020, 9:37am UTC](https://forums.sketchup.com/t/position-material-uv-mapping-need-help/125670/3 "2020-05-17T09:37:51Z")

</div>

i want to reset the texture ratio inside a group when the scale of group changes  
this is the code. i successfully reset the vertical height.but not the horizontal width.  
i tried lots of combination of “pts”. no clue how and why it works  
so how to position a material with a certain ratio?

```auto
def self.reset_texture(ets,tr) #entities & transformation
    ets.each { |e|
        case e
        when Sketchup::Group
            reset_texture(e.entities, e.transformation*tr)
        when Sketchup::ComponentInstance
            reset_texture(e.definition.entities, e.transformation*tr)
        when Sketchup::Face
            if e.material!=nil
                t= [e.bounds.min,e.bounds.max]
                h= t[1].transform(tr).z - t[0].transform(tr).z
                n= h/ e.material.texture.height
                n= n<0.5 ? 1:n
                vts = e.vertices.map{|v|v.position}
                pts=[vts[0],[n,0,0],vts[-1],[0,0,0]]
                e.position_material(e.material,pts,true)
            end
        end
    }
end

```

thanks for reply. learned a lot from your extension 🙂

---

<div class="post-metadata">

**Author:** ![Zhou\_si\_fu](https://avatars.discourse-cdn.com/v4/letter/z/f19dbf/32.png) [@Zhou\_si\_fu](https://forums.sketchup.com/u/Zhou_si_fu)\
**Post date:** [May 18, 2020, 2:59pm UTC](https://forums.sketchup.com/t/position-material-uv-mapping-need-help/125670/4 "2020-05-18T14:59:16Z")

</div>

finally… 3 pairs is what i need
