inksim 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- inksim-0.1.0/LICENSE +18 -0
- inksim-0.1.0/PKG-INFO +345 -0
- inksim-0.1.0/README.md +311 -0
- inksim-0.1.0/pyproject.toml +31 -0
- inksim-0.1.0/pyproject.toml.orig +30 -0
- inksim-0.1.0/src/inksim/__init__.py +6 -0
- inksim-0.1.0/src/inksim/inksim.py +2733 -0
inksim-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
GNU GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2026 Tony Karnigen
|
|
5
|
+
|
|
6
|
+
InkSim is free software: you can redistribute it and/or modify it under the
|
|
7
|
+
terms of the GNU General Public License as published by the Free Software
|
|
8
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
9
|
+
version.
|
|
10
|
+
|
|
11
|
+
InkSim is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
12
|
+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
13
|
+
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
The full text of the GNU General Public License is available at
|
|
16
|
+
<https://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
SPDX-License-Identifier: GPL-3.0-or-later
|
inksim-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: inksim
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Interactive embroidery simulator
|
|
5
|
+
Author: Tony Karnigen
|
|
6
|
+
License: GNU GENERAL PUBLIC LICENSE
|
|
7
|
+
Version 3, 29 June 2007
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2026 Tony Karnigen
|
|
10
|
+
|
|
11
|
+
InkSim is free software: you can redistribute it and/or modify it under the
|
|
12
|
+
terms of the GNU General Public License as published by the Free Software
|
|
13
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
14
|
+
version.
|
|
15
|
+
|
|
16
|
+
InkSim is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
17
|
+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
18
|
+
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
19
|
+
|
|
20
|
+
The full text of the GNU General Public License is available at
|
|
21
|
+
<https://www.gnu.org/licenses/>.
|
|
22
|
+
|
|
23
|
+
SPDX-License-Identifier: GPL-3.0-or-later
|
|
24
|
+
Requires-Dist: wxpython==4.2.5
|
|
25
|
+
Requires-Dist: numba
|
|
26
|
+
Requires-Dist: numpy
|
|
27
|
+
Requires-Dist: pillow
|
|
28
|
+
Requires-Dist: pystitch==1.0.0
|
|
29
|
+
Requires-Python: >=3.12
|
|
30
|
+
Project-URL: Homepage, https://github.com/karnigen/inksim
|
|
31
|
+
Project-URL: Repository, https://github.com/karnigen/inksim.git
|
|
32
|
+
Project-URL: Issues, https://github.com/karnigen/inksim/issues
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# InkSim
|
|
36
|
+
|
|
37
|
+
InkSim is a standalone interactive embroidery simulator and preview renderer.
|
|
38
|
+
It opens embroidery files, displays their stitch sequence, and lets the user
|
|
39
|
+
inspect or replay the design before production. It is implemented as a small
|
|
40
|
+
Python/wxPython/Numba application with its own standalone user interface.
|
|
41
|
+
|
|
42
|
+
## Project status
|
|
43
|
+
|
|
44
|
+
InkSim is an experimental and actively evolving project. Much of its code was
|
|
45
|
+
created and iterated with substantial assistance from custom AI and LLM tools,
|
|
46
|
+
then reviewed, corrected, and tested during development. It is provided as-is
|
|
47
|
+
for experimentation and development, while already offering a useful way to
|
|
48
|
+
inspect stitch order, replay designs, and create preview images before
|
|
49
|
+
production.
|
|
50
|
+
|
|
51
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines, including
|
|
52
|
+
AI-assisted development and checking the provenance and licenses of submitted
|
|
53
|
+
code and other material.
|
|
54
|
+
|
|
55
|
+
The program is useful for:
|
|
56
|
+
|
|
57
|
+
- quickly checking stitch order, thread colors, jumps, trims, and commands;
|
|
58
|
+
- replaying a design stitch by stitch or at adjustable playback speeds;
|
|
59
|
+
- inspecting the design at fit-to-window, physical 1:1, or custom zoom levels;
|
|
60
|
+
- previewing the design on a procedural fabric background;
|
|
61
|
+
- exporting clean PNG previews for print or documentation.
|
|
62
|
+
|
|
63
|
+
## Requirements
|
|
64
|
+
|
|
65
|
+
- system Python3 or any virtual environment;
|
|
66
|
+
- wxPython;
|
|
67
|
+
- NumPy and Numba;
|
|
68
|
+
- Pillow;
|
|
69
|
+
- pystitch.
|
|
70
|
+
|
|
71
|
+
## Installation
|
|
72
|
+
|
|
73
|
+
The project uses `pyproject.toml` and `uv.lock` for dependency management.
|
|
74
|
+
Install [uv](https://docs.astral.sh/uv/getting-started/installation/) first.
|
|
75
|
+
|
|
76
|
+
### Linux
|
|
77
|
+
|
|
78
|
+
On supported Linux distributions, set up the environment with:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
./scripts/setup_linux.sh
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The script detects the operating system and selects the matching wxPython
|
|
85
|
+
package source. It asks before changing an existing `.venv`; use `-y` for a
|
|
86
|
+
clean, non-interactive setup that removes and recreates it:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
./scripts/setup_linux.sh -y
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The script is Linux-only. It selects a matching wxPython package source for
|
|
93
|
+
supported distributions and asks before changing an existing `.venv`.
|
|
94
|
+
|
|
95
|
+
### Windows and macOS
|
|
96
|
+
|
|
97
|
+
On Windows or macOS, create or update the environment directly from the
|
|
98
|
+
project files:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
uv sync
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
This uses the wxPython package available for the selected platform. The Linux
|
|
105
|
+
setup script must not be run on Windows or macOS.
|
|
106
|
+
|
|
107
|
+
Start the application on either platform with:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
uv run python src/inksim/inksim.py
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The repository already contains the project dependency configuration. From the
|
|
114
|
+
repository root, use the project environment:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
./inksim
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
The script also contains a fallback to virtual-environment bootstrap. When it is
|
|
121
|
+
started with a system Python and a project `.venv` exists, it re-executes
|
|
122
|
+
itself with that interpreter.
|
|
123
|
+
|
|
124
|
+
## Basic Usage
|
|
125
|
+
|
|
126
|
+
Open an empty viewer:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
./inksim
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Open a design immediately:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
./inksim design.dst
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Start playback from the first stitch:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
./inksim design.dst --play
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Start fullscreen or choose an explicit window geometry:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
./inksim design.dst --fullscreen
|
|
148
|
+
./inksim design.dst --size 1600x1000 --position 100,50
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Interactive Controls
|
|
152
|
+
|
|
153
|
+
### Mouse and Window
|
|
154
|
+
|
|
155
|
+
| Action | Function |
|
|
156
|
+
| -------------------------- | ------------------------- |
|
|
157
|
+
| Mouse wheel | Zoom around the cursor |
|
|
158
|
+
| Left-drag in viewer | Pan the design |
|
|
159
|
+
| Click or drag the timeline | Seek to a stitch position |
|
|
160
|
+
| Drop a file on the viewer | Open the file |
|
|
161
|
+
| `F11` | Toggle fullscreen |
|
|
162
|
+
|
|
163
|
+
### Playback and Navigation
|
|
164
|
+
|
|
165
|
+
| Shortcut | Function |
|
|
166
|
+
| ---------------------------- | ----------------------------------------------------------------------------- |
|
|
167
|
+
| `Space` | Play or pause |
|
|
168
|
+
| `Right` / `Left` | Move by the configured step when stopped; change playback speed while playing |
|
|
169
|
+
| `Alt+Right` / `Alt+Left` | Move one stitch |
|
|
170
|
+
| `Up` / `Down` | Move by ten configured steps |
|
|
171
|
+
| `Home` / `End` | Move to the first or last stitch |
|
|
172
|
+
| `Ctrl+Right` / `Ctrl+Left` | Move to the next or previous color section |
|
|
173
|
+
| `Shift+Right` / `Shift+Left` | Move to the next or previous command event |
|
|
174
|
+
| `Esc` | Stop playback |
|
|
175
|
+
|
|
176
|
+
The playback step can also be selected from the Playback menu: 1, 10, 50,
|
|
177
|
+
100, or 500 stitches.
|
|
178
|
+
|
|
179
|
+
### View and Analysis
|
|
180
|
+
|
|
181
|
+
| Shortcut | Function |
|
|
182
|
+
| --------------------- | ---------------------------------------------------------- |
|
|
183
|
+
| `C` | Center the design |
|
|
184
|
+
| `F` | Fit the design to the viewer |
|
|
185
|
+
| `1` | Display at physical 1:1 size when display PPI is available |
|
|
186
|
+
| `G` | Toggle the 1 cm helper grid |
|
|
187
|
+
| `V` | Toggle embroidery visibility |
|
|
188
|
+
| `R` | Toggle realistic thread rendering and fabric background |
|
|
189
|
+
| `J` | Cycle jumps: off, all jumps, risky jumps only |
|
|
190
|
+
| `X` | Toggle the stitch-density map |
|
|
191
|
+
| `N` | Toggle the needle marker |
|
|
192
|
+
| `H` | Show help |
|
|
193
|
+
| `I` | Show current viewer settings |
|
|
194
|
+
| `+` / `-` | Increase or decrease thread width |
|
|
195
|
+
| `[` / `]` | Adjust dark shading |
|
|
196
|
+
| `Shift+[` / `Shift+]` | Adjust light shading |
|
|
197
|
+
|
|
198
|
+
## Rendering Architecture
|
|
199
|
+
|
|
200
|
+
InkSim keeps the loaded design in a NumPy array with one row per stitch
|
|
201
|
+
segment:
|
|
202
|
+
|
|
203
|
+
```text
|
|
204
|
+
[x1, y1, x2, y2, red, green, blue]
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Coordinates are converted from pystitch units to millimeters during loading.
|
|
208
|
+
The viewer then projects millimeters to screen pixels using:
|
|
209
|
+
|
|
210
|
+
```text
|
|
211
|
+
screen_x = world_x * zoom + pan_x
|
|
212
|
+
screen_y = world_y * zoom + pan_y
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
The image is rendered into an RGB NumPy buffer and converted to a wxPython
|
|
216
|
+
bitmap. Numba kernels perform the pixel-heavy work.
|
|
217
|
+
|
|
218
|
+
### Flat and Shaded Rendering
|
|
219
|
+
|
|
220
|
+
`render_shaded_numba` is the normal fast path. It supports both flat colors
|
|
221
|
+
and a lightweight longitudinal gradient. It rasterizes each stitch segment
|
|
222
|
+
with a bounded line width and a small anti-aliased edge. The renderer is kept
|
|
223
|
+
deliberately simple so it remains responsive during playback and navigation.
|
|
224
|
+
|
|
225
|
+
### Realistic Rendering
|
|
226
|
+
|
|
227
|
+
When `R` is enabled and the zoom is high enough for detail to be meaningful,
|
|
228
|
+
InkSim renders a procedural fabric background and routes the stitch data to
|
|
229
|
+
`render_realistic_numba`. The realistic path is separate from the normal
|
|
230
|
+
renderer and includes:
|
|
231
|
+
|
|
232
|
+
- a cylindrical cross-section for each thread;
|
|
233
|
+
- diffuse lighting from a fixed top-left light direction;
|
|
234
|
+
- a specular highlight for thread sheen;
|
|
235
|
+
- a small longitudinal twist modulation;
|
|
236
|
+
- soft cast shadows on the fabric;
|
|
237
|
+
- anti-aliased thread edges;
|
|
238
|
+
- zoom-aware fabric relief and low-zoom texture suppression to reduce moire.
|
|
239
|
+
|
|
240
|
+
The realistic renderer is an intentionally approximate per-stitch model. Its
|
|
241
|
+
isolated cylinders can exaggerate sewing direction and dark gaps, especially
|
|
242
|
+
in satin areas. A future photorealistic implementation should treat a satin
|
|
243
|
+
column as one continuous anisotropic surface or use a normal map instead of
|
|
244
|
+
shading every microscopic stitch as an independent cylinder.
|
|
245
|
+
|
|
246
|
+
### Analysis Overlays
|
|
247
|
+
|
|
248
|
+
Analysis overlays are drawn after the cached bitmap:
|
|
249
|
+
|
|
250
|
+
- jump paths are shown as dashed lines;
|
|
251
|
+
- risky jumps are distinguished from jumps associated with color changes;
|
|
252
|
+
- the density map colors stitch endpoints by local stitch density;
|
|
253
|
+
- the needle marker shows the current endpoint and briefly enlarges after
|
|
254
|
+
navigation.
|
|
255
|
+
|
|
256
|
+
The density calculation is lazy. It is performed only when the density mode
|
|
257
|
+
is first enabled and is cached until a new design is loaded.
|
|
258
|
+
|
|
259
|
+
## File Loading
|
|
260
|
+
|
|
261
|
+
The open dialog builds its file filter from the reader formats reported by
|
|
262
|
+
`pystitch.EmbPattern.supported_formats()`. The viewer therefore follows the
|
|
263
|
+
formats supported by the installed pystitch version instead of maintaining a
|
|
264
|
+
second hard-coded extension list.
|
|
265
|
+
|
|
266
|
+
Thread colors are read from the pattern thread list when available. If a file
|
|
267
|
+
does not provide thread colors, InkSim uses a deterministic fallback palette.
|
|
268
|
+
Embroidery commands such as jumps, color changes, trims, stops, slow, fast,
|
|
269
|
+
and end markers are interpreted while the stitch sequence is converted.
|
|
270
|
+
|
|
271
|
+
## PNG Export
|
|
272
|
+
|
|
273
|
+
InkSim supports three non-interactive export modes:
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
./inksim design.dst --simple-png output.png
|
|
277
|
+
./inksim design.dst --png shaded-output.png
|
|
278
|
+
./inksim design.dst --icon preview.png
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Options:
|
|
282
|
+
|
|
283
|
+
| Option | Description |
|
|
284
|
+
| ------------------------- | ------------------------------------------- |
|
|
285
|
+
| `--simple-png PATH` | Flat PNG at the design's physical size |
|
|
286
|
+
| `--png PATH` | Shaded PNG at the design's physical size |
|
|
287
|
+
| `--icon PATH` | 256 x 256 transparent preview |
|
|
288
|
+
| `--dpi N` | DPI for print-sized exports; default is 300 |
|
|
289
|
+
| `--bg transparent\|white` | Select the export background |
|
|
290
|
+
| `--grid` | Add a 10 mm grid to the exported image |
|
|
291
|
+
|
|
292
|
+
Only one export option may be used at a time. Export mode creates a wx
|
|
293
|
+
application without entering the interactive main loop, renders the design,
|
|
294
|
+
writes PNG metadata, and exits with status 0 on success.
|
|
295
|
+
|
|
296
|
+
The PNG metadata includes design dimensions, background, layer type, rendering
|
|
297
|
+
mode, and DPI where applicable. The interactive fabric/realistic viewport
|
|
298
|
+
renderer is intentionally separate from the current standalone export
|
|
299
|
+
renderer.
|
|
300
|
+
|
|
301
|
+
## Performance Notes
|
|
302
|
+
|
|
303
|
+
- Numba compiles each kernel on its first use; the first render can therefore
|
|
304
|
+
take longer than subsequent renders.
|
|
305
|
+
- The viewer caches the rendered bitmap and uses a temporary stretched bitmap
|
|
306
|
+
while zooming, then schedules a full-quality render after zooming settles.
|
|
307
|
+
- Pan operations can reuse the cached bitmap without rerendering the stitches.
|
|
308
|
+
- The realistic renderer is more expensive than the normal path because it
|
|
309
|
+
evaluates a pixel footprint around every visible stitch and includes a
|
|
310
|
+
separate shadow pass.
|
|
311
|
+
- Maximum thread width and maximum sampling steps are bounded to prevent a
|
|
312
|
+
single long stitch from consuming excessive CPU time.
|
|
313
|
+
|
|
314
|
+
## Design Boundaries and Future Work
|
|
315
|
+
|
|
316
|
+
InkSim is a preview and inspection tool, not a stitch optimizer or machine
|
|
317
|
+
driver. It does not alter the source design during loading and it does not
|
|
318
|
+
replace production-specific checks performed in an embroidery production
|
|
319
|
+
workflow.
|
|
320
|
+
|
|
321
|
+
Likely future rendering improvements include:
|
|
322
|
+
|
|
323
|
+
- continuous satin-surface or normal-map shading;
|
|
324
|
+
- better handling of stitch overlap and needle-hole depressions;
|
|
325
|
+
- adaptive supersampling for very dense designs;
|
|
326
|
+
- optional texture quality controls;
|
|
327
|
+
- a shared export/rendering pipeline when visual parity is required.
|
|
328
|
+
|
|
329
|
+
## Development Checks
|
|
330
|
+
|
|
331
|
+
Run the syntax check with the project environment:
|
|
332
|
+
|
|
333
|
+
```bash
|
|
334
|
+
python3 -m py_compile src/inksim/inksim.py
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
Check the patch for whitespace errors:
|
|
338
|
+
|
|
339
|
+
```bash
|
|
340
|
+
git diff --check -- src/inksim/inksim.py README.md
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
## License
|
|
344
|
+
|
|
345
|
+
InkSim is released under the [GNU General Public License v3 or later](LICENSE).
|
inksim-0.1.0/README.md
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
# InkSim
|
|
2
|
+
|
|
3
|
+
InkSim is a standalone interactive embroidery simulator and preview renderer.
|
|
4
|
+
It opens embroidery files, displays their stitch sequence, and lets the user
|
|
5
|
+
inspect or replay the design before production. It is implemented as a small
|
|
6
|
+
Python/wxPython/Numba application with its own standalone user interface.
|
|
7
|
+
|
|
8
|
+
## Project status
|
|
9
|
+
|
|
10
|
+
InkSim is an experimental and actively evolving project. Much of its code was
|
|
11
|
+
created and iterated with substantial assistance from custom AI and LLM tools,
|
|
12
|
+
then reviewed, corrected, and tested during development. It is provided as-is
|
|
13
|
+
for experimentation and development, while already offering a useful way to
|
|
14
|
+
inspect stitch order, replay designs, and create preview images before
|
|
15
|
+
production.
|
|
16
|
+
|
|
17
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines, including
|
|
18
|
+
AI-assisted development and checking the provenance and licenses of submitted
|
|
19
|
+
code and other material.
|
|
20
|
+
|
|
21
|
+
The program is useful for:
|
|
22
|
+
|
|
23
|
+
- quickly checking stitch order, thread colors, jumps, trims, and commands;
|
|
24
|
+
- replaying a design stitch by stitch or at adjustable playback speeds;
|
|
25
|
+
- inspecting the design at fit-to-window, physical 1:1, or custom zoom levels;
|
|
26
|
+
- previewing the design on a procedural fabric background;
|
|
27
|
+
- exporting clean PNG previews for print or documentation.
|
|
28
|
+
|
|
29
|
+
## Requirements
|
|
30
|
+
|
|
31
|
+
- system Python3 or any virtual environment;
|
|
32
|
+
- wxPython;
|
|
33
|
+
- NumPy and Numba;
|
|
34
|
+
- Pillow;
|
|
35
|
+
- pystitch.
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
The project uses `pyproject.toml` and `uv.lock` for dependency management.
|
|
40
|
+
Install [uv](https://docs.astral.sh/uv/getting-started/installation/) first.
|
|
41
|
+
|
|
42
|
+
### Linux
|
|
43
|
+
|
|
44
|
+
On supported Linux distributions, set up the environment with:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
./scripts/setup_linux.sh
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The script detects the operating system and selects the matching wxPython
|
|
51
|
+
package source. It asks before changing an existing `.venv`; use `-y` for a
|
|
52
|
+
clean, non-interactive setup that removes and recreates it:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
./scripts/setup_linux.sh -y
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The script is Linux-only. It selects a matching wxPython package source for
|
|
59
|
+
supported distributions and asks before changing an existing `.venv`.
|
|
60
|
+
|
|
61
|
+
### Windows and macOS
|
|
62
|
+
|
|
63
|
+
On Windows or macOS, create or update the environment directly from the
|
|
64
|
+
project files:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
uv sync
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
This uses the wxPython package available for the selected platform. The Linux
|
|
71
|
+
setup script must not be run on Windows or macOS.
|
|
72
|
+
|
|
73
|
+
Start the application on either platform with:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
uv run python src/inksim/inksim.py
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The repository already contains the project dependency configuration. From the
|
|
80
|
+
repository root, use the project environment:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
./inksim
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The script also contains a fallback to virtual-environment bootstrap. When it is
|
|
87
|
+
started with a system Python and a project `.venv` exists, it re-executes
|
|
88
|
+
itself with that interpreter.
|
|
89
|
+
|
|
90
|
+
## Basic Usage
|
|
91
|
+
|
|
92
|
+
Open an empty viewer:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
./inksim
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Open a design immediately:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
./inksim design.dst
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Start playback from the first stitch:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
./inksim design.dst --play
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Start fullscreen or choose an explicit window geometry:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
./inksim design.dst --fullscreen
|
|
114
|
+
./inksim design.dst --size 1600x1000 --position 100,50
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Interactive Controls
|
|
118
|
+
|
|
119
|
+
### Mouse and Window
|
|
120
|
+
|
|
121
|
+
| Action | Function |
|
|
122
|
+
| -------------------------- | ------------------------- |
|
|
123
|
+
| Mouse wheel | Zoom around the cursor |
|
|
124
|
+
| Left-drag in viewer | Pan the design |
|
|
125
|
+
| Click or drag the timeline | Seek to a stitch position |
|
|
126
|
+
| Drop a file on the viewer | Open the file |
|
|
127
|
+
| `F11` | Toggle fullscreen |
|
|
128
|
+
|
|
129
|
+
### Playback and Navigation
|
|
130
|
+
|
|
131
|
+
| Shortcut | Function |
|
|
132
|
+
| ---------------------------- | ----------------------------------------------------------------------------- |
|
|
133
|
+
| `Space` | Play or pause |
|
|
134
|
+
| `Right` / `Left` | Move by the configured step when stopped; change playback speed while playing |
|
|
135
|
+
| `Alt+Right` / `Alt+Left` | Move one stitch |
|
|
136
|
+
| `Up` / `Down` | Move by ten configured steps |
|
|
137
|
+
| `Home` / `End` | Move to the first or last stitch |
|
|
138
|
+
| `Ctrl+Right` / `Ctrl+Left` | Move to the next or previous color section |
|
|
139
|
+
| `Shift+Right` / `Shift+Left` | Move to the next or previous command event |
|
|
140
|
+
| `Esc` | Stop playback |
|
|
141
|
+
|
|
142
|
+
The playback step can also be selected from the Playback menu: 1, 10, 50,
|
|
143
|
+
100, or 500 stitches.
|
|
144
|
+
|
|
145
|
+
### View and Analysis
|
|
146
|
+
|
|
147
|
+
| Shortcut | Function |
|
|
148
|
+
| --------------------- | ---------------------------------------------------------- |
|
|
149
|
+
| `C` | Center the design |
|
|
150
|
+
| `F` | Fit the design to the viewer |
|
|
151
|
+
| `1` | Display at physical 1:1 size when display PPI is available |
|
|
152
|
+
| `G` | Toggle the 1 cm helper grid |
|
|
153
|
+
| `V` | Toggle embroidery visibility |
|
|
154
|
+
| `R` | Toggle realistic thread rendering and fabric background |
|
|
155
|
+
| `J` | Cycle jumps: off, all jumps, risky jumps only |
|
|
156
|
+
| `X` | Toggle the stitch-density map |
|
|
157
|
+
| `N` | Toggle the needle marker |
|
|
158
|
+
| `H` | Show help |
|
|
159
|
+
| `I` | Show current viewer settings |
|
|
160
|
+
| `+` / `-` | Increase or decrease thread width |
|
|
161
|
+
| `[` / `]` | Adjust dark shading |
|
|
162
|
+
| `Shift+[` / `Shift+]` | Adjust light shading |
|
|
163
|
+
|
|
164
|
+
## Rendering Architecture
|
|
165
|
+
|
|
166
|
+
InkSim keeps the loaded design in a NumPy array with one row per stitch
|
|
167
|
+
segment:
|
|
168
|
+
|
|
169
|
+
```text
|
|
170
|
+
[x1, y1, x2, y2, red, green, blue]
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Coordinates are converted from pystitch units to millimeters during loading.
|
|
174
|
+
The viewer then projects millimeters to screen pixels using:
|
|
175
|
+
|
|
176
|
+
```text
|
|
177
|
+
screen_x = world_x * zoom + pan_x
|
|
178
|
+
screen_y = world_y * zoom + pan_y
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
The image is rendered into an RGB NumPy buffer and converted to a wxPython
|
|
182
|
+
bitmap. Numba kernels perform the pixel-heavy work.
|
|
183
|
+
|
|
184
|
+
### Flat and Shaded Rendering
|
|
185
|
+
|
|
186
|
+
`render_shaded_numba` is the normal fast path. It supports both flat colors
|
|
187
|
+
and a lightweight longitudinal gradient. It rasterizes each stitch segment
|
|
188
|
+
with a bounded line width and a small anti-aliased edge. The renderer is kept
|
|
189
|
+
deliberately simple so it remains responsive during playback and navigation.
|
|
190
|
+
|
|
191
|
+
### Realistic Rendering
|
|
192
|
+
|
|
193
|
+
When `R` is enabled and the zoom is high enough for detail to be meaningful,
|
|
194
|
+
InkSim renders a procedural fabric background and routes the stitch data to
|
|
195
|
+
`render_realistic_numba`. The realistic path is separate from the normal
|
|
196
|
+
renderer and includes:
|
|
197
|
+
|
|
198
|
+
- a cylindrical cross-section for each thread;
|
|
199
|
+
- diffuse lighting from a fixed top-left light direction;
|
|
200
|
+
- a specular highlight for thread sheen;
|
|
201
|
+
- a small longitudinal twist modulation;
|
|
202
|
+
- soft cast shadows on the fabric;
|
|
203
|
+
- anti-aliased thread edges;
|
|
204
|
+
- zoom-aware fabric relief and low-zoom texture suppression to reduce moire.
|
|
205
|
+
|
|
206
|
+
The realistic renderer is an intentionally approximate per-stitch model. Its
|
|
207
|
+
isolated cylinders can exaggerate sewing direction and dark gaps, especially
|
|
208
|
+
in satin areas. A future photorealistic implementation should treat a satin
|
|
209
|
+
column as one continuous anisotropic surface or use a normal map instead of
|
|
210
|
+
shading every microscopic stitch as an independent cylinder.
|
|
211
|
+
|
|
212
|
+
### Analysis Overlays
|
|
213
|
+
|
|
214
|
+
Analysis overlays are drawn after the cached bitmap:
|
|
215
|
+
|
|
216
|
+
- jump paths are shown as dashed lines;
|
|
217
|
+
- risky jumps are distinguished from jumps associated with color changes;
|
|
218
|
+
- the density map colors stitch endpoints by local stitch density;
|
|
219
|
+
- the needle marker shows the current endpoint and briefly enlarges after
|
|
220
|
+
navigation.
|
|
221
|
+
|
|
222
|
+
The density calculation is lazy. It is performed only when the density mode
|
|
223
|
+
is first enabled and is cached until a new design is loaded.
|
|
224
|
+
|
|
225
|
+
## File Loading
|
|
226
|
+
|
|
227
|
+
The open dialog builds its file filter from the reader formats reported by
|
|
228
|
+
`pystitch.EmbPattern.supported_formats()`. The viewer therefore follows the
|
|
229
|
+
formats supported by the installed pystitch version instead of maintaining a
|
|
230
|
+
second hard-coded extension list.
|
|
231
|
+
|
|
232
|
+
Thread colors are read from the pattern thread list when available. If a file
|
|
233
|
+
does not provide thread colors, InkSim uses a deterministic fallback palette.
|
|
234
|
+
Embroidery commands such as jumps, color changes, trims, stops, slow, fast,
|
|
235
|
+
and end markers are interpreted while the stitch sequence is converted.
|
|
236
|
+
|
|
237
|
+
## PNG Export
|
|
238
|
+
|
|
239
|
+
InkSim supports three non-interactive export modes:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
./inksim design.dst --simple-png output.png
|
|
243
|
+
./inksim design.dst --png shaded-output.png
|
|
244
|
+
./inksim design.dst --icon preview.png
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Options:
|
|
248
|
+
|
|
249
|
+
| Option | Description |
|
|
250
|
+
| ------------------------- | ------------------------------------------- |
|
|
251
|
+
| `--simple-png PATH` | Flat PNG at the design's physical size |
|
|
252
|
+
| `--png PATH` | Shaded PNG at the design's physical size |
|
|
253
|
+
| `--icon PATH` | 256 x 256 transparent preview |
|
|
254
|
+
| `--dpi N` | DPI for print-sized exports; default is 300 |
|
|
255
|
+
| `--bg transparent\|white` | Select the export background |
|
|
256
|
+
| `--grid` | Add a 10 mm grid to the exported image |
|
|
257
|
+
|
|
258
|
+
Only one export option may be used at a time. Export mode creates a wx
|
|
259
|
+
application without entering the interactive main loop, renders the design,
|
|
260
|
+
writes PNG metadata, and exits with status 0 on success.
|
|
261
|
+
|
|
262
|
+
The PNG metadata includes design dimensions, background, layer type, rendering
|
|
263
|
+
mode, and DPI where applicable. The interactive fabric/realistic viewport
|
|
264
|
+
renderer is intentionally separate from the current standalone export
|
|
265
|
+
renderer.
|
|
266
|
+
|
|
267
|
+
## Performance Notes
|
|
268
|
+
|
|
269
|
+
- Numba compiles each kernel on its first use; the first render can therefore
|
|
270
|
+
take longer than subsequent renders.
|
|
271
|
+
- The viewer caches the rendered bitmap and uses a temporary stretched bitmap
|
|
272
|
+
while zooming, then schedules a full-quality render after zooming settles.
|
|
273
|
+
- Pan operations can reuse the cached bitmap without rerendering the stitches.
|
|
274
|
+
- The realistic renderer is more expensive than the normal path because it
|
|
275
|
+
evaluates a pixel footprint around every visible stitch and includes a
|
|
276
|
+
separate shadow pass.
|
|
277
|
+
- Maximum thread width and maximum sampling steps are bounded to prevent a
|
|
278
|
+
single long stitch from consuming excessive CPU time.
|
|
279
|
+
|
|
280
|
+
## Design Boundaries and Future Work
|
|
281
|
+
|
|
282
|
+
InkSim is a preview and inspection tool, not a stitch optimizer or machine
|
|
283
|
+
driver. It does not alter the source design during loading and it does not
|
|
284
|
+
replace production-specific checks performed in an embroidery production
|
|
285
|
+
workflow.
|
|
286
|
+
|
|
287
|
+
Likely future rendering improvements include:
|
|
288
|
+
|
|
289
|
+
- continuous satin-surface or normal-map shading;
|
|
290
|
+
- better handling of stitch overlap and needle-hole depressions;
|
|
291
|
+
- adaptive supersampling for very dense designs;
|
|
292
|
+
- optional texture quality controls;
|
|
293
|
+
- a shared export/rendering pipeline when visual parity is required.
|
|
294
|
+
|
|
295
|
+
## Development Checks
|
|
296
|
+
|
|
297
|
+
Run the syntax check with the project environment:
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
python3 -m py_compile src/inksim/inksim.py
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
Check the patch for whitespace errors:
|
|
304
|
+
|
|
305
|
+
```bash
|
|
306
|
+
git diff --check -- src/inksim/inksim.py README.md
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## License
|
|
310
|
+
|
|
311
|
+
InkSim is released under the [GNU General Public License v3 or later](LICENSE).
|