• entries
5
6
• views
7793

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

1048 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

• Hi there,
i recently start learning unity and im working in my first game ,

I was wondering if unity had functions to support the motion control effect (tilting screen to move character) you see
in doodle jump (which is 2d game) ? If it exists, what are they called? and how it works ?

Thanks

• For reference I am use Unity as my game engine and the A* Pathfinding Project for path finding as there is no chance I would be able to create anything close to as performant as that in any reasonable amount of time.
So I am looking to build a game that is going to have a very similar style as Prison Architect / Rim World / SimAirport / etc. One of the things that I assume is going to effect performance is path finding. Decisions about the game I have already made that I think relate to this are:
1. While I am going to be using Colliders, all of them will be trigger colliders so everything can pass through each other and I will not be use physics for anything else as it has no relevance for my game
2. I am going to want to have a soft cap at the map size being 300x300 (90,000 tiles), I might allow bigger sizes but do something like Rim World does in warning the player about possible side effect (whether it be performance or gameplay)
3. The map will be somewhat dynamic in that the user will be able to build / gather stuff from the map but outside of that, it should not change very much
Now I am going to build my game around the idea that users would be in control of no more than 50 pawns at any given time (which is something I can probably enforce through the game play) but I am also going to want to have number other pawns that are AI controlled on the map (NPCs, animals, etc.) that would also need path finding enabled. Now I did a basic test in which I have X number of pawns pick a random location in the 300 x 300 map. move towards it, and then change the location every 3-5 seconds. My initial test was pretty slow (not surprising as I was calculating the path every frame for each pawn) so I decided to cache the calculated path results and only update it ever 2 seconds which got me:
100 pawns: 250 - 450 FPS
150 pawns: 160 - 300 FPS
200 pawns: 90 - 150 FPS
250 pawns: 50 - 100 FPS
There is very little extra happening in the game outside of rendering the tilemap.
I would imagine the most pawns on the map at a given time that need path finding might be a 1000 (and I would probably be able to make due with like 500 - 600). Now obviously I would not need all the pawn to be calculation paths every 2 seconds nor would they need to be calculating paths that are so long but even at a 5 second path refresh rate and paths that are up to 10 tiles long, I am still only able to get to about 400 pawns before I start to see some big performance issues. The issue with reducing the refresh rate is that there are going to be cases where maybe a wall is built before the pawns path is refreshed having them walk through the wall but not sure if there is a clean way to update the path only when needed.
I am sure when I don't run the game in the Unity editor I will see increase performance but I am just trying to figure out what things I could be doing to make sure path finding is as smaller of a performance hit as possible as there is a lot of other simulation stuff I am going to want to run on top of the path finding.

• well I am able to get my sprites to rotate and move in all directions, I have drawn two plane sprites, I am also able to shoot a bullet in the up direction, I want to shoot bullets in all directions just like my plane rotates, I just need a hint on how to proceed, go easy on me this is new stuff to me. However I am making progress.

• well I have managed to get a plane sprite to move around the screen I want to know what to add to my game. I hope this question is appropriate.

• Hey. We are a young team of online game developers from Ukraine. We made an excellent game for home and office. This MMORPG with open world and unique mechanics. The game is made in the style of graphic MUD. We really want to show our game to people.
Dark Swords is a free online role-playing game of new generation. The action takes place in a unique world which doesn't have analogues. DarkSwords combines the traditional role-playing system with innovative approach to the game process implementation, character development and social aspect. You can join the players from all parts of the world right now for free!
Welcome: http://darkswords.com
Russian version: http://darkswords.ru

×