From 993e90f0ee108f22384e028dc398a9959a34e04f Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sat, 9 May 2026 09:37:13 -0700 Subject: [PATCH] feat(editor): add --gen-mesh-sundial garden-timekeeper primitive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 55th procedural mesh: 6-box garden sundial — square base plate at floor, central vertical gnomon slab spanning the diameter (long axis along Z, the blade that casts a shadow), and 4 small hour-marker nubs at the cardinal points (N/S/E/W) around the rim. Useful for monastery courtyards, mage tower observatories, druidic stone circles, manor gardens — anywhere a fantasy world wants visible time-keeping. Defaults to 0.80m square base with 0.35m gnomon (~0.41m total height). --- tools/editor/cli_gen_mesh.cpp | 120 ++++++++++++++++++++++++++++++++++ tools/editor/cli_help.cpp | 2 + tools/editor/main.cpp | 2 +- 3 files changed, 123 insertions(+), 1 deletion(-) diff --git a/tools/editor/cli_gen_mesh.cpp b/tools/editor/cli_gen_mesh.cpp index 285fddf1..ddbe2720 100644 --- a/tools/editor/cli_gen_mesh.cpp +++ b/tools/editor/cli_gen_mesh.cpp @@ -4655,6 +4655,123 @@ int handleCoffin(int& i, int argc, char** argv) { return 0; } +int handleSundial(int& i, int argc, char** argv) { + // Sundial: 8-box garden timekeeper — square base plate at + // floor, central vertical gnomon slab spanning the diameter + // (long axis along Z, simulates the angled blade that casts + // a shadow), and 4 small hour-marker nubs at the cardinal + // points around the rim. Useful for monastery courtyards, + // mage tower observatories, druidic stone circles. The + // 55th procedural mesh primitive. + std::string womBase = argv[++i]; + float baseSize = 0.80f; + float baseHeight = 0.06f; + float gnomonHeight = 0.35f; + float gnomonT = 0.04f; + if (i + 1 < argc && argv[i + 1][0] != '-') { + try { baseSize = std::stof(argv[++i]); } catch (...) {} + } + if (i + 1 < argc && argv[i + 1][0] != '-') { + try { baseHeight = std::stof(argv[++i]); } catch (...) {} + } + if (i + 1 < argc && argv[i + 1][0] != '-') { + try { gnomonHeight = std::stof(argv[++i]); } catch (...) {} + } + if (i + 1 < argc && argv[i + 1][0] != '-') { + try { gnomonT = std::stof(argv[++i]); } catch (...) {} + } + if (baseSize <= 0 || baseHeight <= 0 || + gnomonHeight <= 0 || gnomonT <= 0 || + gnomonT * 2 >= baseSize) { + std::fprintf(stderr, + "gen-mesh-sundial: dims > 0; gnomonT 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}); + } + }; + float halfBase = baseSize * 0.5f; + // Base plate at floor. + addBox(0, baseHeight * 0.5f, 0, + halfBase, baseHeight * 0.5f, halfBase); + // Gnomon: vertical slab centered on the base, spanning the + // diameter along Z (the long axis). Sits on top of the base. + float halfGnomonT = gnomonT * 0.5f; + float halfGnomonZ = baseSize * 0.45f; // slightly inset from base edges + float gnomonCY = baseHeight + gnomonHeight * 0.5f; + addBox(0, gnomonCY, 0, + halfGnomonT, gnomonHeight * 0.5f, halfGnomonZ); + // 4 hour-marker nubs at cardinal positions (N, S, E, W) on + // the base's top face. Small protrusions above the base + // plate so they read as raised markers. + float markerW = baseSize * 0.06f; + float markerH = baseHeight * 1.5f; + float halfMW = markerW * 0.5f; + float markerOff = halfBase * 0.85f; + float markerCY = baseHeight + markerH * 0.5f; + addBox( markerOff, markerCY, 0, halfMW, markerH * 0.5f, halfMW); // E + addBox(-markerOff, markerCY, 0, halfMW, markerH * 0.5f, halfMW); // W + addBox(0, markerCY, markerOff, halfMW, markerH * 0.5f, halfMW); // N + addBox(0, markerCY, -markerOff, halfMW, markerH * 0.5f, halfMW); // S + 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 = baseHeight + gnomonHeight; + wom.boundMin = glm::vec3(-halfBase, 0.0f, -halfBase); + wom.boundMax = glm::vec3( halfBase, totalH, halfBase); + if (!wowee::pipeline::WoweeModelLoader::save(wom, womBase)) { + std::fprintf(stderr, + "gen-mesh-sundial: failed to save %s.wom\n", womBase.c_str()); + return 1; + } + std::printf("Wrote %s.wom\n", womBase.c_str()); + std::printf(" base : %.3f square × %.3f thick\n", + baseSize, baseHeight); + std::printf(" gnomon : %.3f tall × %.3f thick (along Z)\n", + gnomonHeight, gnomonT); + std::printf(" markers : 4 (N/S/E/W cardinal points)\n"); + std::printf(" total H : %.3f\n", totalH); + std::printf(" vertices : %zu\n", wom.vertices.size()); + std::printf(" triangles : %zu\n", wom.indices.size() / 3); + return 0; +} + int handleScarecrow(int& i, int argc, char** argv) { // Scarecrow: 5-box cruciform farm pest deterrent — anchor // post into the ground, vertical body, horizontal arm cross, @@ -6742,6 +6859,9 @@ bool handleGenMesh(int& i, int argc, char** argv, int& outRc) { if (std::strcmp(argv[i], "--gen-mesh-scarecrow") == 0 && i + 1 < argc) { outRc = handleScarecrow(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--gen-mesh-sundial") == 0 && i + 1 < argc) { + outRc = handleSundial(i, argc, argv); return true; + } return false; } diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index 25666755..34e87bbe 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -222,6 +222,8 @@ void printUsage(const char* argv0) { std::printf(" Weathervane: base + post + N-S/E-W cross arms + arrow with tail (default 1.50/0.05/0.30/0.40/0.55)\n"); std::printf(" --gen-mesh-scarecrow [bodyH] [armSpan] [postT] [headSize] [hatSize]\n"); std::printf(" Scarecrow: cruciform body + cross arms + head + brimmed hat (default 1.80/1.40/0.06/0.22/0.32)\n"); + std::printf(" --gen-mesh-sundial [baseSize] [baseH] [gnomonH] [gnomonT]\n"); + std::printf(" Sundial: square base + central gnomon slab + 4 cardinal hour markers (default 0.80/0.06/0.35/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 340fc54d..4891787d 100644 --- a/tools/editor/main.cpp +++ b/tools/editor/main.cpp @@ -164,7 +164,7 @@ int main(int argc, char* argv[]) { "--gen-mesh-mailbox", "--gen-mesh-tombstone", "--gen-mesh-crate", "--gen-mesh-stool", "--gen-mesh-cauldron", "--gen-mesh-gate", "--gen-mesh-beehive", "--gen-mesh-weathervane", - "--gen-mesh-scarecrow", + "--gen-mesh-scarecrow", "--gen-mesh-sundial", "--gen-texture-gradient", "--gen-mesh-from-heightmap", "--export-mesh-heightmap", "--displace-mesh",