feat(editor): add --gen-texture-carbon fiber-weave pattern

57th procedural texture: 2x2 cell pattern where alternating
cells hold horizontal vs vertical fiber segments. Each
segment gets a sin² brightness profile across its
perpendicular axis — 0 at the segment edge, peak at center —
giving the rounded highlight of a real woven fiber bundle.

Cell-pair parity (cx + cy) % 2 determines orientation, so
adjacent cells always alternate weave direction in both X
and Y. Reads as the unmistakable carbon-fiber checkerboard
even at small scales.

Useful for sci-fi armor, sleek tech panels, vehicle bodies,
ritual obsidian inlays, dwarven runeplate accents — any
"machined composite" surface where flat dark grey would
read as plain plastic.

Default 12-pixel cell at 256x256 reads cleanly with about
21 visible weave segments per side.
This commit is contained in:
Kelsi 2026-05-09 11:49:20 -07:00
parent 9347290335
commit 68af5c10c9
3 changed files with 73 additions and 0 deletions

View file

@ -90,6 +90,7 @@ const char* const kArgRequired[] = {
"--gen-texture-rope", "--gen-texture-caustics",
"--gen-texture-starburst", "--gen-texture-studs",
"--gen-texture-moss", "--gen-texture-woodgrain",
"--gen-texture-carbon",
"--validate-glb", "--info-glb", "--info-glb-tree", "--info-glb-bytes",
"--validate-jsondbc", "--check-glb-bounds", "--validate-stl",
"--validate-png", "--validate-blp",

View file

@ -4235,6 +4235,75 @@ int handleKnit(int& i, int argc, char** argv) {
return 0;
}
int handleCarbon(int& i, int argc, char** argv) {
// Carbon-fiber weave: 2x2 cells where alternating cells hold
// horizontal vs vertical fiber segments. Each segment has a
// sin² brightness profile across its perpendicular axis,
// simulating the rounded highlight on a real woven fiber bundle.
// Useful for sci-fi armor, sleek tech panels, hi-tech vehicle
// bodies, ritual obsidian inlays, or any "machined composite"
// surface where a flat color would read as plastic.
std::string outPath = argv[++i];
std::string bgHex = argv[++i];
std::string fibHex = argv[++i];
int cellSize = 12;
int W = 256, H = 256;
parseOptInt(i, argc, argv, cellSize);
parseOptInt(i, argc, argv, W);
parseOptInt(i, argc, argv, H);
if (W < 1 || H < 1 || W > 8192 || H > 8192 ||
cellSize < 2 || cellSize > 1024) {
std::fprintf(stderr,
"gen-texture-carbon: invalid dims (W/H 1..8192, "
"cellSize 2..1024)\n");
return 1;
}
uint8_t br_, bg_, bb_, fr, fg, fb_;
if (!parseHex(bgHex, br_, bg_, bb_) ||
!parseHex(fibHex, fr, fg, fb_)) {
std::fprintf(stderr,
"gen-texture-carbon: bg or fiber hex color is invalid\n");
return 1;
}
std::vector<uint8_t> pixels(static_cast<size_t>(W) * H * 3, 0);
const float pi = 3.14159265358979f;
const float invCell = 1.0f / cellSize;
for (int y = 0; y < H; ++y) {
int cy = y / cellSize;
int ly = y - cy * cellSize;
for (int x = 0; x < W; ++x) {
int cx = x / cellSize;
int lx = x - cx * cellSize;
// (cx + cy) parity determines fiber orientation.
// Brightness profile is sin² of the perpendicular
// local coord normalized to [0, π].
bool horiz = ((cx + cy) & 1) == 0;
float perp = horiz ? (ly * invCell) : (lx * invCell);
float s = std::sin(perp * pi);
float t = s * s; // 0..1, peak at center
uint8_t r = static_cast<uint8_t>(br_ + t * (fr - br_));
uint8_t g = static_cast<uint8_t>(bg_ + t * (fg - bg_));
uint8_t b = static_cast<uint8_t>(bb_ + t * (fb_ - 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-carbon: 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/fiber : %s / %s\n", bgHex.c_str(), fibHex.c_str());
std::printf(" weave cell : %d\n", cellSize);
return 0;
}
int handleWoodgrain(int& i, int argc, char** argv) {
// Wood-end grain: concentric annual rings centered slightly
// outside the image (so the texture shows arcs sweeping across
@ -5058,6 +5127,7 @@ constexpr TextureEntry kTextureTable[] = {
{"--gen-texture-studs", 3, handleStuds},
{"--gen-texture-moss", 3, handleMoss},
{"--gen-texture-woodgrain", 3, handleWoodgrain},
{"--gen-texture-carbon", 3, handleCarbon},
};
} // namespace

View file

@ -147,6 +147,8 @@ void printUsage(const char* argv0) {
std::printf(" Moss: irregular spots scattered on a hash-jittered grid (forest floor / weathered stone / swamp)\n");
std::printf(" --gen-texture-woodgrain <out.png> <lightHex> <darkHex> [spacing] [seed] [W H]\n");
std::printf(" Woodgrain: concentric annual rings centered off-image with per-ring jitter (end-cut wood)\n");
std::printf(" --gen-texture-carbon <out.png> <bgHex> <fiberHex> [cellSize] [W H]\n");
std::printf(" Carbon-fiber: 2x2 alternating-orientation weave with sin² fiber highlights (sci-fi/tech panels)\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");