diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index f9796c60..abdf2cb7 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -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", diff --git a/tools/editor/cli_gen_texture.cpp b/tools/editor/cli_gen_texture.cpp index 2a1ebeda..82843789 100644 --- a/tools/editor/cli_gen_texture.cpp +++ b/tools/editor/cli_gen_texture.cpp @@ -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 pixels(static_cast(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(br_ + t * (fr - br_)); + uint8_t g = static_cast(bg_ + t * (fg - bg_)); + uint8_t b = static_cast(bb_ + t * (fb_ - 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-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 diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index 3c605149..96affc5a 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -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 [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 [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 [renameTo]\n"); std::printf(" Copy an existing PNG into (optionally renaming it on the way in)\n"); std::printf(" --gen-mesh [size]\n");