• entries
9
10
• views
9098

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

1481 views

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"; HypershadeWindow; for($i = 0; $i < size($filenames); $i++) { textureTo2DPlane($filenames[\$i]);
}
}

promptForFiles();

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

I hope you find it useful

There are no comments to display.

## Create an account

Register a new account

• ### Similar Content

• Hello folks, I was hoping I could get some feedback on some character designs I've been working on for a game I'm making.
This is for a 2D platformer with a cartoony design.  I'm making three playable characters.
I'm looking for any feedback at all on these designs; let me know what you think.  Be honest; you don't need to sugar-coat anything.
Also I have a couple different versions I've sketched out and I'd like to see which ones people like the best.
One of the designs I'm implementing is that when the player has one hit left, part of their attire get blown off.  (Like in Ghosts n' goblins, when you lose your armor.)  The design on the far left is the one that represents this "no armor" state.
First of all, this is the mage.  I'm pretty satisfied with his design so I never created different variations.  But I'm still interested in feedback about his design if you have anything you want to say.

Next up is the reaper.  I was originally planning for her armored version to just be a generic cloak, but I've been thinking lately that I should have something more distinct; something more unique.  So I drew some different sketches of some different ideas, and I'd really like to know which of these people like.

And finally, the ranger.  I just have a couple different variations on her outfit.  With and without a pauldron, and a shoulder cape.

And for context, here's a sample scene with some slightly older versions of these characters if you want to see what kind of visual environment they are designed for: https://imgur.com/cZ4oR6L
Let me know what you think!

• Looking for a 2D artist to make with me a top-down game with cool features, guns, spells, and powerups. I'm a programmer, and I already made the code for the guns, different spells, powerups and basic mechanics like shooting and moving and stuff like that. I just don't have any assets to use so I'm looking for 1-2 2D artists, can be a pixel artist or anything that you want. Compensation will be 50% for you and 50% for me if we are only 2 and will be different if we are gonna be a trio, you are not working for me (or volunteering) we are a team. The only thing that I control and you not is the money, but you can argue with me and I will probably give you the amount that you think that you deserve. It doesn't have a name yet, we will decide about the name together. You can create guns with no coding because of a system that I created so you will also be able to create content for the game, besides ideas and art. I really need an artist so if you are interested please contact me in discord: #1615Cringey Boy

I will leave a video to see the game and also the build to try and actually play the game that I have right now. I don't have any art so it looks bad (;
https://drive.google.com/drive/folders/1Na3JKPBYXuUpxtP-lBUO-hIl0xO1ujSj?usp=sharing < this is the build, just download the folder called "Dungeon" and in there press on Dungeon.exe to open the game.
Controls:
1. Switch to the main gun
2. Switch to the secondary gun
Mouse Left Click. Shoot (you also aim with the mouse)
R. Reload the gun that you are holding.
E. Use main spell (currently, fireball which explodes and deals damage. And you also aim that with the mouse)
Q. Use secondary spell (currently, heal aura which heals you pretty fast. You don't need to aim)
(In the video there is no restart but in the build, there will be a restart button when you die)

Desktop 2019.10.21 - 20.55.18.02.mp4 Desktop 2019.10.21 - 20.55.18.02.mp4 )

• well I am working on a simpler game called tic tac toe, my question is how do I get the mouse click to draw an X on the  board. when I click the mouse nothing happens.
#include <freeglut.h> #include <iostream> using namespace std; void drawBoard() { glPushMatrix(); glColor3f(1.0f, 0.0f, 0.0f); glBegin(GL_LINE_STRIP); glVertex3f(-18.75f, 6.25f, 0.0f); glVertex3f(18.75f, 6.25f, 0.0f); glEnd(); glBegin(GL_LINE_STRIP); glVertex3f(-18.75f, -6.25f, 0.0f); glVertex3f(18.75f, -6.25f, 0.0f); glEnd(); glBegin(GL_LINE_STRIP); glVertex3f(-6.25f, 18.75f, 0.0f); glVertex3f(-6.25f, -18.75f, 0.0f); glEnd(); glBegin(GL_LINE_STRIP); glVertex3f(6.25f, 18.75f, 0.0f); glVertex3f(6.25f, -18.75f, 0.0f); glEnd(); glPopMatrix(); } void drawText() { glColor3f(0.0f, 1.0f, 1.0f); glRasterPos2f(10.0f, 10.0f); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'X'); } void renderScene() { glClear(GL_COLOR_BUFFER_BIT); drawBoard(); glutSwapBuffers(); } void ChangeSize(GLsizei w, GLsizei h) { GLfloat aspectRatio; if (h == 0) h = 1; glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); aspectRatio = (GLfloat)w / (GLfloat)h; if (w <= h) glOrtho(-100.0, 100.0, -100.0 / aspectRatio, 100.0 / aspectRatio, 1.0, -1.0); else glOrtho(-100.0*aspectRatio, 100.0*aspectRatio, -100.0, 100.0, 1.0, -1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void mouseClicks(int button, int state, int x, int y) { if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { drawText(); } } int main(int argc, char**argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE); glutInitWindowPosition(600, 400); glutInitWindowSize(800, 600); glutCreateWindow("Tic Tac Toe"); glutDisplayFunc(renderScene); glutReshapeFunc(ChangeSize); glutMouseFunc(mouseClicks); glutMainLoop(); }

• On Aura you can find the Track Ray fossilized bones usually split up in 6 parts. This extinct reptile was incredibly colourful and was one of the largest land animals ever to have inhabited this cold planet. It is speculated that the thick feathers and scales were good insulators for the cold and the colour was most likely a display to attract mates.

• On Lelantos you can use Portals to quickly go from one side of the map to the other. Each Portal has a number that once discovered will show up on the mini-map to help you keep track of where you are. Just be careful when using these teleportation devices, you never know what waits on the other side of the gate!