Adding motion in RhinoScript
This tutorial explains step-by-step how to setup animation in any RhinoScript. In this particular and simple case, we are going to move a sphere on a path that is defined by a curve. This example can be, then, expanded to more complex scenarios: for example, using the new animation to trigger some response, as in the case of the component wall.
In cartoons and movies, animation is achieved by rapidly displaying a sequence of pictures that have a common structure. This method creates the illusion of movement, because our brains will, as they are used to, reconstruct the pattern of motion from the static pieces.
How many frames
As we are going to animate an object, we will make it follow a curve. We need, therefore, to sample this curve in a number of (small) intervals. The number of intervals will determine the number of final frames we produce. If you plan to show your animation, later, on a TV screen, then you can take the frame rates of the PAL or NTSC systems: the European PAL has 25 frames per second (fps) and the American NTSC 29,97. If you plan to show your video online, you will need relatively fewer images: at least 18 fps, but most times 24 or 25 fps.
- For a European minute, therefore, the computer will need to render (60 s * 25 frames/s = ) 1500 frames.
- Similarly, for an American minute we will need (60 s * 29,97 frames/s = ) 1789 frames.
Subdividing the curve
To make the movement better controllable, we can, instead of subdividing the curve by Euclidean distance, evaluate it at a fraction of its domain (in its own parameterization). We will therefore be able of applying a weight to a control point, and it will influence the speed in proximity of the respective knot.
- A higher weight coefficient “slows” down the movement in the area.
- Two or more control points close to each other will make the animation basically stop for some time.
Moving the objects
RhinoScript gives us a number of methods to define the position of objects. For example, we can calculate the volume centroid of closed Breps, or the area centroid of open meshes. We will use these points to define the original location of our objects (O).
Because we want to follow a curve, we will need to move the object to the curve beginning, or S. For each frame, we will move by a t parameter farther on the curve. To avoid small summing errors, the script takes again the original coordinate and then sums the vector OS and SN, and does NOT move every time from the previous location (P) to the next (N). This would be subject to errors for small numbers, or for many frames.
The animation details like the ID of the object we move and the original position are saved in a class called animator. As the namespace for VBScript is shared, we can define the class “animator” only once. Therefore, you can load the animator once for every Rhinoceros session. The class does the job of finding out which type of object we are dealing with on its own, so we just need to feed it an ID after initialization with the method setUp(). When we destroy the object, such as in the case we stop the script by pressing ESC or we are finished with our script, the object original position will be restored.
The activity file will create one sphere and look for the first instance of a curve in the document. Make sure that it can find it. Then, it will make the sphere follow the curve in 750 frames. The constant DontRenderUpTo will skip the rendering part of the loop for all 750 frames.
Many other ways to achieve motion in Rhino are explained on the Grasshopper tools page, at the renderAnimation link.