tconkling / flump

Exports Flash .FLAs to GPU-friendly formats
MIT License
381 stars 70 forks source link

How to use ATF (wiki request) #92

Open thejustinwalsh opened 10 years ago

thejustinwalsh commented 10 years ago

Anyone willing to write up how to use ATF textures and add it to the wiki.

Is it as simple as unzipping, running the atf conversion, replacing .png atlases with .atf, then zip it all back up? Do i need to reference the file extension of the atlas in the json file as well? Anything else I am missing?

roguenet commented 10 years ago

There's one other minor step: you need to change a couple things in the library.json. This is the (mac bash) script I use to convert my UI Flump archive:

#!/bin/bash

unzip flump.zip -d tmp
pushd tmp
for png in *.png; do
    echo "Converting $png..."
    TexturePacker --data tmp.plist --sheet fixed.png --border-padding 0 --shape-padding 0 \
        --reduce-border-artifacts --trim-mode None --disable-rotation --disable-auto-alias \
        --max-size 4096 $png
    mv fixed.png $png
    png2atf -q 0 -n 0,0 -i $png -o `echo $png | sed 's/\.png/.atf/'`
    rm $png
done
rm tmp.plist
cat library.json | sed 's/{/{"textureFormat":"atf",/' | sed 's/\.png/.atf/g' > library-atf.json
mv library-atf.json library.json
zip -r flump.zip *
popd
mv tmp/flump.zip flump.zip
rm -rf tmp

exit 0

As you can see on the "cat library.json..." line, I'm adding a textureFormat property to the top level object in the json, and replacing all references of .png to .atf. That's all that's required to get ATF working in a flump zip.

The additional thing I do here is the TexturePacker bit. The important bit there is the --reduce-border-artifacts. The rest of it is just to keep it from mangling the image dimensions or orientation in any way. The border artifacts thing helps an atlas with components that have transparent edges from ending up with a black halo effect at runtime, which was noticeable in some of my flump usage. The black halo is caused by a difference in how Bitmap textures vs ATF textures are used in the Stage3D runtime, specifically premultiplied alpha. More info on that particular problem: http://www.pixelenvision.com/3273/texture-packer-the-tool-that-stands-the-test-of-time/.

At any rate, you might not see a problem in your own project, or you might decide it's not bad enough to spring for the $40 TexturePacker license.

I suppose it wouldn't take much to make this into a wiki article, but I'm just going to leave it here for now. Hopefully that answers your questions. Feel free to drop any more relating to ATF in here, I'm pretty well versed with it at this point.

roguenet commented 10 years ago

Whoops, didn't mean to close it prematurely. Reopening in case there are more questions.

roguenet commented 10 years ago

Oh one other note: My UI was getting visible artifacts with the default JPEG XHR compression used by png2atf, which is why I went with -q 0. That means that the resulting .zip is actually larger than the .png version exported by Flump. It does load faster though, and it produces less junk during the library texture upload phase, which is important for my mobile project. I recommend just playing around with the -q setting to see what looks good for your project.

CodeAndWeb commented 9 years ago

Good news from my side: TexturePacker 3.5.0 now supports writing ATF directly. No need to use png2atf anymore. And you can also set the quality for PVRTC, ETC1 and DXT....