SketchUp / api-issue-tracker

Public issue tracker for the SketchUp and LayOut's APIs
https://developer.sketchup.com/
39 stars 10 forks source link

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

Open LItterBoy-GB opened 4 months ago

LItterBoy-GB commented 4 months ago

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

thomthom commented 4 months ago

For the record, I'm attaching the test file packages in a zip file here.

tets.zip

thomthom commented 4 months ago

Hm.. I would need to dig into this to understand what is going on.

However, Method 2 is using texture writer. When using that to obtain UVs via UVHelper you might get different UVs if the texture is not affine (distorted). Though I don't think that's a factor here. Just something to beware of that many aren't.

LItterBoy-GB commented 4 months ago

When using that to obtain UVs via UVHelper you might get different UVs if the texture is not affine (distorted).

Is it possible to directly supplement the API and obtain the transformation from UV to World?

C api have same question.

sketchup[bot] commented 4 months ago

Logged as: SKEXT-4204