RealFlow 10 Tutorial: Pencils Dynamic Simulation

Hello and welcome to the “Falling Pencils” tutorial for RealFlow. In this project we are going to create a simulation with 60 pencils falling down and interacting with a ground object. The pencils have been modelled in a 3D program and will be imported to RealFlow a little later. For now start with a new project. Add a gravity daemon and a cube. Make the cube big enough to catch all pencils, and change the colour if you want. Then define the cube as a “Passive rigid body”, because it should not move. Increase “Object friction” to slow down the pencils… … and increase “Elasticity” for stronger bounces. Now we can import the pencils from an Alembic or SD file. Select the imported objects and make them “Active rigid bodies”. We also group the objects with a right-click and rename the group to “Pencils”. When you take a look at the “Node Params” panel you will see that all pencils have exactly the same mass. And this is going to be changed with a Python script, where the “Mass” parameters will be randomized. To do this, open a “Batch Script” editor from the “Layout” menu. First of all we have to import Python’s random number generator. Then, we get the “Pencils“ group from the scene… …and in the next step, we read out the nodes from this group. We also want to apply a new standard mass (“stdMass”) – here it’s going to be 10. And we want to create a variation of the standard mass (“varMass”) within, let’s say 4 percent. These two values will be the base for a new, randomized mass. Now we introduce a loop to access the group’s nodes, and within this loop we calculate a new “Mass” value for each pencil. It’s very important that you always mind the indents after a colon, because without them you will get syntax errors… …andd believe me: missing indents are the most common source of errors in Python scripts. Alright. “rnd Mass” will be used as the basis for the randomization. And, “add Mass” is the actual random number, based on the value we’ve just defined in the previous line. ”addMass“ can be positive or negative and will be added to the “stdMass”. Finally, this “newMass” value will be applied to every single pencil in the group. To do that, transfer the parameter’s name to the script and put it into quotation marks, because it’s a string. Before we run the script, it’s a good idea to check the syntax. Here, everything’s Ok and we can hit ”Run“. After the execution of the script every pencil has a different mass between 9.6 and 10.4. That’s exactly the 4 percent variation. And now we can also proceed to randomize “Object friction” and “Elasticity”. The principle is exactly the same. Just define the new base values for the two parameters and their variations in percent… …then go to the loop and calculate the parameters, based on the default settings from the beginning of the script and the random values. And then assemble the final values. In the last step you define the parameters you want to change and their new values, and don’t forget to use quotation marks for the strings. What we have now is a fully randomized setup and the script can be reused again and again in different projects. Of course we also want to render the result inside RealFlow, and therefore a texture map will be applied. Select the group nodes and load a predefined texture. RealFlow uses existing UVs for the mapping, and this way you can also create wet-dry maps, for example. But, for some reason only the first object has been textured, and the rest remains white. Instead of adding each texture manually, we simply create another script. The start is the same as before: read out the “Pencils” group and its nodes. …and treat every pencil individually with the help of a loop. We have a colon here, so don’t forget to create an indent. And now copy the path from the “Load Texture” parameter to the script’s “setParameter” statement. That’s all! We can check and run the script and watch how the pencils are being textured. For the final render it’s also possible to change some basic material properties like reflectivity. And here I also want to activate a predefined perspective by dragging a camera to the viewport. Before we simulate we open the project’s “Simulation Options“ next to the “Simulate“ button. And since we have a pure rigid body simulation, all substeps can be set to 1, and 25 is enough for the rigid body solver’s “Quality“. These two simple changes will make the simulation roughly 5 times faster. And finally set “Jittering” to 25 to keep a slight amount of motion. When you’re ready: simulate. And here is an OpenGL preview to see the motion in realtime. If necessary, adjust the preview range. Ok, let’s the render the whole thing. To get an idea of the lighting setup we render out a test frame with the Maxwell “FIRE” engine. Choose any frame from the simulation… …then hit the “FIRE” button. “FIRE” lets you change lighting and perspective interactively. To change lights, open the “Maxwell Preferences” and make your settings. To see the effect, click on “Apply“. Maxwell will start a new render immediately and once you’re happy confirm with “OK“. In this project randomized parameters helped us to achieve a more realistic behaviour. But instead of addressing every node manually, we’ve used a script and completed this task within a few seconds. And this is exactly what scripting is about, because in most cases you will be writing short tools like that to accelerate your workflow. As always thanks for watching and Happy Simulating with RealFlow. Goodbye!

One comment

  • mae

    Fuckkkkkkkkk.. I FUKN hate scripting. and my favorite software is turning into one..

    why?????. hahahaha. but I guess this is much easier rather than just trying to do it one by one.. this looks fun to try and learn.



Leave a Reply

Your email address will not be published. Required fields are marked *