Well, I had got this to work in a previous version of the code.
But now I’ve had to re-sequence the code, and I’m stuck again, in just the same kind of way. I get an error when trying to add a polygon face to a Polygon mesh. It seems to be taking the x-value of a point as the index to the face in the mesh, and that clearly doesn’t work. But why is it doing that at all?
Here’s my first version code, which works:
RiverArch ellipses drawing.rb (7.2 KB)
This is line 178 that adds a polygon face to the mesh:
mesh.add_polygon points1[i], points2[i], points2[i+1], points1[i+1]
It draws parts of an arch (for Newthinking2’s River Arch) - one face at a time, depending on the input parameters.
Here’s my second version code, which successfully creates and displays in the model as a component the two series of points1 and points2 that define the edges. But I can’t seem to create the mesh from it, not even the first face at the base of the arch section.
Draw arch v2.rb (9.5 KB)
I’m now trying again to add the faces to the mesh, and failing.
The mesh is defined as before:
# Set up mesh for arch section
num_pts = 2 * (max_slices + 1)
num_poly = max_slices + 1
# Now we have the points, create a polygon mesh to add faces
mesh = Geom::PolygonMesh.new # num_pts, num_poly
i’ve tried with and without commenting out the parameters num_pts and num_poly.
Later when four points in the points1 and points2 series have been defined, I’m trying again to add points to the mesh, in line 247:
Here are the lines where it errors:
if i > 0 && z1 < a1
puts "Polygon points for slice i = #{i}: #{points1[i-1]}, #{points2[i-1]}, #{points2[i]}, #{points1[i]}"
index = mesh.add_polygon points1[i-1], points2[i-1], points2[i], points1[i]
end
Except for the shift in index from i to i-1 this appears to do the same as before, but doesn’t work.
And since I test for i > 0 it shouldn’t be ‘out of range’.
Before even getting to the third ‘slice’ (i = 2, n = 0) it dies with the following error:
`
:in `' SketchUp:1:in `eval' `draw_arch()
Polygon points for slice i = 1: [-12000.0, 0.0, 0.0], [-9150.0, 0.0, 0.0], [-9149.854789563884, 12.0, 60.0], [-11999.849999062488, 12.0, 60.0]
Error: #<ArgumentError: point index -11999 out of range>
/Users/JohnWMcC/Downloads/RiverArch/Draw arch v2.rb:247:inadd_polygon' /Users/JohnWMcC/Downloads/RiverArch/Draw arch v2.rb:247:indraw_arch’
The points look to be valid points (and where I expect them to be), and co-planar, but the mesh won’t add them.
I’m sure it’s something simple I’m overlooking, but for the moment at least, I just can’t see the difference between the code that works, and the code that doesn’t. And unfortunately, in my previous post, I didn’t detail what else (if anything) I did in changing from trying to add_faces_from_mesh to add_polygon that suddenly made it work.
Anyone able to help?