feat(editor): add --gen-mesh-well village-prop primitive

44th procedural mesh: 7-box water well — 4 stone walls
arranged in a hollow square (interior visible, like a real
well shaft) + 2 vertical roof posts on opposite sides + 1
horizontal cross beam at the top where rope/bucket would
mount. Useful for village squares, courtyards, dungeon
water sources, druidic shrines.

Defaults to 1.4 m square footprint with 0.8 m walls and
1.6 m roof posts (~2.4 m total height). The east/west
walls are shortened so the corner joints line up cleanly
without overlap geometry.
This commit is contained in:
Kelsi 2026-05-09 07:47:15 -07:00
parent 5c350ee0af
commit 549bdaf191
3 changed files with 138 additions and 1 deletions

View file

@ -4655,6 +4655,138 @@ int handleCoffin(int& i, int argc, char** argv) {
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
// roof posts on opposite sides + 1 horizontal cross beam at
// the top (where the rope/bucket would mount). Useful for
// village squares, courtyards, dungeon water sources.
// The 44th procedural mesh primitive.
std::string womBase = argv[++i];
float outerSize = 1.4f; // square wall outer footprint
float wallH = 0.8f; // wall height above ground
float wallT = 0.15f; // wall thickness
float postH = 1.6f; // roof post height above wall
float postT = 0.12f; // roof post thickness (square)
if (i + 1 < argc && argv[i + 1][0] != '-') {
try { outerSize = std::stof(argv[++i]); } catch (...) {}
}
if (i + 1 < argc && argv[i + 1][0] != '-') {
try { wallH = std::stof(argv[++i]); } catch (...) {}
}
if (i + 1 < argc && argv[i + 1][0] != '-') {
try { wallT = std::stof(argv[++i]); } catch (...) {}
}
if (i + 1 < argc && argv[i + 1][0] != '-') {
try { postH = std::stof(argv[++i]); } catch (...) {}
}
if (i + 1 < argc && argv[i + 1][0] != '-') {
try { postT = std::stof(argv[++i]); } catch (...) {}
}
if (outerSize <= 0 || wallH <= 0 || wallT <= 0 ||
postH <= 0 || postT <= 0 || wallT * 2 >= outerSize) {
std::fprintf(stderr,
"gen-mesh-well: dims > 0; wallT must fit in outerSize\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<uint32_t>(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 halfOuter = outerSize * 0.5f;
float halfWallT = wallT * 0.5f;
float halfPostT = postT * 0.5f;
// 4 wall panels arranged in a hollow square. Each panel
// spans full outerSize along its long axis. Walls along X
// sit at z = ±(halfOuter - halfWallT); walls along Z sit at
// x = ±(halfOuter - halfWallT) but shortened so they don't
// overlap the X walls (interior length = outerSize - 2*wallT).
float wallCY = wallH * 0.5f;
// North wall (+Z edge) — full outerSize wide.
addBox(0, wallCY, halfOuter - halfWallT,
halfOuter, wallH * 0.5f, halfWallT);
// South wall (-Z edge) — full outerSize wide.
addBox(0, wallCY, -halfOuter + halfWallT,
halfOuter, wallH * 0.5f, halfWallT);
// East wall (+X edge) — interior length only.
float eastWestLen = outerSize - 2 * wallT;
addBox(halfOuter - halfWallT, wallCY, 0,
halfWallT, wallH * 0.5f, eastWestLen * 0.5f);
// West wall (-X edge) — interior length only.
addBox(-halfOuter + halfWallT, wallCY, 0,
halfWallT, wallH * 0.5f, eastWestLen * 0.5f);
// 2 vertical roof posts mounted on top of the east and west
// walls, centred in z. Posts rise from the top of the walls
// (y=wallH) by postH.
float postCY = wallH + postH * 0.5f;
float postX = halfOuter - halfPostT;
addBox( postX, postCY, 0, halfPostT, postH * 0.5f, halfPostT);
addBox(-postX, postCY, 0, halfPostT, postH * 0.5f, halfPostT);
// Horizontal cross beam connecting the post tops. The beam
// spans the full distance between posts (so it ends inside
// each post). Beam is square in cross section, slightly
// thicker than the posts so it visually overlaps the joint.
float beamT = postT * 1.2f;
float halfBeamT = beamT * 0.5f;
float beamCY = wallH + postH - halfBeamT;
addBox(0, beamCY, 0,
halfOuter * 0.85f, halfBeamT, halfBeamT);
wowee::pipeline::WoweeModel::Batch batch;
batch.indexStart = 0;
batch.indexCount = static_cast<uint32_t>(wom.indices.size());
batch.textureIndex = 0;
wom.batches.push_back(batch);
float totalH = wallH + postH;
wom.boundMin = glm::vec3(-halfOuter, 0.0f, -halfOuter);
wom.boundMax = glm::vec3( halfOuter, totalH, halfOuter);
if (!wowee::pipeline::WoweeModelLoader::save(wom, womBase)) {
std::fprintf(stderr,
"gen-mesh-well: failed to save %s.wom\n", womBase.c_str());
return 1;
}
std::printf("Wrote %s.wom\n", womBase.c_str());
std::printf(" outerSize : %.3f square\n", outerSize);
std::printf(" wall : %.3f tall, %.3f thick\n", wallH, wallT);
std::printf(" roof posts : 2 × %.3f tall\n", postH);
std::printf(" total H : %.3f (with cross beam)\n", totalH);
std::printf(" vertices : %zu\n", wom.vertices.size());
std::printf(" triangles : %zu\n", wom.indices.size() / 3);
return 0;
}
int handleLadder(int& i, int argc, char** argv) {
// Ladder: 2 vertical rails + N horizontal rungs evenly
// spaced between them. Sits flat against +Z (the climbing
@ -5418,6 +5550,9 @@ bool handleGenMesh(int& i, int argc, char** argv, int& outRc) {
if (std::strcmp(argv[i], "--gen-mesh-ladder") == 0 && i + 1 < argc) {
outRc = handleLadder(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--gen-mesh-well") == 0 && i + 1 < argc) {
outRc = handleWell(i, argc, argv); return true;
}
return false;
}

View file

@ -186,6 +186,8 @@ void printUsage(const char* argv0) {
std::printf(" Bed: 4 legs + mattress + headboard + footboard + pillow (default 2.0/1.2/0.30/0.20/1.0/0.4)\n");
std::printf(" --gen-mesh-ladder <wom-base> [height] [width] [rungs] [railThick] [rungThick]\n");
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 <wom-base> [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(" Procedural tree: cylindrical trunk + spherical foliage (default 0.1/2.0/0.7)\n");
std::printf(" --displace-mesh <wom-base> <heightmap.png> [scale]\n");
std::printf(" Offset each vertex along its normal by heightmap brightness × scale (default 1.0)\n");

View file

@ -139,7 +139,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-ladder", "--gen-mesh-well",
"--gen-texture-gradient",
"--gen-mesh-from-heightmap", "--export-mesh-heightmap",
"--displace-mesh",