How to get points for face.position_material?

I have been struggling with it for 2 days more. I have no idea how to calculate the points for face.position_material().

face.position_material(material, pt_array, on_front)

I suppose that I could get the points from face.get_UVHelper in an existing model, then restored the model with position_material method. But I could not figure out how to feed position_material with the uvs from get_UVHelper.

All coordinates are expressed as Geom::Point3d objects, although the Z coordinate isn’t used for the UV coordinates. Each pair links up a position on the texture with a position in 3d space. One pair just translates the texture into place. Two pairs can also rotate and scale it. 3 pairs allow for shearing and non-uniform scaling and 4 pairs allow for “perspective” or non-affine material placement.

I want to know how to calculate the pairs of points.

Well, given that you will …

… and that you get UV coordinates (not points) from a face’s UVHelper by passing in a vertex position (as a 3D point on that face,) … then your pt_array pairs will simply be matched as the face vertex (which you pass to UVHelper) and the resultant normalized UV.

The getter method docs show you how to normalize the UVQ.

So then, try the following …

  helper = face.get_UVHelper(true, true)
  pt = face.vertices[0].position
  uvq = helper.get_front_UVQ(pt)
  uv = Geom::Point3d.new( uvq.u / uvq.q, uvq.v / uvq.q, 0 )

  # Then in new model:
  new_face.material = copied_matl
  # Position the material using the same vertex that was used to get the UVs:
  new_face.position_material(
    copied_matl, [ new_face.vertices[0].position, uv ], true
  )

This attempt would “assume” that the face vertex arrays will return the vertices in the same order.

:crossed_fingers: