While writing PC code to draw some “buckyballs”, I noticed some erratic behavior of faces that have specified duplicate points. Behavior seen on a PC under SU21(w/o Build) and SU22.
To test, open the Ruby console and run this self documenting example code, then wait while for SU to clean up - the red faces are deleted.
The methods .add_polygon and .add_faces_from_mesh seem to discard duplicate points, but the faces are treated differently. Some are erased by SU’s garbage collection and some are not.
Build .add_face seems to act the same as mesh faces do.
The entities method .add_face allows the face (p1, p2, p3, p1), I assume this is to support both open and closed polygon specification. I found no other combination of duplicate points that were allowed.
Why are some faces erased while others remain? And why no error message/return? Is there a defect in the way I code?
module BB_test
def BB_test.bbtest
p1 = Geom::Point3d.new( 0.0, 0.0, 2.0)
p2 = Geom::Point3d.new(-1.0, 0.0, 1.0)
p3 = Geom::Point3d.new( 0.0, 0.0, 0.0)
puts
puts "Red faces will be erased"
mesh1 = Geom::PolygonMesh.new
ret = mesh1.add_polygon(p1, p2, p3, p1)
puts
puts "PolygonMesh"
puts("add_polygon(p1,p2,p3,p1) returns: " + ret.inspect + " Face will be erased")
puts " mesh1.count_points= " + mesh1.count_points.to_s
(mG1 = Sketchup.active_model.entities.add_group).entities.add_faces_from_mesh(mesh1,0)
mG1.material = 'red'
mesh2 = Geom::PolygonMesh.new
ret = mesh2.add_polygon(p1, p2, p2, p3)
puts("add_polygon(p1,p2,p2,p3) returns: " + ret.inspect + " Face will be erased")
puts " mesh2.count_points= " + mesh2.count_points.to_s
(mG2 = Sketchup.active_model.entities.add_group).entities.add_faces_from_mesh(mesh2,0)
mG2.material = 'red'
mesh3 = Geom::PolygonMesh.new
ret = mesh3.add_polygon(p1, p1, p2, p3)
puts("add_polygon(p1,p1,p2,p3) returns: " + ret.inspect + " Face will remain")
puts " mesh3.count_points= " + mesh3.count_points.to_s
(mG3 = Sketchup.active_model.entities.add_group).entities.add_faces_from_mesh(mesh3,0)
mG3.material = 'magenta'
mesh4 = Geom::PolygonMesh.new
ret = mesh4.add_polygon(p1, p2, p3)
puts(" add_polygon(p1,p2,p3) returns: " + ret.inspect + " Face will remain")
puts " mesh4.count_points= " + mesh4.count_points.to_s
(mG4 = Sketchup.active_model.entities.add_group).entities.add_faces_from_mesh(mesh4,0)
mG4.material = 'magenta'
f = (fG1 = Sketchup.active_model.entities.add_group).entities.add_face(p1, p2, p3, p1)
fG1.material = 'blue'
puts
puts "Group"
puts(" add_face(p1,p2,p3,p1) returns: " + f.class.to_s + " Face will remain")
puts " f.outer_loop.vertices.count= " + f.outer_loop.vertices.count.to_s
puts(" add_face(p1,p1,p2,p3) returns- <ArgumentError: Duplicate points in array>")
puts(" add_face(p1,p2,p2,p3) returns- <ArgumentError: Duplicate points in array>")
puts(" add_face(p1,p2,p3,p3) returns- <ArgumentError: Duplicate points in array>")
f = (fG2 = Sketchup.active_model.entities.add_group).entities.add_face(p1, p2, p3)
fG2.material = 'blue'
puts(" add_face(p1,p2,p3) returns: " + f.class.to_s + " Face will remain")
puts " f.outer_loop.vertices.count= " + f.outer_loop.vertices.count.to_s
bf1 = (bG1 = Sketchup.active_model.entities.add_group).entities.build { |builder|
face1 = builder.add_face([p1, p2, p3, p1])
face1.material = 'red'
puts
puts"Build"
puts(" builer.add_face([p1,p2,p3,p1]) returns: " + face1.class.to_s + " Face will be erased" )
puts " face1.outer_loop.vertices.count= " + face1.outer_loop.vertices.count.to_s
}
bf2 = (bG2 = Sketchup.active_model.entities.add_group).entities.build { |builder|
face2 = builder.add_face([p1, p2, p2, p3])
face2.material = 'red'
puts(" builder.add_face([p1,p2,p2,p3]) returns: " + face2.class.to_s + " Face will be erased" )
puts " face2.outer_loop.vertices.count= " + face2.outer_loop.vertices.count.to_s
}
bf3 = (bG3 = Sketchup.active_model.entities.add_group).entities.build { |builder|
face3 = builder.add_face([p1, p1, p2, p3])
face3.material = 'magenta'
puts(" builder.add_face([p1,p1,p2,p3]) returns: " + face3.class.to_s + " Face will remain" )
puts " face3.outer_loop.vertices.count= " + face3.outer_loop.vertices.count.to_s
}
t = Geom::Transformation.new(Geom::Point3d.new(0, 0, 2.5))
mG1.transform!(t*t*t*t*t*t*t*t*t)
mG2.transform!(t*t*t*t*t*t*t*t)
mG3.transform!(t*t*t*t*t*t*t)
mG4.transform!(t*t*t*t*t*t)
fG1.transform!(t*t*t*t*t)
fG2.transform!(t*t*t*t)
bG1.transform!(t*t*t)
bG2.transform!(t*t)
bG3.transform!(t)
end
end