api-issue-tracker icon indicating copy to clipboard operation
api-issue-tracker copied to clipboard

Unable to obtain the correct X-axis for UV coordinates.

Open LItterBoy-GB opened this issue 1 year ago • 4 comments

Bug Reports

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

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

image

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

image

LItterBoy-GB avatar May 31 '24 08:05 LItterBoy-GB