feat(editor): add --gen-texture-stripes for two-color band patterns

Synthesizes a two-color stripe pattern PNG. Stripe width in pixels,
plus direction (diagonal default, or horizontal/vertical). Color
endpoints share the same RRGGBB / RGB hex syntax as other texture
gens.

Useful for caution tape, marble bands, hazard markers, racing-style
start/finish flags — patterns that --gen-texture's checker/grid
don't capture.

Verified: 128×128 diagonal yellow/black at 32px ('caution tape')
and 256×256 horizontal red/white at 16px both written successfully
with correct headers reported. Brings command count to 227 (and
the texture-synthesis family to 6: solid + checker + grid + linear
gradient + radial gradient + noise + stripes).
This commit is contained in:
Kelsi 2026-05-07 08:05:18 -07:00
parent 3852bac1d8
commit 734e7dc2f0

View file

@ -532,6 +532,8 @@ static void printUsage(const char* argv0) {
std::printf(" Synthesize a smooth value-noise PNG (deterministic from seed; default 256x256)\n");
std::printf(" --gen-texture-radial <out.png> <centerHex> <edgeHex> [W H]\n");
std::printf(" Synthesize a radial gradient PNG (center→edge, smooth distance-based blend)\n");
std::printf(" --gen-texture-stripes <out.png> <colorAHex> <colorBHex> [stripePx] [diagonal|horizontal|vertical] [W H]\n");
std::printf(" Synthesize a two-color stripe pattern (default 16px diagonal, 256x256)\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> [size]\n");
@ -981,7 +983,7 @@ int main(int argc, char* argv[]) {
"--gen-texture-noise", "--rotate-mesh",
"--center-mesh", "--flip-mesh-normals", "--mirror-mesh",
"--merge-meshes",
"--gen-texture-radial",
"--gen-texture-radial", "--gen-texture-stripes",
"--validate-glb", "--info-glb", "--info-glb-tree", "--info-glb-bytes",
"--validate-jsondbc", "--check-glb-bounds", "--validate-stl",
"--validate-png", "--validate-blp",
@ -15864,6 +15866,115 @@ int main(int argc, char* argv[]) {
std::printf(" edge : %s (rgb %u,%u,%u)\n",
edgeHex.c_str(), re, ge, be);
return 0;
} else if (std::strcmp(argv[i], "--gen-texture-stripes") == 0 && i + 3 < argc) {
// Two-color stripe pattern. Stripe width in pixels, plus
// direction (diagonal default, or horizontal/vertical).
// Useful for caution tape, marble bands, hazard markers,
// and racing-style start/finish flags — patterns that
// checker/grid don't capture.
std::string outPath = argv[++i];
std::string aHex = argv[++i];
std::string bHex = argv[++i];
int stripePx = 16;
std::string dir = "diagonal";
int W = 256, H = 256;
if (i + 1 < argc && argv[i + 1][0] != '-') {
try { stripePx = std::stoi(argv[++i]); } catch (...) {}
}
if (i + 1 < argc && argv[i + 1][0] != '-') {
std::string d = argv[i + 1];
std::transform(d.begin(), d.end(), d.begin(),
[](unsigned char c) { return std::tolower(c); });
if (d == "diagonal" || d == "horizontal" || d == "vertical") {
dir = d;
i++;
}
}
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 ||
stripePx < 1 || stripePx > 4096) {
std::fprintf(stderr,
"gen-texture-stripes: invalid dims (W/H 1..8192, stripe 1..4096)\n");
return 1;
}
auto parseHex = [](std::string hex,
uint8_t& r, uint8_t& g, uint8_t& b) -> bool {
std::transform(hex.begin(), hex.end(), hex.begin(),
[](unsigned char c) { return std::tolower(c); });
if (!hex.empty() && hex[0] == '#') hex.erase(0, 1);
auto fromHexC = [](char c) -> int {
if (c >= '0' && c <= '9') return c - '0';
if (c >= 'a' && c <= 'f') return 10 + c - 'a';
return -1;
};
int v[6];
if (hex.size() == 6) {
for (int k = 0; k < 6; ++k) {
v[k] = fromHexC(hex[k]);
if (v[k] < 0) return false;
}
r = static_cast<uint8_t>((v[0] << 4) | v[1]);
g = static_cast<uint8_t>((v[2] << 4) | v[3]);
b = static_cast<uint8_t>((v[4] << 4) | v[5]);
return true;
}
if (hex.size() == 3) {
for (int k = 0; k < 3; ++k) {
v[k] = fromHexC(hex[k]);
if (v[k] < 0) return false;
}
r = static_cast<uint8_t>((v[0] << 4) | v[0]);
g = static_cast<uint8_t>((v[1] << 4) | v[1]);
b = static_cast<uint8_t>((v[2] << 4) | v[2]);
return true;
}
return false;
};
uint8_t ra, ga, ba, rb, gb, bb;
if (!parseHex(aHex, ra, ga, ba)) {
std::fprintf(stderr,
"gen-texture-stripes: '%s' is not a valid hex color\n",
aHex.c_str());
return 1;
}
if (!parseHex(bHex, rb, gb, bb)) {
std::fprintf(stderr,
"gen-texture-stripes: '%s' is not a valid hex color\n",
bHex.c_str());
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) {
int proj;
if (dir == "horizontal") proj = y;
else if (dir == "vertical") proj = x;
else proj = x + y;
bool isA = ((proj / stripePx) & 1) == 0;
size_t i2 = (static_cast<size_t>(y) * W + x) * 3;
pixels[i2 + 0] = isA ? ra : rb;
pixels[i2 + 1] = isA ? ga : gb;
pixels[i2 + 2] = isA ? ba : bb;
}
}
if (!stbi_write_png(outPath.c_str(), W, H, 3,
pixels.data(), W * 3)) {
std::fprintf(stderr,
"gen-texture-stripes: 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(" direction : %s\n", dir.c_str());
std::printf(" stripe : %d px\n", stripePx);
std::printf(" colors : %s + %s\n", aHex.c_str(), bHex.c_str());
return 0;
} else if (std::strcmp(argv[i], "--gen-mesh") == 0 && i + 2 < argc) {
// Synthesize a procedural primitive WOM. Generates proper
// per-face normals, planar UVs, a bounding box, and a