Runtime Texture Atlas (RTA) + CL tool

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
EngineerSmith
Prole
Posts: 38
Joined: Thu Dec 02, 2021 11:38 am
Contact:

Runtime Texture Atlas (RTA) + CL tool

Post by EngineerSmith »

Runtime Texture Atlas, or RTA, is designed to pack your images into an atlas at runtime to help improve asset management and performance in Love!

Get the latest version from the git repo with documentation in the readme, + examples.
https://github.com/EngineerSmith/Runtime-TextureAtlas

There are two types of atlases that the library defines. Fixed Size and Dynamic Size.

A Fixed size atlas are for images that are all the same image size. All 16x16, or all 32x64, etc. It uses a homebrew algorithm, which boils down to grid packing.
A Dynamic size atlas are for any sized images. It uses a homebrew algorithm, which boils down to cell packing.

Features:
  • Easy to manage assets, no more having to update your atlas in another tool when it can be packed at runtime
  • Padding, add space between all images and the edge of the atlas
  • Extrude, extend your images using it's warp mode (See warp modes on love wiki for examples)
  • Spacing, add space between all images (no spacing between images of edge of atlas)
  • Ease of ​use, see examples in repo or the example below for how simple it is to use
  • Headless mode, can be used with pure imageData for command line tools. Create your own, or use the one provided.
Maybe you want a command line tool that uses this library? https://github.com/EngineerSmith/Export-TextureAtlas Easy to integrate into your build pipeline. You can export the quad data into any format you want, and then import it into any tool you want (not just usable love!) Note, it doesn't include parser for reading in quad data into your target tool e.g. back into love. It should be trivial to write one for the format you choose.

Why did I create this library?
I wrote this library for myself as I needed assets to be packed into a single texture at runtime for meshes. I noticed a visible gap for this kind of library within the love community and decided to attempt creating it for everyone to use. It has led me on an interesting journey that resulted in creating my own packing algorithms as ones out there solve the bin packing problem, but don't solve the rectangle packing problem. I'm proud of the results of this library and hope it brings you much use as it does for my projects.

Example:
This is a minimal example, you can find further examples in the readme's repo https://github.com/EngineerSmith/Runtime-TextureAtlas which covers more of the features of the library.

Code: Select all

local RTA = require("RTA")
local atlas = RTA.newDynamicSize()
atlas:setFilter("nearest", "nearest")
atlas:add(love.graphics.newImage("512x512.png"), "duck") -- index as any valid table index
atlas:add(love.graphics.newImage("25x1250.png"), 1)

atlas:hardBake() -- This call can take some time, but only needs to be called once on load
-- All image references are removed with hardBake and can be cleaned up by GC if they have no more references
collectgarbage("collect")

love.draw = function()
  atlas:draw("duck", 50,50, 0, 5,5) -- Draws id duck at 50,50 scaled by 5
  
  local drawID = atlas:getDrawFuncForID(1) -- Maybe you don't want to pass around the atlas and id
  drawID(500,50, math.pi) -- Draws id 1 at 500,50 rotated by pi
  
  -- Above 2 draw calls with be batched automatically by love now as they use the same image!
end
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests