i did a lot of test about “position_material”, searched internet about UV mapping
The pt_array must contain 2, 4, 6 or 8 points. The points are used in pairs to tell where a point in the texture image is positioned on the Face. The first point in each pair is a 3D point in the model. It should be a point on the Face. The second point in each pair of points is a 2D point that gives the (u,v) coordinates of a point in the image to match up with the 3D point.
still uncertain and confused of this API , is there any other documents can tell me more?
i know vector as array works the same, but what does each number of array mean?
please help me
The array is
[model coordinates, texture coordinates]
or
[model coordinates, texture coordinates, model coordinates, texture coordinates]
or
[model coordinates, texture coordinates, model coordinates, texture coordinates, model coordinates, texture coordinates]
or
[model coordinates, texture coordinates, model coordinates, texture coordinates, model coordinates, texture coordinates, model coordinates, texture coordinates]
.
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 palcement.
1 Like
i want to reset the texture ratio inside a group when the scale of group changes
this is the code. i successfully reset the vertical height.but not the horizontal width.
i tried lots of combination of “pts”. no clue how and why it works
so how to position a material with a certain ratio?
def self.reset_texture(ets,tr) #entities & transformation
ets.each { |e|
case e
when Sketchup::Group
reset_texture(e.entities, e.transformation*tr)
when Sketchup::ComponentInstance
reset_texture(e.definition.entities, e.transformation*tr)
when Sketchup::Face
if e.material!=nil
t= [e.bounds.min,e.bounds.max]
h= t[1].transform(tr).z - t[0].transform(tr).z
n= h/ e.material.texture.height
n= n<0.5 ? 1:n
vts = e.vertices.map{|v|v.position}
pts=[vts[0],[n,0,0],vts[-1],[0,0,0]]
e.position_material(e.material,pts,true)
end
end
}
end
thanks for reply. learned a lot from your extension
1 Like
finally… 3 pairs is what i need
1 Like