I have limited experience with Rhino, Python Scripting for Rhino and Grasshopper, and hope to get hints in the right direction for the following task I’m trying to automate:
I want to geometrically interconnect two touching meshes across their complete common / touching surface areas. The example picture below should clearify how the result could look like.The cylinders with cones at the top are fused to the bottom mesh and have been cut out of the top mesh, to realize a form fit between the two parts.
Given are two solid and arbitrarily complex meshes that touch with one or more parts of their surfaces, like in the example picture below:
The two objects need to be geometrically connected at the touching surfaces with some geometry like this:
- The density in which the connection objects are placed on the surface should be configurable by the user
- The height and position of the connection objects has to be adjusted in a way, that the connections are „invisible“ from the outside, meaning they can’t pierce the sides or the top of the mesh they connect to (see example picture below).
So far I have been able to extract all mesh faces of one mesh, that have their center points very close to the other mesh, but that does not really define the touching surface as a whole. Some mesh faces are only touching the other mesh partially and others are not extracted at all, as their center points are not touching the target mesh.
The following picture shows the mesh faces extracted from the bottom object:
The code used:
# -- coding: utf-8 --
import rhinoscriptsyntax as rs import Rhino import math import scriptcontext as sc rs.EnableRedraw(False) # Minimal distance to define "touching" MIN_DIST = 0.25 # mm # User object selection obj_a = rs.GetObject("Pick the first Mesh-Object", rs.filter.mesh) obj_b = rs.GetObject("Pick the second Mesh-Object", rs.filter.mesh) # Mesh to nurb of object a, to make each face a nurb surface to work with obj_a_brep = rs.MeshToNurb(obj_a) # Deconstruct polysurface a_explode = rs.ExplodePolysurfaces(obj_a_brep) # Result List conn_surfaces =  for a_surf in a_explode: centroid = rs.SurfaceAreaCentroid(a_surf) closest_point = rs.MeshClosestPoint(obj_b, centroid) distance = rs.Distance(centroid, closest_point) if distance <= MIN_DIST: conn_surfaces.append(rs.CopyObject(a_surf, translation=(0,100,0))) rs.DeleteObjects(a_explode) rs.DeleteObjects([obj_a_brep]) rs.EnableRedraw(True)
My current idea for an algorithm solving my problem partially is shown below, but I’m hoping for suggestions and tips for a simpler, faster or generally smarter solution for this problem:
- User selects two mesh objects a and b
- One mesh is converted to a nurb polysurface (every mesh face becoms nurb surface)
- For every surface patch (former mesh-face) of object a:
- …Measure the surface and place a number of points on it, depending on the size (small → few points, large → more points)
- For every point placed on object a:
- …Check, if the point touches object b (or has a very small distance to it), if not: remove
- For every remaining point on object a:
- …Check, if there is some other point closer than a defined minimal distance and if so: remove
- We now should have points covering the touching parts of object a and b with a minimal distance between the points
- Place a user defined connection object on each point and orient it with the surface normal at that location (maybe also scale object here)
- Merge the connection objects to object a
- Clip the modified object a from object b, to create a form-fit between the two objects
- Remove all parts of the connection structure that pierce object b on the side or the top or are too close to an edge. So far I have no idea how to realise this step.
I would be very happy to get your opinion on my suggested solution or any hints for methods or plugins I should look into!
Given the vast possibilities of the tools and plugins of Rhino and especially Grasshopper, I guess and hope that there are other ways to connect two meshes geometrically, and I greatly appreciate any tips and suggestions