Skip to content

Godot

SpriteDicing has a Godot integration with a full-fledged atlas editor. It communicates with the Rust libraries via C ABI and outputs sprite resources which can be rendered with a dedicated DicedSprite2D node.

cover

The plugin bundles pre-built binaries for Windows x64, Mac ARM and Linux x64. All the code is editor-only, so this covers all the Godot editor-supported platforms.

Minimum supported Godot version: 4.6.

Installation

Download the plugin from the latest release on GitHub.

Unzip it under the project's addons folder.

cover

Enable SpriteDicing in the project settings.

cover

Usage

Create a new DicedSpriteAtlas resource.

cover

Select a folder containing source sprite textures and click Build Atlas.

cover

Add a DicedSprite2D node to your scene.

cover

Set the Atlas and Sprite ID properties.

cover

Atlas Generation Options

You can optionally configure atlas generation settings in the inspector.

cover
OptionDescription
Trim TransparentWhether to discard fully-transparent diced units on the generated mesh. Disable to preserve original texture dimensions (usable for animations).
Default PivotRelative pivot point position in 0 to 1 range, counting from the bottom-left corner. Can be changed after build for each sprite individually.
Keep OriginalWhether to use pivot set on source textures (if any) instead of default.
Atlas Size LimitMaximum size of a single generated atlas texture; will generate multiple textures when the limit is reached.
SquareThe generated atlas textures will always be square. Less efficient, but required for PVRTC compression.
POTThe generated atlas textures will always have width and height of power of two. Extremely inefficient, but may be required by some older GPUs.
Pixels Per UnitHow many pixels in the sprite correspond to the unit in the world.
Dice Unit SizeThe size of a single diced unit.
PaddingThe size of a pixel border to add between adjacent diced units inside atlas. Increase to prevent texture bleeding artifacts (usually appear as thin gaps between diced units). Larger values will consume more texture space, but yield better anti-bleeding results. Minimum value of 2 is recommended in most cases. When 2 is not enough to prevent bleeding, consider adding a bit of UV Inset before increasing the padding.
UV InsetRelative inset of the diced units UV coordinates. Can be used in addition to (or instead of) Padding to prevent texture bleeding artifacts. Won't consume any texture space, but higher values could visually distort the final result.
Input FolderAsset folder with source sprite textures.
Include SubfoldersWhether to recursively search for textures inside the input folder.
SeparatorWhen sprite is from a sub-folder(s), the separator will be used to join the folder name(s) and the sprite name.

All the above descriptions are available as tooltips when hovering corresponding configuration options in the editor.

Compression Ratio

When inspecting atlas asset, notice Compression Ratio line; it shows the ratio between source textures size and generated data (atlas textures + sprite meshes).

cover

When around to 1.0 or lower, the generated data size is close to or even larger than the source. You should either change atlas generation configuration (eg, increase dice unit size) or not use the solution at all.

Export Mode

When exporting the project, make sure to not include the source textures. Otherwise, your build will contain both the original textures and their diced counterparts baked into the atlas textures.

Use the Export Mode to control which resources are exported. The simplest way to exclude the source textures is by changing the mode to "Export selected scenes" — this will make Godot only include the resources actually used in the selected scenes.

cover

API

DicedSpriteAtlas

gdscript
# Get a sprite resource by identifer
var sprite = atlas.get_sprite("sprite_id")

# Collect all sprite identifiers
var ids := PackedStringArray()
atlas.collect_sprite_ids(ids)

DicedSprite2D

gdscript
# Change the displayed sprite
sprite_node.sprite_id = "new_sprite"

# Change the atlas
sprite_node.atlas = new_atlas

Building the GDExtension

Prerequisites

  1. Python 3.6+ with SCons installed:

    bash
    pip install scons
  2. C++ Compiler:

    • Windows: Visual Studio 2019+ with C++ workload
    • macOS: Xcode Command Line Tools
    • Linux: GCC or Clang

Build Steps

  1. Clone godot-cpp into the native directory:

    bash
    cd godot/addons/sprite_dicing/editor/native
    git clone https://github.com/godotengine/godot-cpp
    cd godot-cpp
    git checkout 4.6  # Match your Godot version
    git submodule update --init --recursive
  2. Build the GDExtension:

    bash
    cd ..  # Back to native directory
    scons target=template_release
  3. The compiled library will be in bin/.

Sample Assets