def _get_building_member_info(self, gripping_config): start = timer() if self.debug else None self.simulator.set_robot_config(self.robot, gripping_config) mesh = mesh_from_guid(Mesh, self.building_member) handle = self.simulator.add_building_member(self.robot, mesh) matrix = self.simulator.get_object_matrices([handle])[handle] parent_handle = self.simulator.get_object_handle('customGripper' + self.robot.name) _, _, mesh_matrix, _, _ = self.simulator.run_child_script( 'getShapeMatrixRelative', [handle, parent_handle], [], []) relative_transform = _to_xform(mesh_matrix) transform = _to_xform(matrix) mesh_at_origin = _transform_to_origin( rs.coercemesh(self.building_member), transform) if self.debug: LOG.debug('Execution time: building member=%.2f', timer() - start) return { 'mesh': mesh_at_origin, 'parent_handle': parent_handle, 'relative_transform': relative_transform }
def from_rhinomesh(cls, guid, **kwargs): """Construct a FormDiagram from a Rhino mesh represented by a guid. Parameters ---------- guid : str A globally unique identifier. Returns ------- FormDiagram A FormDiagram object. Examples -------- .. code-block:: python import compas_rhino from compas_tna.diagrams import FormDiagram guid = compas_rhino.select_mesh() form = FormDiagram.from_rhinomesh(guid) """ from compas_rhino.helpers import mesh_from_guid mesh = mesh_from_guid(cls, guid) if 'name' in kwargs: mesh.name = kwargs['name'] return mesh
def from_rhinomesh(cls, guid): """Class method for constructing a block from a Rhino mesh. Parameters ---------- guid : str The GUID of the mesh. Returns ------- Block The block corresponding to the Rhino mesh. """ from compas_rhino.helpers import mesh_from_guid return mesh_from_guid(cls, guid)
def explore(processing_func=dummy_processing_func, evaluation_func=dummy_evaluation_func): guid = rs.GetObject('get mesh', filter=32) mesh = mesh_from_guid(CoarseQuadMesh, guid) explorator = Explorator(mesh) explorator.set_processing_func(processing_func) explorator.set_evaluation_func(evaluation_func) explorator.set_scales() explorator.modify_add_settings() rs.EnableRedraw(False) rs.DeleteObject(guid) explorator.redraw_current_mesh() rs.EnableRedraw(True) count = 20 while count: count -= 1 explorator.suggest_delete_rules() explorator.suggest_add_rules() explorator.move_suggested_meshes() rs.EnableRedraw(False) explorator.redraw_suggested_meshes() explorator.evaluate() rs.EnableRedraw(True) meshes = explorator.select_suggested_meshes() add_rules, delete_rules = explorator.select_rules(meshes) explorator.apply_rules(add_rules, delete_rules) explorator.move_saved_meshes() rs.EnableRedraw(False) explorator.undraw_suggested_meshes() explorator.redraw_current_mesh() explorator.redraw_saved_meshes() explorator.evaluate() rs.EnableRedraw(True) if rs.GetString('continue?', 'No', ['Yes', 'No']) != 'Yes': break explorator.modify_add_settings()
guid_target = compas_rhino.select_mesh() guid_border = compas_rhino.select_polyline() guid_points = compas_rhino.select_points() # wrap the Rhino mesh object for convenience # wrap the Rhino curve object for convenience # get the point coordinates target = RhinoMesh(guid_target) border = RhinoCurve(guid_border) points = compas_rhino.get_point_coordinates(guid_points) # make a mesh datastructure from the Rhino mesh # triangulate the mesh mesh = mesh_from_guid(Mesh, guid_target) mesh_quads_to_triangles(mesh) # identify the fixed vertices # by matching the coordinates of the selected points # up to a precision keys = mesh_identify_vertices(mesh, points, '1f') fixed = set(keys) # create a conduit for visualisation # define a callback # for updating the conduit # and for pulling the mesh back to the original during remeshing # and for keeping the boundary on the boundary curve
# define a callback for updating the conduit def callback(k, args): conduit.lines = [[vertices[u], vertices[v]] for u, v in iter(edges)] conduit.redraw(k) dz = 10 # select a Rhino mesh # and make it into a mesh datastructure guid = compas_rhino.select_mesh() mesh = mesh_from_guid(Mesh, guid) # extract the data needed by the smoothing algorithm # identify the boundary as fixed vertices = mesh.get_vertices_attributes('xyz') faces = [mesh.face_vertices(fkey) for fkey in mesh.faces()] adjacency = [mesh.vertex_faces(key, ordered=True) for key in mesh.vertices()] fixed = mesh.vertices_on_boundary() # add two additional fixed vertices # on the inside of the mesh # and set their z coordinates to a low point for key in (161, 256): vertices[key][2] -= dz
from compas_fea.structure import Structure from compas_fea.structure import FixedDisplacement from compas_fea.structure import ElasticIsotropic from compas_fea.structure import ShellSection from compas_fea.structure import ElementProperties from compas_fea.structure import GravityLoad from compas_fea.structure import GeneralStep from compas_rhino.helpers import mesh_from_guid # Author(s): Tomás Méndez Echenagucia (github.com/tmsmendez) # get mesh from rhino layer ---------------------------------------------------- mesh = mesh_from_guid(Mesh, rs.ObjectsByLayer('mesh')[0]) # add shell elements from mesh ------------------------------------------------- name = 'shell_example' s = Structure(name=name, path=compas_fea.TEMP) shell_keys = s.add_nodes_elements_from_mesh(mesh, element_type='ShellElement') s.add_set('shell', 'element', shell_keys) # add supports from rhino layer------------------------------------------------- pts = rs.ObjectsByLayer('pts') pts = [rs.PointCoordinates(pt) for pt in pts] nkeys = [] for pt in pts: nkeys.append(s.check_node_exists(pt))
from compas_tna.equilibrium import vertical_from_formforce_rhino as vertical_from_formforce from compas_tna.rhino import FormArtist from compas_tna.rhino import ForceArtist __author__ = ['Tom Van Mele', 'Tomas Mendez Echenagucia'] __copyright__ = 'Copyright 2016 - Block Research Group, ETH Zurich' __license__ = 'MIT License' __email__ = '*****@*****.**' # ------------------------------------------------------------------------------ # make form diagram from rhino mesh # ------------------------------------------------------------------------------ guid = get_meshes(layer='mesh')[0] form = mesh_from_guid(FormDiagram, guid) # find mesh boundaries --------------------------------------------------------- boundaries = form.vertices_on_boundaries() exterior = boundaries[0] interior = boundaries[1:] # set anchor points ------------------------------------------------------------ for key in form.vertices_where({'vertex_degree': 2}): form.vertex[key]['is_anchor'] = True # relax form diagram ----------------------------------------------------------- form.set_edges_attribute('q', 15, keys=form.edges_on_boundary()) form.relax(fixed=form.vertices_where({'vertex_degree': 2})) # pre-process / feet-making ----------------------------------------------------
def find_path(cls, host='127.0.0.1', port=19997, mode='local', **kwargs): """Finds a path for the specified scene description. There is a large number of parameters that can be passed as `kwargs`. It can run in two modes: *remote* or *local*. In remote mode, the `host` and `port` parameters correspond to a simulation coordinator, and in local mode, `host` and `port` correspond to a V-REP instance. Args: host (:obj:`str`): IP address of the service (simulation coordinator in `remote`, V-REP in `local` mode) port (:obj:`int`): Port of the service. mode (:obj:`str`): Execution mode, either ``local`` or ``remote``. kwargs: Keyword arguments. Returns: list: list of configurations representing a path. """ parser = InputParameterParser() options = {'robots': []} active_robot = None if 'robots' in kwargs: for i, settings in enumerate(kwargs['robots']): if 'robot' not in settings: raise KeyError( "'robot' not found at kwargs['robots'][%d]" % i) robot = {'robot': settings['robot']} if 'start' in settings: start = parser.get_config_or_pose(settings['start']) if start: robot['start'] = start.to_data() if 'goal' in settings: if not active_robot: active_robot = robot goal = parser.get_config_or_pose(settings['goal']) if goal: robot['goal'] = goal.to_data() else: raise ValueError( 'Multi-move is not (yet) supported. Only one goal can be specified.' ) if 'building_member' in settings: robot['building_member'] = mesh_from_guid( Mesh, settings['building_member']).to_data() if 'metric_values' in settings: robot['metric_values'] = map( float, settings['metric_values'].split(',')) if 'joint_limits' in settings: robot['joint_limits'] = settings['joint_limits'] options['robots'].append(robot) if 'collision_meshes' in kwargs: mesh_guids = parser.compact_list(kwargs['collision_meshes']) options['collision_meshes'] = [ mesh_from_guid(Mesh, m).to_data() for m in mesh_guids ] options['debug'] = kwargs.get('debug') options['trials'] = kwargs.get('trials') options['shallow_state_search'] = kwargs.get('shallow_state_search') options['optimize_path_length'] = kwargs.get('optimize_path_length') options['planner_id'] = kwargs.get('planner_id') options['resolution'] = kwargs.get('resolution') if mode == 'remote': LOG.debug('Running remote path planner executor. Host=%s:%d', host, port) return SimulationCoordinator.remote_executor(options, host, port) else: LOG.debug('Running local path planner executor. Host=%s:%d', host, port) return SimulationCoordinator.local_executor(options, host, port)
section='sec_ends', elset='elset_ends'), ]) # Displacements mdl.add([ RollerDisplacementY(name='disp_top', nodes='nset_top'), RollerDisplacementY(name='disp_bot', nodes='nset_bot'), ]) # Loads mdl.add(GravityLoad(name='load_gravity', elements='elset_mesh')) mesh = mesh_from_guid(Mesh(), rs.ObjectsByLayer('elset_mesh')[0]) point_loads = {} for key in mesh.vertices(): xyz = mesh.vertex_coordinates(key) pt = rs.ProjectPointToSurface([xyz], rs.ObjectsByLayer('surface')[0], [0, 0, 1])[0] pz = mesh.vertex_area(key) * distance_point_point(xyz, pt) * 2400 * 9.81 point_loads[mdl.check_node_exists(xyz)] = {'z': -pz} mdl.add(PointLoads(name='load_points', components=point_loads)) # Steps displacements = ['disp_top', 'disp_bot'] loads = ['load_gravity', 'load_points']
]) # Displacements mdl.add([ RollerDisplacementXY(name='disp_edges', nodes='nset_edges'), PinnedDisplacement(name='disp_pinned', nodes='nset_corner1'), GeneralDisplacement(name='disp_xdof', nodes='nset_corner2', x=0), ]) # Loads mdl.add([ GravityLoad(name='load_gravity', elements=['elset_ribs', 'elset_vault']), PrestressLoad(name='load_prestress', elements='elset_ties', sxx=10*10**6), TributaryLoad(mdl, name='load_area', mesh=mesh_from_guid(Mesh(), rs.ObjectsByLayer('load_mesh')[0]), z=-2000), ]) # Steps mdl.add([ GeneralStep(name='step_bc', displacements=['disp_edges', 'disp_pinned', 'disp_xdof']), GeneralStep(name='step_loads', loads=['load_gravity', 'load_area'], factor={'load_gravity': 1.35, 'load_area': 1.50}), ]) mdl.steps_order = ['step_bc', 'step_loads'] # Summary mdl.summary() # Run