def identify_vertices_on_points(diagram, guids): gkey_key = diagram.gkey_key() keys = [] for guid in guids: point = RhinoPoint(guid) gkey = geometric_key(point.xyz) if gkey in gkey_key: key = gkey_key[gkey] keys.append(key) return keys
def customized_smoothing_constraints(mesh, constraints): """Add custom point, curve and surface constraints to the vertices of a mesh to smooth. Parameters ---------- mesh : Mesh The mesh to apply the constraints to for smoothing. constraints : dict A dictionary of mesh constraints for smoothing as vertex keys pointing to point, curve or surface objects. Returns ------- constraints : dict The updated dictionary of mesh constraints for smoothing as vertex keys pointing to point, curve or surface objects. """ while True: guids = display_smoothing_constraints(mesh, constraints) vkeys = mesh_select_vertices(mesh) if len(vkeys) == 2 and rs.GetString( 'get all polyedge?', strings=['True', 'False']) == 'True': u, v = vkeys vkeys = mesh.polyedge(u, v) if vkeys is None: break constraint = rs.GetString( 'edit smoothing constraints?', strings=['point', 'curve', 'surface', 'exit']) rs.DeleteObjects(guids) if constraint is None or constraint == 'exit': break elif constraint == 'point': point = RhinoPoint.from_selection() constraints.update({vkey: point.guid for vkey in vkeys}) elif constraint == 'curve': curve = RhinoCurve.from_selection() constraints.update({vkey: curve.guid for vkey in vkeys}) elif constraint == 'surface': surface = RhinoSurface.from_selection() constraints.update({vkey: surface.guid for vkey in vkeys}) return constraints
def from_guid(guid): """Create a ``RhinoGeometry`` instance of the correct type based on a given guid. Parameters ---------- guid : str or System.Guid The *guid* of the Rhino object. Returns ------- RhinoPoint If the type of the Rhino object is ``rs.filter.point``. RhinoCurve If the type of the Rhino object is ``rs.filter.curve``. RhinoMesh If the type of the Rhino object is ``rs.filter.mesh``. RhinoSurface If the type of the Rhino object is ``rs.filter.surface``. Examples -------- >>> """ from compas_rhino.geometry import RhinoPoint from compas_rhino.geometry import RhinoCurve from compas_rhino.geometry import RhinoMesh from compas_rhino.geometry import RhinoSurface otype = rs.ObjectType(guid) if otype == rs.filter.point: return RhinoPoint(guid) if otype == rs.filter.curve: return RhinoCurve(guid) if otype == rs.filter.mesh: return RhinoMesh(guid) if otype == rs.filter.surface: return RhinoSurface(guid)
def callback(k, args): mesh, constraints = args for vkey, constraint in constraints.items(): if rs.ObjectType(constraint) == 1: x, y, z = RhinoPoint.from_guid(constraint).xyz elif rs.ObjectType(constraint) == 4: x, y, z = RhinoCurve.from_guid(constraint).closest_point( mesh.vertex_coordinates(vkey)) elif rs.ObjectType(constraint) == 8: x, y, z = RhinoSurface.from_guid(constraint).closest_point( mesh.vertex_coordinates(vkey)) elif rs.ObjectType(constraint) == 32: x, y, z = RhinoMesh.from_guid(constraint).closest_point( mesh.vertex_coordinates(vkey)) else: continue mesh.vertex[vkey]['x'] = x mesh.vertex[vkey]['y'] = y mesh.vertex[vkey]['z'] = z
def RunCommand(is_interactive): scene = get_scene() if not scene: return proxy = get_proxy() if not proxy: return delaunay = proxy.function('compas.geometry.delaunay_from_points_numpy') # Get input data. surf_guid = compas_rhino.select_surface("Select a surface to decompose.") if not surf_guid: return point_guids = compas_rhino.select_points( "Select points to include in the decomposition.") curve_guids = [] compas_rhino.rs.HideObjects([surf_guid] + point_guids + curve_guids) surface = RhinoSurface.from_guid(surf_guid) curves = [RhinoCurve.from_guid(guid) for guid in curve_guids] points = [RhinoPoint.from_guid(guid) for guid in point_guids] # Compute the feature discretisation length. box = compas_rhino.rs.BoundingBox([surf_guid]) diagonal = compas_rhino.rs.Distance(box[0], box[6]) D = 0.05 * diagonal # Get the target length for the final quad mesh. L = compas_rhino.rs.GetReal( "Define the target edge length of the pattern.", 1.0) # Generate the pattern pattern = Pattern.from_surface_and_features(D, L, surf_guid, curve_guids, point_guids, delaunay=delaunay) scene.clear() scene.add(pattern, name='pattern') scene.update() kmax = 10 # Constrain mesh components to the feature geometry. constraints = automated_smoothing_surface_constraints(pattern, surface) constraints.update( automated_smoothing_constraints(pattern, rhinopoints=points, rhinocurves=curves)) while True: option = compas_rhino.rs.GetString("Smoothen the pattern?", "No", ["Yes", "No"]) if not option: break if option != "Yes": break constrained_smoothing(pattern, kmax=kmax, damping=0.5, constraints=constraints, algorithm="area") scene.update() print('Pattern object successfully created. Input object has been hidden.')