Makeatlas - simple tool to pack a texture atlas

Monkey Forums/Monkey Programming/Makeatlas - simple tool to pack a texture atlas

Skn3(Posted 2013) [#1]
MakeAtlas is a tool for creating packed textures.

Version 1.11
- added projects
- added batch build option
- improved result reporting
- cleaned up weird use of registry and xml for settings
- removed save/load settings


http://www.skn3.com/junk/makeatlas/makeatlas1.11.zip


Enjoy, for free :D


Features:
- XML, JSON, Sparrow, LibGDX
- multiple import paths
- multiple texture pages
- image trimmming
- projects
- import PNG/JPEG
- image bleeding


therevills(Posted 2013) [#2]
Cool! Have you used any format standard (Sparrow etc) or just made it up yourself?


Amon(Posted 2013) [#3]
Nice!


therevills(Posted 2013) [#4]
Just played with it and its good... it'll be better if you could select multiple folders.

And maybe get it to output standard XML like Sparrow so we don't have to recode our apps ;)


Nobuyuki(Posted 2013) [#5]
This is a kickass thing. I haven't tested it yet, but one thing I can think of is that it would be nice to have the source available so that we can write our own exporters! Seems it would solve people's "standard" XML issue and anyone else who want a metadata format that this thing doesn't do. And every other feature, of course ;)

Anyway, when I get a chance, I'll check what kinda formats this thing outputs here -- I'm presuming this uses your rect packing algo? I was actually going to use that to write my own texture packer app (in VB.NET), since the one we use in our projects kinda really sucks (and I don't know who made it). Already have a pretty nice TextureAtlas class that I'd like to release with a nice packer like this as a bit of a 1-2 combo for the average monkeycoder's toolbox, but it uses some wacky plaintext metadata format that probably no one else uses.

So yeah, when you can call this complete, source please, if it's not too much trouble :)


Skn3(Posted 2013) [#6]
Hey,

I will look at this on Monday when back to work and see what's doable. Unfortunately I can't really release this open source. I'd like to, to get support, but it includes some some stuff which I spent a lot of time on such as an image toolkit module (for building the images)... That has lots of stuff that can't really be open sourced.

What does the sparrow format look like? I could potentially post the abstract exporter class if people wanted to extend that?

I'll definitely look at adding multi file/folder support.

I originally had this a tool for converting existing bitmap fonts to a better packed system with more character data pre baked... It ended up being converted to a texture builder. It is for a spine animation lib I am writing for monkey. Should be released soon!

... Ironically it is using code from Objecty for the packing and such, but as long as it goes to good use to support monkey users...


therevills(Posted 2013) [#7]
What does the sparrow format look like?

This was generated by TexturePacker with the output of Sparrow:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with TexturePacker http://texturepacker.com-->
<!-- $TexturePacker:SmartUpdate:6530f0775c39afcf7a22c327e6bea36a$ -->
<TextureAtlas imagePath="monster.png">
    <SubTexture name="mon_arms/forearm_0" x="417" y="354" width="84" height="108"/>
    <SubTexture name="mon_arms/forearm_a" x="220" y="734" width="99" height="78"/>
    <SubTexture name="mon_arms/hand_0_0" x="2" y="657" width="110" height="117"/>
    <SubTexture name="mon_arms/hand_0_1" x="114" y="597" width="110" height="117"/>
    <SubTexture name="mon_arms/hand_0_2" x="2" y="538" width="110" height="117"/>
    <SubTexture name="mon_arms/hand_0_3" x="138" y="478" width="110" height="117"/>
    <SubTexture name="mon_arms/hand_a_0" x="405" y="622" width="104" height="113"/>
    <SubTexture name="mon_arms/hand_a_1" x="2" y="776" width="104" height="113"/>
    <SubTexture name="mon_arms/hand_a_2" x="114" y="716" width="104" height="113"/>
    <SubTexture name="mon_arms/hand_a_3" x="226" y="619" width="104" height="113"/>
    <SubTexture name="mon_arms/shoulder_0" x="138" y="382" width="114" height="94"/>
    <SubTexture name="mon_arms/shoulder_a" x="332" y="619" width="71" height="115"/>
    <SubTexture name="mon_head/head_0" x="2" y="221" width="144" height="151"/>
    <SubTexture name="mon_head/head_1" x="294" y="201" width="144" height="151"/>
    <SubTexture name="mon_head/head_2" x="148" y="68" width="144" height="151"/>
    <SubTexture name="mon_head/head_3" x="2" y="68" width="144" height="151"/>
    <SubTexture name="mon_legs/foot_0" x="148" y="221" width="139" height="159"/>
    <SubTexture name="mon_legs/foot_a" x="2" y="374" width="134" height="162"/>
    <SubTexture name="mon_legs/pelvis_0" x="254" y="468" width="110" height="149"/>
    <SubTexture name="mon_legs/thigh_0" x="417" y="464" width="81" height="156"/>
    <SubTexture name="mon_legs/thigh_a" x="289" y="354" width="126" height="112"/>
    <SubTexture name="mon_shadows/shadow_idle" x="2" y="2" width="321" height="64"/>
    <SubTexture name="mon_torso/torso_0" x="325" y="2" width="180" height="197"/>
</TextureAtlas>


Nice and simple ;)


Skn3(Posted 2013) [#8]
Updated to version 1.0

- Added support for multiple import files/folders
- Added ability to export to sparrow format
- Added ability to specify if texture should be split across multiple pages
- Added ability to automatically trim blank alpha space from images
- Added ability to save and load settings to a file

Let me know if you spot any bugs.

If your interested in writing an exporter for a format that isn't yet supported, here is an example of two exporters...

json exporter


sparrow xml exporter



Skn3(Posted 2013) [#9]
Small update:
Added option to specify if PNG and JPEG should be imported
Added option to prefix atlas item names with source folder name


Soap(Posted 2013) [#10]
This is great! You should give a free version away which can only make 1 texture at a time, and then charge like at least $5 for a "pro" version which can export multiple pages. Better than doing a donation option - you will get a lot of buyers! Seriously, please charge some money!


Skn3(Posted 2013) [#11]
Surely it would be best to keep it free for everyone :) ?


GfK(Posted 2013) [#12]
Surely it would be best to keep it free for everyone :) ?
Better for them - not better for you. If you've got something with value, why give it away?

I paid £20 quite recently for TexturePacker Pro, and did so knowing that I did not need 99% of it's features - just wanted something to efficiently pack textures and spit out an image and corresponding XML file (which I wrote my own loader for in about half an hour).


Skn3(Posted 2013) [#13]
Ok interesting, so what features would you require in Make Atlas to make it worth say a £10 note?

Command line support?
Custom Exporters?
Atlas Preview?
Mask Color Removal?
Mac?
Linux?
Any other ideas?

The issue is if I start doing this it would become a product that takes a lot more than the days worth of work that this has taken. But I guess I'll see what interest there is and what ideas people have.


Soap(Posted 2013) [#14]
As is I'd pay you £10 for this. With multi page support your tool already has more value to me than TPP. None of those suggestions to me mean more value. Possibly what would be really worth it to me would be to have options to interface with pngout, and have multifolder support following a "recipe" file with certain steps. I'm going to e-mail you a script which may inspire you for more ideas.

No, free is not better for us, unless we were all making free software. Many of us are commercial developers and we would prefer you were supported for the work you did, because it means you can actually keep doing it.

I'd only request you make sure it work perfectly with your Spine port!


therevills(Posted 2013) [#15]
Since I already own TexturePacker of course I wouldn't buy this, but that's not saying there isn't a market out there for it.

As you known £10 isn't $10...

So you got to either add a lot to compete with TexturePacker or do a cut down version. Have a look at all the features of TexturePacker and there are a lot there and see what you can do for a decent price point.


Soap(Posted 2013) [#16]
AFAIK TexturePacker still (I requested it long ago) doesn't support multiple pages, so I never bought it, because that's crucial for me. Not going to hold my breath that they will finally support this feature. £10 = $15.56 USD, which is fair (TPP is double that). I'd personally still pay more for this. It already does all of the things I really need, while TPP does a lot of things I don't. Still, I'm not everyone, and some people have different needs. Charging a high price is good for everyone as long as you provide the value to match or even be above the price. The higher the value vs the price the easier it is for people to impulsively purchase. Products become bloated with features... because people connect number of features with value... even if they would only ever use a few of the available features ever.


Milky Joe(Posted 2013) [#17]
I'd happily pay for a Mac version.


Skn3(Posted 2013) [#18]
Well the texture packing part of objecty is like 95% complete with stuff like custom exporters (lua) multiple pages, trimming, custom data, hotspots, image slicing, animated image import, visual editor, etc...

But it's a tricky one as it could take a week to wrap up or maybe a month.

I think tbh even though it's not sensible for me I'd rather provide a simple useful tool for people for free that does the job with no messing about. Will definitely have to visit objecty again at some point in the future though...

Call me crazy :D


Why0Why(Posted 2013) [#19]
I will wind up using this. I just want to say that I really appreciate your contributions here. The general all around things you provide like this and the XML module are great.

Anytime you are in the neighborhood, dinner and drinks on me ;)


Skn3(Posted 2013) [#20]
hah no problemo ;) mines an Ale of local variety please!


Why0Why(Posted 2013) [#21]
Hey John,

I am trying to parse your XML output so that I can add this to fantomEngine. No matter what I do I can't get it to read anything. I also can't get your XML samples to work. It comes up and tells me how many ms it took to parse but I can't get it to read any of the atlas attributes. Can you give me a hand?

Thanks!


Skn3(Posted 2013) [#22]
Hey Eric,

Hmm not sure whats going on there? What are you using to parse the xml?

http://monkeycoder.co.nz/Community/posts.php?topic=4125

this?

Post your xml file here as well if you dont mind?


Why0Why(Posted 2013) [#23]
Yep, using your XML module.

Here is the xml:




Skn3(Posted 2013) [#24]
Well the XML looks normal, what about the code you are doing to read the xml in?

Make sure you have updated to the latest version of the XML module as I fairly recently added the ability for it to read tags that are self closing
e.g
<blah id="123" />

I suspect that this might be the cause, the older version of module doesn't see the atlas items described in this self-closing way.


Why0Why(Posted 2013) [#25]
Edit: Got the samples working with the updated XML. Can you give me a sample of how you would pull out the info listed in the above XML using your module?

Thanks!


Skn3(Posted 2013) [#26]
Like this (not tested)



Why0Why(Posted 2013) [#27]
I can't seem to get the example to work. Thanks for putting it up. It gives me an idea of how it should work.


Skn3(Posted 2013) [#28]
Hey Eric,

I potentially got the example wrong by specifying "path" in the ParseXML function. You should pass in the xml data instead by loading it with LoadString(path) first.

Check the repo I have added this as a working example3.monkey

Also note there is a sheet.GetChildAtPath("items/item") which can be used instead of sheet.GetChild("items").GetChild("item")

It shouldn't make much difference performance-wise, but out of personal preference I tend to not use the path option.


ziggy(Posted 2013) [#29]
Is there any chance that the tool ignores if I uncheck the remove transparent pixels flag? Not sure if there's a bug in my code, or in the tool


Why0Why(Posted 2013) [#30]
John,

I actually was trying to use the path option and tried it multiple ways.

Mike added Sparrow format to fantomEngine after me bugging him, so I can use the tool and it is supported now. I was just going to add support myself with XML. I intend to use XML to store data for the game that I am working on so the example was helpful.

Thanks for taking the time! The community here really makes life better by being so helpful for coders such as myself that aren't so advanced.

Eric


Skn3(Posted 2013) [#31]
Ziggy:
Just tested it now and transparent pixels on/off worked for me. Do you have a test case I could have to try it out on my machine?

Eric:
No problem :D glad my contributions are helping out the monkey community!


ziggy(Posted 2013) [#32]
Yes, I could send it to you tomorrow. the thing is I have a Spine animation and files, I export everything (spine and this tool) and the animation has some srites missplacedm and seems to be moved exactly the amount of transparent pixels. I don't have the project here, but I could send you the files tomorrow if I ensure there's something wrong.


Tibit(Posted 2013) [#33]
TexturePacker have now started crashing on me so I wanted to try this, but I see no importer code? I assume *everyone* using this is using an importer?

Like the one for texture packer?
Local image:Image = TexturePack.Get("button") 'where 'button' is 'button.png' loaded into the Atlas.

Or should I look for a Sparrow Importer for TexturePacker?

EDIT - After coding a xml importer halfway through I managed to get Texture Packer to work again - I had a .txt file among the images in the folder and this made it crash...


Skn3(Posted 2013) [#34]
Could you post an example of the texture packer output? When I look at fixing the bug reported by Ziggy could also add in support for reading files of that format.


Tibit(Posted 2013) [#35]
Do you mean that MakeAtlas could export to the same format as texture packer? Or Maybe I misunderstood?

If so here is how texture packer output looks like that I can import into Monkey:


Code below import txt above into Monkey. Result is this:

Local textureLoader:TextureLoader = LoadAtlas("atlas.png")

Local image:Image = textureLoader.Grab("star",, Image.MidHandle) 'assuming an image called 'star.png' was packed.



Skn3(Posted 2013) [#36]
Yeah perfect, will look at adding that as an export option. Thanks.


Skn3(Posted 2013) [#37]
Hey Tibit,

Bit confused with this. What Data Format do you have selected in Texture Packer to get this output?

I started an exporter for MakeAtlas and then wanted to understand what the index value was for in your posted data. But I am not sure which format you were using to get that output?


Tibit(Posted 2013) [#38]
It is called LibGDX.

I have no preference in using it except someone programmed an working importer for it in Monkey :)

So if it is easier for you to make an importer, or maybe someone already have made more than this one then that is just as good.


Why0Why(Posted 2013) [#39]
Mike added and importer to FantomEngine that you can look at. I am using it with this tool and it works great.


Skn3(Posted 2013) [#40]
Thanks for the LibGDX pointer. So I did this on my lunch break, and also fixed a bug I noticed the other day.

Updated to Version 1.02
- Added LibGDX exporter
- Fixed bug when multiple files were dragged onto the window


The LibGDX format exports like so:
'each page is seperated by an empty blank line
'index for region relates to original filename of image...
'if original region filename was my_sprite_6 then the region name would be my_sprite and the index would be 6
'otherwise teh index will be -1
rem
page_1.png
format: RGBA8888
filter: Linear,Linear
repeat: none
region1
  rotate: false
  xy: 2, 147
  size: 159, 76
  orig: 159, 76
  offset: 0, 0
  index: -1
region2
  ...
  ...
  
page_2.png
format: RGBA8888
...
...



dragon(Posted 2013) [#41]
i miss a feature to extend image pieces by extra pixels of same colors.

this is usefull for seamless tiling.
otherwise you will see some space between tiles

empty space between tiles is bad


like this "EXTRUDE":
http://www.codeandweb.com/texturepacker/documentation


Raph(Posted 2013) [#42]
I have a set of tiles that are texture variants output by a tool I wrote (it's alphablend tiles for smooth tile blending). The other tool outputs the files as tile_1.png, tile_2.png, etc.

Looks to me from the makeatlas output that those endings are getting eaten off?

perlinatlastest_0.png
format: RGBA8888
filter: Linear,Linear
Repeat: none
dirt
  rotate: False
  xy: 4, 522
  size: 64, 64
  orig: 64, 64
  offset: 0, 0
  index: -1
dirt
  rotate: False
  xy: 4, 588
  size: 64, 64
  orig: 64, 64
  offset: 0, 0
  index: 10
dirt
  rotate: False
  xy: 4, 654
  size: 64, 64
  orig: 64, 64
  offset: 0, 0
  index: 11
dirt
  rotate: False
  xy: 4, 720
  size: 64, 64
  orig: 64, 64
  offset: 0, 0
  index: 2


I am going to change the other tool's filename convention anyway, but thought you'd like to know.


Wylaryzel(Posted 2013) [#43]
I'm already a fan of the tool :-) It makes my life a lot easier. If you are still working on improvements/changes would it be possible to include the following:

* Add image files (png/jpeg) from subfolders and not only from the selected folder(s)?
* Currently the tool is organizing the images (if they are all the same size) down a column, then a a row, then down a column again, than again a row - would it be possible if the tool identifies no opportunity to better organize the atlas that it is always add the images into the same order?
* Would it be possible to have some 'sort' buttons next to the folder/files? If I wrongly add a folder, its currently a bit cumbersome to add a folder in the middle of an already established list (if I use the XML importer or something like this it wouldn't be a issue, but if I use a self-made importer that has to rely on a particular order in the file itself its a bit more complicated) :-)


Even without the mentioned changes above, it is already an timesaver without question :-) thx for releasing it for 'free' :-)

Br
Wyl


Raph(Posted 2013) [#44]
I'd like to second the idea of "extrude." I'm definitely running into picking problems where images are getting inaccuracies along the edges.


Skn3(Posted 2013) [#45]
Looks to me from the makeatlas output that those endings are getting eaten off?


This is a feature of the sparrow exporter. Notice that the "index" value per item represents the "_x".


Re improvements:

Perhaps its time to charge a little fee for this tool then?

If I added a few more features and charged say £10 would that be acceptable to people? It is not what I originally wanted to do, but if you want more features then what do people think?


Wylaryzel(Posted 2013) [#46]
From my perspective, if the few additions are added to the tool that enhances my productivity I'm more than happy to pay 10 bucks :-)


Skn3(Posted 2014) [#47]
Inbetween spluttering with manflu I managed to get a small update done for this.

Version 1.03
- fixed small typos for loading/saving certain settings
- added ability to bleed image edges

http://www.skn3.com/junk/makeatlas/makeatlas.zip


ziggy(Posted 2014) [#48]
I supose 10 for a tool like this one is a reasonable price. Have you considered to make it scriptable so it can be "called" from batch processes?


Sammy(Posted 2014) [#49]
Nice.

Sorry to hear you have the flu though.

BTW what GUI did you use here Skn3?


Skn3(Posted 2014) [#50]
I supose 10 for a tool like this one is a reasonable price. Have you considered to make it scriptable so it can be "called" from batch processes?


Not sure how to make a windows gui app also function as a command app? Don't think its possible, how would I output to the console to inform the calling app?

Nice.

Sorry to hear you have the flu though.

BTW what GUI did you use here Skn3?


*cough splutter* lol

Its using MAXGUI for blitzmax ( http://www.blitzbasic.com )


ziggy(Posted 2014) [#51]
Not sure how to make a windows gui app also function as a command app? Don't think its possible, how would I output to the console to inform the calling app?
If it's BlitzMax (as I *think*), use Print to write to the standardiopipe. You could just print "ok" or "error" and exit with a given error level (0 if all worked properly). Print works too on Gui apps, it just that the console is hidden (in windows at last, I guess it's the same on MacOs and *nix)


Skn3(Posted 2014) [#52]
Does this help?

(I read up a bit and it seems you cant have an exe be both console and gui, so I improved the functionality of the app to add batch building)

Version 1.1
- added projects
- added batch build option
- improved result reporting
- cleaned up weird use of registry and xml for settings
- removed save/load settings


http://www.skn3.com/junk/makeatlas/makeatlas1.1.zip



Skn3(Posted 2014) [#53]
Small fix where copying atlas was not copying source paths

http://www.skn3.com/junk/makeatlas/makeatlas1.11.zip


ziggy(Posted 2014) [#54]
(I read up a bit and it seems you cant have an exe be both console and gui, so I improved the functionality of the app to add batch building)
Yes, that's true but the diference is that a gui app won't show a console, not that the standard i/o pipe won't be getting information, so when it is automated form any other process, the standard pipes can also be read without any problems. That's how blitzMax and Monkey debugger works, so it's a non issue if you ever want to take a look to it.


Skn3(Posted 2014) [#55]
Yes, that's true but the diference is that a gui app won't show a console, not that the standard i/o pipe won't be getting information, so when it is automated form any other process, the standard pipes can also be read without any problems. That's how blitzMax and Monkey debugger works, so it's a non issue if you ever want to take a look to it.


I will take a look, wasn't able to get GUI app to output to console though. Print("blah") output to the debugger console, but when run from command line, no show. Any idea how to get around this?


Pharmhaus(Posted 2014) [#56]
WriteStdout("Hello without line feed~n")
WriteStderr("Error without line feed~n")
exit_ -1 ' What to return to the operating system

You could try these, not sure if they help you.
EDIT: don't seem to work...
EDIT2: It doesn't display anything in the commandline but works fine when you use TProcess to launch/read things. Please note that it performs a readline operation which requires a "~n" in the writestdout/err
SuperStrict

Local Path:String = "C:\Users\Laptop\Desktop\Stuff\exitthings.exe"
Local App:TProcess = TProcess.Create(Path,0) ' 0 = no cmd window

If App<>Null Then
	While App.Status() <> 0 ' 1 while process is running, 0 when done
	    Local errcode:String = App.err.ReadLine()
	    Local outcode:String = App.pipe.ReadLine()
	    If outcode <> "" Then Print outcode
	    If errcode <> "" Then Print errcode 
	Wend
Else
	RuntimeError "Could not launch process for application "+Path
EndIf




Skn3(Posted 2014) [#57]
Hey,

Thanks for the input. I think this is what print() is doing anyway. The issue is if I am making a command line app, I need some way to inform the console or calling process that the operation has succeeded/failed. Having this only work when called from certain situations doesn't seem like a good solution to me......

Thinking about it, it seems my best option wood be to compile two versions of the app. It seems there is not a clean way in windows to have a windows app that can also operate as a fully working console app.

Unless someone else can shed some light?

Another option is that I could let a batch file operate from comand line, and then it would just show a result window upon completion?

Not really batch file friendly though...


Nobuyuki(Posted 2014) [#58]
use standard in/out/error to inform calling app. Batch files and other programs can then utilize it a lot better/easier

http://en.wikipedia.org/wiki/Standard_streams


Skn3(Posted 2014) [#59]
small update

version 1.12

http://www.skn3.com/junk/makeatlas/makeatlas1.12.zip

- made it so new project is empty
- fixed so new project wipes previous saved path, so we can save afresh
- added save warning when exiting the app
- fixed so import routine uses correct source paths folder
- fixed so images bleed all the time, sometimes were not bleeding if certain setting combination was selected



Skn3(Posted 2014) [#60]
Thanks for the pointers. When I get a chance to look at doing command line support I will check it out.


mouser(Posted 2014) [#61]
Thanks for that.