Grasshopper: Visual Scripting for Rhinoceros 3D. David Bachman

Чтение книги онлайн.

Читать онлайн книгу Grasshopper: Visual Scripting for Rhinoceros 3D - David Bachman страница 9

Автор:
Жанр:
Серия:
Издательство:
Grasshopper: Visual Scripting for Rhinoceros 3D - David Bachman

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

href="#ulink_f8a3a429-5832-5eb1-93a5-b187b5adf25b">Figure 5.7 is a modification of that in Figure 5.5. For this example we will use the “panel” depicted in Figure 5.8. As before, this is referenced by the Brep component in the script.

img

      To get a paneling effect, we break up the domain of the surface into smaller regions with the Divide Domain2 component (Math tab, Domain panel). At the U and V inputs to this component we set numbers to tell it how many times to break up the domain in each direction. For the script depicted here, we have set the U input to the value 10, and the V input to the value 5. Thus, at the S output we get a list of 50 smaller rectangular domains. Each of these is then fed to a Deconstruct Domain2 component (Math tab, Domain panel) to find sets of U and V parameters. Finally, at the W input of the Surface Morph component we use a “0.0 to 1.0” Domain, output by default from a Construct Domain component (Math tab, Domain panel). After playing with the values set at the radius (R) and length (L) inputs of the Cylinder component, the result is the paneling of a cylinder depicted in Figure 5.9.

img img

       More List Manipulations

      As we have already seen, most Grasshopper scripts contain components that act on every element in a list. However, it is often the case that you will want different things to happen to different elements of a list. To accomplish this, Grasshopper contains many special components to separate lists and put them back together. Two of the most common are the Weave and Dispatch components (both in Set tab, List panel). We illustrate the use of both of these components with the script of Figure 6.1, which is a further modification of the paneling script from the last chapter.

      The Brep component shown here is set to reference the panel depicted in Figure 6.2. The U and V inputs to the Divide Domain2 component are set to 16 and 9, respectively, creating 144 subdomains of the cylinder. The N input of the Duplicate Data component (Set tab, Sequence panel), fed by the Brep component, is set to 144. This creates a list of 144 copies of the referenced surface, one for each subdomain. This list is immediately passed to the Dispatch component. By default this component creates two lists. At the A output is a list of every even numbered list element of the input list. At the B output is a list consisting of the odd numbered inputs.

img img

      Every element of the B list is now sent to a Mirror component (Transform tab, Euclidean panel), which creates the mirror image object across the XY plane. Finally, both the list at the A output of the Dispatch component and the output of the Mirror component are sent to a Weave component. This has the opposite effect as the Dispatch component: by default it creates a new list whose even numbered elements come from the 0 input, and whose odd elements come from the 1 input.

      The last thing of note before the Surface Morph component is that the entire list of surfaces is passed to a Bounding Box component. Notice in the figure that this component has been set to act in “Union Box” mode (right-click to see this option). This creates one bounding box that contains everything coming in to the component, rather than separate bounding boxes for each input geometry.

      The script of Figure 6.1 produces the object depicted in Figure 6.3. Here we have colored two individual panel components so you can see that one comes from the mirror image of the other.

      In the previous example we used the Dispatch and Weave components to perform different actions on every other element of a list. A different use of Dispatch and Weave is to create a conditional “if... then... else...” statement. This is accomplished by evaluating some boolean (e.g., true/false) condition for each list element, and feeding the resulting list of true/false values to the P inputs.

      We illustrate this idea in the Grasshopper script depicted in Figure 6.4. This script has the same effect as the Offset component (Curve tab, Util panel). However, a slight modification of this script will produce variable offset curves, which are not possible with the Offset component.

      The script begins with a Curve component, set to reference some closed curve created in Rhino’s XY plane. As discussed in previous chapters, we obtain 100 values of the curve’s parameter with a Divide Curve component, with the N input set to 100. We then use a Curvature component (Curve tab, Analysis panel) to obtain a vector K that is perpendicular (normal) to the curve at each curve point P, corresponding to each input parameter value t. We then rescale each of these normal vectors to have length one with a Unit Vector component (Vector tab, Vector panel). Adding these vectors to the curve point at which they are based then produces a set of points that are exactly one unit away from the curve. These points are depicted in Figure 6.5.

      You can immediately see that there are many problems with these points. Some are inside the curve and some are outside. If we were to create a new interpolated curve through these points it would cross the original curve in several places. This is clearly not the desired offset.

img

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