feat(editor): add --gen-texture-embroidery cross-stitch grid

73rd procedural texture: a grid of X-shape cross stitches.
Each cell holds an X formed by two diagonal strokes from
opposing cell corners through the center. A pixel falls on
a stitch if its in-cell position is within strokeW/2 of
either diagonal axis.

Distinct from --gen-texture-checker (filled squares),
--gen-texture-knit (V-stitch chevron), --gen-texture-lattice
(diagonal trellis). Embroidery is the explicit two-direction
diagonal stitch mark used by counted-thread textile work.

Useful for sampler-cloth detail, folk-art trim, peasant-
clothier border bands, witch-hut wall hangings, hearth-rug
overlays. Default 12-cell / 2-stroke gives a fine X-stitch
look; bump cellSize for chunkier sampler stitches.
This commit is contained in:
Kelsi 2026-05-09 13:25:41 -07:00
parent 81f605617a
commit 7d308e6044
3 changed files with 64 additions and 0 deletions

View file

@ -109,6 +109,7 @@ const char* const kArgRequired[] = {
"--gen-texture-houndstooth", "--gen-texture-chevron",
"--gen-texture-dunes", "--gen-texture-swirl",
"--gen-texture-ironbark", "--gen-texture-mold",
"--gen-texture-embroidery",
"--validate-glb", "--info-glb", "--info-glb-tree", "--info-glb-bytes",
"--validate-jsondbc", "--check-glb-bounds", "--validate-stl",
"--validate-png", "--validate-blp",

View file

@ -3500,6 +3500,66 @@ int handleKnit(int& i, int argc, char** argv) {
return 0;
}
int handleEmbroidery(int& i, int argc, char** argv) {
// Cross-stitch embroidery: a grid of X-shape stitches. Each
// cell holds an X formed by two diagonal strokes from cell
// corners through the center. Distinct from --gen-texture-
// checker (filled squares) and --gen-texture-knit (V-stitch
// chevron) — embroidery is the explicit two-direction
// diagonal stitch mark used by counted-thread textile work.
std::string outPath = argv[++i];
std::string bgHex = argv[++i];
std::string threadHex = argv[++i];
int cellSize = 12;
int strokeW = 2;
int W = 256, H = 256;
parseOptInt(i, argc, argv, cellSize);
parseOptInt(i, argc, argv, strokeW);
parseOptInt(i, argc, argv, W);
parseOptInt(i, argc, argv, H);
if (W < 1 || H < 1 || W > 8192 || H > 8192 ||
cellSize < 4 || cellSize > 1024 ||
strokeW < 1 || strokeW * 2 >= cellSize) {
std::fprintf(stderr,
"gen-texture-embroidery: invalid dims (W/H 1..8192, "
"cellSize 4..1024, strokeW 1..cellSize/2)\n");
return 1;
}
uint8_t br_, bg_, bb_, tr, tg, tb_;
if (!parseHexOrError(bgHex, br_, bg_, bb_,
"gen-texture-embroidery")) return 1;
if (!parseHexOrError(threadHex, tr, tg, tb_,
"gen-texture-embroidery")) return 1;
std::vector<uint8_t> pixels(static_cast<size_t>(W) * H * 3, 0);
const float halfW = strokeW * 0.5f;
for (int y = 0; y < H; ++y) {
int yLocal = y % cellSize;
for (int x = 0; x < W; ++x) {
int xLocal = x % cellSize;
// X-shape test: pixel is on a diagonal stroke if
// |xLocal - yLocal| < strokeW (top-left to bottom-right)
// OR |xLocal + yLocal - cellSize| < strokeW
// (top-right to bottom-left).
float d1 = std::abs(static_cast<float>(xLocal) - yLocal);
float d2 = std::abs(static_cast<float>(xLocal) + yLocal -
cellSize);
uint8_t r, g, b;
if (d1 < halfW || d2 < halfW) {
r = tr; g = tg; b = tb_;
} else {
r = br_; g = bg_; b = bb_;
}
setPixelRGB(pixels, W, x, y, r, g, b);
}
}
if (!savePngOrError(outPath, W, H, pixels,
"gen-texture-embroidery")) return 1;
printPngWrote(outPath, W, H);
std::printf(" bg/thread : %s / %s\n", bgHex.c_str(), threadHex.c_str());
std::printf(" cells : %d, strokeW=%d\n", cellSize, strokeW);
return 0;
}
int handleMold(int& i, int argc, char** argv) {
// Mold: Worley (cellular) noise thresholded into mold patches.
// Each grid cell hosts a hash-jittered center; each pixel
@ -5318,6 +5378,7 @@ constexpr TextureEntry kTextureTable[] = {
{"--gen-texture-swirl", 3, handleSwirl},
{"--gen-texture-ironbark", 3, handleIronbark},
{"--gen-texture-mold", 3, handleMold},
{"--gen-texture-embroidery", 3, handleEmbroidery},
};
} // namespace

View file

@ -179,6 +179,8 @@ void printUsage(const char* argv0) {
std::printf(" Ironbark: vertical wood streaks + horizontal plate bands (mature hardwood / sycamore / ironwood)\n");
std::printf(" --gen-texture-mold <out.png> <bgHex> <moldHex> [stride] [thresholdFrac] [seed] [W H]\n");
std::printf(" Mold: Worley-noise field patches (cellars / dungeon walls / sewer overflow / fungal growth)\n");
std::printf(" --gen-texture-embroidery <out.png> <bgHex> <threadHex> [cellSize] [strokeW] [W H]\n");
std::printf(" Embroidery: grid of cross-stitch X marks (counted-thread textile / sampler / folk-art trim)\n");
std::printf(" --add-texture-to-zone <zoneDir> <png-path> [renameTo]\n");
std::printf(" Copy an existing PNG into <zoneDir> (optionally renaming it on the way in)\n");
std::printf(" --gen-mesh <wom-base> <cube|plane|sphere|cylinder|torus|cone|ramp> [size]\n");