Open Wisext opened 2 years ago
Logged as: SKEXT-3433
I find another situation. test.skp
face_g, model_g = nil, nil
Sketchup.active_model.entities.grep(Sketchup::Group).each do |g|
if g.entities.grep(Sketchup::Face).empty?
model_g = g
else
face_g = g
end
end
model_g.entities.intersect_with(true, model_g.transformation, Sketchup.active_model.entities, IDENTITY, false, face_g)
The reason for these bugs is that the faces are not planar enough. Something like the following snippet can be used to paint non-planar faces red - select a group and run the script:
module WonkyFacePaint
def self.paint_wonky_faces(g)
g.entities.grep(Sketchup::Face).each do |f|
pts = f.outer_loop.vertices.map(&:position)
scale = 100
tr = Geom::Transformation.scaling(pts.first, scale, scale, scale)
pts = pts.map { |pt| pt.transform(tr) }
plane = Geom::fit_plane_to_points(pts)
f.material = 'red' unless pts.all?{ |pt| pt.on_plane?(plane) }
end
g.entities.grep(Sketchup::Group).each { |g| paint_wonky_faces(g)}
end
Sketchup.active_model.start_operation("paint", true)
paint_wonky_faces(Sketchup.active_model.selection.first)
Sketchup.active_model.commit_operation
end
The faces have to be triangulated before intersect in order for intersect_with
to work. Sketchup does this if intersect is performed from the UI and the geometry to be intersected is in the outer context.
Bug Report
Here is a SketchUp file containing 2 faces in the model and one face in a group: https://forums.sketchup.com/uploads/short-url/waas7ch2iaN5MkdMUCyTrFMerMB.skp
If you use the intersect_with method (https://ruby.sketchup.com/Sketchup/Entities.html#intersect_with-instance_method) to get the intersection between the group and the model, there is no intersection for the face in blue. Here is a code to use the method on the provided file:
The snippet is equivalent to opening the group for edit and then invoking Intersect Faces With…Model via the GUI and you get the same issue.