Saturday, August 13, 2016

Rigid Body Objects and Simulations in Maya

The study of motion simulation in Maya for special effects has been an extremely fascinating one. I appreciate that the simulations in Maya work in a similar manner to what I’ve worked with in Houdini in the past.The project I approached this week was similar to the rudimentary Marble Machine simulation featured in the blog post below.The majority of the scene was created by other artists and was very basic. The object was to get the entire machine to create a chain reaction of some sort from beginning to end.

In simulations, you have to primary functions you can add to each individual piece of geometry, and you assign them depending on what you want that object to do.
An Active Rigid Body can be assigned to a piece of geometry that you want to move and to be affected by the world in which it exists. In the simulation you will view below, all of the objects you see move were Active Rigid Bodies.
All of the objects which come into contact with, and have effect upon the Active Rigid Body objects, are Passive Rigid Body objects. These are objects that we want to interact with, but do not require movement or any extreme dynamics. These objects are not controlled by forces such as gravity, which we will talk about later. Passive Rigid Body objects primarily exist to interact with our items in motion while remaining absolutely motionless. Though a Passive Rigid Body does not move, it is not entirely without its own dynamics. The surface of the object still maintains dynamic attributes that can be changed, such as friction and bounciness. So while our focus in the creation of this machine is primarily on the Active Rigid Body objects, the attention to the settings on the Passive objects will end up being just as important to the final product.

An object which has neither of these (not Active, nor Passive) will not interact with the Active and Passive items at all. Instead, when an Active Rigid Body object hits a piece of geometry that has no dynamic effect attributes applied to it, they will simply pass through one another like ghosts, with no effect.

If you are having trouble understanding this, simply view the video at the bottom of this post.
The hammer, which you will see swinging is an Active Rigid Body object, as is the marble and the cog. But the surface the marble rolls on and the other static objects which interact with our active objects are Static Rigid Body objects.

Now when we create either of these objects and simply push play on the timeline, which begins the simulation, you will see that absolutely nothing happens. That is because we have not applied any fields to these objects. By selecting the object, such as the active rigid body object which you want to move, and then applying a Gravity field, you can cause the object to move when you click play on the timeline. It is now affected by gravity and begins to fall. Gravity will only affect the objects which it has been assigned to. So you can apply a Gravity field to a marble, and have a completely different Gravity field applied to the Dominoes right next to it. That gravity field holds it's own attributes. Most namely, the Magnitude attribute, which controls the strength of the gravity field applied to the object. Multiple objects can also share the same gravity field by connecting them in the Dynamic Relationship Editor that the lovely people at Autodesk have been so wonderful as to create for us.

Before I get into explaining more about the fields that can be applied to objects, I'll explain how constraints work.

Without Constraints, our objects would simply fall or fly through space. Constraints allow us to do very cool things, and they are featured all throughout the scene below. Nearly every Active Rigid Body object in the scene has a constraint applied to it.
There are Barrier constraints, Hinge Constraints, Point Constraints, Pin Constraints, Nail Constraints, and Spring Constraints.
On the Hammer, you will see that it swings as though it is hanging from something. It is hanging from a Hinge Constraint which is set up like a nail going through the handle of the hammer. The cog that the ball hits gives the illusion that it is sitting in the small peg of geometry in the center of the cog, but it's actually not attached to anything other than a constraint. It is another hinge constraint with a pivot point that has been placed directly in the center of the cog, so that the cog can rotate freely around it. There is also a hinge constraint on the large rotating object at the end of the dominoes. On the Mallet which swings upward and knocks over the cup that contains the marbles, there is a Rigid Pin Constraint. The Pin Constraint works almost like a lightbulb hanging from a string, and it must be created between two different objects. I primarily only used these two constraints throughout the scene, with the exception of the Spring Constraint which causes the plate that launches the ball near the end of the scene to spring upward so sharply. That plate contains both a Spring Constraint and a Hinge Constraint.

Another force used in this scene, in addition to Gravity, is a Uniform Field. A Uniform Field essentially will pull certain assigned objects in a specific desired direction. I was having trouble getting the three marbles that roll out of the cup to roll into the next required area, so I applied a Uniform Field, and keyframed it so that it turns on when the marbles would have begun to slow down, and turns off once it gets the marbles close enough to where they need to go.
This same effect could have been accomplished with a Volume Field, however, due to the fact that this scene was created in Maya 2014 and I am currently using Maya 2016, there is a discrepancy that will not allow me to use that type of field in this scene.

Simulations take up a lot of computing power, and therefore everything becomes quite slow if you do not bake the animation of your objects intermittently throughout your progress.
When I would finish a complex scene and find an area in which I wanted to lead off, I would select the objects I had simulated and I would bake them. Baking an object is basically telling the computer to record the motion that is taking place in the live simulation, and it records the motion by setting keyframes on every frame. Sometimes, this must be done once or twice to get the perfect result, as every simulation is different every time since it is computing in real time. Once the bake has taken place and the simulation has been recorded through keyframes as animation, the constraints, the forcefields, and the rigid bodies can be deleted. This speeds up our progress quite a lot.

Using these methods and functions, I was able to complete the entirety of the marble scene and add my own style to it.
I decided to take each object into Substance Painter and apply textures. They are high quality textures, yet my render was not set to a high enough quality to perfectly capture them, so you will see some issues throughout the final render depending on the distance of the camera from the objects.

To create two strings in the scene, I created a tube object and constrained the end of each tube to the thing I wanted the string to be attached to. I then simulated a piece of string with nCloth, and the animation drove the movement of the simulated string. The animation of the strings were baked out just the same way that the rigid body objects were baked.

Overall, I was able to create this great and dynamic scene by using a variety of the incredible function that Maya offers for simulations. It was a great process and a good learning experience.