joint related mel snippets

david | mel script | Tuesday, February 26th, 2008

I've been rigging a bit lately, so I thought I would share a few of the little mel scripts that I have written to use as marking-menus. They are only a few lines each but they save me several clicks and a couple of seconds everytime I use them.

djSelectJointsBelow.mel & djSelectNonJointsBelow.mel

Handy when I have a skeleton heirarchy that contains a mix of joint and non-joint nodes (I try to keep my heirarchy as clean as I can, but there are the inevitable constraints, controllers and space nodes that mess it up a bit). If I select a node and run djSelectJointsBelow.mel my selection is modified to include all the joints below that node. And obviously, djSelectNonJointsBelow.mel selects everything except the joints. I use these when rigging and then again when animating to save me picking my way through the outliner, or worrying about creating additional selection sets.

djDisplayLocalAxis.mel

I use this to turn on and off the display of the local axis for joints when I am doing the joint orientation phase of my rigging. The script requires two integer arguments to control it's behavior. The first argument: o=OFF, 1=ON and the 2nd argument 0=single, 1=heirarchy. So, for example, "djDisplayLocalAxis 1 0" turns on the local axis display for the selected node. And "djDisplayLocalAxis 0 1" would turn off the local axis display for the selected node and everything below it in the heirarchy.

updated: 7 April 2008 - fixed error when shapeNodes were found in the heirarchy.

djZeroJointRotations.mel

For most of my joint orientation I use Michael Comet's "cometJointOrient.mel" to align the local axes along the bones, but for some joints like the wrist I need to manually rotate the local axis to my liking. The trouble is that after a manual rotation the joints "Rotate Axis" values will be non-zero, where as if you used Comet's script they get zero'd out (frozen into the joint orientation) as part of the process. For some things it doesnt really matter, but lately I have been playing with the cMuscle add-on and I noticed that capsules made from bones with non-zero rotate-axis values dont align correctly with the bone. So, djZeroJointRotations.mel simply does the zeroing out step for the selected joint(s) (non-joint selections are ignored).

Download page.

cMusclePaint.mel modification

david | animation,dj mod,mel script | Saturday, February 23rd, 2008

Anyone who has tried the new maya muscle system would have to agree that the Paint Muscle Weights tool is a big improvement on the old Paint Skin Weights tool. The colored weight display now makes a lot more sense. I think we owe Michael Comet a big thank-you.

After playing with the Paint Muscle Weights tool, I noticed that I was stumbling each time I locked or unlocked weights. My modified version of cMusclePaint.mel addresses two issues.

1. The right-mouse-button menu for weight locking is too wordy and bordering on ambiguity. Here is a snapshot.

cMusclePaintBefore.jpg

I'm sure I could learn to live with it, but there is too much unneccessary text here.

2. My preferred weight painting workflow involves locking all joints except two. I smooth between those two joints and then move on down the chain to the next two. This would involve at least two goes with that rmb-menu to lock a joint and unlock another.

So I changed a few lines in cMusclePaint.mel and now the interface looks like this.

cMusclePaintAfter.jpg

In my opinion the menu is easier to read at a glance. The new "Unlock Selected...Lock the rest" function saves me a few mouse clicks. And the new "Unlock All" function does so while retaining the joint selection in the list.

Download here.

djToggleClippingPlanes.mel

david | mel script | Friday, February 22nd, 2008

The switch for camera clipping plane display is burried too deeply. You need to navigate 3 drop-down menus and it only does one camera at a time.

djToggleClippingPlanes.mel is designed to be run from a hot-key, shelf-button or marking menu. Select you camera (one or more) and run the script to toggle the clipping plane display. If your camera happens to be nested in a heirarchy you can just select any of the nodes above it.

Download here.

envSphere, mentalray and IBL

david | mentalray,rendering,tutorials | Wednesday, February 13th, 2008

The way mentalray has been integrated with maya's native shaders is a constant source of curiosity. Some things work the way you expect, some not at all and some need to be tricked into working. In this post I'm going to share the results of my experimentation with maya's envSphere shader in a mentalray context, which led me to the obvious conclusion that IBL is a better choice.

After years of using maya's own software renderer I'm used to doing things in a certain way. The envSphere environment shader is easy to use. I hook up a fileTexture, or a rampTexture and I can then use the place2dTexture node control exactly how they sit within the sphere. For example if I have a 180deg panorama, I will probably want to set the repeatU=2 in the place2dTexture.

The trouble with envSphere is that it doesnt seem to work properly with mentalray shaders. If I connect it to the camera's mentalray environment shader slot maya crashes when I attempt to render.

To the untrained eye, the mentalray equivalent of an envSphere would appear to be mib_lookup_spherical, but it is not so user-friendly, because it forces you to use a mentalrayTexture node and a whole bunch of other nodes to get anything approaching the functionality of the place2dTexture. Too hard! And I could never figure out how to hook up a ramp texture. Often I have simply resorted to mapping my fileTexture onto a big nurbs sphere. Easy!

But I like messing around with mentalray and the hypershader, and today, almost by accident, I discovered that its possible to use envSphere as a mentalray environment shader after all. Rather than connect it directly to the camera, you need to go via a multiplyDivide node (or something similar). Here is a snapshot of the hypershade connections (click image for the full size version).

envSphereHypershadeSml.jpg

I guess the multiplyDivide node acts as some kind of data converter. Here's a render I did.

envSphereMR_filter1.jpg

I'm using a fairly lores image, but it should not be that blurry. What I realized is that you need to set the fileTexture filter=0 in the effects tab (dont set the filter type to none; leave it as quadratic of mipmap). Then when I rerendered I got this.

envSphereMR_filter0.jpg

This works pretty well. I've got the convenience of the place3dTexture to rotate the environment and the place2dTexture to set my repeats and to fine tune the offset. Here is one I did with a ramp instead.

envSphereMR_ramp.jpg

My excitement was short lived though. When I turned on final gather I got this.

envSphereMR_FG.jpg

Dohhh!

Fortunately, there is a solution - Image Based Lighting. You can create a mentalrayIbl node by clicking a button in the Environment tab at the bottom of the render settings window. There is no need to connect it to the camera. Once the IBL node is in your scene mentalray will use it as your environment.

Here is my artifact free render with final gather where I have removed the envSphere from the scene and created an IBL node and connected my ramp to it.

IBL_ramp_FG.jpg

When you create an IBL it defaults to Type=Image File and expects you to give it the name of your image file. But if you want to fine tune your image mapping with a place2dTexture node or you want to use a ramp then you need to change to Type=Texture and connect a maya fileTexture or a ramp texture.

A minor inconvenience is that you cant simply drag-and-drop the texture node onto the texture swatch in the IBL attribute editor. You can try, but no connection gets made. To connect an existing node you need to use the connection editor and connect as shown here.

connectRampToIBL.jpg

Notice how the IBL attribute called "texture" in the attribute editor (below) is called "color" in the connection editor (above right) - just to confuse you.

IBL_attr.jpg

A bonus with the IBL node is that you get a textured preview in the viewport which really helps you line up your reflections. By default the IBL will be scaled very large and you may need to scale it down to see it within your camera's clipping planes.

IBL_viewport.jpg

The IBL can also do light and photon emission. Neither are turned on by default, but they are there if you want them, and you can afford the render time.

Conclusion: Sometimes it is possible get mentalray to do things it probably wasn't meant to do, but for an environment shader, Image Based Lighting is a better choice than envSphere (and forget mib_lookup_spherical unless you like complication).

layering shaders with mentalray

david | mentalray,rendering,tutorials | Friday, February 1st, 2008

This is a mini tutorial where I will show one method of layering shaders using mentalray for maya 2008. To make it slightly more interesting one of the shaders will be the misss_fast_simple.

Maya comes with its own layered shader node and you can hook it up with mentalray shaders, but it doesnt always work, and I'm not a big fan of the interface so I dont use it. For several years I have been using the mix8layers shader (from ctrl.studio). It is a reliable shader and texture layering node with lots of features. But today my layering example will use a phenomenon I created called dj_mix_colors which is built upon the mib_color_mix node.

I am going to layer a rusty metalic looking blinn over misss_fast_simple to get the result you can see in this picture.

layeringShadersInMR_DJ001.jpg

I created a sphere on a plane with a couple of area lights as shown in the next picture

perspView.jpg

Then I created a blinn shader with its color coming from a crater texture and bump from a noise texture.

Next I created a misss_fast_simple. When you do this in maya 2008 a few extra nodes are automatically created at the same time. The extra nodes are a lightmap node and a mentalrayTexture and they are used to generate and store the sub surface scattering calculations. The important thing to realize is that the misss_fast_lmap_maya node (the light map) connects to the shading group node rather than to the material node. This connection to the shading group node must be taken into consideration when I do the shader layering.

Before getting into any layering I simply assigned the blinn to my sphere and adjusted the material attributes to make the rusty metalic appearance. Then I assigned the misss_fast_skin and adjusted the lighting to show off the subsurface scattering.

Next I created a dj_mix_colors node. This node can either be used as a texture or as a material in mentalray shader networks. For reasons which I will not explain here, if you are trying this example, you may not be able to assign dj_mix_colors to a surface using the hypershade Assign Material To Selection menu. However it can be easily done by assigning another shader (say a lambert) to create a shading group node, and then you can drag-and-drop the dj_mix_colors into the mentalray Material Shader slot in the shading group node. The lambert will be ignored (and can be deleted).

In this example I just reused the shading group node that was created along with the misss_fast_simple material. I connected my dj_mix_colors node so that it replaced the misss_fast_simple material. This saved me creating that temporary lambert material, but much more importantly it means the lightmap connection is already set up.

So here is what the shading group attribute editor looks like now (I have renamed it to be more meaningful)

layeringShadersSG_attr.jpg

dj_mix_colors can mix upto 8 different inputs in a variety of ways. In this case I started by setting color0 to black. I then enabled 2 additional colors and set the mode for each of these to add. I dragged the blinn to color1 and dragged the misss_fast_simple to color2.

If I do a render now then both materials are added together. In dj_mix_colors weight1 and weight2 controls the relative strength of the 2 layers. But I want to use a mask to cut out one material, and in this example I am using a simple checker texture with the repeatU set to 0.5 so I get horizontal stripes.

First I connect the checker to the dj_mix_colors weight2. Now the misss_fast_simple will only effect the areas defined by the white parts of the checker. I need to also connect to weight1 but this needs to go via a reverse node so that the blinn will be seen only in the areas where the checker is black.

The dj_mix_colors attribute editor looks like this

dj_mix_colors_attr.jpg

Rending now shows that the materials colors are masked correctly, but the bump continues to cover the sphere. This is due to the way maya handles bump maps. Even though the bump node is connected to the material, that is not how the renderer sees it. To correct the bump I just have to connect the reversed checker to the alphaGain of the noise texture to cancel out the noise.

Thats it!

Here is a snapshot of the hypershade network with the connections highlighted. Click the image for the full sized image

layersHyperGraphSmall.jpg

And here is the render again

layeringShadersInMR_DJ001.jpg

You can download my scene file here.

To use this example you will also need to get dj_mix_colors but the technique could also be used with the standard mib_color_mix.

Powered by WordPress | Based on a theme by Roy Tanck