Jump to content
  • Advertisement
  • entries
  • comments
  • views

2D animation in Maya: a script that import images as planes

Sign in to follow this  


This is basically a duplicate of what I've wrote on my recently created blog (https://ongamex.github.io/maya/mel/2017-09-08-Maya2DAnim/).

In order to do 2D animation in Maya, you have to import the images, assign them to material, then assign those materials to planes, and those planes must be properly sized with correct UVs, in order not to stretch the images. Doing this by hand is extremely annoying, so I wrote this script

// <?php This is actually mel script, I'm just using the syntax highlight for php ^_^

// This scripts creates a planes and assignes to them materails
// that use 2D textures for their colors. Useful quickly importing 2D 
// things for animation.

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"`;
	for($i = 0; $i < size($filenames); $i++)


You can execute it directly in the "script editor", or create a shelf button that executes it.


I hope you find it useful ^_^

Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Advertisement
  • Blog Entries

  • Similar Content

    • By LonelyStep
      Thought I'd reach out for some feedback on my little project. This is an android two-player game for top-down boxing matches. The core mechanics are all that I have accomplished thus far, later I want to add different configurations for your boxer (special effects, increased health or damage, etc) and maybe even a single player AI to practice against.



      Right now the gameplay feedback I'm looking for is on the fundamental mechanics of the game.

      One area of particular concern is the window of opportunity for a player to block after their opponent has begun a punch. Currently that window is one-tenth of a second, otherwise you will be to late to counter their blow. I want it to be difficult to successfully pull off a block and have it be something that requires real attention to accomplish. I'm wondering though if it isn't too difficult right now, which may encourage mindless button mashing, which is certainly not what I want to condone.

      Another consideration is whether having three main actions (block, attack, charge) provides a good balance. My idea with having three main areas is that your two thumbs will have to leave one section uncovered at all times. This should result in hand movements that telegraph actions to the opponent.

      Aside from these, any other constructive criticism is very welcome.

      My game can be found at the Google Play Store here:

      NOTE There is a known graphics error when performing a special punch. There are no doubt other unknown errors as well.

        Thank you for your time, I hope you'll be able to find some fun in this little game!
    • By Vandallord
      Link: https://www.kongregate.com/games/Vandallord/idle-stone-history

      A wicked witch turned the main hero into the stone, you need to find a way to break the spell.
      Click on the objects and they will open.
      Click on the stone and its skill to attack the animals will grow as well as a the losses from clicking on animals.
      Click on the river to improve the function to manage time and clicks on the animals will be more precise.
      Click on the tree and it will give you things from animals and the level of luck will grow which give you an opportunity to Harder hits.
      The higher the level of monsters the more animal can visit the stone and give presents which are essential to make a portion.
    • By Feirx
      Current Project
      -Over the Shoulder/3rd person
      -Steampunk/Medieval aesthetic
      -Co-op (2 Player story line)
      Calling all content creators and programmers of any skill and experience level to join the team. Please be at least 16+ years of age. Artist(s) NEEDED (Unspecific; 3D Models, Concept Art, Animation, Ads, Graphic Design, ...)*
      *Artist(s), We currently do not have any art styles set. We are looking for an original artist to set the art style for our production. This is a big opportunity.

      Feel free to ask questions. I am super excited to get started and meet some new people.

      Comment or message me for Discord server invitation.
      A new entry in the devlog for 13 Ronin, a retro 2d samurai fighting game, this time it's about implementing the logic for the computer player.
      Happy coding!
    • By Znippy
      Hello everyone!  
      This is my submission for the Frogger challenge.
      The final build for the project can be found here!
      I hope I have fulfilled all requirements for this challenge. Sadly, I do not have time to create a gameplay video. I am not sure if this is a must. I have added a couple of screenshots from my blog series.
      My post-mortem post will be done next week. 
      As I already mentioned on the project page, I also could offer a Linux build if somebody needs one!
      I hope you like it and I am excited to see your high scores!
      Please tell me if there is anything missing!

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!