QME skin reduction trick

QME has a number of tools up its sleeves for creating front/back skinmaps for Quake models. As I mentioned in a skinmapping retrospective a while back, just having an editor which lets you manipulate vertices allows for models that were previously impossible to make. However, one of QME’s features that never fulfilled its promise was the “Cut Away Unused Skin” command.

The idea behind the command is to offer better skin coverage by slicing off the empty sections. A quick example will show where the shortcomings lie.
skin1

Here’s a skin comprising four distinct objects, with some obviously wasted space. When we run the Cut Away Unused Skin command, the skin is transformed to this:

skin2

There’s no denying that the skin is smaller, but it has ended up wider as well. The algorithm takes each individual component, cuts a bounding rectangle around it, then places each rectangle in a line from left to right. Since component B was taller than the other three components, we get wasted space below A, C and D. In models with dozens of small components and one tall one, the waste is magnified. Even when this method generates little waste, very wide skins are more awkward to work with than squarer ones.

Historical aside: I don’t know why QME goes for horizontal stacking when vertical stacks would typically produce squarer skins (since front and back are on the left and right side). But I can take a guess. In DOS Quake models were limited to skins that were 200px tall, but there was no limit on width. Going left to right ensured the algorithm never turned a valid model invalid. The height restriction does not exist in any other engine and is now ignored by all.

In fairness to QME, actually automating this process is not easy – the rectangle packing problem is not solved in general to my knowledge. So we need to do some of the work manually, but we can get QME to help with one little trick along the way.

Step 1
First we use the skin editor in vertex mode to pack the components tighter together. Here we’re manually doing the part of the problem that requires creativity and problem solving – where there isn’t a perfect algorithm and the human touch is helpful. When we’re finished we should have a tight bundle of polygons with a border of wasted space.skin3

Step 2
What we’d now like to do is trim that border away using Cut Away Unused Skin, but if we do that now then it’ll rearrange all our packing. When we looked at the algorithm, we saw that it applied per component, a collection of connected polygons. If we connect all of the components of the model together, then the command will only trim away the excess skin on the outside.

One easy way to join the components is what I will dub the Maypole method. Go into model view, and insert an extra vertex above the model. For each component of the model, select two of its vertices, select the added “Maypole” vertex, then press ctrl-t to make a triangle.maypole

Step 3
Return to the skin editor. You’ll notice that the new vertex we added occupies the very top left of the skin.skin4

If we leave it where it is, then the whole top and left border of our skin will be preserved by its presence. Drag it into the middle of the segment of skin we are keeping, and it won’t alter the bounding boxes any more.

Step 4
We’re now ready to go! Select Cut Away Unused Skin and marvel at how we’ve got a lovely compact skin.skin5

Step 5
Do not skip this step! If you are creating a skin from scratch, at this point you should resize the skin to dimensions that are a power of 2 (16, 32, 64, 128, 256, 512). This is often ignored in Quake because none of the original models did it, but it keeps your skin sharper in glquake so you should always pay heed. Knowing that this step is coming may make some ways of packing the polygons preferable to others, with a mind to reducing the distortion it may cause. If you’re trying to tidy the skin on an existing model, you have to weigh the value of better skin dimensions against the cost of redrawing the entire skin.

Step 6
Before we call it a day, we need to undo the hack that let us crop the skin. Go back into model editing mode, and select the Maypole vertex we added. Delete it, and all the extra triangles will disappear, the model is back to normal.

It’s a pretty simple idea, and not too hard to execute (although if your model has many components then it may be time-consuming to join them all in step 2). I hope that you find it useful!

Advertisements

One thought on “QME skin reduction trick

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s