With rigid body dynamics, it is often necessary to slightly change physical properties of an object. Good examples are random differences in mass or elasticity. Though the variations are sometimes very subtle it is a good idea to think about this possibility, because it adds some extra realism to a simulation. Changing the properties for a few dozens or even hundreds of nodes is not a fun job. Doing it once is already a hassle, but what if you have to present several simulations with different values? Here a script is the only solution!
Name | ChangeRBDMass.rfs |
---|---|
Type | Batch script |
Description | This program automatically activates the rigid body property for a custom selection of nodes and randomly changes the "@ mass" parameter. |
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
import random percentVariation = 10 range = (currentMass / 100) * (percentVariation / 2) randomValue = random.uniform(-range, range) newMass = currentMass + randomValue |
Info |
---|
Please note that the operation above might fail for very small mass settings! |
The last action is to print out a little message together with the time the script needed for applying the new mass value. Since this little program is a batch script it is not possible to use RealFlow’s simulation time. The scene.getCurrentTime()
statements has no effect here, but fortunately Python provides a module called “time”. This module comes with Python’s standard distribution and should be installed by default. To access the specific clock()
function a new notation is required:
...
Here you can see a different notation for the "import" command. If you would like to learn more about advanced techniques to load modules, we suggest that you do some research online. The clock()
function from this module simply measures and stores the current time during function call. Keeping this in mind it is easy to create a time difference:
...