From 61bc9dfb15f161dac22e001ce2fb1357eabf4b76 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sat, 9 May 2026 06:58:38 -0700 Subject: [PATCH] feat(editor): add --gen-mesh-table furniture primitive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 40th procedural mesh: simple 5-box table — flat top slab on 4 vertical corner legs. Pairs with --gen-mesh-bench / --gen-mesh-throne / --gen-mesh-bookshelf for taverns, dining halls, libraries, and study set dressing. Defaults to 1.6 × 1.0 base × 0.85 tall, 0.10-square legs, 0.06-thick top — sensible dining-table proportions. Customizable per dimension so a single primitive covers desks, end tables, and big banquet tables. --- tools/editor/cli_gen_mesh.cpp | 111 ++++++++++++++++++++++++++++++++++ tools/editor/cli_help.cpp | 2 + tools/editor/main.cpp | 1 + 3 files changed, 114 insertions(+) diff --git a/tools/editor/cli_gen_mesh.cpp b/tools/editor/cli_gen_mesh.cpp index 9e7e3a3d..443d608f 100644 --- a/tools/editor/cli_gen_mesh.cpp +++ b/tools/editor/cli_gen_mesh.cpp @@ -4655,6 +4655,114 @@ int handleCoffin(int& i, int argc, char** argv) { return 0; } +int handleTable(int& i, int argc, char** argv) { + // Table: 5 boxes — flat tabletop slab on top of 4 vertical + // legs at each corner. Thinnest of the furniture meshes, + // pairs naturally with --gen-mesh-bench / --gen-mesh-throne + // for taverns and dining halls. The 40th procedural mesh + // primitive. + std::string womBase = argv[++i]; + float width = 1.6f; // along X + float depth = 1.0f; // along Z + float height = 0.85f; // along Y (top of tabletop) + float legT = 0.10f; // leg thickness (square cross-section) + float topT = 0.06f; // tabletop thickness + if (i + 1 < argc && argv[i + 1][0] != '-') { + try { width = std::stof(argv[++i]); } catch (...) {} + } + if (i + 1 < argc && argv[i + 1][0] != '-') { + try { depth = std::stof(argv[++i]); } catch (...) {} + } + if (i + 1 < argc && argv[i + 1][0] != '-') { + try { height = std::stof(argv[++i]); } catch (...) {} + } + if (i + 1 < argc && argv[i + 1][0] != '-') { + try { legT = std::stof(argv[++i]); } catch (...) {} + } + if (i + 1 < argc && argv[i + 1][0] != '-') { + try { topT = std::stof(argv[++i]); } catch (...) {} + } + if (width <= 0 || depth <= 0 || height <= 0 || legT <= 0 || + topT <= 0 || legT * 2 > width || legT * 2 > depth || + topT >= height) { + std::fprintf(stderr, + "gen-mesh-table: dims > 0; legT must fit in width/depth; topT < height\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 halfW = width * 0.5f; + float halfD = depth * 0.5f; + float halfLeg = legT * 0.5f; + float legHeight = height - topT; + // Tabletop: spans full width × depth, sits at y=height-topT to y=height. + addBox(0, height - topT * 0.5f, 0, + halfW, topT * 0.5f, halfD); + // 4 legs: one at each corner, inset by legT/2 from the edge. + float legCY = legHeight * 0.5f; + float legX = halfW - halfLeg; + float legZ = halfD - halfLeg; + addBox( legX, legCY, legZ, halfLeg, legHeight * 0.5f, halfLeg); + addBox(-legX, legCY, legZ, halfLeg, legHeight * 0.5f, halfLeg); + addBox( legX, legCY, -legZ, halfLeg, legHeight * 0.5f, halfLeg); + addBox(-legX, legCY, -legZ, 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(-halfW, 0.0f, -halfD); + wom.boundMax = glm::vec3( halfW, height, halfD); + if (!wowee::pipeline::WoweeModelLoader::save(wom, womBase)) { + std::fprintf(stderr, + "gen-mesh-table: failed to save %s.wom\n", womBase.c_str()); + return 1; + } + std::printf("Wrote %s.wom\n", womBase.c_str()); + std::printf(" size : %.3f x %.3f x %.3f\n", width, height, depth); + std::printf(" legs : 4 × %.3f square (%.3f tall)\n", + legT, legHeight); + std::printf(" top thick : %.3f\n", topT); + std::printf(" vertices : %zu\n", wom.vertices.size()); + std::printf(" triangles : %zu\n", wom.indices.size() / 3); + return 0; +} + int handleBookshelf(int& i, int argc, char** argv) { // Bookshelf: cabinet (5 panels: back / left / right / top / // bottom) divided by N-1 horizontal shelves, with rows of @@ -4928,6 +5036,9 @@ bool handleGenMesh(int& i, int argc, char** argv, int& outRc) { if (std::strcmp(argv[i], "--gen-mesh-bookshelf") == 0 && i + 1 < argc) { outRc = handleBookshelf(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--gen-mesh-table") == 0 && i + 1 < argc) { + outRc = handleTable(i, argc, argv); return true; + } return false; } diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index 6c28c47c..277570dc 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -170,6 +170,8 @@ void printUsage(const char* argv0) { std::printf(" Hexagonal coffin: narrow head + wide shoulder + tapered foot prism (default 2.0/0.8/0.6)\n"); std::printf(" --gen-mesh-bookshelf [width] [height] [depth] [shelves]\n"); std::printf(" Bookshelf: 5-panel cabinet with N-1 shelves and rows of varied book boxes (default 1.5/2.0/0.4/4)\n"); + std::printf(" --gen-mesh-table [width] [depth] [height] [legThick] [topThick]\n"); + std::printf(" Table: flat top slab on 4 corner legs (default 1.6/1.0/0.85/0.10/0.06)\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 2035cb67..9a1cc0e1 100644 --- a/tools/editor/main.cpp +++ b/tools/editor/main.cpp @@ -130,6 +130,7 @@ int main(int argc, char* argv[]) { "--gen-mesh-banner", "--gen-mesh-grave", "--gen-mesh-bench", "--gen-mesh-shrine", "--gen-mesh-totem", "--gen-mesh-cage", "--gen-mesh-throne", "--gen-mesh-coffin", "--gen-mesh-bookshelf", + "--gen-mesh-table", "--gen-texture-gradient", "--gen-mesh-from-heightmap", "--export-mesh-heightmap", "--displace-mesh",