|
| 1 | +from compas_viewer.viewer import Viewer |
| 2 | +from OCC.Core import ShapeAnalysis |
| 3 | + |
| 4 | +from compas.colors import Color |
| 5 | +from compas.geometry import Box |
| 6 | +from compas.geometry import Plane |
| 7 | +from compas.geometry import Polygon |
| 8 | +from compas.geometry import Polyline |
| 9 | +from compas.geometry import Vector |
| 10 | +from compas.geometry import offset_polyline |
| 11 | +from compas_occ.brep import OCCBrep |
| 12 | + |
| 13 | +polyline = Polyline([[0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0], [0, 5, 0]]) |
| 14 | + |
| 15 | +inside = Polyline(offset_polyline(polyline, 0.05)) |
| 16 | +outside = Polyline(offset_polyline(polyline, -0.05)) |
| 17 | + |
| 18 | +polygon = Polygon(outside.points + inside.points[::-1]) |
| 19 | + |
| 20 | +brep = OCCBrep.from_polygons([polygon]) |
| 21 | +extrusion = OCCBrep.from_extrusion(brep.faces[0], Vector(0, 0, 5)) |
| 22 | +extrusion.heal() |
| 23 | +extrusion.make_solid() |
| 24 | + |
| 25 | +box = Box(10, 1, 3).to_brep() |
| 26 | +extrusion = OCCBrep.from_boolean_difference(extrusion, box) |
| 27 | + |
| 28 | +plane = Plane([3, 5, 7.5], [1, 0, 0]) |
| 29 | +cutter = OCCBrep.from_plane(plane, domain_u=(-10, 10), domain_v=(-10, 10)) |
| 30 | +extrusion = extrusion.split(cutter)[1] |
| 31 | + |
| 32 | +print(extrusion.is_closed) |
| 33 | +print(extrusion.is_orientable) |
| 34 | + |
| 35 | +print(extrusion.is_compound) |
| 36 | +print(extrusion.is_solid) |
| 37 | +print(extrusion.is_infinite) |
| 38 | + |
| 39 | +closedwires = ShapeAnalysis.ShapeAnalysis_FreeBounds(extrusion.occ_shape).GetClosedWires() |
| 40 | +openwires = ShapeAnalysis.ShapeAnalysis_FreeBounds(extrusion.occ_shape).GetOpenWires() |
| 41 | + |
| 42 | +print("Number of closed wires:", closedwires) |
| 43 | +print("Number of open wires:", openwires) |
| 44 | + |
| 45 | +viewer = Viewer() |
| 46 | +viewer.scene.add(polyline) |
| 47 | + |
| 48 | +viewer.scene.add(inside, color=Color.red()) |
| 49 | +viewer.scene.add(outside, color=Color.blue()) |
| 50 | +viewer.scene.add(polygon, color=Color.green()) |
| 51 | + |
| 52 | +viewer.scene.add(extrusion, facecolor=Color.cyan(), linecolor=Color.cyan().contrast) |
| 53 | + |
| 54 | +viewer.show() |
0 commit comments