mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 14:38:34 +01:00
removed utility scripts
This commit is contained in:
parent
543560feac
commit
4e3d5705a4
3 changed files with 1 additions and 87 deletions
|
@ -31,7 +31,7 @@ namespace MLEM.Data {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// To see a Data Texture Atlas in action, you can check out the sandbox project: https://github.com/Ellpeck/MLEM/blob/main/Sandbox/Content/Textures/Furniture.atlas.
|
/// To see a Data Texture Atlas in action, you can check out the sandbox project: https://github.com/Ellpeck/MLEM/blob/main/Sandbox/Content/Textures/Furniture.atlas.
|
||||||
/// Additionally, if you are using Aseprite, there is a script to automatically populate it: https://github.com/Ellpeck/MLEM/blob/main/Utilities/Populate%20Data%20Texture%20Atlas.lua.
|
/// Additionally, if you are using Aseprite, there is a script to automatically populate it: https://gist.github.com/Ellpeck/e597c1412465c10f41a42050ec117ea2.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class DataTextureAtlas {
|
public class DataTextureAtlas {
|
||||||
|
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
"""
|
|
||||||
This script prints out a <CharacterRegions> xml element that contains efficiently calculated regions for
|
|
||||||
all of the font's supported unicode characters. Pass the font file (not the spritefont xml) as an argument.
|
|
||||||
This script requires FontTools. Install using: pip install fonttools
|
|
||||||
"""
|
|
||||||
|
|
||||||
""" The amount of characters that can be missing in a sequence to still put them in one region """
|
|
||||||
leeway = 0
|
|
||||||
|
|
||||||
from fontTools.ttLib import TTFont
|
|
||||||
from sys import argv
|
|
||||||
|
|
||||||
|
|
||||||
def print_region(start, end):
|
|
||||||
print(f" <CharacterRegion>")
|
|
||||||
print(f" <Start>&#{start};</Start>")
|
|
||||||
print(f" <End>&#{end};</End>")
|
|
||||||
print(f" </CharacterRegion>")
|
|
||||||
|
|
||||||
|
|
||||||
# get all supported characters and sort them
|
|
||||||
ttf = TTFont(argv[1])
|
|
||||||
chars = list(set(y[0] for x in ttf["cmap"].tables for y in x.cmap.items()))
|
|
||||||
chars.sort()
|
|
||||||
ttf.close()
|
|
||||||
|
|
||||||
# split them into regions based on the leeway
|
|
||||||
start = -1
|
|
||||||
last = 0
|
|
||||||
total = 0
|
|
||||||
print("<CharacterRegions>")
|
|
||||||
for char in chars:
|
|
||||||
if char - last > leeway + 1:
|
|
||||||
if start != -1:
|
|
||||||
print_region(start, last)
|
|
||||||
total += last - start + 1
|
|
||||||
start = char
|
|
||||||
last = char
|
|
||||||
# print the remaining region
|
|
||||||
print_region(start, last)
|
|
||||||
total += last - start + 1
|
|
||||||
print("</CharacterRegions>")
|
|
||||||
|
|
||||||
print(f"The font contains {len(chars)} characters")
|
|
||||||
print(f"The spritefont will contain {total} characters")
|
|
|
@ -1,41 +0,0 @@
|
||||||
-- This is a lua script for Aseprite that allows automatically populating a MLEM.Data Data Texture Atlas.
|
|
||||||
-- To use this script, you need to select a rectangular area that should be your texture region.
|
|
||||||
-- If you want a custom pivot point, you also need to un-select exactly one pixel, the pivot point.
|
|
||||||
-- When you then execute the script and input the name of the texture region, it gets appended to the "SpriteName.atlas" file.
|
|
||||||
|
|
||||||
-- get the currently selected sprite
|
|
||||||
local selection = app.activeSprite.selection
|
|
||||||
if selection == nil then return end
|
|
||||||
local bounds = selection.bounds
|
|
||||||
|
|
||||||
local loc = "loc "..bounds.x.." "..bounds.y.." "..bounds.width.." "..bounds.height.."\n"
|
|
||||||
local piv = ""
|
|
||||||
|
|
||||||
-- find the pivot point, which should be the only de-selected pixel in the selection
|
|
||||||
for x = bounds.x, bounds.x + bounds.width - 1 do
|
|
||||||
for y = bounds.y, bounds.y + bounds.height - 1 do
|
|
||||||
if not selection:contains(x, y) then
|
|
||||||
piv = "piv "..x.." "..y.."\n"
|
|
||||||
goto foundPivot
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
::foundPivot::
|
|
||||||
|
|
||||||
-- open the name dialog
|
|
||||||
local dialog = Dialog("Populate Data Texture Atlas")
|
|
||||||
:entry{ id = "name", label = "Region Name", focus = true }
|
|
||||||
:button{ id = "ok", text="&OK" }
|
|
||||||
:button{ text = "&Cancel" }
|
|
||||||
dialog:show()
|
|
||||||
|
|
||||||
local data = dialog.data
|
|
||||||
if not data.ok then return end
|
|
||||||
local name = data.name
|
|
||||||
|
|
||||||
-- get the atlas file and write the data to it
|
|
||||||
local spriteFile = app.activeSprite.filename
|
|
||||||
local atlas = spriteFile:match("(.+)%..+")..".atlas"
|
|
||||||
local file = io.open(atlas, "a")
|
|
||||||
file:write("\n"..name.."\n"..loc..piv)
|
|
||||||
file:close()
|
|
Loading…
Reference in a new issue