diff --git a/tools/editor/cli_gen_texture.cpp b/tools/editor/cli_gen_texture.cpp index 0c131b1d..dd2e8dbd 100644 --- a/tools/editor/cli_gen_texture.cpp +++ b/tools/editor/cli_gen_texture.cpp @@ -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 pixels(static_cast(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(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; } diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index 23cc1ae3..b1f2be8b 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -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 [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 [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 [renameTo]\n"); std::printf(" Copy an existing PNG into (optionally renaming it on the way in)\n"); std::printf(" --gen-mesh [size]\n"); diff --git a/tools/editor/main.cpp b/tools/editor/main.cpp index 34131e2d..aa0b1c76 100644 --- a/tools/editor/main.cpp +++ b/tools/editor/main.cpp @@ -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",