SpriteCollection#
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) -> SpriteImport 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):
| Argument | Values | Meaning |
|---|---|---|
max_size | whole pixels, 0 = source size | longest imported edge, aspect kept, never enlarged |
pixels_per_unit | number, 0 = one unit wide | how many pixels a Sprite Renderer 2D draws per world unit |
filter | "default", "nearest", "linear" | sampling; sprites default to nearest, materials to linear with mips |
mips | True/False or "default"/"on"/"off" | smaller copies for distant or small drawing |
srgb | as mips | colour (on) or data (off) map; materials only |
wrap | "default", "clamp", "repeat" | tiling |
compression | "default", "none", "bc", "bc7" | GPU block compression |
border | one int, or (left, top, right, bottom) pixels | nine-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.
Related types#
Source#
- _live.py:373