In my work I typically deal with production-ready files: 3D models containing parts intended for fabrication, laser cutting, CNC milling or 3D printing. It is not uncommon for me to miss interferences between parts, ending up managing the frustration of colleagues who could not assemble the problematic pieces or, in the worst case, had to repeat the entire production process.
Rhino and Grasshopper both offer tools to check for interferences, but they are extremely limited and do not allow you to inspect the entire model at once. I therefore decided to build a small routine in Grasshopper around the Clash component, to catch intersections before the parts go into production.
For this exercise I used an old 3D model of the Ultra-Fast Charging Station in Fredericia, Denmark, designed by Cobe Architects, which I had modelled years ago for a personal project. I have hidden a small error that, if we have done everything correctly, will be detected by the script. At the bottom of this page you will find the links to download the Grasshopper file and the Rhino model.
First, we import all geometries into Grasshopper in a generic Geometry container. I recommend working with clean, closed polysurfaces or extrusions, because clash detection is performed on meshes and starting from a correct base geometry is essential. The next step is to convert the breps into meshes using the Mesh Brep component. For the S (settings) input, the Speed preset is sufficient as it keeps the polygon count to the bare minimum. If you're working with many curves and organic geometries, it's better to use the Smooth or Custom preset instead.
At this point the meshes need to be scaled from their vertices by a tiny amount, just enough to avoid false positives caused by elements that touch but don't actually intersect. To do this, they first need to be welded using Wb's Join Meshes and Weld (from Weaverbird, my preferred option, though a default version also exists), then deconstructed with Deconstruct Mesh. Finally, we move the vertices by a negative value along their normals and rebuild the mesh with Construct Mesh, using the vertices in their new position and the original faces. The offset must be truly minimal, otherwise this trick itself becomes a source of error.
The Clash component in Grasshopper detects collisions between two sets of elements. The starting point is to compare each element against the entire list, but this way we would end up clashing every piece against itself, without solving anything. The solution is to build, for each element (SetA), a SetB with the remaining n−1 elements.
For simple projects this might already be enough, but with thousands of elements the number of comparisons to evaluate quickly becomes enormous (n × (n−1)).
To optimize the calculation we introduce a preliminary filtering step based on bounding boxes. Before building the SetBs, we check whether the bounding box coordinates of each element in SetA overlap with those of the elements in SetB: if even a single coordinate does not overlap, the two objects cannot touch and we can safely ignore them.
In practice: using Deconstruct Box we extract the X, Y and Z domains for both sets, then evaluate the overlap with Interval Connection (a component from Heteroptera), which returns a boolean in OVR (Overlapped). We feed everything into Gate And, which returns True only if all three domains overlap. Instead of managing n lists of geometries, we work with n lists of booleans, much lighter.
At this point we use the Gate And output as a pattern in a Cull Pattern to clean up the SetB, then connect SetA to input A and SetB to input B of the Clash component.
This step can make the difference between minutes and hours of computation, and significantly increases the number of elements that can be evaluated in a single pass.
The Clash component has done its job, now it is up to us to extract the results and decide how to handle them visually. The only output we care about is N (Clash Count). With a Larger Than component (if you type 0 while placing it on the canvas it will be inserted automatically) we check which elements register collisions and create a mask to filter the GUIDs of the original geometries, not the meshes, but the BReps. To retrieve the GUIDs it is enough to attach a GUID container, and you do not need to worry about the order: if you have followed the steps correctly, the boolean order is identical to that of the GUIDs.
At this point we use Cull Pattern to isolate the GUIDs of the colliding objects, which we connect to the Interact with Rhino Objects component from Elefront with the Isolate option active (selectable by right-clicking on it). Finally, with Dispatch and Entwine we build a tree to assign red to the intersecting objects and green to the clean ones.
And there it is. The script has found it: two elements in the upper right corner of the roof structure, highlighted in red against the rest of the model in green. The error we had hidden at the beginning is now impossible to miss, and we did not have to manually inspect a single part to find it.
This is exactly the kind of feedback that makes the difference in a production workflow: immediate, visual, and unambiguous. No more surprises on the shop floor.