Tutorial 4: Chase -- intro to object dynamics

preview video clip

RealFlow3 Final Project Files for this tutorial

Scene Data File for this tutorial

Objectives

This tutorial provides a further introduction to the use of imported objects in RF3. The tutorial illustrates how object motion can be controlled by some daemons just like fluid particles, and provides a useful example that can be used in many scenes: the simulation of a dynamic moving camera.

This scene introduces some object concepts that will be used again in more advanced tutorials involving objects.

The tutorial is for beginners, but the application to camera movement and shake may be interesting to more experienced users.

Introduction

Daemons can be used to affect particles, and also objects. This is a lesser known, or at least lesser used, feature of RF3 but a very important one for scenes involving dynamically-moving objects.

In this tutorial we're going to imagine we've been handed a task in a production: A spaceship is flying quickly through a futuristic city, on a twisting and turning path. The animation of the flight is given to you, and the task is to deliver physically realistic camera motion that follows the spaceship like it was a chase. As we all know, if you really were following behind and holding a camera, there would be camera shake related to your own motion, and also due to the camera operator's efforts to track the lead spaceship ("camera target shake"). Digital camera moves often look too digital, but RF3 gives us the ability to add the physical elements back in with essentially no keyframing and a very quick simulation.

The work will focus on using objects and cover a little more on daemons as well.

This tutorial assumes you are familiar with the RF3 interface and basic concepts. If you are not, you may wish to first try Tutorial 1 on making a geyser, or accessing some of the other help resources that are freely available (see below). The tutorial will not touch on fluids, meshing, waves, constraints, transferring data between RF3 and 3D applications, and rendering.

The structure is designed for quick navigation depending on your level of experience with RealFlow, and your level of learning interest:

-         For those wanting to quickly cover the basics and like to learn by doing and experimenting rather than get into details, just follow the bold steps giving simple instructions. Or, download the project files and examine them, running tests simulations and tweaking parameters.

-         If you like more detailed instructions and explanations, follow the main body of the tutorial text. Sections devoted to explaining how RealFlow works or relevant aspects of physics theory are broken out in blue italics and indicated with the subheading “Explanation”.

-         For more experienced users who feel they know how to do this kind of project, but want to gain a better understanding of aspects of RealFlow, scan the bold instructions and then check out the explanation sections.

-         Finally, at the end of the tutorial are notes giving useful tips and alternative approaches.

If you want additional help during the tutorial or are looking for other tutorials afterward, there are a lot of resources available to you:

Under Help>contents… you’ll find the online manual that is packed with information, and is a good place to start (if you’re a total beginner, check the Getting Started section).

Second, check the Next Limit website for more, as well as example scenes that are great for learning. Third, there are a lot of very good user tutorials accessible from Next Limit’s RF3 forum, in the tutorial section. These tutorials have been checked over and rated by experts, and a good place to start is in the index of tutorials in that part of the forum.

Finally, take advantage of the user community in the forum to ask questions and gain a variety of insights.

While working in RF3, use the tooltip-style help when you need reminding or definitions of functions: hover the cursor over an interface element and hit F1 to get a popup giving you info on that element. If the element is a sub-panel tab, RMB-click over it for information. For more shortcuts, go to Help>Key Shortcuts…

Before we start, let’s define some common abbreviations:

RF3 = RealFlow version 3.x

UI = user interface

LMB / MMB / RMB = left, middle and right mouse button, respectively

Ctrl = the control button on your keyboard

Alt = the alt button on your keyboard

Shift = the shift button on your keyboard

1,2,3,4,Q,W,E,R = those buttons on your keyboard (e.g., W = the W button on your keyboard)

1 – Initial setup

Start up RealFlow, create a new project called “chase”. Also set up the workspace using File>Preferences…, to give the view setup you want, and add some Summary Info.

If you want your view to look like those below, select the 3-view window and otherwise keep everything at the default values.

Finally, you may wish to add some file information by going to File>Summary Info...

We are going to import the objects and animation of the spaceship flight, and attach daemons to the spaceship to pull along two chasing objects -- one represents the camera target, the other the camera itself.

2. Import the scene data

Download the archive containing the .SD file called objs_2rf_chase.sd, and unzip it into the objects folder of the chase project. Import the scene data and play the animation.

If you haven't done it yet, download the zip archive of the scene data file containing all the objects you'll need, plus the animation of the "spaceship". The file is called objs_2rf_chase.sd, and you should unzip it into the objects folder of your new chase project.

The SD file was created by exporting from a 3D platform using Next Limit's scene data exporter plugin, available for free download from the downloads section of the Next Limit website.

Import the scene data into the scene by going to the objects tab and LMB-clicking on the folder icon below the display window. The dialogue should start by looking at the contents of the objects folder for this project.

Play the animation - you can see that there is just one animated object in this 360-frame sequence, called "target", which is a simple cube representing the spaceship position. If this was a real production, then a simple object like this cube would still be the right thing to bring into RF3 for our purposes. The simpler the objects you can use, the better: it makes for markedly faster calculations. This is simple to do, requiring just attaching a simple object like a cube to the more complex object in your 3D package.

The two objects called chaser_far and chaser_close will be the objects we make follow the target.

Explanation: Object Import

If you import objects in SD files, they come into RF3 as a group. You can disable individual objects in the objects tab display, by un-checking the box beside their name.

Disabled objects are left out of all aspects of the scene - they are not included in object-object, object-daemons or object-fluid interactions. They get dimmed in the viewport but they are still there to clutter the view. You cannot, however, delete individual objects if imported in SD files, if you delete one you will delete all. In addition, you can only have one imported SD file at any time. If you attempt to import another, the previously imported objects will be removed.

If you want more flexibility with objects and they aren't being imported with animation, you can export them from your 3D package individually in Wavefront .obj format, and then import them individually. This was done in the more advanced tutorial "playcatch". It's a good idea to triangulate the objects in your 3D platform before exporting to .obj format, because some 3D platforms may otherwise produce .obj objects with polygon holes. These will not behave in the way you want them to in RF3, especially when fluids interact with the objects.

Objects imported in .obj format can be individually removed and re-added. If these objects are involved in dynamics calculations, you can import them to your scene in your 3D package and then the Next Limit dynamics importer will recognize them and apply the position, scale and rotation sequences to them without issue.

3. Set-up Dynamics for Objects

For the 2 chaser objects, turn on Dynamics, set Dyn Motion to Yes, and Collision to No.

In the objects tab, select both the chaser_far and chaser_close objects, and expand the Dynamics subpanel.

Turn on Dynamics -- this toggle tells RF3 whether to include the object in collision calculations. If it is set to No, fluids and other objects will shoot right through the object. If Yes, particles and dynamically controlled objects will be able to interact with it. When set to Yes, the various other dynamics parameters become available to you.

Turn on Dyn Motion -- If Dyn Motion is set to No, the object's motion will not be controlled by the dynamics engine; it will be static or, if you keyframe-animated it, it will move as animated. For example if you animated a big ball rolling over a surface, and wanted it to knock over a barrel using dynamics in RF3, you could leave Dyn Motion set to No for the animated ball and set it to Yes for the barrel. Then the ball would affect the barrel, but it would not bounce off the barrel or be in any way slowed or affected by the impatct. We want the chaser objects to be influenced by daemons, so we need this set to Yes.

Turn Collision off -- If Collision is set to No, then the object will not experience collisions with other objects but it can collide with particles. We don't want the chaser objects to hit each other or other objects at all, since they represent the camera and the camera viewpoint. If they represented actual objects chasing the spaceship, we would turn this on and also turn on dynamics for the rest of the objects in the scene. We'll run that experiment later, for fun.

We'll discuss the other parameters later, for now leave the default settings. You may notice that the chaser objects have now been surrounded by a bright green cube. This reflects the Primitive setting. Primitive tells RF3 what shape to take for the object for calculating collisions. The simpler the shape, the faster the calculations so when you can get away with making this a simple cube, it is a wise idea. We aren't using collisions here so it doesn't matter what Primitive is set on. That aspect will be explored in some detail in other tutorials.

4. Add Daemons

Add an attractor daemon and a drag force daemon, and link the attractor to the target. Set the drag strength to 10 -- this will slow down the chaser_close object and prevent too much oscillating.

The idea here is to make the target object attract the chaser objects, so they follow along. How quickly they follow will depend on the strength of attraction, applied drag / friction, and their mass. Depending on these settings, we can get the objects stuck to the target, trailing closely behind, or swinging and overshooting sloppily as though they were weights attached to a long rope.

There are only a few daemons that can affect objects: gravity, attractor, drag and vortex. These give plenty of flexibility, however, because as usual you can animate their values and use them in interesting combinations. But note that attenuation of deamons does not work with objects, and bounding only works with attractors.

First, go to the daemons tab and add an attractor to the scene. Link it to the target object. It will now go along for the ride when the target moves, and pull the chasers toward it during the flight. If we wanted to control its strength depending on the distance between it and the chaser objects, we'd have to use expressions. We don't need that level of complexity here but it's worth knowing.

Ideally we'd like to pull harder on the chaser_close object, to get it closer to the target. One way to do this would be to use two linked attractors -- one for each chaser object. We'll use just one here and instead make the friction on each chaser object different. Leave the internal force at 5 for now. We'll alter it in the testing stage.

Now add a drag daemon and set the drag strength to 10. We are adding this daemon to help control the inertial overshoot of the chaser objects. Without drag, there tends to be a lot of overshoot that would not make for good camera motion -- unless the cameraman had a few too many drinks over lunch. In fact we could get away without this daemon in this scene by just using the air friction settings on each object separately, but it's handy to be able to control the global drag with it.

5. Setup Export Central and Scene Tree

In Export Central, enable saving of dynamics results. In the Scene Tree, add the attractor and drag daemons to both the chaser objects.

We're almost ready to run the simulation, but if you run it now you'll see that nothing happens except for the keyframe animation of the moving target. In addition, nothing is setup to be saved from the simulation.

Go to Export Central and enable the saving of dynamics calculations. This means that a file called dynamics.sd will be saved, containing the position, scale and rotation information for all objects controlled by dynamics -- back in your 3D platform, you would direct the Next Limit dynamics importer plugin to this file to bring the dynamics results into your scene.

On the timeline, you'll see a tiny yellow square appear at both ends, and the label of the Export Central button will go yellow. These are both visual cues that dynamics data is now set to be saved.

Next, open the scene tree. We have to tell RF3 which objects and daemons affect each other. In our case, we just want the two daemons to act on the two chaser objects, so don't hit the Add All button. Instead, select both the daemons in the right window, and drag them to each of the chaser objects in the right window.

In this particular scene, in fact, it would not have mattered if we hit Add All. This is because dynamics is turned off for everything except the chaser objects. Nevertheless it's good practice to apply the daemons to just what you need, since in many scenes you work on you could end up causing daemons to get applied differently than you need. If we had decided to use two separate attractors, one for each chaser object, this is where we would tell RF3 which attractor affected which object.

6. Run tests and tweak values

Run some tests and experiment with values for the attractor and drag strengths and sizes, the mass of the chaser objects, and the air friction.

We will now start running test simulations to get our parameter values sorted out.

First, try running the simulation with the current values. You'll see that it runs very quickly, because the physics involves no fluids and no collisions.

You should see the target fly around the "city" on its path, and the chaser objects will barely move. This is a result of too weak an attraction, and too great a mass for the chasers.

Increase the attractor internal force to 200 and run again, and you'll see the chaser objects move a lot more but still they are moving far too sluggishly. Up the value to 10,000 and the objects will follow more closely, but now they overshoot by huge amounts where the target turns sharply, and they get left behind when it accelerates. Obviously, they have too much inertia.

To improve the situation, we'll reduce their mass and alter the air friction each feels.

First, reduce the attraction internal strength to 1000 -- it's always better to stick to values that aren't too huge, to avoid numerical instability.

Go to the objects tab and select chaser_close. You'll see in the Dynamics subpanel that the mass is set at about 130 kg. On import, this gets automatically assigned based on the volume of the object and an assumed density. If you wanted to set a mass that corresponded to a specific density, RF3 can tell you the volume using the Measure utility: Select the object, then go to Tools>Measure utility.

In this scene we just want a lower mass so set the value for chaser_close to something much smaller. Try 5. We want it smaller than for chaser_far because it should follow the target quite closely, despite quick turns and accelerations.

Run the simulation again, and you'll see that the chaser_close follows quite closely now, although it still overshoots in a number of places.

Another important parameter is the air friction -- this is just like a drag daemon built into every object. We'll use it for added control.

Run further tests, varying the air friction on the chaser_close object. We decided that a mass of 2 and an air friction left at the default 0.001 gave reasonable results, where the chaser_close object followed quite closely, but still displayed interial effects consistent with what you might expect as the focus point for a handheld camera.

Run similar tests for the chaser_far object. Remember that this represents the camera position. In reality, back in our 3D package we'd probably mix the resulting position sequences with other motion tracks. For example, adding height to the camera so it would move above the "city" and not go straight through buildings. From that perspective, the dynamics for the camera movement becomes a useful component for layering into a final animatin, that would be tough to keyframe well because it involves accounting for the effects of weight. With this process in mind, you can experiment and find settings for the chaser_far's mass and air friction that has it follow the target more-or-less, keeping a reasonable distance and smooth motion. We settled on a mass of 20 and an air friction of 0.05, to give a camera motion that followed smoothly but not too closely.

That concludes this tutorial -- we now have dynamics-derived motion for our camera and it's point of focus.

Tips

- The methods covered in this tutorial could also be used to generate the motion tracks of solid objects chasing the target, but in that case you would want to allow collisions with the objects making up the "city". You can easily try this out for the current scene by going to the objects tab, selecting all the other objects in the scene, then turning Dynamics to Yes, Primitive to Mesh, and making sure that Collision is set to Yes. Set Collision to Yes for the chaser objects too. When you run the simulation, you might want to go to the options panel and set the time step to Fixed, rather than Adaptive -- this makes for far faster, but slightly less accurate, simulations when using rigid body dynamics. You'll see that the chaser objects now smack into and bounce off the other objects. If you increased the number of chasing objects, you could easily and quickly produce complex swarming motions.

- The same methods could be improved for a chase scene with another spaceship. In that case, you'd want the chasing ship to keep oriented during the motion. You could do this by mounting an attractor on the ships nose, and a negative strength attractor (repulsor) on its tail, and then make these affect just the target. You could do something similar by using objects attached with fix constraints to various points on the ship, with different attractors linked to the target to control the relative orientation of the chasing ship. Other attractors could be used above the scene to affect the roll of the ship. In effect, you would be creating a physics-based animation rig to drive the spaceship. This kind of setup has the potential to produce animation tracks with a great deal of physicality, since the distribution of weight would get taken into account by the simulation and that is the most challenging part of keyframing by hand. Similar techniques could be applied to many other simulations, such as the motion of a robot arm or an entire animated character. A highly simplified version of this will be explored in the next tutorial (billiards).