BLOG > SHAPEDIVER BASICA

Meshes vs B-Reps Explained!

November 28, 2018 by Edwin Hernandez

Hi, my name is Edwin. I'm a Grasshopper expert at ShapeDiver and in this blog post I will show the difference between standard meshes and b-reps and how this can impact the performance and rendering of your Grasshopper definitions on ShapeDiver. Let's get going!

It's All About Performance

Grasshopper represents geometry in two ways: using b-reps or using meshes. This is something the majority of Grasshopper developers already know, but a deeper understanding of these concepts can help clarify how they can affect the performance of Grasshopper definitions when they run on ShapeDiver.

This performance is especially crucial for any ShapeDiver model that will be accessed or interacted with via a web browser, where the available internet connection or even the device's own hardware can play a significant role on the UX. At ShapeDiver we recommendour users to create definitions that typically load in under 5 seconds as it's proven that the average B2C end user won't wait for longer than this time before heading elsewhere.

In this post I will discuss the difference between b-reps and meshes and I will give you some tips and tricks that will make your definitions load in the least possible time.

What Is A Mesh?

mesh is the native geometry representation your graphics card (GPU) needs in order to display objects and it consists of a collection of vertices (points) and faces (typically triangles and rectangles).

The more vertices and faces a mesh has, the more time will be required to transfer the mesh to the end device and the more GPU resources will be used. This amount of vertices and faces is what we need to keep the lowest possible in order to have a definition with a great performance.

What Is A B-Rep?

On the other hand, a b-rep (or brep) is the short name given to "Boundary Representation". It consists of representing surfaces through mathematical equations and a set of limits in the 3D space. B-Reps are both more compact in their definition while retaining more structural information about the shape. Therefore, one can define complex operations on them easily (such as boolean differences or piping) which is challenging to do with meshes.

However, b-reps need to be converted to meshes in order to be rendered by a GPU. During this operation, any performance benefit from using b-rep can be cancelled by the meshing algorithm, if it isn't done right. To get precise information on any given b-rep, type "what" in the Rhino command line. This will open a window describing the object you have selected. At the bottom of this window you'll be able to see the size of the mesh that is being rendered to display this object.

What Happens When Displaying B-Reps In ShapeDiver's Viewer?

All b-reps output to ShapeDiver's viewer are eventually converted to meshes. We try to make this conversion as efficient as possible. However, the automatic conversion potentially comes with two issues: it will increase the online loading times of the models in a non predictable way, and it can produce visual artefacts since the amount of vertices and faces of the meshes can't be controlled. For example, whenever a b-rep contains several faces grouped with hard edges, those faces might be meshed independently and might not appear watertight in the online viewer.

How Can I Handle B-Reps Then?

Optimal performance on ShapeDiver can be achieved by balancing b-rep and mesh operations, keeping the b-rep representation as long as necessary to perform complex operations in the most efficient way but switching to meshes whenever it makes sense, and definitely before outputting geometry to the viewer using one of the ShapeDiver display components.

Keep in mind that the meshing steps of your definition increase the computation time, but at least it is a time that you can predictably control, as opposed to letting our servers do the meshing themselves and possibly output heavy meshes to the viewer. One should always think of how relevant and how big each piece of geometry is in the definition, and optimizetheir mesh size as much as possible according to it.

For example, let's say we are creating a house and we need to have the 3D model of the door knobs. The most probably situation is that these door knobs will be barely seen in the entire definition as they are a very small detail. In this case, using a perfect sphere to represent the knobs is not worth it. Instead, improve your definitions by using a sphere with very few polygons. But...

How Does One Convert B-Reps Into Meshes?

The most efficient way is to use primitive shapes since Grasshopper already offers direct solutions to create meshes in which you can clearly and exactly define the amount of polygons that you wish to use.

However, in most cases, your geometry will be more complex than a primitive shape, which means you will need to use the component "MeshBrep" that offers different settings solutions to play with the amount of faces and vertices your mesh has.

The simplest setting component is called "Settings(Speed)" and will try to make your mesh as efficient as possible. However, sometimes it is better to use the "Settings(Custom)" as this one has a variety of options to optimize your mesh even more.

Other components which need meshes as inputs will also convert your b-reps directly into meshes, such as the Texture Mapping components in the Human plugin or our owncomponent "ShapeDiverTextureTransform" (I talked about this tool in my previous blog post), but it is not recommended to convert your b-reps in this way as you won't have any controlover this conversion.

TIP: If you want to visually check how the wireframe (faces and vertices) of your mesh is, type ctrl+m in Grasshopper, as usually Grasshopper hides the wireframe by default.

* Vertices and faces count difference when converting to mesh directly vs using mesh settings with the "MeshBrep" component.

How Can You Test The Performance Difference Between B-Reps and Meshes?

I have created two performance test models on ShapeDiver. The first one was created using meshes while the second one was created using b-reps. If you push the definitions by drastically changing the settings from the minimum values to the maximum ones, you can notice how the b-rep definition (the second one) takes almost double the time to load in comparison to the mesh definition. Sometimes, depending on your device, the b-rep definition might even crash the browser.

How Can One Be Even More Efficient?

If you have any knowledge using C# Scripting or other programming languages available in Grasshopper, you can create very efficient definitions by coding exactly the way a mesh will be constructed from scratch. You can also use different components inside the mesh tab in Grasshopper.

As a demonstration of using the components just mentioned, I would like to share a clusterthat we have created which allows you to do something as simple as extruding, but it outputs a mesh that can be easily optimized using the tolerance parameter.


This example outputs the same geometry than the one in the "MeshBrep" component example, but as you can see, we could bring the face count to half of what was obtained in the best case with "MeshBrep".

Conclusions

The performance/loading times of Grasshopper definitions are not always the main preoccupation of a Grasshopper designer, but since ShapeDiver.com brings the possibility to share those definitions online, we as Grasshopper developers have to make sure that everyone can have a pleasant experience by making the loading times as fast as possible in the majority of devices.

I hope that knowing the difference between b-reps and meshes will let you improve the performance of your present and future projects, but this is just the beginning. If you want to learn other ways of making your definitions as smooth as possible, visit our Forum and stay tuned for future blog posts.

--

Was this tutorial helpful? Do you have any comments or feedback? Make sure to visit our Forum and start a thread with your doubts! We're always checking for new topics from our users so we'll make sure to give you useful answers.

More posts