mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-10 02:53:51 +00:00
feat(editor): add --gen-mesh-totem stacked carved totem primitive
Stack of N square blocks with alternating widths: even-indexed blocks (0, 2, 4...) get full base width, odd blocks (1, 3, 5...) get 70% — gives the carved-segment look characteristic of totem poles. Defaults: baseW=0.5, 5 segments, segH=0.5. Useful for tribal zones, druid groves, fairgrounds, primitive village markers. Brings the procedural mesh primitive set to 35.
This commit is contained in:
parent
a23eb420ef
commit
47e78d4e08
3 changed files with 98 additions and 1 deletions
|
|
@ -4189,6 +4189,98 @@ int handleShrine(int& i, int argc, char** argv) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int handleTotem(int& i, int argc, char** argv) {
|
||||||
|
// Tribal totem: stack of N square blocks alternating wide/
|
||||||
|
// narrow widths so each carved face reads as distinct.
|
||||||
|
// Even-indexed blocks are full width, odd are 70% — gives
|
||||||
|
// the carved-segment look characteristic of totem poles.
|
||||||
|
// The 35th procedural mesh primitive.
|
||||||
|
std::string womBase = argv[++i];
|
||||||
|
float baseW = 0.5f; // base block half-width × 2
|
||||||
|
int segments = 5; // number of stacked blocks
|
||||||
|
float segH = 0.5f; // height of each block
|
||||||
|
if (i + 1 < argc && argv[i + 1][0] != '-') {
|
||||||
|
try { baseW = std::stof(argv[++i]); } catch (...) {}
|
||||||
|
}
|
||||||
|
if (i + 1 < argc && argv[i + 1][0] != '-') {
|
||||||
|
try { segments = std::stoi(argv[++i]); } catch (...) {}
|
||||||
|
}
|
||||||
|
if (i + 1 < argc && argv[i + 1][0] != '-') {
|
||||||
|
try { segH = std::stof(argv[++i]); } catch (...) {}
|
||||||
|
}
|
||||||
|
if (baseW <= 0 || segH <= 0 || segments < 1 || segments > 32) {
|
||||||
|
std::fprintf(stderr,
|
||||||
|
"gen-mesh-totem: dims > 0, segments 1..32\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);
|
||||||
|
glm::vec3 ext(hx, hy, hz);
|
||||||
|
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*ext.x, f.du.y*ext.y, f.du.z*ext.z);
|
||||||
|
glm::vec3 dv = glm::vec3(f.dv.x*ext.x, f.dv.y*ext.y, f.dv.z*ext.z);
|
||||||
|
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});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Stack blocks bottom-up. Bottom block always full width.
|
||||||
|
// Even blocks (0, 2, 4...) get full width, odd blocks 70%.
|
||||||
|
for (int s = 0; s < segments; ++s) {
|
||||||
|
float cy = (s + 0.5f) * segH;
|
||||||
|
float halfW = (s & 1) ? (baseW * 0.5f * 0.70f) : (baseW * 0.5f);
|
||||||
|
addBox(0, cy, 0, halfW, segH * 0.5f, halfW);
|
||||||
|
}
|
||||||
|
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 maxY = segments * segH;
|
||||||
|
float maxXZ = baseW * 0.5f;
|
||||||
|
wom.boundMin = glm::vec3(-maxXZ, 0, -maxXZ);
|
||||||
|
wom.boundMax = glm::vec3( maxXZ, maxY, maxXZ);
|
||||||
|
if (!wowee::pipeline::WoweeModelLoader::save(wom, womBase)) {
|
||||||
|
std::fprintf(stderr,
|
||||||
|
"gen-mesh-totem: failed to save %s.wom\n", womBase.c_str());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
std::printf("Wrote %s.wom\n", womBase.c_str());
|
||||||
|
std::printf(" base width : %.3f\n", baseW);
|
||||||
|
std::printf(" segments : %d (each %.3f tall)\n", segments, segH);
|
||||||
|
std::printf(" total H : %.3f\n", maxY);
|
||||||
|
std::printf(" vertices : %zu\n", wom.vertices.size());
|
||||||
|
std::printf(" triangles : %zu\n", wom.indices.size() / 3);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
bool handleGenMesh(int& i, int argc, char** argv, int& outRc) {
|
bool handleGenMesh(int& i, int argc, char** argv, int& outRc) {
|
||||||
|
|
@ -4286,6 +4378,9 @@ bool handleGenMesh(int& i, int argc, char** argv, int& outRc) {
|
||||||
if (std::strcmp(argv[i], "--gen-mesh-shrine") == 0 && i + 1 < argc) {
|
if (std::strcmp(argv[i], "--gen-mesh-shrine") == 0 && i + 1 < argc) {
|
||||||
outRc = handleShrine(i, argc, argv); return true;
|
outRc = handleShrine(i, argc, argv); return true;
|
||||||
}
|
}
|
||||||
|
if (std::strcmp(argv[i], "--gen-mesh-totem") == 0 && i + 1 < argc) {
|
||||||
|
outRc = handleTotem(i, argc, argv); return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,8 @@ void printUsage(const char* argv0) {
|
||||||
std::printf(" Wooden bench: seat plank + 2 leg slabs (default 1.5/0.5/0.06/0.4)\n");
|
std::printf(" Wooden bench: seat plank + 2 leg slabs (default 1.5/0.5/0.06/0.4)\n");
|
||||||
std::printf(" --gen-mesh-shrine <wom-base> [size] [pillarHeight] [pillarRadius] [roofThickness]\n");
|
std::printf(" --gen-mesh-shrine <wom-base> [size] [pillarHeight] [pillarRadius] [roofThickness]\n");
|
||||||
std::printf(" Small canopy: square base + 4 corner pillars + flat roof slab (default 1.5/2/0.1/0.15)\n");
|
std::printf(" Small canopy: square base + 4 corner pillars + flat roof slab (default 1.5/2/0.1/0.15)\n");
|
||||||
|
std::printf(" --gen-mesh-totem <wom-base> [width] [segments] [segmentHeight]\n");
|
||||||
|
std::printf(" Tribal totem: stack of N alternating-width carved blocks (default w=0.5, 5 segs, h=0.5)\n");
|
||||||
std::printf(" Procedural tree: cylindrical trunk + spherical foliage (default 0.1/2.0/0.7)\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(" --displace-mesh <wom-base> <heightmap.png> [scale]\n");
|
||||||
std::printf(" Offset each vertex along its normal by heightmap brightness × scale (default 1.0)\n");
|
std::printf(" Offset each vertex along its normal by heightmap brightness × scale (default 1.0)\n");
|
||||||
|
|
|
||||||
|
|
@ -204,7 +204,7 @@ int main(int argc, char* argv[]) {
|
||||||
"--gen-mesh-archway", "--gen-mesh-barrel", "--gen-mesh-chest",
|
"--gen-mesh-archway", "--gen-mesh-barrel", "--gen-mesh-chest",
|
||||||
"--gen-mesh-anvil", "--gen-mesh-mushroom", "--gen-mesh-cart",
|
"--gen-mesh-anvil", "--gen-mesh-mushroom", "--gen-mesh-cart",
|
||||||
"--gen-mesh-banner", "--gen-mesh-grave", "--gen-mesh-bench",
|
"--gen-mesh-banner", "--gen-mesh-grave", "--gen-mesh-bench",
|
||||||
"--gen-mesh-shrine",
|
"--gen-mesh-shrine", "--gen-mesh-totem",
|
||||||
"--gen-texture-gradient",
|
"--gen-texture-gradient",
|
||||||
"--gen-mesh-from-heightmap", "--export-mesh-heightmap",
|
"--gen-mesh-from-heightmap", "--export-mesh-heightmap",
|
||||||
"--displace-mesh",
|
"--displace-mesh",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue