How can get xaxis of uv in world?

The direction obtained may be incorrect in some cases.
The texture directions of the two faces are consistent, but the calculated vectors differ by 90 degrees.
I got the same result using method one on the last two faces, and the same result using method two on the first two faces.

tets.skp (134.3 KB)

Method1

Sketchup.active_model.selection.each do |f|
  pts = f.uv_tile_at(f.vertices[0].position, true)
  uv_x_in_model = pts[2] - pts[0]
  puts uv_x_in_model.normalize
end

Method2

def get_texture_rotation(face)
  return nil unless face.material && face.get_UVHelper(true, true, Sketchup.create_texture_writer)

  uv_helper = face.get_UVHelper(true, true, Sketchup.create_texture_writer)
  points = face.outer_loop.vertices.map(&:position)

  uvq1 = uv_helper.get_front_UVQ(points[0])
  uvq2 = uv_helper.get_front_UVQ(points[1])
  vec = uvq2 - uvq1
  angle = vec.angle_between(X_AXIS)
  angle = -angle if (vec * X_AXIS).samedirection?(Z_AXIS)
  tr = Geom::Transformation.rotation(ORIGIN, face.normal, angle)
  vec = points[1] - points[0]
  vec.transform(tr).normalize
end

Sketchup.active_model.selection.each do |f|
  puts get_texture_rotation(f)
end

Please, do not call me out explicitly on topics. (I find it rude.)

If I have expertise and the time, I will answer. If not, I will not.
Basically, I do not profess to be an expert on texture mapping.

So, I’ll let someone else who knows give an answer.

sorry.

Unable to obtain the correct X-axis for UV coordinates. · Issue #979 · SketchUp/api-issue-tracker (github.com)

1 Like