Sunday, May 29, 2011

Tutorial: Restricting a Nonlinear deformation to a single axis

**( If you are already familiar with the Nonlinear deformers, you can just scroll down to the "Let's get started!" part. )

Many times when modeling, you may come across a situation that requires a complex shape to be created that would take quite a long time to do properly by hand, and even still not look very good. One such scenario is a screw, if you were to try and model all the threads by hand, this would take a very long time and still not look very good, most people wouldn't even know where to start. But, with the help of the Twist deformer for example, this task can be done within minutes by merely twisting an object that has every second edge pushed out further, and with enough divisions to support the twisting effect.

If you do not know about the deformers, they are located in Create Deformers>Nonlinear, which is a menu option when the menu is set to Animation. (By default your menu bar is set to Polygons)

Another scenario is bending pipes. A smooth bend that keeps proper volume can be time consuming to do by hand and still won't be 100% proper. But using the Bend deformer, you can easily bend the pipe smoothly to almost any angle and still retain it's volume in the bend.

These are only two examples, and there are a few other deformers and many other uses for them, especially when dealing with high poly objects that you need to smoothly change the shape of.

So lets get on to what this tutorial is about. The Flare deformer. This deformer has two circles at the bottom and top, which it interpolates a curve between, the amount this curve bends being defined by you. When applied to an object or vertices, it will squish or expand those vertices according to that curve. Which is very helpful for creating various cylindrical objects, such as vases, or for creating squash and stretch, as well a plethora of other uses for animation since the parameters can be keyed and the deformation tool can be translated, rotated and scaled to change the location or result of the effect on an object.

Flare deformer being used the typical way

Since the Flare deformer works in a cylindrical fashion, it's going to bend your object inward/outward all the way around it. So what can you do if you only want to get that nice smooth curve deformation happening from a single direction? Which is usually the case with objects that aren't cylindrical or when only wanting to deform a small portion of something.

Well, that's what this tutorial is going to be about.


Let's get started!

In this tutorial, we will approach the problem of smoothly deforming the lengthwise shape of a pipe. Which obviously would be part of a scenario where you are creating pipework that requires some braces, seals or caps that are custom made to fit certain things, such as a T joint.


Here is a picture that shows what the typical result would be like if you just went ahead and used the Flare deformer, along with the proper result we want, achieved using the method in this tutorial.

So now let's create the proper result.
1. 'Create>Polygon>Pipe'. Give it a good amount of divisions so it's a fairly smooth pipe, simulating a scenario where moving the points by hand isn't ideal. And give it the amount of thickness you'd like.

2. 'Create>Polygon>Plane'. Rotate it 90 degrees so it is aligned lengthwise with your pipe. 
Give it a higher amount of height divisions than your pipe has from a front view, and no other divisions. We want it to have it a lot so that our deformation is smooth.

3. Select the Pipe and then Shift+Select the Plane.
Go to 'Create Deformers > Wrap' on your menu bar (Set the menu to Animation to see the option). 
Make sure to set the Wrap options to "Exclusive Bind".
 Basically what 'Wrap' does, is it turns the second object into a lattice for your first object. So whenever you move points on the Plane for example, it will move points on the Pipe. And since we are using a Plane which is a 2D object as our lattice for the Pipe, the deformer will only be able to deform it length-wise and not width-wise since it has no width. This deformation will then be transferred to our Pipe

4. Select the side points of the Plane up to the point you want the curve deformation to start.
(Or you can select them all like I did here, and just change the start position of the deformer afterwards)

5. With the points selected, go to 'Create Deformers > Nonlinear > Flare'.
Rotate the newly created Flare tool to an appropriate position for the deformation direction we want.

6. Now in your Attribute Editor, which should be open on the right side of Maya, play with the values in the "flare" tab to get the deformation you want.

*The High & Low 'Bound' defines the distance of the top and bottom deformation circles in relation to the center. So if you lower them, anything outside of them won't be effected by the deformation. And if you raise them, you can create more gradual curves.
*The Start/End Flare values define the X/Z scale of the circles. So you can have an elliptical shape instead of a uniform cylinder.
*And the 'Curve' value of course defines how bent the curve is between the circles.


Now we have a custom pipe joint created which has retained it's volume and cylindrical shape. If we are done and know we will not need to make anymore modification to the deformer, we can simply go to 'Edit > Delete by Type > History', which will freeze the vertices into their new position and delete the deformer tool.


This technique can of course be applied to any of the other deformers also, to restrict an effect to one axis. And if you do not delete the history, you can keyframe the Flare values to create an animation of the pipe taking shape.


____________________________________________________________________________
Thank you for reading my tutorial. I hope you found it helpful in giving you new ideas on how to approach the modeling of various objects, and also for expanding your toolset. This was only one technique I developed for one set of problems. I recommend people to play around with the other deformers, figuring out for yourself different ways you can use them in the modeling and animation process. As they are quite useful.

Monday, May 23, 2011

Tutorial: Using Maya's hidden "Membrane" node to wrap or deform objects

Maya has many unofficial features that aren't publicly exposed within it, either because they are still in development, havn't had enough beta testing time, turned out to be too buggy, were superseded by better methods, or just havn't been implemented fully due to a case of priorities for the developers.
One of these features is the 'Membrane' dynamic deformer. Not many people know about this deformer, and I only found out about it from a post by someone else on CGSociety who discovered it when digging through Maya's API. It's apparently been sitting in Maya for a few years now, oddly not officially announced or GUI integrated even though it seems to be quite useful.

There are many possibilities this node can be used for, since it has gravity, wind/drag/lift, cloth, internal pressure, rigid body, collision and turbulance dynamics built into it, all based around the nCloth solver in Maya, sort of making it sit inbetween being a deformer and a simulation. Just a little fooling around and some imagination and you can create something interesting with it.

In this little tutorial, i'll show you one technique with it I came up with for wrapping objects onto other objects. Giving you a powerful tool to aid in modeling interesting shapes and deforming things in ways that would normally take ages by hand, and still not look as good.

Let's Begin!
For this tutorial, you can just start a new scene with a simple sphere and polygon plane to get an idea of how it works. Make the sphere relatively smooth, around 40x40 divisions. And the polygon plane between 20x20 and 30x30 divisions.. Position the polygon plane on top of the sphere.

Now select the plane, and open your script editor by hitting the button at the bottom right of Maya.

Type in:
source createMembrane;
createMembrane;

Then hit the   >  play/execute button at the top of the window to execute your code.
A membrane node will now have been created for the polygon plane, which you will see a tab for in your Attribute Editor window on the right.
In the future, you will only need to type "createMembrane", as "source createMembrane" only needs to be run once so Maya knows you use it.

Next:
1. Select your Plane and Sphere, go to Window>Hypergraph: Connections.

2. Find the "pSphereShape" node, middle-click and drag from it to the membrane node, and choose Other in the options that appear.

3. Now in this new window that will have popped up, find the "worldMesh" output on the left panel, click it, and then click the "collideMesh" input on the right panel, and close the window.

4. In the veiwport, select your polygon Plane and head to the membrane tab in the attributes window.
To reduce unnecessary computation over-head, we will zero any features were aren't using:
-Set Gravity and Wind options to 0.
-Under the Collision section set Friction to 0.

5. Under Collision, set Thickness to something like -0.020, Push out to -1, and Push out radius to something like 5 or higher (depends on mesh size, can always adjust this after, it determines the radius in which points are affected by the push-out.)

6. In Dynamic Properties, resistence levels between 0-2 are pretty good, adjust as needed though for any scenario. Rest Length Scale is also an important one, you'll need to adjust that one as needed to achieve the result you want.

That should be about all you need to do. If your polygon Plane is already lined up with the Sphere (also rotated for proper angle if it's off to the side) everything should already be looking pretty good. You can select your mesh and move it around on the surface since this is a deformer (if you move it too far, you'll want to rotate it a bit so you don't get a scrunched piece of fabric).

You can increase substeps as needed for quality control near the bottom in the Quality Settings section, although 3/3 seems to be good enough for most situations, and usually even lower. And the distance you move the pivot from or into the collision mesh effects how stretched the Plane becomes, so just play around with it, it's an interesting tool.


Here's a little more complex of a test I did using a face from one of my models:
Since the effect I was going for in this test wasn't about keeping my original shape uniform, I use a positive value in the Push Out, since I want to be pushing the mesh onto my collision object, instead of pulling it outward. In most cases this is the method you will want to use, unless dealing with just a flat polygon plane that you want wrapped onto a convex object.

Merely delete the history on your deformed mesh to save the shape it is in (which will also delete the membane node on it). Or you can key values in the attribute window by right clicking on a values name and choosing to key it, allowing you to create an animation of the deformation in action to be rendered out.

This was just a taste of the many possibilities this node brings. I encourage people to play around with it's various other settings also. It is always good to expand ones knowledge, increasing their toolset and ability to create great CG work.

Somewhat detailed descriptions for each of the Membranes options can be found here:
http://download.autodesk.com/us/maya/2009help/Nodes/membrane.html

Sunday, May 8, 2011

multiConstrain_v0.1 - Well that was a good hour and a half spent XD

Today I saw a post that popped up on CGSociety asking if there is a way to Aim Constraint multiple objects at once to a target  (not a group, since that would just make the groups pivot constrained.). The poster could not find a solution or an available script online, nor could I after searching.

So, since I've been interested in learning MEL for a while, I decided to take a stab at developing a simple script that would allow Maya to do what he was asking. After a little research into executing MEL commands on each object in a selection individually, and using similar examples, I thought I would have a working code. The code would work for commands like translate or delete, but since aimConstraint requires a target and something to constrain to it, that wasn't working, since it would bring the target object into the selected objects loop and screw it up. Tried so many different configurations until I finally figured out a simple loop structure that worked for it.

And here's my script :)


//Batch Aim Constraint script, by Mitch Zais
//Replace "target" with the name of your target object
//Select all objects you want to aim constrain to the target and execute the script

$aimTarget = "target";
string $selection[] = `ls -sl -l`;
for ( $each in $selection ) {
aimConstraint $aimTarget $each;
}


I want to keep learning MEL, so I plan on further developing this script now as a way of learning, since as it stands there isn't much to it. I'd like to develop an options window for it and branch it out to other constraints and operations that don't allow multiple objects to be done at once.

First thing to do is allow you to just select your target object in the viewport, so people don't have to edit the target name at the top of the script. Once I do that, I'll probably upload it to CreativeCrash.com to share with people, and continually update it there.

Wednesday, March 23, 2011

Work Room WIP 1

A work room I am creating for part of my demo reel. Going for a photo-realistic image. This is just what I have so far from about 12 or so hours of work.

The render took 4 hours with 800 FG quality, 3 point density, 8 refr/refl, 8 shadow, 4 diff bounces and level 3 adaptive sampling. Still, the image quality isn't that good, will have to play with the settings some more.

Wednesday, March 2, 2011