# How do Textures work?

**URL:** <https://forums.sketchup.com/t/how-do-textures-work/47943>\
**Category:** Ruby API\
**Tags:** textures, ruby, face\
**Created:** [July 8, 2017, 9:52pm UTC](https://forums.sketchup.com/t/how-do-textures-work/47943 "2017-07-08T21:52:29Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![barracuda](https://avatars.discourse-cdn.com/v4/letter/b/e19b73/32.png) [@barracuda](https://forums.sketchup.com/u/barracuda)\
**Post date:** [July 8, 2017, 9:52pm UTC](https://forums.sketchup.com/t/how-do-textures-work/47943/1 "2017-07-08T21:52:29Z")

</div>

I would like to create simple script to work with texture which is used by face. So far I have found that

**Class: Sketchup::UVHelper** _contains methods allowing you to determine the location (UV coordinates) of a texture on a face._

**Class: Sketchup::Face**  
back\_material _is used to retrieve the material assigned to the back side of the face._  
back\_material _is used to set the material assigned to the back side of the face._  
position\_material(material, pt\_array, o\_front)  
_is used to position a material on a face._

and  
**Class: Sketchup::Texture** contains _methods for obtaining information about textures that are part of your materials in your model (within the In-Model section of the Materials Browser)._

But still I cannot find out where are methods to work with scale, dimensions, rotation etc. of the texture used by face. Can someone clarify how Sketchup Rubi API works when you use material and apply it to face and then when you modify these texture - properties? Where are they saved? Is there any hidden storage of properties used by faces? In the Class: Sketchup::Face class I did not find any information for this subject.

---

<div class="post-metadata">

**Author:** ![Centaur](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/centaur/32/30837_2.png) [@Centaur](https://forums.sketchup.com/u/Centaur)\
**Post date:** [July 9, 2017, 4:58am UTC](https://forums.sketchup.com/t/how-do-textures-work/47943/2 "2017-07-09T04:58:44Z")

</div>

UV coordinates are ‘saved’ with the face properties, and are accessible via the UVHelper methods.  
You will notice that your skp file will increase in size after applying UV coordinates to a face.

To set the UV coordinates, pass an array of coordinates (pt\_array) to face.position\_material, where the array contains alternating positions (typically the positions of the face vertices, but that is not mandatory), followed by the UV coordinate as a Geom::Point3d.new(u,v,0)

So, to rotate or scale, you could rotate or scale the UV coordinates before applying to a face, and for that, use the basic geometry transformation classes, since UVs are stored as a Point3d.  
.

---

<div class="post-metadata">

**Author:** ![barracuda](https://avatars.discourse-cdn.com/v4/letter/b/e19b73/32.png) [@barracuda](https://forums.sketchup.com/u/barracuda)\
**Post date:** [July 9, 2017, 8:04am UTC](https://forums.sketchup.com/t/how-do-textures-work/47943/3 "2017-07-09T08:04:30Z")

</div>

I start to understand it. So UV coordinates are coordinates of the “pins” or corners of the image. So they define the scale, size, dimensions, position…

Originally I did not understand this:

**Class: Sketchup::Face**  
`position_material`(material, **pt\_array** , o\_front) ⇒ Object

_The `position_material` method is used **to position** a material on a face._

I thought that this defines only the x,y,z position of the texture, but now I see it can define all pins of textures so now it makes sense.

---

<div class="post-metadata">

**Author:** ![barracuda](https://avatars.discourse-cdn.com/v4/letter/b/e19b73/32.png) [@barracuda](https://forums.sketchup.com/u/barracuda)\
**Post date:** [July 9, 2017, 1:56pm UTC](https://forums.sketchup.com/t/how-do-textures-work/47943/4 "2017-07-09T13:56:47Z")

</div>

Who is responsible for maintenance of [ruby.sketchup.com](http://ruby.sketchup.com) ? I found some [error in the code.](http://ruby.sketchup.com/Sketchup/UVHelper.html#get_back_UVQ-instance_method)

Request to correct this:

```auto
uv_helper = face.get_UVHelper true, true, my_texture_writer
face.outer_loop.vertices.each do |vert|
  uvq = uv_help.get_back_UVQ(vert.position)
  puts "u=" + uvq.x.to_s + " v=" + uvq.y.to_s
end
```

uv\_help was not defined.

Also could be useful to add page about **get\_UVHelper** method. As there is no writing about it.

---

<div class="post-metadata">

**Author:** ![thomthom](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/thomthom/32/12606_2.png) [@thomthom](https://forums.sketchup.com/u/thomthom)\
**Post date:** [July 9, 2017, 6:03pm UTC](https://forums.sketchup.com/t/how-do-textures-work/47943/5 "2017-07-09T18:03:37Z")

</div>

> [@barracuda](#):
>
> Who is responsible for maintenance of [ruby.sketchup.com](http://ruby.sketchup.com) ?

That’s the SketchUp team. You can log an issue here: [Issues · SketchUp/ruby-api-stubs · GitHub](https://github.com/SketchUp/ruby-api-stubs/issues)  
(Even better you can make a pull request.)

> [@barracuda](#):
>
> uv\_help was not defined.

A good number of the old examples doesn’t have complete code that can just run. When we add new examples we try to add complete standalone snippets.

> [@barracuda](#):
>
> Also could be useful to add page about get\_back\_UVQ method. As there is no writing about it.

What did you have in mind - as oppose to `get_front_UVQ`? It’s just fetching the UV data from the backside of the face.

---

<div class="post-metadata">

**Author:** ![barracuda](https://avatars.discourse-cdn.com/v4/letter/b/e19b73/32.png) [@barracuda](https://forums.sketchup.com/u/barracuda)\
**Post date:** [July 9, 2017, 6:12pm UTC](https://forums.sketchup.com/t/how-do-textures-work/47943/6 "2017-07-09T18:12:46Z")

</div>

You say what it means, but who can estimate this? It is unusual when it is not possible to find function used by API in reference.

---

<div class="post-metadata">

**Author:** ![thomthom](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/thomthom/32/12606_2.png) [@thomthom](https://forums.sketchup.com/u/thomthom)\
**Post date:** [July 9, 2017, 6:24pm UTC](https://forums.sketchup.com/t/how-do-textures-work/47943/7 "2017-07-09T18:24:41Z")

</div>

What would you like to see added to `get_back_UVQ`?

---

<div class="post-metadata">

**Author:** ![barracuda](https://avatars.discourse-cdn.com/v4/letter/b/e19b73/32.png) [@barracuda](https://forums.sketchup.com/u/barracuda)\
**Post date:** [July 9, 2017, 6:28pm UTC](https://forums.sketchup.com/t/how-do-textures-work/47943/8 "2017-07-09T18:28:08Z")

</div>

Sorry, I have wrong copy/pasted the name of the function/method. It is **get\_UVHelper**.

---

<div class="post-metadata">

**Author:** ![thomthom](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/thomthom/32/12606_2.png) [@thomthom](https://forums.sketchup.com/u/thomthom)\
**Post date:** [July 24, 2017, 2:54pm UTC](https://forums.sketchup.com/t/how-do-textures-work/47943/9 "2017-07-24T14:54:43Z")

</div>

Gotcha. Yea, that would be a good candidate for a small tutorial.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sketchup/original/3X/f/2/f2a121500b085ed60806607a82720b092d800bb3.png) [@system](https://forums.sketchup.com/u/system)\
**Post date:** [October 24, 2017, 6:54am UTC](https://forums.sketchup.com/t/how-do-textures-work/47943/10 "2017-10-24T06:54:49Z")

</div>

Closed on October 24, 2017, 6:54am UTC

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.
