Читать книгу Grasshopper: Visual Scripting for Rhinoceros 3D - David Bachman - Страница 10
ОглавлениеIn previous chapters we saw how to make your Grasshopper scripts interactive by using a number slider. However, this is just one way in which a user can interact with a script. For example, one can use a Control Knob (Params tab, Input panel) in place of a slider to simulate setting a dial. However, this is really just an alternate way to do the same thing.
The number slider itself is an extremely versatile component. As we have seen, some components expect a real number input, such as the R input (radius) of the Circle component. Others expect a natural number as an input, such as the N input of the Range component. Sliders can be used at those inputs, too, by right-clicking on them and changing the “Slider type” to “Integer.” For example, examine the simple script depicted in Figure 3.1. The output of the slider determines the number of real numbers that the Range component will pick in the given domain. These numbers are then passed to the X input of a Construct Point component.
FIGURE 3.1. Using a slider to change an integer-valued input.
Another useful way to interact with a Grasshopper script is with the Graph Mapper component (Params tab, Input panel). Examine the script depicted in Figure 3.2. This script creates 10 circles at different heights, parallel to the XY-plane, and lofts them. The radius of each circle is determined by a function depicted right on the Graph Mapper component. When you right-click on this component, you’ll have the choice of a variety of different types of functions under the “Graph types” submenu. Each such function is marked with a few white dots that determine its shape. Moving these dots around changes the function, and therefore the final output geometry. One can see the effect of this in Figure 3.3.
FIGURE 3.2. A surface of revolution whose profile is determined by the interactive Graph Mapper component.
FIGURE 3.3. Changing the graph shape will change the shape of the resulting surface.
Direct Interaction with Rhino Geometry
For a different way to interact with Grasshopper, try building the script depicted in Figure 3.4. The Series components (Set tab, Sequence panel) in this script are each outputting the list of numbers 0,1,2,...,9. These are both fed into a Construct Point component, with the second one grafted, thereby creating a 10-by-10 grid of points. The Point component toward the bottom of the script is referencing the highlighted point in the Rhino viewport, defined by right-clicking on the component and selecting “Set one Point.” Both the grid of points and this individual point are fed into a Distance component (Vec tab, Point panel), which measures the distance between the chosen point and each point of the grid. Finally, these distances are used as the radii of circles, centered at each grid point.
FlGURE 3.4. The pattern of circles in the Rhino viewport will change as you move the highlighted point.
To reveal the interactive nature of this script, make sure the Point component is selected, and move the referenced point around in the Rhino Top viewport. You’ll notice the pattern of circles changes dramatically as you move it. See Figure 3.5. In a similar way, any Rhino geometry can be used as the basis for an interactive Grasshopper script. Creating a curve in Rhino, and referencing that curve by right-clicking on the C input of a Pipe component, creates a surface. Modifying the curve in Rhino (by turning “Points on,” for example) will cause Grasshopper to modify the resulting surface.
FIGURE 3.5. The pattern of circles in the Rhino viewport will change dramatically as you move the highlighted point.