How do Textures work?

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.

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.
.

3 Likes

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.

Who is responsible for maintenance of ruby.sketchup.com ? I found some error in the code.

Request to correct this:

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.

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

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.

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.

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.

What would you like to see added to get_back_UVQ?

Sorry, I have wrong copy/pasted the name of the function/method. It is get_UVHelper.

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

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