feat(editor): add --gen-texture-lattice diagonal-grid pattern

41st procedural texture: garden trellis / mesh fence done as
two perpendicular sets of diagonal lines (+45° and -45°)
drawn simultaneously across the whole image so they form
diamond-shaped openings between the lines.

Distinct from --gen-texture-herringbone (which alternates
strip orientation): lattice draws both diagonal sets at every
pixel. Useful for trellises, wire mesh fences, dragon-scale
chain mail, decorative window grilles. Defaults to 24-px line
spacing with 3-px line width.
This commit is contained in:
Kelsi 2026-05-09 08:40:14 -07:00
parent 6430a3f554
commit 16f9c072c7
3 changed files with 80 additions and 0 deletions

View file

@ -3887,6 +3887,80 @@ int handleGingham(int& i, int argc, char** argv) {
return 0;
}
int handleLattice(int& i, int argc, char** argv) {
// Lattice: garden trellis — two sets of diagonal lines, one
// at +45° and one at -45°, drawn simultaneously across the
// whole image so they form diamond-shaped openings between
// the lines. Distinct from --gen-texture-herringbone (which
// alternates strip orientation) — this draws both diagonals
// at every pixel.
std::string outPath = argv[++i];
std::string bgHex = argv[++i];
std::string lineHex = argv[++i];
int lineSpacing = 24;
int lineWidth = 3;
int W = 256, H = 256;
if (i + 1 < argc && argv[i + 1][0] != '-') {
try { lineSpacing = std::stoi(argv[++i]); } catch (...) {}
}
if (i + 1 < argc && argv[i + 1][0] != '-') {
try { lineWidth = std::stoi(argv[++i]); } catch (...) {}
}
if (i + 1 < argc && argv[i + 1][0] != '-') {
try { W = std::stoi(argv[++i]); } catch (...) {}
}
if (i + 1 < argc && argv[i + 1][0] != '-') {
try { H = std::stoi(argv[++i]); } catch (...) {}
}
if (W < 1 || H < 1 || W > 8192 || H > 8192 ||
lineSpacing < 4 || lineSpacing > 256 ||
lineWidth < 1 || lineWidth >= lineSpacing) {
std::fprintf(stderr,
"gen-texture-lattice: invalid dims (W/H 1..8192, spacing 4..256, width 1..spacing-1)\n");
return 1;
}
uint8_t br_, bg_, bb_, lr, lg, lb_;
if (!parseHex(bgHex, br_, bg_, bb_) ||
!parseHex(lineHex, lr, lg, lb_)) {
std::fprintf(stderr,
"gen-texture-lattice: bg or line hex color is invalid\n");
return 1;
}
std::vector<uint8_t> pixels(static_cast<size_t>(W) * H * 3, 0);
for (int y = 0; y < H; ++y) {
for (int x = 0; x < W; ++x) {
// +45° line set: where (x + y) mod spacing is small.
int posMod = ((x + y) % lineSpacing + lineSpacing) % lineSpacing;
// -45° line set: where (x - y) mod spacing is small.
int negMod = ((x - y) % lineSpacing + lineSpacing) % lineSpacing;
bool onLine = (posMod < lineWidth) || (negMod < lineWidth);
uint8_t r, g, b;
if (onLine) {
r = lr; g = lg; b = lb_;
} else {
r = br_; g = bg_; b = bb_;
}
size_t idx = (static_cast<size_t>(y) * W + x) * 3;
pixels[idx + 0] = r;
pixels[idx + 1] = g;
pixels[idx + 2] = b;
}
}
if (!stbi_write_png(outPath.c_str(), W, H, 3,
pixels.data(), W * 3)) {
std::fprintf(stderr,
"gen-texture-lattice: stbi_write_png failed for %s\n",
outPath.c_str());
return 1;
}
std::printf("Wrote %s\n", outPath.c_str());
std::printf(" size : %dx%d\n", W, H);
std::printf(" bg / line : %s / %s\n", bgHex.c_str(), lineHex.c_str());
std::printf(" diagonals : ±45° at %d-px spacing, %d-px width\n",
lineSpacing, lineWidth);
return 0;
}
} // namespace
bool handleGenTexture(int& i, int argc, char** argv, int& outRc) {
@ -4012,6 +4086,9 @@ bool handleGenTexture(int& i, int argc, char** argv, int& outRc) {
if (std::strcmp(argv[i], "--gen-texture-gingham") == 0 && i + 4 < argc) {
outRc = handleGingham(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--gen-texture-lattice") == 0 && i + 3 < argc) {
outRc = handleLattice(i, argc, argv); return true;
}
return false;
}

View file

@ -115,6 +115,8 @@ void printUsage(const char* argv0) {
std::printf(" Spider web: N radial spokes + M concentric polygonal rings centered on the image\n");
std::printf(" --gen-texture-gingham <out.png> <bgHex> <stripeHex> <crossHex> [spacing] [width] [W H]\n");
std::printf(" Gingham: 3-tone fabric — bg + perpendicular stripes + darker color where they cross\n");
std::printf(" --gen-texture-lattice <out.png> <bgHex> <lineHex> [spacing] [width] [W H]\n");
std::printf(" Lattice: ±45° diagonal grid forming diamond openings (garden trellis / mesh fence)\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");

View file

@ -171,6 +171,7 @@ int main(int argc, char* argv[]) {
"--gen-texture-shingles", "--gen-texture-frost",
"--gen-texture-parquet", "--gen-texture-bubbles",
"--gen-texture-spider-web", "--gen-texture-gingham",
"--gen-texture-lattice",
"--validate-glb", "--info-glb", "--info-glb-tree", "--info-glb-bytes",
"--validate-jsondbc", "--check-glb-bounds", "--validate-stl",
"--validate-png", "--validate-blp",