Chapter 13
Dynamic Effects

The nCloth system in the Autodesk® Maya® software was originally designed to make dynamic cloth simulation for characters easier to create and animate. The Nucleus dynamics solver, which you learned about in Chapter 12, “Introducing nParticles,” is at the heart of nCloth simulations. (The n in nCloth stands for “nucleus.”) nCloth has evolved into a dynamic system that goes well beyond simply simulating clothing. Creative use of nCloth in combination with nParticles yields nearly limitless possibilities for interesting effects, as you’ll see when you go through the exercises in this chapter.

You’ll delve deeper into Maya dynamics to understand how the various dynamic systems, such as nCloth, nParticles, and rigid bodies, can be used together to create spectacular effects. You’ll also use particle expressions to control the motion of particle instances.

In this chapter, you will learn to

  • Use nCloth
  • Combine nCloth and nParticles
  • Use nParticles to drive instanced geometry
  • Create nParticle expressions
  • Create a soft body simulation with Bullet

Creating nCloth Objects

Typically, nCloth is used to make polygon geometry behave like clothing, but nCloth can be used to simulate the behavior of a wide variety of materials. Everything from concrete to water balloons can be achieved by adjusting the attributes of the nCloth object. nCloth uses the same dynamic system as nParticles and applies it to the vertices of a piece of geometry. An nCloth object is simply a polygon object that has had its vertices converted to nParticles. A system of virtual springs connects the nParticles and helps maintain the shape of nCloth objects. nCloth objects automatically collide with other nDynamic systems (such as nParticles and nRigids) that are connected to the same Nucleus solver, and an nCloth object collides with itself.

In this section, you’ll see how to get up and running fast with nCloth using the presets that ship with Maya as well as get some background on how the Nucleus solver works. The examples in this chapter illustrate a few of the ways that nCloth and nParticles can be used together to create interesting effects. These examples are only the beginning; there are so many possible applications and uses for nCloth that a single chapter barely scratches the surface. The goal of this chapter is to give you a starting place so that you feel comfortable designing your own unique effects. Chapter 14, “Hair and Clothing,” demonstrates techniques for using nCloth to make clothing for an animated character.

Making a Polygon Mesh Dynamic

Any polygon mesh that you model in Maya can be converted into a dynamic nCloth object (also known as an nDynamic object); there’s nothing special about the way that the polygon object needs to be prepared. The only restriction is that only polygon objects can be used. NURBS and subdivision surfaces can’t be converted to nCloth.

certificate_objective

There are essentially two types of nCloth objects: active and passive. Active nCloth objects are the ones that behave like cloth. They are the soft, squishy, or bouncy objects. Passive nCloth objects are solid pieces of geometry that react with active objects. For example, to simulate a tablecloth sliding off a table, the tablecloth would be the active nCloth object, and the table would be the passive nCloth object. The table prevents the tablecloth from falling in space. You can animate a passive object, and the active object will react to the animation. Thus you can keyframe the table tilting, and the tablecloth will slide off the table based on its dynamic settings.

The first exercise in this chapter shows you how to create the effect of a dividing cell using two nCloth objects:

  1. Open cellDivide_v01.ma from the chapter13scenes folder at the book’s web page (www.sybex.com/go/masteringmaya2016). The scene contains two polygon hemispheres.
  2. Switch to the FX menu set. Select both objects, and choose nCloth ➣ Create nCloth. In the Outliner, you’ll see that two nCloth nodes have been added.
  3. Switch to Wireframe mode, and select nCloth1. One of the cell halves turns purple, indicating that the nCloth node is an input connection to that particular piece of geometry.
  4. Rename the nCloth1 and nCloth2 nodes cellLeftCloth and cellRightCloth, according to which piece of geometry they are connected to (see Figure 13.1).
  5. Set the timeline to 400 frames, and play the scene. You’ll see that both pieces of geometry fall in space. This is because Gravity is turned on by default in the Nucleus solver. When you create an nCloth object or any nCloth dynamic system (nParticles, nRigids), several additional nodes are created and connected. You can see this when you graph the cellLeftShape node on the Hypergraph, as shown in Figure 13.2.

    Each nCloth object consists of the original geometry, the nCloth node, and the Nucleus solver. By default, any additional nDynamic objects you create are attached to the same Nucleus solver. Additional nodes include the original cellLeftShape node, which is connected as the inputMesh to the cellLeftClothShape node. This determines the original starting shape of the nCloth object.

  6. Select the cellLeftCloth node, and open the Attribute Editor.
  7. Switch to the cellLeftClothShape tab, as shown in Figure 13.3. This node was originally named nCloth1.

    The tabs found in the Attribute Editor include the following:

    cellLeftCloth  This tab contains the settings for the nCloth1 transform node. Most of the time you won’t have a reason to change these settings.

    cellLeftClothShape  This tab contains the settings that control the dynamics of the nCloth object. There are a lot of settings on this tab, and this is where you will spend most of your time adjusting the settings for this particular nCloth object.

    nucleus1  This tab contains all of the global settings for the Nucleus solver. These include the overall solver quality settings but also the Gravity and Air Density settings. If you select the cellRightCloth node in the Outliner, you’ll notice that it also has a nucleus1 tab. In fact, this is the same node as attached to the cellLeftCloth object.

    It’s possible to create different Nucleus solvers for different nDynamic objects, but unless the nDynamic objects are connected to the same Nucleus solver, they will not directly interact.

  8. Choose the cellLeftClothShape tab. Under the Dynamic Properties section, change Input Motion Drag to 1.0.

    Input Motion Drag controls how much the nCloth object follows its input mesh. Increasing it to 1.0 causes the simulated motion of the nCloth hemisphere to be blended with its stationary input mesh. By default, the input mesh or, in this case, the cellLeftShape node, is set to Intermediate Object under its Object Display settings. You can toggle its visibility by unchecking Intermediate Object or by choosing nCloth ➣ Display Input Mesh.

  9. Choose the cellRightClothShape tab. Change its Input Motion Drag to 1.0 as well.

    When you rewind and play the scene, the cells slowly descend under the influence of gravity and their input meshes.

images

Figure 13.1 Add two nCloth nodes to the Outliner, one for each side of the cell, and rename them cellLeftCloth and cellRightCloth.

images

Figure 13.2 The input and output connections for the cellLeftShape node are graphed on the Hypergraph.

images

Figure 13.3 The Attribute Editor for the cellLeftClothShape node has tabs for the transform and shape nodes as well as the nucleus1 solver.

Applying nCloth Presets

The concept behind this particular example is that both halves of the cell together form a single circular spherical shape. To make the cells separate, you’ll adjust the nDynamic settings so that each half of the cell inflates and pushes against the other half, moving them in opposite directions. Creating the correct settings to achieve this action can be daunting simply because there is a bewildering array of available settings on each nCloth shape node. To help you get started, Maya includes a number of presets that can act as templates. You can apply a preset to the nCloth objects and then adjust a few settings until you get the effect that you want.

  1. Continue with the scene from the previous section.
  2. Select the cellLeftCloth node, and open the Attribute Editor to the cellLeftClothShape node.
  3. At the top of the editor, click and hold the Presets button in the upper right. The asterisk by the button label means that there are saved presets available for use.
  4. From the list of presets, scroll down to find the waterBalloon preset. A small pop-up appears; from this pop-up, choose Replace (see Figure 13.4). You’ll see the settings in the Attribute Editor change, indicating the preset has been loaded.
  5. Repeat steps 2 through 4 for the cellRightCloth node.
  6. Rewind and play the animation. Immediately, you have a decent cell division.
images

Figure 13.4 Using a preset selected from the Presets list is a quick way to start a custom nCloth material.

The next task is to create a more realistic behavior by adjusting the setting on the nCloth objects:

  1. Switch to the nucleus1 tab, and set Air Density to 35 (see Figure 13.5). This makes the cells look like they are in a thick medium, such as water.
  2. You can blend settings from other presets together to create your own unique look. Select cellLeftCloth and, in its shape node tab, click and hold the Presets button in the upper right.
  3. Choose Honey ➣ Blend 10%. Do the same for the cellRightCloth.
  4. Play the animation. The two cells separate more slowly.
  5. You can save these settings as your own preset so that it will be available in other Maya sessions. From the Presets menu, choose Save nCloth Preset. In the dialog box, name the preset cell.
  6. Save the scene as cellDivide_v02.ma.
images

Figure 13.5 Increasing the Air Density setting on the nucleus1 tab makes it appear as though the cells are in a thick medium.

Making Surfaces Sticky

At this point, you can start to adjust some of the settings on the nCloth tabs to create a more interesting effect. To make the cells stick together as they divide, you can increase the Stickiness attribute:

  1. Continue with the scene from the previous section, or open the cellDivide_v02.ma scene from the chapter13scenes folder at the book’s web page.
  2. Select the cellLeftCloth node, and open the Attribute Editor to its shape node tab.
  3. Expand the Collisions rollout, and set Stickiness to 1 (see Figure 13.6). Do the same for the cellRight object.

    Notice that many of the settings in the Collision rollout are the same as the nParticle Collision settings. For a more detailed discussion of how nucleus collisions work, consult Chapter 12.

  4. Play the animation; the cells remain stuck as they inflate. By adjusting the strength of the Stickiness attribute, you can tune the effect so that the cells eventually come apart. Shift+click both the cellLeftCloth and cellRightCloth nodes in the Outliner. Open the Channel Box and, with both nodes selected, set Stickiness to 0.4.
  5. We will manually move the right cell away from the left cell to get them to separate. To do so, it is best to turn off the Nucleus solver to prevent it from solving. Select nucleus1, and open its Attribute Editor.
  6. Deselect Enable, effectively stopping the cells from being simulated.
  7. Select cellRight and keyframe its position at frame 10 for its translation and rotation.
  8. Move to frame 100 on the timeline, and change the following attributes:
    • Translate Y: 7.0
    • Translate Z: –8.0
    • Rotate X: –50

      You will not see the geometry move unless you display the cell’s input mesh.

  9. Return to frame 1, and enable the Nucleus solver. Play the simulation to see the results (see Figure 13.7).
  10. Save the nCloth settings as stickyCell. Save the scene as cellDivide_v03.ma.
images

Figure 13.6 Increase the Stickiness attribute in the cellLeftClothShape tab of the Attribute Editor.

images

Figure 13.7 The stickiness tries to keep the cells together as they move away from one another.

Creating nConstraints

nConstraints can be used to attach nCloth objects together. The constraints themselves can be broken depending on how much force is applied. In this example, nConstraints will be used as an alternative technique to the Stickiness attribute. There are some unique properties of nConstraints that can allow for more creativity in this effect.

  1. Open the cellDivide_v03.ma scene from the chapter13scenes folder at the book’s web page.
  2. Switch to the side view. In the Outliner, Shift+click the cellLeft and cellRight polygon nodes. Set the selection mode to Component. The vertices on both objects will appear.
  3. Drag a selection down the middle of the two objects so that the vertices along the center line are selected (see Figure 13.8).
  4. In the FX menu set, choose nConstraint ➣ Component To Component. Doing so creates a series of springs that connect the two objects.
  5. Rewind and play the scene. The two sides of the cell are stuck together.
  6. In the Outliner, a new node named dynamicConstraint1 has been created. Select this node, and open the Attribute Editor.

    A wide variety of settings are available in the Attribute Editor for the dynamicConstraint node; each one is described in detail in the Maya documentation. For the moment, your main concern is adjusting the constraint strength.

  7. Strength determines the overall impact or effect that the constraint has on the objects it is constraining. Tangent Strength creates a resistance to the tangential motion of the constraint. In this example, you can leave Strength at 20 and set Tangent Strength to 0.
  8. Glue Strength is the setting that determines whether the constraint will break when force is applied. It is calculated in world space based on the size of the objects. A value of 1 means that the constraint can’t be broken; a value of 0 turns the constraint off altogether. Set this attribute to 0.25.
  9. Glue Strength Scale modifies the Glue Strength based on the world space distance between the constraints. Set this value to 0.6.
  10. Rewind and play the animation. The two sides of the cell start to separate but fail to part completely.

    The Force attribute determines the level of attraction between the constraints. Positive values cause the constraints to repel each other after they break; negative values cause the constraints to attract each other. In this scene, very small values can create a big difference.

  11. Set the Force attribute on the dynamic constraint node to 0.01. Rewind and play the scene.
  12. The cells now push each other apart and keep going. To halt their motion after separation, adjust the Dropoff Distance value. Set this to 3.
  13. Adjust the Strength Dropoff curve so that there is a sharp decline to 0 on the right side of the curve. The strength of the force drops to 0 as the distance between the constraints approaches 3 units (see Figure 13.9).
  14. You can fine-tune the effect by adding a small amount of motion drag. Set Motion Drag to 0.01. If the cells can’t quite separate, try raising Force by small increments until you get a result you like.
images

Figure 13.8 Create nConstraints between the vertices along the flattened side of each cell.

images

Figure 13.9 Add a small value to the Force attribute, and lower the Dropoff Distance to a value of 3. By adjusting the Strength Dropoff ramp, you can fine-tune the effect.

Working with nDynamics becomes an experimental process much like cooking; you adjust the sliders and season to taste until the effect looks like what you want. Since many of the attributes are interconnected, it’s best to adjust one at a time and test as you go. You can move an nCloth object after it has been constrained. However, the results of the simulation might not behave the way you’d expect. It’s best to make sure that your nCloth objects and their constraints are positioned where you want them. Avoid setting keyframes on the translation or rotation of the nCloth object.

Rest Length attributes significantly affect how the simulation behaves. Rest length refers to the length of each constraint when no tension is applied. (Imagine an unattached spring sitting on a table; its length at rest is its rest length.) If Rest Length Method is set to From Start Distance, then the rest length of each constraint is equal to its length at the first frame of the animation. If this option is set to Constant, the rest length is determined using the Rest Length numeric input.

Rest Length Scale applies a scaling factor to the constraints. If this is set to 1 and Rest Length Method is set to From Start Distance, then the constraints have no initial tension. In other words, at frame 1, the scale is equal to the rest length. Lowering this value increases the tension on the constraint and makes it harder to break.

  1. Rewind the animation, and set Rest Length Scale to 0.5.
  2. Play the animation to frame 40, and set a keyframe on Rest Length Scale.
  3. Play the animation to 50, and set Rest Length Scale to 1.
  4. Set another keyframe. Rewind and play the animation. This is one way in which you can control the timing of the cell division. You can also control this attribute using an expression or Set Driven Key. The cells may not separate completely at this point—that’s okay, because in the next section, you’ll add pressure to complete the division effect.
  5. Save the scene as cellDivide_v04.ma.

To see a version of the scene up to this point, open the cellDivide_v04.ma scene from the chapter13scenes folder at the book’s web page.

Making nCloth Objects Expand Using Pressure

Using pressure, you can inflate a piece of geometry like a balloon or, in the case of this example, make it appear as though the geometry is filled with fluid.

There are two ways to calculate pressure:

Manual Pressure Setting  Found under the Pressure section of the nCloth’s shape tab, Manual Pressure Setting is simple—the Pressure slider and Pressure Damping slider are the only two controls (see Figure 13.10). These can be keyframed to make it appear as though the nCloth object is being filled with air. If you set Pressure to 0 and create a keyframe and then play the animation to frame 100, set Pressure to 1, and set another keyframe, the nCloth object will grow in size over those frames as if it were being inflated.

images

Figure 13.10 Manual Pressure Setting has simple controls for adding internal pressure to nCloth objects.

Volume Tracking Model  Volume Tracking Model, which is used by the waterBalloon preset originally applied to the cell geometry, is a more accurate method for calculating volume and has more controls (see Figure 13.11).

images

Figure 13.11 Volume Tracking Model has more controls and produces a more accurate internal pressure simulation for nCloth objects.

When Volume Tracking Model is selected as the pressure method, you have access to additional controls, such as Pump Rate, Air Tightness, and Incompressibility. The Pump Rate value determines the rate at which air is added within the volume. Positive values continue to pump air into the volume; negative values suck the air out. The Start Pressure value sets the initial pressure of the air inside the volume at the start of the animation.

The Air Tightness value determines the permeability of the nCloth object. Lower settings allow the air to escape the volume. The Incompressibility setting refers to the air within the volume. A lower value means that the air is more compressible, which slows down the inflation effect of the cell. Activating Seal Holes causes the solver to ignore openings in the geometry.

As you may have noticed, after the cells divide in the example scene, they don’t quite return to the size of the original dividing cell. You can use the Pump Rate attribute to inflate the cells:

  1. Continue with the scene from the previous section, or open the cellDivide_v04.ma scene from the chapter13scenes folder at the book’s web page.
  2. Select the cellRightCloth shape, and open its Attribute Editor.
  3. Expand the Pressure settings. Note that Pressure Method is already set to Volume Tracking Model. These settings were determined by the waterBalloon preset originally used to create the effect.
  4. Set Pump Rate to 50 for each cell, and play the animation (see Figure 13.12). Each cell starts to grow immediately and continues to grow after the cell divides.
  5. Try setting keyframes on the start Pump Rate of both cells so that at frame 15 Pump Rate is 0, at frame 50 it’s 50, and at frame 100 it’s 0.
  6. To give an additional kick at the start of the animation, set Start Pressure to 0.25.
images

Figure 13.12 Setting Pump Rate to 50 on the cellRightCloth object causes it to grow as it separates from the right side.

Additional Techniques

To finish the animation, here are additional techniques that you can use to add some style to the behavior of the cells:

  1. In the Collisions rollout, increase the Stickiness attribute of each cell to a value of 0.5. You can also try painting a Stickiness texture map. To do so, select the cells and choose nCloth ➣ Paint Texture Properties ➣ Stickiness. This activates the Artisan Brush, which allows you to paint specific areas of stickiness on the cell surface. (Refer to Chapter 12 to see how a similar technique is used to paint the strength of a force field on geometry.)
  2. If you want the objects to start out solid and become soft at a certain point in time, set keyframes on each cell’s Input Mesh Attract attribute, found in the Dynamic Properties section of the nCloth’s shape tab. The input mesh is the original geometry that was converted into the nCloth object. Setting the Input Mesh Attract attribute to 1 or higher causes the nCloth objects to assume the shape of the original geometry. As this value is lowered, the influence of the nucleus dynamics increases, causing the objects to become soft.

To see a finished version of the scene, open the cellDivide_v05.ma scene from the chapter13scenes folder at the book’s web page.

Creating an nCache

At this point, you’ll want to cache the dynamics so that playback speed is improved and the motion of the cells is the same every time you play the animation. Doing so also ensures that when you render the scene, the dynamics are consistent when using multiple processors.

  1. Shift+click the cellLeft and cellRight objects in the Outliner.
  2. Choose nCache ➣ Create New Cache ➣ nObject ➣ Options.

    In the options, you can specify where the cache will be placed. By default, the cache is created in a subfolder of the current project’s Data folder. If the scene is going to be rendered on a network, make sure that the cache is in a subfolder that can be accessed by all of the computers on the network.

    In the options, you can specify whether you want to create a separate cache file for each frame or a single cache file. You can also create a separate cache for each geometry object; this is not always necessary when you have more than one nCloth object in a scene (see Figure 13.13). However, caching objects individually is preferred when dealing with complex simulations. Having individual caches enables you to make isolated adjustments.

  3. The default settings should work well for this scene. Click the Create button to create the cache. Maya will play through the scene.

    After the nCache has been created, it is important that you disable the nCloth objects so that Maya does not calculate dynamics for objects that are cached. This is especially important for large scenes with complex nDynamics.

  4. In the Attribute Editor for cellLeftClothShape, scroll to the top and uncheck the Enable box to disable the nCloth calculation. Do the same for cellRightClothShape.
  5. You can select the cellLeft and cellRight objects and move them so that they overlap at the center at the start of the scene. This removes the seam in the middle and makes it look as though there is a single object dividing into two copies.
  6. You can also select the cellLeft and cellRight objects and smooth them using Mesh ➣ Smooth from the Modeling Menu Set, or you can simply select the nCloth object and activate Smooth Mesh Preview by pressing the 3 key on the keyboard.
images

Figure 13.13 The options for creating an nCache

Creating nCloth and nParticle Interactions

Creating dynamic interaction between nParticles and nCloth objects is quite easy because both systems can share the same Nucleus solver. Effects that were extremely difficult to create in previous versions of Maya are now simple to create, thanks to the collision properties of nDynamics. Before continuing with this section, review Chapter 12 so that you understand the basics of working with nParticles.

In this section, you’ll see how you can use nParticles to affect the behavior of nCloth objects. nCloth objects can be used to attract nParticles, nParticles can fill nCloth objects and cause them to tear open, and many interesting effects can be created by using nParticles and nCloth objects together.

Creating an nParticle Goal

Goal objects attract nParticles like a magnet. A goal can be a locator, a piece of geometry (including nCloth), or even another nParticle. In Chapter 12, you worked with force fields, which are similar to goals in some respects in that they attract nParticles dynamically. Deciding whether you need to use a goal or a force field generated by an nDynamic object (or a combination of the two) depends on the effect that you want to create and usually involves some experimentation. This section will demonstrate some uses of goal objects with some simple examples.

  1. Create a new, empty scene in Maya.
  2. Create a locator (Create ➣ Locator).
  3. Switch to the FX menu set, and choose nParticles ➣ Create Options ➣ Balls to set the nParticle style to Balls.
  4. Choose nParticles ➣ Create Emitter. By default, an omni emitter is created at the center of the scene.
  5. Use the Move tool to position the emitter away from the locator (set Translate X, Y, and Z to 20).
  6. Set the length of the timeline to 300.
  7. Play the animation. Balls are emitted and fall through space because of the Gravity settings on the nucleus node.
  8. Select the nParticle object, and Ctrl/Command+click locator1. Choose nParticles ➣ Goal ➣ Options.
  9. In the options, set Goal Weight to 1 (see Figure 13.14).
  10. Rewind and play the scene.

    The nParticles appear on the locator and bunch up over time. Since Goal Weight is set to 1, the goal is at maximum strength and the nParticles move so quickly between the emitter and the goal object that they cannot be seen until they land on the goal. Since the Balls-style nParticles have Collision on by default, they stack up as they land on the goal.

  11. Select the nParticle object. In the Channel Box, set Goal Weight to 0.25. Play the animation. You can see the nParticles drawn toward the locator. They move past the goal and then move back toward it, where they bunch up and start to collide, creating a swarm (see Figure 13.15).
  12. Create a second locator. Position locator2 10 units above locator1.
  13. Select the nParticle and Ctrl/Command+click locator2. Make it a goal with a weight of 0.25 as well.
  14. Play the scene. The nParticles swarm between the two goals.
  15. Select one of the locators, and choose Fields/Solvers ➣ Interactive Playback. You can move the locator in the scene while it’s playing and watch the nParticles follow. They are always drawn to the midpoint between the two goals (see Figure 13.16).
  16. Open the Attribute Editor for the nParticle, and switch to the nParticleShape1 tab. Try lowering the Conserve value on the nParticles, under the Dynamic Properties section. This causes the nParticles to lose energy as they fly through the scene.
  17. Try these settings:
    • Conserve: 0.98
    • Drag: 0.05
    • Wind Speed on the Nucleus tab: 8
    • Wind Noise: 25

      You can edit these settings in the Attribute Editor or in the Channel Box for the nParticleShape1 node. Suddenly, a swarm of particles buzzes between the goal. By animating the position of the goals, you control where the swarm goes.

  18. Enter the following settings:
    • Point Force Field on the nParticleShape node (under Force Field Generation): World Space
    • Self Attract: –10
    • Point Field Distance: 10

      Now the motion of the nParticles is controlled by the goals, gravity, wind, wind noise, and a force field generated by the nParticles themselves. You can quickly create complex behavior without the need for a single expression (see Figure 13.17).

images

Figure 13.14 Convert the locator into a goal for the nParticles.

images

Figure 13.15 Lower the Goal Weight for the nParticle in the Channel Box, causing the nParticles to swarm around the locator.

images

Figure 13.16 Using Interactive Playback, you can move the goals around and watch the nParticles follow.

images

Figure 13.17 Combining goals, forces, dynamic attributes, and wind noise creates some complex nParticle behaviors.

To see an example version of this scene, open the swarm.ma file from the chapter13scenes folder at the book’s web page. To see another example of the use of goals, open the nClothGoal.ma scene from the same location.

Controlling Collision Events

certificate_objective

Using the Collision Event Editor, you can specify what happens when a collision between an nParticle and a goal object occurs.

  1. Open the nClothGoal.ma scene from the chapter13scenes folder.
  2. Select the nParticle, and choose nParticles ➣ Particle Collision Event Editor.
  3. In the Editor window, select the nParticle. Leave the All Collisions check box selected.
  4. Set Event Type to Emit.
  5. Enter the following settings:
    • Num Particles: 5
    • Spread: 0.5
    • Inherit Velocity: 0.5

      Select the Original Particle Dies option. Click Create Event to create the event (see Figure 13.18).

      Note that the collision event will create a new nParticle object.

  6. Rewind and play the scene.

    It may be difficult to distinguish the new nParticles that are created by the collision event from the original colliding nParticles. To fix this, continue with these steps:

  7. Select nParticle2 in the Outliner, and open its Attribute Editor.
  8. In the Particle Size rollout, set Radius to 0.05.
  9. In the Shading rollout, set Color Ramp to a solid yellow.
  10. Rewind and play the scene.
images

Figure 13.18 The Collision Event Editor allows you to create an event wherever the nParticle collides with a surface.

Each time an nParticle hits the nCloth object, it dies and emits three new nParticles. The nParticle2 node in the Outliner controls the behavior of and settings for the new nParticles. To see an example of this scene, open the collisionEvents.ma scene from the chapter13scenes folder at the book’s web page.

Bursting an Object Open Using Tearable nConstraints

This short example demonstrates how to create a bursting surface using nParticles and an nCloth surface:

  1. In a new Maya scene, create a polygon cube at the center of the grid. The cube should have one subdivision in width, height, and depth.
  2. Scale the cube up 8 units in each axis.
  3. Select the cube, switch to the Modeling menu set, and choose Mesh ➣ Smooth.
  4. In the Channel Box, select the polySmoothFace1 node and set Divisions to 3.
  5. Select the cube, and switch to the FX menu set.
  6. Choose nCloth ➣ Create nCloth to make the object an nCloth.
  7. Open the Attribute Editor for the nCloth object, and use the Presets menu to apply the rubberSheet preset to the nCloth object.
  8. Switch to the nucleus1 tab, and set Gravity to 0.
  9. Choose nParticles ➣ Create Options ➣ Balls to set the nParticle style to Balls.
  10. Choose nParticles ➣ Create Emitter to create a new emitter. By default, the emitter is placed at the origin inside the nCloth object.
  11. Select the nParticles; in the Attribute Editor for the nParticleShape1 tab, expand the Particle Size rollout and set Radius to 0.5.
  12. Set the length of the timeline to 800.
  13. Rewind and play the animation. The nParticles start to fill up the surface, causing it to expand (see Figure 13.19). If some nParticles are passing through the surface, switch to the Nucleus solver and raise the Substeps value to 8.
  14. Create a new shader, and apply it to the nCloth object.
  15. Set the transparency of the shader to a light gray so that you can see the nParticles inside the nCloth object.
  16. Select the pCube1 object in the Outliner.
  17. Choose nConstraint ➣ Tearable Surface. This applies a new nConstraint to the surface.
  18. If you play the scene, you’ll see the surface burst open (see Figure 13.20). Open the Attribute Editor for the nDynamic constraint. Set Glue Strength to 0.3 and Glue Strength Scale to 0.8; this will make the nConstraint more difficult to tear, so the bursting will not occur until around frame 500.
images

Figure 13.19 Placing the emitter inside the nCloth object causes it to fill with nParticles.

images

Figure 13.20 Adding a Tearable Surface nConstraint allows the surface to rip when a certain amount of force is applied.

To see two examples of Tearable Surface nConstraints, open burst.ma and burst2.ma from the chapter13scenes folder at the book’s web page.

Crumbling Tower

nCloth objects can also be made into rigid objects. The advantage of doing this is that it allows you to make the nCloth objects semi-rigid. In addition, the setup can be easier. Maya 2013 added the ability to simulate polygon shells—combined geometry made into a single node—as if they were separate objects. The next project takes you through the steps.

  1. Open the tower_v01.ma scene in the chapter13scenes folder.
  2. Select a few well-chosen bricks from the tower and delete them (see Figure 13.21).
  3. Select the tower node, and choose Mesh ➣ Combine from the Modeling menu set.
  4. Delete the history, and rename the combined node back to tower.
  5. Switch to the FX menu set, and choose nCloth ➣ Create nCloth.
  6. Open nCloth1’s Attribute Editor.
  7. Under Dynamic Properties, set Rigidity to 10.0 and check Use Polygon Shells (see Figure 13.22).
  8. Under the Collisions section, change Self Collision Flag to VertexEdge.
  9. Select ground.
  10. Choose nCloth ➣ Create Passive Collider.
  11. Play the simulation, and watch the tower crumble (see Figure 13.23).
images

Figure 13.21 Delete from the tower several bricks that will cause it to fall.

images

Figure 13.22 Turn on Use Polygon Shells.

images

Figure 13.23 The tower crumbles.

Try modifying the attributes to get the individual bricks to lose their shape as well. Hint: Use a low Deform Resistance value instead of Rigidity, and set Restitution Angle to 0.0.

Soft Body Dynamics

certificate_objective

certificate_objective

Soft body dynamics in Maya 2016 now use the nucleus engine to drive their simulation. Soft bodies assign nParticles to each vertex of a polygon or NURBS object. Normal dynamic fields, such as air and gravity, can influence the nParticles as well as rigid bodies. When influenced, the nParticles cause the vertices to follow, deforming the geometry.

There are two options for creating a soft body object. The first method is to make the geometry soft, which simply adds particles to every vertex. This allows the geometry to deform freely, never returning to its original shape. The second option is to make a duplicate, with one of the objects becoming a goal for the other. This method allows the geometry to return to its original shape. Using a goal is useful for creating objects that jiggle, like fat or gelatin.

Use the following steps to create and adjust a soft body object:

  1. Select a polygon or NURBS object.
  2. Choose nParticles ➣ Soft Body ➣ Options.
  3. Set the Creation Options to Duplicate, Make Copy Soft, and select Make Non-Soft A Goal. Click Create.

With the soft body selected, you can add any field to influence the particles. Moving the original object will cause the soft body to follow. You can adjust the Goal Smoothness and Goal Weight values on the particle node to alter the soft body’s behavior.

Creating Flying Debris Using nParticle Instancing

nParticle instancing attaches one or more specified pieces of geometry to a particle system. The instanced geometry then inherits the motion and much of the behavior of the particle system. For this example, you’ll instance debris and shrapnel to a particle system and add it to the current explosion animation. In addition, you’ll control how the instance geometry behaves through expressions and fields.

The goal for the exercises in this section is to add bits of flying debris to the explosion that behave realistically. This means that you’ll want debris of various sizes flying at different speeds and rotating as the particles move through the air. The first step is to add an nParticle system to the scene that behaves like debris flying through the air.

Adding nParticles to the Scene

The first step in creating the explosion effect is to add nParticles to the scene and make sure that they are interacting with the ground and the bricks of the tower. It’s a good idea to be efficient in your approach to doing this so that Maya is not bogged down in unnecessary calculations. To begin, you’ll add a volume emitter at the center of the tower.

  1. Open the rigidBodyTower_v02.ma scene from the chapter13scenes folder. In this scene, the rigid body simulation has been baked into keyframes.
  2. Switch to the FX menu set, and choose nParticles ➣ Create nParticles ➣ Balls, to set the nParticle style to Balls.
  3. Choose nParticles ➣ Create Emitter ➣ Options.
  4. In the options, set Emitter Type to Volume and Rate to 800.
  5. In the Distance/Direction Attributes rollout, set Direction X and Direction Z to 0 and Direction Y to 1 so that the nParticles initially move upward.
  6. In the Volume Emitter Attributes rollout, set Volume Shape to Cylinder.
  7. In the Volume Speed Attributes rollout, enter the following settings:
    • Away From Axis: 1
    • Along Axis: 0.5
    • Random Direction: 1
    • Directional Speed: 4
  8. Click Create to create the emitter (see Figure 13.24).
  9. Switch to Wireframe mode. Select emitter1 in the Outliner, and use the Move and Scale tools to position the emitter at the center of the stone tower.
  10. Set Translate Y to 3.1 and all three Scale channels to 2.
  11. Rewind and play the animation.

    The nParticles start pouring out of the emitter. They pass through the bricks and the ground.

  12. Select the ground, and choose nCloth ➣ Create Passive Collider.
  13. Shift+click the bricks in the passive group, and convert them to passive colliders; do the same for the bricks in the active group.

    The nParticles still pass through the static bricks at the back of the tower. You can convert the static bricks to passive colliders; however, this adds a large number of new nRigid nodes to the scene, which may slow down the performance of the scene. You can conserve some of the energy Maya spends on collision detection by creating a single, simple collider object to interact with the nParticles that hit the back of the tower. This object can be hidden in the render.

  14. Switch to the Modeling menu set, and choose Create ➣ Polygon Primitives ➣ Cylinder.
  15. Select the nParticle1 node and, in the Attribute Editor for the shape nodes, set Enable to Off to disable the calculations of the nParticle temporarily while you create the collision object.
  16. Set the timeline to frame 100 so that you can easily see the opening in the exploded tower.
  17. Set the scale and position of the cylinder so that it blocks the nParticles from passing through the back of the tower. Set the following:
    • Translate Y: 2.639
    • Scale X and Scale Z: 2.34
    • Scale Y: 3.5
  18. Select the cylinder, and switch to Face Selection mode; delete the faces on the top and bottom of the cylinder and in the opening of the exploded tower (see Figure 13.25).
  19. Rename the cylinder collider. Switch to the FX menu set, and choose nCloth ➣ Create Passive Collider.
  20. Select the nParticles, and turn Enable back on.
  21. Rewind and play the animation; the nParticles now spill out of the front of the tower once it breaks open (see Figure 13.26).
  22. Save the scene as explodingTower_v01.ma.

    To see a version of the scene up to this point, open the explodingTower_v01.ma scene from the chapter13scenes folder at the book’s web page.

images

Figure 13.24 The options for the volume emitter

images

Figure 13.25 Delete the faces on the top and bottom of the cylinder, as well as the faces near the opening of the exploded tower.

images

Figure 13.26 With the collision surface in place, the nParticles pour out of the opening in the front of the stone tower.

Sending the Debris Flying Using a Field

So far, the effects look like a popcorn popper gone bad. To make it look as though the nParticles are expelled from the source of the explosion, you can connect the radial field to the nParticle.

  1. Continue with the scene from the previous section, or open explodingTower_v01.ma from the chapter13scenes folder at the book’s web page. Select nParticle1, and rename it particleDebris.
  2. Open the Attribute Editor for particleDebris. Switch to the nucleus1 tab.
  3. In the Time Attributes rollout, set Start Frame to 20 so that the emission of the nParticles is in sync with the exploding brick.

    It’s not necessary to have the debris continually spewing from the tower. You need only a certain number of nParticles. You can either set keyframes on the emitter’s rate or set a limit to the number of nParticles created by the emitter. The latter method is easier to do and to edit later.

  4. In the Attribute Editor for particleDebrisShape, expand the Emission Attributes rollout. Max Count is set to –1 by default, meaning that the emitter can produce an infinite number of nParticles. Set this value to 1200 (see Figure 13.27).
  5. After the number of nParticles reaches 1200, the emitter stops creating new nParticles. Select the emitter, and set the rate to 2400. This means that the emitter will create 1,200 nParticles in half a second, making the explosion faster and more realistic.
  6. You can connect the particleDebris node to the existing radial field that was used to push out the bricks. To connect the radial field to the particleDebris node, select the particle-Debris node and Ctrl/Command+click radialField1 in the Outliner. Choose Fields/Solvers ➣ Assign To Selected.
  7. Rewind and play the animation. Not all of the nParticles make it out of the tower; many of the nParticles are pushed down on the ground and toward the back of the collider object. To fix this, reposition the radial field.
  8. Set the Translate X of the field to 1.347 and the Translate Y to 0.364 (see Figure 13.28).
  9. Save the scene as explodingTower_v02.ma.
images

Figure 13.27 Set Max Count to 1200, limiting the number of nParticles created by the emitter.

images

Figure 13.28 Once you reposition the radial field, the nParticles are sent flying out of the tower.

To see a version of the scene up to this point, open the explodingTower_v02.ma scene from the chapter13scenes folder at the book’s web page.

Creating a More Convincing Explosion by Adjusting nParticle Mass

Next, to create a more convincing behavior for the nParticles, you can randomize the mass. This means that there will be random variation in how the nParticles move through the air as the radial field launches them.

  1. Select the particleDebris node in the Outliner, and open its shape node in the Attribute Editor.
  2. Under the Dynamic Properties rollout, you can leave Mass at a value of 1. In the Mass Scale settings, set Mass Scale Input to Randomized ID. This randomizes the mass of each nParticle using its ID number as a seed value to generate the random value.
  3. If you play the animation, the mass does not seem all that random. To create a range of values, add a point to the Mass Scale ramp on the right side, and bring it down to a value of 0.1.

    When Mass Scale Input is set to Randomized ID, you can alter the range of variation by adjusting the Input Max slider. If you think of the Mass Scale ramp as representing possible random ranges, lowering Input Max shrinks the available number of random values to the randomize function, thus forcing the randomizer to have more “contrast” between values. Increasing Input Max makes more data points available to the randomize function, making a smoother variation between random values and producing less contrast (see Figure 13.29).

  4. Set the Input Max slider to 0.5.

    The Input Max slider is part of the Mass Scale Input options. The slider is an additional randomization value that is multiplied against the initial mass value. You can further set the Mass Scale Input to read the speed, age, or acceleration of the particle. Or you can use the slider to add some random variation to the mass. You don’t need to use this slider if the Mass Scale input is set to Randomized ID, and sometimes it can result in creating random values so close to 0 that the nParticles end up getting stuck in the air.

  5. Create a playblast of the scene so that you can see how the simulation is working so far.

    The nParticles are sliding along the ground in a strange way. To make them stop, you can increase the stickiness and friction of the ground.

  6. Select the ground geometry, and open its Attribute Editor.
  7. Switch to the nRigidShape1 tab. Under the Collisions rollout, set Stickiness to 1 and Friction to 0.2.
  8. Save the scene as explodingTower_v03.ma.
images

Figure 13.29 Mass Scale sets a range for the mass for each nParticle. The Input Max value is used to add contrast to the values generated by the ramp.

To see a version of the scene, open explodingTower_v03.ma from the chapter13scenes folder at the book’s web page.

Instancing Geometry

The debris is currently in the shape of round balls, which is not very realistic. To create the effect of flying shrapnel, you’ll need to instance some premade geometry to each nParticle. This means that a copy of each piece of geometry will follow the motion of each nParticle.

  1. Continue using the scene from the previous section, or open the explodingTower_v03.ma scene from the chapter13scenes folder.
  2. The debris is contained in a separate file, which will be imported into the scene. Choose File ➣ Import, and select the debris.ma scene from the chapter13scenes folder at the book’s web page.

    The debris scene is simply a group of seven polygon objects in the shape of shards.

  3. Expand the debris:debris group in the Outliner, Shift+click all of the members of the group, and choose nParticles ➣ Instancer ➣ Options.

    In the Options window, all of the debris objects are listed in the order in which they were selected in the Outliner. Notice that each one has a number to the left in the list. This number is the index value of the instance. The numbering starts with 0.

  4. In the Particle Object To Instance drop-down menu, choose the particleDebrisShape object. This sets the instance to the correct nDynamic object (see Figure 13.30).
  5. Leave the rest of the settings at their defaults, and choose Create to instance the nParticles. In the Outliner, a new node named instance1 has been created.
  6. Play the scene. Switch to Wireframe mode, and zoom in closely to the nParticles so that you can see what’s going on.
  7. Save the scene as explodingTower_v04.ma.
images

Figure 13.30 The selected objects appear in the Instanced Objects list. Select the particleDebrisShape node in the Particle Object To Instance options.

To see a version of the scene up to this point, open the explodingTower_v04.ma scene from the chapter13scenes folder at the book’s web page.

When playing the scene, you’ll notice that each nParticle has the same piece of geometry instanced to it, and they are all oriented the same way (see Figure 13.31). To randomize which objects are instanced to the nParticles and their size and orientation, you’ll need to create some expressions. In the next section, you’ll learn how to assign the different objects in the imported debris group randomly to each nParticle as well as how to make them rotate as they fly through the air. You will also learn how to use each nParticle’s mass to determine the size of the instanced geometry. All of this leads to a much more realistic-looking explosion.

images

Figure 13.31 Each nParticle has the same piece of geometry instanced to it.

Animating Instances Using nParticle Expressions

nParticles allow you to create more interesting particle effects than in previous versions of Maya without relying on expressions. However, in some situations, expressions are still required to achieve a believable effect. If you’ve never used particle expressions, they can be a little intimidating at first, and the workflow is not entirely intuitive. Once you understand how to create expressions, you can unleash an amazing level of creative potential; combine them with the power of the Nucleus solver, and there’s almost no effect that you can’t create. Expressions work the same way for both nParticles and traditional Maya particles.

Randomizing Instance Index

The first expression that you’ll create will randomize which instance is copied to which nParticle. To do this, you’ll need to create a custom attribute. This custom attribute will assign a random value between 0 and 6 for each nParticle, and this value will be used to determine the index number of the instance copied to that particular particle.

  1. Select the particleDebris node in the Outliner, and open its Attribute Editor to the particleDebrisShape tab.
  2. Scroll down and expand the Add Dynamic Attributes rollout.
  3. Click the General button; a pop-up dialog box appears (see Figure 13.32). This dialog box offers you options to determine what type of attribute will be added to the particle shape.
  4. In the Long Name field, type debrisIndex. This is the name of the attribute that will be added to the nParticle.
  5. Set Data Type to Float. A float is a single numeric value that can have a decimal. Numbers like 3, 18.7, and –0.314 are examples of floats.
  6. Set Attribute Type to Per Particle (Array).
  7. Click OK to add the attribute.
images

Figure 13.32 The General button in the Add Dynamic Attributes section allows you to create your own custom attributes.

Now that you have an attribute, you need to create the expression to determine its value:

  1. Expand the Per Particle (Array) Attributes rollout, and you’ll see Debris Index listed.
  2. Right-click the field next to Debris Index, and choose Creation Expression (see Figure 13.33).

    The Expression Editor opens, and debrisIndex is selected in the Attributes list. Notice that the Particle mode is automatically set to Creation.

  3. In the Expression field, type debrisIndex=rand(0,6); (see Figure 13.34). Remember that the list of instanced objects contains seven objects, but the index list starts with 0 and goes to 6.

    This adds a random function that assigns a number between 0 and 6 to the debrisIndex attribute of each nParticle. The semicolon at the end of the expression is typical scripting syntax and acts like a period at the end of a sentence.

  4. Click the Create button to create the expression.
  5. Rewind and play the animation.

    Nothing has changed at this point—the same piece of debris is assigned to all of the nParticles. This is because, even though you have a custom attribute with a random value, you haven’t told Maya how to apply the attribute to the particle.

  6. Expand the Instancer (Geometry Replacement) rollout in the Attribute Editor of particleDebrisShape.
  7. In the General Options section, expand the Object Index menu and choose debrisIndex from the list (see Figure 13.35).

    Now when you rewind and play the animation, you’ll see a different piece of geometry assigned to each nParticle.

  8. Save the scene as explodingTower_v05.ma.
images

Figure 13.33 The new Debris Index attribute appears in the Per Particle (Array) Attributes list. To create an expression, right-click and choose Creation Expression.

images

Figure 13.34 Add an expression to randomize the value of the debrisIndex attribute for each nParticle.

images

Figure 13.35 Assign the new debrisIndex attribute as the input for the Object Index attribute in the Instancer section of the nParticle’s Attribute Editor.

To see a version of the scene up to this point, open the explodingTower_v05.ma scene from the chapter13scenes folder at the book’s web page.

Connecting Instance Size to nParticle Mass

Next you’ll create an expression that determines the size of each nParticle based on its mass. Small pieces of debris that have a low mass will float down through the air. Larger pieces that have a higher mass will be shot through the air with greater force. The size of instances is determined by their Scale X, Scale Y, and Scale Z attributes, much like a typical piece of geometry that you work with when modeling in Maya. This is different from a Balls-type nParticle that uses a single radius value to determine its size.

The size attributes for instanced geometry are contained in a vector. A vector is an attribute with a three-dimensional value, as opposed to an integer or a float, which has only a single-dimensional value.

  1. Select the particleDebris object and, in the shape node’s Attribute Editor, under Add Dynamic Attributes, click the General button to create a new attribute.
  2. Set the Long Name value to debrisScale.
  3. Set Data Type to Vector and Attribute Type to Per Particle (Array), and click OK to create the attribute (see Figure 13.36).
  4. In the Per Particle (Array) Attributes section, right-click the field next to debrisScale, and choose Creation Expression.

    In the Expression field of the Expression Editor, you’ll see the debrisIndex expression. Note that the name debrisIndex has been expanded; it now says particleDebrisShape.debrisIndex=rand(0,6);. Maya does this automatically when you create the expression.

  5. Below the debrisIndex expression, type debrisScale=<<mass,mass,mass>>;. Click Edit to add this to the expression (see Figure 13.37).

    The double brackets are the syntax used when specifying vector values. Using mass as the input value for each dimension of the vector ensures that the pieces of debris are uniformly scaled.

  6. In the Instancer (Geometry Replacement) attributes of the particleDebris object, set the Scale menu to debrisScale (see Figure 13.38).
  7. Rewind and play the animation.
images

Figure 13.36 Create another attribute, and name it debrisScale; this time set Data Type to Vector.

images

Figure 13.37 Set the debris-Scale attribute to be equivalent to the mass of each nParticle. Add the expression in the Expression Editor.

images

Figure 13.38 The size of the debris is determined by the mass of each nParticle. In some cases, the mass is so small that the instanced geometry can’t be seen.

The pieces of debris are now sized based on the mass of the nParticles, but of course the mass of some of the particles is so small that the instanced particles are invisible. To fix this, you can edit the expression, as follows:

  1. In the Per-Particle (Array) Attributes section, right-click debrisScale and choose Creation Expression to open the Expression Editor.
  2. In the Expression field, add the following text above the debris scale expression:

    float $massScale = mass*3;
  3. Now edit the original debrisScale expression, as shown in Figure 13.39, so that it reads as follows:

    debrisScale = <<$massScale, $massScale, $massScale>>;

    By using the float command in the Expression Editor, you’re creating a local variable that is available to be used only in the creation expressions used by the nParticle. This variable is local, meaning that since it was created in the Creation expression box, it’s available only for creation expressions. If you use this variable in a runtime expression, Maya gives you an error message. The variable is preceded by a dollar sign. The $massScale variable is assigned the mass multiplied by 3.

  4. Click Edit to implement the changes to the expression.
  5. Rewind and play the animation.

    It’s an improvement; some debris pieces are definitely much bigger, but some are still too small. You can fix this by adding a clamp function. clamp sets an upper and lower limit to the values generated by the expression. The syntax is clamp(lower limit, upper limit, input);. Make sure that you click the Edit button in the editor after typing the expression.

  6. Edit the expression for the massScale variable so that it reads float $massScale=clamp(1,5,mass*5);. Again, make sure that you click the Edit button in the editor after typing the expression.
  7. Play the animation.

    Now you have a reasonable range of sizes for the debris, and they are all based on the mass on the particles (see Figure 13.40).

    certificate_objective

  8. In the Attribute Editor for the particleDebris, scroll to the Shading section and set Particle Render Type to Points so that you can see the instanced geometry more easily.
  9. Save the scene as explodingTower_v06.ma.
images

Figure 13.39 Edit the expression so that the size of each nParticle is equal to the mass multiplied by 3.

images

Figure 13.40 After you add the clamp expression, the range of size for the debris is more reasonable.

To see a version of the scene, open the explodingTower_v06.ma scene from the chapter13scenes folder at the book’s web page.

Controlling the Rotation of nParticles

Rotation attributes are calculated per particle and can be used to control the rotation of geometry instanced to the nParticles. In addition, the Rotation Friction and Rotation Damp attributes can be used to fine-tune the quality of the rotation. In this exercise, you’ll add rotation to the debris:

  1. Continue with the scene from the previous section, or open the explodingTower_v06.ma scene from the chapter13scenes folder at the book’s web page.
  2. Select the particleDebris node in the Outliner, and open its Attribute Editor to the particleDebrisShape tab.
  3. Expand the Rotation rollout, and turn on Compute Rotation (see Figure 13.41). This automatically adds a new attribute to the Per Particle Array Attributes list. However, you won’t need to create any expressions in order to make the nParticle rotate.
  4. Scroll down to the Instancer (Geometry Replacement) settings. In the Rotation Options, set the Rotation menu to rotationPP.
  5. Create a playblast of the scene.
  6. You may notice that some of the debris rotates a bit too quickly as it falls to Earth. To adjust this, scroll up to the Rotation section, and set Rotation Damp to 0.01. Try making another playblast.
  7. Save the scene as explodingTower_v07.ma.
images

Figure 13.41 Turn on Compute Rotation in order to add per-particle rotation attributes to the nParticles.

Rotation Friction and Rotation Damp are per-particle attributes, which can be used in per-particle expressions to drive other attributes:

Rotation Friction  This attribute determines how likely an nParticle will rotate based on its collision with other nDynamic objects and self-collisions (inter-particle collisions within the same nParticle shape). Setting Rotation Friction to 0 turns off rotation.

Rotation Damp  This attribute causes the rotation of nParticles to slow down after collisions with other nDynamic objects and self-collisions.

To see a version of the scene, open the explodingTower_v07.ma scene from the chapter13scenes folder at the book’s web page.

Bullet Physics

Bullet physics is based on the open source Bullet Physics Library. Bullet is a plug-in to Maya and is available only for 64-bit versions. Using Bullet, you can create realistic dynamic simulations on a large scale. Bullet supports rigid bodies, rigid body constraints, and soft bodies. In addition, you can create rigid body kinematics or ragdoll effects. The following exercise takes you through the process of creating a rigid body simulation:

  1. Load the Bullet plug-in. Choose Windows ➣ Settings/Preferences ➣ Plug-in Manager. Find bullet.mll (bullet.bundle on the Mac), and select Loaded and Auto Load.
  2. Open the wreckingBall_v01.ma scene from the chapter13scenes folder at the book’s web page.
  3. Select the wreckingBall node in the Outliner.
  4. Choose Bullet ➣ Active Rigid Body. A collision box is placed around the wrecking ball (see Figure 13.42). This is a new shape node called bulletRigidBodyShape1.
  5. Open the Attribute Editor for bulletRigidBodyShape1. The wrecking ball’s rigid body properties are controlled through this node. Expand the Collider Properties rollout. Set the Collider Shape Type to Sphere, as Figure 13.43 shows.
  6. Click Play to watch the simulation. The wrecking ball falls into infinite space. To get the ball to swing, you will first need to add a constraint. With the wrecking ball selected, choose Bullet ➣ Rigid Body Constraint.
  7. All of the rigid body constraints share the same attributes. Open the Attribute Editor for bulletRigidBodyConstraint1. At the top of the editor is the Constraint Type option. You can change this setting at any point when constructing your simulation. Leave Constraint Type set to Point.
  8. Translate the constraint to 9.0 units in the Translate Y. The manipulator will move, but the actual constraint does not update until the simulation is refreshed. Click Play to refresh the simulation. The wrecking ball no longer falls.
  9. To give the wrecking ball motion, you need to add some velocity. Open the wrecking ball’s Attribute Editor. Choose the bulletRigidBodyShape1 tab.
  10. Under the Initial Conditions rollout, set the Initial Velocity to –20.0.
  11. The wrecking ball now spins around its constraint during the simulation. Let’s give it something to hit. Select all of the cubes in the scene. Make sure that you are selecting the actual nodes and not the group node to which they are parented.
  12. With all 252 blocks selected, choose Bullet ➣ Active Rigid Body. Click Play to watch the simulation (see Figure 13.44).
  13. The simulation is working, but it’s not as explosive as we would like. The blocks fall through space just like the wrecking ball prior to adding its constraint. You do not want to restrict the blocks’ movement with a constraint. Instead, you want to add a floor. Choose Bullet ➣ Select Bullet Solver.
  14. Under the bulletSolverShape1 tab in the Attribute Editor, select Ground Plane from the Solver Properties rollout.
  15. Watch the simulation again. The cubes rest on the artificial ground plane. The wrecking ball, however, barely makes a dent. Select the wrecking ball and open the Rigid Body Properties in the Attribute Editor. Change Mass to 100. Click Play to see the results (see Figure 13.45).
  16. The wrecking ball moves too much. Below the Mass attribute change Linear Damping to 0.5. The motion is now less erratic.
  17. Although Linear Damping helped, the ball wobbles quite a bit. Choose Bullet ➣ Select Bullet Solver. Change Internal Fixed Frame Rate to 240Hz. This speeds up the simulation calculations, resulting in smoother motion.
  18. Save the scene as wreckingBall_v02.ma.
images

Figure 13.42 Create an active rigid body from the wrecking ball.

images

Figure 13.43 Change the collision box to match the shape of the wrecking ball.

images

Figure 13.44 The wrecking ball hits the falling blocks.

images

Figure 13.45 The increased mass makes a huge impact on the blocks.

To see a version of the scene, open the wreckingBall_v02.ma scene from the chapter13scenes folder at the book’s web page.

The Bottom Line

Use nCloth.  nCloth can be used to make polygon geometry behave dynamically to simulate a wide variety of materials. Using the presets that come with Maya, you can design your own materials and create your own presets for use in your animations.

Master It  Create the effect of a cube of gelatinous material rolling down the stairs.

Combine nCloth and nParticles.  Because nCloth and nParticles use the same dynamic systems, they can be combined easily to create amazing simulations.

Master It  Make a water balloon burst as it hits the ground.

Use nParticles to drive instanced geometry.  Modeled geometry can be instanced to nParticles to create a wide variety of effects.

Master It  Create the effect of a swarm of insects attacking a beach ball.

Create nParticle expressions.  nParticle expressions can be used to further extend the power of nParticles. Using expressions to automate instanced geometry simulations is just one of the ways in which expressions can be used.

Master It  Improve the animation of the insects attacking the beach ball by adding different types of insects to the swarm. Randomize their size, and create expressions so that larger insects move more slowly.

Create a soft body simulation with Bullet.  Bullet physics are fast and accurate. In addition to creating rigid body simulations, you can use Bullet to create clothlike effects with its soft bodies.

Master It  Drape a tablecloth over a table using soft body physics.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset