refactor(editor): extract addBox into shared cli_box_emitter
36 procedural mesh primitives in cli_gen_mesh.cpp each open-
coded the same ~30-line lambda for emitting a flat-shaded
axis-aligned box (per-face vertices for unique normals,
6 faces × 4 verts × 2 tris). Hoist the implementation into
cli_box_emitter.{hpp,cpp} as addFlatBox(WoweeModel&, ...)
with two overloads:
• addFlatBox(wom, cx, cy, cz, hx, hy, hz)
center + half-extents form, used by 34 primitives
• addFlatBox(wom, glm::vec3 lo, glm::vec3 hi)
lo/hi corners form, used by --gen-mesh-archway and
--gen-mesh-fence which compute corners directly
Each lambda site collapses from ~30 lines to a 3-line thin
wrapper: cli_gen_mesh.cpp drops from 7374 to 6989 lines.
Output bytes verified identical via --info-mesh-stats
(firepit surface area 2.1100 m² unchanged, vertex/triangle
counts match across firepit/canopy/dock/archway/fence).
Future box-based primitives now opt in by including one
header instead of pasting the lambda again.
2026-05-09 11:24:35 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "pipeline/wowee_model.hpp"
|
|
|
|
|
#include <glm/glm.hpp>
|
2026-05-09 11:29:52 -07:00
|
|
|
#include <cstdint>
|
refactor(editor): extract addBox into shared cli_box_emitter
36 procedural mesh primitives in cli_gen_mesh.cpp each open-
coded the same ~30-line lambda for emitting a flat-shaded
axis-aligned box (per-face vertices for unique normals,
6 faces × 4 verts × 2 tris). Hoist the implementation into
cli_box_emitter.{hpp,cpp} as addFlatBox(WoweeModel&, ...)
with two overloads:
• addFlatBox(wom, cx, cy, cz, hx, hy, hz)
center + half-extents form, used by 34 primitives
• addFlatBox(wom, glm::vec3 lo, glm::vec3 hi)
lo/hi corners form, used by --gen-mesh-archway and
--gen-mesh-fence which compute corners directly
Each lambda site collapses from ~30 lines to a 3-line thin
wrapper: cli_gen_mesh.cpp drops from 7374 to 6989 lines.
Output bytes verified identical via --info-mesh-stats
(firepit surface area 2.1100 m² unchanged, vertex/triangle
counts match across firepit/canopy/dock/archway/fence).
Future box-based primitives now opt in by including one
header instead of pasting the lambda again.
2026-05-09 11:24:35 -07:00
|
|
|
|
|
|
|
|
namespace wowee {
|
|
|
|
|
namespace editor {
|
|
|
|
|
namespace cli {
|
|
|
|
|
|
2026-05-09 11:29:52 -07:00
|
|
|
// Append one vertex (position, normal, UV) to a WoweeModel and
|
|
|
|
|
// return its newly-assigned index. Inline because the procedural
|
|
|
|
|
// mesh primitives call this thousands of times per build and the
|
|
|
|
|
// abstraction shouldn't cost a function-call frame each time.
|
|
|
|
|
// Pre-extraction this was the same 5-line lambda copy-pasted into
|
|
|
|
|
// 21 different handlers.
|
|
|
|
|
inline uint32_t addVertex(wowee::pipeline::WoweeModel& wom,
|
|
|
|
|
glm::vec3 p, glm::vec3 n, glm::vec2 uv) {
|
|
|
|
|
wowee::pipeline::WoweeModel::Vertex vtx;
|
|
|
|
|
vtx.position = p;
|
|
|
|
|
vtx.normal = n;
|
|
|
|
|
vtx.texCoord = uv;
|
|
|
|
|
wom.vertices.push_back(vtx);
|
|
|
|
|
return static_cast<uint32_t>(wom.vertices.size() - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Per-float overload used by handlers that compute pos/normal/uv
|
|
|
|
|
// components inline rather than building intermediate glm vectors
|
|
|
|
|
// (--gen-mesh-stairs, --gen-mesh-tube, --gen-mesh-capsule,
|
|
|
|
|
// --gen-mesh-arch). Same semantics as the vec3/vec2 form.
|
|
|
|
|
inline uint32_t addVertex(wowee::pipeline::WoweeModel& wom,
|
|
|
|
|
float px, float py, float pz,
|
|
|
|
|
float nx, float ny, float nz,
|
|
|
|
|
float u, float v) {
|
|
|
|
|
return addVertex(wom, glm::vec3(px, py, pz), glm::vec3(nx, ny, nz),
|
|
|
|
|
glm::vec2(u, v));
|
|
|
|
|
}
|
|
|
|
|
|
refactor(editor): extract addBox into shared cli_box_emitter
36 procedural mesh primitives in cli_gen_mesh.cpp each open-
coded the same ~30-line lambda for emitting a flat-shaded
axis-aligned box (per-face vertices for unique normals,
6 faces × 4 verts × 2 tris). Hoist the implementation into
cli_box_emitter.{hpp,cpp} as addFlatBox(WoweeModel&, ...)
with two overloads:
• addFlatBox(wom, cx, cy, cz, hx, hy, hz)
center + half-extents form, used by 34 primitives
• addFlatBox(wom, glm::vec3 lo, glm::vec3 hi)
lo/hi corners form, used by --gen-mesh-archway and
--gen-mesh-fence which compute corners directly
Each lambda site collapses from ~30 lines to a 3-line thin
wrapper: cli_gen_mesh.cpp drops from 7374 to 6989 lines.
Output bytes verified identical via --info-mesh-stats
(firepit surface area 2.1100 m² unchanged, vertex/triangle
counts match across firepit/canopy/dock/archway/fence).
Future box-based primitives now opt in by including one
header instead of pasting the lambda again.
2026-05-09 11:24:35 -07:00
|
|
|
// Append a flat-shaded axis-aligned box to a WoweeModel. The box
|
|
|
|
|
// is centered at (cx, cy, cz) with half-extents (hx, hy, hz). Each
|
|
|
|
|
// of the 6 faces emits its own 4 vertices with the face's outward
|
|
|
|
|
// normal, so adjacent faces don't share normals — exactly what
|
|
|
|
|
// flat shading needs. UVs are 0..1 across each face.
|
|
|
|
|
//
|
|
|
|
|
// Used pervasively by --gen-mesh-* primitives that build meshes
|
|
|
|
|
// from axis-aligned box primitives (firepit stones, dock pilings,
|
|
|
|
|
// canopy posts, woodpile logs, tent walls before the door cutout
|
|
|
|
|
// added one-off triangles, etc.). Hoisted out of cli_gen_mesh.cpp
|
|
|
|
|
// where 36 identical lambdas duplicated this implementation.
|
|
|
|
|
void addFlatBox(wowee::pipeline::WoweeModel& wom,
|
|
|
|
|
float cx, float cy, float cz,
|
|
|
|
|
float hx, float hy, float hz);
|
|
|
|
|
|
|
|
|
|
// Overload taking lower/upper corner positions (lo, hi). Some
|
|
|
|
|
// callers (--gen-mesh-archway, --gen-mesh-fence) compute corners
|
|
|
|
|
// directly rather than center+halfsize.
|
|
|
|
|
void addFlatBox(wowee::pipeline::WoweeModel& wom,
|
|
|
|
|
glm::vec3 lo, glm::vec3 hi);
|
|
|
|
|
|
|
|
|
|
} // namespace cli
|
|
|
|
|
} // namespace editor
|
|
|
|
|
} // namespace wowee
|