sunnuntai 15. helmikuuta 2015

Maya: Select Every N-th Edge + Transform Components

Hey! Just documenting a very quick tip for future me and others. For one reason or another we might need a cylinder with a bunch of protruding parts in a regular but asymmetrical pattern. It could seem challenging, but is actually very easy to create in Maya (2015 + bonus tools) with a couple of tricks. Here's the protagonist:


Most of this is basic stuff. We start off by making a cylinder. Shift + Right Mouse Button :)

Set the required subdivision level.
I use the new Multi-Cut Tool to add edge loops but you could use the Insert Edge Loop Tool just as well.

Here's the first part that was not instantly obvious to me. Select two edges along the same edge loop to indicate the Select Every N-th Edge in Loop tool which edges (and ultimately faces) we will be selecting. My edges had one edge between them because I wanted every other face to be extruded, but you could select every 3rd or 4th edge or whatever to achieve the effect you're after.

Bonus Tools is not a part of a default Maya installation, you can get it here: http://area.autodesk.com/bonus_tools ---> download page. (You should also check out Bonus Tools > Auto Unwrap UVs Tool if you regularly layout UVs.)


Here's a pic illustrating the end result of Select Every N-th Edge in Loop as well as the next step, which is to convert the selection to faces (CTRL + RMB > To Faces > To Faces).





The conversion gives us unwanted faces, we get rid of them by rotating the object and a CTRL + DRAG to unselect.


Yay, now we have the faces we need. But all faces on the side of the cylinder are equally wide, which is not what we want this time. We shall make the selected faces wider with Edit Mesh > Transform Components. Use the red cube to widen (scale on the local X-axis, shown here in yellow as I messed with it just before taking the screenshot).

Now we are finally ready to extrude. To quickly make the exact shape needed (protruding and slightly narrower than base), just pull the faces outward (local Z) with the blue arrow and then scale them in local XY by doing a CTRL + DRAG on the blue cube.


Bevel the top and bottom edges of the cylinder just for fun :P

So there, that's it. This combination of basic techniques and well, basic-ish techniques was useful for me yesterday and I though it might be useful for someone in the future. Here it is. Select Every N-th Edge in Loop and Transform Components were new for me. Have a nice day!

(If you're feeling nitpicky, you might notice that the object in the first image is not an exact copy of what we have here at the end. I'm aware. No further commentary required. :) )


Maya MEL: Custom shortcut - extrude with a specific div level

I was making a ribcage in Maya and I felt like my workflow could be improved, so I wrote a little script and assigned it a custom shortcut. I had a spine model and the ribs were spine faces extruded along a curve. Every time I extruded, after extruding I had to go back and change the amount of divisions on the extrusion to make the added part usable. The script I wrote does that automatically.

After the fact I realized that I can achieve the same effect by just changing the amount of divisions in the extrude settings. Thus, all this is mostly waste of time and might even be harmful as the script is not very well-behaved and pollutes the global namespace. Also, it is untested on wrong number or type of selections, so it might break things. I guess it still was a good little exercise and I'm documenting it to not repeat the same mistake. Please do not use this for anything, just learn from my experience.

The custom shortcut was created by going to Window > Settings/Preferences > Hotkey Editor, creating a new hotkey under 'User' and pasting the code there. Usage: first select face to extrude, then curve to extrude along and then Ctrl+Shift+N to extrude. The amount of division is set in $divs and is 30 in my case. Pic and code below.


int $divs = 30;

string $selection[] = `ls -selection -long`;
string $object;
string $tokenized[];
string $extrudeInputs[] = {};
for ( $object in $selection ) {
    tokenize $object "|" $tokenized;
    $extrudeInputs[ size($extrudeInputs) ] = ($tokenized[ size($tokenized)-1 ]);
}

print( "Extruding face '" + $extrudeInputs[0] + "' along curve '" + $extrudeInputs[1] + "' with " + $divs + " divisions.\n" );

polyExtrudeFacet -constructionHistory 1 -keepFacesTogether 1 -divisions $divs -twist 0 -taper 1 -off 0 -thickness 0 -smoothingAngle 30 -inputCurve $extrudeInputs[1] $extrudeInputs[0];