确定相交后要擦除的正确面可能非常棘手。
但由于您使用的是圆柱体形状(即实体),我建议您使用 SketchUp 8 Pro 中引入的实体布尔运算。例如,您可以使用Group.subtract
。http://www.sketchup.com/intl/en/developer/docs/ourdoc/group#subtract
但是,如果您没有使用 SketchUp 8 Pro 或更新版本,那么您将无法使用这些方法。
替代解决方案 - 避免 Pro 版本的 Solid Tools 方法:
entities = Sketchup.active_model.entities
# (!) You created a circle with so many edges that at the scale
# you drew it they where pushing the boundary of how small
# units SketchUp can handle. (1/1000th inch).
# If you has Edge Outline style enabled you could see that
# not all edges where fully merged.
# I reduced the curve segments from 360 to 180.
# (Do you really need such a high mesh density anyway?)
# make tube
tube = entities.add_group
tube_inner = tube.entities.add_circle Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1), 5, 180
tube_outer = tube.entities.add_circle Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1), 6, 180
cross_section_face = tube.entities.add_face tube_outer
inner_face = tube.entities.add_face tube_inner
tube.entities.erase_entities inner_face
cross_section_face.pushpull -10, false
# make a cylinder that punches through the wall
hole_punch = entities.add_group
hole_outer = hole_punch.entities.add_circle Geom::Point3d.new(0,0, 5), Geom::Vector3d.new(0,1,0), 3, 180
face = hole_punch.entities.add_face hole_outer
face.pushpull 10, false
# draw the intersection lines and erase the hole punch
entities.intersect_with true, hole_punch.transformation, tube, tube.transformation, true, hole_punch
hole_punch.erase!
# Find all the edges that belong to the Circle elements drawn
# earlier (including the ones push-pulled).
# (Could also collect these earlier before intersecting by
# collecting all non-smooth edges.)
circles = tube.entities.grep(Sketchup::Edge).select { |e| e.curve }.uniq
# Then we pick out all the faces that isn't connected to these edges and erase them.
new_faces = tube.entities.grep(Sketchup::Face).select { |f| (f.edges & circles).empty? }
entities.erase_entities( new_faces )
如果您真的想要 360 度圈,您可以放大组的内容 - 同时缩小组实例。这样,组定义的规模就更大了。(参见这篇关于 SketchUp 中的实例和定义的文章:http ://www.thomthom.net/thoughts/2012/02/definitions-and-instances-in-sketchup/ )
此外,如果您希望面填充内外蒙皮之间的孔,您还需要与该部分相交。
请注意Entities.intersect_with
描述 - 当前文档并不能很好地解释所有论点。有两种entities
说法。
第一个应该是Sketchup::Entities
相交对象应该出现的对象。(我有点惊讶它通过给它喂一个Sketchup::Group
物体来起作用。)
第二个不应该Sketchup::Entities
- 那将失败。它必须是对象Sketchup:Entity
或对象数组Sketchup:Entity
。