Plush

SpriteCollection#

plupy · Type index

Module: plupy · obtained from plupy.data.sprites

plupy.data.sprites: images for material maps and 2D renderers, imported from files.

class SpriteCollection(DataCollection)

Inherits DataCollection: its members are documented there.

Usage and examples

Members: import_file

import_file#

import_file(path: str, *, max_size: int | None=None, pixels_per_unit: float | None=None, filter: str | None=None, mips: bool | str | None=None, srgb: bool | str | None=None, wrap: str | None=None, compression: str | None=None, border: int | tuple[int, int, int, int] | None=None) -> Sprite

Import a .png/.jpg/.jpeg/.webp image as a sprite (a texture for materials and 2D), with its import settings. A file outside the project is copied in; one already inside is registered in place, or its existing sprite returned.

Imports a .png, .jpg, .jpeg or .webp image as a sprite datablock, the same as the editor's Import texture. A file outside the project is copied in; a file already inside the project is registered where it is, and importing it again returns the existing sprite. Assign the sprite to a material map (material.baseColorMap, …) or a 2D renderer.

The keyword arguments are the texture's import settings, validated before anything is written; each one you omit keeps its current value (a new import's default):

ArgumentValuesMeaning
max_sizewhole pixels, 0 = source sizelongest imported edge, aspect kept, never enlarged
pixels_per_unitnumber, 0 = one unit widehow many pixels a Sprite Renderer 2D draws per world unit
filter"default", "nearest", "linear"sampling; sprites default to nearest, materials to linear with mips
mipsTrue/False or "default"/"on"/"off"smaller copies for distant or small drawing
srgbas mipscolour (on) or data (off) map; materials only
wrap"default", "clamp", "repeat"tiling
compression"default", "none", "bc", "bc7"GPU block compression
borderone int, or (left, top, right, bottom) pixelsnine-slice borders (needs pixels_per_unit)
panel = plupy.data.sprites.import_file("Assets/Sprites/panel.png", pixels_per_unit=64, border=24)
tile = plupy.data.sprites.import_file("Assets/Sprites/ground.png", pixels_per_unit=64, filter="nearest", wrap="repeat")

Original image files are preserved. Later edits go through sprite.set_import(...) or sprite.props["sprite.maxSize"] and support Undo. Imported pixels have a 128 MiB budget and a 16384-pixel edge limit. For an 8K square source, use max_size=4096.

DataCollection · Sprite

Source#