def identify_vertices_on_curve(diagram, guid): gkey_key = diagram.gkey_key() keys = [] curve = RhinoCurve.from_guid(guid) for key in diagram.vertices(): xyz = diagram.vertex_coordinates(key) closest = curve.closest_point(xyz) gkey = geometric_key(closest) if gkey in gkey_key: if key == gkey_key[gkey]: keys.append(key) return keys
from compas_rhino.geometry import RhinoCurve from compas_rhino.artists import MeshArtist # ============================================================================== # RPC # ============================================================================== igl = Proxy("compas_libigl") # ============================================================================== # Input # ============================================================================== # boundary guids = compas_rhino.select_curves() curve = RhinoCurve.from_guid(guids[0]) points = [list(point) for point in curve.points] boundary = points # segments guids = compas_rhino.select_curves() curve = RhinoCurve.from_guid(guids[0]) points = curve.divide(10, over_space=True) segments = points # hole guids = compas_rhino.select_curves() curve = RhinoCurve.from_guid(guids[0]) points = curve.divide(10, over_space=True) hole = points
def RunCommand(is_interactive): scene = get_scene() if not scene: return proxy = get_proxy() if not proxy: return conforming_delaunay_triangulation = proxy.function( 'compas.geometry.conforming_delaunay_triangulation') boundary_guids = compas_rhino.select_curves('Select outer boundary.') if not boundary_guids: return hole_guids = compas_rhino.select_curves('Select inner boundaries.') segments_guids = compas_rhino.select_curves('Select constraint curves.') target_length = rs.GetReal('Specifiy target edge length.', 1.0) if not target_length: return gkey_constraints = {} # outer boundary boundary = [] for guid in boundary_guids: compas_rhino.rs.EnableRedraw(False) segments = compas_rhino.rs.ExplodeCurves(guid) for segment in segments: curve = RhinoCurve.from_guid(segment) N = max(int(curve.length() / target_length), 1) points = map(list, curve.divide(N, over_space=True)) for point in points: gkey = geometric_key(point) if gkey not in gkey_constraints: gkey_constraints[gkey] = [] gkey_constraints[gkey].append(segment) boundary.extend(points) compas_rhino.delete_objects(segments, purge=True) compas_rhino.rs.EnableRedraw(True) # constraint polylines polylines = [] if segments_guids: for guid in segments_guids: curve = RhinoCurve.from_guid(guid) N = int(curve.length() / target_length) or 1 points = map(list, curve.divide(N, over_space=True)) for point in points: gkey = geometric_key(point) if gkey not in gkey_constraints: gkey_constraints[gkey] = [] gkey_constraints[gkey].append(guid) polylines.append(points) # hole polygons polygons = [] if hole_guids: for guid in hole_guids: curve = RhinoCurve.from_guid(guid) N = int(curve.length() / target_length) or 1 points = map(list, curve.divide(N, over_space=True)) for point in points[:-1]: gkey = geometric_key(point) if gkey not in gkey_constraints: gkey_constraints[gkey] = [] gkey_constraints[gkey].append(guid) polygons.append(points) area = target_length**2 * 0.5 * 0.5 * 1.732 vertices, faces = conforming_delaunay_triangulation(boundary, polylines=polylines, polygons=polygons, angle=30, area=area) # vertices, faces = constrained_delaunay_triangulation(boundary, polylines=polylines, polygons=polygons) vertices[:] = [[float(x), float(y), float(z)] for x, y, z in vertices] pattern = Pattern.from_vertices_and_faces(vertices, faces) gkey_key = { geometric_key(pattern.vertex_coordinates(key)): key for key in pattern.vertices() } for gkey in gkey_constraints: guids = gkey_constraints[gkey] if gkey in gkey_key: key = gkey_key[gkey] if len(guids) > 1: pattern.vertex_attribute(key, 'is_fixed', True) pattern.vertex_attribute(key, 'constraints', [str(guid) for guid in guids]) compas_rhino.rs.HideObject(boundary_guids + hole_guids + segments_guids) scene.clear() scene.add(pattern, name='pattern') scene.update() print( "Pattern object successfully created. Input geometry have been hidden." )