Time Based Modelling - Jumping Ball
Expected Time: 30 min
Designers occasionally use animation to visualize their designs. Although Rhino in combination with Grasshopper is not developed for making animations, there are some workarounds to give your parametric design some movement. In this tutorial we will explain the principle of making time based animations in Grasshopper. Before starting this tutorial, it is important to note some limitations:
- Grasshopper uses a timer component based on the internal clock of your operating system. In the case of Windows the minimum interval is 1 ms. Therefore, the trigger component in Grasshopper cannot step shorter than 1 ms.
- Grasshopper is NOT intended to use for complex animations. Please use software like Blender, Houdini or Maya to make efficient animations.
- Animations in Grasshopper are slow, sometimes very slow, if you compare them to other software. Use it only fitting circumstances.
- In many cases, the use of the recorder component in Grasshopper is required. This component can be highly memory based. Your laptop/PC may therefore not be able to animate great amounts of data.
In this tutorial, we will explain the basics of animation in Grasshopper. To illustrate the possibilities, we will create a jumping ball.
Animating a jumping ball
First, we need to create the object we want to move. If you have followed the tutorials of the TOIpedia, you may have noted we do not use meshes most of the time, because can be hard to model. For animation however, it is better to use meshes, because they can be displayed using the Graphics Card of your computer.
- Create a mesh sphere
- Define the radius with a Number slider
- Divide the radius by two
- Create a point as base for the sphere on half the height of the radius
Now we need to create the stepper for our script. This can be done in several ways. For most of the options you will need a plugin for you Grasshopper. In the following case this is not necessary:
- Create a Number parameter
- Set a value of 1 to the parameter
- Connect a trigger component to the Number parameter
If you now click on play, the data inside the parameter will update at an interval you defined. To change the interval, right click on the trigger component.
- Change the interval to 100 ms
Next, we record the data of the number parameter using the Data Recorder function. This function can also be useful if you want to save multiple stages of your model using standard parametric design.
- Connect a data recorder to the number parameter
By right-clicking on the Data Recorder you can specify the maximum amount of iterations to store. By clicking on the X sign, you can delete the data.
Now the Data Recorder will add the value 1 to it’s internal stage every 100ms. However, this is not what we want. By connecting a List Length to the output of the Data Recorder, we can track how many iterations we did. Therefore we have a fully working counter.
- Connect a List Length to the output of the Data Recorder
Shortly click on play on the trigger to get an output for the List Length. After you got an output, turn the trigger off. We don’t want the trigger on while we are building the script.
In the following part of this tutorial we will make the sphere move fluently up and down. First connect a move node to the mesh sphere output.
- Connect a Move component to the Mesh sphere output
Since we don’t want to move the sphere up infinitely, we have to limit the counter. We can do that by calculating the modulus of the List Length output. Simply said, the modulus calculates the remainder of a division. By connecting a Number Slider to the B input, you can define the maximum height of the jump.
- Connect the List Length output to the A input of a modulus function
- Define the max height with a Number Slider into the B input of the modulus
If would now connect this to the Move component with a Z-vector, the sphere would just jump up. We want it to go up and down, and do this smoothly. Therefore we have to remap the value.
- Remap the modulus output to a range 0 to 1
- Use the Number Slider for the height as input for the Source range
Now we use a Graph mapper to change the values of the remap node output. By using a inverted parabola type, we make sure the ball goes up and down smoothly.
- Connect the Remap Numbers output to a Graph mapper
- Set the type to parabola
- Change the position of the parabola top upwards
Now we multiply the Graph mapper output by the height of maximum height Number Slider.
- Multiply the Graph Mapper output by the height
As final step, we need to convert the value to a z-vector. By using the Unit Z node, we can define the direction and length the ball has to move to.
- Convert the value to a Unit Z vector
Now connect the Unit Z vector output to the Motion input of the Move component. If you now click on play on the trigger (make sure you set the preview off for all nodes except the move component), you will see the sphere moving in your Rhino viewport.
- Connect the Unit Z to the motion input of the Move component
- Click on play on the trigger
- By setting the trigger to a lower interval, you can make the animation smoother
By adding a custom preview at the end of the script and adding a color, you can see a rendered version in your rendered viewport.
- Connect a Custom Preview to the Move component output
- Define a color using a Colour Swatch
Export the Animation
Unfortunately it is not possible to just export the animation as you see it in the Rhino viewport. However, there are some work-arounds. Replace the trigger part of the script by a Number Slider. This means: everything from the trigger component to the List Length component.
- Replace the trigger part of the script with a Number Slider
- Set the Number Slider range to the amount of frames you want to create
Right-click on the Number Slider and click on animate. Here you can setup the frame resolution and location to store the frames. If you now click on OK, Rhino will calculate all the frames as individual images. If you want a transparent background, make sure you change the file type to PNG. Using other software like Photoshop or Premiere Pro, you can combine all the frames to a video.
- Right-click on the Number Slider and click Animate...
- Set the resolution and location to store the frames
- Change the file type to PNG if you use a transparent background
- Click on OK
- Combine the frames to a video in software like Photoshop or Premiere Pro