De-Limer Photoshop Script, fixes that annoying Lime/Lime64 texture corruption!

De-Limer Version 1. (And likely final ever version)

For those of you who dabble in model porting you may have noticed that Lime sometimes corrupts normal maps, alpha masks and specular maps, so that they look like this:

https://dl.dropboxusercontent.com/u/11994337/Delimer/russian_military_assault_a_nml.jpg[/t]
What happens is that it vertically flips 4px high strip all the way through the texture, naturally this results in a very broken texture.

This has been reported and the creator is planning to fix it as far as I’m aware but until then this is a stop gap I worked on after Ninja Nub complained about it. I had previously heard about this bug from Kali but only recently came up with an idea to solve it.

So I present De-Limer! A script for Photoshop CS6 (But also compatible with Photoshop CS2, untested in other versions.) This is based off a script that I found made by an Oisin Conolly that would make an image into a 100 layers with each being 10px by 10px which can be found at http://www.digitalbiscuits.co.uk/projects/photoshop-scripts/Photoshop_Grid_To_Layers.js, I then found a fixed version by txanatan on https://gist.github.com/txanatan/4333894 and worked on adapting it to my needs.

Below is a full parse of the script which works by making an array and selecting 4px * image width boxes, copying them to a new layer, rotating them 180 degrees, flattening then selecting the next layer. Once the end of the array has been reached it flips the canvas horizontally. The reason for this is there is no way to simply flip the selection or a single layer, you can only flip the whole canvas. I’m sure there much more elegant and better solutions to this problem but this was just something I could do to help a couple of friends.

To use it download or make your own .jsx file, then load your borken image into photoshop, file > scripts > browse > delimer.jsx, let it run and do its thing, it usually takes about 1 or 2 minutes on large images then simply save your image. Sadly you must repeat the process for every image but it’s better than doing it manually.


// modification of a script by Oisin Conolly (digitalbiscuits.co.uk),
// found on StackOverflow, further edited by ViralHatred for Call of Duty Normalmaps.
// Lime exporter sometimes exports normal and specular maps wrong, this script can correct it.
// The problem is that it flips vertically 4px strips down the entire image, this is time consuming to fix by hand.
 
// x and y size of the slices we want to take
// X is set to app.activedocument.width so it should scale to any image size. Y is fixed at 4px which is what the strips are at.
var xSize = app.activeDocument.width;
var ySize = 4;
 
// set the ruler type
if (app.preferences.rulerUnits != Units.PIXELS) {
    app.preferences.rulerUnits = Units.PIXELS;
}
 
// keep a reference to the document and original layer
var docRef = app.activeDocument;
var layerRef = docRef.activeLayer;
 
for (y = 0; y<docRef.height; y+=ySize) {
    for (x = 0; x<docRef.width; x+=xSize) {
        // activate the original layer
        docRef.activeLayer = layerRef;
        // make the selection
        docRef.selection.select(Array (Array(x, y), Array(x, y+ySize), Array(x+xSize,y+ySize), Array(x+xSize,y)), SelectionType.REPLACE, 0, false);
 
        // copy the selection
        docRef.selection.copy();
        // create new layer
        docRef.artLayers.add();
        // and paste it
        docRef.paste();
        // Rotate it - No way to flip it vertically layer by layer, rotate it 180 then flip canvas horizontally.
        docRef.activeLayer.rotate(180);
        // Flatten - We don't want too many layers to deal with.
        docRef.flatten();
        // Flip it - Don't need to flip it right now, flip it at end of process.
        //  docRef.flipCanvas(Direction.HORIZONTAL);
        // deselect so that the paste hits 0,0 like we want it to for the animation
        docRef.selection.deselect();
        //
    
    } 
}    
// We rotated it 180 degrees so it is on the wrong side, flip canvas horizontally.
{
    app.activeDocument.flipCanvas(Direction.HORIZONTAL);
}// JavaScript Document


End result will look like so:
[t]https://dl.dropboxusercontent.com/u/11994337/Delimer/russian_military_assault_a_nml_fixed.jpg

Download: https://dl.dropboxusercontent.com/u/11994337/Delimer/Delimer.rar
(I don’t know of any other good file hosts.)

Credits for scripting go to Oisin Conolly, txanatan and myself (ViralHatred) and for testing thanks to Kali and Ninja Nub.

This has my endorsement, for whatever it’s worth

It un-fucks things that are fucked up. Good job, Viral.

ye it’s some good shit
made these nigs possible

https://dl.dropboxusercontent.com/u/44650710/rustestmw3.jpg

Since you stated that this is untested in every version of Photoshop except CS2 and CS6, I’ll go ahead and test it out with CS3. I’ve got a few models from Advanced Warfare that have bugged texture files, so I’ll see how the script functions for CS3. I’ll either edit this post or make a new one (depending on if someone else posts) after I’ve tested this in CS3 to let you know how it turns out.

[editline].[/editline]
Looks like it works for CS3 as well. Thanks, this will be useful.