David Bachman

Grasshopper: Visual Scripting for Rhinoceros 3D


Скачать книгу

little boxes along the top. The blank part is called the canvas, and it is where you’ll build your programs, called scripts. Each object and operation in Rhino is represented by a box, called a component. For example, there are components corresponding to Rhino primitive objects like spheres and cylinders, components corresponding to Rhino transformations like revolve and translate, and components for building one object from others, such as loft.

      A menu of the most basic components initially appears across the top of the Rhino window. Those components are put into panels, and more components in each panel can be accessed by clicking on the name of the panel. For example, clicking on the word Geometry at the top of the screen expands that panel, as shown in Figure 1.1, giving you access to many more components. Furthermore, many more panels of components are in different tabs.

      To build a Grasshopper script, you simply drag components onto the canvas, and connect them with “wires,” represented as arcs. The input and output to each component is either an object (e.g., a sphere), a piece of data (e.g., a number), or an operation (e.g., a rotation). Information always passes between components from left to right. Hence, wires connected to the left side of a component represent a flow of input data, and wires connected on the right represent output.

      As with any design package, there are often several ways to create a desired object in Grasshopper. For our first examples of Grasshopper scripts, we will see five different ways to create the simple cylinder shown in Figure 1.2.

      Since a cylinder is a basic object in Rhino, there is a built-in Grasshopper component that does the same thing. Click on the Surface tab to bring up the panels of components for working with surfaces. Then click on the Primitive panel, and finally select Cylinder. Now click anywhere on the canvas to place a Cylinder component there.

img

      Immediately you should notice several things about this component. On the left side of the box there are three little white bumps. These are places where you can connect wires from other components for input data. The bumps correspond to the letters “B,” “R,” and “L,” which stand for “Base Plane,” “Radius,” and “Length.” If you rest the pointer over each of these letters, a little callout window will pop up telling you what the input represents, and its default value. The “Base Plane” is the plane on which the cylinder will sit. This not only sets the 3-dimensional orientation of the cylinder, but also its location in space, since the center of the base of the cylinder is the origin of the Base Plane.

      In the Rhino viewports you should see the cylinder created by this component.

      To change the radius of the cylinder, right-click on the letter “R.” A secondary pop-up menu will appear. Select “Set Number,” type any number in the window, and click “Commit Changes.” The cylinder in the Rhino viewport will now change.

      One of the most powerful things about Grasshopper is its ability to dynamically interact with the user. To see this, go to the Params tab, and select the Number Slider component from the Input panel. By default, this slider outputs a real number between 0 and 1. Place this component on the canvas to the left of the Cylinder component. Then move the pointer to the white bump on the right side of the slider, hold down the left mouse button, and drag a wire to the “R” input of the Cylinder component. Notice that the name of the slider automatically changes to the word “Radius.”

      Watch the Rhino viewport as you play with the Grasshopper slider. You should see the cylinder expanding and contracting as its radius changes. You can also place a second slider on the canvas, and connect it to the “L” input. Adjusting that slider will change the height of the cylinder. See Figure 1.3.

img

      Now try double-clicking on the name of either slider. A new window will pop up, where you can adjust the minimum and maximum values of the slider (among other things). Changing these will allow you to make the cylinder as big as you want.

      At this point, the cylinder you see in the Rhino window is only a preview of what Grasshopper is generating. It is not a Rhino object, and thus cannot be manipulated within Rhino. Once you are satisfied with the look of your cylinder, you can turn it into a Rhino object by right-clicking on the “C” output of the Cylinder component, and selecting “Bake.”

      For our second method, we’ll do a vertical extrusion of a circle, as in Figure 1.4. Start with the Circle component (Curve tab, Primitive panel). By default, this creates a circle of radius 1 in the XY-plane. To make a cylinder we’ll do a vertical extrusion. Place an Extrude component (Surface tab, Freeform panel) on the canvas to the right of the Circle component. Then connect the output of the Circle component to the “B” input of the Extrude component.

img

      At this point the Extrude component should be orange, indicating that it needs more information in order to function. A small bubble appears in its top-right corner, and hovering over it reveals the message “Input parameter D failed to collect data.” The “D” input is waiting for a vector to tell the Extrude component which direction to do the extrusion, and how far. Drop a Unit Z component (Vector tab, Vector panel), representing a unit vector in the Z-direction, on the canvas and connect it to the “D” input of the Extrude component. All components should now be their usual gray, representing the fact that they are functioning properly, and a cylinder should appear in the Rhino viewport.

      Hovering over the output of each component reveals a description of what that component is generating. For example, hovering over the output of the Unit Z component displays “{0.0,0.0,1,0},” which is a vertical vector of length one. As with the previous method, to change the radius of the cylinder, just attach a number slider to the “R” input of the Circle component. To change the height, attach a number slider to the “F” input of the Unit Z component. This has the effect of rescaling the vector coming out of that component, which in turn tells the Extrude component to create a surface of a different height.

      At this point there are two components outputting geometry to the Rhino viewport: the Circle component and the Extrude component. When we build more complicated objects, you will want to display only the object generated by one particular component. To do this, click on the small icon in the top-right corner of the Grasshopper window that looks like a half-green, half-gray surface, as shown in Figure 1.5. Now you’ll only see objects in the Rhino viewport when you select them on the canvas, and they will appear there green.

img