3D Grid from Surface

From TOI-Pedia


Expected Time: 20 min
Possible result of this tutorial

This tutorial is focused on three useful tools in Grasshopper: UV subdivision of surfaces, box morphing and finally coloring based on surface properties. First we create a lofted surface in Rhino. The surface can be changed by control points along the curves of the loft.

3D Grid from Surface

Create a loft with two curves

First you set two curves drawn in Rhino and create a loft between them using the loft component.

  • Create two curves in Rhino Rhino » Freeform » Curve » Control-points
  • Create a curve parameter in Grasshopper Params » Geometry » Curve
  • Set the curves on the curve parameter RMB on curve parameter » Set multiple curves
  • Loft the curves Surface » Freeform » Loft

Divide the surface in smaller surfaces

Subdivide the surface with UV segments using the isotrim component

  • Subdivide the surface Maths » Domain » Divide Domain2
  • Connect two number sliders to the U and V input Params » Input » Number Slider
  • Trim the surface using the UV domain Surface » Util » Istotrim

The result is a series of smaller surfaces, you've pannelized the surface. These are the cells of your grid.


Once the surface is pannellized into a uv-grid, you can use it for many different transformations. One of the transformations we will demonstrate here are the Surface Box and the BoxMorph tool. A SurfaceBox creates 3D cells (with a specified height) from the 2D cells of the divided Surface. The Boxmorph places an object within those 3D cells, automatically adjusting the dimensions of your geometry. It adjusts the BoundingBox of the geometry to match the 3d boxes on the surface, and scales the geometry accordingly.

Create boxes on the isotrim surfaces

First, you need to convert the 2D cells to 3D by using the SurfaceBox command. Connect the original surface and use the Domain from the Divide Domain component. Specificy the Height by using a Number Slider. Now you have generated the Target boxes for the geometry.

  • Create boxes on the grid using the surface, isotrim and a Height number slider as input Transform » Morph » SurfaceBox
  • Define the height with a Number Slider. You may have to use a negative value Params » Input » Number Slider

Design a geometry to morph on the surface

Now you can create a geometry in Rhino that you want to morph over the surface. Then set it on a geometry parameter in Grasshopper.

  • Design the geometry you want to morph over the surface in Rhino
  • Create a geometry parameter Params » Geometry » Geometry
  • Set the geometry on the parameter RMB on geometry parameter » Set one geometry

Design a geometry to morph on the surface

Now we create a bounding box around the object. A bounding box is the smallest possible box around an object using the axes of a specific plane. After that, we morph the geometry back to the surface.

  • Use the bounding box function on the geometry using the content input Primitive » Surface » Bounding Box
  • Create a surface morph node. Plug the BoundingBox into the Reference Box input on the Boxmorph tool. Finally add the Target boxes from the SurfaceBox command. Transform » Morph » BoxMorph

The box morph is a computationally expensive process, so it may take a while to get the result

Use multiple objects to morph

If you want to morph multiple objects to the surface, you can change the bounding box setting by right-clicking and selecting Union Box. You also need to group the objects for the Geometry input.

  • If using multiple geometries, set bounding box to union box RMB on Bounding Box » Union Box
  • Group the geometries before the Geometry input Transform » Util » Group

Surface Analysis

Evaluate the isotrim surfaces

The surface subdivision can also be useful in analyzing the surface. For example, by using Evaluate Surface node, we can evaluate the surface based on a uv coordinate.

  • Turn off the preview of the Box Morph section
  • Connect the isotrim surface to an Evaluate Surface node Surface » Analysis » Evaluate Surface

Reparametrize the surface input

UV coordinates refer to the domain of the surface. For our purposes we will reparametrize the surface, meaning we redistribute the uv domain from 0-1.

  • Right-click on the Surface input of the Evaluate Surface component and select Reparametrize RMB on Surface input » Reparametrize

Find the center of the isotrim surfaces

Using the MD Slider is visually easy to understand as the square lay-out of the slider mimics the uv-point in relation to the surface. The output of the slider is a x,y,z coordinate where the z is always 0.

  • Calculate the center point of the surface with the MD Slider, do not change the values Params » Input » MD Slider
  • Connect the MD Slider output to the Point input of the Evaluate Surface node

Internalise the Point input if you wish

To keep your definition compact you can decide to internalise the uv-coordinate. This means that the data is stored inside the component and is permanent until substituted with another input. Right-click the uv-input and select internalise data

Color by Slope

The Evaluate Surface component returns a Point, a Normal and a Frame (plane derived from geometry). We can use this data to analyze the curvature of the surface. In order to visualize this data, we will color the subdivisions according to their slope. This could be useful when you are generating a walkable surface and the slope cannot by higher than 10% (wheelchair accessibility, for example. This can be done in many ways, but to understand the process exactly we calculate the vector of the normal compared to a vertical vector. If we multiply this by 100, we obtain the slope percentage.

Create two SDL lines from the evaluate surface output

To visualize the process we will first draw two SDL-lines. One SDL-line will Start from the evaluated surface Point following the Direction of the Normal. The L doesn't matter, a Number Slider can be used in this case. The other SDL-line follows the z-Direction, Starting from the same Point, using the same Number Slider for the Length.

  • Create two SDL-lines from the Evaluate Surface Point output Curve » Primitive » Line SDL
  • Define a random length with a Number Slider Params » Input » Number Slider
  • For the second SDL line, use a Z-Unit Vector as input, instead of the Normal output Vector » Vector » Unit Z

Reverse the direction of the Normal SDL line

Make sure they have the same orientation, if not (like in the example here) one of them needs to be inverted by using the Math » Operators » Negative.

  • If necessary, flip the direction of one of the SDL line direction inputs Math » Operators » Negative

Create two vectors from the SDL lines

Now we extract the Endpoints of the lines to easily generate a 2-Point Vector, ensuring the correct direction of both vectors instantly.

  • Find the endpoints of the SDL lines Curve » Analysis » End Points
  • Create two vectors from the endpoints per line Vector » Vector » Vector 2Pt

Calculate the angle between the vectors

Compute the angle between the two vectors. This equals the slope since calculating the difference between the horizontal vector and the tangent vector on the surface (90 degrees rotated normal) returns the same number.

  • Compute the angle between the vectors Vector » Vector » Angle
  • Multiply the output angle with 100

Display the surface angle using a gradient

For a colored representation of the different slopes we can use a color gradient option. Connect the slope percentages from the Multiplication component into the Parameter t of the Color Gradient. Plug the Divided Surface geometry into a Custom Preview component. Then enter the output of the Color Gradient into the Color input of the Custom Preview.

  • Display the angles of the surface using the t input of a gradient Params » Input » Gradient
  • Set the Upper Limit input to 90
  • Connect the gradient output to a Custom Preview Shader input Display » Preview » Custom Preview
  • Connect the isotrim surfaces to the geometry input of the Custom Preview node

Set the color preset

There are different pre-sets if you right-click on the colored component. Moving the small dots adjusts the corresponding colors and percentages.

Final script
Personal tools