MB_dynamicaUI Notes
September 2010
michael@mBakr.com


DESCRIPTION

MB_dynamicaUI extends the default feature set of the Dynamica plugin for Autodesk Maya with tools designed for pre-shatter rigid body workflows. These tools are exposed as additional tabs - Build, Activate, Bake, and PolyCutter.


INSTALLATION

move or copy the file MB_dynamicaUI.mel into your Maya scripts directory (~username/maya/scripts (Linux) or drive:\Documents and Settings\username\My Documents\maya\scripts (Windows)). Invoke the UI by typing [ source "MB_dynamicaUI"; ] (without the square brackets) into the commandline input to launch the MB_dynamicaUI window.


TOOLS

- Build -
This will build dRigidBodies (dRBs) of the Hull or Mesh type from selection of mesh objects. The source meshes can exist anywhere in scene space with or without frozen transforms and centered pivots, but they must have conformed out-facing normals - otherwise the collision mesh will distort. When the Build process runs, each mesh is parented to a corresponding dRB of the same topology, but scaled by a user specified collision margin. This configuration allows for visually accurate collisions without popping or gaps. The default collision margin of -0.060 should produce accurate collisions for most geometry.

The original meshes and resulting dRBs are assigned to separate display layers named DynamicaMeshes and DynamicaRigidBodies respectively. The DynamicaMeshes layer display mode is set to Reference for easier selection of dRBs in the viewport. dRB objects and collision meshes are also grouped for easier scene management.

- Activate -

This toolset is used to control the timing of dRB activation. By default, a Dynamica Active Rigid Body responds to simulation forces starting on frame 1. The Activation tools can prevent this behavior and instead suspend the simulation of dRBs until a single specified frame (Single Frame mode), or across a range of frames during playback (Multi Frame mode).

Three Input Methods (Axis Gradient, Radial Gradient, and 3D Texture) are supported in Multi Frame mode to control the timing of dRB activation during the specified frame range. Additionally, enabling Compute Mass and specifying a density value can increase the realism of dRB interactions.

Applying dRB activation adds two attributes to each dRB - activeFrame and activeMass. An expression is also added to control the mass attribute of the dRB shape node. A mass of 0 effectively turns the dRB into a Passsive Rigid Body, while a non-zero value re-activates it. The expression sets the dRB mass to the value of activeMass when activeFrame is reached on the timeline. Setting activeFrame to 0 effectively disables activation. These attributes can also be edited via the Channel Box or Attribute Spread Sheet if fine adjustments are necessary.

Input Methods:

Axis Gradient -
Axis Gradient will progressively activate dRBs along a user specified axis (+X, -X, +Y, -Y, +Z, -Z) during the Start/End Frame range.

Radial Gradient -
Radial Gradient will progressively activate dRBs away from, or converging toward, a single focal point. A reference object in the scene serves as the focal point from which a spherical activation gradient is created. The Search Radius can be set via Numeric Input or automatically (based on the reference object's bounding box). dRBs within the Search Radius are activated outward by default, or inward if the Inverted option is checked. Actviation proceeds linearly during the Start/End Frame range. 

3D Texture -
3D Texture will progressively activate dRBs across the black to white (or 0 to 1) gradient defined by the specified 3D texture during the Start/End Frame range.

- Bake -
This will bake all or part of the simulation into keyframes within the user specified frame range, and optionally delete construction history and static channels. The process begins by copying the scene to a new file of the same name, but with _BAKED appended to the filename (i.e. dynamicaScene1.mb -> dynamicaScene1_BAKED.mb). A valid Project workspace must be active. Note: pre-existing _BAKED files can be optionally overwritten - this allows a scene to be baked in stages.

To save memory usage, Undo is temporarily disabled and only translation and rotation are stored as keyframes. It is also recommended that history and static channels be deleted during post processing. Maya RigidBody nodes are automatically deleted - these result from using fields to influence dRBs. Following recommended settings results in a clean efficient scene ready for the next phase of production.

- PolyCutter -
This utility will cut polygon meshes along intersecting NURBS surfaces. A typical workflow involves creating curves (Linear or Cubic) along desired fault lines, lofting the curves, and using PolyCutter to fracture single or multiple polygon meshes. This process can be combined with voronoi and other pre-shatter methods to control fragment size and alignment.


APPLICATION

The MB_dUI tools work well with pre-shattered mesh objects. Maya's built in shattering tools can be used for this, or one of the many shatter scripts available. Voronoi shatter is flexible and works well with Rigid Body hulls. Activation effects can be edited and combined to achieve complex Rigid Body simulations. A few examples:

- A Radial Gradient could be used to create crumbling from a local impact and a series of Axis Gradients could then be used to control secondary fracturing caused by the impact.

- 3D Texure activation can simulate the effects of random structural failure from fire or earthquake. Axis Gradients could be combined with this effect to control the timing and behavior of structural collapse.

- An Axis Gradient can create a vertically progressing fracture on a surface and then areas of the surface can be disabled to maintain structural integrity

dg_voroPy by Dave Greenwood works well and is available here: http://www.creativecrash.com/maya/downloads/scripts-plugins/c/dg_voro_py--2

Alternatively, as_polyFracture by Alin Sfetcu is available here: http://www.creativecrash.com/maya/downloads/scripts-plugins/c/as_polyfracture

* special thanks to user RBD on the Bullet forums for sharing tools and info.

MINI TUTORIAL

1) Start with a new scene in Maya. Create ten standard size polygon cubes (disable interactive creation if needed). Distribute them along the Z axis, a couple units apart. Move them up (+Y) off the grid about 10 units.

2) Launch the MB_dUI window by entering [ source "MB_dynamicaUI"; ] (without the square brackets). You can middle mouse drag this to a Shelf to create a shortcut.

3) Click on the Create tab. Under Passive Rigid Bodies, click Plane. A blue XZ plane named dRigidBody1 appears in the scene centered at the origin. This will serve as a ground collision surface. You can optionally hide this object to make selecting the other objects easier. Hiding it from view will NOT hide it from the simulation.

4) Select the ten cubes created on step 1.

5) Select the Build tab at the top of the MB_dUI window. leave the settings at their defaults and click the Build Simulation button at the bottom of the window.

If the viewport is in wireframe mode, you will see slightly smaller triangulated cubes inside the original polygon cubes. In the Outliner, two new groups have appeared - dRigidBodies and dCollisionMeshes. The dRigidBodies group holds the generated dRigidBody objects - which are parents to their original polygon cubes. In the dCollisionMeshes group you will find polygon objects that were generated from the Margin setting in the Build options - these are the surfaces from which the dRigidBodies were created.

You will also find two Display Layers - DynamicaMeshes and DynamicaRigidBodies. The DynamicaMeshes layer holds the original polygon cubes - it's display mode is set to Reference - to make selection of the dRigidBodies in the viewport easier. You can hide this layer to see only the dRigidBody objects. The DynamicaRigidBodies layer holds the dRigidBody objects - you can easily select them here via right-clicking and choosing Select All from the popup menu.

6) Set the playback range to 1 - 200 frames, set the playhead to frame 1, and click the Play button. The cubes fall a few units and visibly collide with the ground plane (whether or not it's hidden). The cubes may appear to be syncronized in their motion. Set the playhead back to frame 1 - the cubes snap back to their original locations. rotate each one in a slightly different orietation. Click the Play button. The cubes fall again, but this time they are no longer synchronized and tumble around in different directions before coming to rest.

7) Set the playhead to frame 1 and select the cubes. Click on the Activate tab at the top of the MB_dUI window. Note the default settings. Click the Activate Dynamica Rigid Bodies button at the bottom of the window.

8) Click the Play button. The cubes remain static until frame 24 and then fall to the ground plane. Look back at the MB_dUI window, the default Activate settings specify Single Frame activation of selected dRigidBodies starting on frame 24. This is why the cubes remained inactive until frame 24.

9) Set the playhead to frame 1 and select the cubes. In the MB_dUI window under the Activate tab, select Multi Frame for the Activation Method. New options appear below and the End Frame field is enabled. By default the Input Method is set to Axis Gradient. In the Axis Gradient Options choose -Z for Axis Direction and click the Activate Dynamica Rigid Bodies button at the bottom of the window. 

10) Click the Play button. The cubes remain static until frame 24 and then progressively fall, one after the other, along the +Z axis. Set the playhead to frame 1 and click the play button again - this time note that the cubes fall starting on frame 24 and ending on frame 48. This happens because the frame range specifed in the MB_dUI Activate options starts at 24 and ends at 48. Open the Channel Box. Select the cubes one at a time and note the value of the attribute named activeFrame.

11) Select one of the cubes and set it's activeFrame attribute to 0. Leave this object selected.

12) Set the playhead to frame 1 and click the Play button. Note the selected cube no longer falls. Setting activeFrame to 0 effectively disables activation.

11) Set the playhead to frame 1 and select the cubes. In the MB_dUI window under the Activate tab, select Single Frame for the Activation Method. 24.000 is visible in the Start Frame field - change this to 0 and click the Activate Dynamica Rigid Bodies button at the bottom of the window.

12) Click the play button. All the cubes remain static because their activeFrame attributes are all set to 0.

13) Set the playhead to frame 1. Create a NURBS sphere and name it, influence. Set the ScaleX, ScaleY, and ScaleZ to 5. Move it upwards along the +Y axis until it's center pivot is at the same height as the cubes.

14) Using the Outliner, expand the dRigidBodies group and select all the cubes, then Ctrl-select the influence object. In the MB_dUI window under the Activate tab, select Multi Frame for the Activation Method. Set the Start Frame to 10 and the End Frame to 50 and Radial Gradient for the Input Method. Under the Radial Gradient Options, selected Automatic for the Search Radius. Click the Activate Dynamica Rigid Bodies button at the bottom of the window.

15) Set the viewport to xray mode. Set the playhead to frame 1 and click the Play button. The cube closest to the center of the influence object activates around frame 10. The remaining cubes progressively activate from the center of the influence object outward. The cubes outside the influence object do not activate.

16) Set the playhead to frame 1 and select the unactivated cubes. In the MB_dUI window under the Activate tab, set the Start Frame to 30 and the End Frame to 60. Select Axis Gradient for the Input Method and choose +Z for Axis Direction and click the Activate Dynamica Rigid Bodies button at the bottom of the window. 

17) The cubes now fall according to two different activation methods during two different frame ranges. Axis Gradient during frames 30 - 60 and Radial Gradient during frames 10 - 50. This creates complex and interesting behavior.

For more advanced workflows and examples of using MB_dUI in production, visit:

mbakr.squarespace.com/articles/MB_dUI-advanced-workflow.html