diff --git a/tools/editor/cli_gen_mesh.cpp b/tools/editor/cli_gen_mesh.cpp index a8dd9a70..ccdba94b 100644 --- a/tools/editor/cli_gen_mesh.cpp +++ b/tools/editor/cli_gen_mesh.cpp @@ -4655,6 +4655,108 @@ int handleCoffin(int& i, int argc, char** argv) { return 0; } +int handleStool(int& i, int argc, char** argv) { + // Stool: 5-box small backless seat — flat round-ish seat + // (square here, since axis-aligned) on 4 short legs at the + // corners. Pairs with --gen-mesh-table for taverns and + // workshops. Smaller-footprint counterpart to --gen-mesh-bench. + // The 49th procedural mesh primitive. + std::string womBase = argv[++i]; + float seatSize = 0.36f; // seat side length + float seatT = 0.04f; // seat thickness + float legHeight = 0.45f; + float legT = 0.04f; // square leg cross-section + if (i + 1 < argc && argv[i + 1][0] != '-') { + try { seatSize = std::stof(argv[++i]); } catch (...) {} + } + if (i + 1 < argc && argv[i + 1][0] != '-') { + try { seatT = std::stof(argv[++i]); } catch (...) {} + } + if (i + 1 < argc && argv[i + 1][0] != '-') { + try { legHeight = std::stof(argv[++i]); } catch (...) {} + } + if (i + 1 < argc && argv[i + 1][0] != '-') { + try { legT = std::stof(argv[++i]); } catch (...) {} + } + if (seatSize <= 0 || seatT <= 0 || legHeight <= 0 || legT <= 0 || + legT * 2 >= seatSize) { + std::fprintf(stderr, + "gen-mesh-stool: dims > 0; legT must fit in seatSize\n"); + return 1; + } + if (womBase.size() >= 4 && + womBase.substr(womBase.size() - 4) == ".wom") { + womBase = womBase.substr(0, womBase.size() - 4); + } + wowee::pipeline::WoweeModel wom; + wom.name = std::filesystem::path(womBase).stem().string(); + wom.version = 3; + auto addBox = [&](float cx, float cy, float cz, + float hx, float hy, float hz) { + struct Face { glm::vec3 n, du, dv; }; + Face faces[6] = { + {{0, 1, 0}, {1, 0, 0}, {0, 0, 1}}, + {{0,-1, 0}, {1, 0, 0}, {0, 0,-1}}, + {{1, 0, 0}, {0, 0, 1}, {0, 1, 0}}, + {{-1,0, 0}, {0, 0,-1}, {0, 1, 0}}, + {{0, 0, 1}, {-1,0, 0}, {0, 1, 0}}, + {{0, 0,-1}, {1, 0, 0}, {0, 1, 0}}, + }; + glm::vec3 c(cx, cy, cz); + for (const Face& f : faces) { + glm::vec3 center = c + glm::vec3(f.n.x*hx, f.n.y*hy, f.n.z*hz); + glm::vec3 du = glm::vec3(f.du.x*hx, f.du.y*hy, f.du.z*hz); + glm::vec3 dv = glm::vec3(f.dv.x*hx, f.dv.y*hy, f.dv.z*hz); + uint32_t base = static_cast(wom.vertices.size()); + auto push = [&](glm::vec3 p, float u, float v) { + wowee::pipeline::WoweeModel::Vertex vtx; + vtx.position = p; vtx.normal = f.n; vtx.texCoord = {u, v}; + wom.vertices.push_back(vtx); + }; + push(center - du - dv, 0, 0); + push(center + du - dv, 1, 0); + push(center + du + dv, 1, 1); + push(center - du + dv, 0, 1); + wom.indices.insert(wom.indices.end(), + {base, base + 1, base + 2, base, base + 2, base + 3}); + } + }; + float halfSeat = seatSize * 0.5f; + float halfLeg = legT * 0.5f; + float seatTopY = legHeight + seatT; + // Seat: flat slab on top of the legs. + addBox(0, legHeight + seatT * 0.5f, 0, + halfSeat, seatT * 0.5f, halfSeat); + // 4 legs: corner-inset by halfLeg so they sit flush with + // the seat's edge. + float legX = halfSeat - halfLeg; + float legCY = legHeight * 0.5f; + addBox( legX, legCY, legX, halfLeg, legHeight * 0.5f, halfLeg); + addBox(-legX, legCY, legX, halfLeg, legHeight * 0.5f, halfLeg); + addBox( legX, legCY, -legX, halfLeg, legHeight * 0.5f, halfLeg); + addBox(-legX, legCY, -legX, halfLeg, legHeight * 0.5f, halfLeg); + wowee::pipeline::WoweeModel::Batch batch; + batch.indexStart = 0; + batch.indexCount = static_cast(wom.indices.size()); + batch.textureIndex = 0; + wom.batches.push_back(batch); + wom.boundMin = glm::vec3(-halfSeat, 0.0f, -halfSeat); + wom.boundMax = glm::vec3( halfSeat, seatTopY, halfSeat); + if (!wowee::pipeline::WoweeModelLoader::save(wom, womBase)) { + std::fprintf(stderr, + "gen-mesh-stool: failed to save %s.wom\n", womBase.c_str()); + return 1; + } + std::printf("Wrote %s.wom\n", womBase.c_str()); + std::printf(" seat : %.3f square × %.3f thick\n", seatSize, seatT); + std::printf(" legs : 4 × %.3f square (%.3f tall)\n", + legT, legHeight); + std::printf(" total H : %.3f\n", seatTopY); + std::printf(" vertices : %zu\n", wom.vertices.size()); + std::printf(" triangles : %zu\n", wom.indices.size() / 3); + return 0; +} + int handleCrate(int& i, int argc, char** argv) { // Crate: 5-box wooden shipping crate — main cube body // plus 4 reinforcement posts running along the vertical @@ -6027,6 +6129,9 @@ bool handleGenMesh(int& i, int argc, char** argv, int& outRc) { if (std::strcmp(argv[i], "--gen-mesh-crate") == 0 && i + 1 < argc) { outRc = handleCrate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--gen-mesh-stool") == 0 && i + 1 < argc) { + outRc = handleStool(i, argc, argv); return true; + } return false; } diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index b1f2be8b..d9f9fa41 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -206,6 +206,8 @@ void printUsage(const char* argv0) { std::printf(" Tombstone: base plinth + tall slab + decorative crown (default 0.60/1.10/0.18/1.45)\n"); std::printf(" --gen-mesh-crate [size] [postRadius]\n"); std::printf(" Crate: cube body + 4 corner reinforcement posts (default 0.80/0.05)\n"); + std::printf(" --gen-mesh-stool [seatSize] [seatThick] [legHeight] [legThick]\n"); + std::printf(" Stool: small backless seat on 4 corner legs (default 0.36/0.04/0.45/0.04)\n"); std::printf(" Procedural tree: cylindrical trunk + spherical foliage (default 0.1/2.0/0.7)\n"); std::printf(" --displace-mesh [scale]\n"); std::printf(" Offset each vertex along its normal by heightmap brightness × scale (default 1.0)\n"); diff --git a/tools/editor/main.cpp b/tools/editor/main.cpp index 156d04bc..3a9da281 100644 --- a/tools/editor/main.cpp +++ b/tools/editor/main.cpp @@ -150,6 +150,7 @@ int main(int argc, char* argv[]) { "--gen-mesh-table", "--gen-mesh-lamppost", "--gen-mesh-bed", "--gen-mesh-ladder", "--gen-mesh-well", "--gen-mesh-signpost", "--gen-mesh-mailbox", "--gen-mesh-tombstone", "--gen-mesh-crate", + "--gen-mesh-stool", "--gen-texture-gradient", "--gen-mesh-from-heightmap", "--export-mesh-heightmap", "--displace-mesh",