|
| 1 | +# Godot |
| 2 | + |
| 3 | +SpriteDicing has a [Godot](https://godotengine.org/) 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. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +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. |
| 8 | + |
| 9 | +Minimum supported Godot version: 4.6. |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +Download the plugin from the [latest release on GitHub](https://github.com/elringus/sprite-dicing/releases/latest/download/sprite-dicing-godot.zip). |
| 14 | + |
| 15 | +Unzip it under the project's `addons` folder. |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +Enable `SpriteDicing` in the project settings. |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +Create a new **DicedSpriteAtlas** resource. |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +Select a folder containing source sprite textures and click **Build Atlas**. |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +Add a **DicedSprite2D** node to your scene. |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +Set the **Atlas** and **Sprite ID** properties. |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +## Atlas Generation Options |
| 42 | + |
| 43 | +You can optionally configure atlas generation settings in the inspector. |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +| Option | Description |
| 48 | +| --- | --- | |
| 49 | +| Trim Transparent | Whether to discard fully-transparent diced units on the generated mesh. Disable to preserve original texture dimensions (usable for animations). | |
| 50 | +| Default Pivot | Relative pivot point position in 0 to 1 range, counting from the bottom-left corner. Can be changed after build for each sprite individually. | |
| 51 | +| Keep Original | Whether to use pivot set on source textures (if any) instead of default. | |
| 52 | +| Atlas Size Limit | Maximum size of a single generated atlas texture; will generate multiple textures when the limit is reached. | |
| 53 | +| Square | The generated atlas textures will always be square. Less efficient, but required for PVRTC compression. | |
| 54 | +| POT | The generated atlas textures will always have width and height of power of two. Extremely inefficient, but may be required by some older GPUs. | |
| 55 | +| Pixels Per Unit | How many pixels in the sprite correspond to the unit in the world. | |
| 56 | +| Dice Unit Size | The size of a single diced unit. | |
| 57 | +| Padding | The 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. | |
| 58 | +| UV Inset | Relative 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. | |
| 59 | +| Input Folder | Asset folder with source sprite textures. | |
| 60 | +| Include Subfolders | Whether to recursively search for textures inside the input folder. | |
| 61 | +| Separator | When sprite is from a sub-folder(s), the separator will be used to join the folder name(s) and the sprite name. | |
| 62 | + |
| 63 | +All the above descriptions are available as tooltips when hovering corresponding configuration options in the editor. |
| 64 | + |
| 65 | +## Compression Ratio |
| 66 | + |
| 67 | +When inspecting atlas asset, notice `Compression Ratio` line; it shows the ratio between source textures size and generated data (atlas textures + sprite meshes). |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +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. |
| 72 | + |
| 73 | +## Export Mode |
| 74 | + |
| 75 | +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. |
| 76 | + |
| 77 | +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. |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | +## API |
| 82 | + |
| 83 | +### DicedSpriteAtlas |
| 84 | + |
| 85 | +```gdscript |
| 86 | +# Get a sprite resource by identifer |
| 87 | +var sprite = atlas.get_sprite("sprite_id") |
| 88 | +
|
| 89 | +# Collect all sprite identifiers |
| 90 | +var ids := PackedStringArray() |
| 91 | +atlas.collect_sprite_ids(ids) |
| 92 | +``` |
| 93 | + |
| 94 | +### DicedSprite2D |
| 95 | + |
| 96 | +```gdscript |
| 97 | +# Change the displayed sprite |
| 98 | +sprite_node.sprite_id = "new_sprite" |
| 99 | +
|
| 100 | +# Change the atlas |
| 101 | +sprite_node.atlas = new_atlas |
| 102 | +``` |
| 103 | + |
| 104 | +## Building the GDExtension |
| 105 | + |
| 106 | +### Prerequisites |
| 107 | + |
| 108 | +1. **Python 3.6+** with SCons installed: |
| 109 | + ```bash |
| 110 | + pip install scons |
| 111 | + ``` |
| 112 | + |
| 113 | +2. **C++ Compiler**: |
| 114 | + - Windows: Visual Studio 2019+ with C++ workload |
| 115 | + - macOS: Xcode Command Line Tools |
| 116 | + - Linux: GCC or Clang |
| 117 | + |
| 118 | +### Build Steps |
| 119 | + |
| 120 | +1. Clone godot-cpp into the native directory: |
| 121 | + ```bash |
| 122 | + cd godot/addons/sprite_dicing/editor/native |
| 123 | + git clone https://github.com/godotengine/godot-cpp |
| 124 | + cd godot-cpp |
| 125 | + git checkout 4.6 # Match your Godot version |
| 126 | + git submodule update --init --recursive |
| 127 | + ``` |
| 128 | + |
| 129 | +2. Build the GDExtension: |
| 130 | + ```bash |
| 131 | + cd .. # Back to native directory |
| 132 | + scons target=template_release |
| 133 | + ``` |
| 134 | + |
| 135 | +3. The compiled library will be in `bin/`. |
| 136 | + |
| 137 | +## Sample Assets |
| 138 | + |
| 139 | +- [Godette by tqqq](https://tqqq.itch.io/godette-3-animations-with-psd-files) (CC-BY 3.0) |
0 commit comments