@tig said:
Read up on this:
http://ruby.sketchup.com/Sketchup/UVHelper.html
and this:
http://ruby.sketchup.com/Sketchup/Face.html#position_material-instance_method
PS: Please format your code examples using
[code]...[/code]
rather that
[ruby]...[/ruby]
It's much easier to read...
Always wondered why my posts looked so strange right after being posted but then fixed themselves.
Thanks for the links.
So what I understand from this block:
samples = []
samples << face_two.vertices[0].position ### 0,0 | Origin
samples << samples[0].offset(face_two.normal.axes.x) ### 1,0 | Offset Origin in X
samples << samples[0].offset(face_two.normal.axes.y) ### 0,1 | Offset Origin in Y
samples << samples[1].offset(face_two.normal.axes.y) ### 1,1 | Offset X in Y
xyz = [];uv = []### Arrays containing 3D and UV points.
uvh = face_two.get_UVHelper(true, true, texture_writer)
samples.each { |position|
xyz << position ### XYZ 3D coordinates
# I switched this to front_UVQ
uvq = uvh.get_front_UVQ(position) ### UV 2D coordinates
uv << self.flattenUVQ(uvq)
}
pts = [] ### Position texture.
(0..3).each { |i|
pts << xyz[i]
pts << uv[i]
}
# set the position and material of face_one
mat = face_two.material
face_one.position_material(mat, pts, true)
From this function that I have adapted from your script, it seems like it should be correct.
- Gets the position of the four points from the face which we want to sample (0, 0), (1, 0), (0, 1), and (1, 1)
- Put the vertex position and UV coordinates (flattened - not sure why although not flattening had no effect) into two arrays (UVs returned in a point form, but only the x and y are used as u and v).
- Interlace these arrays as the position_material function calls for.
- Call position_material. Supply the correct material (which I do), the points (which I obviously don't) and true as it is a front face.
I understand what's going on here. I am a bit confused about why we are flattening the UVs but the math behind the function to do so makes sense.
Still stumped on what exactly I am getting wrong about the point array...
Edit: Interestingly, if I just leave the model flat and raycast down, it gets the texture and orientation correct. Now I am wondering if it's the raycast, but I really doubt it...
Also, it didn't seem to matter if I included just three points (0,0), (0,1) and (1,1) for both the points and uvs.
Edit: I have attached what I have so far (code wise)
The latest episode in my endless struggle for simplification