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

13 comments:

  1. hi! is it possible to hookup a weight map to attributes from the membrane?

    ReplyDelete
    Replies
    1. I have not tested that personally, but I don't see any reason why not. Just have to do it through the Hypershade.

      Delete
  2. Hi, I found the worldMesh property once, now I can't find it again and I know I've done everything correctly ?

    ReplyDelete
    Replies
    1. The WorldMesh property is in the Shape node for the object you want your Membrane to collide against. Say I created a sphere, I'll have a node called "pSphere1" and another named "pSphereShape1", I want that "pSphereShape1" selected in my Hypergraph, and connect from it to my membrane node. (Hold middle-click, drag from it to the membrane node, and choose "other", then you'll be able to find WorldMesh on the left panel.

      I just checked in Maya 2015 and it's still the same!

      Delete
  3. Cannot find collideMesh in the connection editor on the right side where Membrane is. In fact, once I have worldMesh selected in the left side (pSphereShape1) everything is greyed out in the right side (membrane1). I am using Maya 2014, any clues.

    ReplyDelete
    Replies
    1. Ok I got it, in the menu of the connetion editor Show Hidden has to be selected.
      Thanks

      Delete
    2. Odd that it's like that, by default in 2015 it showed for me.

      Delete
  4. Same as Szymon and Christopher, I couldn't find a property either in the connection editor (for me, it was the worldMesh for the pSphereShape in the connection editor) and took me a bit to figure it out. If you're not finding a property, look at the "Left Display" or the "Right Display" menu at the top of the Connection Editor window, and check either the Show Hidden or (in my case) Show Non-Keyable - or may even be something else for you - but that should allow you to see attributes that you couldn't see before. This is where you select what attributes you can see for each node. In case it helps anyone else. And thanks for this tutorial, Mitch. Much appreciated.

    ReplyDelete
  5. I envisioned this technique as letting the points on the plane that start to touch the sphere just lie on the sphere as the other points come down. But as I start to move my plane down towards the sphere, the vertex points on the plane that are closest to the sphere start snapping down to the sphere while the plane is still quite a bit above the sphere, and while the rest of the vertex points on the plane are still hovering above (as if there's a magnet on the sphere that, once the plane gets close enough, just pulls the vertex points on the plane to it, even though the plane is not close to touching the sphere yet). I've tried playing around with the settings for a while, but I can't seem to improve this behavior. Any thoughts on this would be appreciated.

    ReplyDelete
    Replies
    1. I noticed that issue too when I just tried using the membrane in 2015. I finally got it working though, but I'm not 100% why. It was my third attempt and it just started working...
      http://i.gyazo.com/ed71253da6e9be376cc87555d38da941.mp4

      I've restarted Maya, and it seems to still work fine everytime now, so that's really strange. It started working after on my third attempt I had tried scaling my objects up about by about 20 units, delete history and froze transforms, created a cube and subdivided it into a sphere and converted smooth mesh preview into mesh. And also rotated my plane a bit.

      So perhaps using a non-default object somehow changed something, I dunno. But I don't need to go through all that, it just works properly.

      Delete
  6. Hey guys, I've also had the issue where the property 'WorldMesh' or 'InMesh' is just not on the list. I've changed the viewing options and even tried on another maya 2015, no results.

    ReplyDelete
    Replies
    1. Ah silly me, I was using the Cube node rather then CubeShape node!

      Delete
  7. can I attach a rest shape to shpere shape node,

    ReplyDelete