Expand description
Sprites, rendered as UnityPy 1.25.2’s SpriteHelper renders them
(docs/plans/extract.md E17; PARITY.md section 15.2), pixel for pixel,
over a sheet crate::decode() gave.
Sheet::new: the sprite’s texture, and its alpha texture merged in where it has one (get_image,export/SpriteHelper.py:44-59).select_render_data: the render dataget_image_from_spriterenders from (:63-86), the Sprite’s own or its atlas’s.render(): one sprite’s image from its sheet, its render data (SpriteData) and, for a tight sprite, its mesh (get_image_from_sprite,:62-127).
What get_image_from_sprite does, and the order here. It crops the
sheet by textureRect (Pillow’s crop: the box’s edges compared, then
each rounded half to even, then the decompression-bomb check, then C
ints; [canvas::crop_box]); reads the settings (a rotation from 5 to
15 raises, Settings::parse); when packed, flips or turns the crop
(:100-113); for tight packing, processes the sprite’s own m_RD mesh
(:116-118) and, when its m_UV0 holds a non-zero value, renders the
first submesh’s triangles from the whole sheet (render_sprite_mesh,
:173-224), and otherwise masks the crop by every submesh’s triangles
(mask_sprite, :130-170); and flips the result top to bottom
(:127). Every check UnityPy makes raises here, as SpriteError,
in UnityPy’s order, within the bounds below. One step is not taken: the
crop is made only where a later step reads it (rectangle packing, and
the mask), since the mesh path replaces it unread; its checks are made
wherever UnityPy makes them, Pillow’s width cap on it and on its turned
size included (SpriteError::ImageTooWide).
Orientation. UnityPy decodes the sheet unflipped
(get_image_from_texture2d(texture, False), :47-58), and
crate::decode() returns a texture flipped, as Texture2D.image
gives it, so a Sheet reads its rows from the last.
Divergences (PARITY.md sections 19.2 and 19.3). A triangle whose
system meets an exactly zero pivot in numpy’s LU on the pinned kernel
copies nothing, where numpy raises LinAlgError (Tier C, affine);
three collinear destination corners need not make one, and where they
do not, the triangle is copied as UnityPy copies it. A canvas of more
than crate::MAX_PIXELS pixels is SpriteError::TooLarge, where
Pillow’s behaviour is its memory’s. A field the render reads that is
missing or of another type is SpriteError::Malformed (Tier U). Every
buffer is charged to the caller’s meter before it is allocated, and
every loop’s work counted on it before it runs (docs/plans/extract.md
E59): an image’s bytes and its rows, an empty image’s rows included,
and of the fields SpriteFields::read and select_render_data
read, each atlas, map entry, field walked and tag, a name’s comparison
by its bytes (fields); a refusal is SpriteError::Charge.
Re-exports§
pub use fields::AtlasKey;pub use fields::Guid;pub use fields::Pptr;pub use fields::RenderData;pub use fields::SpriteFields;pub use fields::atlas_render_data;pub use fields::select_render_data;
Modules§
- affine
- The affine path of
copy_triangle(export/SpriteHelper.py:271-301): the 6 x 6 systemnumpy.linalg.solvesolves for the map from the destination triangle to the source, and Pillow’s nearest-neighbour affine transform of the sheet by it. - fields
- What
get_image_from_spritereads of a Sprite and of its atlas (export/SpriteHelper.py:63-88), from aParsedobject: the Sprite’sm_PixelsToUnits,m_RD,m_SpriteAtlas,m_AtlasTagsandm_RenderDataKey, and an atlas’sm_RenderDataMapentry for the sprite’s key. - helpers
- Standalone adapters reuse the renderer’s mask, mesh and triangle operations.
Structs§
- Settings
SpriteSettings(export/SpriteHelper.py:29-40):settingsRaw’s bits.- Sheet
- What a sprite renders from (module docs): the decoded texture, or the texture with its alpha texture merged in.
- Sprite
Data - What
render()reads of a sprite: its render data’s rectangle and settings (the Sprite’sm_RD, or the atlas’sSpriteAtlasDatafor it), and the Sprite’sm_PixelsToUnits, as Pythonfloats andints.
Enums§
- Packing
Mode SpritePackingMode(enums/SpritePackingMode.py).- Rotation
SpritePackingRotation(enums/SpritePackingRotation.py).- Sprite
Error - Why a sprite did not render. Each variant but
Self::Malformed,Self::UnverifiedMode,Self::AtlasUnresolved,Self::TooLarge,Self::ChargeandSelf::Panickedis a case where UnityPy 1.25.2 raises;Self::pythongives its exception’s class and message.
Functions§
- render
- One sprite’s image (module docs):
sheetis the render data’s texture (and alpha texture),dataits rectangle and settings with the Sprite’sm_PixelsToUnits, andmeshprocesses the Sprite’s ownm_RD(MeshHandler(m_Sprite.m_RD, version).process()), called only for a tight sprite, where UnityPy calls it. The image is charged tometer, and every buffer and loop on the way; the pixel work runs undercrate::contain().