Skip to main content

Python spine atlas parsing

Project description

SpineAtlas

Modify atlas data and export frames or convert other atlas-like data to spine atlas

Installation

Install the latest version of SpineAtlas from PyPI:

pip install SpineAtlas

Usage

Opening and saving atlas

from SpineAtlas import ReadAtlasFile

atlas = ReadAtlasFile('1.atlas')
# The code will automatically determine the format of Atlas
atlas.version = False # Convert to Atlas 3.0 format
atlas.version = True # Convert to Atlas 4.0 format
atlas.SaveAtlas('1_v4.atlas')

Check if the atlas is missing a textures

from SpineAtlas import ReadAtlasFile

atlas = ReadAtlasFile('1.atlas')
# If the texture and atlas are in the same directory, you don't need to pass the path
miss = atlas.CheckTextures()
# If `miss` is empty, it means there is no missing textures

Modify the texture scaling of the atlas

from SpineAtlas import ReadAtlasFile

atlas = ReadAtlasFile('1.atlas')
# If the texture and atlas are in the same directory, you don't need to pass the path
atlas.ReScale()
atlas.SaveAtlas('1_scale.atlas')

Export atlas frames

from SpineAtlas import ReadAtlasFile

atlas = ReadAtlasFile('1.atlas')
# If the texture and atlas are in the same directory, you don't need to pass the texture path
# mode : ['Normal', 'Premul', 'NonPremul']
# --- Normal - do not process the texture
# --- Premul - convert the texture to premultiplied
# --- NonPremul - convert the texture to non-premultiplied
atlas.SaveFrames(path='1_frames', mode='Premul')

Convert other formats to Spine Atlas

from SpineAtlas import Atlas, AtlasTex, AtlasFrame

'''
{
Texture:
    Texture_Name: str
    Texture_Wdith: int
    Texture_Height: int
	
Frame:
[
    [
    Frame_Name: str
    Cut_X: int
    Cut_Y: int
    Cut_Wdith: int
    Cut_Height: int
    Original_X: int
    Original_Y: int
    Original_Wdith: int
    Original_Height: int
    Rotate: int
    ],
    ...
]
}
'''
TextureDict = {...}
frames = []
for i in TextureDict['Frame']:
    frames.append(AtlasFrame(i['Frame_Name'], i['Cut_X'], i['Cut_Y'], i['Cut_Wdith'], i['Cut_Height'], i['Original_X'], i['Original_Y'], i['Original_Wdith'], i['Original_Height'], i['Rotate']))
tex = TextureDict['Texture']
texture = AtlasTex(tex['Texture_Name'], tex['Texture_Wdith'], tex['Texture_Height'], frames=frames)
atlas = Atlas([texture])
atlas.SaveAtlas('1.atlas')

Recalculate the clipping anchor point

from SpineAtlas import ReadAtlasFile, Anchor

'''
class Anchor(IntEnum):
    TOP_LEFT = 1
    TOP_CENTER = 2
    TOP_RIGHT = 3
    CENTER_LEFT = 4
    CENTER = 5
    CENTER_RIGHT = 6
    BOTTOM_LEFT = 7
    BOTTOM_CENTER = 8
    BOTTOM_RIGHT = 9
'''

atlas = ReadAtlasFile('1.atlas')
# The default anchor point for Spine Atlas clipping is the top left corner
atlas.cutp = Anchor.BOTTOM_LEFT
atlas.ReOffset() # Recalculate clipping X/Y starting from the upper left corner
atlas.SaveAtlas('1_1_ReOffset.atlas')

Recalculate the Offset anchor point

from SpineAtlas import ReadAtlasFile, Anchor

'''
class Anchor(IntEnum):
    TOP_LEFT = 1
    TOP_CENTER = 2
    TOP_RIGHT = 3
    CENTER_LEFT = 4
    CENTER = 5
    CENTER_RIGHT = 6
    BOTTOM_LEFT = 7
    BOTTOM_CENTER = 8
    BOTTOM_RIGHT = 9
'''

atlas = ReadAtlasFile('1.atlas')
# The default anchor point for Spine Atlas Offset is the bottom left corner
atlas.offp = Anchor.TOP_LEFT
atlas.ReOffset() # Recalculate Offset X/Y starting from the bottom left corner
atlas.SaveAtlas('1_1_ReOffset.atlas')

Convert image to premultiplied/non-premultiplied

from PIL.Image import open as imgop
from SpineAtlas import ImgPremultiplied, ImgNonPremultiplied

img = imgop('1.png')

tex = ImgPremultiplied(img)
tex.save('1_premultiplied.png')

tex = ImgNonPremultiplied(img)
tex.save('1_non-premultiplied.png')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spineatlas-1.0.12.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spineatlas-1.0.12-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file spineatlas-1.0.12.tar.gz.

File metadata

  • Download URL: spineatlas-1.0.12.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spineatlas-1.0.12.tar.gz
Algorithm Hash digest
SHA256 91b7ec2c3f673e27e167cae77d411c068daef295686baa37aca926f9a394947d
MD5 999597e3d11e7c09154f0db0dda64639
BLAKE2b-256 523bc135e11156b375b0be57253b2d292e689a6e3f19bce02845c50a50a9b621

See more details on using hashes here.

File details

Details for the file spineatlas-1.0.12-py3-none-any.whl.

File metadata

  • Download URL: spineatlas-1.0.12-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spineatlas-1.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 a4dc8efa1a009612ed44b143f04028aab8f4291ef43e5df8bf83993846b84ff2
MD5 d485a90caff629261243f6357057d178
BLAKE2b-256 b5ae48570ae0996b339fc941c8967188018955d7df8d631477c8f04b26949c71

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page