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