Hello all ^_^
I'm new to the forums. Actually I'm not an artist but a programmer and form time to time I try to do some art.
A while ago I've tried to make a simple cut-out animation in Maya, just a few *.png files slapped on planes. I've tried to do it by hand, but I grew tiered pretty quickly, so I wrote a small MEL script to do this for me.
// <?php This is actually mel script, I'm just using the syntax highlight for php ^_^
// This scripts creates a planes and assignees to them materials
// that use 2D textures for their colours.
proc string obtainFilename(string $path)
{
$filepart = match( "[^/\\]*$", $path );
string $buffer[];
tokenize $filepart "." $buffer;
return $buffer[0];
}
proc textureTo2DPlane(string $textureFileName)
{
$filename = obtainFilename($textureFileName);
// Create the texture and a 2D placement for it.
$textureFile = `shadingNode -asTexture -isColorManaged file -name ("file_"+$filename)`;
$texturePlacement2D = `shadingNode -asUtility place2dTexture`;
connectAttr -f ($texturePlacement2D+".coverage") ($textureFile+".coverage");
setAttr -type "string" ($textureFile+".fileTextureName") $textureFileName;
// Create the material and attach the file as an input color.
$material = `shadingNode -asShader lambert -name ("mtl_" + $filename)`;
connectAttr -f ($textureFile+".outColor") ($material+".color");
connectAttr -f ($textureFile+".outTransparency") ($material+".transparency");
// Obtain the size of the texture.
float $size[2] = `getAttr ($textureFile+".outSize")`;
// " -axis 0 0 1" will make the "plane" in XY plane, facing Z.
// "sx" and "sy" control the amount of segments in each plane.
$mesh = `polyPlane -w ($size[0]) -h ($size[1]) -sx 1 -sy 1 -axis 0 0 1 -name ($filename)`;
// Now apply the newly created material.
// TODO: Check if we could do this without selecting.
// TODO: Should I create a default shading group?
select $mesh;
hyperShade -assign ($material);
}
proc promptForFiles()
{
string $filenames[] = `fileDialog2 -fileMode 4 -caption "Import Image"`;
HypershadeWindow;
for($i = 0; $i < size($filenames); $i++)
{
textureTo2DPlane($filenames[$i]);
}
}
promptForFiles();
EDIT:
This is a bit like advertisement, but
You can read in my blog about it
https://ongamex.github.io/maya/mel/2017-09-08-Maya2DAnim/