From af3c4f0bd6ec55643400fa5d0647462b8857bf59 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sat, 9 May 2026 07:58:45 -0700 Subject: [PATCH] feat(editor): add --gen-mesh-signpost wayfinding primitive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 45th procedural mesh: 4-box signpost — stone base anchor, tall vertical pole, thin sign board mounted face-out near the top, and a small decorative cap. Useful for crossroads, tavern fronts, town entrances, dungeon area markers, quest hub indicators. Sign board's long axis runs along Z so the player reads the sign when facing parallel to the road. Defaults to a 2.5 m post with a 0.8 x 0.35 m board (~2.7 m total). --- tools/editor/cli_gen_mesh.cpp | 127 ++++++++++++++++++++++++++++++++++ tools/editor/cli_help.cpp | 2 + tools/editor/main.cpp | 2 +- 3 files changed, 130 insertions(+), 1 deletion(-) diff --git a/tools/editor/cli_gen_mesh.cpp b/tools/editor/cli_gen_mesh.cpp index 8888330a..93ffa184 100644 --- a/tools/editor/cli_gen_mesh.cpp +++ b/tools/editor/cli_gen_mesh.cpp @@ -4655,6 +4655,130 @@ int handleCoffin(int& i, int argc, char** argv) { return 0; } +int handleSignpost(int& i, int argc, char** argv) { + // Signpost: 4-box wayfinding prop — stone base anchor at the + // ground, tall vertical pole, decorative cap, and one + // horizontal sign board mounted face-out from the pole near + // the top. Useful for crossroads, tavern fronts, town + // entrances, dungeon area markers. The 45th procedural mesh. + std::string womBase = argv[++i]; + float postHeight = 2.5f; + float postThickness = 0.10f; + float baseSize = 0.30f; + float signWidth = 0.80f; // along Z (perpendicular to pole face) + float signHeight = 0.35f; // along Y + if (i + 1 < argc && argv[i + 1][0] != '-') { + try { postHeight = std::stof(argv[++i]); } catch (...) {} + } + if (i + 1 < argc && argv[i + 1][0] != '-') { + try { postThickness = std::stof(argv[++i]); } catch (...) {} + } + if (i + 1 < argc && argv[i + 1][0] != '-') { + try { baseSize = std::stof(argv[++i]); } catch (...) {} + } + if (i + 1 < argc && argv[i + 1][0] != '-') { + try { signWidth = std::stof(argv[++i]); } catch (...) {} + } + if (i + 1 < argc && argv[i + 1][0] != '-') { + try { signHeight = std::stof(argv[++i]); } catch (...) {} + } + if (postHeight <= 0 || postThickness <= 0 || baseSize <= 0 || + signWidth <= 0 || signHeight <= 0 || + postThickness >= baseSize) { + std::fprintf(stderr, + "gen-mesh-signpost: dims > 0; post must fit in base\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}); + } + }; + // Base plinth at the floor. + float baseHeight = baseSize * 0.45f; + float halfBase = baseSize * 0.5f; + addBox(0, baseHeight * 0.5f, 0, + halfBase, baseHeight * 0.5f, halfBase); + // Pole rising above the base. + float poleBottomY = baseHeight; + float poleTopY = baseHeight + postHeight; + float poleCY = (poleBottomY + poleTopY) * 0.5f; + float halfPole = postThickness * 0.5f; + addBox(0, poleCY, 0, + halfPole, postHeight * 0.5f, halfPole); + // Sign board: thin rectangle mounted on the pole near the top. + // signWidth runs along Z (the long axis), signHeight along Y, + // and a sliver of postThickness along X — a billboard that + // reads as a sign when viewed from either +Z or -Z. + float signCenterY = poleTopY - signHeight * 0.7f; + float signThickness = postThickness * 0.6f; + addBox(0, signCenterY, 0, + signThickness * 0.5f, signHeight * 0.5f, signWidth * 0.5f); + // Decorative cap on top of the pole. + float capHeight = postThickness * 0.8f; + float capCY = poleTopY + capHeight * 0.5f; + float halfCap = postThickness * 0.9f; + addBox(0, capCY, 0, + halfCap, capHeight * 0.5f, halfCap); + wowee::pipeline::WoweeModel::Batch batch; + batch.indexStart = 0; + batch.indexCount = static_cast(wom.indices.size()); + batch.textureIndex = 0; + wom.batches.push_back(batch); + float totalH = capCY + capHeight * 0.5f; + float halfSignZ = signWidth * 0.5f; + wom.boundMin = glm::vec3(-std::max(halfBase, halfSignZ), 0.0f, -halfSignZ); + wom.boundMax = glm::vec3( std::max(halfBase, halfSignZ), totalH, halfSignZ); + if (!wowee::pipeline::WoweeModelLoader::save(wom, womBase)) { + std::fprintf(stderr, + "gen-mesh-signpost: failed to save %s.wom\n", womBase.c_str()); + return 1; + } + std::printf("Wrote %s.wom\n", womBase.c_str()); + std::printf(" total H : %.3f\n", totalH); + std::printf(" base : %.3f square × %.3f tall\n", + baseSize, baseHeight); + std::printf(" pole : %.3f square × %.3f tall\n", + postThickness, postHeight); + std::printf(" sign board : %.3f × %.3f (wide × tall)\n", + signWidth, signHeight); + std::printf(" vertices : %zu\n", wom.vertices.size()); + std::printf(" triangles : %zu\n", wom.indices.size() / 3); + return 0; +} + int handleWell(int& i, int argc, char** argv) { // Well: 4 stone walls arranged in a square ring (hollow // interior so a player can see down the shaft) + 2 vertical @@ -5553,6 +5677,9 @@ bool handleGenMesh(int& i, int argc, char** argv, int& outRc) { if (std::strcmp(argv[i], "--gen-mesh-well") == 0 && i + 1 < argc) { outRc = handleWell(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--gen-mesh-signpost") == 0 && i + 1 < argc) { + outRc = handleSignpost(i, argc, argv); return true; + } return false; } diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index 971e4030..c246b3bc 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -190,6 +190,8 @@ void printUsage(const char* argv0) { std::printf(" Ladder: 2 vertical rails + N evenly-spaced horizontal rungs (default 3.0/0.6/8/0.06/0.04)\n"); std::printf(" --gen-mesh-well [outerSize] [wallH] [wallT] [postH] [postT]\n"); std::printf(" Well: 4 stone walls in a hollow square + 2 roof posts + cross beam (default 1.4/0.8/0.15/1.6/0.12)\n"); + std::printf(" --gen-mesh-signpost [poleH] [poleT] [baseSize] [signWidth] [signHeight]\n"); + std::printf(" Signpost: base + pole + sign board + cap (default 2.5/0.10/0.30/0.80/0.35)\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 13b5079f..64bb1cdc 100644 --- a/tools/editor/main.cpp +++ b/tools/editor/main.cpp @@ -140,7 +140,7 @@ int main(int argc, char* argv[]) { "--gen-mesh-shrine", "--gen-mesh-totem", "--gen-mesh-cage", "--gen-mesh-throne", "--gen-mesh-coffin", "--gen-mesh-bookshelf", "--gen-mesh-table", "--gen-mesh-lamppost", "--gen-mesh-bed", - "--gen-mesh-ladder", "--gen-mesh-well", + "--gen-mesh-ladder", "--gen-mesh-well", "--gen-mesh-signpost", "--gen-texture-gradient", "--gen-mesh-from-heightmap", "--export-mesh-heightmap", "--displace-mesh",