NavBar

Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Wednesday, April 20, 2011

PyMel

I print tshirts for a living, and that means that a good chunk of my work-day is spent waiting for the machine to spit out the next shirt. It gets pretty boring if I spend that time just sitting and waiting, so I get on my laptop and do useful things instead. This week, for example, I started to look into using PyMel for some of my scripting needs.

To get everyone up to speed, Maya uses its own embedded scripting language called MEL - Maya Embedded Language. It's a good start for learning how Maya works behind the scenes, but it is rather rigid in its structure, and has a tendency to be very very verbose.

Newer versions of Maya have begun to include a Python runtime as well as a library which ports all (most? I'm not 100% sure) of Maya's MEL commands for use in Python. This essentially allows you to write MEL code while taking advantages of some of Python's nicer features: dynamically typed variables, more refined string manipulation, and not having to check every freaking line of code for the one semi-colon you missed that's causing your whole script to break. However, it still requires you to think largely in more of a MEL-type flow, which ends up feeling like a half-baked hybrid that nobody really would want to look at.

That's where PyMel is intended to come it. From what I gather, PyMel is designed as a more Python-y integration of Maya commands into Python. Honestly, I don't have enough experience to say for sure, but at first glance it does seem to be an improvement. I will add one caveat: it appears that others more experienced than I have a less-than-enthusiastic opinion of PyMel, primarily because they have found it to become excessively slow for large iterative tasks. However, since I'm writing small helper scripts rather than full-on tools, the speed differences have so far been indistinguishable. (As a final aside, a brief websearch indicates that PyMel is faster overall for scripting control, but it is faster to then switch to the Maya.Cmds functions for iterating large loops.)

Anyways, why is all this important? Because I'm a perfectionist and a minimalist (usually within reason). I like to do as much as I can with as little as I can get away with. For example, why write 5 lines of MEL code when I can do the same thing with 1 line of PyMel?

//Parent constrain lower-level control object's zero-group to higher-level control object
//MEL Code
string $OA_ctrl_parent_selection[] = `ls -sl`;
string $parent_ctrl = $OA_ctrl_parent_selection[0];
string $child_ctrl = $OA_ctrl_parent_selection[1];
string $child_group = "GRP_" + $child_ctrl + "_zero";
parentConstraint -mo $parent_ctrl $child_group

//Parent constrain lower-level control object's zero-group to higher-level control object
//Python/PyMel Code
parentConstraint( ls(sl = 1)[0] , "GRP_" + ls(sl = 1)[1] + "_zero" , mo = 1 )

I'll be the first to admit that the PyMel snippet is much more difficult to decipher, but ultimately it's going onto my shelf as a button anyways. I'm also working on translating to PyMel the script I talked about in my previous post, but it's still a work in progress. In the end, though, I just really love writing these bits of automation to make my life easier. My rigging is already getting faster just by reducing the number of operations I have to execute to get the same results.

Thursday, January 27, 2011

Obsessions

It feels good to be coding again. Minecraft quickly turned into an addiction, which I have curbed by turning it into a project. I'm writing a Python script that converts Minecraft's world save data into Maya scenes.

When I was looking for Minecraft wallpaper for my desktop, I discovered an image where someone had taken Minecraft's level data and exported it to a different game engine, then used the game engine to export an OBJ to Blender. The final render looks like this:



I was blown away, but I quickly discovered that their method was quite specific to their software and, more importantly, Mac-only.

My script is still in the rough stages, but much of the basic functionality is there. It can open the .DAT files in which Minecraft stores its world chunks, strip out the section about what kind of blocks make up the chunk, then use that data to re-create the chunk inside of Maya. The end result looks like this:


It's an ugly pile of dirt, but it's a start. The blurry stuff on the top is water, and the various colored blocks are the different materials that make up the chunk. In the end, the script should create a set of geometry like this, as well as a proxy model, save to a file, then reference all the completed chunks into a central map scene.

I also have a list of features I'd like to add:
1) A shell mode where blocks that cannot be seen will not be created. Each chunk is 16 blocks wide, 16 blocks deep, and 128 blocks tall. That comes out to 32768 blocks per chunk...
2) A way to generate better water geometry. In the end, this may just have to be put in manually using planes.
3) UV layout and assignment to use the in-game textures.
4) Automatic lighting creation and placement for things like torches, lava, glowstone, etc.

I'm having a lot of fun with this. It's the biggest technical challenge I've had to tackle, and it's been a rewarding experience.

Monday, August 16, 2010

New developments

I apologize for my extended absence, but I've been busy working on a number of projects. I've been hired full time as resident artist, web-designer, and t-shirt wrangler at my sister's father-in-law's promotions and embroidery business. Needless to say, I've had my hands full getting the current sites prettied up, as well as getting ready to launch a new spin-off product line.

I've also gotten started on a major side project. I've decided to start making my own game. The plan is to make a small, relatively simple turn-based strategy game in Python using pixel art and 8-bit music, all created by me. I've already started to hammer out some of the base classes in an effort to wrap my head around object oriented programming, and it's a ton of fun.

It'll be a while before I have much worth looking at, but I'll do my best to load up art work, screen shots, and (once I have it working better) some beta code.