Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411490 Posts in 69371 Topics- by 58428 Members - Latest Member: shelton786

April 24, 2024, 08:57:19 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)2D cut-out animation in Maya
Pages: [1]
Print
Author Topic: 2D cut-out animation in Maya  (Read 733 times)
ongamex
Level 0
**


View Profile
« on: September 30, 2017, 08:23:32 AM »

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.

Code:
// <?php This is actually mel scriptI'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/

Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic