Skip to content

Commit fdaf1ed

Browse files
committed
feat(godot): add godot plugin (#50)
1 parent d0a81ec commit fdaf1ed

File tree

80 files changed

+1227
-24
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1227
-24
lines changed

docs/.vitepress/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ export default defineConfig({
5151
{ text: "API", link: "/guide/api" },
5252
{ text: "ABI", link: "/guide/abi" },
5353
{ text: "CLI", link: "/guide/cli" },
54-
{ text: "Unity", link: "/guide/unity" }
54+
{ text: "Unity", link: "/guide/unity" },
55+
{ text: "Godot", link: "/guide/godot" },
5556
]
5657
}
5758
]

docs/guide/getting-started.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Getting Started
22

3-
SpriteDicing comes in 3 forms: native C ABI library for embedding into other applications, such as game engines or frameworks, standalone CLI executable to use the tool directly and Unity game engine package.
3+
SpriteDicing comes in three forms: native C ABI library for embedding into other applications, such as game engines or frameworks, standalone CLI executable to use the tool directly and first-party plugins for the Unity and Godot game engines.
44

55
Download artifacts for the latest release via the links below:
66

@@ -20,4 +20,5 @@ For more information on how to use each type of the artifact, refer to the dedic
2020
- [Rust crate](/guide/api)
2121
- [Native C ABI library](/guide/abi)
2222
- [CLI Tool](/guide/cli)
23-
- [Unity integration](/guide/unity)
23+
- [Unity plugin](/guide/unity)
24+
- [Godot plugin](/guide/godot)

docs/guide/godot.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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+
![](https://i.gyazo.com/93aaa8ed9a9aab15841c6faaf4516fa1.png)
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+
![](https://i.gyazo.com/457436bd5ceedec8688ee38b4a84589f.png)
18+
19+
Enable `SpriteDicing` in the project settings.
20+
21+
![](https://i.gyazo.com/814b7ad9ee4c41afb1319d6088648d5b.png)
22+
23+
## Usage
24+
25+
Create a new **DicedSpriteAtlas** resource.
26+
27+
![](https://i.gyazo.com/257dfb9734d26ff55b882eb3a6fd3e3d.png)
28+
29+
Select a folder containing source sprite textures and click **Build Atlas**.
30+
31+
![](https://i.gyazo.com/f1ab20f8caff059ec475f73707d350e5.png)
32+
33+
Add a **DicedSprite2D** node to your scene.
34+
35+
![](https://i.gyazo.com/82325449a7e9021577f7def108028e29.png)
36+
37+
Set the **Atlas** and **Sprite ID** properties.
38+
39+
![](https://i.gyazo.com/fe39ca501b88f4b7e769e6be93b73419.png)
40+
41+
## Atlas Generation Options
42+
43+
You can optionally configure atlas generation settings in the inspector.
44+
45+
![](https://i.gyazo.com/7fc948fe098f8cd0b6909200162404d1.png)
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+
![](https://i.gyazo.com/80575364742301fbf5902d91972f2d4f.png)
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+
![](https://i.gyazo.com/488b2fe92ecd692708f76b66663e45f8.png)
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)

docs/guide/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
Use SpriteDicing to split a set of sprite textures into units, discard identical ones, bake unique units into atlas textures to then seamlessly reconstruct the original sprites at runtime, without actually keeping original textures in the build.
44

5-
The solution significantly reduces build size when multiple textures with identical areas are used. Consider a [visual novel](https://en.wikipedia.org/wiki/Visual_novel) type of game, where multiple textures per character are used, each portraying different emotion; most of the texture space is occupied with identical data, while only a small area varies:
5+
The solution significantly reduces the build size when multiple textures with identical areas are used. Consider a [visual novel](https://en.wikipedia.org/wiki/Visual_novel) type of game, where multiple textures per character are used, each portraying different emotion; most of the texture space is occupied with identical data, while only a small area varies:
66

77
![](https://raw.githubusercontent.com/elringus/sprite-dicing/main/docs/public/img/banner.png)
88

9-
These original five textures have total size of **17.5MB**. After dicing, the resulting atlas texture will contain only the unique areas of the original textures and consume just **2.4MB**, effectively compressing the textures by **86.3%**.
9+
These original five textures have a total size of **17.5MB**. After dicing, the resulting atlas texture will contain only the unique areas of the original textures and consume just **2.4MB**, effectively compressing the textures by **86.3%**.
1010

1111
<a href="https://naninovel.com">
1212
<p align="center">Sprite Dicing is used in <strong>Naninovel</strong> — visual novel engine. Check it out!</p>

docs/guide/unity.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Unity
22

3-
SpriteDicing has a [Unity](https://unity.com/) integration with full-fledged atlas editor. It communicates with the Rust libraries via C ABI and outputs native Unity sprite assets.
3+
SpriteDicing has a [Unity](https://unity.com/) integration with a full-fledged atlas editor. It communicates with the Rust libraries via C ABI and outputs native Unity sprite assets.
44

55
The extension package bundles pre-built binaries for Windows x64, Mac ARM and Linux x64. All the code is editor-only, so this covers all the Unity editor-supported platforms.
66

7-
Minimum supported Unity version: 2022.3. For previous Unity versions use legacy v1.x branch: https://github.com/elringus/sprite-dicing/tree/arch/v1.
7+
Minimum supported Unity version: 2022.3. For previous Unity versions use the legacy v1.x branch: https://github.com/elringus/sprite-dicing/tree/arch/v1.
88

99
## Installation
1010

@@ -16,14 +16,14 @@ https://github.com/elringus/sprite-dicing.git?path=/plugins/unity/Assets/SpriteD
1616

1717
![](/img/upm.mp4)
1818

19-
Alternatively, clone the repository and install [extension directory](https://github.com/elringus/sprite-dicing/tree/main/plugins/unity/Assets/SpriteDicing) as local package.
19+
Alternatively, clone the repository and install [extension directory](https://github.com/elringus/sprite-dicing/tree/main/plugins/unity/Assets/SpriteDicing) as a local package.
2020

2121
## Usage
2222

2323
1. Create a `DicedSpriteAtlas` asset using `Assets -> Create -> Diced Sprite Atlas` menu command, select it;
24-
2. Specify `Input Folder` — project directory, containing the source textures to process. You can drag-drop a folder from the project hierarchy window or select one with object picker;
24+
2. Specify `Input Folder` — project directory, containing the source textures to process. You can drag-drop a folder from the project hierarchy window or select one with the object picker;
2525
3. Click `Build Atlas` button and wait for the procedure to finish;
26-
4. Generated sprites will appear inside the atlas asset; drag and drop them on scene like regular sprites.
26+
4. Generated sprites will appear inside the atlas asset; drag and drop them on a scene like regular sprites.
2727

2828
![](https://i.gyazo.com/faddf19580d8e6c9e0660d61976b2bef.gif)
2929

@@ -58,7 +58,7 @@ When inspecting atlas asset, notice `Compression Ratio` line; it shows the ratio
5858

5959
![](https://i.gyazo.com/c104f864bb4ce2b33760616ced9a9276.png)
6060

61-
When close to 1 or lower, the value will be in yellow/red color indicating the generated data size is close to or even larger than the source and you should either change atlas generation configuration (eg, increase dice unit size) or not use the solution at all.
61+
When close to 1 or lower, the value will be in yellow/red color indicating 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.
6262

6363
## uGUI
6464

@@ -68,10 +68,10 @@ To use the diced sprites in with Unity UI (aka uGUI), enable `Use Sprite Mesh`.
6868

6969
## UI Toolkit
7070

71-
Diced sprites are normal Unity sprite assets and can be assigned as source for various visual UI Toolkit elements, no additional setup is required. Check "UI" scene in the [samples directory](https://github.com/elringus/sprite-dicing/tree/main/plugins/unity/Assets/Samples) for an example.
71+
Diced sprites are normal Unity sprite assets and can be assigned as a source for various visual UI Toolkit elements, no additional setup is required. Check the "UI" scene in the [samples directory](https://github.com/elringus/sprite-dicing/tree/main/plugins/unity/Assets/Samples) for an example.
7272

7373
## Animation
7474

75-
It's possible to use diced sprites for animation. Make sure to disable `Trim Transparent` when generating the atlas to preserve relative positions of the generated sprites. An example on animating diced sprites is available in "Animation" scene.
75+
It's possible to use diced sprites for animation. Make sure to disable `Trim Transparent` when generating the atlas to preserve relative positions of the generated sprites. An example on animating diced sprites is available in the "Animation" scene.
7676

7777
![](https://i.gyazo.com/9df7af39368a7b17f067a03a50c41509.gif)

docs/index.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ hero:
4141
<div class="icon">🧩️</div>
4242
<h2 class="title">Engine-agnostic</h2>
4343
</div>
44-
<p class="details">SpriteDicing is compiled into native library with C ABI making it embeddable to any game engine, framework or programming language.</p></article>
44+
<p class="details">SpriteDicing is compiled into a native library with C ABI making it embeddable to any game engine, framework or programming language.</p></article>
4545
</div>
4646
</div>
4747
<div class="grid-3 item">
@@ -51,7 +51,7 @@ hero:
5151
<div class="icon">💻</div>
5252
<h2 class="title">Standalone Tool</h2>
5353
</div>
54-
<p class="details">Alternatively, standalone CLI tool is available for Windows, macOS and Linux; it'll produce atlases and JSON with the diced sprites specs.</p></article>
54+
<p class="details">Alternatively, a standalone CLI tool is available for Windows, macOS and Linux; it'll produce atlases and JSON with the diced sprites specs.</p></article>
5555
</div>
5656
</div>
5757
</div>
@@ -63,7 +63,7 @@ hero:
6363
<div class="icon">🦀</div>
6464
<h2 class="title">Written in Rust</h2>
6565
</div>
66-
<p class="details">SpriteDicing is authored in Rust programming language for best performance and reliability.</p></article>
66+
<p class="details">The core is written in the Rust programming language for the best performance and reliability.</p></article>
6767
</div>
6868
</div>
6969
<div class="grid-4 item">
@@ -83,17 +83,17 @@ hero:
8383
<div class="icon">🛠️</div>
8484
<h2 class="title">Customizable</h2>
8585
</div>
86-
<p class="details">Has plethora of options: atlas size limit, UV inset, padding, trimming, sprite pivot and more.</p></article>
86+
<p class="details">Has a plethora of options: atlas size limit, UV inset, padding, trimming, sprite pivot and more.</p></article>
8787
</div>
8888
</div>
8989
<div class="grid-4 item">
9090
<div class="VPLink no-icon VPFeature">
9191
<article class="box">
9292
<div class="box-title">
9393
<div class="icon">🕹️</div>
94-
<h2 class="title">Unity Integration</h2>
94+
<h2 class="title">Engine Plugins</h2>
9595
</div>
96-
<p class="details">First-party plugin for Unity game engine with a dedicated editor UI; outputs native sprite assets.</p></article>
96+
<p class="details">First-party plugins for the Unity and Godot game engines with dedicated editor UIs.</p></article>
9797
</div>
9898
</div>
9999
</div>

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"devDependencies": {
99
"typescript": "5.7.2",
1010
"@types/node": "22.10.0",
11-
"vitepress": "1.5.0",
11+
"vitepress": "1.6.4",
1212
"imgit": "0.2.1"
1313
}
1414
}

0 commit comments

Comments
 (0)